/*! maintenance_supporter frontend 2.94.0 */ import{c as P,l as O,m as A}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-IRVVKPDP.js";import{a as E,g as N,k as H,m as U}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-ZA53FZUW.js";import{i as z,j as w}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-63C4ZGBD.js";import{a as C}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-K4SNNHPR.js";import{A as R,B as q,P as F,a,b as x,c,f as h,h as k,l as p,m as _,s as n,z as I}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-JE577H3E.js";var S=class{constructor(d,e){this.host=d;this.opts=e;this.photos=[];this.uploadedIds=[];this.uploading=!1;this.errorKey="";this._session=0;this._uploadEntry=new Map;this.max=e.max??10,d.addController(this)}hostConnected(){}get ids(){return this.photos.map(d=>d.id)}get remaining(){return Math.max(this.max-this.photos.length,0)}get full(){return this.remaining===0}errorText(d){return this.errorKey?n(this.errorKey,d).replace("{max}",String(this.max)):""}clearError(){this.errorKey=""}reset(d=[]){this._endSession(),this._revokeAll(),this.photos=d.map(e=>({id:e,preview:""})),this.uploadedIds=[],this._uploadEntry.clear(),this.errorKey="",this.host.requestUpdate()}async addFiles(d){if(d.length===0)return;let e=this._session,i=this.opts.hass(),t=this.opts.entryId(),s=d.slice(0,this.remaining);this.uploading=!0,this.errorKey="",this.host.requestUpdate();try{for(let r of s){let o=await O(i,t,r);if(e!==this._session){A(i,t,[o]);return}this.uploadedIds=[...this.uploadedIds,o],this._uploadEntry.set(o,t),this.photos=[...this.photos,{id:o,preview:URL.createObjectURL(r)}],this.host.requestUpdate()}d.length>s.length&&(this.errorKey="photos_limit")}catch(r){if(e!==this._session)return;this.errorKey=r instanceof Error&&r.message==="doc_too_large"?"doc_too_large":"doc_upload_failed"}finally{e===this._session&&(this.uploading=!1,this.host.requestUpdate())}}remove(d){let e=this.photos.find(i=>i.id===d);e?.preview&&URL.revokeObjectURL(e.preview),this.photos=this.photos.filter(i=>i.id!==d),this.uploadedIds.includes(d)&&(this.uploadedIds=this.uploadedIds.filter(i=>i!==d),this._discard([d])),this.host.requestUpdate()}discardOrphans(){if(this._endSession(),this.uploadedIds.length===0)return;let d=this.uploadedIds;this.uploadedIds=[],this._discard(d)}markAttached(){this._endSession(),this.uploadedIds=[],this._uploadEntry.clear()}_endSession(){this._session++,this.uploading=!1}_discard(d){let e=new Map;for(let t of d){let s=this._uploadEntry.get(t)??this.opts.entryId();this._uploadEntry.delete(t),e.set(s,[...e.get(s)??[],t])}let i=this.opts.hass();for(let[t,s]of e)A(i,t,s)}_revokeAll(){for(let d of this.photos)d.preview&&URL.revokeObjectURL(d.preview)}};function T(){if(window.externalApp!==void 0)return!0;let d=typeof navigator<"u"&&navigator.userAgent||"";return/Home Assistant\//.test(d)&&/Android/.test(d)}var L={objectSections:"msp-object-sections",printOptions:"msp-print-options",batteryRosterOpen:"msp-bf-roster-open",docSort:"msp-doc-sort",cameraLabel:"msp-camera-label",overviewTab:"msp-overview-tab",collapsedSections:"msp-collapsed-sections",chartRange:"msp-chart-range",chartHideOutliers:"msp-chart-hide-outliers",taskSort:"maintenance_supporter_sort",objectSort:"maintenance_supporter_object_sort",groupBy:"maintenance_supporter_groupby",objectView:"maintenance_supporter_object_view",objectsCache:"msp-objects-cache",gettingStartedDismissed:"msp-gs-dismissed",batteryRosterSort:"ms_bf_roster_sort"};function j(g){try{return localStorage.getItem(g)}catch{return null}}function Q(g,d){try{localStorage.setItem(g,d)}catch{}}function Y(){if(!T())return!1;let g=typeof navigator<"u"?navigator.mediaDevices:void 0;return!!g&&typeof g.getUserMedia=="function"}var J=1920,Z=.88,ee={retryMs:500,windowMs:5e3},te=new Set(["NotReadableError","AbortError","TrackStartError"]),V=80,D=/back|rear|environment|rück|hinten/i,B=/front|user|selfie|vorne/i;function K(g){let d=/camera2?\s*(\d+)/i.exec(g);return d?Number(d[1]):Number.MAX_SAFE_INTEGER}function M(g,d){if(d){let i=g.find(t=>t.label===d);if(i)return i}return g.filter(i=>i.label&&D.test(i.label)).sort((i,t)=>K(i.label)-K(t.label))[0]??null}var G=g=>g?.name||"Error",ie=g=>g?.message||"",b=class extends k{constructor(){super(...arguments);this.lang="en";this._open=!1;this._busy=!1;this._switching=!1;this._devices=[];this._deviceIndex=-1;this._switchFailed=!1;this._copied=!1;this.timing={...ee};this._facing="environment";this._stream=null;this._opening=!1;this._gen=0;this._refused=new Set;this._log=[];this._t0=0;this._lastError=""}async open(){if(this._open||this._opening)return;this._opening=!0;let e=++this._gen;try{await this._acquireAndShow(e)}finally{this._opening=!1}}_live(e){return e===this._gen&&this.isConnected}async _acquireAndShow(e){let i=typeof navigator<"u"?navigator.mediaDevices:void 0;if(!i||typeof i.getUserMedia!="function"){this._unavailable("no_media_devices");return}this._log=[],this._t0=Date.now(),this._lastError="",this._refused.clear(),this._switchFailed=!1,this._copied=!1,this._note(navigator.userAgent);let t=j(L.cameraLabel),s=await this._enumerate(i);if(!this._live(e))return;let r=M(s,t),o="refused";if(r&&(o=await this._openPatiently(i,e,this._byDevice(r))),o==="cancelled")return;if(o!=="ok"){if(o=await this._openPatiently(i,e,{video:{facingMode:{ideal:"environment"}},what:"facing environment"}),o==="cancelled")return;if(o!=="ok"){this._unavailable(this._lastError||"camera_unavailable");return}if(s=await this._enumerate(i),!this._live(e)){this._stopStream();return}}if(this._devices=s,this._deviceIndex=this._indexOfCurrent(),this._facing=this._currentFacing(),this._open=!0,await this.updateComplete,!this._live(e)){this._stopStream(),this._open=!1;return}await this._attach();let u=r?null:M(s,t),m=this._deviceIndex>=0?s[this._deviceIndex]:void 0;if(!u||u.deviceId===m?.deviceId)return;let f=await this._replace(i,e,[this._byDevice(u)],this._restoreCandidates(m));if(f!=="cancelled"){if(f==="lost"){this._unavailable("camera_lost");return}this._settle(f)}}async _openPatiently(e,i,t){let s=Date.now();for(;;){let r;try{r=await e.getUserMedia({video:t.video,audio:!1})}catch(o){let u=G(o),m=ie(o);if(this._lastError=u,this._note(`${t.what} \u2192 ${u}${m&&m!==u?`: ${m}`:""}`),!this._live(i))return"cancelled";if(!te.has(u))return"refused";if(Date.now()-s+this.timing.retryMs>this.timing.windowMs)return"busy";if(await new Promise(f=>setTimeout(f,this.timing.retryMs)),!this._live(i))return"cancelled";continue}if(!this._live(i)){for(let o of r.getTracks())o.stop();return"cancelled"}return this._stream=r,this._note(`${t.what} \u2192 ok (${this._describeTrack()})`),"ok"}}async _replace(e,i,t,s){this._switching=!0,this._stopStream();try{for(let r of t){let o=await this._openPatiently(e,i,r);if(o==="ok")return r;if(o==="cancelled")return o;if(o==="busy"){r.deviceId&&this._refused.add(r.deviceId);break}}for(let r of s){let o=await this._openPatiently(e,i,r);if(o==="ok")return"restored";if(o==="cancelled")return o}return"lost"}finally{this._switching=!1}}_settle(e){if(e==="restored"){this._switchFailed=!0;let t=this._indexOfCurrent();return t>=0&&(this._deviceIndex=t),this._attach(),!1}this._switchFailed=!1;let i=e.deviceId?this._devices.findIndex(t=>t.deviceId===e.deviceId):-1;return this._deviceIndex=i>=0?i:this._indexOfCurrent(),this._facing=this._currentFacing(),this._attach(),!0}_byDevice(e){return{video:{deviceId:{exact:e.deviceId}},what:e.label||"camera (no label)",deviceId:e.deviceId}}_restoreCandidates(e,i){let t=[],s=e?.deviceId||i;return s&&t.push({video:{deviceId:{exact:s}},what:`${e?.label||"previous camera"} (back again)`,deviceId:s}),t.push({video:{facingMode:{ideal:this._facing}},what:`facing ${this._facing} (back again)`}),t}async _attach(){let e=this._video;if(!(!e||!this._stream)){e.srcObject=this._stream;try{await e.play()}catch{}}}async _enumerate(e){if(typeof e.enumerateDevices!="function")return[];try{let i=(await e.enumerateDevices()).filter(t=>t.kind==="videoinput"&&!!t.deviceId);return this._note(`cameras: ${i.map(t=>t.label||"(no label)").join(" | ")||"none listed"}`),i}catch(i){return this._note(`enumerateDevices \u2192 ${G(i)}`),[]}}_indexOfCurrent(){let e=this._stream?.getVideoTracks()[0];if(!e)return-1;let i=e.getSettings().deviceId,t=i?this._devices.findIndex(s=>s.deviceId===i):-1;return t>=0?t:e.label?this._devices.findIndex(s=>s.label===e.label):-1}_currentFacing(){let e=this._stream?.getVideoTracks()[0],i=e?.getSettings().facingMode;if(i==="user"||i==="environment")return i;let t=(this._deviceIndex>=0?this._devices[this._deviceIndex]?.label:"")||e?.label||"";return B.test(t)?"user":D.test(t)?"environment":this._facing}_describeTrack(){let e=this._stream?.getVideoTracks()[0];if(!e)return"no track";let i=e.getSettings(),t=i.width&&i.height?`${i.width}\xD7${i.height}`:"size ?";return[e.label||"no label",t,i.facingMode].filter(Boolean).join(", ")}_note(e){this._log.push(`+${Date.now()-this._t0} ms ${e}`),this._log.length>V&&this._log.splice(1,this._log.length-V)}async _switchCamera(){let e=typeof navigator<"u"?navigator.mediaDevices:void 0;if(!e||this._devices.length<2||this._busy||this._switching)return;let i=this._gen,t=this._deviceIndex,s=t>=0?this._devices[t]:void 0,r=this._stream?.getVideoTracks()[0]?.getSettings().deviceId||s?.deviceId,o=this._facing==="user"?"environment":"user",u=this._nextCameras(t,r);!u.length&&this._refused.size&&(this._refused.clear(),u=this._nextCameras(t,r)),this._note(`switch from ${s?.label||"unknown camera"}`);let m=[...u.map(f=>this._byDevice(this._devices[f])),{video:{facingMode:{exact:o}},what:`facing ${o} (exact)`},{video:{facingMode:{ideal:o}},what:`facing ${o}`}];this._busy=!0,this._switchFailed=!1,this._copied=!1;try{let f=await this._replace(e,i,m,this._restoreCandidates(s,r));if(f==="cancelled")return;if(f==="lost"){this._unavailable("camera_lost");return}if(f!=="restored"&&!f.deviceId){if(this._isCamera(r,this._facing)){this._switchFailed=!0,await this._attach();return}this._facing=o}if(this._settle(f)&&f!=="restored"&&f.deviceId){let v=this._devices[this._deviceIndex]?.label??"";v&&Q(L.cameraLabel,B.test(v)?"":v)}}finally{this._busy=!1}}_nextCameras(e,i){let t=this._devices.length,s=[];for(let r=1;r<=(e<0?t:t-1);r++){let o=(e+r)%t,u=this._devices[o].deviceId;u===i||this._refused.has(u)||s.push(o)}return s}_isCamera(e,i){let t=this._stream?.getVideoTracks()[0]?.getSettings();return e&&t?.deviceId?t.deviceId===e:!!t?.facingMode&&t.facingMode===i}close(){this._gen++,this._stopStream(),this._open=!1,this._busy=!1,this._switching=!1}disconnectedCallback(){super.disconnectedCallback(),this._gen++,this._stopStream()}get _video(){return this.shadowRoot?.querySelector("video")??null}_stopStream(){for(let i of this._stream?.getTracks()??[])i.stop();this._stream=null;let e=this._video;e&&(e.srcObject=null)}_unavailable(e){this._stopStream(),this._open=!1,this.dispatchEvent(new CustomEvent("capture-unavailable",{detail:{reason:e},bubbles:!0,composed:!0}))}async _copyLog(){let e=this._log.join(` `),i=!1;try{navigator.clipboard?.writeText&&(await navigator.clipboard.writeText(e),i=!0)}catch{}if(!i){let t=this.shadowRoot?.querySelector(".details textarea");if(t){t.focus(),t.select();try{i=document.execCommand("copy")}catch{i=!1}}}this._copied=i}async _shoot(){let e=this._video;if(!(!e||this._busy||this._switching)){this._busy=!0;try{let i=e.videoWidth||640,t=e.videoHeight||480,s=Math.min(1,J/Math.max(i,t)),r=document.createElement("canvas");r.width=Math.round(i*s),r.height=Math.round(t*s);let o=r.getContext("2d");if(!o)throw new Error("no_canvas");o.drawImage(e,0,0,r.width,r.height);let u=await new Promise(v=>r.toBlob(v,"image/jpeg",Z));if(!u)throw new Error("no_blob");let m=new Date().toISOString().replace(/[-:]/g,"").slice(0,15),f=new File([u],`photo-${m}.jpg`,{type:"image/jpeg"});this.close(),this.dispatchEvent(new CustomEvent("photo-captured",{detail:{file:f},bubbles:!0,composed:!0}))}catch(i){this._unavailable(i instanceof Error?i.message:String(i))}finally{this._busy=!1}}}render(){if(!this._open)return h;let e=this.lang,i=this._busy||this._switching;return c`
`}};b.styles=x` :host { display: contents; } .overlay { position: fixed; inset: 0; z-index: 10000; background: #000; color: #fff; display: flex; flex-direction: column; } video { flex: 1; min-height: 0; width: 100%; object-fit: contain; background: #000; } .bar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); background: rgba(0, 0, 0, 0.8); } button { font: inherit; border-radius: 24px; padding: 10px 18px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; } .cancel { background: transparent; color: #fff; border: 1px solid rgba(255, 255, 255, 0.6); } .switch { background: transparent; color: #fff; border: 1px solid rgba(255, 255, 255, 0.6); padding: 10px 12px; } .switch[disabled] { opacity: 0.5; cursor: default; } .switch ha-icon { --mdc-icon-size: 22px; } .switch-pos { font-size: 12px; opacity: 0.85; } .switching { position: absolute; top: 45%; left: 50%; transform: translate(-50%, -50%); padding: 8px 16px; border-radius: 16px; background: rgba(0, 0, 0, 0.6); font-size: 14px; } .switch-note { position: absolute; left: 12px; right: 12px; bottom: 84px; max-height: 60%; overflow: auto; text-align: center; color: #fff; font-size: 13px; text-shadow: 0 1px 2px #000; } .details { margin-top: 6px; text-align: start; text-shadow: none; } .details summary { cursor: pointer; text-align: center; opacity: 0.85; } .details textarea { display: block; box-sizing: border-box; width: 100%; margin: 6px 0; font: 11px/1.35 monospace; color: #fff; background: rgba(255, 255, 255, 0.12); border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 6px; padding: 6px; resize: vertical; } .copy { background: transparent; color: #fff; border: 1px solid rgba(255, 255, 255, 0.6); padding: 6px 14px; font-size: 13px; } .shoot { background: var(--primary-color, #03a9f4); color: #fff; border: none; font-weight: 600; } .shoot[disabled] { opacity: 0.6; cursor: default; } .shoot ha-icon { --mdc-icon-size: 22px; } `,a([p({type:String})],b.prototype,"lang",2),a([_()],b.prototype,"_open",2),a([_()],b.prototype,"_busy",2),a([_()],b.prototype,"_switching",2),a([_()],b.prototype,"_devices",2),a([_()],b.prototype,"_deviceIndex",2),a([_()],b.prototype,"_switchFailed",2),a([_()],b.prototype,"_copied",2);customElements.get("ms-camera-capture")||customElements.define("ms-camera-capture",b);var X=x` ms-photo-picker { display: contents; } .photo-pickers { display: flex; flex-wrap: wrap; gap: 8px; } .photo-pick { display: inline-flex; flex-direction: row; 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:focus-visible { outline: 2px solid var(--primary-color); outline-offset: 2px; } .photo-pick.disabled { opacity: 0.6; cursor: default; } .photo-pick input[type="file"] { display: none; } .photo-android-hint { font-size: 12px; color: var(--secondary-text-color); margin-top: 4px; } `,y=class extends k{constructor(){super(...arguments);this.lang="en";this.disabled=!1;this.busy=!1;this.accept="image/*";this.showCamera=!0;this.showGallery=!0;this.compact=!1;this.remaining=1/0;this._singlePick=T();this._inAppCamera=Y()}createRenderRoot(){return this}get _locked(){return this.disabled||this.busy}_emit(e){e.length!==0&&this.dispatchEvent(new CustomEvent("files-picked",{detail:{files:e},bubbles:!0,composed:!0}))}_onInput(e){let i=e.target,t=Array.from(i.files??[]);i.value="",this._emit(t)}_onCameraClick(e){!this._inAppCamera||this._locked||(e.preventDefault(),this.querySelector("ms-camera-capture")?.open())}_onCameraUnavailable(){this._inAppCamera=!1,this.querySelector(".photo-pick-camera input")?.click()}_onKeydown(e){e.key!=="Enter"&&e.key!==" "||(e.preventDefault(),!this._locked&&e.currentTarget.click())}render(){if(this.remaining<=0||!this.showCamera&&!this.showGallery)return h;let e=this.lang,i=this._locked?"disabled":"",t=this.busy?n("uploading",e):n("doc_camera",e),s=n(this._singlePick?"choose_photo":"choose_photos",e);return c`