/*! maintenance_supporter frontend 2.96.0 */
import{a as P,c as R,d as K,e as G,f as Q}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-MJTDRBP6.js";import{c as se,f as ie,g as ae}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-3DX24CU6.js";import{a as F}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-3VJOJBZ5.js";import{a as Z,b as L}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-AU57O2BC.js";import{f as k}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-BYGTDXRD.js";import"/maintenance_supporter_panelfiles/panel-chunks/chunk-QLW72JHE.js";import{a as U,b as D}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-2U4DNN5T.js";import{a as Y,b as W,c as V,e as J}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-4PTWLV7V.js";import{a as ee,b as te,c as A}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-WJT4RRLS.js";import{a as X}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-BFBOHWBW.js";import{B as N,S as M,a as d,b as z,c as r,e as x,f as l,g as I,h as B,l as S,m as p,s,y as O,z as H}from"/maintenance_supporter_panelfiles/panel-chunks/chunk-N6F5RX6S.js";var $={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},j=m=>(...h)=>({_$litDirective$:m,values:h}),w=class{constructor(h){}get _$AU(){return this._$AM._$AU}_$AT(h,e,t){this._$Ct=h,this._$AM=e,this._$Ci=t}_$AS(h,e){return this.update(h,e)}update(h,e){return this.render(...e)}};var E=class extends w{constructor(h){if(super(h),this.it=l,h.type!==$.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(h){if(h===l||h==null)return this._t=void 0,this.it=h;if(h===x)return h;if(typeof h!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(h===this.it)return this._t;this.it=h;let e=[h];return e.raw=e,this._t={_$litType$:this.constructor.resultType,strings:e,values:[]}}};E.directiveName="unsafeHTML",E.resultType=1;var ne=j(E);var{I:fe}=I;var re=m=>m.strings===void 0;var ce={},oe=(m,h=ce)=>m._$AH=h;var y=j(class extends w{constructor(m){if(super(m),m.type!==$.PROPERTY&&m.type!==$.ATTRIBUTE&&m.type!==$.BOOLEAN_ATTRIBUTE)throw Error("The `live` directive is not allowed on child or event bindings");if(!re(m))throw Error("`live` bindings can only contain a single expression")}render(m){return m}update(m,[h]){if(h===x||h===l)return h;let e=m.element,t=m.name;if(m.type===$.PROPERTY){if(h===e[t])return x}else if(m.type===$.BOOLEAN_ATTRIBUTE){if(!!h===e.hasAttribute(t))return x}else if(m.type===$.ATTRIBUTE&&e.getAttribute(t)===h+"")return x;return oe(m),h}});var de=["EUR","USD","GBP","JPY","CHF","CAD","AUD","NZD","CNY","INR","BRL","CZK","PLN","RUB","SEK","NOK","DKK","UAH"],pe=(([m,h])=>Array.from({length:h-m+1},(e,t)=>m+t))(ee.currency_decimals),c=class extends B{constructor(){super(...arguments);this.budget=null;this._settings=null;this._loading=!0;this._importCsv="";this._importUnmatched=[];this._importLoading=!1;this._includeHistory=!0;this._toast="";this._testingNotification=!1;this._personTargets=[];this._testingUser="";this._users=[];this._savedViews=[];this._vacEnabled=!1;this._vacStart="";this._vacEnd="";this._vacBuffer=3;this._vacExempt=new Set;this._vacIsActive=!1;this._vacWindowEnd=null;this._vacAllTasks=[];this._vacPreview=[];this._vacPreviewLoading=!1;this._previewBusy=!1;this._vacSaving=!1;this._qrObjects=[];this._qrSelectedEntries=new Set;this._qrActions=new Set(["view"]);this._qrUrlMode="companion";this._qrBatchLoading=!1;this._qrBatchResults=[];this._qrObjectsLoaded=!1;this._exportObjects=[];this._exportSelectedEntries=new Set;this._exportObjectsLoaded=!1;this._docArchiveLoading=!1;this._loaded=!1;this._userService=null;this._sendTestNotification=async e=>{e?this._testingUser=e:this._testingNotification=!0;try{let t=await this.hass.connection.sendMessagePromise({type:"maintenance_supporter/global/test_notification",...e?{user_id:e}:{}}),i=t.message||(t.success?s("test_notification_success",this._lang):s("test_notification_failed",this._lang));this._showToast(i)}catch{this._showToast(s("test_notification_failed",this._lang))}finally{e?this._testingUser="":this._testingNotification=!1}};this._toastTimer=new ae;this._compacting=!1;this._allTemplates=[];this._templateCategories={};this._homeProfile=null;this._tplOpenGroups=new Set;this._templatesRequested=!1}get _lang(){return O(this.hass)}updated(e){super.updated(e),e.has("hass")&&this.hass&&!this._loaded?(this._loaded=!0,this._userService=new J(this.hass),this._loadSettings(),this._loadUsers()):e.has("hass")&&this.hass&&this._userService&&this._userService.updateHass(this.hass)}async _loadUsers(){if(this._userService){try{this._users=await this._userService.getUsers()}catch{this._users=[]}this._loadNotifyTargets()}}async _loadNotifyTargets(){try{let e=await this.hass.connection.sendMessagePromise({type:"maintenance_supporter/notify/user_targets"});this._personTargets=e.targets||[]}catch{this._personTargets=[]}}async _loadSettings(){this._loading=!0;try{let e=await this.hass.connection.sendMessagePromise({type:"maintenance_supporter/settings"});this._settings=e,H(this._settings.budget),this._hydrateVacationFromSettings()}catch{}try{let e=await this.hass.connection.sendMessagePromise({type:"maintenance_supporter/views/list"});this._savedViews=e.views||[]}catch{}this._loading=!1}_hydrateVacationFromSettings(){let e=this._settings?.vacation;e&&(this._vacEnabled=e.enabled,this._vacStart=e.start||"",this._vacEnd=e.end||"",this._vacBuffer=e.buffer_days,this._vacExempt=new Set(e.exempt_task_ids||[]),this._vacIsActive=e.is_active,this._vacWindowEnd=e.window_end)}_renderBatteryLifetimes(e){let t=this._settings?.general?.battery_lifetimes;if(!t||!t.length)return l;let i=this._settings?.general?.battery_lifetime_months??{},a=v=>s("lifetime_source_"+v.source,e),n=s("settings_battery_lifetime_months",e),o=v=>v.learned_models.length?r`
${s("settings_battery_lifetime_learned_models",e).replace("{list}",v.learned_models.map(f=>`${f.model} ${f.months} ${n} (${f.samples})`).join(" \xB7 "))}
`:l,_=(v,f,C)=>{let q=Number.parseInt(f.value,10);if(!Number.isFinite(q)||q<1||q>240){f.value=String(C);return}this._updateSetting("battery_lifetime_months",{...i,[v]:q}).then(le=>{le||(f.value=String(C))})},g=v=>{let f={...i};delete f[v],this._updateSetting("battery_lifetime_months",f)},u=t.filter(v=>v.in_fleet),b=t.filter(v=>!v.in_fleet),T=v=>r`
${v.type}${v.in_fleet?r` ${s("settings_battery_lifetime_in_fleet",e)} `:l}
_(v.type,f.target,v.months)} />
${s("settings_battery_lifetime_months",e)}
${a(v)}
${v.source==="override"?r`g(v.type)}>${s("settings_battery_lifetime_reset",e)} `:l}
${o(v)}
`;return r`
${s("settings_battery_lifetimes",e)}
${s("settings_battery_lifetimes_hint",e)}
${u.map(T)}
${b.length?r`${b.length} × ${b.map(T)} `:l}
`}_renderBatteryNotesHint(e){let t=this._settings?.general?.battery_notes;if(!t||!t.devices)return l;let i=this._settings?.general?.battery_low_percent??20,a=t.default>i,n=s("bn_summary",e).replace("{name}","Battery Notes").replace("{pct}",String(t.default)).replace("{n}",String(t.devices)),o=(a?s("bn_above_floor",e).replace("{name}","Battery Notes"):s("bn_floor_decides",e)).replace("{floor}",String(i)),_=n.search(/[::]/),g=_<0?n:n.slice(0,_),u=_<0?"":n.slice(_);return r`
${g} ${u}
${t.overrides.length?r` · ${s("bn_overrides",e).replace("{n}",String(t.overrides.length+t.more))}
${t.overrides.map((b,T)=>r`${T?" \xB7 ":" "}${b.device_id?r`${b.name} `:b.name} (${b.threshold} %)`)}
${t.more?r` ${s("bn_more",e).replace("{n}",String(t.more))} `:l}`:l}
${o}
`}_renderMemberAvatars(e){if(!this._users.length)return l;let t=this._settings?.member_display||{};return r`
${s("member_avatars",e)}
${s("member_avatars_hint",e)}
${this._users.map(i=>{let a=W(i),n=t[i.id]||{};return r`
${V(a)}
${i.name}
this._setMemberAvatar(i.id,{initials:o.target.value})} />
${Y.map(o=>r`
this._setMemberAvatar(i.id,{color:o})}> `)}
${n.initials||n.color?r`this._setMemberAvatar(i.id,null)}>${s("member_avatar_reset",e)} `:l}
`})}
`}async _setMemberAvatar(e,t){let i={...this._settings?.member_display||{}};if(t===null)delete i[e];else{let a={...i[e]||{},...t};"initials"in t&&!(t.initials||"").trim()&&delete a.initials,Object.keys(a).length?i[e]=a:delete i[e]}await this._updateSetting("member_display",i);try{this._users=await this._userService?.getUsers(!0)??this._users}catch{}}async _updateSetting(e,t){let i=await this._ws({type:"maintenance_supporter/global/update",settings:{[e]:t}});return i?(this._settings=i,H(this._settings.budget),ie(),this._showToast(s("settings_saved",this._lang)),this.dispatchEvent(new CustomEvent("settings-changed")),!0):(this.requestUpdate(),!1)}_showToast(e){this._toast=e,this._toastTimer.schedule(()=>{this._toast=""})}disconnectedCallback(){super.disconnectedCallback(),this._toastTimer.clear(),this._toast=""}_ws(e,t,i){return X(this,e,{fallbackKey:t,busy:i,onError:a=>this._showToast(a)})}async _compactReferenceNumbers(){let e=this._lang;if(this._compacting||!window.confirm(s("settings_compact_refs_confirm",e)))return;let t=await this._ws({type:"maintenance_supporter/reference_numbers/compact"},"action_error",i=>{this._compacting=i});t&&this._showToast(s("settings_compact_refs_done",e).replace("{objects}",String(t.objects)).replace("{tasks}",String(t.tasks)).replace("{completions}",String(t.completions)))}_onBoundedIntChange(e,t,i,a,n){let o=e.target,_=parseInt(o.value,10);if(Number.isInteger(_)&&_>=i&&_<=a){this._updateSetting(t,_).then(g=>{g||(o.value=String(n))});return}this._showToast(s("settings_value_out_of_range",this._lang).replace("{min}",String(i)).replace("{max}",String(a))),o.value=String(n)}_intSetting(e,t){let[i,a]=te(e);return r` this._onBoundedIntChange(n,e,i,a,t)} />`}_downloadFile(e,t,i){U(e,t,i)}render(){let e=this._lang;return this._loading||!this._settings?r`Loading…
`:r`
${this._renderFeatures(e)}
${this._renderPanelAccess(e)}
${this._renderMemberAvatars(e)}
${this._renderGeneral(e)}
${this._renderObjectsColumns(e)}
${this._settings.general.notifications_enabled?this._renderNotifications(e):l}
${this.features.budget?this._renderBudget(e):l}
${this._renderArchive(e)}
${this._renderVacation(e)}
${this._renderPrintQr(e)}
${this._renderImportExport(e)}
${this._renderHomeProfile(e)}
${this._renderTemplateToggles(e)}
${this._toast?r`${this._toast}
`:l}
`}scrollToSection(e){requestAnimationFrame(()=>{let t=this.shadowRoot;if(!t)return;let i=t.querySelector(`[data-section="${e}"]`)??t.querySelector(`[data-section-alt="${e}"]`);i&&i.scrollIntoView({behavior:"smooth",block:"start"})})}_renderPanelAccess(e){let t=new Set(this._settings.admin_panel_user_ids||[]),i=this._users.filter(o=>!o.is_admin),a=this._settings.operator_write_enabled??!1,n=(o,_)=>{let g=new Set(t);_?g.add(o):g.delete(o),this._updateSetting("admin_panel_user_ids",[...g])};return r`
`}_renderFeatures(e){let t=this._settings.features,i=[{key:"adaptive",settingKey:"advanced_adaptive_visible",label:s("feat_adaptive",e),desc:s("feat_adaptive_desc",e)},{key:"seasonal",settingKey:"advanced_seasonal_visible",label:s("feat_seasonal",e),desc:s("feat_seasonal_desc",e)},{key:"environmental",settingKey:"advanced_environmental_visible",label:s("feat_environmental",e),desc:s("feat_environmental_desc",e)},{key:"budget",settingKey:"advanced_budget_visible",label:s("feat_budget",e),desc:s("feat_budget_desc",e)},{key:"groups",settingKey:"advanced_groups_visible",label:s("feat_groups",e),desc:s("feat_groups_desc",e)},{key:"checklists",settingKey:"advanced_checklists_visible",label:s("feat_checklists",e),desc:s("feat_checklists_desc",e)},{key:"schedule_time",settingKey:"advanced_schedule_time_visible",label:s("feat_schedule_time",e),desc:s("feat_schedule_time_desc",e)},{key:"completion_actions",settingKey:"advanced_completion_actions_visible",label:s("feat_completion_actions",e),desc:s("feat_completion_actions_desc",e)}];return r`
${s("settings_features",e)}
${s("settings_features_desc",e)}
${i.map(a=>r`
${a.label}
${a.desc}
this._updateSetting(a.settingKey,n.target.checked)} />
`)}
`}async _loadTemplates(){if(!this._templatesRequested){this._templatesRequested=!0;try{let e=await this.hass.connection.sendMessagePromise({type:"maintenance_supporter/templates",language:this._lang});this._allTemplates=e.templates||[],this._templateCategories=e.categories||{},this._homeProfile=e.profile??null}catch{}}}_renderHomeProfile(e){this._loadTemplates();let t=this._homeProfile,i=this._settings.home_type||"auto",a=t?.climate,n=a&&a.koppen?s("home_climate_value",e).replace("{koppen}",a.koppen).replace("{cold}",String(a.coldest_c??"\u2013")).replace("{warm}",String(a.warmest_c??"\u2013")):s("home_climate_unknown",e),o=G(t?.country,e);return r`
${s("home_profile_title",e)}
${s("home_profile_hint",e)}
${s("home_type_label",e)}
{this._setHomeType(_.target.value)}}>
${s("home_type_auto",e).replace("{detected}",K(t?.dwelling_detected??"unknown",e))}
${s("home_dwelling_house",e)}
${s("home_dwelling_apartment",e)}
${t&&t.dwelling_reasons.length?r`
${s("home_detected_from",e).replace("{reasons}",Q(t.dwelling_reasons,e))}
`:l}
${s("home_climate_label",e)}
${o?`${o} \xB7 `:""}${n}
${t?.regions?.length?this._renderHomeRegion(t,e):l}
${t?.hemisphere==="south"?r`
${s("home_hemisphere_south",e)}
`:l}
${t&&t.traits.length?r`
${t.traits.map(_=>r`${s(`home_trait_${_}`,e)} `)}
`:l}
`}_renderHomeRegion(e,t){let i=e.regions||[],a=this._settings.home_region||"auto",n=i.some(_=>_.code===a)?a:"auto",o=e.region_detected_name||s("home_region_none",t);return r`
${s("home_region_label",t)}
{this._setHomeRegion(_.target.value)}}>
${s("home_type_auto",t).replace("{detected}",o)}
${i.map(_=>r`${_.name} `)}
${s("home_region_hint",t)}
`}async _setHomeRegion(e){await this._updateSetting("home_region",e)&&(this._templatesRequested=!1,await this._loadTemplates())}async _setHomeType(e){await this._updateSetting("home_type",e)&&(this._templatesRequested=!1,await this._loadTemplates())}_renderTemplateToggles(e){this._loadTemplates();let t=new Set(this._settings.disabled_template_ids||[]),i=new Map;for(let n of Object.keys(this._templateCategories))i.set(n,[]);for(let n of this._allTemplates)i.has(n.category)||i.set(n.category,[]),i.get(n.category).push(n);let a=n=>this._templateCategories[n]?.["name_"+e]||this._templateCategories[n]?.name_en||n;return r`
${s("settings_templates_label",e)}
${s("settings_templates_hint",e)}
${[...i.entries()].filter(([,n])=>n.length>0).map(([n,o])=>{let _=o.filter(u=>!t.has(u.id)).length,g=this._tplOpenGroups.has(n);return r`
`})}
`}_toggleTemplate(e,t){let i=new Set(this._settings.disabled_template_ids||[]);t?i.delete(e):i.add(e),this._updateSetting("disabled_template_ids",[...i])}_toggleTplGroupOpen(e){let t=new Set(this._tplOpenGroups);t.has(e)?t.delete(e):t.add(e),this._tplOpenGroups=t}_toggleTemplateGroup(e,t){let i=new Set(this._settings.disabled_template_ids||[]);for(let a of e)t?i.delete(a):i.add(a);this._updateSetting("disabled_template_ids",[...i])}_renderObjectsColumns(e){let t=R(this._settings.objects_table_columns);return r`
${s("objects_table_columns_label",e)}
${s("objects_table_columns_hint",e)}
${P.map(i=>r`
${s(i.labelKey,e)}
this._toggleColumn(i.key,a.target.checked)}
/>
`)}
`}_toggleColumn(e,t){let i=new Set(R(this._settings.objects_table_columns));t?i.add(e):i.delete(e);let a=P.filter(n=>n.required||i.has(n.key)).map(n=>n.key);this._updateSetting("objects_table_columns",a)}_renderGeneral(e){let t=this._settings.general,i=t.notify_targets??[],a=this._settings.budget;return r`
${s("settings_general",e)}
${s("settings_default_warning",e)}
${this._intSetting("default_warning_days",t.default_warning_days)}
${s("settings_consumable_threshold",e)}
${this._intSetting("default_consumable_threshold",t.default_consumable_threshold??10)}
${s("settings_battery_low_percent",e)}
${this._intSetting("battery_low_percent",t.battery_low_percent??20)}
${s("settings_battery_recovered_percent",e)}
${this._intSetting("battery_recovered_percent",t.battery_recovered_percent??50)}
${s("settings_battery_recovered_percent_hint",e)}
${s("settings_battery_auto_record",e)}
this._updateSetting("battery_auto_record_recovery",n.target.checked)} />
${s("settings_battery_auto_record_hint",e)}
${this._renderBatteryNotesHint(e)}
${this._renderBatteryLifetimes(e)}
${s("settings_thresholds_hint",e)}
${s("settings_part_search_url",e)}
this._updateSetting("part_search_url_template",n.target.value.trim())} />
${s("settings_part_search_url_hint",e)}
${s("settings_row_actions",e)}
this._updateSetting("row_action_style",n.target.value)}>
${se.map(n=>r`
${s(`row_actions_${n}`,e)} `)}
${s("settings_ref_numbers_in_lists",e)}
this._updateSetting("ref_numbers_in_lists",n.target.checked)} />
${s("settings_ref_numbers_in_lists_hint",e)}
${this.hass?.user?.is_admin?r`
${s("settings_compact_refs",e)}
${s("settings_compact_refs",e)}
${s("settings_compact_refs_hint",e)}
`:l}
${s("settings_currency",e)}
this._updateSetting("budget_currency",n.target.value)}>
${de.map(n=>r`${n} `)}
${s("settings_currency_decimals",e)}
this._updateSetting("currency_decimals",Number(n.target.value))}>
${pe.map(n=>r`${n} `)}
${s("settings_currency_decimals_hint",e)}
${s("settings_parts_cost_mode",e)}
this._updateSetting("parts_cost_mode",n.target.value)}>
${s("settings_parts_cost_purchase",e)}
${s("settings_parts_cost_use",e)}
${s("settings_parts_cost_mode_hint",e)}
${s("settings_panel_enabled",e)}
this._updateSetting("panel_enabled",n.target.checked)} />
${t.panel_enabled?r`
${s("settings_panel_title",e)}
this._updateSetting("panel_title",n.target.value.trim())} />
`:""}
${s("settings_install_assist_sentences",e)}
this._updateSetting("install_assist_sentences",n.target.checked)} />
${s("settings_install_assist_sentences_hint",e)}
${s("settings_notifications",e)}
this._updateSetting("notifications_enabled",n.target.checked)} />
${t.notifications_enabled?r`
${s("settings_notify_service",e)}
this._updateSetting("notify_service",n.target.value.trim())} />
${i.map(n=>r` `)}
${s("test_notification",e)}
this._sendTestNotification()}>
${this._testingNotification?s("testing",e):s("send_test",e)}
${this._personTargets.length?r`
${s("notify_per_person",e)}
${this._personTargets.map(n=>r`
${n.name}
${n.services.length?n.services.join(", "):s("notify_no_own_device",e)}
this._sendTestNotification(n.user_id)}>
${this._testingUser===n.user_id?s("testing",e):s("send_test",e)}
`)}
`:l}
`:l}
${s("settings_shopping_list",e)}
this._updateSetting("shopping_list_entity",n.target.value)}>
${s("shopping_list_none",e)}
${this._todoEntities(t.shopping_list_entity||"").map(n=>r`
${n}
`)}
`}_todoEntities(e){let t=Object.keys(this.hass?.states||{}).filter(i=>i.startsWith("todo.")).sort();return e&&!t.includes(e)&&t.unshift(e),t}_renderNotifications(e){let t=this._settings.notifications,i=this._settings.actions;return r`
${s("settings_notifications",e)}
${s("settings_notify_due_soon",e)}
this._updateSetting("notify_due_soon_enabled",a.target.checked)} />
${t.due_soon_enabled?r`
${s("settings_interval_hours",e)}
${this._intSetting("notify_due_soon_interval_hours",t.due_soon_interval_hours)}
`:l}
${s("settings_notify_overdue",e)}
this._updateSetting("notify_overdue_enabled",a.target.checked)} />
${t.overdue_enabled?r`
${s("settings_interval_hours",e)}
${this._intSetting("notify_overdue_interval_hours",t.overdue_interval_hours)}
`:l}
${s("settings_notify_triggered",e)}
this._updateSetting("notify_triggered_enabled",a.target.checked)} />
${t.triggered_enabled?r`
${s("settings_interval_hours",e)}
${this._intSetting("notify_triggered_interval_hours",t.triggered_interval_hours)}
`:l}
${s("settings_quiet_hours",e)}
this._updateSetting("quiet_hours_enabled",a.target.checked)} />
${t.quiet_hours_enabled?r`
${s("settings_quiet_start",e)}
{let n=a.detail.value;n&&this._updateSetting("quiet_hours_start",n)}}
>
${s("settings_quiet_end",e)}
{let n=a.detail.value;n&&this._updateSetting("quiet_hours_end",n)}}
>
`:l}
${s("settings_max_per_day",e)}
${this._intSetting("max_notifications_per_day",t.max_per_day)}
${s("settings_bundling",e)}
this._updateSetting("notification_bundling_enabled",a.target.checked)} />
${t.bundling_enabled?r`
${s("settings_bundle_threshold",e)}
${this._intSetting("notification_bundle_threshold",t.bundle_threshold)}
`:l}
${s("settings_reminder_leads",e)}
{let n=a.target.value.split(",").map(o=>parseInt(o.trim(),10)).filter(o=>Number.isInteger(o)&&o>=0&&o<=365);this._updateSetting("reminder_lead_days",[...new Set(n)])}} />
${s("settings_reminder_leads_hint",e)}
${s("settings_notify_scope",e)}
this._updateSetting("notify_scope_view_id",a.target.value)}
>
${s("settings_notify_scope_all",e)}
${this._savedViews.map(a=>r`${a.name} `)}
${s("settings_notify_scope_hint",e)}
${s("settings_notify_completed",e)}
this._updateSetting("notify_completed",a.target.value)}>
${s("notify_completed_off",e)}
${s("notify_completed_automatic",e)}
${s("notify_completed_all",e)}
${s("settings_notify_completed_hint",e)}
${s("settings_title_style",e)}
this._updateSetting("notification_title_style",a.target.value)}>
${s("title_style_default",e)}
${s("title_style_object_name",e)}
${s("title_style_task_name",e)}
${s("settings_title_style_hint",e)}
${s("settings_notify_rule",e)}
${s("settings_notify_rule_hint",e)}
${s("settings_notify_event_only",e)}
this._updateSetting("notify_event_only",a.target.checked)} />
${s("settings_notify_event_only_hint",e)}
${s("settings_notify_extra_data",e)}
${s("settings_notify_extra_data_hint",e)}
${s("settings_actions",e)}
${s("settings_action_complete",e)}
this._updateSetting("action_complete_enabled",a.target.checked)} />
${s("settings_action_skip",e)}
this._updateSetting("action_skip_enabled",a.target.checked)} />
${s("settings_action_snooze",e)}
this._updateSetting("action_snooze_enabled",a.target.checked)} />
${i.snooze_enabled?r`
${s("settings_snooze_hours",e)}
${this._intSetting("snooze_duration_hours",i.snooze_duration_hours)}
`:l}
${s("settings_weekly_digest",e)}
this._updateSetting("weekly_digest_enabled",a.target.checked)} />
${s("settings_weekly_digest_hint",e)}
${s("settings_warranty_reminder",e)}
this._updateSetting("warranty_reminder_enabled",a.target.checked)} />
${i.warranty_reminder_enabled?r`
${s("settings_warranty_reminder_days",e)}
${this._intSetting("warranty_reminder_days",i.warranty_reminder_days)}
`:l}
${s("settings_warranty_reminder_hint",e)}
`}_renderBudget(e){let t=this._settings.budget;return r`
${s("settings_budget",e)}
${s("settings_budget_monthly",e)}
this._updateSetting("budget_monthly",parseFloat(i.target.value)||0)} />
${s("settings_budget_yearly",e)}
this._updateSetting("budget_yearly",parseFloat(i.target.value)||0)} />
${s("settings_budget_alerts",e)}
this._updateSetting("budget_alerts_enabled",i.target.checked)} />
${t.alerts_enabled?r`
${s("settings_budget_threshold",e)}
${this._intSetting("budget_alert_threshold",t.alert_threshold_pct)}
`:l}
`}_renderArchive(e){let t=this._settings.archive??{oneoff_days:14,delete_archived_oneoff_days:0};return r`
${s("settings_archive",e)}
${s("settings_archive_desc",e)}
${s("settings_archive_oneoff_days",e)}
${this._intSetting("archive_oneoff_days",t.oneoff_days)}
${s("settings_delete_archived_oneoff_days",e)}
${this._intSetting("delete_archived_oneoff_days",t.delete_archived_oneoff_days)}
`}_renderVacation(e){let t=this._vacEnabled&&!this._vacIsActive&&this._vacWindowEnd&&new Date(this._vacWindowEnd)
${s("vacation_title",e)}
${this._vacIsActive?r`${s("vacation_active",e)} `:l}
${t?r`${s("vacation_ended",e)} `:l}
${s("vacation_desc",e)}
this._toggleVacationEnabled(a.target.checked)} />
${s("vacation_enable",e)}
${s("vacation_exempt_title",e)}
${i>0?r`${i} `:l}
${s("vacation_exempt_desc",e)}
${this._vacAllTasks.length===0?r`${s("vacation_load_tasks",e)} `:r`
${this._renderVacationTaskList(e)}
`}
${this._vacStart&&this._vacEnd?r`
${this._vacPreviewLoading?"\u2026":s("vacation_preview_btn",e)}
${this._vacPreview.length>0?r`${this._vacPreview.length} ${s("vacation_preview_affected",e)} `:l}
${this._vacPreview.length>0?this._renderVacationPreview(e):l}
`:l}
${this._vacIsActive||t?r`
${s("vacation_end_now",e)}
`:l}
`}_renderVacationTaskList(e){let t=new Map;for(let a of this._vacAllTasks){let n=t.get(a.object_name)||[];n.push(a),t.set(a.object_name,n)}return[...t.entries()].sort(([a],[n])=>a.localeCompare(n)).map(([a,n])=>r`
${a||s("no_objects",e)}
${n.sort((o,_)=>o.task_name.localeCompare(_.task_name)).map(o=>r`
this._toggleVacationExempt(o.task_id,_.target.checked)} />
${o.task_name}
`)}
`)}_renderVacationPreview(e){return r`
${this._vacPreview.map(t=>{let i=t.events.map(n=>{let o=`vacation_event_${n.status}`;return`${n.date} (${s(o,e)})`}).join(" \xB7 "),a=!t.will_suppress;return r`
${t.object_name} · ${t.task_name}
${t.kind==="sensor_based"?r`${s("vacation_sensor_based",e)} `:l}
${i}
this._previewActionComplete(t)}>${s("qr_action_complete",e)}
${t.kind==="time_based"&&t.allow_skip!==!1?r`this._previewActionSkip(t)}>${s("qr_action_skip",e)} `:l}
this._toggleVacationExempt(t.task_id,!a)}>
${a?s("vacation_action_unsilence",e):s("vacation_action_notify",e)}
`})}
`}async _loadAllTasksForVacation(){let e=await this._ws({type:"maintenance_supporter/objects"});if(!e)return;let t=[];for(let i of e.objects||[])for(let a of i.tasks||[])t.push({entry_id:i.entry_id,object_name:i.object.name||"",task_id:a.id,task_name:a.name||""});this._vacAllTasks=t}async _saveVacation(e){if(!this._vacSaving){this._vacSaving=!0;try{let t=await this._ws({type:"maintenance_supporter/vacation/update",...e});if(!t)return;this._vacEnabled=t.enabled,this._vacStart=t.start||"",this._vacEnd=t.end||"",this._vacBuffer=t.buffer_days,this._vacExempt=new Set(t.exempt_task_ids||[]),this._vacIsActive=t.is_active,this._vacWindowEnd=t.window_end,this.dispatchEvent(new CustomEvent("settings-changed"))}finally{this._vacSaving=!1}}}_toggleVacationEnabled(e){this._saveVacation({enabled:e})}_setVacationDate(e,t){let i={};i[e]=t||null,this._saveVacation(i)}_setVacationBuffer(e){let t=e.target,[i,a]=A,n=Number(t.value);if(t.value.trim()!==""&&Number.isInteger(n)&&n>=i&&n<=a){this._saveVacation({buffer_days:n});return}this._showToast(s("settings_value_out_of_range",this._lang).replace("{min}",String(i)).replace("{max}",String(a))),t.value=String(this._vacBuffer)}_toggleVacationExempt(e,t){let i=new Set(this._vacExempt);t?i.add(e):i.delete(e),this._saveVacation({exempt_task_ids:[...i]})}async _loadVacationPreview(){let e=await this._ws({type:"maintenance_supporter/vacation/preview"},void 0,t=>{this._vacPreviewLoading=t});e&&(this._vacPreview=e.rows||[])}async _previewActionComplete(e){if(!this._previewBusy){this._previewBusy=!0;try{if(await this._ws({type:"maintenance_supporter/task/complete",entry_id:e.entry_id,task_id:e.task_id})===void 0)return;this._showToast(s("vacation_marked_complete",this._lang)),await this._loadVacationPreview()}finally{this._previewBusy=!1}}}async _previewActionSkip(e){if(!this._previewBusy){this._previewBusy=!0;try{if(await this._ws({type:"maintenance_supporter/task/skip",entry_id:e.entry_id,task_id:e.task_id,reason:"Skipped before vacation"})===void 0)return;this._showToast(s("vacation_marked_skip",this._lang)),await this._loadVacationPreview()}finally{this._previewBusy=!1}}}async _endVacationNow(){let e=await this._ws({type:"maintenance_supporter/vacation/end_now"});e&&(this._vacEnabled=e.enabled,this._vacEnd=e.end||"",this._vacIsActive=e.is_active,this._vacWindowEnd=e.window_end,this.dispatchEvent(new CustomEvent("settings-changed")),this._showToast(s("vacation_ended",this._lang)))}_qrSelectedRows(){return this._qrSelectedEntries.size===0?this._qrObjects:this._qrObjects.filter(e=>this._qrSelectedEntries.has(e.entry_id))}_renderPrintQr(e){let t=this._qrSelectedRows(),i=t.reduce((g,u)=>g+u.task_count,0),a=t.reduce((g,u)=>g+u.quick_count,0),n=[...this._qrActions].reduce((g,u)=>g+(u==="quick_complete"?a:i),0),o=this._qrActions.size,_=n>200;return r`
${s("qr_print_title",e)}
${s("qr_print_desc",e)}
${this._qrObjectsLoaded?r`
${s("qr_print_filter",e)}
${s("qr_print_objects",e)}
${this._qrObjects.length===0?r`
${s("no_objects",e)}
`:this._qrObjects.map(g=>r`
this._toggleQrObject(g.entry_id,u.target.checked)} />
${g.name}
${g.task_count}
`)}
${s("qr_print_actions",e)}
${["view","complete","skip","quick_complete"].map(g=>{let u=g==="quick_complete"&&a===0;return r`
this._toggleQrAction(g,b.target.checked)} />
${s("qr_action_"+g,e)}${g==="quick_complete"&&a>0?` (${a})`:""}
`})}
${a===0?r`
${s("qr_print_quick_none",e)}
`:l}
${s("qr_print_url_mode",e)}
{this._qrUrlMode=g.target.value}}>
${s("qr_mode_companion",e)}
${s("qr_mode_local",e)}
${s("qr_mode_server",e)}
${s("qr_print_estimate",e)}: ${n}
${_?r` — ${s("qr_print_over_limit",e)}`:l}
${this._qrBatchLoading?s("qr_print_generating",e):s("qr_print_generate",e)}
${this._qrBatchResults.length>0?r`
${this._qrBatchResults.length} ${s("qr_print_ready",e)}
${s("qr_print_print_button",e)}
${this._qrBatchResults.map(g=>r`
${ne(g.svg)}
${g.object_name}
${g.task_name}
${s("qr_action_"+g.action,e)}
`)}
`:l}
`:r`
${s("qr_print_load",e)} `}
`}async _loadQrObjects(){let e=await this._loadObjectRows();e&&(this._qrObjects=e,this._qrObjectsLoaded=!0)}async _loadObjectRows(){let e=await this._ws({type:"maintenance_supporter/objects"});if(e)return(e.objects||[]).map(t=>({entry_id:t.entry_id,name:t.object.name,task_count:(t.tasks||[]).length,quick_count:(t.tasks||[]).filter(i=>i.quick_complete_defaults&&Object.keys(i.quick_complete_defaults).length>0).length})).sort((t,i)=>t.name.localeCompare(i.name))}_toggleQrObject(e,t){let i=new Set(this._qrSelectedEntries);if(i.size===0)for(let a of this._qrObjects)i.add(a.entry_id);t?i.add(e):i.delete(e),i.size===this._qrObjects.length&&i.clear(),this._qrSelectedEntries=i}_toggleQrAction(e,t){let i=new Set(this._qrActions);t?i.add(e):i.delete(e),this._qrActions=i}async _generateBatch(){this._qrBatchLoading=!0,this._qrBatchResults=[];try{let e={type:"maintenance_supporter/qr/batch_generate",actions:[...this._qrActions],url_mode:this._qrUrlMode};this._qrSelectedEntries.size>0&&(e.entry_ids=[...this._qrSelectedEntries]);let t=await this._ws(e);if(!t)return;this._qrBatchResults=t.qrs||[],this._qrBatchResults.length===0&&this._showToast(s("qr_print_empty",this._lang))}finally{this._qrBatchLoading=!1}}_printQrs(){if(this._qrBatchResults.length===0)return;let e=this._lang,t=this._qrBatchResults.map(o=>{let _=s("qr_action_"+o.action,e);return`
${o.svg}
${this._escapeHtml(o.object_name)}
${this._escapeHtml(o.task_name)}
${this._escapeHtml(_)}
`}).join(""),i=s("qr_print_title",e),a=`
${this._escapeHtml(i)}
${this._escapeHtml(i)} \u2014 ${this._qrBatchResults.length}
${this._escapeHtml(s("qr_print_print_button",e))}
${t}