import{i as e}from"./chunk-aKtaBQYM.js";import{Ft as t,vt as n}from"./mui-BgU4WrXF.js";import{i as r,n as i,r as a,t as o}from"./ExpandMore-D0ycvrdR.js";import{t as s}from"./Typography-7EcQ2i3p.js";import{t as c}from"./TextField-DctlzLY-.js";import{Ft as l,Pt as u,Ut as d,Vt as f,X as p,Y as m,ct as h,mt as g,pt as _,w as v}from"./index-bel1r0Sr.js";import{t as y}from"./SelectField-Bcp-L6wk.js";import{n as b,t as x}from"./useSettingsStyles-Bugi6oTj.js";import{t as S}from"./EditItemView-BPUZddYO.js";var C=e(t(),1),w=n(),T=()=>{let{classes:e}=x(),t=_(),[n,T]=(0,C.useState)(),E=g(e=>e.startsWith(`alarm`)).map(e=>({key:p(`alarm`,e),name:t(e)})),D=h(async()=>{await Promise.all(n.notificators.split(/[, ]+/).map(async e=>{await v(`/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)(s,{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(m(`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(m(`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)(d,{variant:`outlined`,color:`primary`,onClick:D,disabled:!n.notificators,children:t(`sharedTestNotificators`)}),(0,w.jsx)(u,{children:(0,w.jsx)(l,{control:(0,w.jsx)(f,{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)(s,{variant:`subtitle1`,children:t(`sharedExtra`)})}),(0,w.jsxs)(a,{className:e.details,children:[(0,w.jsx)(c,{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)(l,{control:(0,w.jsx)(f,{checked:n.attributes&&n.attributes.priority,onChange:e=>T({...n,attributes:{...n.attributes,priority:e.target.checked}})}),label:t(`sharedPriority`)})})]})]})]})})};export{T as default};