import{ar as d,u as p,j as t,b,l as h,r as w}from"./index-fb4a4614.js";import{p as y}from"./powerSourceTypeToTranslationKey-452dac81.js";var m=[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 j(e,a){var n=e<0?1:0;e=Math.abs(e);for(var r=e,s=0;e>=m[s]&&s<m.length;s++)e/=m[s];return e=Math.floor(e),s*=2,e>(s===0?9:1)&&(s+=1),a(e,s,r)[n].replace("%s",e.toString())}function _(e,a){var n=a?x(a):new Date;return(+n-+x(e))/1e3}var N=function(e,a,n){var r=_(e,n&&n.relativeDate);return j(r,d(a))};function k(e){const{value:a,name:n}=e,{t:r}=p("values"),s={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=s[n]||s._default;return t.jsx(t.Fragment,{children:i.get(a)})}function L(e){const{t:a}=p("values"),{value:n}=e;switch(typeof n){case"boolean":return t.jsx(k,{...e});case"undefined":return t.jsx(t.Fragment,{children:"N/A"});case"object":return t.jsx(t.Fragment,{children:n===null?a("null"):JSON.stringify(n)});case"string":return t.jsx(t.Fragment,{children:n===""?t.jsx("small",{className:"text-muted",children:a("empty_string")}):n});default:return t.jsx(t.Fragment,{children:JSON.stringify(n)})}}function v(e){const{i18n:a}=p(),{state:n,lastSeenType:r}=e,s=h(n,r);return s?t.jsx(t.Fragment,{children:N(s,a.language)}):t.jsx(t.Fragment,{children:"N/A"})}const D="_plug_1sba2_1",M={plug:D},F=({device:e,deviceState:a,showLevel:n,...r})=>{const{t:s}=p("zigbee");let i;switch(e!==void 0&&(i=e.power_source),i){case"Battery":let g=s(y(i)),u="",l="fa-question",o,f,c;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&&(c=a.battery_low)),o!==void 0)if(u=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(u=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 c!==void 0&&(u=c?"LOW":"OK",l=c?"fa-battery-empty":"fa-battery-full");return c===!0&&(l+=" animation-blinking text-danger"),u!==""&&(g+=", "+s("power_level")+`: ${u}`),t.jsxs(w.Fragment,{children:[n?t.jsxs("span",{className:"pe-2",children:[s("battery")," ",u]}):null,t.jsx("i",{className:`fa ${l}`,title:g,...r})]});case"Mains (single phase)":case"DC Source":return t.jsx("i",{className:`fa fa-plug ${M.plug}`,title:s(y(i)),...r});default:return t.jsx("i",{className:"fa fa-question",title:i,...r})}},q=F;export{L as D,v as L,q as P};
