import{i as e}from"./chunk-aKtaBQYM.js";import{Vt as t,wt as n}from"./mui-B6lh3XSP.js";import{i as r,n as i,r as a,t as o}from"./ExpandMore-BvigPYWL.js";import{t as s}from"./TextField-DOdnjCrL.js";import{t as c}from"./Typography-DfQXhGTT.js";import{Qt as l,Ut as u,Wt as d,bt as f,en as p,mt as m,nt as h,tt as g,w as _,yt as v}from"./index-KVuxnkWj.js";import{t as y}from"./SelectField-9K8NpSQG.js";import{n as b,t as x}from"./useSettingsStyles-X3caKosH.js";import{t as S}from"./EditItemView-BNkSnNuu.js";var C=e(t(),1),w=n(),T=()=>{let{classes:e}=x(),t=v(),[n,T]=(0,C.useState)(),E=f(e=>e.startsWith(`alarm`)).map(e=>({key:h(`alarm`,e),name:t(e)})),D=m(async()=>{await Promise.all(n.notificators.split(/[, ]+/).map(async e=>{await _(`/api/notifications/test/${e}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)})}))});return(0,w.jsx)(S,{endpoint:`notifications`,item:n,setItem:T,validate:()=>n&&n.type&&n.notificators&&(!n.notificators?.includes(`command`)||n.commandId),menu:(0,w.jsx)(b,{}),breadcrumbs:[`settingsTitle`,`sharedNotification`],children:n&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(r,{defaultExpanded:!0,children:[(0,w.jsx)(i,{expandIcon:(0,w.jsx)(o,{}),children:(0,w.jsx)(c,{variant:`subtitle1`,children:t(`sharedRequired`)})}),(0,w.jsxs)(a,{className:e.details,children:[(0,w.jsx)(y,{value:n.type,onChange:e=>T({...n,type:e.target.value}),endpoint:`/api/notifications/types`,keyGetter:e=>e.type,titleGetter:e=>t(g(`event`,e.type)),label:t(`sharedType`),helperText:[`geofenceEnter`,`geofenceExit`].includes(n.type)?t(`notificationGeofenceLabel`):null}),n.type===`alarm`&&(0,w.jsx)(y,{multiple:!0,value:n.attributes&&n.attributes.alarms?n.attributes.alarms.split(/[, ]+/):[],onChange:e=>T({...n,attributes:{...n.attributes,alarms:e.target.value.join()}}),data:E,keyGetter:e=>e.key,label:t(`sharedAlarms`)}),(0,w.jsx)(y,{multiple:!0,value:n.notificators?n.notificators.split(/[, ]+/):[],onChange:e=>T({...n,notificators:e.target.value.join()}),endpoint:`/api/notifications/notificators`,keyGetter:e=>e.type,titleGetter:e=>t(g(`notificator`,e.type)),label:t(`notificationNotificators`)}),n.notificators?.includes(`command`)&&(0,w.jsx)(y,{value:n.commandId,onChange:e=>T({...n,commandId:Number(e.target.value)}),endpoint:`/api/commands`,titleGetter:e=>e.description,label:t(`sharedSavedCommand`)}),(0,w.jsx)(p,{variant:`outlined`,color:`primary`,onClick:D,disabled:!n.notificators,children:t(`sharedTestNotificators`)}),(0,w.jsx)(u,{children:(0,w.jsx)(d,{control:(0,w.jsx)(l,{checked:n.always,onChange:e=>T({...n,always:e.target.checked})}),label:t(`notificationAlways`)})})]})]}),(0,w.jsxs)(r,{children:[(0,w.jsx)(i,{expandIcon:(0,w.jsx)(o,{}),children:(0,w.jsx)(c,{variant:`subtitle1`,children:t(`sharedExtra`)})}),(0,w.jsxs)(a,{className:e.details,children:[(0,w.jsx)(s,{value:n.description||``,onChange:e=>T({...n,description:e.target.value}),label:t(`sharedDescription`)}),(0,w.jsx)(y,{value:n.calendarId,onChange:e=>T({...n,calendarId:Number(e.target.value)}),endpoint:`/api/calendars`,label:t(`sharedCalendar`)}),[`geofenceEnter`,`geofenceExit`].includes(n.type)&&(0,w.jsx)(y,{multiple:!0,value:n.attributes?.geofenceIds?n.attributes.geofenceIds.split(`,`):[],onChange:e=>{let t=e.target.value.join(),r={...n.attributes};t?r.geofenceIds=t:delete r.geofenceIds,T({...n,attributes:r})},endpoint:`/api/geofences`,keyGetter:e=>String(e.id),label:t(`sharedGeofences`)}),(0,w.jsx)(u,{children:(0,w.jsx)(d,{control:(0,w.jsx)(l,{checked:n.attributes&&n.attributes.priority,onChange:e=>T({...n,attributes:{...n.attributes,priority:e.target.checked}})}),label:t(`sharedPriority`)})})]})]})]})})};export{T as default};