text: !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("fecha")):"function"==typeof define&&define.amd?define(["exports","fecha"],t):t((e||self).customCardHelpers={},e.fecha)}(this,function(e,t){function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=a(t);function n(e){var t=e.split(":").map(Number);return 3600*t[0]+60*t[1]+t[2]}var i,s=function(){try{(new Date).toLocaleDateString("i")}catch(e){return"RangeError"===e.name}return!1}()?function(e,t){return e.toLocaleDateString(t.language,{year:"numeric",month:"long",day:"numeric"})}:function(e){return r.default.format(e,"mediumDate")},o=function(){try{(new Date).toLocaleString("i")}catch(e){return"RangeError"===e.name}return!1}()?function(e,t){return e.toLocaleString(t.language,{year:"numeric",month:"long",day:"numeric",hour:"numeric",minute:"2-digit"})}:function(e){return r.default.format(e,"haDateTime")},c=function(){try{(new Date).toLocaleTimeString("i")}catch(e){return"RangeError"===e.name}return!1}()?function(e,t){return e.toLocaleTimeString(t.language,{hour:"numeric",minute:"2-digit"})}:function(e){return r.default.format(e,"shortTime")},u=[60,60,24,7],l=["second","minute","hour","day"],m=function(e){return e<10?"0"+e:e};function h(){return(h=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(e[r]=a[r])}return e}).apply(this,arguments)}function f(e){return e.substr(0,e.indexOf("."))}function d(e){var t=e.locale.language||"en";return e.translationMetadata.translations[t]&&e.translationMetadata.translations[t].isRTL||!1}function p(e){return f(e.entity_id)}e.NumberFormat=void 0,(i=e.NumberFormat||(e.NumberFormat={})).language="language",i.system="system",i.comma_decimal="comma_decimal",i.decimal_comma="decimal_comma",i.space_comma="space_comma",i.none="none";var g=function(t,a,r){var n;switch(null==a?void 0:a.number_format){case e.NumberFormat.comma_decimal:n=["en-US","en"];break;case e.NumberFormat.decimal_comma:n=["de","es","it"];break;case e.NumberFormat.space_comma:n=["fr","sv","cs"];break;case e.NumberFormat.system:n=void 0;break;default:n=null==a?void 0:a.language}if(Number.isNaN=Number.isNaN||function e(t){return"number"==typeof t&&e(t)},!Number.isNaN(Number(t))&&Intl&&(null==a?void 0:a.number_format)!==e.NumberFormat.none)try{return new Intl.NumberFormat(n,b(t,r)).format(Number(t))}catch(e){return console.error(e),new Intl.NumberFormat(void 0,b(t,r)).format(Number(t))}return t?t.toString():""},b=function(e,t){var a=t||{};if("string"!=typeof e)return a;if(!t||!t.minimumFractionDigits&&!t.maximumFractionDigits){var r=e.indexOf(".")>-1?e.split(".")[1].length:0;a.minimumFractionDigits=r,a.maximumFractionDigits=r}return a},v="hass:bookmark",_=["closed","locked","off"],y=new Set(["fan","input_boolean","light","switch","group","automation"]),w=function(e,t,a,r){r=r||{},a=null==a?{}:a;var n=new Event(t,{bubbles:void 0===r.bubbles||r.bubbles,cancelable:Boolean(r.cancelable),composed:void 0===r.composed||r.composed});return n.detail=a,e.dispatchEvent(n),n},k=new Set(["call-service","divider","section","weblink","cast","select"]),S={alert:"toggle",automation:"toggle",climate:"climate",cover:"cover",fan:"toggle",group:"group",input_boolean:"toggle",input_number:"input-number",input_select:"input-select",input_text:"input-text",light:"toggle",lock:"lock",media_player:"media-player",remote:"toggle",scene:"scene",script:"script",sensor:"sensor",timer:"timer",switch:"toggle",vacuum:"toggle",water_heater:"climate",input_datetime:"input-datetime"},N={alert:"hass:alert",automation:"hass:playlist-play",calendar:"hass:calendar",camera:"hass:video",climate:"hass:thermostat",configurator:"hass:settings",conversation:"hass:text-to-speech",device_tracker:"hass:account",fan:"hass:fan",group:"hass:google-circles-communities",history_graph:"hass:chart-line",homeassistant:"hass:home-assistant",homekit:"hass:home-automation",image_processing:"hass:image-filter-frames",input_boolean:"hass:drawing",input_datetime:"hass:calendar-clock",input_number:"hass:ray-vertex",input_select:"hass:format-list-bulleted",input_text:"hass:textbox",light:"hass:lightbulb",mailbox:"hass:mailbox",notify:"hass:comment-alert",person:"hass:account",plant:"hass:flower",proximity:"hass:apple-safari",remote:"hass:remote",scene:"hass:google-pages",script:"hass:file-document",sensor:"hass:eye",simple_alarm:"hass:bell",sun:"hass:white-balance-sunny",switch:"hass:flash",timer:"hass:timer",updater:"hass:cloud-upload",vacuum:"hass:robot-vacuum",water_heater:"hass:thermometer",weblink:"hass:open-in-new"};function D(e,t){if(e in N)return N[e];switch(e){case"alarm_control_panel":switch(t){case"armed_home":return"hass:bell-plus";case"armed_night":return"hass:bell-sleep";case"disarmed":return"hass:bell-outline";case"triggered":return"hass:bell-ring";default:return"hass:bell"}case"binary_sensor":return t&&"off"===t?"hass:radiobox-blank":"hass:checkbox-marked-circle";case"cover":return"closed"===t?"hass:window-closed":"hass:window-open";case"lock":return t&&"unlocked"===t?"hass:lock-open":"hass:lock";case"media_player":return t&&"off"!==t&&"idle"!==t?"hass:cast-connected":"hass:cast";case"zwave":switch(t){case"dead":return"hass:emoticon-dead";case"sleeping":return"hass:sleep";case"initializing":return"hass:timer-sand";default:return"hass:z-wave"}default:return console.warn("Unable to find icon for domain "+e+" ("+t+")"),v}}var T=function(e){w(window,"haptic",e)},x=function(e,t,a){void 0===a&&(a=!1),a?history.replaceState(null,"",t):history.pushState(null,"",t),w(window,"location-changed",{replace:a})},O=function(e,t,a){void 0===a&&(a=!0);var r,n=f(t),i="group"===n?"homeassistant":n;switch(n){case"lock":r=a?"unlock":"lock";break;case"cover":r=a?"open_cover":"close_cover";break;default:r=a?"turn_on":"turn_off"}return e.callService(i,r,{entity_id:t})},E=function(e,t){var a=_.includes(e.states[t].state);return O(e,t,a)},I=function(e,t,a,r){if(r||(r={action:"more-info"}),!r.confirmation||r.confirmation.exemptions&&r.confirmation.exemptions.some(function(e){return e.user===t.user.id})||(T("warning"),confirm(r.confirmation.text||"Are you sure you want to "+r.action+"?")))switch(r.action){case"more-info":(a.entity||a.camera_image)&&w(e,"hass-more-info",{entityId:a.entity?a.entity:a.camera_image});break;case"navigate":r.navigation_path&&x(0,r.navigation_path);break;case"url":r.url_path&&window.open(r.url_path);break;case"toggle":a.entity&&(E(t,a.entity),T("success"));break;case"call-service":if(!r.service)return void T("failure");var n=r.service.split(".",2);t.callService(n[0],n[1],r.service_data),T("success");break;case"fire-dom-event":w(e,"ll-custom",r)}},F={humidity:"hass:water-percent",illuminance:"hass:brightness-5",temperature:"hass:thermometer",pressure:"hass:gauge",power:"hass:flash",signal_strength:"hass:wifi"},A={binary_sensor:function(e){var t=e.state&&"off"===e.state;switch(e.attributes.device_class){case"battery":return t?"hass:battery":"hass:battery-outline";case"cold":return t?"hass:thermometer":"hass:snowflake";case"connectivity":return t?"hass:server-network-off":"hass:server-network";case"door":return t?"hass:door-closed":"hass:door-open";case"garage_door":return t?"hass:garage":"hass:garage-open";case"gas":case"power":case"problem":case"safety":case"smoke":return t?"hass:shield-check":"hass:alert";case"heat":return t?"hass:thermometer":"hass:fire";case"light":return t?"hass:brightness-5":"hass:brightness-7";case"lock":return t?"hass:lock":"hass:lock-open";case"moisture":return t?"hass:water-off":"hass:water";case"motion":return t?"hass:walk":"hass:run";case"occupancy":return t?"hass:home-outline":"hass:home";case"opening":return t?"hass:square":"hass:square-outline";case"plug":return t?"hass:power-plug-off":"hass:power-plug";case"presence":return t?"hass:home-outline":"hass:home";case"sound":return t?"hass:music-note-off":"hass:music-note";case"vibration":return t?"hass:crop-portrait":"hass:vibrate";case"window":return t?"hass:window-closed":"hass:window-open";default:return t?"hass:radiobox-blank":"hass:checkbox-marked-circle"}},cover:function(e){var t="closed"!==e.state;switch(e.attributes.device_class){case"garage":return t?"hass:garage-open":"hass:garage";case"door":return t?"hass:door-open":"hass:door-closed";case"shutter":return t?"hass:window-shutter-open":"hass:window-shutter";case"blind":return t?"hass:blinds-open":"hass:blinds";case"window":return t?"hass:window-open":"hass:window-closed";default:return D("cover",e.state)}},sensor:function(e){var t=e.attributes.device_class;if(t&&t in F)return F[t];if("battery"===t){var a=Number(e.state);if(isNaN(a))return"hass:battery-unknown";var r=10*Math.round(a/10);return r>=100?"hass:battery":r<=0?"hass:battery-alert":"hass:battery-"+r}var n=e.attributes.unit_of_measurement;return"°C"===n||"°F"===n?"hass:thermometer":D("sensor")},input_datetime:function(e){return e.attributes.has_date?e.attributes.has_time?D("input_datetime"):"hass:calendar":"hass:clock"}};e.DEFAULT_DOMAIN_ICON=v,e.DEFAULT_PANEL="lovelace",e.DEFAULT_VIEW_ENTITY_ID="group.default_view",e.DOMAINS_HIDE_MORE_INFO=["input_number","input_select","input_text","scene","weblink"],e.DOMAINS_MORE_INFO_NO_HISTORY=["camera","configurator","history_graph","scene"],e.DOMAINS_TOGGLE=y,e.DOMAINS_WITH_CARD=["climate","cover","configurator","input_select","input_number","input_text","lock","media_player","scene","script","timer","vacuum","water_heater","weblink"],e.DOMAINS_WITH_MORE_INFO=["alarm_control_panel","automation","camera","climate","configurator","cover","fan","group","history_graph","input_datetime","light","lock","media_player","script","sun","updater","vacuum","water_heater","weather"],e.STATES_OFF=_,e.UNIT_C="°C",e.UNIT_F="°F",e.applyThemesOnElement=function(e,t,a,r){void 0===r&&(r=!1),e._themes||(e._themes={});var n=t.default_theme;("default"===a||a&&t.themes[a])&&(n=a);var i=h({},e._themes);if("default"!==n){var s=t.themes[n];Object.keys(s).forEach(function(t){var a="--"+t;e._themes[a]="",i[a]=s[t]})}if(e.updateStyles?e.updateStyles(i):window.ShadyCSS&&window.ShadyCSS.styleSubtree(e,i),r){var o=document.querySelector("meta[name=theme-color]");if(o){o.hasAttribute("default-content")||o.setAttribute("default-content",o.getAttribute("content"));var c=i["--primary-color"]||o.getAttribute("default-content");o.setAttribute("content",c)}}},e.computeCardSize=function(e){return"function"==typeof e.getCardSize?e.getCardSize():4},e.computeDomain=f,e.computeEntity=function(e){return e.substr(e.indexOf(".")+1)},e.computeRTL=d,e.computeRTLDirection=function(e){return d(e)?"rtl":"ltr"},e.computeStateDisplay=function(e,t,a,r){var n=void 0!==r?r:t.state;if("unknown"===n||"unavailable"===n)return e("state.default."+n);if(t.attributes.unit_of_measurement)return g(n,a)+" "+t.attributes.unit_of_measurement;var i=p(t);if("input_datetime"===i){var u;if(!t.attributes.has_time)return u=new Date(t.attributes.year,t.attributes.month-1,t.attributes.day),s(u,a);if(!t.attributes.has_date){var l=new Date;return u=new Date(l.getFullYear(),l.getMonth(),l.getDay(),t.attributes.hour,t.attributes.minute),c(u,a)}return u=new Date(t.attributes.year,t.attributes.month-1,t.attributes.day,t.attributes.hour,t.attributes.minute),o(u,a)}return"humidifier"===i&&"on"===n&&t.attributes.humidity?t.attributes.humidity+" %":"counter"===i||"number"===i?g(n,a):t.attributes.device_class&&e("component."+i+".state."+t.attributes.device_class+"."+t.state)||e("component."+i+".state._."+t.state)||t.state},e.computeStateDomain=p,e.createThing=function(e,t){void 0===t&&(t=!1);var a=function(e,t){return r("hui-error-card",{type:"error",error:e,config:t})},r=function(e,t){var r=window.document.createElement(e);try{r.setConfig(t)}catch(r){return console.error(e,r),a(r.message,t)}return r};if(!e||"object"!=typeof e||!t&&!e.type)return a("No type defined",e);var n=e.type;if(n&&n.startsWith("custom:"))n=n.substr("custom:".length);else if(t)if(k.has(n))n="hui-"+n+"-row";else{if(!e.entity)return a("Invalid config given.",e);var i=e.entity.split(".",1)[0];n="hui-"+(S[i]||"text")+"-entity-row"}else n="hui-"+n+"-card";if(customElements.get(n))return r(n,e);var s=a("Custom element doesn't exist: "+e.type+".",e);s.style.display="None";var o=setTimeout(function(){s.style.display=""},2e3);return customElements.whenDefined(e.type).then(function(){clearTimeout(o),w(s,"ll-rebuild",{},s)}),s},e.debounce=function(e,t,a){var r;return void 0===a&&(a=!1),function(){var n=[].slice.call(arguments),i=this,s=function(){r=null,a||e.apply(i,n)},o=a&&!r;clearTimeout(r),r=setTimeout(s,t),o&&e.apply(i,n)}},e.domainIcon=D,e.durationToSeconds=n,e.evaluateFilter=function(e,t){var a=t.value||t,r=t.attribute?e.attributes[t.attribute]:e.state;switch(t.operator||"=="){case"==":return r===a;case"<=":return r<=a;case"<":return r<a;case">=":return r>=a;case">":return r>a;case"!=":return r!==a;case"regex":return r.match(a);default:return!1}},e.fireEvent=w,e.fixedIcons=N,e.formatDate=s,e.formatDateTime=o,e.formatNumber=g,e.formatTime=c,e.forwardHaptic=T,e.getLovelace=function(){var e=document.querySelector("home-assistant");if(e=(e=(e=(e=(e=(e=(e=(e=e&&e.shadowRoot)&&e.querySelector("home-assistant-main"))&&e.shadowRoot)&&e.querySelector("app-drawer-layout partial-panel-resolver"))&&e.shadowRoot||e)&&e.querySelector("ha-panel-lovelace"))&&e.shadowRoot)&&e.querySelector("hui-root")){var t=e.lovelace;return t.current_view=e.___curView,t}return null},e.handleAction=function(e,t,a,r){var n;"double_tap"===r&&a.double_tap_action?n=a.double_tap_action:"hold"===r&&a.hold_action?n=a.hold_action:"tap"===r&&a.tap_action&&(n=a.tap_action),I(e,t,a,n)},e.handleActionConfig=I,e.handleClick=function(e,t,a,r,n){var i;if(n&&a.double_tap_action?i=a.double_tap_action:r&&a.hold_action?i=a.hold_action:!r&&a.tap_action&&(i=a.tap_action),i||(i={action:"more-info"}),!i.confirmation||i.confirmation.exemptions&&i.confirmation.exemptions.some(function(e){return e.user===t.user.id})||confirm(i.confirmation.text||"Are you sure you want to "+i.action+"?"))switch(i.action){case"more-info":(i.entity||a.entity||a.camera_image)&&(w(e,"hass-more-info",{entityId:i.entity?i.entity:a.entity?a.entity:a.camera_image}),i.haptic&&T(i.haptic));break;case"navigate":i.navigation_path&&(x(0,i.navigation_path),i.haptic&&T(i.haptic));break;case"url":i.url_path&&window.open(i.url_path),i.haptic&&T(i.haptic);break;case"toggle":a.entity&&(E(t,a.entity),i.haptic&&T(i.haptic));break;case"call-service":if(!i.service)return;var s=i.service.split(".",2),o=s[0],c=s[1],u=h({},i.service_data);"entity"===u.entity_id&&(u.entity_id=a.entity),t.callService(o,c,u),i.haptic&&T(i.haptic);break;case"fire-dom-event":w(e,"ll-custom",i),i.haptic&&T(i.haptic)}},e.hasAction=function(e){return void 0!==e&&"none"!==e.action},e.hasConfigOrEntityChanged=function(e,t,a){if(t.has("config")||a)return!0;if(e.config.entity){var r=t.get("hass");return!r||r.states[e.config.entity]!==e.hass.states[e.config.entity]}return!1},e.hasDoubleClick=function(e){return void 0!==e&&"none"!==e.action},e.navigate=x,e.relativeTime=function(e,t,a){void 0===a&&(a={});var r,n=((a.compareTime||new Date).getTime()-e.getTime())/1e3,i=n>=0?"past":"future";n=Math.abs(n);for(var s=0;s<u.length;s++){if(n<u[s]){n=Math.floor(n),r=t("ui.components.relative_time.duration."+l[s],"count",n);break}n/=u[s]}return void 0===r&&(r=t("ui.components.relative_time.duration.week","count",n=Math.floor(n))),!1===a.includeTense?r:t("ui.components.relative_time."+i,"time",r)},e.secondsToDuration=function(e){var t=Math.floor(e/3600),a=Math.floor(e%3600/60),r=Math.floor(e%3600%60);return t>0?t+":"+m(a)+":"+m(r):a>0?a+":"+m(r):r>0?""+r:null},e.stateIcon=function(e){if(!e)return v;if(e.attributes.icon)return e.attributes.icon;var t=f(e.entity_id);return t in A?A[t](e):D(t,e.state)},e.timerTimeRemaining=function(e){var t=n(e.attributes.remaining);if("active"===e.state){var a=(new Date).getTime(),r=new Date(e.last_changed).getTime();t=Math.max(t-(a-r)/1e3,0)}return t},e.toggleEntity=E,e.turnOnOffEntities=function(e,t,a){void 0===a&&(a=!0);var r={};t.forEach(function(t){if(_.includes(e.states[t].state)===a){var n=f(t),i=["cover","lock"].includes(n)?n:"homeassistant";i in r||(r[i]=[]),r[i].push(t)}}),Object.keys(r).forEach(function(t){var n;switch(t){case"lock":n=a?"unlock":"lock";break;case"cover":n=a?"open_cover":"close_cover";break;default:n=a?"turn_on":"turn_off"}e.callService(t,n,{entity_id:r[t]})})},e.turnOnOffEntity=O});
  //# sourceMappingURL=index.umd.js.map
  