import{i as e}from"./chunk-aKtaBQYM.js";import{Ft as t,vt as n}from"./mui-BgU4WrXF.js";import{d as r}from"./IconButton-oialqkv3.js";import{t as i}from"./EditAttributesAccordion-J3XCwwrK.js";import{i as a,n as o,r as s,t as c}from"./ExpandMore-D0ycvrdR.js";import{t as l}from"./Typography-7EcQ2i3p.js";import{t as u}from"./TextField-DctlzLY-.js";import{Ft as d,Ut as f,Vt as p,ct as m,k as h,pt as g,w as _}from"./index-bel1r0Sr.js";import{t as v}from"./QrCodeDialog-DHpBbH0W.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"./FileInput-C3yEGmbG.js";import{t as C}from"./EditItemView-BPUZddYO.js";import{t as w}from"./useCommonDeviceAttributes-jzyUxblM.js";var T=e(t(),1),E=[`default`,`animal`,`bicycle`,`boat`,`bus`,`car`,`camper`,`crane`,`helicopter`,`motorcycle`,`person`,`plane`,`ship`,`tractor`,`trailer`,`train`,`tram`,`truck`,`van`,`scooter`],D=e=>(0,T.useMemo)(()=>({"command.sender":{name:e(`deviceCommandSender`),type:`string`},"web.reportColor":{name:e(`attributeWebReportColor`),type:`string`,dataType:`color`},devicePassword:{name:e(`attributeDevicePassword`),type:`string`},deviceImage:{name:e(`attributeDeviceImage`),type:`string`},"processing.copyAttributes":{name:e(`attributeProcessingCopyAttributes`),type:`string`},"decoder.timezone":{name:e(`sharedTimezone`),type:`string`},"forward.url":{name:e(`attributeForwardUrl`),type:`string`}}),[e]),O=n(),k=()=>{let{classes:e}=x(),t=g(),n=h(),k=w(t),A=D(t),[j]=r(),M=j.get(`uniqueId`),[N,P]=(0,T.useState)(M?{uniqueId:M}:null),[F,I]=(0,T.useState)(!1),[L,R]=(0,T.useState)(null),z=m(async e=>{if(R(e),e&&N?.id){let t=await _(`/api/devices/${N.id}/image`,{method:`POST`,body:e});P({...N,attributes:{...N.attributes,deviceImage:await t.text()}})}else if(!e){let{deviceImage:e,...t}=N.attributes||{};P({...N,attributes:t})}});return(0,O.jsxs)(C,{endpoint:`devices`,item:N,setItem:P,validate:()=>N&&N.name&&N.uniqueId,menu:(0,O.jsx)(b,{}),breadcrumbs:[`settingsTitle`,`sharedDevice`],children:[N&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(a,{defaultExpanded:!0,children:[(0,O.jsx)(o,{expandIcon:(0,O.jsx)(c,{}),children:(0,O.jsx)(l,{variant:`subtitle1`,children:t(`sharedRequired`)})}),(0,O.jsxs)(s,{className:e.details,children:[(0,O.jsx)(u,{value:N.name||``,onChange:e=>P({...N,name:e.target.value}),label:t(`sharedName`)}),(0,O.jsx)(u,{value:N.uniqueId||``,onChange:e=>P({...N,uniqueId:e.target.value}),label:t(`deviceIdentifier`),helperText:t(`deviceIdentifierHelp`),disabled:!!M})]})]}),(0,O.jsxs)(a,{children:[(0,O.jsx)(o,{expandIcon:(0,O.jsx)(c,{}),children:(0,O.jsx)(l,{variant:`subtitle1`,children:t(`sharedExtra`)})}),(0,O.jsxs)(s,{className:e.details,children:[(0,O.jsx)(y,{value:N.groupId,onChange:e=>P({...N,groupId:Number(e.target.value)}),endpoint:`/api/groups`,label:t(`groupParent`)}),(0,O.jsx)(u,{value:N.phone||``,onChange:e=>P({...N,phone:e.target.value}),label:t(`sharedPhone`)}),(0,O.jsx)(u,{value:N.model||``,onChange:e=>P({...N,model:e.target.value}),label:t(`deviceModel`)}),(0,O.jsx)(u,{value:N.contact||``,onChange:e=>P({...N,contact:e.target.value}),label:t(`deviceContact`)}),(0,O.jsx)(y,{value:N.category||`default`,onChange:e=>P({...N,category:e.target.value}),data:E.map(e=>({id:e,name:t(`category${e.replace(/^\w/,e=>e.toUpperCase())}`)})).sort((e,t)=>e.name.localeCompare(t.name)),label:t(`deviceCategory`)}),(0,O.jsx)(y,{value:N.calendarId,onChange:e=>P({...N,calendarId:Number(e.target.value)}),endpoint:`/api/calendars`,label:t(`sharedCalendar`)}),(0,O.jsx)(u,{label:t(`userExpirationTime`),type:`date`,value:N.expirationTime?N.expirationTime.split(`T`)[0]:`2099-01-01`,onChange:e=>{e.target.value&&P({...N,expirationTime:new Date(e.target.value).toISOString()})},disabled:!n}),(0,O.jsx)(d,{control:(0,O.jsx)(p,{checked:N.disabled,onChange:e=>P({...N,disabled:e.target.checked})}),label:t(`sharedDisabled`),disabled:!n}),(0,O.jsx)(f,{variant:`outlined`,color:`primary`,onClick:()=>I(!0),children:t(`sharedQrCode`)})]})]}),N.id&&(0,O.jsxs)(a,{children:[(0,O.jsx)(o,{expandIcon:(0,O.jsx)(c,{}),children:(0,O.jsx)(l,{variant:`subtitle1`,children:t(`attributeDeviceImage`)})}),(0,O.jsx)(s,{className:e.details,children:(0,O.jsx)(S,{placeholder:t(`attributeDeviceImage`),value:L,onChange:z,slotProps:{htmlInput:{accept:`image/*`}}})})]}),(0,O.jsx)(i,{attributes:N.attributes,setAttributes:e=>P({...N,attributes:e}),definitions:{...k,...A}})]}),(0,O.jsx)(v,{open:F,onClose:()=>I(!1)})]})};export{k as default};