iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 23.8 kB
JavaScript
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[31355],{91069:function(e,t,i){i.a(e,async function(e,s){try{i.d(t,{EO:function(){return b},Yq:function(){return w},_U:function(){return T},eE:function(){return E},fU:function(){return D},ol:function(){return y},xo:function(){return I}});var o=i(78016),a=i(31810),r=i(87950),n=i(81977),d=i(36307),l=i(35932),h=i(73983),c=i(6946),u=i(92913),_=i(83339),m=i(77972),p=i(31886),g=i(46927),v=e([p]);p=(v.then?(await v)():v)[0];const f=(e,t,i,s)=>{const o=i(new p.BB(e,t),s);return o instanceof Date?new Date(o.getTime()):o},y=(e,t,i,s,o)=>i.time_zone===g.Wj.server?f(e,s.time_zone,t,o):t(e,o),I=(e,t,i,s,o)=>i.time_zone===g.Wj.server?f(e,s.time_zone,t,o):t(e,o),b=(e,t,i,s,o)=>I(e,i,s,o,s.time_zone===g.Wj.server?new p.BB(t,o.time_zone):t),E=(e,t,i,s,p)=>{let g,v;if(I(e,o.e,s,p)&&I(t,a.c,s,p)){const o=(b(t,e,r.W,s,p)+1)*(i?1:-1);g=y(e,n.P,s,p,o),v=y(y(t,n.P,s,p,o),d.p,s,p)}else if(I(e,e=>(0,l.o)(e).getMilliseconds()===e.getMilliseconds(),s,p)&&I(t,e=>(0,h.D)(e).getMilliseconds()===e.getMilliseconds(),s,p)){const o=(b(t,e,c.c,s,p)+1)*(i?1:-1);g=y(e,u.f,s,p,o),v=y(t,u.f,s,p,o)}else{const o=b(t,e,_.b,s,p)*(i?1:-1);g=y(e,m.A,s,p,o),v=y(t,m.A,s,p,o)}return{start:g,end:v}},T=(e,t)=>{const i=new p.BB(e,t);return new Date(i.getTime())},w=(e,t)=>new p.BB(e,t).toISOString().split("T")[0],D=(e,t)=>new p.BB(e,t).toISOString().split("T")[1].split(".")[0];s()}catch(f){s(f)}})},85938:function(e,t,i){i(18111),i(22489),i(3362),i(46058),i(62953);var s=i(40445),o=i(5124),a=i(67576),r=i(1087);let n,d=e=>e;class l extends o.WF{updated(e){e.has("disabled")&&(this.disabled?this._destroySortable():this._createSortable())}disconnectedCallback(){super.disconnectedCallback(),this._shouldBeDestroy=!0,setTimeout(()=>{this._shouldBeDestroy&&(this._destroySortable(),this._shouldBeDestroy=!1)},1)}connectedCallback(){super.connectedCallback(),this._shouldBeDestroy=!1,this.hasUpdated&&!this.disabled&&this._createSortable()}createRenderRoot(){return this}render(){return this.noStyle?o.s6:(0,o.qy)(n||(n=d` <style>.sortable-fallback{display:none!important}.sortable-ghost{box-shadow:0 0 0 2px var(--primary-color);background:rgba(var(--rgb-primary-color),.25);border-radius:var(--ha-border-radius-sm);opacity:.4}.sortable-drag{border-radius:var(--ha-border-radius-sm);opacity:1;background:var(--card-background-color);box-shadow:0px 4px 8px 3px #00000026;cursor:grabbing}</style> `))}async _createSortable(){if(this._sortable)return;const e=this.children[0];if(!e)return;const t=(await Promise.all([i.e(85283),i.e(70322)]).then(i.bind(i,80745))).default,s=Object.assign(Object.assign({scroll:!0,forceAutoScrollFallback:!0,scrollSpeed:20,animation:150},this.options),{},{onChoose:this._handleChoose,onStart:this._handleStart,onEnd:this._handleEnd,onUpdate:this._handleUpdate,onAdd:this._handleAdd,onRemove:this._handleRemove});this.draggableSelector&&(s.draggable=this.draggableSelector),this.handleSelector&&(s.handle=this.handleSelector),void 0!==this.invertSwap&&(s.invertSwap=this.invertSwap),this.group&&(s.group=this.group),this.filter&&(s.filter=this.filter),this._sortable=new t(e,s)}_destroySortable(){this._sortable&&(this._sortable.destroy(),this._sortable=void 0)}constructor(...e){super(...e),this.disabled=!1,this.noStyle=!1,this.invertSwap=!1,this.rollback=!0,this._shouldBeDestroy=!1,this._handleUpdate=e=>{(0,r.r)(this,"item-moved",{newIndex:e.newIndex,oldIndex:e.oldIndex})},this._handleAdd=e=>{(0,r.r)(this,"item-added",{index:e.newIndex,data:e.item.sortableData,item:e.item})},this._handleRemove=e=>{(0,r.r)(this,"item-removed",{index:e.oldIndex})},this._handleEnd=async e=>{(0,r.r)(this,"drag-end"),this.rollback&&e.item.placeholder&&(e.item.placeholder.replaceWith(e.item),delete e.item.placeholder)},this._handleStart=()=>{(0,r.r)(this,"drag-start")},this._handleChoose=e=>{this.rollback&&(e.item.placeholder=document.createComment("sort-placeholder"),e.item.after(e.item.placeholder))}}}(0,s.Cg)([(0,a.MZ)({type:Boolean})],l.prototype,"disabled",void 0),(0,s.Cg)([(0,a.MZ)({type:Boolean,attribute:"no-style"})],l.prototype,"noStyle",void 0),(0,s.Cg)([(0,a.MZ)({type:String,attribute:"draggable-selector"})],l.prototype,"draggableSelector",void 0),(0,s.Cg)([(0,a.MZ)({type:String,attribute:"handle-selector"})],l.prototype,"handleSelector",void 0),(0,s.Cg)([(0,a.MZ)({type:String,attribute:"filter"})],l.prototype,"filter",void 0),(0,s.Cg)([(0,a.MZ)({type:String})],l.prototype,"group",void 0),(0,s.Cg)([(0,a.MZ)({type:Boolean,attribute:"invert-swap"})],l.prototype,"invertSwap",void 0),(0,s.Cg)([(0,a.MZ)({attribute:!1})],l.prototype,"options",void 0),(0,s.Cg)([(0,a.MZ)({type:Boolean})],l.prototype,"rollback",void 0),l=(0,s.Cg)([(0,a.EM)("ha-sortable")],l)},65590:function(e,t,i){i.d(t,{EE:function(){return d},Ed:function(){return l},K1:function(){return m},Pe:function(){return p},Xf:function(){return c},aO:function(){return n},fk:function(){return u},wE:function(){return _},yU:function(){return h}});i(89463),i(74423),i(26910),i(18111),i(22489),i(61701),i(3362);var s=i(71727),o=i(28978),a=i(52220),r=i(22675),n=function(e){return e.NeedsAction="needs_action",e.Completed="completed",e}({}),d=function(e){return e.NONE="none",e.ALPHA_ASC="alpha_asc",e.ALPHA_DESC="alpha_desc",e.DUEDATE_ASC="duedate_asc",e.DUEDATE_DESC="duedate_desc",e}({}),l=function(e){return e[e.CREATE_TODO_ITEM=1]="CREATE_TODO_ITEM",e[e.DELETE_TODO_ITEM=2]="DELETE_TODO_ITEM",e[e.UPDATE_TODO_ITEM=4]="UPDATE_TODO_ITEM",e[e.MOVE_TODO_ITEM=8]="MOVE_TODO_ITEM",e[e.SET_DUE_DATE_ON_ITEM=16]="SET_DUE_DATE_ON_ITEM",e[e.SET_DUE_DATETIME_ON_ITEM=32]="SET_DUE_DATETIME_ON_ITEM",e[e.SET_DESCRIPTION_ON_ITEM=64]="SET_DESCRIPTION_ON_ITEM",e}({});const h=(e,t=!0)=>Object.keys(e.states).filter(i=>{var o;return"todo"===(0,s.m)(i)&&e.states[i].state!==r.Hh&&(t||!0!==(null===(o=e.entities[i])||void 0===o?void 0:o.hidden))}).map(t=>Object.assign(Object.assign({},e.states[t]),{},{entity_id:t,name:(0,o.u)(e.states[t])})).sort((t,i)=>(0,a.xL)(t.name,i.name,e.locale.language)),c=(e,t,i)=>e.connection.subscribeMessage(i,{type:"todo/item/subscribe",entity_id:t}),u=(e,t,i)=>{var s,o;return e.callService("todo","update_item",{item:i.uid,rename:i.summary,status:i.status,description:i.description,due_datetime:null!==(s=i.due)&&void 0!==s&&s.includes("T")?i.due:void 0,due_date:void 0===i.due||null!==(o=i.due)&&void 0!==o&&o.includes("T")?void 0:i.due},{entity_id:t})},_=(e,t,i)=>{var s,o;return e.callService("todo","add_item",{item:i.summary,description:i.description||void 0,due_datetime:null!==(s=i.due)&&void 0!==s&&s.includes("T")?i.due:void 0,due_date:void 0===i.due||null!==(o=i.due)&&void 0!==o&&o.includes("T")?void 0:i.due},{entity_id:t})},m=(e,t,i)=>e.callService("todo","remove_item",{item:i},{entity_id:t}),p=(e,t,i,s)=>e.callWS({type:"todo/item/move",entity_id:t,uid:i,previous_uid:s})},62134:function(e,t,i){i.a(e,async function(e,s){try{i.r(t),i.d(t,{HuiTodoListCard:function(){return _e},ITEM_TAP_ACTION_EDIT:function(){return ce},ITEM_TAP_ACTION_TOGGLE:function(){return ue}});i(89463),i(16280),i(74423),i(26910),i(13609),i(18111),i(22489),i(20116),i(61701),i(3362),i(62953);var o=i(40445),a=i(92913),r=i(73983),n=i(66465),d=i(69137),l=i(81977),h=i(36307),c=i(56434),u=i(69748),_=i(83309),m=i(5124),p=i(67576),g=i(6412),v=i(75751),f=i(22786),y=i(91069),I=i(380),b=i(42372),E=i(82286),T=i(52220),w=(i(76776),i(30716),i(29823)),D=(i(70947),i(26300)),S=(i(8630),i(38377),i(36158)),A=i(606),M=(i(85938),i(67094),i(91485)),$=i(22675),C=i(65590),k=i(65063),O=i(12295),x=i(13632),H=i(85979),V=e([w,D,S,A,M,I,H,y]);[w,D,S,A,M,I,H,y]=V.then?(await V)():V;let P,L,z,U,q,B,R,N,Z,F,W,j,K,X,G,Q,J,Y,ee,te,ie,se=e=>e;const oe="M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M16.2,16.2L11,13V7H12.5V12.2L17,14.9L16.2,16.2Z",ae="M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z",re="M15,16H19V18H15V16M15,8H22V10H15V8M15,12H21V14H15V12M3,18A2,2 0 0,0 5,20H11A2,2 0 0,0 13,18V8H3V18M14,5H11L10,4H6L5,5H2V7H14V5Z",ne="M12,16A2,2 0 0,1 14,18A2,2 0 0,1 12,20A2,2 0 0,1 10,18A2,2 0 0,1 12,16M12,10A2,2 0 0,1 14,12A2,2 0 0,1 12,14A2,2 0 0,1 10,12A2,2 0 0,1 12,10M12,4A2,2 0 0,1 14,6A2,2 0 0,1 12,8A2,2 0 0,1 10,6A2,2 0 0,1 12,4Z",de="M21 11H3V9H21V11M21 13H3V15H21V13Z",le="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z",he="M18 21L14 17H17V7H14L18 3L22 7H19V17H22M2 19V17H12V19M2 13V11H9V13M2 7V5H6V7H2Z",ce="edit",ue="toggle";class _e extends m.WF{static async getConfigElement(){return await i.e(90143).then(i.bind(i,24770)),document.createElement("hui-todo-list-card-editor")}static getStubConfig(e,t,i){return{type:"todo-list",entity:(0,x.B)(e,1,t,i,["todo"])[0]||""}}connectedCallback(){super.connectedCallback(),this.hasUpdated&&this._subscribeItems(),this._setRefreshTimer()}disconnectedCallback(){var e;super.disconnectedCallback(),null===(e=this._unsubItems)||void 0===e||e.then(e=>e()),this._unsubItems=void 0,this._clearRefreshTimer()}getCardSize(){return 3+(this._config&&this._config.title?2:0)}setConfig(e){this.checkConfig(e),this._config=e,this._entityId=e.entity}checkConfig(e){if(!e.entity||"todo"!==e.entity.split(".")[0])throw new Error("Specify an entity from within the todo domain")}getEntityId(){}_sortItems(e,t){if(t===C.EE.ALPHA_ASC||t===C.EE.ALPHA_DESC){const i=t===C.EE.ALPHA_ASC?1:-1;return e.sort((e,t)=>{var s;return i*(0,T.SH)(e.summary,t.summary,null===(s=this.hass)||void 0===s?void 0:s.locale.language)})}if(t===C.EE.DUEDATE_ASC||t===C.EE.DUEDATE_DESC){const i=t===C.EE.DUEDATE_ASC?1:-1;return e.sort((e,t)=>{var s,o;const a=null!==(s=this._getDueDate(e))&&void 0!==s?s:1/0,r=null!==(o=this._getDueDate(t))&&void 0!==o?o:1/0;return a===r?0:a<r?-i:i})}return e}_filterItems(e,t,i){const s=i&&i.calendar&&i.calendar.period?this._addPeriod(new Date,i.calendar):void 0;return e.filter(e=>{if(!t.includes(e.status||null))return!1;if(!s)return!0;const i=this._getDueDate(e);return i&&i<=s})}_addPeriod(e,t){const i=this.hass.locale,s=this.hass.config,o=t.offset||0;switch(t.period){case"day":return(0,a.f)((0,y.ol)(e,r.D,i,s),o);case"week":{const t=(0,I.P)(i);return(0,n.J)((0,y.ol)(e,d.$,i,s,{weekStartsOn:t}),o)}case"month":return(0,l.P)((0,y.ol)(e,h.p,i,s),o);case"year":return(0,c.e)((0,y.ol)(e,u.Q,i,s),o);default:return}}_setRefreshTimer(){var e;if(this._clearRefreshTimer(),!this.hass||null===(e=this._config)||void 0===e||!e.due_date_period)return;const t=new Date,i=(0,y.ol)(t,r.D,this.hass.locale,this.hass.config);this._refreshTimer=window.setTimeout(()=>{this._refreshTimer=void 0,this.requestUpdate()},i.getTime()-t.getTime())}_clearRefreshTimer(){void 0!==this._refreshTimer&&(window.clearTimeout(this._refreshTimer),this._refreshTimer=void 0)}willUpdate(e){this.hasUpdated?!e.has("_entityId")&&this._items||(this._items=void 0,this._subscribeItems()):(this._entityId||(this._entityId=this.getEntityId()),this._subscribeItems()),this._refreshTimer||this._setRefreshTimer()}updated(e){if(super.updated(e),!this._config||!this.hass)return;const t=e.get("hass"),i=e.get("_config");(e.has("hass")&&(null==t?void 0:t.themes)!==this.hass.themes||e.has("_config")&&(null==i?void 0:i.theme)!==this._config.theme)&&(0,b.Q)(this,this.hass.themes,this._config.theme)}render(){if(!this._config||!this.hass||!this._entityId)return m.s6;const e=this.hass.states[this._entityId];if(!e)return(0,m.qy)(P||(P=se` <hui-warning .hass="${0}"> ${0} </hui-warning> `),this.hass,(0,H.j)(this.hass,this._entityId));const t=e.state===$.Hh||e.state===$.HV,i=this._config.due_date_period?(0,y.ol)(new Date,r.D,this.hass.locale,this.hass.config).getTime():0,s=this._getCheckedItems(this._items,this._config.display_order,this._config.due_date_period,i),o=this._getUncheckedItems(this._items,this._config.display_order,this._config.due_date_period,i),a=this._getItemsWithoutStatus(this._items,this._config.display_order,this._config.due_date_period,i),n=this._reordering?this._getUncheckedAndItemsWithoutStatus(this._items,this._config.display_order,this._config.due_date_period,i):void 0;return(0,m.qy)(L||(L=se` <ha-card .header="${0}" class="${0}"> ${0} <ha-sortable handle-selector="ha-svg-icon" draggable-selector=".draggable" .disabled="${0}" -moved="${0}"> <ha-list wrapFocus multi> ${0} ${0} ${0} ${0} </ha-list> </ha-sortable> </ha-card> `),this._config.title,(0,g.H)({"has-header":"title"in this._config}),!this._config.hide_create&&this._todoListSupportsFeature(C.Ed.CREATE_TODO_ITEM)?(0,m.qy)(z||(z=se` <div class="addRow"> <ha-input .placeholder="${0}" ="${0}" .disabled="${0}"> <ha-icon-button slot="end" class="addButton" .path="${0}" .title="${0}" .disabled="${0}" ="${0}"> </ha-icon-button> </ha-input> </div> `),this.hass.localize("ui.panel.lovelace.cards.todo-list.add_item"),this._addKeyPress,t,le,this.hass.localize("ui.panel.lovelace.cards.todo-list.add_item"),t,this._addItem):m.s6,!this._reordering,this._itemMoved,o.length||a.length?this._reordering?(0,m.qy)(q||(q=se`<div class="header" role="separator"> <h2> ${0} </h2> ${0} </div> ${0}`),this.hass.localize("ui.panel.lovelace.cards.todo-list.reorder_items"),this._renderMenu(this._config,t),this._renderItems(null!=n?n:[],t)):m.s6:(0,m.qy)(U||(U=se`<p class="empty"> ${0} </p>`),this.hass.localize("ui.panel.lovelace.cards.todo-list.no_unchecked_items")),!this._reordering&&o.length?(0,m.qy)(B||(B=se` ${0} ${0} `),this._config.hide_section_headers?m.s6:(0,m.qy)(R||(R=se`<div class="header"> <h2> ${0} </h2> ${0} </div>`),this.hass.localize("ui.panel.lovelace.cards.todo-list.unchecked_items"),this._renderMenu(this._config,t)),this._renderItems(o,t)):m.s6,!this._reordering&&a.length?(0,m.qy)(N||(N=se` <div> ${0} <div class="header" role="separator"> <h2> ${0} </h2> ${0} </div> </div> ${0} `),o.length?(0,m.qy)(Z||(Z=se`<div class="divider" role="separator"></div>`)):m.s6,this.hass.localize("ui.panel.lovelace.cards.todo-list.no_status_items"),o.length?m.s6:this._renderMenu(this._config,t),this._renderItems(a,t)):m.s6,!this._config.hide_completed&&s.length?(0,m.qy)(F||(F=se` <div> <div class="divider" role="separator"></div> ${0} </div> ${0} `),this._config.hide_section_headers?m.s6:(0,m.qy)(W||(W=se`<div class="header"> <h2> ${0} </h2> ${0} </div>`),this.hass.localize("ui.panel.lovelace.cards.todo-list.checked_items"),this._todoListSupportsFeature(C.Ed.DELETE_TODO_ITEM)?(0,m.qy)(j||(j=se`<ha-dropdown -select="${0}" placement="bottom-end"> <ha-icon-button slot="trigger" .path="${0}"></ha-icon-button> <ha-dropdown-item value="clear" variant="danger"> ${0} <ha-svg-icon slot="icon" .path="${0}"> </ha-svg-icon> </ha-dropdown-item> </ha-dropdown>`),this._handleCompletedMenuSelect,ne,this.hass.localize("ui.panel.lovelace.cards.todo-list.clear_items"),re):m.s6),this._renderItems(s,t)):m.s6)}_renderMenu(e,t){return e.display_order&&e.display_order!==C.EE.NONE||!this._todoListSupportsFeature(C.Ed.MOVE_TODO_ITEM)?m.s6:(0,m.qy)(K||(K=se`<ha-dropdown -select="${0}" placement="bottom-end"> <ha-icon-button slot="trigger" .path="${0}"></ha-icon-button> <ha-dropdown-item value="reorder"> ${0} <ha-svg-icon slot="icon" .path="${0}"> </ha-svg-icon> </ha-dropdown-item> </ha-dropdown>`),this._handlePrimaryMenuSelect,ne,this.hass.localize(this._reordering?"ui.panel.lovelace.cards.todo-list.exit_reorder_items":"ui.panel.lovelace.cards.todo-list.reorder_items"),he)}_getDueDate(e){return e.due?e.due.includes("T")?new Date(e.due):(0,r.D)(new Date(`${e.due}T00:00:00`)):void 0}_renderItems(e,t=!1){return(0,m.qy)(X||(X=se` ${0} `),(0,v.u)(e,e=>e.uid,e=>{const i=this._todoListSupportsFeature(C.Ed.DELETE_TODO_ITEM)&&!this._todoListSupportsFeature(C.Ed.UPDATE_TODO_ITEM),s=e.status!==C.aO.Completed&&this._reordering,o=this._getDueDate(e),a=o&&!e.due.includes("T")&&(0,_.r)(new Date,o);return(0,m.qy)(G||(G=se` <ha-check-list-item left .hasMeta="${0}" class="editRow ${0}" .selected="${0}" .disabled="${0}" .checkboxDisabled="${0}" .indeterminate="${0}" .noninteractive="${0}" .itemId="${0}" ="${0}" ="${0}" separate-checkbox-click -selected="${0}" ="${0}"> <div class="column"> <span class="summary">${0}</span> ${0} ${0} </div> ${0} </ha-check-list-item> `),s||i,(0,g.H)({draggable:e.status!==C.aO.Completed,completed:e.status===C.aO.Completed,multiline:Boolean(e.description||e.due)}),e.status===C.aO.Completed,t,!this._todoListSupportsFeature(C.Ed.UPDATE_TODO_ITEM),!e.status,!this._todoListSupportsFeature(C.Ed.UPDATE_TODO_ITEM),e.uid,this._completeItem,this._itemTap,this._requestSelected,this._handleKeydown,e.summary,e.description?(0,m.qy)(Q||(Q=se`<ha-markdown-element class="description" .content="${0}"></ha-markdown-element>`),e.description):m.s6,o?(0,m.qy)(J||(J=se`<div class="due ${0}"> <ha-svg-icon .path="${0}"></ha-svg-icon>${0} </div>`),o<new Date?"overdue":"",oe,a?this.hass.localize("ui.panel.lovelace.cards.todo-list.today"):(0,m.qy)(Y||(Y=se`<ha-relative-time capitalize .hass="${0}" .datetime="${0}"></ha-relative-time>`),this.hass,o)):m.s6,s?(0,m.qy)(ee||(ee=se` <ha-svg-icon .title="${0}" class="reorderButton handle" .path="${0}" slot="meta"> </ha-svg-icon> `),this.hass.localize("ui.panel.lovelace.cards.todo-list.drag_and_drop"),de):i?(0,m.qy)(te||(te=se`<ha-icon-button .title="${0}" class="deleteItemButton" .path="${0}" .itemId="${0}" slot="meta" ="${0}"> </ha-icon-button>`),this.hass.localize("ui.panel.lovelace.cards.todo-list.delete_item"),ae,e.uid,this._deleteItem):m.s6)}))}_todoListSupportsFeature(e){const t=this.hass.states[this._entityId];return t&&(0,E.$)(t,e)}async _subscribeItems(){this._unsubItems&&(this._unsubItems.then(e=>e()),this._unsubItems=void 0),this.hass&&this._entityId&&this._entityId in this.hass.states&&(this._unsubItems=(0,C.Xf)(this.hass,this._entityId,e=>{this._items=e.items}))}_getItem(e){var t;return null===(t=this._items)||void 0===t?void 0:t.find(t=>t.uid===e)}_requestSelected(e){e.stopPropagation()}_handleKeydown(e){" "!==e.key?"Enter"===e.key&&this._itemTap(e):this._completeItem(e)}_itemTap(e){this._config.item_tap_action&&this._config.item_tap_action!==ce?this._config.item_tap_action===ue&&this._completeItem(e):this._openItem(e)}_openItem(e){if(e.stopPropagation(),e.composedPath().find(e=>["input","a","button"].includes(e.localName)))return;const t=this._getItem(e.currentTarget.itemId);(0,O.X)(this,{entity:this._entityId,item:t})}async _completeItem(e){let t,i;"keydown"===e.type&&(i=this._list,t=i.getFocusedItemIndex());const s=this._getItem(e.currentTarget.itemId);s&&(await(0,C.fk)(this.hass,this._entityId,{uid:s.uid,summary:s.summary,status:s.status===C.aO.NeedsAction?C.aO.Completed:C.aO.NeedsAction}),void 0!==t&&i&&(await this.updateComplete,await i.updateComplete,i.focusItemAtIndex(t)))}_handleCompletedMenuSelect(e){var t;"clear"===(null===(t=e.detail)||void 0===t||null===(t=t.item)||void 0===t?void 0:t.value)&&this._clearCompletedItems()}_clearCompletedItems(){if(!this.hass)return;const e=this._getCheckedItems(this._items).map(e=>e.uid);(0,k.dk)(this,{title:this.hass.localize("ui.panel.lovelace.cards.todo-list.delete_confirm_title"),text:this.hass.localize("ui.panel.lovelace.cards.todo-list.delete_confirm_text",{number:e.length}),dismissText:this.hass.localize("ui.common.cancel"),confirmText:this.hass.localize("ui.common.delete"),destructive:!0,confirm:()=>{(0,C.K1)(this.hass,this._entityId,e)}})}get _newItem(){return this._input}async _addItem(e){const t=this._newItem;var i;if(t.value.length>0)if(null!==(i=this._config)&&void 0!==i&&i.due_date_period){const e={summary:t.value,status:C.aO.NeedsAction};await(0,O.X)(this,{entity:this._entityId,item:e})}else(0,C.wE)(this.hass,this._entityId,{summary:t.value});t.value="",e&&t.focus()}_deleteItem(e){const t=this._getItem(e.target.itemId);t&&(0,C.K1)(this.hass,this._entityId,[t.uid])}_addKeyPress(e){"Enter"===e.key&&this._addItem(null)}_handlePrimaryMenuSelect(e){var t;"reorder"===(null===(t=e.detail)||void 0===t||null===(t=t.item)||void 0===t?void 0:t.value)&&this._toggleReorder()}_toggleReorder(){this._reordering=!this._reordering}async _itemMoved(e){e.stopPropagation();const{oldIndex:t,newIndex:i}=e.detail;this._moveItem(t,i)}_findFirstItem(e,t,i){let s,o="up"===i?t-1:t;for(;"ha-check-list-item"!==(null===(a=s)||void 0===a?void 0:a.localName);){var a;if(s=e[o],o="up"===i?o-1:o+1,!s)break}return s}async _moveItem(e,t){var i;await this.updateComplete;const s=this._list.children,o=s[e].itemId,a=null===(i=this._findFirstItem(s,t,t<e?"up":"down"))||void 0===i?void 0:i.itemId,r=this._items.findIndex(e=>e.uid===o),n=this._items.splice(r,1)[0];if(a){const e=this._items.findIndex(e=>e.uid===a);this._items.splice(e+1,0,n)}else this._items.unshift(n);this._items=[...this._items],await(0,C.Pe)(this.hass,this._entityId,o,a)}constructor(...e){super(...e),this._reordering=!1,this._getUncheckedAndItemsWithoutStatus=(0,f.A)((e,t,i,s)=>e?this._sortItems(this._filterItems(e,[null,C.aO.NeedsAction],i),t):[]),this._getCheckedItems=(0,f.A)((e,t,i,s)=>e?this._sortItems(this._filterItems(e,[C.aO.Completed],i),t):[]),this._getUncheckedItems=(0,f.A)((e,t,i,s)=>e?this._sortItems(this._filterItems(e,[C.aO.NeedsAction],i),t):[]),this._getItemsWithoutStatus=(0,f.A)((e,t,i,s)=>e?this._sortItems(this._filterItems(e,[null],i),t):[])}}_e.styles=(0,m.AH)(ie||(ie=se`ha-card{height:100%;box-sizing:border-box;overflow-y:auto}.has-header{padding-top:0}.addRow{padding:16px;padding-bottom:0;position:relative}.addRow ha-icon-button{--ha-icon-button-size:32px}.addRow,.header{display:flex;flex-direction:row;align-items:center}.header{padding-left:var(--ha-space-4);padding-right:var(--ha-space-4);padding-inline-start:var(--ha-space-4);padding-inline-end:var(--ha-space-4);margin-top:var(--ha-space-2);justify-content:space-between;direction:var(--direction)}.header h2{color:var(--primary-text-color);font-size:inherit;font-weight:var(--ha-font-weight-medium)}.empty{padding:var(--ha-space-4) var(--ha-space-8);display:inline-block}.item{margin-top:var(--ha-space-2)}ha-check-list-item{min-height:40px;height:auto;--mdc-list-side-padding:var(--ha-space-5)}.row{display:flex;justify-content:space-between}.multiline .column{display:flex;flex-direction:column;margin-top:var(--ha-space-2);margin-bottom:var(--ha-space-2)}.completed .summary{text-decoration:line-through}.description,.due{font-size:var(--ha-font-size-s);color:var(--secondary-text-color)}.description{white-space:initial;overflow:hidden;display:-webkit-box;-webkit-line-clamp:3;line-clamp:3;-webkit-box-orient:vertical}.description p{margin:0}.description a{color:var(--primary-color)}.due{display:flex;align-items:center}.due ha-svg-icon{margin-right:4px;margin-inline-end:4px;margin-inline-start:initial;--mdc-icon-size:14px}.due.overdue{color:var(--warning-color)}.completed .due.overdue{color:var(--secondary-text-color)}.handle{cursor:move;cursor:grab;height:24px;padding:16px 4px}.deleteItemButton{position:relative;left:8px;inset-inline-start:8px;inset-inline-end:initial}ha-input{flex-grow:1}.divider{height:1px;background-color:var(--divider-color);margin:10px 0}.clearall{cursor:pointer}.todoList{display:block;padding:8px}.warning{color:var(--error-color)}`)),(0,o.Cg)([(0,p.MZ)({attribute:!1})],_e.prototype,"hass",void 0),(0,o.Cg)([(0,p.wk)()],_e.prototype,"_config",void 0),(0,o.Cg)([(0,p.wk)()],_e.prototype,"_entityId",void 0),(0,o.Cg)([(0,p.wk)()],_e.prototype,"_items",void 0),(0,o.Cg)([(0,p.wk)()],_e.prototype,"_reordering",void 0),(0,o.Cg)([(0,p.P)("ha-input",!0)],_e.prototype,"_input",void 0),(0,o.Cg)([(0,p.P)("ha-list")],_e.prototype,"_list",void 0),_e=(0,o.Cg)([(0,p.EM)("hui-todo-list-card")],_e),s()}catch(P){s(P)}})},12295:function(e,t,i){i.d(t,{X:function(){return a}});i(3362),i(62953);var s=i(1087);const o=()=>i.e(10734).then(i.bind(i,54653)),a=(e,t)=>{(0,s.r)(e,"show-dialog",{dialogTag:"dialog-todo-item-editor",dialogImport:o,dialogParams:t})}}}]);