import{i as e}from"./chunk-aKtaBQYM.js";import{Ft as t,vt as n}from"./mui-BgU4WrXF.js";import{a as r,r as i,t as a}from"./Select-Bu2vmaew.js";import{i as o,n as s,r as c,t as l}from"./ExpandMore-D0ycvrdR.js";import{t as u}from"./Typography-7EcQ2i3p.js";import{r as d,t as f}from"./Autocomplete-OJ15wScd.js";import{t as p}from"./TextField-DctlzLY-.js";import{Dt as m,Et as h,Ut as g,ct as _,l as v,pt as y,w as b}from"./index-bel1r0Sr.js";import{t as x}from"./SelectField-Bcp-L6wk.js";import{n as S,t as C}from"./useSettingsStyles-Bugi6oTj.js";import{t as w}from"./EditItemView-BPUZddYO.js";var T=e(t(),1),E=n(),D=[`valid`,`latitude`,`longitude`,`altitude`,`speed`,`course`,`address`,`accuracy`],O=()=>{let{classes:e}=C(),t=y(),n=v(t),[O,k]=(0,T.useState)(),[A,j]=(0,T.useState)(),[M,N]=(0,T.useState)(),P=Object.entries(n).filter(([e,t])=>!t.property||D.includes(e)).map(([e,t])=>({key:e,name:t.name,type:t.type})),F=d({stringify:e=>e.name}),I=_(async()=>{N(await(await b(`/api/attributes/computed/test?${new URLSearchParams({deviceId:A}).toString()}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(O)})).text())});return(0,E.jsx)(w,{endpoint:`attributes/computed`,item:O,setItem:k,validate:()=>O&&O.description&&O.expression,menu:(0,E.jsx)(S,{}),breadcrumbs:[`settingsTitle`,`sharedComputedAttribute`],children:O&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(o,{defaultExpanded:!0,children:[(0,E.jsx)(s,{expandIcon:(0,E.jsx)(l,{}),children:(0,E.jsx)(u,{variant:`subtitle1`,children:t(`sharedRequired`)})}),(0,E.jsxs)(c,{className:e.details,children:[(0,E.jsx)(p,{value:O.description||``,onChange:e=>k({...O,description:e.target.value}),label:t(`sharedDescription`)}),(0,E.jsx)(f,{freeSolo:!0,value:P.find(e=>e.key===O.attribute)||O.attribute||null,onChange:(e,t)=>{let n=t?t.key||t.inputValue||t:null;t&&(t.type||t.inputValue)?k({...O,attribute:n,type:t.type}):k({...O,attribute:n})},filterOptions:(e,n)=>{let r=F(e,n);return n.inputValue&&!e.some(e=>(typeof e==`object`?e.key:e)===n.inputValue)&&r.push({inputValue:n.inputValue,name:`${t(`sharedAdd`)} "${n.inputValue}"`}),r},options:P,getOptionLabel:e=>typeof e==`object`?e.inputValue||e.name:e,renderOption:(e,t)=>(0,E.jsx)(`li`,{...e,children:t.name||t}),renderInput:e=>(0,E.jsx)(p,{...e,label:t(`sharedAttribute`)})}),(0,E.jsx)(p,{value:O.expression||``,onChange:e=>k({...O,expression:e.target.value}),label:t(`sharedExpression`),multiline:!0,rows:4}),(0,E.jsxs)(r,{disabled:O.attribute in n,children:[(0,E.jsx)(i,{children:t(`sharedType`)}),(0,E.jsxs)(a,{label:t(`sharedType`),value:O.type||``,onChange:e=>k({...O,type:e.target.value}),children:[(0,E.jsx)(m,{value:`string`,children:t(`sharedTypeString`)}),(0,E.jsx)(m,{value:`number`,children:t(`sharedTypeNumber`)}),(0,E.jsx)(m,{value:`boolean`,children:t(`sharedTypeBoolean`)})]})]})]})]}),(0,E.jsxs)(o,{children:[(0,E.jsx)(s,{expandIcon:(0,E.jsx)(l,{}),children:(0,E.jsx)(u,{variant:`subtitle1`,children:t(`sharedExtra`)})}),(0,E.jsx)(c,{className:e.details,children:(0,E.jsx)(p,{type:`number`,value:O.priority||0,onChange:e=>k({...O,priority:Number(e.target.value)}),label:t(`sharedPriority`)})})]}),(0,E.jsxs)(o,{children:[(0,E.jsx)(s,{expandIcon:(0,E.jsx)(l,{}),children:(0,E.jsx)(u,{variant:`subtitle1`,children:t(`sharedTest`)})}),(0,E.jsxs)(c,{className:e.details,children:[(0,E.jsx)(x,{value:A,onChange:e=>j(Number(e.target.value)),endpoint:`/api/devices`,label:t(`sharedDevice`)}),(0,E.jsx)(g,{variant:`outlined`,color:`primary`,onClick:I,disabled:!A,children:t(`sharedTestExpression`)}),(0,E.jsx)(h,{open:!!M,onClose:()=>N(null),autoHideDuration:2750,message:M})]})]})]})})};export{O as default};