import{i as e}from"./chunk-aKtaBQYM.js";import{Vt as t,wt as n,zt as r}from"./mui-B6lh3XSP.js";import{t as i}from"./Autocomplete-BugREI_2.js";import{t as a}from"./TextField-DOdnjCrL.js";import{O as o,Qt as s,Wt as c,pt as l,tt as u,w as d,yt as f}from"./index-KVuxnkWj.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=n(),g=({deviceId:e,item:t,setItem:n,includeSaved:g=!1,savedId:_,setSavedId:v})=>{let y=f(),b=o(`limitCommands`),x=r(e=>e.session.server.textEnabled),S=m(y),[C,w]=(0,p.useState)([]),[T,E]=(0,p.useState)([]);return l(async({signal:t})=>{if(g){let n=(await(await d(`/api/commands/send?deviceId=${e}`,{signal:t})).json()).map(e=>({...e,optionType:`saved`,key:`saved-${e.id}`}));if(!b){let r=await(await d(`/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 d(`/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(u(`command`,e.type)),renderOption:(e,t)=>(0,h.jsx)(`li`,{...e,children:t.optionType===`saved`?t.description:y(u(`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,r)=>{if(r?.optionType===`saved`)v?.(r.id),n({});else if(r?.type){v?.(0);let e={};S[r.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}}),n({...t,type:r.type,attributes:e})}},renderInput:e=>(0,h.jsx)(a,{...e,label:y(`sharedType`)})}),(!g||!_)&&C.map(({key:e,name:r,type:i})=>i===`boolean`?(0,h.jsx)(c,{control:(0,h.jsx)(s,{checked:t.attributes[e],onChange:r=>{let i={...t,attributes:{...t.attributes}};i.attributes[e]=r.target.checked,n(i)}}),label:r},e):(0,h.jsx)(a,{type:i===`number`?`number`:`text`,value:t.attributes[e],onChange:r=>{let a={...t,attributes:{...t.attributes}};a.attributes[e]=i===`number`?Number(r.target.value):r.target.value,n(a)},label:r},e)),x&&(0,h.jsx)(c,{control:(0,h.jsx)(s,{checked:t.textChannel,onChange:e=>n({...t,textChannel:e.target.checked})}),label:y(`commandSendSms`)}),!t.textChannel&&(0,h.jsx)(c,{control:(0,h.jsx)(s,{checked:t.attributes?.noQueue,onChange:e=>n({...t,attributes:{...t?.attributes,noQueue:e.target.checked}})}),label:y(`commandNoQueue`)})]})};export{g as t};