import{i as e}from"./chunk-aKtaBQYM.js";import{Vt as t,wt as n}from"./mui-B6lh3XSP.js";import{i as r,n as i,r as a,t as o}from"./ExpandMore-BvigPYWL.js";import{r as s,t as c}from"./Autocomplete-BugREI_2.js";import{t as l}from"./TextField-DOdnjCrL.js";import{t as u}from"./Typography-DfQXhGTT.js";import{Bt as d,Ft as f,Gt as p,Mt as m,Nt as h,en as g,l as _,mt as v,w as y,yt as b}from"./index-KVuxnkWj.js";import{t as x}from"./SelectField-9K8NpSQG.js";import{n as S,t as C}from"./useSettingsStyles-X3caKosH.js";import{t as w}from"./EditItemView-BNkSnNuu.js";var T=e(t(),1),E=n(),D=[`valid`,`latitude`,`longitude`,`altitude`,`speed`,`course`,`address`,`accuracy`],O=()=>{let{classes:e}=C(),t=b(),n=_(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=s({stringify:e=>e.name}),I=v(async()=>{N(await(await y(`/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)(r,{defaultExpanded:!0,children:[(0,E.jsx)(i,{expandIcon:(0,E.jsx)(o,{}),children:(0,E.jsx)(u,{variant:`subtitle1`,children:t(`sharedRequired`)})}),(0,E.jsxs)(a,{className:e.details,children:[(0,E.jsx)(l,{value:O.description||``,onChange:e=>k({...O,description:e.target.value}),label:t(`sharedDescription`)}),(0,E.jsx)(c,{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)(l,{...e,label:t(`sharedAttribute`)})}),(0,E.jsx)(l,{value:O.expression||``,onChange:e=>k({...O,expression:e.target.value}),label:t(`sharedExpression`),multiline:!0,rows:4}),(0,E.jsxs)(p,{disabled:O.attribute in n,children:[(0,E.jsx)(d,{children:t(`sharedType`)}),(0,E.jsxs)(h,{label:t(`sharedType`),value:O.type||``,onChange:e=>k({...O,type:e.target.value}),children:[(0,E.jsx)(f,{value:`string`,children:t(`sharedTypeString`)}),(0,E.jsx)(f,{value:`number`,children:t(`sharedTypeNumber`)}),(0,E.jsx)(f,{value:`boolean`,children:t(`sharedTypeBoolean`)})]})]})]})]}),(0,E.jsxs)(r,{children:[(0,E.jsx)(i,{expandIcon:(0,E.jsx)(o,{}),children:(0,E.jsx)(u,{variant:`subtitle1`,children:t(`sharedExtra`)})}),(0,E.jsx)(a,{className:e.details,children:(0,E.jsx)(l,{type:`number`,value:O.priority||0,onChange:e=>k({...O,priority:Number(e.target.value)}),label:t(`sharedPriority`)})})]}),(0,E.jsxs)(r,{children:[(0,E.jsx)(i,{expandIcon:(0,E.jsx)(o,{}),children:(0,E.jsx)(u,{variant:`subtitle1`,children:t(`sharedTest`)})}),(0,E.jsxs)(a,{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)(m,{open:!!M,onClose:()=>N(null),autoHideDuration:2750,message:M})]})]})]})})};export{O as default};