import{Y as D,a3 as A,u as _,r as l,j as e,a4 as z,B as w,F as v,a5 as O,a as m,E as p,s as u,L as j,ai as T,aV as g,aW as q,aX as S,aT as F,t as G,S as $,M as H,A as I,aU as E}from"./index-ClCsMWbS.js";import{s as V}from"./snakeCase-D0nOJtgb.js";import{a as B,A as J,D as W}from"./Availability-CvHBs7oh.js";import{T as K}from"./TextareaField-BeRpIFjo.js";import{D as X}from"./DeviceImage-Bs0M9j-k.js";import{D as Q}from"./DisplayValue-qZ7xyN8v.js";import{L as Y}from"./LastSeen-BOY7jIoe.js";import{M as Z,V as ee}from"./VendorLink-C93xowAR.js";import{P as se}from"./PowerSource--PK2quZc.js";import"./envs-CSqIi4cL.js";import"./_createCompounder-CDQ_1ElC.js";import"./isObjectLike-D4auEUP9.js";import"./RemoveDeviceModal-Dcccpw6_.js";import"./CheckboxField-BxtT6ttj.js";import"./InputField-CqTVHKf8.js";import"./index-C8QGyin-.js";import"./TimeAgo-55eetS_D.js";const te=D.create(({device:a,setDeviceDescription:s})=>{const i=A(),{t:n}=_(["zigbee","common"]),[o,c]=l.useState(a.description||"");return l.useEffect(()=>{c(a.description||"")},[a.description]),l.useEffect(()=>{const r=b=>{b.key==="Escape"&&(b.preventDefault(),i.remove())};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[i]),e.jsx(z,{isOpen:i.visible,title:`${n(r=>r.update_description)} ${a.friendly_name}`,footer:e.jsxs(e.Fragment,{children:[e.jsx(w,{className:"btn btn-neutral",onClick:i.remove,children:n(r=>r.cancel,{ns:"common"})}),e.jsx(w,{className:"btn btn-primary ms-1",onClick:async()=>{i.remove(),await s(a.ieee_address,o)},children:n(r=>r.save_description)})]}),children:e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(K,{label:n(r=>r.description),name:"update_description",onChange:r=>c(r.target.value),rows:3,value:o})})})}),ae=l.memo(({device:a,setDeviceDescription:s})=>{const{t:i}=_("zigbee");return e.jsx(w,{className:`btn btn-link btn-sm${a.description?" btn-square":""} tooltip-bottom`,onClick:async()=>await D.show(te,{device:a,setDeviceDescription:s}),title:i(n=>n.edit_description),children:a.description?e.jsx(v,{icon:O}):i(n=>n.edit_description)})}),ie=/\[(.*?)]\((.*?)\)/,ne={native:"badge-success",external:"badge-info",generated:"badge-warning"},re=(a,s)=>{if(!(a==="bindings"||a==="configured_reportings"||a==="scenes"))return s},oe=l.memo(({sourceIdx:a,device:s})=>{const{t:i}=_("zigbee"),n=m(p(c=>c.bridgeInfo[a])),o={template:"external_converter.yaml",title:`[External Converter]: ${s.model_id} from ${s.manufacturer}`,z2m_version:`${n.version} (${n.commit})`,notes:`
software_build_id: \`${s.software_build_id}\`
date_code: \`${s.date_code}\`
endpoints:
\`\`\`json
${JSON.stringify(s.endpoints,re)}
\`\`\``};return e.jsx(j,{target:"_blank",rel:"noopener noreferrer",to:`${E}?${new URLSearchParams(o).toString()}`,className:"link link-hover",children:i(c=>c.submit_converter)})}),le=l.memo(({sourceIdx:a,device:s})=>{const{t:i}=_("zigbee"),n=m(p(r=>r.bridgeInfo[a])),o=m(p(r=>r.bridgeHealth[a])),c={template:"problem_report.yaml",title:`[${s.model_id} / ${s.manufacturer}] ???`,z2m_version:`${n.version} (${n.commit})`,adapter_fwversion:JSON.stringify(n.coordinator.meta),adapter:n.coordinator.type,setup:`os: \`${n.os.version}\`
node: \`${n.os.node_version}\`
ha: \`${n.config.homeassistant.enabled}\``,notes:`
#### Device
software_build_id: \`${s.software_build_id}\`
date_code: \`${s.date_code}\`
endpoints:
\`\`\`json
${JSON.stringify(s.endpoints)}
\`\`\``};return o.response_time>0&&(c.notes+=`
##### Health
time: \`${new Date(o.response_time)}\`
os.load_average: \`${o.os.load_average.join(", ")}\`
os.memory_percent: \`${o.os.memory_percent}\`
process.memory_percent: \`${o.process.memory_percent}\`
process.uptime_sec: \`${Math.round(o.process.uptime_sec)}\`
\`\`\`json
${JSON.stringify(o.devices[s.ieee_address]??{})}
\`\`\`
`),e.jsx(j,{target:"_blank",rel:"noopener noreferrer",to:`${E}?${new URLSearchParams(c).toString()}`,className:"btn btn-ghost",children:i(r=>r.report_problem)})});function Se({sourceIdx:a,device:s}){const{t:i}=_(["zigbee","availability","common"]),n=m(p(t=>t.deviceStates[a])),o=m(p(t=>t.bridgeInfo[a].config)),c=m(p(t=>t.availability[a])),r=m(p(t=>t.recentActivity[a])),b=o.homeassistant.enabled,x=n[s.friendly_name]??{},f=r[s.friendly_name],C=l.useCallback(async(t,d)=>{await u(a,"bridge/request/device/options",{id:t,options:{description:d}})},[a]),y=l.useCallback(async(t,d,h,N)=>{await u(t,"bridge/request/device/rename",{from:d,to:h,homeassistant_rename:N,last:void 0})},[]),L=l.useCallback(async([t,d])=>{await u(t,"bridge/request/device/configure",{id:d})},[]),M=l.useCallback(async([t,d])=>{await u(t,"bridge/request/device/interview",{id:d})},[]),P=l.useCallback(async(t,d,h,N)=>{await u(t,"bridge/request/device/remove",{id:d,force:h,block:N})},[]),k=o.devices[s.ieee_address]?.availability,U=l.useMemo(()=>{const t=s.definition?.description?ie.exec(s.definition?.description):void 0;if(t){const[,d,h]=t;return e.jsx(j,{target:"_blank",rel:"noopener noreferrer",to:h,className:"link link-hover",children:d})}return e.jsx(e.Fragment,{children:s.definition?.description})},[s.definition]),R=l.useMemo(()=>{switch(s.interview_state){case g.Pending:return e.jsx(v,{icon:S,className:"text-info"});case g.InProgress:return e.jsx(v,{icon:S,spin:!0,className:"text-info"});case g.Successful:return e.jsx(v,{icon:q,className:"text-success"});default:return e.jsx(v,{icon:T,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(X,{device:s,otaState:x.update?.state,disabled:s.disabled})}),e.jsxs("div",{className:"card-body",children:[e.jsxs("h2",{className:"card-title",children:[s.friendly_name,e.jsx(B,{sourceIdx:a,name:s.friendly_name,renameDevice:y,homeassistantEnabled:b,style:"btn-link btn-sm btn-square"})]}),e.jsxs("div",{className:"flex flex-row flex-wrap gap-2",children:[e.jsxs("span",{className:`badge ${s.definition?ne[s.definition.source]:""}`,children:[e.jsx(Q,{name:"supported",value:s.supported}),s.definition?`: ${s.definition.source}`:""]}),!s.supported&&e.jsx("span",{className:"badge animate-bounce",children:e.jsx(j,{target:"_blank",rel:"noopener noreferrer",to:F,className:"link link-hover",children:i(t=>t.how_to_add_support)})}),s.definition?.source==="external"&&e.jsx("span",{className:"badge animate-bounce",children:e.jsx(oe,{sourceIdx:a,device:s})}),e.jsxs("span",{className:"badge opacity-70 tooltip tooltip-bottom","data-tip":s.interview_state,children:[i(t=>t.interview_state),": ",R]})]}),e.jsxs("div",{children:[e.jsx("pre",{className:"inline text-wrap break-all",children:s.description||""}),e.jsx(ae,{device:s,setDeviceDescription:C})]}),e.jsxs("div",{className:"stats stats-vertical lg:stats-horizontal shadow",children:[e.jsxs("div",{className:"stat px-3",children:[e.jsx("div",{className:"stat-title",children:s.type}),e.jsx("div",{className:"stat-value text-xl tooltip tooltip-bottom","data-tip":i(t=>t.ieee_address),children:s.ieee_address}),e.jsx("div",{className:"stat-desc text-base-content/0",children:"-"})]}),e.jsxs("div",{className:"stat px-3",children:[e.jsx("div",{className:"stat-title",children:i(t=>t.network_address)}),e.jsx("div",{className:"stat-value text-xl tooltip tooltip-bottom","data-tip":i(t=>t.network_address_hex),children:G(s.network_address)}),e.jsxs("div",{className:"stat-desc",children:[i(t=>t.network_address_dec),": ",s.network_address]})]}),e.jsxs("div",{className:"stat px-3",children:[e.jsx("div",{className:"stat-title",children:i(t=>t.power)}),e.jsx("div",{className:"stat-value text-xl",children:e.jsx(se,{showLevel:!0,device:s,batteryPercent:x.battery,batteryState:x.battery_state,batteryLow:x.battery_low})}),e.jsx("div",{className:"stat-desc",children:s.type==="GreenPower"?"GreenPower":i(t=>t[V(s.power_source)]||t.unknown)})]})]}),e.jsxs("div",{className:"stats stats-vertical lg:stats-horizontal shadow",children:[e.jsxs("div",{className:"stat px-3",children:[e.jsx("div",{className:"stat-title",children:i(t=>t.zigbee_model)}),e.jsx("div",{className:"stat-value text-xl",children:s.model_id}),e.jsxs("div",{className:"stat-desc",children:[s.manufacturer," (",U,")"]})]}),e.jsxs("div",{className:"stat px-3",children:[e.jsx("div",{className:"stat-title",children:i(t=>t.model)}),e.jsx("div",{className:"stat-value text-xl",children:e.jsx(Z,{device:s})}),e.jsx("div",{className:"stat-desc",children:e.jsx(ee,{device:s})})]}),e.jsxs("div",{className:"stat px-3",children:[e.jsx("div",{className:"stat-title",children:i(t=>t.firmware_id)}),e.jsx("div",{className:"stat-value text-xl",children:s.software_build_id||i(t=>t.unknown)}),e.jsx("div",{className:"stat-desc",children:s.date_code||i(t=>t.unknown)})]})]}),e.jsxs("div",{className:"stats stats-vertical lg:stats-horizontal shadow",children:[e.jsxs("div",{className:"stat px-3",children:[e.jsx("div",{className:"stat-title",children:i(t=>t.last_seen)}),e.jsx("div",{className:"stat-value text-xl",children:e.jsx(Y,{config:o.advanced.last_seen,lastSeen:x.last_seen})}),e.jsxs("div",{className:"stat-desc",children:[i(t=>t.availability,{ns:"availability"}),": ",e.jsx(J,{availability:c[s.friendly_name]?.state??"offline",disabled:s.disabled,availabilityFeatureEnabled:o.availability.enabled,availabilityEnabledForDevice:k!=null?!!k:void 0})]})]}),f&&e.jsxs("div",{className:"stat px-3 min-w-0",children:[e.jsx("div",{className:"stat-title",children:i(t=>t.recent_activity,{ns:"common"})}),e.jsxs("div",{className:"stat-value text-xl truncate",children:[e.jsx($,{idx:a,autoHide:!0}),f.desc]}),e.jsx("div",{className:"stat-desc",children:new Date(f.timestamp).toLocaleString()})]})]}),e.jsxs("div",{className:"stats stats-vertical lg:stats-horizontal shadow",children:[e.jsxs("div",{className:"stat px-3",children:[e.jsx("div",{className:"stat-title",children:"MQTT"}),e.jsxs("div",{className:"stat-value text-xl",children:[o.mqtt.base_topic,"/",s.friendly_name]}),e.jsx("div",{className:"stat-desc text-base-content/0",children:"-"})]}),H&&e.jsxs("div",{className:"stat px-3",children:[e.jsx("div",{className:"stat-title",children:i(t=>t.source,{ns:"common"})}),e.jsx("div",{className:"stat-value text-xl",children:e.jsx($,{idx:a,alwaysShowName:!0})}),e.jsx("div",{className:"stat-desc",children:I[a]})]})]}),e.jsxs("div",{className:"card-actions justify-end mt-2",children:[e.jsx(le,{sourceIdx:a,device:s}),e.jsx(W,{sourceIdx:a,device:s,otaState:x.update?.state,homeassistantEnabled:b,renameDevice:y,configureDevice:L,interviewDevice:M,removeDevice:P})]})]})]})}export{Se as default};
