import{a as x,b as r,c as M,d as c,e as $,f as g,g as l,i as V,j as s,k as Z,l as J,m as U,n as X,o as Q,p as tt,q as et,r as it,s as k}from"./chunk-2LLDFX26.js";import{a}from"./chunk-LO2NM3CE.js";var E=class extends ${constructor(){super(...arguments);this.label="";this.value="";this.placeholder="";this.type="text";this.required=!1;this.disabled=!1}_onInput(t){let e=t.target.value;this.value=e,this.dispatchEvent(new CustomEvent("input",{bubbles:!0,composed:!0,detail:{value:e}}))}render(){return r` `}};E.styles=x` :host { display: block; } .field { display: flex; flex-direction: column; gap: 4px; } .label { font-size: 12px; color: var(--secondary-text-color, #888); font-weight: 500; } .req { color: var(--error-color, #f44336); margin-left: 2px; } input { padding: 8px 10px; font-size: 14px; background: var(--secondary-background-color, rgba(0,0,0,0.06)); color: var(--primary-text-color); border: 1px solid var(--divider-color, rgba(255,255,255,0.12)); border-radius: 6px; font-family: inherit; width: 100%; box-sizing: border-box; outline: none; } input:focus { border-color: var(--primary-color); } input:disabled { opacity: 0.5; cursor: not-allowed; } .helper { font-size: 11px; color: var(--secondary-text-color); font-style: italic; } `,a([g()],E.prototype,"label",2),a([g()],E.prototype,"value",2),a([g()],E.prototype,"placeholder",2),a([g()],E.prototype,"type",2),a([g({type:Boolean})],E.prototype,"required",2),a([g({type:Boolean})],E.prototype,"disabled",2),a([g()],E.prototype,"step",2),a([g()],E.prototype,"min",2),a([g()],E.prototype,"max",2),a([g()],E.prototype,"pattern",2),a([g()],E.prototype,"helper",2);customElements.get("ms-textfield")||customElements.define("ms-textfield",E);var f=class extends ${constructor(){super(...arguments);this.objects=[];this._open=!1;this._loading=!1;this._error="";this._name="";this._manufacturer="";this._model="";this._serialNumber="";this._areaId="";this._installationDate="";this._warrantyExpiry="";this._documentationUrl="";this._notes="";this._haDeviceId="";this._parentEntryId="";this._entryId=null}get _lang(){return this.hass?.language??navigator.language.split("-")[0]??"en"}openCreate(){this._entryId=null,this._name="",this._manufacturer="",this._model="",this._serialNumber="",this._areaId="",this._installationDate="",this._warrantyExpiry="",this._documentationUrl="",this._notes="",this._haDeviceId="",this._parentEntryId="",this._error="",this._open=!0}openEdit(t,e){this._entryId=t,this._name=e.name||"",this._manufacturer=e.manufacturer||"",this._model=e.model||"",this._serialNumber=e.serial_number||"",this._areaId=e.area_id||"",this._installationDate=e.installation_date||"",this._warrantyExpiry=e.warranty_expiry||"",this._documentationUrl=e.documentation_url||"",this._notes=e.notes||"",this._haDeviceId=e.ha_device_id||"",this._parentEntryId=e.parent_entry_id||"",this._error="",this._open=!0}async _save(){if(!this._loading&&this._name.trim()){this._loading=!0,this._error="";try{this._entryId?await this.hass.connection.sendMessagePromise({type:"maintenance_supporter/object/update",entry_id:this._entryId,name:this._name,manufacturer:this._manufacturer||null,model:this._model||null,serial_number:this._serialNumber||null,area_id:this._areaId||null,installation_date:this._installationDate||null,warranty_expiry:this._warrantyExpiry||null,documentation_url:this._documentationUrl.trim()||null,notes:this._notes.trim()||null,ha_device_id:this._haDeviceId||null,parent_entry_id:this._parentEntryId||null}):await this.hass.connection.sendMessagePromise({type:"maintenance_supporter/object/create",name:this._name,manufacturer:this._manufacturer||null,model:this._model||null,serial_number:this._serialNumber||null,area_id:this._areaId||null,installation_date:this._installationDate||null,warranty_expiry:this._warrantyExpiry||null,documentation_url:this._documentationUrl.trim()||null,notes:this._notes.trim()||null,ha_device_id:this._haDeviceId||null,parent_entry_id:this._parentEntryId||null}),this._open=!1,this.dispatchEvent(new CustomEvent("object-saved"))}catch(t){this._error=k(t,this._lang,s("save_error",this._lang))}finally{this._loading=!1}}}_parentChoices(){return(this.objects||[]).filter(t=>t.entry_id!==this._entryId)}_close(){this._open=!1}render(){if(!this._open)return r``;let t=this._lang,e=this._entryId?s("edit_object",t):s("new_object",t);return r`
${e}
${this._error?r`
${this._error}
`:c} this._name=i.target.value} > this._manufacturer=i.target.value} > this._model=i.target.value} > this._serialNumber=i.target.value} > this._documentationUrl=i.target.value} > this._areaId=i.detail.value||""} > this._installationDate=i.target.value} > this._warrantyExpiry=i.target.value} > s("link_device_optional",t)} @value-changed=${i=>this._haDeviceId=i.detail.value?.device||""} > ${this._parentChoices().length?r``:c}
${s("cancel",this._lang)} ${this._loading?s("saving",this._lang):s("save",this._lang)}
`}};f.styles=x` .dialog-title { font-size: 18px; font-weight: 500; padding-bottom: 12px; } .content { display: flex; flex-direction: column; gap: 16px; min-width: 300px; } .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 16px; } ms-textfield { display: block; } .textarea-field { display: flex; flex-direction: column; gap: 4px; } .textarea-label { font-size: 12px; color: var(--secondary-text-color, #888); font-weight: 500; } .textarea-field textarea { padding: 8px 10px; font-size: 14px; font-family: inherit; background: var(--secondary-background-color, rgba(0,0,0,0.06)); color: var(--primary-text-color); border: 1px solid var(--divider-color); border-radius: 6px; resize: vertical; } .textarea-field textarea:focus { outline: none; border-color: var(--primary-color); } .parent-select { padding: 8px 10px; font-size: 14px; font-family: inherit; background: var(--secondary-background-color, rgba(0,0,0,0.06)); color: var(--primary-text-color); border: 1px solid var(--divider-color); border-radius: 6px; } .error { color: var(--error-color, #f44336); font-size: 13px; } `,a([g({attribute:!1})],f.prototype,"hass",2),a([g({attribute:!1})],f.prototype,"objects",2),a([l()],f.prototype,"_open",2),a([l()],f.prototype,"_loading",2),a([l()],f.prototype,"_error",2),a([l()],f.prototype,"_name",2),a([l()],f.prototype,"_manufacturer",2),a([l()],f.prototype,"_model",2),a([l()],f.prototype,"_serialNumber",2),a([l()],f.prototype,"_areaId",2),a([l()],f.prototype,"_installationDate",2),a([l()],f.prototype,"_warrantyExpiry",2),a([l()],f.prototype,"_documentationUrl",2),a([l()],f.prototype,"_notes",2),a([l()],f.prototype,"_haDeviceId",2),a([l()],f.prototype,"_parentEntryId",2),a([l()],f.prototype,"_entryId",2);customElements.get("maintenance-object-dialog")||customElements.define("maintenance-object-dialog",f);var W=class{constructor(d){this.usersCache=null;this.cacheTimestamp=0;this.CACHE_TTL_MS=6e4;this.hass=d}updateHass(d){this.hass=d}async getUsers(d=!1){let t=Date.now();if(!d&&this.usersCache&&t-this.cacheTimestampe.id===d)?.name||null}getUser(d){return!d||!this.usersCache?null:this.usersCache.find(t=>t.id===d)||null}getCurrentUserId(){return this.hass.user?.id||null}isCurrentUser(d){return d?d===this.getCurrentUserId():!1}clearCache(){this.usersCache=null,this.cacheTimestamp=0}};var yt=["cleaning","inspection","replacement","calibration","service","reading","custom"],xt=["low","normal","high"],$t=["time_based","weekdays","nth_weekday","day_of_month","sensor_based","one_time","manual"],kt=["weekdays","nth_weekday","day_of_month"],st=["threshold","counter","state_change","runtime"],wt=[...st,"compound"];function Et(){return{entityIds:"",type:"threshold",above:"",below:"",forMinutes:"0",targetValue:"",deltaMode:!1,fromState:"",toState:"",targetChanges:"",runtimeHours:""}}function It(n){return{entityIds:(n.entity_ids||(n.entity_id?[n.entity_id]:[])).join(", "),type:n.type||"threshold",above:n.trigger_above?.toString()??"",below:n.trigger_below?.toString()??"",forMinutes:n.trigger_for_minutes?.toString()??"0",targetValue:n.trigger_target_value?.toString()??"",deltaMode:n.trigger_delta_mode||!1,fromState:n.trigger_from_state||"",toState:n.trigger_to_state||"",targetChanges:n.trigger_target_changes?.toString()??"",runtimeHours:n.trigger_runtime_hours?.toString()??""}}function Tt(n){let d=n.entityIds.split(",").map(e=>e.trim()).filter(Boolean);if(d.length===0)return null;let t={entity_id:d[0],entity_ids:d,type:n.type};if(n.type==="threshold"){let e=parseFloat(n.above);isNaN(e)||(t.trigger_above=e);let i=parseFloat(n.below);isNaN(i)||(t.trigger_below=i);let o=parseInt(n.forMinutes,10);isNaN(o)||(t.trigger_for_minutes=o)}else if(n.type==="counter"){let e=parseFloat(n.targetValue);isNaN(e)||(t.trigger_target_value=e),t.trigger_delta_mode=n.deltaMode}else if(n.type==="state_change"){n.fromState&&(t.trigger_from_state=n.fromState),n.toState&&(t.trigger_to_state=n.toState);let e=parseInt(n.targetChanges,10);isNaN(e)||(t.trigger_target_changes=e)}else if(n.type==="runtime"){let e=parseFloat(n.runtimeHours);isNaN(e)||(t.trigger_runtime_hours=e)}return t}function At(n){return Array.from({length:7},(d,t)=>Q(t,n,"short"))}var h=class extends ${constructor(){super(...arguments);this.checklistsEnabled=!1;this.scheduleTimeEnabled=!1;this.completionActionsEnabled=!1;this.defaultWarningDays=7;this._open=!1;this._loading=!1;this._error="";this._entryId="";this._taskId=null;this._objectChoices=[];this._name="";this._type="custom";this._scheduleType="time_based";this._intervalDays="30";this._intervalUnit="days";this._dueDate="";this._warningDays="7";this._earliestCompletionDays="";this._intervalAnchor="completion";this._weekdays=[];this._nth="1";this._nthWeekday="5";this._domDay="1";this._domLastDay=!1;this._domBusiness=!1;this._calOffset="0";this._notes="";this._documentationUrl="";this._customIcon="";this._priority="normal";this._labels="";this._enabled=!0;this._triggerEntityId="";this._triggerEntityIds=[];this._triggerEntityLogic="any";this._triggerAttribute="";this._triggerType="threshold";this._triggerAbove="";this._triggerBelow="";this._triggerForMinutes="0";this._triggerTargetValue="";this._triggerDeltaMode=!1;this._autoCompleteOnRecovery=!1;this._triggerFromState="";this._triggerToState="";this._triggerTargetChanges="";this._triggerRuntimeHours="";this._compoundLogic="AND";this._compoundConditions=[];this._suggestedAttributes=[];this._availableAttributes=[];this._entityDomain="";this._lastPerformed="";this._nfcTagId="";this._readingUnit="";this._availableTags=[];this._responsibleUserId=null;this._assigneePool=[];this._rotationStrategy="";this._availableUsers=[];this._checklistText="";this._scheduleTime="";this._actionService="";this._actionTargetEntity="";this._actionData={};this._actionDataJsonFallback="";this._actionTesting=!1;this._actionTestResult="";this._actionTestError="";this._qcNotes="";this._qcCost="";this._qcDuration="";this._qcFeedback="";this._environmentalEntity="";this._environmentalAttribute="";this._environmentalInitial="";this._environmentalAttributeInitial="";this._userService=null}get _lang(){return this.hass?.language??navigator.language.split("-")[0]??"en"}async openCreate(t,e){this._entryId=t,this._taskId=null,this._error="",!t&&e&&e.length>0?(this._objectChoices=e.map(i=>({entry_id:i.entry_id,name:i.object.name})).sort((i,o)=>i.name.localeCompare(o.name)),this._entryId=this._objectChoices[0].entry_id):this._objectChoices=[],this._resetFields(),await Promise.all([this._loadUsers(),this._loadTags()]),this._open=!0}async openEdit(t,e){this._entryId=t,this._taskId=e.id,this._error="",this._name=e.name,this._type=e.type,this._scheduleType=e.schedule_type,this._intervalDays=e.interval_days!=null?String(e.interval_days):"",this._intervalUnit=e.interval_unit||"days",this._dueDate=e.due_date||"";let i=e.schedule;this._weekdays=i?.kind==="weekdays"?[...i.weekdays??[]]:[],this._nth=i?.kind==="nth_weekday"?String(i.nth??1):"1",this._nthWeekday=i?.kind==="nth_weekday"?String(i.weekday??5):"5",this._domDay=i?.kind==="day_of_month"&&(i.day??1)>=1?String(i.day??1):"1",this._domLastDay=i?.kind==="day_of_month"&&i.day===-1,this._domBusiness=i?.kind==="day_of_month"&&i.business===!0,this._calOffset=i?.offset?String(i.offset):"0",this._warningDays=e.warning_days.toString(),this._earliestCompletionDays=e.earliest_completion_days!=null?String(e.earliest_completion_days):"",this._intervalAnchor=e.interval_anchor||"completion",this._notes=e.notes||"",this._documentationUrl=e.documentation_url||"",this._customIcon=e.custom_icon||"",this._priority=e.priority||"normal",this._labels=(e.labels||[]).join(", "),this._enabled=e.enabled!==!1,this._lastPerformed=e.last_performed||"",this._nfcTagId=e.nfc_tag_id||"",this._readingUnit=e.reading_unit||"",this._responsibleUserId=e.responsible_user_id||null,this._assigneePool=[...e.assignee_pool||[]],this._rotationStrategy=e.rotation_strategy||"",this._checklistText=(e.checklist||[]).join(` `),this._scheduleTime=e.schedule_time||"";let o=e.on_complete_action;if(o&&o.service){this._actionService=o.service;let p=o.target?.entity_id;this._actionTargetEntity=Array.isArray(p)?p[0]||"":p||"",this._actionData=o.data&&typeof o.data=="object"?{...o.data}:{},this._actionDataJsonFallback=""}else this._actionService="",this._actionTargetEntity="",this._actionData={},this._actionDataJsonFallback="";let u=e.quick_complete_defaults;this._qcNotes=u?.notes||"",this._qcCost=u?.cost!=null?String(u.cost):"",this._qcDuration=u?.duration!=null?String(u.duration):"",this._qcFeedback=u?.feedback||"";let _=e.adaptive_config||{};if(this._environmentalEntity=_.environmental_entity||"",this._environmentalAttribute=_.environmental_attribute||"",this._environmentalInitial=this._environmentalEntity,this._environmentalAttributeInitial=this._environmentalAttribute,e.trigger_config){let p=e.trigger_config;this._triggerEntityId=p.entity_id||"",this._triggerEntityIds=p.entity_ids||(p.entity_id?[p.entity_id]:[]),this._triggerEntityLogic=p.entity_logic||"any",this._triggerAttribute=p.attribute||"",this._triggerType=p.type||"threshold",this._triggerAbove=p.trigger_above?.toString()||"",this._triggerBelow=p.trigger_below?.toString()||"",this._triggerForMinutes=p.trigger_for_minutes?.toString()||"0",this._triggerTargetValue=p.trigger_target_value?.toString()||"",this._triggerDeltaMode=p.trigger_delta_mode||!1,this._autoCompleteOnRecovery=p.auto_complete_on_recovery||!1,this._triggerFromState=p.trigger_from_state||"",this._triggerToState=p.trigger_to_state||"",this._triggerTargetChanges=p.trigger_target_changes?.toString()||"",this._triggerRuntimeHours=p.trigger_runtime_hours?.toString()||"",p.type==="compound"?(this._compoundLogic=p.compound_logic==="OR"?"OR":"AND",this._compoundConditions=(p.conditions||[]).map(It)):(this._compoundLogic="AND",this._compoundConditions=[])}else this._resetTriggerFields();this._triggerEntityId&&this._fetchEntityAttributes(this._triggerEntityId),await Promise.all([this._loadUsers(),this._loadTags()]),this._open=!0}_resetFields(){this._name="",this._type="custom",this._scheduleType="time_based",this._intervalDays="30",this._intervalUnit="days",this._dueDate="",this._warningDays=String(this.defaultWarningDays),this._earliestCompletionDays="",this._intervalAnchor="completion",this._weekdays=[],this._nth="1",this._nthWeekday="5",this._domDay="1",this._domLastDay=!1,this._domBusiness=!1,this._calOffset="0",this._notes="",this._documentationUrl="",this._customIcon="",this._priority="normal",this._labels="",this._enabled=!0,this._lastPerformed="",this._nfcTagId="",this._readingUnit="",this._responsibleUserId=null,this._assigneePool=[],this._rotationStrategy="",this._checklistText="",this._scheduleTime="",this._environmentalEntity="",this._environmentalAttribute="",this._environmentalInitial="",this._environmentalAttributeInitial="",this._actionService="",this._actionTargetEntity="",this._actionData={},this._actionDataJsonFallback="",this._actionTesting=!1,this._actionTestResult="",this._qcNotes="",this._qcCost="",this._qcDuration="",this._qcFeedback="",this._resetTriggerFields()}_resetTriggerFields(){this._triggerEntityId="",this._triggerEntityIds=[],this._triggerEntityLogic="any",this._triggerAttribute="",this._suggestedAttributes=[],this._availableAttributes=[],this._entityDomain="",this._triggerType="threshold",this._triggerAbove="",this._triggerBelow="",this._triggerForMinutes="0",this._triggerTargetValue="",this._triggerDeltaMode=!1,this._autoCompleteOnRecovery=!1,this._triggerFromState="",this._triggerToState="",this._triggerTargetChanges="",this._triggerRuntimeHours="",this._compoundLogic="AND",this._compoundConditions=[]}async _loadUsers(){this._userService||(this._userService=new W(this.hass));try{this._availableUsers=await this._userService.getUsers()}catch(t){console.error("Failed to load users:",t),this._availableUsers=[]}}_toggleAssignee(t){this._assigneePool=this._assigneePool.includes(t)?this._assigneePool.filter(e=>e!==t):[...this._assigneePool,t]}async _testAction(){let t=this._actionService.trim();if(!t||!/^[a-z][a-z0-9_]*\.[a-z0-9_]+$/.test(t)){this._actionTestResult="error",this._actionTestError="Invalid service format (expected 'domain.service')",setTimeout(()=>{this._actionTestResult="",this._actionTestError=""},5e3);return}let[e,i]=t.split(".");if(!this.hass?.services?.[e]?.[i]){this._actionTestResult="error",this._actionTestError=`Service "${t}" is not registered in Home Assistant. Check spelling and that the integration providing it is loaded.`,setTimeout(()=>{this._actionTestResult="",this._actionTestError=""},8e3);return}let o=this._actionTargetEntity.trim();if(o){let u=o.split(".")[0];if(u!==e&&!new Set(["homeassistant","scene","notify","persistent_notification"]).has(e)){this._actionTestResult="error",this._actionTestError=`Service "${t}" only works on ${e}.* entities; entity "${o}" is in ${u}.* \u2014 pick a service that matches the entity domain (e.g. ${u}.${i})`,setTimeout(()=>{this._actionTestResult="",this._actionTestError=""},8e3);return}if(!this.hass.states?.[o]){this._actionTestResult="error",this._actionTestError=`Target entity "${o}" not found in Home Assistant \u2014 the entity may have been renamed or its integration removed.`,setTimeout(()=>{this._actionTestResult="",this._actionTestError=""},8e3);return}}this._actionTestResult="ok",setTimeout(()=>{this._actionTestResult="",this._actionTestError=""},5e3)}_buildActionData(){if(this._actionDataJsonFallback.trim())try{let t=JSON.parse(this._actionDataJsonFallback);if(t&&typeof t=="object"&&!Array.isArray(t))return t}catch{}return{...this._actionData}}_serviceSchema(){let t=this._actionService.trim();if(!t||!/^[a-z][a-z0-9_]*\.[a-z0-9_]+$/.test(t))return null;let[e,i]=t.split("."),o=this.hass?.services?.[e]?.[i]?.fields;return!o||Object.keys(o).length===0?null:Object.entries(o).map(([u,_])=>({name:u,required:!!_.required,selector:_.selector||{text:{}}}))}_renderCompletionActionsSection(t){if(!this.completionActionsEnabled)return c;let e=this._serviceSchema();return r`
${s("on_complete_action_title",t)}

${s("on_complete_action_desc",t)}

{this._actionService=i.detail.value||"";let o=this._serviceSchema();if(o){let u=new Set(o.map(_=>_.name));this._actionData=Object.fromEntries(Object.entries(this._actionData).filter(([_])=>u.has(_)))}}} > s("on_complete_action_target",t)} @value-changed=${i=>{let o=i.detail.value;this._actionTargetEntity=o.target_entity||""}} >

${s("on_complete_action_target_hint",t)}

${e?r` {this._actionData={...i.detail.value}}} > `:r` {this._actionDataJsonFallback=i.target.value}} > `}
${this._actionTestResult==="ok"?r`${s("on_complete_action_test_success",t)}`:c} ${this._actionTestResult==="error"?r`
${s("on_complete_action_test_failed",t)} ${this._actionTestError?r`
${this._actionTestError}
`:c}
`:c}
${s("quick_complete_defaults_title",t)}

${s("quick_complete_defaults_desc",t)}

{this._qcNotes=i.target.value}} > {this._qcCost=i.target.value}} > {this._qcDuration=i.target.value}} >
`}async _loadTags(){try{let t=await this.hass.connection.sendMessagePromise({type:"maintenance_supporter/tags/list"});this._availableTags=t.tags||[]}catch{this._availableTags=[]}}async _fetchEntityAttributes(t){if(!t||!this.hass){this._suggestedAttributes=[],this._availableAttributes=[],this._entityDomain="";return}try{let e=await this.hass.connection.sendMessagePromise({type:"maintenance_supporter/entity/attributes",entity_id:t});this._entityDomain=e.domain||"",this._suggestedAttributes=e.suggested_attributes||[],this._availableAttributes=e.available_attributes||[]}catch{this._suggestedAttributes=[],this._availableAttributes=[],this._entityDomain=""}}async _save(){if(!this._loading&&this._name.trim()){this._loading=!0,this._error="";try{let t={type:this._taskId?"maintenance_supporter/task/update":"maintenance_supporter/task/create",entry_id:this._entryId,name:this._name,task_type:this._type,schedule_type:this._scheduleType,warning_days:parseInt(this._warningDays,10)||7},e=this._earliestCompletionDays.trim();if(t.earliest_completion_days=e===""?null:Math.max(0,parseInt(e,10)||0),this._taskId&&(t.task_id=this._taskId),this._scheduleType==="one_time"?(t.due_date=this._dueDate||null,t.interval_days=null):kt.includes(this._scheduleType)?(t.schedule=this._buildSchedule(),t.interval_days=null,this._taskId&&(t.due_date=null)):(this._taskId&&(t.due_date=null),this._scheduleType!=="manual"&&this._intervalDays?(t.interval_days=parseInt(this._intervalDays,10),t.interval_unit=this._intervalUnit,t.interval_anchor=this._intervalAnchor):this._taskId&&(t.interval_days=null,t.interval_anchor="completion")),t.notes=this._notes||null,t.documentation_url=this._documentationUrl||null,t.custom_icon=this._customIcon||null,t.priority=this._priority,t.labels=this._labels.split(",").map(_=>_.trim()).filter(Boolean),t.enabled=this._enabled,t.last_performed=this._lastPerformed||null,t.nfc_tag_id=this._nfcTagId||null,t.reading_unit=this._readingUnit.trim()||null,t.responsible_user_id=this._responsibleUserId,t.assignee_pool=this._assigneePool,t.rotation_strategy=this._assigneePool.length>=2&&this._rotationStrategy?this._rotationStrategy:null,this._scheduleType==="sensor_based"&&this._triggerType==="compound"){let _=this._compoundConditions.map(Tt).filter(p=>p!==null);if(_.length>0){let p={type:"compound",compound_logic:this._compoundLogic,conditions:_};this._autoCompleteOnRecovery&&(p.auto_complete_on_recovery=!0),t.trigger_config=p}else this._taskId&&(t.trigger_config=null)}else if(this._scheduleType==="sensor_based"&&this._triggerEntityId){let _=this._triggerEntityIds.length>0?this._triggerEntityIds:[this._triggerEntityId],p={entity_id:_[0],entity_ids:_,type:this._triggerType};if(this._triggerAttribute&&(p.attribute=this._triggerAttribute),this._autoCompleteOnRecovery&&(p.auto_complete_on_recovery=!0),_.length>1&&(p.entity_logic=this._triggerEntityLogic),this._triggerType==="threshold"){if(this._triggerAbove){let m=parseFloat(this._triggerAbove);isNaN(m)||(p.trigger_above=m)}if(this._triggerBelow){let m=parseFloat(this._triggerBelow);isNaN(m)||(p.trigger_below=m)}if(this._triggerForMinutes){let m=parseInt(this._triggerForMinutes,10);isNaN(m)||(p.trigger_for_minutes=m)}}else if(this._triggerType==="counter"){if(this._triggerTargetValue){let m=parseFloat(this._triggerTargetValue);isNaN(m)||(p.trigger_target_value=m)}p.trigger_delta_mode=this._triggerDeltaMode}else if(this._triggerType==="state_change"){if(this._triggerFromState&&(p.trigger_from_state=this._triggerFromState),this._triggerToState&&(p.trigger_to_state=this._triggerToState),this._triggerTargetChanges){let m=parseInt(this._triggerTargetChanges,10);isNaN(m)||(p.trigger_target_changes=m)}}else if(this._triggerType==="runtime"&&this._triggerRuntimeHours){let m=parseFloat(this._triggerRuntimeHours);isNaN(m)||(p.trigger_runtime_hours=m)}t.trigger_config=p}else this._taskId&&(t.trigger_config=null);if(this.scheduleTimeEnabled&&this._scheduleType==="time_based"){let _=this._scheduleTime.trim();t.schedule_time=/^([01]\d|2[0-3]):[0-5]\d$/.test(_)?_:null}if(this.checklistsEnabled){let _=this._checklistText.split(` `).map(p=>p.trim()).filter(Boolean).slice(0,100);t.checklist=_.length?_:null}if(this.completionActionsEnabled){let _=this._actionService.trim();if(_&&/^[a-z][a-z0-9_]*\.[a-z0-9_]+$/.test(_)){let I={service:_},z=this._actionTargetEntity.trim();z&&(I.target={entity_id:z});let w=this._buildActionData();Object.keys(w).length>0&&(I.data=w),t.on_complete_action=I}else t.on_complete_action=null;let p={};this._qcNotes.trim()&&(p.notes=this._qcNotes.trim());let m=parseFloat(this._qcCost);!isNaN(m)&&m>=0&&(p.cost=m);let y=parseInt(this._qcDuration,10);!isNaN(y)&&y>=0&&(p.duration=y),this._qcFeedback&&(p.feedback=this._qcFeedback),t.quick_complete_defaults=Object.keys(p).length?p:null}let i=await this.hass.connection.sendMessagePromise(t),o=this._taskId||i?.task_id,u=this._environmentalEntity!==this._environmentalInitial||this._environmentalAttribute!==this._environmentalAttributeInitial;if(o&&this._scheduleType==="sensor_based"&&u)try{await this.hass.connection.sendMessagePromise({type:"maintenance_supporter/task/set_environmental_entity",entry_id:this._entryId,task_id:o,environmental_entity:this._environmentalEntity||null,environmental_attribute:this._environmentalAttribute||null}),this._environmentalInitial=this._environmentalEntity,this._environmentalAttributeInitial=this._environmentalAttribute}catch{}this._open=!1,this.dispatchEvent(new CustomEvent("task-saved"))}catch(t){this._error=k(t,this._lang,s("save_error",this._lang))}finally{this._loading=!1}}}_close(){this._open=!1}_renderTriggerFields(){if(this._scheduleType!=="sensor_based")return c;let t=this._lang,e=this._triggerType==="compound";return r`

${s("trigger_configuration",t)}

${e?this._renderCompoundEditor():r` 0?this._triggerEntityIds.join(", "):this._triggerEntityId} @input=${i=>{let u=i.target.value.split(",").map(_=>_.trim()).filter(Boolean);this._triggerEntityId=u[0]||"",this._triggerEntityIds=u,u[0]&&this._fetchEntityAttributes(u[0])}} > ${this._triggerEntityIds.length>1?r`
`:c} ${this._availableAttributes.length>0?r`
`:r` this._triggerAttribute=i.target.value} > `} ${this._renderTriggerTypeFields()} `}
${s("auto_complete_on_recovery_help",t)}
this._intervalDays=i.target.value} > ${this._intervalDays?this._renderUnitSelect():c} `}_patchCondition(t,e){this._compoundConditions=this._compoundConditions.map((i,o)=>o===t?{...i,...e}:i)}_addCondition(){this._compoundConditions=[...this._compoundConditions,Et()]}_removeCondition(t){this._compoundConditions=this._compoundConditions.filter((e,i)=>i!==t)}_renderCompoundEditor(){let t=this._lang;return r`
${s("compound_help",t)}
${this._compoundConditions.length===0?r`
${s("compound_no_conditions",t)}
`:this._compoundConditions.map((e,i)=>this._renderCondition(e,i))} `}_renderCondition(t,e){let i=this._lang,o=e+1;return r`
${s("compound_condition",i)} ${o}
this._patchCondition(e,{entityIds:u.target.value})} >
${this._renderConditionTypeFields(t,e)}
`}_renderConditionTypeFields(t,e){let i=this._lang;return t.type==="threshold"?r` this._patchCondition(e,{above:o.target.value})}> this._patchCondition(e,{below:o.target.value})}> this._patchCondition(e,{forMinutes:o.target.value})}> `:t.type==="counter"?r` this._patchCondition(e,{targetValue:o.target.value})}> `:t.type==="state_change"?r` this._patchCondition(e,{fromState:o.target.value})}> this._patchCondition(e,{toState:o.target.value})}> this._patchCondition(e,{targetChanges:o.target.value})}> `:t.type==="runtime"?r` this._patchCondition(e,{runtimeHours:o.target.value})}> `:c}_renderUnitSelect(){let t=this._lang;return r`
`}_toggleWeekday(t){this._weekdays=this._weekdays.includes(t)?this._weekdays.filter(e=>e!==t):[...this._weekdays,t]}_buildSchedule(){let t=i=>{let o=parseInt(this._calOffset,10)||0;return o&&(i.offset=Math.max(-15,Math.min(o,15))),i};if(this._scheduleType==="weekdays")return t({kind:"weekdays",weekdays:[...this._weekdays].sort((i,o)=>i-o)});if(this._scheduleType==="nth_weekday")return t({kind:"nth_weekday",nth:parseInt(this._nth,10),weekday:parseInt(this._nthWeekday,10)});let e={kind:"day_of_month",day:this._domLastDay?-1:parseInt(this._domDay,10)||1};return this._domBusiness&&(e.business=!0),t(e)}_renderCalendarFields(){let t=this._lang,e=At(t);if(this._scheduleType==="weekdays")return r`
${e.map((i,o)=>r` `)}
${this._renderCalOffsetField()}`;if(this._scheduleType==="nth_weekday"){let i=[["1",s("ord_1",t)],["2",s("ord_2",t)],["3",s("ord_3",t)],["4",s("ord_4",t)],["5",s("ord_5",t)],["-1",s("ord_last",t)]];return r`
${this._renderCalOffsetField()}`}return this._scheduleType==="day_of_month"?r` ${this._domLastDay?c:r` this._domDay=i.target.value} >`} ${this._renderCalOffsetField()}`:c}_renderCalOffsetField(){let t=this._lang;return r` this._calOffset=e.target.value} >`}_renderTriggerTypeFields(){let t=this._lang;return this._triggerType==="threshold"?r` this._triggerAbove=e.target.value} > this._triggerBelow=e.target.value} > this._triggerForMinutes=e.target.value} > `:this._triggerType==="counter"?r` this._triggerTargetValue=e.target.value} > `:this._triggerType==="state_change"?r` this._triggerFromState=e.target.value} >
${s("state_value_help",t)}
this._triggerToState=e.target.value} > this._triggerTargetChanges=e.target.value} >
${s("target_changes_help",t)}
`:this._triggerType==="runtime"?r` this._triggerRuntimeHours=e.target.value} > `:c}render(){if(!this._open)return r``;let t=this._lang,e=this._taskId?s("edit_task",t):s("new_task",t);return r`
${e}
${this._error?r`
${this._error}
`:c} ${this._objectChoices.length>0?r`
`:c} this._name=i.target.value} >
${this._type==="reading"?r` this._readingUnit=i.target.value} >
${s("reading_unit_help",t)}
`:c}
this._labels=i.target.value} />
${s("labels_help",t)}
${this._scheduleType==="time_based"?r` this._intervalDays=i.target.value} > ${this._renderUnitSelect()}
${this.scheduleTimeEnabled?r` this._scheduleTime=i.target.value} > `:c} `:c} ${this._renderCalendarFields()} ${this._scheduleType==="one_time"?r` this._dueDate=i.target.value} > `:c} this._warningDays=i.target.value} > this._earliestCompletionDays=i.target.value} > ${this.checklistsEnabled?r`

${s("checklist_steps_optional",t)}

${s("checklist_help",t)}
`:c} this._lastPerformed=i.target.value} >
${this._availableUsers.length>=2?r`
${s("shared_with_help",t)}
${this._availableUsers.map(i=>r` `)}
${this._assigneePool.length>=2?r`
`:c} `:c} ${this._renderTriggerFields()} ${this._scheduleType==="sensor_based"?r` this._environmentalEntity=i.target.value.trim()} > ${this._environmentalEntity?r` this._environmentalAttribute=i.target.value.trim()} > `:c} `:c} this._notes=i.target.value} > this._documentationUrl=i.target.value} > this._customIcon=i.detail.value||""} > ${this._availableTags.length>0?r`
`:r` this._nfcTagId=i.target.value} >
${s("nfc_tags_empty_help",t)} ${s("nfc_tags_open_settings",t)} ·
`} ${this._renderCompletionActionsSection(t)}
${s("cancel",t)} ${this._loading?s("saving",t):s("save",t)}
`}};h.styles=x` .dialog-title { font-size: 18px; font-weight: 500; padding-bottom: 12px; } /* v1.3.0: completion-action sections */ .ca-section { border: 1px solid var(--divider-color); border-radius: 6px; padding: 8px 12px; margin-top: 8px; } .ca-section > summary { cursor: pointer; font-weight: 500; } .ca-section ms-textfield, .ca-section ha-entity-picker, .ca-section ha-service-picker, .ca-section ha-form, .ca-section .qc-feedback { width: 100%; margin-top: 8px; display: block; } .ca-section .qc-feedback { padding: 8px; border: 1px solid var(--divider-color); border-radius: 4px; background: var(--card-background-color, #fff); color: var(--primary-text-color); } .ca-test-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; } .ca-test-ok { color: var(--success-color, #4caf50); font-size: 13px; } .ca-test-error { color: var(--error-color, #f44336); font-size: 13px; font-weight: 500; } .ca-test-error-block { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; } .ca-test-error-detail { font-size: 12px; color: var(--secondary-text-color); background: rgba(244, 67, 54, 0.08); padding: 6px 8px; border-radius: 4px; line-height: 1.4; word-break: break-word; } .content { display: flex; flex-direction: column; gap: 12px; min-width: 350px; max-height: 70vh; overflow-y: auto; } @media (max-width: 600px) { .content { min-width: 0; max-height: none; } } .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 16px; } ms-textfield { display: block; } .field-label { font-size: 12px; color: var(--secondary-text-color); } .checklist-textarea { width: 100%; min-height: 88px; padding: 8px; font-family: inherit; font-size: 14px; border: 1px solid var(--divider-color); border-radius: 4px; background: var(--card-background-color); color: var(--primary-text-color); resize: vertical; box-sizing: border-box; } .field-help { font-size: 12px; color: var(--secondary-text-color); } .field-help a, .link-button { background: none; border: 0; padding: 0; color: var(--primary-color); cursor: pointer; font: inherit; text-decoration: underline; } .field-help a:hover, .link-button:hover { text-decoration: none; } /* Smaller refresh icon-button when shown next to the dropdown. */ .select-row .link-button { margin-left: 8px; text-decoration: none; font-size: 16px; } .select-row .link-button:hover { color: var(--primary-color); opacity: 0.7; } h3 { margin: 8px 0 0; font-size: 14px; color: var(--primary-color); } .select-row { display: flex; flex-direction: column; gap: 4px; } .assignee-pool { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 4px; } .checkbox-row { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; margin: 2px 0; } .checkbox-row input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; } .pool-item { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; } .pool-item input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; } .select-row label { font-size: 12px; color: var(--secondary-text-color); } .select-row select { padding: 8px; border: 1px solid var(--divider-color); border-radius: 4px; background: var(--card-background-color, #fff); color: var(--primary-text-color); font-size: 14px; } .field-label { font-size: 12px; color: var(--secondary-text-color); } .weekday-chips { display: flex; flex-wrap: wrap; gap: 6px; } .weekday-chip { padding: 6px 12px; border: 1px solid var(--divider-color); border-radius: 16px; background: var(--card-background-color, #fff); color: var(--primary-text-color); font-size: 13px; cursor: pointer; } .weekday-chip.selected { background: var(--primary-color, #03a9f4); color: var(--text-primary-color, #fff); border-color: var(--primary-color, #03a9f4); } .error { color: var(--error-color, #f44336); font-size: 13px; } .toggle-row { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; } `,a([g({attribute:!1})],h.prototype,"hass",2),a([g({type:Boolean,attribute:"checklists-enabled"})],h.prototype,"checklistsEnabled",2),a([g({type:Boolean,attribute:"schedule-time-enabled"})],h.prototype,"scheduleTimeEnabled",2),a([g({type:Boolean,attribute:"completion-actions-enabled"})],h.prototype,"completionActionsEnabled",2),a([g({type:Number,attribute:"default-warning-days"})],h.prototype,"defaultWarningDays",2),a([l()],h.prototype,"_open",2),a([l()],h.prototype,"_loading",2),a([l()],h.prototype,"_error",2),a([l()],h.prototype,"_entryId",2),a([l()],h.prototype,"_taskId",2),a([l()],h.prototype,"_objectChoices",2),a([l()],h.prototype,"_name",2),a([l()],h.prototype,"_type",2),a([l()],h.prototype,"_scheduleType",2),a([l()],h.prototype,"_intervalDays",2),a([l()],h.prototype,"_intervalUnit",2),a([l()],h.prototype,"_dueDate",2),a([l()],h.prototype,"_warningDays",2),a([l()],h.prototype,"_earliestCompletionDays",2),a([l()],h.prototype,"_intervalAnchor",2),a([l()],h.prototype,"_weekdays",2),a([l()],h.prototype,"_nth",2),a([l()],h.prototype,"_nthWeekday",2),a([l()],h.prototype,"_domDay",2),a([l()],h.prototype,"_domLastDay",2),a([l()],h.prototype,"_domBusiness",2),a([l()],h.prototype,"_calOffset",2),a([l()],h.prototype,"_notes",2),a([l()],h.prototype,"_documentationUrl",2),a([l()],h.prototype,"_customIcon",2),a([l()],h.prototype,"_priority",2),a([l()],h.prototype,"_labels",2),a([l()],h.prototype,"_enabled",2),a([l()],h.prototype,"_triggerEntityId",2),a([l()],h.prototype,"_triggerEntityIds",2),a([l()],h.prototype,"_triggerEntityLogic",2),a([l()],h.prototype,"_triggerAttribute",2),a([l()],h.prototype,"_triggerType",2),a([l()],h.prototype,"_triggerAbove",2),a([l()],h.prototype,"_triggerBelow",2),a([l()],h.prototype,"_triggerForMinutes",2),a([l()],h.prototype,"_triggerTargetValue",2),a([l()],h.prototype,"_triggerDeltaMode",2),a([l()],h.prototype,"_autoCompleteOnRecovery",2),a([l()],h.prototype,"_triggerFromState",2),a([l()],h.prototype,"_triggerToState",2),a([l()],h.prototype,"_triggerTargetChanges",2),a([l()],h.prototype,"_triggerRuntimeHours",2),a([l()],h.prototype,"_compoundLogic",2),a([l()],h.prototype,"_compoundConditions",2),a([l()],h.prototype,"_suggestedAttributes",2),a([l()],h.prototype,"_availableAttributes",2),a([l()],h.prototype,"_entityDomain",2),a([l()],h.prototype,"_lastPerformed",2),a([l()],h.prototype,"_nfcTagId",2),a([l()],h.prototype,"_readingUnit",2),a([l()],h.prototype,"_availableTags",2),a([l()],h.prototype,"_responsibleUserId",2),a([l()],h.prototype,"_assigneePool",2),a([l()],h.prototype,"_rotationStrategy",2),a([l()],h.prototype,"_availableUsers",2),a([l()],h.prototype,"_checklistText",2),a([l()],h.prototype,"_scheduleTime",2),a([l()],h.prototype,"_actionService",2),a([l()],h.prototype,"_actionTargetEntity",2),a([l()],h.prototype,"_actionData",2),a([l()],h.prototype,"_actionDataJsonFallback",2),a([l()],h.prototype,"_actionTesting",2),a([l()],h.prototype,"_actionTestResult",2),a([l()],h.prototype,"_actionTestError",2),a([l()],h.prototype,"_qcNotes",2),a([l()],h.prototype,"_qcCost",2),a([l()],h.prototype,"_qcDuration",2),a([l()],h.prototype,"_qcFeedback",2),a([l()],h.prototype,"_environmentalEntity",2),a([l()],h.prototype,"_environmentalAttribute",2);customElements.get("maintenance-task-dialog")||customElements.define("maintenance-task-dialog",h);var v=class extends ${constructor(){super(...arguments);this.entryId="";this.taskId="";this.taskName="";this.lang="en";this.checklist=[];this.adaptiveEnabled=!1;this.taskType="";this.readingUnit="";this._open=!1;this._notes="";this._cost="";this._duration="";this._loading=!1;this._error="";this._checklistState={};this._feedback="needed";this._photoDocId="";this._photoPreview="";this._photoUploading=!1;this._readingValue=""}open(){this._open||(this._open=!0,this._notes="",this._cost="",this._duration="",this._error="",this._checklistState={},this._feedback="needed",this._photoDocId="",this._photoPreview="",this._photoUploading=!1,this._readingValue="")}_toggleCheck(t){let e=String(t);this._checklistState={...this._checklistState,[e]:!this._checklistState[e]}}_setFeedback(t){this._feedback=t}async _onPhotoInput(t){let e=t.target,i=e.files?.[0];if(e.value="",!!i){this._photoUploading=!0,this._error="";try{let o=new FormData;o.append("entry_id",this.entryId),o.append("tags","photo"),o.append("file",i,i.name);let u=await fetch("/api/maintenance_supporter/document/upload",{method:"POST",headers:{Authorization:`Bearer ${this.hass.auth?.data?.access_token??""}`},body:o});if(!u.ok){this._error=u.status===413?s("doc_too_large",this.lang):s("doc_upload_failed",this.lang);return}let _=await u.json();_.id&&(this._photoDocId=_.id,this._photoPreview=URL.createObjectURL(i))}catch{this._error=s("doc_upload_failed",this.lang)}finally{this._photoUploading=!1}}}_removePhoto(){this._photoPreview&&URL.revokeObjectURL(this._photoPreview),this._photoDocId="",this._photoPreview=""}async _complete(){this._loading=!0,this._error="";try{let t={type:"maintenance_supporter/task/complete",entry_id:this.entryId,task_id:this.taskId};if(this._notes&&(t.notes=this._notes),this._cost){let e=parseFloat(this._cost);!isNaN(e)&&e>=0&&(t.cost=e)}if(this._duration){let e=parseInt(this._duration,10);!isNaN(e)&&e>=0&&(t.duration=e)}if(this.checklist.length>0&&(t.checklist_state=this._checklistState),this.adaptiveEnabled&&(t.feedback=this._feedback),this._photoDocId&&(t.photo_doc_id=this._photoDocId),this._readingValue!==""){let e=parseFloat(this._readingValue);isNaN(e)||(t.reading_value=e)}await this.hass.connection.sendMessagePromise(t),this._open=!1,this.dispatchEvent(new CustomEvent("task-completed"))}catch(t){this._error=k(t,this.lang,s("save_error",this.lang))}finally{this._loading=!1}}_close(){this._open=!1}render(){if(!this._open)return r``;let t=this.lang||this.hass?.language||"en";return r`
${s("complete_title",t)}${this.taskName}
${this._error?r`
${this._error}
`:c} ${this.checklist.length>0?r`
${this.checklist.map((e,i)=>r` `)}
`:c} ${this.taskType==="reading"?r` `:c}
${s("completion_photo_optional",t)} ${this._photoPreview?r`
`:r` `}
${this.adaptiveEnabled?r` `:c}
${s("cancel",t)} ${this._loading?s("completing",t):s("complete",t)}
`}};v.styles=x` .dialog-title { font-size: 18px; font-weight: 500; padding-bottom: 12px; } .content { display: flex; flex-direction: column; gap: 16px; min-width: 300px; } .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 16px; } .error { color: var(--error-color, #f44336); font-size: 13px; } .field { display: flex; flex-direction: column; gap: 4px; } .field-label { font-size: 12px; color: var(--secondary-text-color); } .field-input { padding: 8px 10px; font-size: 14px; background: var(--secondary-background-color, rgba(0,0,0,0.06)); color: var(--primary-text-color); border: 1px solid var(--divider-color); border-radius: 6px; font-family: inherit; width: 100%; box-sizing: border-box; } .field-input:focus { outline: none; border-color: var(--primary-color); } .photo-pick { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px dashed var(--divider-color); border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--secondary-text-color); width: fit-content; } .photo-pick:hover { border-color: var(--primary-color); } .photo-pick input[type="file"] { display: none; } .photo-preview { position: relative; width: fit-content; } .photo-preview img { max-width: 160px; max-height: 160px; border-radius: 8px; display: block; } .photo-remove { position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; border-radius: 50%; border: none; background: var(--error-color, #db4437); color: #fff; cursor: pointer; font-size: 12px; line-height: 1; } .checklist-section { display: flex; flex-direction: column; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--divider-color); margin-bottom: 4px; } .checklist-label { font-weight: 500; font-size: 13px; color: var(--secondary-text-color); } .checklist-item { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 0; font-size: 14px; } .checklist-item input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; } .feedback-section { display: flex; flex-direction: column; gap: 8px; padding: 8px 0; border-top: 1px solid var(--divider-color); } .feedback-label { font-weight: 500; font-size: 13px; color: var(--secondary-text-color); } .feedback-buttons { display: flex; gap: 8px; } .feedback-btn { flex: 1; padding: 8px 12px; border: 1px solid var(--divider-color); border-radius: 8px; background: var(--card-background-color, #fff); color: var(--primary-text-color); font-size: 13px; cursor: pointer; text-align: center; transition: all 0.2s; } .feedback-btn:hover { background: var(--secondary-background-color, #f5f5f5); } .feedback-btn.selected { background: var(--primary-color); color: var(--text-primary-color, #fff); border-color: var(--primary-color); } `,a([g({attribute:!1})],v.prototype,"hass",2),a([g()],v.prototype,"entryId",2),a([g()],v.prototype,"taskId",2),a([g()],v.prototype,"taskName",2),a([g()],v.prototype,"lang",2),a([g({type:Array})],v.prototype,"checklist",2),a([g({type:Boolean})],v.prototype,"adaptiveEnabled",2),a([g()],v.prototype,"taskType",2),a([g()],v.prototype,"readingUnit",2),a([l()],v.prototype,"_open",2),a([l()],v.prototype,"_notes",2),a([l()],v.prototype,"_cost",2),a([l()],v.prototype,"_duration",2),a([l()],v.prototype,"_loading",2),a([l()],v.prototype,"_error",2),a([l()],v.prototype,"_checklistState",2),a([l()],v.prototype,"_feedback",2),a([l()],v.prototype,"_photoDocId",2),a([l()],v.prototype,"_photoPreview",2),a([l()],v.prototype,"_photoUploading",2),a([l()],v.prototype,"_readingValue",2);customElements.get("maintenance-complete-dialog")||customElements.define("maintenance-complete-dialog",v);var R=class extends ${constructor(){super(...arguments);this._open=!1;this._saving=!1;this._error="";this._draft=null;this._originalSnapshot=null}get _lang(){return this.hass?.language||"en"}openEdit(t){this._draft={...t},this._originalSnapshot={...t},this._error="",this._open=!0}close(){this._open=!1,this._error="",this._draft=null,this._originalSnapshot=null}_set(t,e){this._draft&&(this._draft={...this._draft,[t]:e})}async _save(){if(!(!this._draft||!this._originalSnapshot)){this._saving=!0,this._error="";try{let t={type:"maintenance_supporter/task/history/update",entry_id:this._draft.entry_id,task_id:this._draft.task_id,original_timestamp:this._originalSnapshot.original_timestamp};if(this._draft.timestamp!==this._originalSnapshot.timestamp&&(t.timestamp=this._draft.timestamp),this._draft.notes!==this._originalSnapshot.notes&&(t.notes=this._draft.notes),this._draft.cost!==this._originalSnapshot.cost&&(t.cost=this._draft.cost),this._draft.duration!==this._originalSnapshot.duration&&(t.duration=this._draft.duration),this._draft.completed_by!==this._originalSnapshot.completed_by&&(t.completed_by=this._draft.completed_by),Object.keys(t).filter(i=>!["type","entry_id","task_id","original_timestamp"].includes(i)).length===0){this.close();return}await this.hass.connection.sendMessagePromise(t),this.dispatchEvent(new CustomEvent("history-entry-saved",{detail:{entry_id:this._draft.entry_id,task_id:this._draft.task_id,new_timestamp:this._draft.timestamp},bubbles:!0,composed:!0})),this.close()}catch(t){this._error=k(t,this._lang)}finally{this._saving=!1}}}render(){if(!this._open||!this._draft)return c;let t=this._lang,e=this._draft;return r`
`}};R.styles=x` :host { display: contents; } .backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 100; } .dialog { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 95vw; max-width: 480px; background: var(--card-background-color, var(--ha-card-background, #1c1c1c)); color: var(--primary-text-color); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.4); padding: 20px; display: flex; flex-direction: column; gap: 12px; z-index: 101; max-height: 90vh; overflow: auto; } h2 { margin: 0; font-size: 18px; } .entry-type { display: flex; align-items: center; gap: 6px; color: var(--secondary-text-color); font-size: 13px; } label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; } label span { color: var(--secondary-text-color); } .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; } input, textarea { padding: 8px; font-size: 14px; background: var(--secondary-background-color, #2c2c2c); color: var(--primary-text-color); border: 1px solid var(--divider-color, #444); border-radius: 6px; width: 100%; box-sizing: border-box; font-family: inherit; } .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; } button { padding: 8px 16px; font-size: 14px; border-radius: 6px; cursor: pointer; border: none; font-weight: 500; } button.cancel { background: transparent; color: var(--primary-text-color); border: 1px solid var(--divider-color); } button.save { background: var(--primary-color); color: var(--text-primary-color, white); } button[disabled] { opacity: 0.5; cursor: wait; } .error { color: var(--error-color, #d32f2f); font-size: 13px; padding: 8px; background: rgba(211,47,47,0.1); border-radius: 6px; } `,a([g({attribute:!1})],R.prototype,"hass",2),a([l()],R.prototype,"_open",2),a([l()],R.prototype,"_saving",2),a([l()],R.prototype,"_error",2),a([l()],R.prototype,"_draft",2);customElements.get("maintenance-history-edit-dialog")||customElements.define("maintenance-history-edit-dialog",R);function N(n){return n.replace(/&/g,"&").replace(//g,">").replace(/"/g,""")}function at(n){return!n.startsWith("data:image/svg+xml,")&&!n.startsWith("data:image/png;base64,")?"":N(n)}function Lt(n){return n.replace(/[/\\:*?"<>|#%]+/g,"").replace(/\s+/g,"-").toLowerCase().substring(0,100)}var T=class extends ${constructor(){super(...arguments);this.lang="en";this._open=!1;this._loading=!1;this._error="";this._viewResult=null;this._completeResult=null;this._urlMode="companion";this._entryId="";this._taskId=null;this._objectName="";this._taskName="";this._generateSeq=0}openForObject(t,e){this._entryId=t,this._taskId=null,this._objectName=e,this._taskName="",this._urlMode="companion",this._error="",this._viewResult=null,this._completeResult=null,this._open=!0,this._generate()}openForTask(t,e,i,o){this._entryId=t,this._taskId=e,this._objectName=i,this._taskName=o,this._urlMode="companion",this._error="",this._viewResult=null,this._completeResult=null,this._open=!0,this._generate()}async _generate(){let t=++this._generateSeq;this._loading=!0,this._error="",this._viewResult=null,this._completeResult=null;try{let e={type:"maintenance_supporter/qr/generate",entry_id:this._entryId,url_mode:this._urlMode};this._taskId&&(e.task_id=this._taskId);let i=[this.hass.connection.sendMessagePromise({...e,action:"view"})];this._taskId&&i.push(this.hass.connection.sendMessagePromise({...e,action:"complete"}));let o=await Promise.all(i);if(t!==this._generateSeq)return;this._viewResult=o[0],o.length>1&&(this._completeResult=o[1])}catch(e){if(t!==this._generateSeq)return;let i=e?.code,o=e?.message;this._error=i==="no_url"||typeof o=="string"&&o.includes("No Home Assistant URL")?s("qr_error_no_url",this.lang):s("qr_error",this.lang)}finally{t===this._generateSeq&&(this._loading=!1)}}_setUrlMode(t){this._urlMode!==t&&(this._urlMode=t,this._generate())}_print(){if(!this._viewResult)return;let t=this._viewResult,e=t.label.task_name?`${t.label.object_name} \u2014 ${t.label.task_name}`:t.label.object_name,i=[t.label.manufacturer,t.label.model].filter(Boolean).join(" "),o=window.open("","_blank","width=600,height=500");if(!o)return;let u=this.lang||"en",_=N(e),p=N(i),m=!!this._completeResult,y=N(s("qr_action_view",u)),I=N(s("qr_action_complete",u));o.document.write(` ${_}

${_}

${p?`
${p}
`:""}
QR Info
${y}
${m?`
QR Complete
${I}
`:""}
${N(this._viewResult.url)}