import{i as e}from"./chunk-aKtaBQYM.js";import{Vt as t,wt as n}from"./mui-B6lh3XSP.js";import{d as r}from"./IconButton-BEBOUWhl.js";import{t as i}from"./EditAttributesAccordion-BaG0aySx.js";import{i as a,n as o,r as s,t as c}from"./ExpandMore-BvigPYWL.js";import{t as l}from"./TextField-DOdnjCrL.js";import{t as u}from"./Typography-DfQXhGTT.js";import{D as d,Qt as f,Wt as p,en as m,mt as h,w as g,yt as _}from"./index-KVuxnkWj.js";import{t as v}from"./QrCodeDialog-By4mbTq2.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"./FileInput-DgZJzdHa.js";import{t as C}from"./EditItemView-BNkSnNuu.js";import{t as w}from"./useCommonDeviceAttributes-C4IpCoKu.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=_(),n=d(),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=h(async e=>{if(R(e),e&&N?.id){let t=await g(`/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)(u,{variant:`subtitle1`,children:t(`sharedRequired`)})}),(0,O.jsxs)(s,{className:e.details,children:[(0,O.jsx)(l,{value:N.name||``,onChange:e=>P({...N,name:e.target.value}),label:t(`sharedName`)}),(0,O.jsx)(l,{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)(u,{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)(l,{value:N.phone||``,onChange:e=>P({...N,phone:e.target.value}),label:t(`sharedPhone`)}),(0,O.jsx)(l,{value:N.model||``,onChange:e=>P({...N,model:e.target.value}),label:t(`deviceModel`)}),(0,O.jsx)(l,{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)(l,{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)(p,{control:(0,O.jsx)(f,{checked:N.disabled,onChange:e=>P({...N,disabled:e.target.checked})}),label:t(`sharedDisabled`),disabled:!n}),(0,O.jsx)(m,{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)(u,{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};