import{i as e}from"./chunk-aKtaBQYM.js";import{Ft as t,Nt as n,vt as r}from"./mui-BgU4WrXF.js";import{t as i}from"./Autocomplete-OJ15wScd.js";import{t as a}from"./TextField-DctlzLY-.js";import{A as o,Ft as s,Vt as c,Y as l,pt as u,st as d,w as f}from"./index-bel1r0Sr.js";var p=e(t(),1),m=e=>(0,p.useMemo)(()=>({custom:[{key:`data`,name:e(`commandData`),type:`string`}],positionPeriodic:[{key:`frequency`,name:e(`commandFrequency`),type:`number`}],setTimezone:[{key:`timezone`,name:e(`commandTimezone`),type:`string`}],sendSms:[{key:`phone`,name:e(`commandPhone`),type:`string`},{key:`message`,name:e(`commandMessage`),type:`string`}],message:[{key:`message`,name:e(`commandMessage`),type:`string`}],sendUssd:[{key:`phone`,name:e(`commandPhone`),type:`string`}],sosNumber:[{key:`index`,name:e(`commandIndex`),type:`number`},{key:`phone`,name:e(`commandPhone`),type:`string`}],silenceTime:[{key:`data`,name:e(`commandData`),type:`string`}],setPhonebook:[{key:`data`,name:e(`commandData`),type:`string`}],voiceMessage:[{key:`data`,name:e(`commandData`),type:`string`}],outputControl:[{key:`index`,name:e(`commandIndex`),type:`number`},{key:`data`,name:e(`commandData`),type:`string`}],voiceMonitoring:[{key:`enable`,name:e(`commandEnable`),type:`boolean`}],setAgps:[{key:`enable`,name:e(`commandEnable`),type:`boolean`}],setIndicator:[{key:`data`,name:e(`commandData`),type:`string`}],configuration:[{key:`data`,name:e(`commandData`),type:`string`}],setConnection:[{key:`server`,name:e(`commandServer`),type:`string`},{key:`port`,name:e(`commandPort`),type:`number`}],setOdometer:[{key:`data`,name:e(`commandData`),type:`string`}],modePowerSaving:[{key:`enable`,name:e(`commandEnable`),type:`boolean`}],modeDeepSleep:[{key:`enable`,name:e(`commandEnable`),type:`boolean`}],alarmGeofence:[{key:`radius`,name:e(`commandRadius`),type:`number`}],alarmBattery:[{key:`enable`,name:e(`commandEnable`),type:`boolean`}],alarmSos:[{key:`enable`,name:e(`commandEnable`),type:`boolean`}],alarmRemove:[{key:`enable`,name:e(`commandEnable`),type:`boolean`}],alarmClock:[{key:`data`,name:e(`commandData`),type:`string`}],alarmSpeed:[{key:`data`,name:e(`commandData`),type:`string`}],alarmFall:[{key:`enable`,name:e(`commandEnable`),type:`boolean`}],alarmVibration:[{key:`data`,name:e(`commandData`),type:`string`}]}),[e]),h=r(),g=({deviceId:e,item:t,setItem:r,includeSaved:g=!1,savedId:_,setSavedId:v})=>{let y=u(),b=o(`limitCommands`),x=n(e=>e.session.server.textEnabled),S=m(y),[C,w]=(0,p.useState)([]),[T,E]=(0,p.useState)([]);return d(async({signal:t})=>{if(g){let n=(await(await f(`/api/commands/send?deviceId=${e}`,{signal:t})).json()).map(e=>({...e,optionType:`saved`,key:`saved-${e.id}`}));if(!b){let r=await(await f(`/api/commands/types?${new URLSearchParams({deviceId:e}).toString()}`,{signal:t})).json();n=n.concat(r.map(e=>({...e,optionType:`type`,key:`type-${e.type}`})))}E(n)}else E((await(await f(`/api/commands/types`,{signal:t})).json()).map(e=>({...e,optionType:`type`,key:`type-${e.type}`})))},[e,g,b]),(0,p.useEffect)(()=>{t&&t.type?w(S[t.type]||[]):w([])},[S,t]),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(i,{size:`small`,options:T,groupBy:g?e=>e.optionType===`saved`?y(`sharedSavedCommands`):y(`sharedType`):null,getOptionLabel:e=>e.optionType===`saved`?e.description:y(l(`command`,e.type)),renderOption:(e,t)=>(0,h.jsx)(`li`,{...e,children:t.optionType===`saved`?t.description:y(l(`command`,t.type))},t.key),isOptionEqualToValue:(e,t)=>e.key===t.key,value:_?T.find(e=>e.optionType===`saved`&&e.id===_)||null:T.find(e=>e.optionType===`type`&&e.type===t.type)||null,onChange:(e,n)=>{if(n?.optionType===`saved`)v?.(n.id),r({});else if(n?.type){v?.(0);let e={};S[n.type]?.forEach(t=>{switch(t.type){case`boolean`:e[t.key]=!1;break;case`number`:e[t.key]=0;break;default:e[t.key]=``;break}}),r({...t,type:n.type,attributes:e})}},renderInput:e=>(0,h.jsx)(a,{...e,label:y(`sharedType`)})}),(!g||!_)&&C.map(({key:e,name:n,type:i})=>i===`boolean`?(0,h.jsx)(s,{control:(0,h.jsx)(c,{checked:t.attributes[e],onChange:n=>{let i={...t,attributes:{...t.attributes}};i.attributes[e]=n.target.checked,r(i)}}),label:n},e):(0,h.jsx)(a,{type:i===`number`?`number`:`text`,value:t.attributes[e],onChange:n=>{let a={...t,attributes:{...t.attributes}};a.attributes[e]=i===`number`?Number(n.target.value):n.target.value,r(a)},label:n},e)),x&&(0,h.jsx)(s,{control:(0,h.jsx)(c,{checked:t.textChannel,onChange:e=>r({...t,textChannel:e.target.checked})}),label:y(`commandSendSms`)}),!t.textChannel&&(0,h.jsx)(s,{control:(0,h.jsx)(c,{checked:t.attributes?.noQueue,onChange:e=>r({...t,attributes:{...t?.attributes,noQueue:e.target.checked}})}),label:y(`commandNoQueue`)})]})};export{g as t};