import{Y as D,a2 as V,u as N,r,j as e,a3 as G,B as v,F as j,a4 as H,a as x,D as f,s as b,L as g,ai as B,ad as y,a_ as J,a$ as C,aY as W,M as K,t as Y,S as $,A as Z,aZ as E}from"./index-DTLwKrFY.js";import{s as Q}from"./snakeCase-48ho8VHI.js";import{O as X,a as ee,A as se,D as te}from"./oui-CsmPme7p.js";import{T as ae}from"./TextareaField-DlAGnMTm.js";import{D as ne}from"./DeviceImage-CmmMipdr.js";import{h as ie}from"./index-yG0-fBDW.js";import{f as oe,b as re}from"./OtaControlGroup-CoW_wL2h.js";import{D as le}from"./DisplayValue-no6ClLSH.js";import{L as ce}from"./LastSeen-_mzTICXk.js";import{M as de,V as me}from"./VendorLink-BZlqzmcf.js";import{P as pe}from"./PowerSource-BtLGM0pk.js";import"./envs-CRUy-_iG.js";import"./_createCompounder-Jh3GrmJ6.js";import"./isObjectLike-BK6keKbA.js";import"./RemoveDeviceModal-BZeBVqD-.js";import"./CheckboxField-C_Qtx-pp.js";import"./InputField-fj8dQezf.js";import"./defineProperty-CegpTSss.js";import"./floating-ui.react-ey6TW0xJ.js";import"./floating-ui.dom-BSrWR8Gl.js";import"./SelectField-Hd9BNgRL.js";import"./TimeAgo-CM34pQ71.js";const be=D.create(({device:a,setDeviceDescription:s})=>{const n=V(),{t:i}=N(["zigbee","common"]),[l,d]=r.useState(a.description||"");return r.useEffect(()=>{d(a.description||"")},[a.description]),r.useEffect(()=>{const o=h=>{h.key==="Escape"&&(h.preventDefault(),n.remove())};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[n]),e.jsx(G,{isOpen:n.visible,title:`${i(o=>o.update_description)} ${a.friendly_name}`,footer:e.jsxs(e.Fragment,{children:[e.jsx(v,{className:"btn btn-neutral",onClick:n.remove,children:i(o=>o.cancel,{ns:"common"})}),e.jsx(v,{className:"btn btn-primary ms-1",onClick:async()=>{n.remove(),await s(a.ieee_address,l)},children:i(o=>o.save_description)})]}),children:e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(ae,{label:i(o=>o.description),name:"update_description",onChange:o=>d(o.target.value),rows:3,value:l})})})}),ue=r.memo(({device:a,setDeviceDescription:s})=>{const{t:n}=N("zigbee");return e.jsx(v,{className:`btn btn-link btn-md ${a.description?"btn-square":""} tooltip-bottom`,onClick:async()=>await D.show(be,{device:a,setDeviceDescription:s}),title:n(i=>i.edit_description),children:a.description?e.jsx(j,{icon:H}):n(i=>i.edit_description)})}),xe=/\[(.*?)]\((.*?)\)/,fe={native:"badge-success",external:"badge-info",generated:"badge-warning"},he=(a,s)=>{if(!(a==="bindings"||a==="configured_reportings"||a==="scenes"))return s},_e=r.memo(({sourceIdx:a,device:s})=>{const{t:n}=N("zigbee"),i=x(f(d=>d.bridgeInfo[a])),l={template:"external_converter.yaml",title:`[External Converter]: ${s.model_id} from ${s.manufacturer}`,z2m_version:`${i.version} (${i.commit})`,notes:`
software_build_id: \`${s.software_build_id}\`
date_code: \`${s.date_code}\`
endpoints:
\`\`\`json
${JSON.stringify(s.endpoints,he)}
\`\`\``};return e.jsx(g,{target:"_blank",rel:"noopener noreferrer",to:`${E}?${new URLSearchParams(l).toString()}`,className:"link link-hover",children:n(d=>d.submit_converter)})}),je=r.memo(({sourceIdx:a,device:s})=>{const{t:n}=N("zigbee"),i=x(f(o=>o.bridgeInfo[a])),l=x(f(o=>o.bridgeHealth[a])),d={template:"problem_report.yaml",title:`[${s.model_id} / ${s.manufacturer}] ???`,z2m_version:`${i.version} (${i.commit})`,adapter_fwversion:JSON.stringify(i.coordinator.meta),adapter:i.coordinator.type,setup:`os: \`${i.os.version}\`
node: \`${i.os.node_version}\`
ha: \`${i.config.homeassistant.enabled}\``,notes:`
#### Device
software_build_id: \`${s.software_build_id}\`
date_code: \`${s.date_code}\`
endpoints:
\`\`\`json
${JSON.stringify(s.endpoints)}
\`\`\``};return l.response_time>0&&(d.notes+=`
##### Health
time: \`${new Date(l.response_time)}\`
os.load_average: \`${l.os.load_average.join(", ")}\`
os.memory_percent: \`${l.os.memory_percent}\`
process.memory_percent: \`${l.process.memory_percent}\`
process.uptime_sec: \`${Math.round(l.process.uptime_sec)}\`
\`\`\`json
${JSON.stringify(l.devices[s.ieee_address]??{})}
\`\`\`
`),e.jsx(g,{target:"_blank",rel:"noopener noreferrer",to:`${E}?${new URLSearchParams(d).toString()}`,className:"btn btn-ghost",children:n(o=>o.report_problem)})});function ze({sourceIdx:a,device:s}){const{t:n}=N(["zigbee","availability","common","ota"]),i=x(f(t=>t.deviceStates[a])),l=x(f(t=>t.bridgeInfo[a].config)),d=x(f(t=>t.availability[a])),o=x(f(t=>t.recentActivity[a])),h=l.homeassistant.enabled,p=i[s.friendly_name]??{},w=o[s.friendly_name],O=r.useMemo(()=>ie(s),[s]),_=r.useMemo(()=>oe(p.update?.installed_version),[p.update?.installed_version]),L=r.useMemo(()=>X.get(s.ieee_address.slice(2,8))??"?",[s.ieee_address]),U=r.useCallback(async(t,c)=>{await b(a,"bridge/request/device/options",{id:t,options:{description:c}})},[a]),k=r.useCallback(async(t,c,m,u)=>{await b(t,"bridge/request/device/rename",{from:c,to:m,homeassistant_rename:u,last:void 0})},[]),M=r.useCallback(async([t,c])=>{await b(t,"bridge/request/device/configure",{id:c})},[]),P=r.useCallback(async([t,c])=>{await b(t,"bridge/request/device/interview",{id:c})},[]),q=r.useCallback(async(t,c,m,u)=>{await b(t,"bridge/request/device/remove",{id:c,force:m,block:u})},[]),A=r.useCallback(async({sourceIdx:t,ieee:c,...m})=>await b(t,"bridge/request/device/ota_update/check",{id:c,...m}),[]),I=r.useCallback(async({sourceIdx:t,ieee:c,downgrade:m,...u})=>await b(t,m?"bridge/request/device/ota_update/update/downgrade":"bridge/request/device/ota_update/update",{id:c,...u}),[]),R=r.useCallback(async({sourceIdx:t,ieee:c,downgrade:m,...u})=>await b(t,m?"bridge/request/device/ota_update/schedule/downgrade":"bridge/request/device/ota_update/schedule",{id:c,...u}),[]),F=r.useCallback(async({sourceIdx:t,ieee:c})=>await b(t,"bridge/request/device/ota_update/unschedule",{id:c}),[]),S=l.devices[s.ieee_address]?.availability,T=r.useMemo(()=>{const t=s.definition?.description?xe.exec(s.definition?.description):void 0;if(t){const[,c,m]=t;return e.jsx(g,{target:"_blank",rel:"noopener noreferrer",to:m,className:"link link-hover",children:c})}return e.jsx(e.Fragment,{children:s.definition?.description})},[s.definition]),z=r.useMemo(()=>{switch(s.interview_state){case y.Pending:return e.jsx(j,{icon:C,className:"text-info"});case y.InProgress:return e.jsx(j,{icon:C,spin:!0,className:"text-info"});case y.Successful:return e.jsx(j,{icon:J,className:"text-success"});default:return e.jsx(j,{icon:B,beat:!0,className:"text-error"})}},[s.interview_state]);return e.jsxs("div",{className:"card lg:card-side bg-base-100",children:[e.jsx("figure",{className:"w-64 h-64",style:{overflow:"visible"},children:e.jsx(ne,{device:s,otaState:p.update?.state,disabled:s.disabled,noIndicator:!0})}),e.jsxs("div",{className:"card-body py-0 px-3",children:[e.jsxs("h2",{className:"card-title",children:[s.friendly_name,e.jsx(ee,{sourceIdx:a,name:s.friendly_name,renameDevice:k,homeassistantEnabled:h,style:"btn-link btn-md btn-square"})]}),e.jsxs("div",{className:"flex flex-row flex-wrap gap-2",children:[e.jsxs("span",{className:`badge ${s.definition?fe[s.definition.source]:""}`,children:[e.jsx(le,{name:"supported",value:s.supported}),s.definition?`: ${s.definition.source}`:""]}),!s.supported&&e.jsx("span",{className:"badge animate-bounce",children:e.jsx(g,{target:"_blank",rel:"noopener noreferrer",to:W,className:"link link-hover",children:n(t=>t.how_to_add_support)})}),s.definition?.source==="external"&&e.jsx("span",{className:"badge animate-bounce",children:e.jsx(_e,{sourceIdx:a,device:s})}),e.jsxs("span",{className:"badge opacity-70 tooltip tooltip-bottom","data-tip":s.interview_state,children:[n(t=>t.interview_state),": ",z]})]}),e.jsxs("div",{children:[e.jsx("pre",{className:"inline text-wrap break-all",children:s.description||""}),e.jsx(ue,{device:s,setDeviceDescription:U})]}),e.jsxs("div",{className:"grid grid-cols-[max-content_1fr] gap-x-3 gap-y-2 text-wrap",children:[e.jsx("div",{className:"font-semibold text-base-content/70",children:n(t=>t.type)}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold",children:s.type}),e.jsxs("p",{className:"text-base-content/50",children:[s.type==="GreenPower"?"GreenPower":n(t=>t[Q(s.power_source)]||t.unknown),e.jsx("span",{className:"ms-3",children:e.jsx(pe,{showLevel:!0,device:s,batteryPercent:p.battery,batteryState:p.battery_state,batteryLow:p.battery_low})})]})]}),e.jsx("div",{className:"font-semibold text-base-content/70",children:n(t=>t.ieee_address)}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold font-mono",children:s.ieee_address}),e.jsx("p",{className:"text-base-content/50",children:e.jsxs("span",{className:"tooltip tooltip-bottom",children:[e.jsxs("span",{className:"tooltip-content",children:["Organizationally Unique Identifier",e.jsx("br",{}),"(IEEE Vendor Prefix)"]}),"OUI: ",L]})})]}),e.jsx("div",{className:"font-semibold text-base-content/70",children:n(t=>t.network_address)}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold",children:e.jsx("span",{className:"tooltip tooltip-bottom","data-tip":n(t=>t.network_address_hex),children:e.jsx("span",{className:"font-mono",children:Y(s.network_address)})})}),e.jsxs("p",{className:"text-base-content/50",children:[n(t=>t.network_address_dec),": ",e.jsx("span",{className:"font-mono",children:s.network_address})]})]}),e.jsx("div",{className:"font-semibold text-base-content/70",children:n(t=>t.zigbee_model)}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold break-all",children:s.model_id}),e.jsx("p",{className:"text-base-content/50",children:s.manufacturer})]}),e.jsx("div",{className:"font-semibold text-base-content/70",children:n(t=>t.model)}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold break-all",children:e.jsx(de,{modelId:s.model_id,supported:s.supported,definitionModel:s.definition?.model,definitionVendor:s.definition?.vendor})}),e.jsxs("p",{className:"text-base-content/50",children:[T," (",e.jsx(me,{supported:s.supported,definitionVendor:s.definition?.vendor}),")"]})]}),s.software_build_id?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"font-semibold text-base-content/70",children:n(t=>t.firmware_id)}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold",children:s.software_build_id||"N/A"}),e.jsx("p",{className:"text-base-content/50",children:s.date_code||"N/A"})]})]}):null,O?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"font-semibold text-base-content/70",children:n(t=>t.firmware_version,{ns:"ota"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"font-semibold",children:[p.update?.installed_version??n(t=>t.unknown),e.jsx("span",{className:"ms-3",children:e.jsx(re,{sourceIdx:a,device:s,otaSettings:l.ota,state:p.update,onCheckClick:A,onUpdateClick:I,onScheduleClick:R,onUnscheduleClick:F})})]}),_?e.jsxs("p",{className:"text-base-content/50",children:[n(t=>t.app,{ns:"ota"}),": ",`${_[0]} build ${_[1]}`," | ",n(t=>t.stack,{ns:"ota"}),": ",`${_[2]} build ${_[3]}`]}):null]})]}):null,e.jsx("div",{className:"font-semibold text-base-content/70",children:n(t=>t.last_seen)}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold",children:e.jsx(ce,{config:l.advanced.last_seen,lastSeen:p.last_seen,fallback:n(t=>t.disabled,{ns:"common"})})}),e.jsxs("p",{className:"text-base-content/50",children:[n(t=>t.availability,{ns:"availability"}),": ",e.jsx(se,{availability:d[s.friendly_name]?.state??"offline",disabled:s.disabled,availabilityFeatureEnabled:l.availability.enabled,availabilityEnabledForDevice:S!=null?!!S:void 0})]})]}),w&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"font-semibold text-base-content/70",children:n(t=>t.recent_activity,{ns:"common"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"font-semibold break-all",children:[e.jsx($,{idx:a,autoHide:!0}),w.desc]}),e.jsx("p",{className:"text-base-content/50",children:new Date(w.timestamp).toLocaleString()})]})]}),e.jsx("div",{className:"font-semibold text-base-content/70",children:"MQTT"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"font-semibold break-all",children:[l.mqtt.base_topic,"/",s.friendly_name]}),e.jsx("p",{className:"text-base-content/0",children:"-"})]}),K&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"font-semibold text-base-content/70",children:n(t=>t.source,{ns:"common"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold",children:e.jsx($,{idx:a,alwaysShowName:!0})}),e.jsx("p",{className:"text-base-content/50",children:Z[a]})]})]})]}),e.jsxs("div",{className:"card-actions justify-center md:justify-end mt-2 me-4",children:[e.jsx(je,{sourceIdx:a,device:s}),e.jsx(te,{sourceIdx:a,device:s,otaState:p.update?.state,homeassistantEnabled:h,renameDevice:k,configureDevice:M,interviewDevice:P,removeDevice:q})]})]})]})}export{ze as default};
