/*! maintenance_supporter frontend 2.80.0 */ import{a as b,g as E,l as S}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-XMX3E3HG.js";import{a as A}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-3IZWSKBJ.js";import{K as P,a as o,b as y,c as a,f as c,h as x,l as n,m as p,q as r,w as $,x as w}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-NAI3MD3R.js";function I(){if(window.externalApp!==void 0)return!0;let h=typeof navigator<"u"&&navigator.userAgent||"";return/Home Assistant\//.test(h)&&/Android/.test(h)}function N(g){if(!g)return[];let h=[],e=g.photo_doc_id;typeof e=="string"&&h.push(e);let t=g.photo_doc_ids;Array.isArray(t)&&h.push(...t);let i=[];for(let l of h){if(typeof l!="string")continue;let d=l.trim();if(!(!d||i.includes(d))&&(i.push(d),i.length>=10))break}return i}async function q(g,h,e){let t=new FormData;t.append("entry_id",h),t.append("tags","photo"),t.append("file",e,e.name);let i=await fetch("/api/maintenance_supporter/document/upload",{method:"POST",headers:{Authorization:`Bearer ${g.auth?.data?.access_token??""}`},body:t});if(i.status===413)throw new Error("doc_too_large");if(!i.ok)throw new Error("doc_upload_failed");let l=await i.json();if(!l.id)throw new Error("doc_upload_failed");return l.id}async function v(g,h){await Promise.all(h.map(e=>g.connection.sendMessagePromise({type:"maintenance_supporter/documents/delete",doc_id:e}).catch(()=>{})))}var s=class extends x{constructor(){super(...arguments);this.entryId="";this.taskId="";this.taskName="";this.lang="en";this.checklist=[];this.adaptiveEnabled=!1;this.taskType="";this.readingUnit="";this.readings=[];this.readingHistory=[];this.restockDefault=null;this.restockUnitCost=null;this.currencySymbol="";this.parts=[];this.consumesParts=[];this.consumesInfo=[];this.requiredFields=[];this.phaseLabel="";this.requireTagScan=!1;this.viaTagScan=!1;this._open=!1;this._notes="";this._cost="";this._duration="";this._loading=!1;this._error="";this._checklistState={};this._feedback="needed";this._photos=[];this._uploadedIds=[];this._photoUploading=!1;this._readingValue="";this._readingValues={};this._restockQty="";this._completedAt="";this._usedParts={};this.checklistPrefill={};this._singlePick=I()}open(e={}){this._open||(this._open=!0,this.viaTagScan=!!e.viaTagScan,this._notes="",this._cost="",this._duration="",this._error="",this._checklistState=Object.fromEntries(this.checklist.map((t,i)=>[String(i),!!this.checklistPrefill[t]]).filter(([,t])=>t)),this._feedback="needed",this._photos.forEach(t=>URL.revokeObjectURL(t.preview)),this._photos=[],this._uploadedIds=[],this._photoUploading=!1,this._readingValue="",this._readingValues={},this._restockQty=this.restockDefault!==null?String(this.restockDefault):"",this._completedAt="",this._usedParts=Object.fromEntries(this.consumesParts.map(t=>[b(t),{...t}])))}_toggleCheck(e){let t=String(e);this._checklistState={...this._checklistState,[t]:!this._checklistState[t]}}_setFeedback(e){this._feedback=e}async _onPhotoInput(e){let t=e.target,i=Array.from(t.files??[]);if(t.value="",i.length===0)return;let l=10-this._photos.length,d=i.slice(0,Math.max(l,0));this._photoUploading=!0,this._error="";try{for(let u of d){let f=await q(this.hass,this.entryId,u);this._uploadedIds=[...this._uploadedIds,f],this._photos=[...this._photos,{id:f,preview:URL.createObjectURL(u)}]}i.length>d.length&&(this._error=r("photos_limit",this.lang).replace("{max}",String(10)))}catch(u){let f=u instanceof Error&&u.message==="doc_too_large"?"doc_too_large":"doc_upload_failed";this._error=r(f,this.lang)}finally{this._photoUploading=!1}}_removePhoto(e){let t=this._photos.find(i=>i.id===e);t&&URL.revokeObjectURL(t.preview),this._photos=this._photos.filter(i=>i.id!==e),this._uploadedIds.includes(e)&&(this._uploadedIds=this._uploadedIds.filter(i=>i!==e),v(this.hass,[e]))}async _complete(){this._loading=!0,this._error="";try{let e={type:"maintenance_supporter/task/complete",entry_id:this.entryId,task_id:this.taskId};if(this._notes&&(e.notes=this._notes),this._cost){let t=parseFloat(this._cost);!isNaN(t)&&t>=0&&(e.cost=t)}if(this._duration){let t=parseInt(this._duration,10);!isNaN(t)&&t>=0&&(e.duration=t)}if(this.checklist.length>0&&(e.checklist_state=this._checklistState),this.adaptiveEnabled&&(e.feedback=this._feedback),this._photos.length>0&&(e.photo_doc_ids=this._photos.map(t=>t.id)),this.viaTagScan&&(e.via_tag_scan=!0),this._completedAt){if(new Date(this._completedAt).getTime()>Date.now()){this._error=r("completed_at_future_error",this.lang),this._loading=!1;return}e.completed_at=this._completedAt.length===16?`${this._completedAt}:00`:this._completedAt}if(this.readings.length>0){let t={};for(let i of this.readings){let l=(this._readingValues[i.id]??"").trim();if(l==="")continue;let d=parseFloat(l.replace(",","."));isNaN(d)||(t[i.id]=d)}Object.keys(t).length>0&&(e.reading_values=t)}else if(this._readingValue!==""){let t=parseFloat(this._readingValue);isNaN(t)||(e.reading_value=t)}if(this.restockDefault!==null&&this._restockQty!==""){let t=parseFloat(this._restockQty);!isNaN(t)&&t>=1&&(e.restock_quantity=t)}this.parts.length>0&&(e.used_parts=Object.values(this._usedParts).filter(t=>Number.isFinite(t.quantity)&&t.quantity>0).map(t=>t.entry_id?{part_id:t.part_id,quantity:t.quantity,entry_id:t.entry_id}:{part_id:t.part_id,quantity:t.quantity})),await this.hass.connection.sendMessagePromise(e),this._uploadedIds=[],this._open=!1,this.dispatchEvent(new CustomEvent("task-completed"))}catch(e){this._error=A(e,this.lang,r("save_error",this.lang))}finally{this._loading=!1}}_renderReadingField(e,t){let i=this._completedAt?new Date(this._completedAt).getTime():NaN,l=E(this.readingHistory,e.id,isNaN(i)?void 0:i),d=e.unit||this.readingUnit,u=(this._readingValues[e.id]??"").trim(),f=u===""?NaN:parseFloat(u.replace(",",".")),_=l!==void 0&&!isNaN(f)&&f ${e.name}${d?` (${d})`:""} {this._readingValues={...this._readingValues,[e.id]:T.target.value}}} /> ${_?a`${r("reading_below_last",t).replace("{value}",k)}`:c} `}get _missingRequired(){let e={notes:this._notes.trim()!=="",cost:this._cost.trim()!=="",duration:this._duration.trim()!=="",photo:this._photos.length>0,user:!!this.hass?.user};return this.requiredFields.filter(t=>!e[t])}_req(e){return this.requiredFields.includes(e)?a``:c}_partsCostSuggestion(){if(this.restockDefault!==null){let i=parseFloat(this._restockQty);return this.restockUnitCost==null||!Number.isFinite(i)||i<=0?null:Math.round(this.restockUnitCost*i*100)/100}if(!this.parts.length)return null;let e=0,t=!1;for(let i of Object.values(this._usedParts)){let l=this.parts.find(d=>b({part_id:d.id,entry_id:d.entry_id})===b(i));l?.cost!=null&&(e+=l.cost*(i.quantity||1),t=!0)}return t?Math.round(e*100)/100:null}_renderCostSuggestion(e){if(this._cost.trim()!=="")return c;let t=this._partsCostSuggestion();if(t==null||t<=0)return c;let i=w(t,this.currencySymbol,e);return a``}_close(){if(this._open=!1,this._uploadedIds.length>0){let e=this._uploadedIds;this._uploadedIds=[],v(this.hass,e)}}_pickCompletedAt(){let e=new Date,t=i=>String(i).padStart(2,"0");this._completedAt=`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}T${t(e.getHours())}:${t(e.getMinutes())}:00`}render(){if(!this._open)return a``;let e=this.lang||this.hass?.language||"en";return a`
${r("complete_title",e)}${this.taskName}
${this.phaseLabel?a`
${r("phase_current",e)}: ${this.phaseLabel}
`:c} ${this.requireTagScan&&!this.viaTagScan?a`
${r("require_tag_scan_hint",e)}
`:c}
${this._error?a`
${this._error}
`:c} ${this.checklist.length>0?a`
${this.checklist.map((t,i)=>a` `)}
`:c} ${this.readings.length>0?a`
${r("readings_section",e)} ${this.readings.map(t=>this._renderReadingField(t,e))}
`:this.taskType==="reading"?a` `:c} ${this.parts.length?a`
${r("complete_parts_used",e)} ${this.parts.map(t=>{let i=b({part_id:t.id,entry_id:t.entry_id}),l=this._usedParts[i],d=l!==void 0,u=t.entry_id?{part_id:t.id,quantity:1,entry_id:t.entry_id}:{part_id:t.id,quantity:1};return a`
${d?a`{let _=parseFloat(f.target.value);this._usedParts={...this._usedParts,[i]:{...u,quantity:Number.isFinite(_)&&_>=.01?_:1}}}} />`:c}
`})}
`:this.consumesInfo.length?a`
${this.consumesInfo.map(t=>a`
${t}
`)}
`:c} ${this.restockDefault!==null?a` `:c}
${r("completed_at_optional",e)} ${this._completedAt?a`this._completedAt=t.detail.value} >`:a``}
${r("completion_photos_optional",e)}${this._req("photo")} ${this._photos.length>0?a`
${this._photos.map(t=>a`
`)}
`:c} ${this._photos.length<10?a`
${this._singlePick?a`
${r("photos_android_hint",e)}
`:c}`:a`
${r("photos_limit",e).replace("{max}",String(10))}
`}
${this.adaptiveEnabled?a` `:c}
${r("cancel",e)} 0} title=${this._missingRequired.length?this._missingRequired.map(t=>r("err_required",e).replace("{field}",r(S[t]??t,e))).join(" \xB7 "):""} > ${this._loading?r("completing",e):r("complete",e)}
`}};s.styles=[P,y` .req-mark { color: var(--error-color, #f44336); margin-left: 2px; font-weight: 600; } /* #104: one-click cost suggestion from parts — quiet link-style chip. */ .cost-suggestion { align-self: flex-start; margin-top: 4px; padding: 0; border: none; background: none; color: var(--primary-color); font-size: 12.5px; cursor: pointer; text-decoration: underline dotted; text-underline-offset: 2px; } .dialog-title { font-size: 18px; font-weight: 500; padding-bottom: 12px; } .scan-required-note { margin: -4px 0 12px; padding: 8px 10px; border-radius: 6px; background: rgba(255, 152, 0, 0.12); color: var(--primary-text-color); font-size: 13px; } .phase-line { margin-top: -8px; padding-bottom: 12px; font-size: 13px; color: var(--secondary-text-color); } .content { display: flex; flex-direction: column; gap: 16px; min-width: 300px; } .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 16px; } .consumes-hint { font-size: 13px; color: var(--secondary-text-color); border-left: 3px solid var(--primary-color); padding: 4px 8px; margin: 4px 0 8px; } /* #99: editable per-completion parts selection */ .used-parts { margin: 4px 0 8px; display: flex; flex-direction: column; gap: 4px; } .used-part-row { display: flex; align-items: center; gap: 8px; } .used-part-check { display: flex; align-items: center; gap: 6px; flex: 1; font-size: 13px; cursor: pointer; } .used-part-check input { cursor: pointer; } /* #111: whose stock this row draws on. Muted but never omitted — an unlabelled foreign pool is indistinguishable from an own part. */ .used-part-owner { color: var(--secondary-text-color); } .used-part-qty { width: 76px; padding: 4px 6px; border-radius: 4px; font: inherit; font-size: 13px; border: 1px solid var(--divider-color); background: var(--card-background-color); color: var(--primary-text-color); } .error { color: var(--error-color, #f44336); font-size: 13px; } /* .field/.field-label/.field-input come from nativeFieldStyles */ /* #161 phase 2: the per-slot reading fields */ .readings-block { display: flex; flex-direction: column; gap: 8px; } .readings-block > .field-label { margin-bottom: -4px; } .reading-warn { font-size: 12px; color: var(--warning-color, #ff9800); } .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); } /* #163: the backdate moment starts EMPTY (= now); the button seeds the HA date+time picker with the current minute instead of the picker's own 00:00 default, so a backdated completion never lands at midnight by accident. */ .backdate-pick { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px dashed var(--divider-color); border-radius: 8px; background: transparent; cursor: pointer; font: inherit; font-size: 13px; color: var(--secondary-text-color); width: fit-content; --mdc-icon-size: 18px; } .backdate-pick:hover { border-color: var(--primary-color); } .photo-pick input[type="file"] { display: none; } /* #161: several photos per completion — tiles wrap into a strip, the two pickers (camera / gallery) sit underneath while there is room left under the cap. */ .photo-pickers { display: flex; flex-wrap: wrap; gap: 8px; } .photo-strip { display: flex; flex-wrap: wrap; gap: 12px; margin: 8px 0; /* room for the remove badges above the tiles */ } .photo-limit { font-size: 12px; color: var(--secondary-text-color); } .photo-android-hint { margin-top: 4px; } .photo-preview { position: relative; width: fit-content; } /* Uniform tiles: a tiny or portrait shot must not collapse the strip. */ .photo-preview img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; display: block; background: var(--secondary-background-color, rgba(0,0,0,0.06)); } .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); } `],o([n({attribute:!1})],s.prototype,"hass",2),o([n()],s.prototype,"entryId",2),o([n()],s.prototype,"taskId",2),o([n()],s.prototype,"taskName",2),o([n()],s.prototype,"lang",2),o([n({type:Array})],s.prototype,"checklist",2),o([n({type:Boolean})],s.prototype,"adaptiveEnabled",2),o([n()],s.prototype,"taskType",2),o([n()],s.prototype,"readingUnit",2),o([n({attribute:!1})],s.prototype,"readings",2),o([n({attribute:!1})],s.prototype,"readingHistory",2),o([n({attribute:!1})],s.prototype,"restockDefault",2),o([n({attribute:!1})],s.prototype,"restockUnitCost",2),o([n()],s.prototype,"currencySymbol",2),o([n({attribute:!1})],s.prototype,"parts",2),o([n({attribute:!1})],s.prototype,"consumesParts",2),o([n({type:Array})],s.prototype,"consumesInfo",2),o([n({type:Array})],s.prototype,"requiredFields",2),o([n()],s.prototype,"phaseLabel",2),o([n({type:Boolean})],s.prototype,"requireTagScan",2),o([n({type:Boolean})],s.prototype,"viaTagScan",2),o([p()],s.prototype,"_open",2),o([p()],s.prototype,"_notes",2),o([p()],s.prototype,"_cost",2),o([p()],s.prototype,"_duration",2),o([p()],s.prototype,"_loading",2),o([p()],s.prototype,"_error",2),o([p()],s.prototype,"_checklistState",2),o([p()],s.prototype,"_feedback",2),o([p()],s.prototype,"_photos",2),o([p()],s.prototype,"_photoUploading",2),o([p()],s.prototype,"_readingValue",2),o([p()],s.prototype,"_readingValues",2),o([p()],s.prototype,"_restockQty",2),o([p()],s.prototype,"_completedAt",2),o([p()],s.prototype,"_usedParts",2),o([n({attribute:!1})],s.prototype,"checklistPrefill",2);customElements.get("maintenance-complete-dialog")||customElements.define("maintenance-complete-dialog",s);export{N as a,q as b,v as c,s as d};