import{aJ as d,u as p,j as t,b as g,l as h,v as w,r as j}from"./index-a77bd902.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 _(e,a){var s=e<0?1:0;e=Math.abs(e);for(var r=e,n=0;e>=m[n]&&n<m.length;n++)e/=m[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 N(e,a){var s=a?x(a):new Date;return(+s-+x(e))/1e3}var k=function(e,a,s){var r=N(e,s&&s.relativeDate);return _(r,d(a))};function D(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:g("text-danger","animation-blinking"),children:r("leaking")},"Leaking")],[!1,r("clear")]]),tamper:new Map([[!0,t.jsx("span",{className:g("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 L(e){const{t:a}=p("values"),{value:s}=e;switch(typeof s){case"boolean":return t.jsx(D,{...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 q(e){const{i18n:a}=p(),{state:s,lastSeenType:r}=e,n=h(s,r);return n?t.jsx("span",{title:w(n),children:k(n,a.language)}):t.jsx(t.Fragment,{children:"N/A"})}const M="_plug_1sba2_1",$={plug:M},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 b=n(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!==""&&(b+=", "+n("power_level")+`: ${u}`),t.jsxs(j.Fragment,{children:[s?t.jsxs("span",{className:"pe-2",children:[n("battery")," ",u]}):null,t.jsx("i",{className:`fa ${l}`,title:b,...r})]});case"Mains (single phase)":case"DC Source":return t.jsx("i",{className:`fa fa-plug ${$.plug}`,title:n(y(i)),...r});default:return t.jsx("i",{className:"fa fa-question",title:i,...r})}},A=F;export{L as D,q as L,A as P};
