import{aJ as w,u as p,j as t,b,l as d,v as j,r as N}from"./index-42f456b7.js";import{p as m}from"./powerSourceTypeToTranslationKey-452dac81.js";var g=[60,60,24,7,365/7/12,12];function x(e){return e instanceof Date?e:!isNaN(e)||/^\d+$/.test(e)?new Date(parseInt(e)):(e=(e||"").trim().replace(/\.\d+/,"").replace(/-/,"/").replace(/-/,"/").replace(/(\d)T(\d)/,"$1 $2").replace(/Z/," UTC").replace(/([+-]\d\d):?(\d\d)/," $1$2"),new Date(e))}function _(e,a){var s=e<0?1:0;e=Math.abs(e);for(var r=e,n=0;e>=g[n]&&n<g.length;n++)e/=g[n];return e=Math.floor(e),n*=2,e>(n===0?9:1)&&(n+=1),a(e,n,r)[s].replace("%s",e.toString())}function k(e,a){var s=a?x(a):new Date;return(+s-+x(e))/1e3}var D=function(e,a,s){var r=k(e,s&&s.relativeDate);return _(r,w(a))};function M(e){const{value:a,name:s}=e,{t:r}=p("values"),n={contact:new Map([[!0,r("closed")],[!1,r("open")]]),occupancy:new Map([[!0,r("occupied")],[!1,r("clear")]]),water_leak:new Map([[!0,t.jsx("span",{className:b("text-danger","animation-blinking"),children:r("leaking")},"Leaking")],[!1,r("clear")]]),tamper:new Map([[!0,t.jsx("span",{className:b("text-danger","animation-blinking"),children:r("tampered")},"tampered")],[!1,r("clear")]]),supported:new Map([[!0,r("supported")],[!1,r("not_supported")]]),_default:new Map([[!0,r("true")],[!1,r("false")]])},i=n[s]||n._default;return t.jsx(t.Fragment,{children:i.get(a)})}function E(e){const{t:a}=p("values"),{value:s}=e;switch(typeof s){case"boolean":return t.jsx(M,{...e});case"undefined":return t.jsx(t.Fragment,{children:"N/A"});case"object":return t.jsx(t.Fragment,{children:s===null?a("null"):JSON.stringify(s)});case"string":return t.jsx(t.Fragment,{children:s===""?t.jsx("small",{className:"text-muted",children:a("empty_string")}):s});default:return t.jsx(t.Fragment,{children:JSON.stringify(s)})}}function P(e){const{i18n:a}=p(),{state:s,lastSeenType:r}=e,n=d(s,r);return n?t.jsx("span",{title:j(n),children:D(n,a.language)}):t.jsx(t.Fragment,{children:"N/A"})}const $="_plug_1sba2_1",h={plug:$},F=({device:e,deviceState:a,showLevel:s,...r})=>{const{t:n}=p("zigbee");let i;switch(e!==void 0&&(i=e.power_source),i){case"Battery":let y=n(m(i)),c="",l="fa-question",o,f,u;if(a!==void 0&&((a==null?void 0:a.battery)!==void 0&&(o=a.battery),(a==null?void 0:a.battery_state)!==void 0&&(f=a.battery_state),(a==null?void 0:a.battery_low)!==void 0&&(u=a.battery_low)),o!==void 0)if(c=o+"%",o>=85)l="fa-battery-full";else if(o>=65)l="fa-battery-three-quarters";else if(o>=40)l="fa-battery-half";else if(o>=20)l="fa-battery-quarter";else if(o>=10)l="fa-battery-empty animation-blinking";else return t.jsxs("span",{className:"animation-blinking text-danger",role:"alert",children:[o,"%"]});else if(f!==void 0)switch(c=f,f){case"high":l="fa-battery-full";break;case"medium":l="fa-battery-half";break;case"low":l="fa-battery-empty animation-blinking";break}else u!==void 0&&(c=u?"LOW":"OK",l=u?"fa-battery-empty":"fa-battery-full");return u===!0&&(l+=" animation-blinking text-danger"),c!==""&&(y+=", "+n("power_level")+`: ${c}`),t.jsxs(N.Fragment,{children:[s?t.jsxs("span",{className:"pe-2",children:[n("battery")," ",c]}):null,t.jsx("i",{className:`fa ${l}`,title:y,...r})]});case"Mains (single phase)":case"Mains (3 phase)":case"DC Source":return t.jsx("i",{className:`fa fa-plug ${h.plug}`,title:n(m(i)),...r});case"Emergency mains and transfer switch":case"Emergency mains constantly powered":return t.jsx("i",{className:`fa fa-plug-circle-exclamation ${h.plug}`,title:n(m(i)),...r});default:return(e==null?void 0:e.type)==="GreenPower"?t.jsx("i",{className:"fa fa-leaf",title:"Green",...r}):t.jsx("i",{className:"fa fa-question",title:i,...r})}},q=F;export{E as D,P as L,q as P};
