SettingsPage-DOroBYzD.js 751 KB

1234567
  1. import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,b as i,f as a,l as o,t as s,v as c,w as l}from"./client-BdOyoZJz.js";import{n as u}from"./QueryClientProvider-Clbyr4Jg.js";import{t as d}from"./useQuery-CCy0EwsM.js";import{t as f}from"./useMutation-qh3Iyscy.js";import{t as p}from"./useQueries-C87lFrjE.js";import{t as m}from"./createLucideIcon-Yo2YoYjm.js";import{a as h,i as g,l as _,n as v,o as y,r as b,t as x,u as S}from"./haSensorDisplay-CSo8Nw_c.js";import{t as C}from"./briefcase-BmuFBTLZ.js";import{t as w}from"./calendar-DiVEdzUw.js";import{t as T}from"./check-D1Pn8T1J.js";import{a as E,i as D,n as O,r as k,t as A}from"./info-DcT0QU8O.js";import{n as ee,r as j}from"./ToastContext-VFOrCCoA.js";import{t as te}from"./cog-pa-nvQzt.js";import{t as M}from"./copy-3N5VKzXz.js";import{t as N}from"./cpu-DAX4KhDZ.js";import{t as ne}from"./dollar-sign-ChtX2KHo.js";import{t as re}from"./eye-off-B6dY82pM.js";import{t as ie}from"./gauge-xO5PdXj0.js";import{t as ae}from"./grip-vertical-D4urhrwn.js";import{t as oe}from"./hard-drive-CN9rq6Uq.js";import{t as P}from"./history-BBZbf3sJ.js";import{t as F}from"./layout-grid-D4S7CgZJ.js";import{t as I}from"./link-2-Bj1oMj3O.js";import{t as L}from"./loader-circle-CB4leTZa.js";import{t as R}from"./lock-C288ZvMI.js";import{_ as se,a as ce,c as z,d as B,f as le,g as V,h as ue,i as de,l as fe,m as pe,n as me,o as he,p as ge,r as _e,s as ve,t as ye,u as be,v as H}from"./locationSensorDefaults-rSWWVL7r.js";import{c as xe,l as Se,o as Ce,t as we,u as Te}from"./CopyButton-CyNT06yS.js";import{t as Ee}from"./package-D9xR0eOt.js";import{t as De}from"./play-DROvjtg7.js";import{t as Oe}from"./qr-code-PQYGpSrt.js";import{t as ke}from"./scale-lRomj4j_.js";import{t as Ae}from"./search-BpAJdxRw.js";import{t as je}from"./settings-2-DYB5IzKV.js";import{t as Me}from"./shield-CfkeOiiL.js";import{t as Ne}from"./skip-forward-BE5zCMec.js";import{t as Pe}from"./smartphone-DOKM2tP4.js";import{n as Fe}from"./wind-CsHQYbhI.js";import{t as Ie}from"./triangle-alert-gIik0G2C.js";import{t as Le}from"./workflow-DxBrfirU.js";import{t as Re}from"./x-Dctff5l9.js";import{i as U,n as W,r as ze,t as G}from"./Card-OUAj0Ayh.js";import{t as K}from"./Button-pwVKPiYn.js";import{a as Be,f as Ve,i as He,u as Ue,v as We}from"./date-G9KUauqz.js";import{t as Ge}from"./filamentSwatchHelpers-D3oXQSGk.js";import{$t as Ke,An as q,At as qe,Cn as Je,Ct as Ye,Dn as Xe,Dt as Ze,En as Qe,Et as $e,Ft as et,Gn as tt,Gt as nt,In as rt,Jt as it,Kt as at,Ln as ot,Mn as st,N as ct,On as lt,Pn as ut,Qt as dt,Rn as ft,S as pt,Sn as mt,St as ht,Tn as gt,Ut as _t,Vn as vt,Vt as yt,Wn as bt,Wt as xt,Xt as St,Yt as Ct,Zt as wt,_t as Tt,at as Et,bn as Dt,bt as Ot,c as kt,cn as At,d as jt,dn as Mt,en as Nt,f as Pt,fn as Ft,gn as It,gt as Lt,h as Rt,hn as zt,ht as Bt,in as Vt,it as Ht,kn as Ut,kt as Wt,l as Gt,ln as Kt,m as qt,nn as Jt,nt as Yt,o as Xt,on as Zt,p as Qt,pn as $t,qt as en,rn as tn,rt as nn,u as rn,vt as an,w as on,wn as sn,x as cn,xn as ln,yt as un}from"./index-BoVbGTav.js";import{t as J}from"./Toggle-CwMiiK0g.js";import{a as dn,i as fn,n as pn,r as mn,s as hn,t as gn}from"./OverlayFrame-BUFy7NI1.js";var _n=m(`arrow-right-left`,[[`path`,{d:`m16 3 4 4-4 4`,key:`1x1c3m`}],[`path`,{d:`M20 7H4`,key:`zbl0bi`}],[`path`,{d:`m8 21-4-4 4-4`,key:`h9nckh`}],[`path`,{d:`M4 17h16`,key:`g4d7ey`}]]),vn=m(`camera-off`,[[`path`,{d:`M14.564 14.558a3 3 0 1 1-4.122-4.121`,key:`1rnrzw`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M20 20H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 .819-.175`,key:`1x3arw`}],[`path`,{d:`M9.695 4.024A2 2 0 0 1 10.004 4h3.993a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v7.344`,key:`1i84u0`}]]),yn=m(`cloud-upload`,[[`path`,{d:`M12 13v8`,key:`1l5pq0`}],[`path`,{d:`M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242`,key:`1pljnt`}],[`path`,{d:`m8 17 4-4 4 4`,key:`1quai1`}]]),bn=m(`cylinder`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5v14a9 3 0 0 0 18 0V5`,key:`aqi0yr`}]]),xn=m(`folder-archive`,[[`circle`,{cx:`15`,cy:`19`,r:`2`,key:`u2pros`}],[`path`,{d:`M20.9 19.8A2 2 0 0 0 22 18V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2h5.1`,key:`1jj40k`}],[`path`,{d:`M15 11v-1`,key:`cntcp`}],[`path`,{d:`M15 17v-2`,key:`1279jj`}]]),Sn=m(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]),Cn=m(`shield-check`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),wn=m(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]);function Tn(e){return e.length<8?`tooShort`:/[A-Z]/.test(e)?/[a-z]/.test(e)?/\d/.test(e)?/[^A-Za-z0-9]/.test(e)?null:`needsSpecial`:`needsDigit`:`needsLowercase`:`needsUppercase`}var En={PLA:0,PETG:0,"PETG-CF":40,ABS:45,ASA:45,PA:50,"PA-CF":55,PC:50,"PC-FR":50,TPU:0,PVA:0,default:0},Dn=[`PA-CF`,`PA`,`PC`,`PC-FR`,`ABS`,`ASA`,`PETG-CF`,`PETG`,`PLA`,`TPU`,`PVA`,`default`];function On(e){if(!e)return{...En};try{let t=JSON.parse(e);if(t&&typeof t==`object`&&!Array.isArray(t)){let e={};for(let[n,r]of Object.entries(t)){let t=typeof r==`number`?r:Number(r);Number.isFinite(t)&&(e[n]=Math.max(0,Math.min(65,Math.round(t))))}return e.default===void 0&&(e.default=En.default),e}}catch{}return{...En}}function kn(e){let t={};for(let n of Dn)e[n]!==void 0&&(t[n]=e[n]);for(let[n,r]of Object.entries(e))n in t||(t[n]=r);return JSON.stringify(t)}var Y=t();function An({value:e,onChange:t,disabled:n=!1}){let{t:r}=l(),i=On(e),a=(e,n)=>{let r=Math.max(0,Math.min(65,Math.round(n)));t(kn({...i,[e]:r}))};return(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-3 gap-y-1.5`,children:Dn.map(e=>{let t=i[e]??En[e]??0,o=e==="default"?r(`settings.preheatFilamentTargetsDefaultRow`,`Other / unmapped`):e;return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs ${e==="default"?`text-bambu-gray italic`:`text-bambu-gray`}`,children:o}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`input`,{type:`number`,min:0,max:65,step:1,value:t,onChange:t=>a(e,parseInt(t.target.value,10)||0),disabled:n,className:`w-16 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-xs text-right focus:outline-none focus:border-bambu-green disabled:opacity-50`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`°C`})]})]},e)})})}var X=e(n(),1);function jn(e,t,n){if(!e)return null;let r=(e[n.source]?.[t]??[]).find(e=>e.id===n.id);return r?r.name:null}var Mn={orca_cloud:`Orca Cloud`,cloud:`Bambu Cloud`,local:`Imported`,standard:`Standard`};function Nn(){let{t:e}=l(),t=u(),{showToast:n}=ee(),{data:i,isLoading:a,error:o}=d({queryKey:[`slicer-pipelines`],queryFn:()=>r.listSlicerPipelines()}),{data:s}=d({queryKey:[`slicer-presets`],queryFn:()=>r.getSlicerPresets()}),{data:c}=d({queryKey:[`printers`],queryFn:()=>r.getPrinters()}),p=f({mutationFn:({id:e,name:t,description:n,target_printer_id:i,target_kind:a,target_model_class:o,fanout_strategy:s})=>r.updateSlicerPipeline(e,{name:t,description:n,target_printer_id:i,target_kind:a,target_model_class:o,fanout_strategy:s}),onSuccess:()=>{t.invalidateQueries({queryKey:[`slicer-pipelines`]}),n(e(`settings.pipelines.toast.saved`,`Pipeline saved`),`success`)},onError:t=>{n(t.message||e(`settings.pipelines.toast.saveFailed`,`Save failed`),`error`)}}),m=f({mutationFn:e=>r.deleteSlicerPipeline(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`slicer-pipelines`]}),n(e(`settings.pipelines.toast.deleted`,`Pipeline deleted`),`success`)},onError:t=>{n(t.message||e(`settings.pipelines.toast.deleteFailed`,`Delete failed`),`error`)}}),[h,g]=(0,X.useState)(``),[_,v]=(0,X.useState)(``),y=(0,X.useMemo)(()=>i?.pipelines??[],[i?.pipelines]),b=(0,X.useMemo)(()=>{let e=new Set,t=new Set,n=!1;for(let r of y)r.target_kind===`printer_class`&&r.target_model_class?t.add(r.target_model_class):r.target_printer_id?e.add(r.target_printer_id):n=!0;return{printers:(c??[]).filter(t=>e.has(t.id)),classes:Array.from(t).sort(),anyWithoutTarget:n}},[y,c]),x=(0,X.useMemo)(()=>{let e=h.trim().toLowerCase();return y.filter(t=>{if(e&&!t.name.toLowerCase().includes(e))return!1;if(_===`none`){if(t.target_kind===`printer_class`?t.target_model_class:t.target_printer_id!==null)return!1}else if(_.startsWith(`p:`)){let e=parseInt(_.slice(2),10);if(t.target_kind===`printer_class`||t.target_printer_id!==e)return!1}else if(_.startsWith(`c:`)){let e=_.slice(2);if(t.target_kind!==`printer_class`||t.target_model_class!==e)return!1}return!0})},[y,h,_]);return(0,Y.jsxs)(G,{children:[(0,Y.jsxs)(U,{children:[(0,Y.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(Le,{className:`w-4 h-4 text-bambu-green`}),e(`settings.pipelines.title`,`Slicer Pipelines`)]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.pipelines.subtitle`,`Reusable preset bundles (printer + process + filaments + bed type). Save one from the Slice dialog and apply it with a single click on the next file.`)})]}),(0,Y.jsxs)(W,{children:[a&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}),e(`settings.pipelines.loading`,`Loading pipelines…`)]}),o&&(0,Y.jsx)(`div`,{className:`text-sm text-red-700 dark:text-red-400`,children:e(`settings.pipelines.loadError`,`Could not load pipelines.`)}),!a&&!o&&y.length>0&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-3`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 min-w-[12rem]`,children:[(0,Y.jsx)(Ae,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-bambu-gray pointer-events-none`}),(0,Y.jsx)(`input`,{type:`search`,value:h,onChange:e=>g(e.target.value),placeholder:e(`settings.pipelines.searchPlaceholder`,`Search pipelines…`),"aria-label":e(`settings.pipelines.searchPlaceholder`,`Search pipelines…`),className:`w-full pl-7 pr-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`})]}),(0,Y.jsxs)(`select`,{value:_,onChange:e=>v(e.target.value),"aria-label":e(`settings.pipelines.filterTarget`,`Filter by target`),className:`text-xs px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,Y.jsx)(`option`,{value:``,children:e(`settings.pipelines.filter.all`,`All targets`)}),b.printers.length>0&&(0,Y.jsx)(`optgroup`,{label:e(`settings.pipelines.field.targetKindSpecific`,`Specific printer`),children:b.printers.map(e=>(0,Y.jsx)(`option`,{value:`p:${e.id}`,children:e.name},`p-${e.id}`))}),b.classes.length>0&&(0,Y.jsx)(`optgroup`,{label:e(`settings.pipelines.field.targetKindClass`,`Printer class`),children:b.classes.map(t=>(0,Y.jsx)(`option`,{value:`c:${t}`,children:e(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:t})},`c-${t}`))}),b.anyWithoutTarget&&(0,Y.jsx)(`option`,{value:`none`,children:e(`settings.pipelines.filter.noTarget`,`No target set`)})]}),(h||_)&&(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e(`settings.pipelines.filter.count`,`{{shown}} / {{total}}`,{shown:x.length,total:y.length})})]}),!a&&!o&&y.length===0&&(0,Y.jsxs)(`div`,{className:`text-sm text-bambu-gray space-y-2`,children:[(0,Y.jsx)(`p`,{children:e(`settings.pipelines.empty.title`,`No pipelines yet.`)}),(0,Y.jsx)(`p`,{children:e(`settings.pipelines.empty.howto`,`Open the Slice dialog for any file, pick your printer / process / filaments / bed type, then click "Save as pipeline". Your saved pipelines will appear here.`)})]}),!a&&!o&&y.length>0&&x.length===0&&(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.pipelines.filter.noMatches`,`No pipelines match the current filters.`)}),!a&&!o&&x.length>0&&(0,Y.jsx)(`div`,{className:`space-y-2`,children:x.map(t=>(0,Y.jsx)(Pn,{pipeline:t,presets:s,printers:c??[],onSave:e=>p.mutate({id:t.id,...e}),onDelete:()=>{confirm(e(`settings.pipelines.confirmDelete`,`Delete this pipeline? This cannot be undone.`))&&m.mutate(t.id)},saving:p.isPending,deleting:m.isPending},t.id))})]})]})}function Pn({pipeline:e,presets:t,printers:n,onSave:i,onDelete:a,saving:o,deleting:s}){let{t:c}=l(),[u,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(e.name),[h,g]=(0,X.useState)(e.description??``),[_,v]=(0,X.useState)(e.target_printer_id),[y,b]=(0,X.useState)(e.target_kind===`printer_class`?`printer_class`:`specific_printer`),[x,S]=(0,X.useState)(e.target_model_class??``),[C,w]=(0,X.useState)(e.fanout_strategy??`max_parallel`),E=Array.from(new Set(n.map(e=>e.model).filter(e=>!!e))).sort(),{data:D}=d({queryKey:[`pipeline-runs`,e.id],queryFn:()=>r.listPipelineRuns(e.id,1),enabled:!u,refetchInterval:15e3}),O=D?.runs?.[0],k=jn(t,`printer`,e.printer_preset),A=jn(t,`process`,e.process_preset),ee=e.filament_presets.map(e=>jn(t,`filament`,e)),j=e.filament_presets.length>1&&e.filament_presets.every(t=>t.source===e.filament_presets[0].source&&t.id===e.filament_presets[0].id),te=t!==void 0&&(k===null||A===null||ee.some(e=>e===null)),M=e.target_printer_id?n.find(t=>t.id===e.target_printer_id):void 0,N=e.target_kind===`printer_class`,ne=N?!e.target_model_class:e.target_printer_id===null;return(0,Y.jsxs)(`div`,{className:`rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 px-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:u?(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`input`,{value:p,onChange:e=>m(e.target.value),"aria-label":c(`settings.pipelines.field.name`,`Pipeline name`),placeholder:c(`settings.pipelines.field.name`,`Pipeline name`),className:`w-full px-2 py-1 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,Y.jsx)(`textarea`,{value:h,onChange:e=>g(e.target.value),"aria-label":c(`settings.pipelines.field.description`,`Description`),placeholder:c(`settings.pipelines.field.description`,`Description`),rows:2,className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:c(`settings.pipelines.field.targetKind`,`Target type`)}),(0,Y.jsxs)(`div`,{className:`flex gap-3 text-xs`,children:[(0,Y.jsxs)(`label`,{className:`flex items-center gap-1 text-white`,children:[(0,Y.jsx)(`input`,{type:`radio`,name:`target-kind-${e.id}`,value:`specific_printer`,checked:y===`specific_printer`,onChange:()=>b(`specific_printer`),"aria-label":c(`settings.pipelines.field.targetKindSpecific`,`Specific printer`)}),c(`settings.pipelines.field.targetKindSpecific`,`Specific printer`)]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-1 text-white`,children:[(0,Y.jsx)(`input`,{type:`radio`,name:`target-kind-${e.id}`,value:`printer_class`,checked:y===`printer_class`,onChange:()=>b(`printer_class`),"aria-label":c(`settings.pipelines.field.targetKindClass`,`Printer class`)}),c(`settings.pipelines.field.targetKindClass`,`Printer class`)]})]})]}),y===`specific_printer`?(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:c(`settings.pipelines.field.targetPrinter`,`Target printer`)}),(0,Y.jsxs)(`select`,{value:_??``,onChange:e=>v(e.target.value?parseInt(e.target.value,10):null),"aria-label":c(`settings.pipelines.field.targetPrinter`,`Target printer`),className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,Y.jsx)(`option`,{value:``,children:c(`settings.pipelines.field.noTarget`,`— No target —`)}),n.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:c(`settings.pipelines.field.targetModelClass`,`Printer model`)}),(0,Y.jsxs)(`select`,{value:x,onChange:e=>S(e.target.value),"aria-label":c(`settings.pipelines.field.targetModelClass`,`Printer model`),className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,Y.jsx)(`option`,{value:``,children:c(`settings.pipelines.field.noTarget`,`— No target —`)}),E.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:c(`settings.pipelines.field.fanoutStrategy`,`Fanout strategy`)}),(0,Y.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),"aria-label":c(`settings.pipelines.field.fanoutStrategy`,`Fanout strategy`),className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,Y.jsx)(`option`,{value:`max_parallel`,children:c(`settings.pipelines.field.fanout.max_parallel`,`Max parallel — distribute across any idle matching printer`)}),(0,Y.jsx)(`option`,{value:`round_robin`,children:c(`settings.pipelines.field.fanout.round_robin`,`Round robin — cycle through eligible printers`)}),(0,Y.jsx)(`option`,{value:`fill_one_first`,children:c(`settings.pipelines.field.fanout.fill_one_first`,`Fill one first — pin all copies to one printer`)})]})]})]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1`,children:[(0,Y.jsx)(`h4`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,Y.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded inline-flex items-center gap-1 ${ne?`bg-amber-100 dark:bg-amber-500/15 text-amber-700 dark:text-amber-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[(0,Y.jsx)(it,{className:`w-3 h-3`}),ne?c(`settings.pipelines.noTargetHint`,`Set a target printer to run this`):N?(0,Y.jsxs)(Y.Fragment,{children:[c(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}),e.fanout_strategy&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[` · `,c(`settings.pipelines.field.fanoutShort.${e.fanout_strategy}`,e.fanout_strategy)]})]}):M?.name??``]})]}),e.description&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.description})]})}),(0,Y.jsx)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:u?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{onClick:()=>{let e=p.trim();e&&(i({name:e,description:h.trim()||null,target_kind:y,target_printer_id:y===`specific_printer`?_??0:0,target_model_class:y===`printer_class`&&x||null,fanout_strategy:C}),f(!1))},disabled:o||!p.trim(),"aria-label":c(`settings.pipelines.action.save`,`Save`),className:`p-1.5 text-bambu-green hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,children:(0,Y.jsx)(T,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>{m(e.name),g(e.description??``),v(e.target_printer_id),b(e.target_kind===`printer_class`?`printer_class`:`specific_printer`),S(e.target_model_class??``),w(e.fanout_strategy??`max_parallel`),f(!1)},"aria-label":c(`settings.pipelines.action.cancel`,`Cancel`),className:`p-1.5 text-bambu-gray hover:bg-bambu-dark-tertiary rounded`,children:(0,Y.jsx)(Re,{className:`w-4 h-4`})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{onClick:()=>f(!0),"aria-label":c(`settings.pipelines.action.rename`,`Rename`),className:`p-1.5 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded`,children:(0,Y.jsx)(se,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:a,disabled:s,"aria-label":c(`settings.pipelines.action.delete`,`Delete`),className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]})})]}),!u&&(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 md:grid-cols-2 gap-x-4 gap-y-2 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wide text-bambu-gray/60`,children:c(`settings.pipelines.group.profiles`,`Profiles`)}),(0,Y.jsx)(In,{label:c(`settings.pipelines.slot.printer`,`Printer`),ref:e.printer_preset,name:k}),(0,Y.jsx)(In,{label:c(`settings.pipelines.slot.process`,`Process`),ref:e.process_preset,name:A}),e.bed_type&&(0,Y.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,Y.jsxs)(`span`,{className:`font-medium text-bambu-gray/80`,children:[c(`settings.pipelines.slot.bed`,`Bed`),`:`]}),` `,(0,Y.jsx)(`span`,{className:`text-white`,children:e.bed_type})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Y.jsxs)(`div`,{className:`text-[10px] uppercase tracking-wide text-bambu-gray/60`,children:[c(`settings.pipelines.group.filaments`,`Filaments`),e.filament_presets.length>1&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray/60 normal-case ml-1`,children:[`(`,e.filament_presets.length,`)`]})]}),j?(0,Y.jsx)(In,{label:c(`settings.pipelines.slot.filamentAll`,`All {{n}} slots`,{n:e.filament_presets.length}),ref:e.filament_presets[0],name:ee[0]}):e.filament_presets.map((t,n)=>(0,Y.jsx)(In,{label:e.filament_presets.length>1?c(`settings.pipelines.slot.filamentN`,`Filament {{n}}`,{n:n+1}):c(`settings.pipelines.slot.filament`,`Filament`),ref:t,name:ee[n]},n))]})]}),!u&&O&&(0,Y.jsxs)(`div`,{className:`mt-1.5 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,Y.jsxs)(`span`,{className:`font-medium text-bambu-gray/80`,children:[c(`settings.pipelines.runs.lastRun`,`Last run`),`:`]}),` `,(0,Y.jsx)(Fn,{status:O.status}),O.created_at&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[`· `,new Date(O.created_at).toLocaleString()]})]}),ne&&!u&&(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 text-xs text-amber-700 dark:text-amber-400`,children:[(0,Y.jsx)(Ie,{className:`w-3.5 h-3.5`}),c(`settings.pipelines.noTargetWarning`,`Set a target printer before running this pipeline.`)]}),te&&!u&&(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 text-xs text-amber-700 dark:text-amber-400`,children:[(0,Y.jsx)(Ie,{className:`w-3.5 h-3.5`}),c(`settings.pipelines.staleWarning`,`One or more referenced presets no longer exist. Re-save this pipeline from the Slice dialog to fix.`)]})]})}function Fn({status:e}){let{t}=l();return(0,Y.jsx)(`span`,{className:{queued:`text-bambu-gray`,slicing:`text-blue-700 dark:text-blue-400`,dispatching:`text-blue-700 dark:text-blue-400`,in_progress:`text-bambu-green`,completed:`text-bambu-green`,failed:`text-red-700 dark:text-red-400`,partial_failure:`text-amber-700 dark:text-amber-400`,cancelled:`text-bambu-gray`}[e],children:t(`settings.pipelines.runs.status.${e}`,e)})}function In({label:e,ref:t,name:n}){return(0,Y.jsxs)(`div`,{className:`text-bambu-gray truncate`,children:[(0,Y.jsxs)(`span`,{className:`font-medium text-bambu-gray/80`,children:[e,`:`]}),` `,n?(0,Y.jsx)(`span`,{className:`text-white`,children:n}):(0,Y.jsxs)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:[`[`,Mn[t.source],` #`,t.id,`]`]})]})}var Ln=90,Rn=365;function zn(e){if(!e)return`—`;let t=We(e);return t?t.toLocaleString():`—`}function Bn(e){let t=We(e);return t?t.getTime()<Date.now():!1}function Vn({onCreated:e,fixedScope:t,onSubmittingChange:n}){let{t:i}=l(),{showToast:a}=ee(),[o,s]=(0,X.useState)(``),[c,u]=(0,X.useState)(Ln),[d,f]=(0,X.useState)(t??`camera_stream`),[p,m]=(0,X.useState)(!1);return(0,Y.jsxs)(`form`,{onSubmit:async l=>{if(l.preventDefault(),!(!o.trim()||p)){m(!0),n?.(!0);try{e(await r.createLongLivedCameraToken({name:o.trim(),expires_in_days:c,scope:t??d})),s(``),u(Ln),f(t??`camera_stream`),a(i(`cameraTokens.toast.created`,`Token created`))}catch(e){a(e instanceof Error&&e.message?e.message:i(`cameraTokens.toast.createFailed`,`Failed to create token`),`error`)}finally{m(!1),n?.(!1)}}},className:`@container/token-form min-w-0 bg-bambu-dark-secondary rounded-lg p-4 mb-6 border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:i(`cameraTokens.create.title`,`Create new token`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 @min-[26rem]/token-form:grid-cols-2 @min-[44rem]/token-form:grid-cols-[minmax(0,1fr)_180px_140px_auto]`,children:[(0,Y.jsx)(`input`,{type:`text`,maxLength:100,required:!0,value:o,onChange:e=>s(e.target.value),placeholder:i(`cameraTokens.create.namePlaceholder`,`e.g. Home Assistant`),className:`min-w-0 w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":i(`cameraTokens.create.nameLabel`,`Token name`)}),(0,Y.jsxs)(`select`,{value:d,disabled:!!t,onChange:e=>f(e.target.value),className:`min-w-0 w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":i(`cameraTokens.create.scopeLabel`,`Scope`),children:[(0,Y.jsx)(`option`,{value:`camera_stream`,children:i(`cameraTokens.scope.camera_stream`,`Camera stream`)}),(0,Y.jsx)(`option`,{value:`camwall`,children:i(`cameraTokens.scope.camwall`,`Cam Wall`)}),(0,Y.jsx)(`option`,{value:`overlay`,children:i(`cameraTokens.scope.overlay`,`Streaming Overlay`)})]}),(0,Y.jsx)(`input`,{type:`number`,min:1,max:Rn,required:!0,value:c,onChange:e=>{let t=Number(e.target.value);u(Math.min(Math.max(t,1),Rn))},className:`min-w-0 w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":i(`cameraTokens.create.daysLabel`,`Days until expiry`)}),(0,Y.jsxs)(`button`,{type:`submit`,disabled:p||!o.trim(),className:`min-w-0 flex items-center justify-center gap-2 px-4 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90 disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),i(`cameraTokens.create.submit`,`Create`)]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:d===`camwall`?i(`cameraTokens.create.hintCamWall`,`A Cam Wall token opens /camwall on a screen with no login — it can see every printer's name and state, and their camera streams. It cannot see filenames, addresses or access codes.`):d===`overlay`?i(`cameraTokens.create.hintOverlay`,`A Streaming Overlay token opens /overlay/{printerId} on a screen with no login — for OBS or any live stream. It can see one printer's camera stream plus its live print status, including the filename shown on screen. It cannot see addresses or access codes.`):i(`cameraTokens.create.hintCameraStream`,`A camera-stream token can only fetch camera streams and snapshots. Use it for Home Assistant, Frigate, or anything embedding a single camera.`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`cameraTokens.create.hint`,`Maximum lifetime is 365 days. The token value is shown only once on creation — copy it now.`)})]})}function Hn({token:e,onConfirm:t,onCancel:n}){let{t:r}=l();return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,role:`dialog`,"aria-modal":`true`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full border border-red-500/40`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,Y.jsx)(Ie,{className:`w-6 h-6 text-red-600 dark:text-red-400 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`cameraTokens.confirmRevoke.title`,`Revoke this token?`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`cameraTokens.confirmRevoke.body`,`Any device using "{{name}}" will lose access immediately. This cannot be undone.`,{name:e.name})})]})]}),(0,Y.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:n,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:r(`cameraTokens.confirmRevoke.cancel`,`Cancel`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 bg-red-500 text-white rounded-md hover:bg-red-600`,children:r(`cameraTokens.confirmRevoke.confirm`,`Revoke`)})]})]})})}function Un({token:e,onClose:t}){let{t:n}=l(),{showToast:r}=ee(),i=e.token??``,a=e.scope===`camwall`&&i?`${window.location.origin}/camwall?token=${encodeURIComponent(i)}`:null,o=e.scope===`overlay`&&i?`${window.location.origin}/overlay/1?token=${encodeURIComponent(i)}`:null,s=async e=>{if(e)try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(e);else{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{t.select(),document.execCommand(`copy`)}finally{document.body.removeChild(t)}}r(n(`cameraTokens.toast.copied`,`Copied to clipboard`))}catch{r(n(`cameraTokens.toast.copyFailed`,`Copy failed — select and copy manually`),`error`)}};return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-2xl w-full border border-bambu-green/40`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,Y.jsx)(Ie,{className:`w-6 h-6 text-yellow-600 dark:text-yellow-400 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`cameraTokens.created.title`,`Token created — copy it now`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:n(`cameraTokens.created.warning`,`This is the only time this token will be visible. After you close this dialog you can never view it again.`)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,Y.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:i}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>s(i),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,Y.jsx)(M,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]}),a&&(0,Y.jsxs)(`div`,{className:`mb-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-white mb-1`,children:n(`cameraTokens.created.camWallUrlTitle`,`Cam Wall URL for this display`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`cameraTokens.created.camWallUrlHint`,`Open this on the screen. Anyone who can read the URL can watch the wall, so treat it like a key — revoke the token to cut the display off.`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:a}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>s(a),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,Y.jsx)(M,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]})]}),o&&(0,Y.jsxs)(`div`,{className:`mb-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-white mb-1`,children:n(`cameraTokens.created.overlayUrlTitle`,`Overlay URL for OBS`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`cameraTokens.created.overlayUrlHint`,`Add this as a Browser Source in OBS. Change the /overlay/1 number to your printer's number (from its URL on the Printers page). Anyone who can read the URL can watch the stream, so treat it like a key — revoke the token to cut it off.`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:o}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>s(o),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,Y.jsx)(M,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]})]}),(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:n(`cameraTokens.created.dismiss`,`I've saved it`)})})]})})}function Wn({token:e,showOwner:t,ownerLabel:n,onRevoke:r}){let{t:i}=l(),a=Bn(e.expires_at);return(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary last:border-b-0`,children:[(0,Y.jsx)(`td`,{className:`py-3 px-3 text-white break-words max-w-64`,children:e.name}),t&&(0,Y.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:n}),(0,Y.jsx)(`td`,{className:`py-3 px-3`,children:(0,Y.jsx)(`span`,{className:`rounded bg-bambu-dark-tertiary px-2 py-0.5 text-xs text-bambu-gray`,children:i(`cameraTokens.scope.${e.scope}`,e.scope)})}),(0,Y.jsxs)(`td`,{className:`py-3 px-3 text-bambu-gray font-mono text-xs`,children:[e.lookup_prefix,`…`]}),(0,Y.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:zn(e.created_at)}),(0,Y.jsxs)(`td`,{className:`py-3 px-3 ${a?`text-red-700 dark:text-red-400`:`text-bambu-gray`}`,children:[zn(e.expires_at),a&&(0,Y.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-300 rounded`,children:i(`cameraTokens.list.expired`,`Expired`)})]}),(0,Y.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:zn(e.last_used_at)}),(0,Y.jsx)(`td`,{className:`py-3 px-3 text-right`,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>r(e.id),className:`inline-flex items-center gap-1 px-2 py-1 text-sm text-red-700 dark:text-red-400 hover:text-red-900 dark:hover:text-red-300`,title:i(`cameraTokens.list.revoke`,`Revoke`),children:[(0,Y.jsx)(qe,{className:`w-4 h-4`}),i(`cameraTokens.list.revoke`,`Revoke`)]})})]})}function Gn({tokens:e,showOwner:t,userIdToName:n,onRevoke:r,emptyMessage:i}){let{t:a}=l();return e.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:i}):(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`text-bambu-gray text-left border-b border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.name`,`Name`)}),t&&(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.owner`,`Owner`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.scope`,`Scope`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.prefix`,`Prefix`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.created`,`Created`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.expires`,`Expires`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.lastUsed`,`Last used`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3`})]})}),(0,Y.jsx)(`tbody`,{children:e.map(e=>(0,Y.jsx)(Wn,{token:e,showOwner:t,ownerLabel:n?.get(e.user_id)??`#${e.user_id}`,onRevoke:r},e.id))})]})})}function Kn(){let{t:e}=l(),{user:t,isAdmin:n}=un(),{showToast:i}=ee(),[a,o]=(0,X.useState)([]),[s,c]=(0,X.useState)([]),[u,d]=(0,X.useState)(new Map),[f,p]=(0,X.useState)(!0),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(null),v=async()=>{p(!0);try{if(o(await r.listMyLongLivedCameraTokens()),n){c(await r.listAllLongLivedCameraTokens());try{let e=await r.getUsersSlim();d(new Map(e.map(e=>[e.id,e.username])))}catch{d(new Map)}}}catch(t){i(t instanceof Error?t.message:e(`cameraTokens.toast.loadFailed`,`Failed to load tokens`),`error`)}finally{p(!1)}};(0,X.useEffect)(()=>{v()},[n]);let y=async e=>{let t=[...a,...s].find(t=>t.id===e);t&&_(t)},b=async()=>{if(!g)return;let t=g.id;_(null);try{await r.revokeLongLivedCameraToken(t),i(e(`cameraTokens.toast.revoked`,`Token revoked`)),await v()}catch(t){i(t instanceof Error?t.message:e(`cameraTokens.toast.revokeFailed`,`Failed to revoke token`),`error`)}},x=(0,X.useMemo)(()=>s.filter(e=>e.user_id!==t?.id),[s,t?.id]);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`cameraTokens.description`,`Long-lived tokens for embedding the camera stream into Home Assistant, Frigate, kiosks, or any other tool that needs a stable URL. Each token is camera-stream-only and can be revoked at any time.`)}),(0,Y.jsx)(Vn,{onCreated:e=>{h(e),v()}}),(0,Y.jsxs)(`div`,{className:`mb-6`,children:[(0,Y.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:e(`cameraTokens.list.myTitle`,`My tokens`)}),f?(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`cameraTokens.loading`,`Loading…`)}):(0,Y.jsx)(Gn,{tokens:a,onRevoke:y,emptyMessage:e(`cameraTokens.list.empty`,`No tokens yet.`)})]}),n&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:e(`cameraTokens.list.allTitle`,`All users (admin view)`)}),(0,Y.jsx)(Gn,{tokens:x,showOwner:!0,userIdToName:u,onRevoke:y,emptyMessage:e(`cameraTokens.list.empty`,`No tokens yet.`)})]}),m&&(0,Y.jsx)(Un,{token:m,onClose:()=>h(null)}),g&&(0,Y.jsx)(Hn,{token:g,onConfirm:()=>void b(),onCancel:()=>_(null)})]})}var qn=[`connected-apps`];function Jn(e){if(!e)return`—`;let t=We(e);return t?t.toLocaleString():`—`}async function Yn(e){if(navigator.clipboard&&window.isSecureContext){await navigator.clipboard.writeText(e);return}let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{t.select(),document.execCommand(`copy`)}finally{document.body.removeChild(t)}}function Xn({label:e,value:t}){let{t:n}=l(),{showToast:r}=ee();return(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:e}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`code`,{className:`flex-1 min-w-0 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:t}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>Yn(t).then(()=>r(n(`connectedApps.toast.copied`)),()=>r(n(`connectedApps.toast.copyFailed`),`error`)),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,Y.jsx)(M,{className:`w-4 h-4`}),n(`connectedApps.copy`)]})]})]})}function Zn({app:e,onClose:t}){let{t:n}=l();return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,role:`dialog`,"aria-modal":`true`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-2xl w-full border border-bambu-green/40 space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(Ie,{className:`w-6 h-6 text-yellow-600 dark:text-yellow-400 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`connectedApps.secret.title`,{name:e.name})}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:n(`connectedApps.secret.warning`)})]})]}),(0,Y.jsx)(Xn,{label:n(`connectedApps.clientId`),value:e.client_id}),(0,Y.jsx)(Xn,{label:n(`connectedApps.clientSecret`),value:e.client_secret??``}),(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:n(`connectedApps.secret.dismiss`)})})]})})}function Qn({title:e,body:t,confirmLabel:n,onConfirm:r,onCancel:i}){let{t:a}=l();return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,role:`dialog`,"aria-modal":`true`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full border border-red-500/40`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,Y.jsx)(Ie,{className:`w-6 h-6 text-red-600 dark:text-red-400 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:t})]})]}),(0,Y.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:i,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:a(`connectedApps.cancel`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:r,className:`px-4 py-2 bg-red-500 text-white rounded-md hover:bg-red-600`,children:n})]})]})})}function $n(){let{t:e}=l(),{authEnabled:t}=un(),{showToast:n}=ee(),i=u(),[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)(``),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)(null),{data:_=[],isLoading:v}=d({queryKey:qn,queryFn:r.listConnectedApps,enabled:t}),y=t=>n(t instanceof Error?t.message:e(`connectedApps.toast.failed`),`error`),b=()=>i.invalidateQueries({queryKey:qn}),x=f({mutationFn:()=>r.createConnectedApp({name:a.trim(),redirect_uri:s.trim()}),onSuccess:t=>{o(``),c(``),m(t),n(e(`connectedApps.toast.created`)),b()},onError:y}),S=f({mutationFn:e=>r.updateConnectedApp(e.id,{enabled:!e.enabled}),onSuccess:t=>{n(t.enabled?e(`connectedApps.toast.enabled`):e(`connectedApps.toast.disabled`)),b()},onError:y}),C=f({mutationFn:e=>r.rotateConnectedAppSecret(e.id),onSuccess:t=>{m(t),n(e(`connectedApps.toast.rotated`)),b()},onError:y}),w=f({mutationFn:e=>r.deleteConnectedApp(e.id),onSuccess:()=>{n(e(`connectedApps.toast.deleted`)),b()},onError:y});if(!t)return(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`connectedApps.requiresAuth`)});let T=`px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`;return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`connectedApps.description`)}),(0,Y.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),a.trim()&&s.trim()&&x.mutate()},className:`grid gap-3 md:grid-cols-[minmax(0,1fr)_minmax(0,1.5fr)_auto]`,children:[(0,Y.jsx)(`input`,{type:`text`,maxLength:100,required:!0,value:a,onChange:e=>o(e.target.value),placeholder:e(`connectedApps.namePlaceholder`),"aria-label":e(`connectedApps.name`),className:T}),(0,Y.jsx)(`input`,{type:`url`,maxLength:500,required:!0,value:s,onChange:e=>c(e.target.value),placeholder:`http://orders.local:8090/auth/callback`,"aria-label":e(`connectedApps.callbackUrl`),className:T}),(0,Y.jsxs)(`button`,{type:`submit`,disabled:x.isPending||!a.trim()||!s.trim(),className:`flex items-center justify-center gap-2 px-4 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90 disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),e(`connectedApps.add`)]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`connectedApps.callbackHint`)}),v?null:_.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`connectedApps.empty`)}):(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`text-left text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:e(`connectedApps.name`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:e(`connectedApps.clientId`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:e(`connectedApps.callbackUrl`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:e(`connectedApps.lastUsed`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3`})]})}),(0,Y.jsx)(`tbody`,{children:_.map(t=>(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary last:border-b-0`,children:[(0,Y.jsxs)(`td`,{className:`py-3 px-3 text-white`,children:[t.name,!t.enabled&&(0,Y.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:e(`connectedApps.disabledBadge`)})]}),(0,Y.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray font-mono text-xs`,children:t.client_id}),(0,Y.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray text-xs break-all`,children:t.redirect_uri}),(0,Y.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:Jn(t.last_used_at)}),(0,Y.jsx)(`td`,{className:`py-3 px-3`,children:(0,Y.jsxs)(`div`,{className:`flex justify-end gap-3 whitespace-nowrap`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>S.mutate(t),className:`text-sm text-bambu-gray hover:text-white`,children:t.enabled?e(`connectedApps.disable`):e(`connectedApps.enable`)}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>g({app:t,action:`rotate`}),className:`inline-flex items-center gap-1 text-sm text-bambu-gray hover:text-white`,children:[(0,Y.jsx)(at,{className:`w-4 h-4`}),e(`connectedApps.rotate`)]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>g({app:t,action:`delete`}),className:`inline-flex items-center gap-1 text-sm text-red-700 dark:text-red-400 hover:text-red-900 dark:hover:text-red-300`,children:[(0,Y.jsx)(qe,{className:`w-4 h-4`}),e(`connectedApps.delete`)]})]})})]},t.id))})]})}),p&&(0,Y.jsx)(Zn,{app:p,onClose:()=>m(null)}),h&&(0,Y.jsx)(Qn,{title:h.action===`rotate`?e(`connectedApps.confirmRotate.title`):e(`connectedApps.confirmDelete.title`),body:h.action===`rotate`?e(`connectedApps.confirmRotate.body`,{name:h.app.name}):e(`connectedApps.confirmDelete.body`,{name:h.app.name}),confirmLabel:h.action===`rotate`?e(`connectedApps.rotate`):e(`connectedApps.delete`),onCancel:()=>g(null),onConfirm:()=>{h.action===`rotate`?C.mutate(h.app):w.mutate(h.app),g(null)}})]})}function er({value:e,onChange:t,onBusyChange:n}){let{t:i}=l(),{showToast:a}=ee(),{authEnabled:o,hasPermission:s}=un(),c=!o||s(`settings:update`),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)({from:e.from||`#00ae42`,to:e.to||`#00ae42`}),m=hn(!0,null,e.logoRevision),h=async o=>{d(!0),n?.(!0);try{o?await r.uploadOverlayLogo(o):await r.deleteOverlayLogo(),t({...e,logo:o!==null,logoRevision:e.logoRevision+1})}catch(e){a(e instanceof Error?e.message:i(`streamOverlay.branding.failed`),`error`)}finally{d(!1),n?.(!1)}},g=(n,r)=>{p(e=>({...e,[n]:r})),fn(r)&&t({...e,from:e.from||`#00ae42`,to:e.to||`#00ae42`,[n]:r})};return(0,Y.jsxs)(`fieldset`,{disabled:u,className:`my-4 space-y-3 rounded-lg border border-bambu-dark-tertiary p-4`,children:[(0,Y.jsx)(`legend`,{className:`px-2 text-sm font-medium text-white`,children:i(`streamOverlay.branding.title`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`streamOverlay.branding.hint`)}),(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray`,children:[i(`streamOverlay.branding.upload`),(0,Y.jsx)(`input`,{type:`file`,accept:`image/png,image/webp`,disabled:!c,className:`mt-1 block w-full text-sm`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&h(t)}})]}),m&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Y.jsx)(`img`,{src:m,alt:i(`streamOverlay.branding.logo`),className:`h-16 max-w-40 object-contain`}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.logo,onChange:n=>t({...e,logo:n.target.checked})}),i(`streamOverlay.branding.logo`)]}),(0,Y.jsx)(`button`,{type:`button`,disabled:!c,onClick:()=>void h(null),className:`text-sm text-red-400 disabled:opacity-50`,children:i(`common.remove`)})]}),(0,Y.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[`from`,`to`].map(t=>(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-colour-${t}`,className:`block text-sm text-bambu-gray mb-1`,children:i(`streamOverlay.branding.${t}`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`input`,{id:`overlay-colour-${t}`,type:`color`,value:e[t]||`#00ae42`,onChange:e=>g(t,e.target.value),className:`h-9 w-12 bg-transparent`}),(0,Y.jsx)(`input`,{"aria-label":`${i(`streamOverlay.branding.${t}`)} (hex)`,value:f[t],onChange:e=>g(t,e.target.value),"aria-invalid":!fn(f[t]),maxLength:7,spellCheck:!1,className:`w-28 rounded border border-bambu-dark-tertiary bg-bambu-dark px-2 py-1 text-white`})]})]},t))}),(0,Y.jsx)(`button`,{type:`button`,className:`text-sm text-bambu-green`,onClick:()=>{p({from:`#00ae42`,to:`#00ae42`}),t({...e,from:``,to:``})},children:i(`streamOverlay.branding.reset`)})]})}var tr=[{key:`printer`,labelKey:`streamOverlay.builder.fieldPrinter`,fallback:`Printer name`},{key:`model`,labelKey:`streamOverlay.builder.fieldModel`,fallback:`Printer model`},{key:`filename`,labelKey:`streamOverlay.builder.fieldFilename`,fallback:`File name`},{key:`status`,labelKey:`streamOverlay.builder.fieldStatus`,fallback:`Status`},{key:`progress`,labelKey:`streamOverlay.builder.fieldProgress`,fallback:`Progress bar`},{key:`layers`,labelKey:`streamOverlay.builder.fieldLayers`,fallback:`Layer count`},{key:`eta`,labelKey:`streamOverlay.builder.fieldEta`,fallback:`Time remaining and ETA`},{key:`nozzle`,labelKey:`printers.heaterHistory.nozzle`,fallback:`Nozzle`},{key:`bed`,labelKey:`printers.heaterHistory.bed`,fallback:`Bed`},{key:`chamber`,labelKey:`printers.heaterHistory.chamber`,fallback:`Chamber`}],nr=[`progress`,`layers`,`eta`,`filename`,`status`],rr=15,ir=`bambuddy.streamOverlayBuilder`,ar={printerId:null,fields:nr,size:`medium`,fps:rr,artwork:`1`,backgroundTransparency:0,showCamera:!0,layout:`landscape`,logo:!1,from:``,to:``};function or(){let e;try{e=JSON.parse(window.localStorage.getItem(ir)??`null`)}catch{return ar}if(!e||typeof e!=`object`)return ar;let t=e,n=(e,t,n,r)=>typeof e==`number`&&Number.isFinite(e)?Math.min(n,Math.max(t,e)):r,r=typeof t.from==`string`&&typeof t.to==`string`&&dn(t.from,t.to);return{printerId:typeof t.printerId==`number`&&Number.isSafeInteger(t.printerId)&&t.printerId>0?t.printerId:null,fields:Array.isArray(t.fields)?t.fields.filter(e=>tr.some(t=>t.key===e)):nr,size:t.size===`small`||t.size===`large`?t.size:`medium`,fps:Math.round(n(t.fps,1,30,rr)),artwork:t.artwork===`2`?`2`:`1`,backgroundTransparency:n(t.backgroundTransparency,0,100,0),showCamera:t.showCamera!==!1,layout:t.layout===`portrait`||t.layout===`both`?t.layout:`landscape`,logo:t.logo===!0,from:r?t.from:``,to:r?t.to:``}}var sr=600;function cr(e){try{return window.localStorage.setItem(ir,JSON.stringify(e)),!0}catch{return!1}}function lr({onTokenCreated:e}){let{t}=l(),{showToast:n}=ee(),{user:i,hasPermission:a}=un(),[o,s]=(0,X.useState)(!1),[c,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(``),h=p,[g,_]=(0,X.useState)(``),[v,y]=(0,X.useState)(!1),[b]=(0,X.useState)(or),x=(0,X.useRef)(null),S=(0,X.useRef)(!1),C=(0,X.useRef)(null),[w,T]=(0,X.useState)([]),[E,D]=(0,X.useState)(b.printerId),[O,k]=(0,X.useState)(b.fields),[A,j]=(0,X.useState)(b.size),[te,N]=(0,X.useState)(b.fps),[ne,ie]=(0,X.useState)(b.artwork),[ae,oe]=(0,X.useState)(b.backgroundTransparency),[P,F]=(0,X.useState)(b.showCamera),[I,L]=(0,X.useState)({...mn,logo:b.logo,from:b.from,to:b.to}),[R,se]=(0,X.useState)(b.layout),[ce,z]=(0,X.useState)(0),[B,le]=(0,X.useState)(!1),[V,ue]=(0,X.useState)(!1);(0,X.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await r.getPrinters();if(e)return;T(t),t.length>0&&D(e=>{let n=e===null||e===b.printerId&&!t.some(t=>t.id===e)?t[0].id:e;return n!==e&&(S.current=!0),n})}catch{}})(),()=>{e=!0}},[b.printerId]),(0,X.useEffect)(()=>{let e={printerId:E,fields:O,size:A,fps:te,artwork:ne,backgroundTransparency:ae,showCamera:P,layout:R,logo:I.logo,from:I.from,to:I.to},r=JSON.stringify(e);if(r===x.current)return;let i=x.current===null||S.current;x.current=r,S.current=!1,!(!cr(e)||i)&&(C.current&&clearTimeout(C.current),C.current=setTimeout(()=>{C.current=null,n(t(`settings.toast.settingsSaved`))},sr))},[E,O,A,te,ne,ae,P,R,I.logo,I.from,I.to,n,t]),(0,X.useEffect)(()=>()=>{C.current&&clearTimeout(C.current)},[]);let de=()=>{D(w[0]?.id??null),k(ar.fields),j(ar.size),N(ar.fps),ie(ar.artwork),oe(ar.backgroundTransparency),F(ar.showCamera),se(ar.layout),L(e=>({...e,logo:!1,from:``,to:``})),z(e=>e+1),ue(!1)},fe=(0,X.useMemo)(()=>{let e=E??1,t=new URLSearchParams,n=tr.filter(e=>O.includes(e.key)).map(e=>e.key);return t.set(`show`,n.join(`,`)),A!==`medium`&&t.set(`size`,A),te!==rr&&t.set(`fps`,String(te)),ne!==`1`&&t.set(`artwork`,ne),ne===`2`&&ae>0&&t.set(`backgroundTransparency`,String(ae)),P||t.set(`camera`,`false`),I.logo&&t.set(`logo`,`1`),I.from&&I.to&&(t.set(`progressFrom`,I.from),t.set(`progressTo`,I.to)),h.trim()&&t.set(`token`,h.trim()),(R===`both`?[`landscape`,`portrait`]:[R]).map(n=>(n===`portrait`?t.set(`layout`,n):t.delete(`layout`),{layout:n,url:`${window.location.origin}/overlay/${e}?${t.toString()}`}))},[E,O,A,te,P,h,ne,R,I,ae]),pe=e=>{let t=new URL(e);return t.searchParams.has(`token`)&&!d&&t.searchParams.set(`token`,`****`),t.toString()},me=()=>{try{let e=new URL(g.trim()),t=/^\/overlay\/([1-9]\d*)\/?$/.exec(e.pathname);if(![`http:`,`https:`].includes(e.protocol)||e.username||e.password||!t)throw Error();let n=Number(t[1]);if(!Number.isSafeInteger(n))throw Error();let r=e.searchParams;if(r.getAll(`token`).length>1)throw Error();let i=r.has(`show`)?r.get(`show`).split(`,`).filter(e=>tr.some(t=>t.key===e)):nr,a=r.get(`size`),o=a===`small`||a===`large`?a:`medium`,s=parseInt(r.get(`fps`)||`15`,10),c=Math.min(Math.max(Number.isNaN(s)?rr:s,1),30),l=Number(r.get(`backgroundTransparency`)),u=Number.isFinite(l)?Math.min(100,Math.max(0,l)):0,d=r.get(`progressFrom`),p=r.get(`progressTo`),h=dn(d,p);D(n),se(r.get(`layout`)===`portrait`?`portrait`:`landscape`),k(i),j(o),N(c),ie(r.get(`artwork`)===`2`?`2`:`1`),F(![`false`,`0`].includes(r.get(`camera`)??``)),oe(u),L(e=>({...e,logo:r.get(`logo`)===`1`,from:h?d:``,to:h?p:``})),z(e=>e+1),m(r.get(`token`)??``),ue(!1),f(!1),_(``),y(!1)}catch{y(!0)}},he=e=>{k(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},ge=async e=>{try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(e);else{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{if(t.select(),!document.execCommand(`copy`))throw Error()}finally{document.body.removeChild(t)}}n(t(`cameraTokens.toast.copied`,`Copied to clipboard`))}catch{n(t(`cameraTokens.toast.copyFailed`,`Copy failed — select and copy manually`),`error`)}};return(0,Y.jsxs)(`div`,{className:`@container/overlay min-w-0`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:t(`streamOverlay.builder.description`,`Build the URL for a streaming overlay — a full-screen camera view with live print data drawn over it, for OBS, a wall display, or any browser source. Pick the fields you want and copy the URL.`)}),(0,Y.jsxs)(`div`,{className:`-mt-2 mb-4 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-bambu-gray`,children:[(0,Y.jsx)(`span`,{children:t(`streamOverlay.builder.rememberedHint`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:de,disabled:c||B,className:`text-bambu-green hover:underline disabled:opacity-50`,children:t(`streamOverlay.builder.resetChoices`)})]}),(0,Y.jsxs)(`div`,{className:`mb-4 space-y-2`,children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-import`,className:`block text-sm font-medium text-white`,children:t(`streamOverlay.builder.importUrl`)}),(0,Y.jsx)(`input`,{id:`overlay-builder-import`,type:`password`,autoComplete:`new-password`,spellCheck:!1,value:g,disabled:c||B,onChange:e=>{_(e.target.value),y(!1)},className:`w-full min-w-0 px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary`}),(0,Y.jsx)(`button`,{type:`button`,disabled:c||B||!g.trim(),onClick:me,className:`px-3 py-2 bg-bambu-dark-tertiary text-white rounded-md disabled:opacity-50`,children:t(`streamOverlay.builder.importAction`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`streamOverlay.builder.importHint`)}),v&&(0,Y.jsx)(`p`,{role:`alert`,className:`text-sm text-red-400`,children:t(`streamOverlay.builder.importError`)})]}),(0,Y.jsxs)(`div`,{className:`mb-4 space-y-2`,children:[i&&a(`camera:view`)&&(0,Y.jsx)(`button`,{type:`button`,disabled:c,onClick:()=>s(e=>!e),className:`px-3 py-2 bg-bambu-dark-tertiary text-white rounded-md`,children:t(o?`common.cancel`:`streamOverlay.builder.createToken`)}),o&&i&&a(`camera:view`)&&(0,Y.jsx)(Vn,{fixedScope:`overlay`,onSubmittingChange:u,onCreated:t=>{e?.(),t.token&&(ue(!1),m(t.token),f(!1),s(!1))}})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 @min-[28rem]/overlay:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-printer`,className:`block text-sm font-medium text-white mb-1`,children:t(`streamOverlay.builder.printer`,`Printer`)}),(0,Y.jsxs)(`select`,{id:`overlay-builder-printer`,value:E??``,onChange:e=>D(Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,children:[w.length===0&&(0,Y.jsx)(`option`,{value:``,children:t(`common.loading`,`Loading…`)}),E!==null&&!w.some(e=>e.id===E)&&(0,Y.jsx)(`option`,{value:E,children:E}),w.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-size`,className:`block text-sm font-medium text-white mb-1`,children:t(`streamOverlay.builder.size`,`Text size`)}),(0,Y.jsxs)(`select`,{id:`overlay-builder-size`,value:A,onChange:e=>j(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`small`,children:t(`streamOverlay.builder.sizeSmall`,`Small`)}),(0,Y.jsx)(`option`,{value:`medium`,children:t(`streamOverlay.builder.sizeMedium`,`Medium`)}),(0,Y.jsx)(`option`,{value:`large`,children:t(`streamOverlay.builder.sizeLarge`,`Large`)})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-layout`,className:`block text-sm font-medium text-white mb-1`,children:t(`streamOverlay.builder.layout`)}),(0,Y.jsxs)(`select`,{id:`overlay-builder-layout`,value:R,onChange:e=>{let t=e.target.value;(t===`landscape`||t===`portrait`||t===`both`)&&se(t)},className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`landscape`,children:t(`streamOverlay.builder.landscape`)}),(0,Y.jsx)(`option`,{value:`portrait`,children:t(`streamOverlay.builder.portrait`)}),(0,Y.jsx)(`option`,{value:`both`,children:t(`streamOverlay.builder.both`)})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-artwork`,className:`block text-sm font-medium text-white mb-1`,children:t(`streamOverlay.builder.artwork`,`Artwork`)}),(0,Y.jsxs)(`select`,{id:`overlay-builder-artwork`,value:ne,onChange:e=>ie(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`1`,children:t(`streamOverlay.builder.artworkClassic`,`Classic`)}),(0,Y.jsx)(`option`,{value:`2`,children:t(`streamOverlay.builder.artworkV2`,`Version 2`)})]})]}),ne===`2`&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{htmlFor:`overlay-builder-background-transparency`,className:`flex justify-between gap-2 text-sm font-medium text-white mb-1`,children:[(0,Y.jsx)(`span`,{children:t(`streamOverlay.builder.backgroundTransparency`)}),(0,Y.jsxs)(`span`,{"aria-hidden":`true`,children:[ae,`%`]})]}),(0,Y.jsx)(`input`,{id:`overlay-builder-background-transparency`,type:`range`,min:0,max:100,step:1,value:ae,"aria-valuetext":`${ae}%`,onChange:e=>oe(Number(e.target.value)),className:`w-full accent-bambu-green`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`streamOverlay.builder.backgroundTransparencyHint`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-fps`,className:`block text-sm font-medium text-white mb-1`,children:t(`streamOverlay.builder.fps`,`Frame rate`)}),(0,Y.jsx)(ct,{id:`overlay-builder-fps`,min:1,max:30,value:te,onChange:N,fallback:1,className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`streamOverlay.builder.fpsHint`,`A1 and P1 cameras top out around 5 fps whatever you ask for.`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-manual-token`,className:`block text-sm font-medium text-white mt-3 mb-1`,children:t(`streamOverlay.builder.manualToken`)}),(0,Y.jsx)(`input`,{id:`overlay-builder-manual-token`,type:d?`text`:`password`,value:p,disabled:c,autoComplete:`new-password`,spellCheck:!1,onChange:e=>{ue(!1),f(!1),m(e.target.value)},placeholder:`bblt_…`,className:`w-full min-w-0 px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary`}),(0,Y.jsx)(`button`,{type:`button`,disabled:!h,onClick:()=>f(e=>!e),className:`mt-2 text-sm text-bambu-gray disabled:opacity-50`,children:t(d?`streamOverlay.builder.hideToken`:`streamOverlay.builder.showToken`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`streamOverlay.builder.credentialHint`,`Create a token above, enter an existing token, or import an overlay URL. Copy the URL before leaving: tokens are held only in memory and cannot be recovered from their stored hash.`)})]})]}),(0,Y.jsxs)(`fieldset`,{className:`mt-4`,children:[(0,Y.jsx)(`legend`,{className:`text-sm font-medium text-white mb-2`,children:t(`streamOverlay.builder.fields`,`Fields to show`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 @min-[24rem]/overlay:grid-cols-2 @min-[36rem]/overlay:grid-cols-3`,children:[tr.map(e=>(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:O.includes(e.key),onChange:()=>he(e.key),className:`accent-bambu-green`}),t(e.labelKey,e.fallback)]},e.key)),(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:P,onChange:e=>F(e.target.checked),className:`accent-bambu-green`}),t(`streamOverlay.builder.fieldCamera`,`Camera feed`)]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:t(`streamOverlay.builder.chamberHint`,`Chamber temperature only appears on models with a real chamber sensor — P1 and A1 printers report a meaningless value, so it is left out there.`)})]}),(0,Y.jsx)(er,{value:I,onChange:L,onBusyChange:le},ce),(0,Y.jsxs)(`div`,{className:`mt-4`,children:[fe.map(({layout:e,url:n})=>(0,Y.jsxs)(`fieldset`,{className:`min-w-0 mb-3`,children:[(0,Y.jsx)(`legend`,{className:`text-sm font-medium text-white mb-1`,children:t(`streamOverlay.builder.orientationUrl`,{orientation:t(`streamOverlay.builder.${e}`)})}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:t(`streamOverlay.builder.sourceDimensions`,pn[e])}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsx)(`code`,{className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono`,children:pe(n)}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>void ge(n),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,Y.jsx)(M,{className:`w-4 h-4`}),t(`cameraTokens.created.copy`,`Copy`)]}),(0,Y.jsxs)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:[(0,Y.jsx)(Je,{className:`w-4 h-4`}),t(`streamOverlay.builder.open`,`Open`)]})]})]},e)),h.trim()&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:t(`streamOverlay.builder.tokenWarning`,`This URL contains a token — anyone who can read it can watch the stream and see the file name. Revoke the token to cut it off.`)})]}),(0,Y.jsxs)(`div`,{className:`mt-4`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>ue(e=>!e),className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80 text-sm`,children:[V?(0,Y.jsx)(re,{className:`w-4 h-4`}):(0,Y.jsx)(mt,{className:`w-4 h-4`}),V?t(`streamOverlay.builder.hidePreview`,`Hide preview`):t(`streamOverlay.builder.showPreview`,`Show preview`)]}),V&&(0,Y.jsx)(`div`,{className:`mt-3 flex flex-wrap items-start gap-4`,children:fe.map(({layout:e,url:n})=>(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1 basis-64`,style:e===`portrait`?{maxWidth:360}:void 0,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white mb-2`,children:t(`streamOverlay.builder.${e}`)}),(0,Y.jsx)(`div`,{className:`overflow-hidden rounded-md border border-bambu-dark-tertiary`,children:(0,Y.jsx)(gn,{layout:e,preview:!0,children:(0,Y.jsx)(ur,{url:n,logoRevision:I.logoRevision,title:t(`streamOverlay.builder.orientationPreview`,{orientation:t(`streamOverlay.builder.${e}`)})})})})]},e))})]})]})}function ur({url:e,logoRevision:t,title:n}){let[r,i]=(0,X.useState)({url:e,logoRevision:t});return(0,X.useEffect)(()=>{let n=window.setTimeout(()=>i({url:e,logoRevision:t}),300);return()=>window.clearTimeout(n)},[e,t]),(0,Y.jsx)(`iframe`,{src:r.url,title:n,className:`w-full h-full border-0`},`${r.url}:${r.logoRevision}`)}function dr({plug:e,onEdit:t}){let{t:n}=l(),i=u(),{showToast:a}=ee(),[o,s]=(0,X.useState)(!1),[c,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(!1),{data:v,isLoading:y}=d({queryKey:[`smart-plug-status`,e.id],queryFn:()=>r.getSmartPlugStatus(e.id),refetchInterval:3e4}),{data:b}=d({queryKey:[`printers`],queryFn:r.getPrinters}),x=b?.find(t=>t.id===e.printer_id),S=f({mutationFn:t=>r.controlSmartPlug(e.id,t),onMutate:async t=>{await i.cancelQueries({queryKey:[`smart-plug-status`,e.id]});let n=i.getQueryData([`smart-plug-status`,e.id]),r=t===`on`?`ON`:t===`off`||v?.state===`ON`?`OFF`:`ON`;return i.setQueryData([`smart-plug-status`,e.id],e=>({...e,state:r})),{previousStatus:n}},onError:(t,r,o)=>{o?.previousStatus&&i.setQueryData([`smart-plug-status`,e.id],o.previousStatus),a(n(`smartPlugs.failedToTurn`,{action:r,name:e.name}),`error`)},onSettled:()=>{setTimeout(()=>{i.invalidateQueries({queryKey:[`smart-plug-status`,e.id]}),i.invalidateQueries({queryKey:[`smart-plugs`]})},1e3)}}),C=f({mutationFn:t=>r.updateSmartPlug(e.id,t),onSuccess:()=>{i.invalidateQueries({queryKey:[`smart-plugs`]}),e.printer_id&&(i.invalidateQueries({queryKey:[`smartPlugByPrinter`,e.printer_id]}),i.invalidateQueries({queryKey:[`scriptPlugsByPrinter`,e.printer_id]}))}}),T=f({mutationFn:()=>r.deleteSmartPlug(e.id),onSuccess:()=>{i.invalidateQueries({queryKey:[`smart-plugs`]}),e.printer_id&&i.invalidateQueries({queryKey:[`scriptPlugsByPrinter`,e.printer_id]})}}),E=v?.state===`ON`,D=e.plug_type===`mqtt`&&v?.energy?.power!==null&&v?.energy?.power!==void 0,O=(v?.reachable??!1)||D,k=S.isPending,A=(()=>{if(e.plug_type!==`tasmota`||!e.ip_address)return null;let t=e.ip_address;return e.username&&e.password?`http://${encodeURIComponent(e.username)}:${encodeURIComponent(e.password)}@${t}/`:`http://${t}/`})();return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(G,{className:`relative`,children:(0,Y.jsxs)(W,{className:`p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2 mb-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded-lg flex-shrink-0 ${e.plug_type===`mqtt`?O?`bg-teal-100 dark:bg-teal-500/20`:`bg-red-100 dark:bg-red-500/20`:O?E?`bg-bambu-green/20`:`bg-bambu-dark`:`bg-red-100 dark:bg-red-500/20`}`,children:e.plug_type===`mqtt`?(0,Y.jsx)(en,{className:`w-5 h-5 ${O?`text-teal-600 dark:text-teal-400`:`text-red-600 dark:text-red-400`}`}):e.plug_type===`homeassistant`?(0,Y.jsx)(Ft,{className:`w-5 h-5 ${O?E?`text-bambu-green`:`text-bambu-gray`:`text-red-600 dark:text-red-400`}`}):e.plug_type===`rest`?(0,Y.jsx)(zt,{className:`w-5 h-5 ${O?E?`text-bambu-green`:`text-bambu-gray`:`text-red-600 dark:text-red-400`}`}):(0,Y.jsx)(dt,{className:`w-5 h-5 ${O?E?`text-bambu-green`:`text-bambu-gray`:`text-red-600 dark:text-red-400`}`})}),(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`h3`,{className:`font-medium text-white truncate`,children:e.name}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray truncate`,title:e.plug_type===`mqtt`?e.mqtt_topic??void 0:e.plug_type===`homeassistant`?e.ha_entity_id??void 0:e.plug_type===`rest`?e.rest_on_url??e.rest_off_url??void 0:e.ip_address??void 0,children:e.plug_type===`mqtt`?e.mqtt_topic:e.plug_type===`homeassistant`?e.ha_entity_id:e.plug_type===`rest`?e.rest_on_url||e.rest_off_url:e.ip_address})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col items-end gap-1 flex-shrink-0`,children:[y?(0,Y.jsx)(L,{className:`w-4 h-4 text-bambu-gray animate-spin`}):e.plug_type===`mqtt`?(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm whitespace-nowrap`,children:[(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-[10px] font-medium rounded flex-shrink-0`,children:`MQTT`}),O&&(0,Y.jsx)(`span`,{className:`text-status-ok`,children:`✓`})]}):e.plug_type===`homeassistant`?(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,Y.jsx)(`span`,{className:`px-1 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 text-[10px] font-medium rounded`,children:`HA`}),(0,Y.jsx)(`span`,{className:O?E?`text-status-ok`:`text-bambu-gray`:`text-status-error`,children:O?v?.state||`?`:n(`smartPlugs.offline`)})]}):e.plug_type===`rest`?(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,Y.jsx)(`span`,{className:`px-1 py-0.5 bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400 text-[10px] font-medium rounded`,children:`REST`}),(0,Y.jsx)(`span`,{className:O?E?`text-status-ok`:`text-bambu-gray`:`text-status-error`,children:O?v?.state||`?`:n(`smartPlugs.offline`)})]}):O?(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,Y.jsx)(ht,{className:`w-4 h-4 text-status-ok`}),(0,Y.jsx)(`span`,{className:E?`text-status-ok`:`text-bambu-gray`,children:v?.state||n(`smartPlugs.unknown`)})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-sm text-status-error`,children:[(0,Y.jsx)(Ye,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{children:n(`smartPlugs.offline`)})]}),A&&(0,Y.jsxs)(`a`,{href:A,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 px-2 py-0.5 bg-bambu-dark hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white text-xs rounded-full transition-colors`,title:n(`smartPlugs.openPlugAdminPage`),children:[(0,Y.jsx)(Je,{className:`w-3 h-3`}),n(`smartPlugs.admin`)]})]})]}),x&&(0,Y.jsxs)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:[(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[n(`smartPlugs.linkedTo`),` `]}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:x.name})]}),(e.power_alert_enabled||e.schedule_enabled||e.plug_type===`mqtt`)&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-3`,children:[e.plug_type===`mqtt`&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-xs rounded-full`,children:[(0,Y.jsx)(mt,{className:`w-3 h-3`}),n(`smartPlugs.monitorOnly`)]}),e.power_alert_enabled&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-xs rounded-full`,children:[(0,Y.jsx)(rt,{className:`w-3 h-3`}),n(`smartPlugs.alerts`)]}),e.schedule_enabled&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 text-xs rounded-full`,children:[(0,Y.jsx)(w,{className:`w-3 h-3`}),e.schedule_on_time&&e.schedule_off_time?`${e.schedule_on_time} - ${e.schedule_off_time}`:e.schedule_on_time?n(`smartPlugs.scheduleOn`,{time:e.schedule_on_time}):n(`smartPlugs.scheduleOff`,{time:e.schedule_off_time})]})]}),e.plug_type!==`mqtt`&&(0,Y.jsxs)(`div`,{className:`flex gap-2 mb-3`,children:[(0,Y.jsxs)(K,{size:`sm`,variant:E?`primary`:`secondary`,disabled:!O||k,onClick:()=>p(!0),className:`flex-1`,children:[k?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Ct,{className:`w-4 h-4`}),n(`smartPlugs.on`)]}),(0,Y.jsxs)(K,{size:`sm`,variant:E?`secondary`:`primary`,disabled:!O||k,onClick:()=>h(!0),className:`flex-1`,children:[k?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(St,{className:`w-4 h-4`}),n(`smartPlugs.off`)]})]}),e.plug_type===`mqtt`&&v?.energy&&(0,Y.jsxs)(`div`,{className:`flex gap-2 mb-3 px-3 py-2 bg-bambu-dark rounded-lg`,children:[v.energy.power!==null&&v.energy.power!==void 0&&(0,Y.jsxs)(`div`,{className:`flex-1 text-center`,children:[(0,Y.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Math.round(v.energy.power),`W`]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.power`)})]}),v.energy.today!==null&&v.energy.today!==void 0&&(0,Y.jsxs)(`div`,{className:`flex-1 text-center border-l border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:v.energy.today.toFixed(3)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.kwhToday`)})]})]}),(0,Y.jsxs)(`button`,{onClick:()=>_(!g),className:`w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(je,{className:`w-4 h-4`}),e.plug_type===`mqtt`?n(`smartPlugs.settings`):n(`smartPlugs.automationSettings`)]}),(0,Y.jsx)(`span`,{children:g?`-`:`+`})]}),g&&(0,Y.jsxs)(`div`,{className:`pt-3 border-t border-bambu-dark-tertiary space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(F,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.showInSwitchbar`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.quickAccessSidebar`)})]})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.show_in_switchbar,onChange:e=>C.mutate({show_in_switchbar:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.printer_id!=null&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Ct,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.controlsPrinterPower`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.controlsPrinterPowerDescription`)})]})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.controls_printer_power,onChange:e=>C.mutate({controls_printer_power:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.plug_type!==`mqtt`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.enabled`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.enableAutomation`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:e=>C.mutate({enabled:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOn`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOnDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.auto_on,onChange:e=>C.mutate({auto_on:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOff`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.auto_off,onChange:e=>C.mutate({auto_off:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOffPersistent`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffPersistentDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.auto_off_persistent,onChange:e=>C.mutate({auto_off_persistent:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off&&(0,Y.jsxs)(`div`,{className:`space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white mb-2`,children:n(`smartPlugs.turnOffDelayMode`)}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsxs)(`button`,{onClick:()=>C.mutate({off_delay_mode:`time`}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${e.off_delay_mode===`time`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(lt,{className:`w-4 h-4`}),n(`smartPlugs.time`)]}),(0,Y.jsxs)(`button`,{onClick:()=>C.mutate({off_delay_mode:`temperature`}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${e.off_delay_mode===`temperature`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(Fe,{className:`w-4 h-4`}),n(`smartPlugs.temp`)]})]})]}),e.off_delay_mode===`time`?(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.delayMinutes`)}),(0,Y.jsx)(ct,{min:1,max:60,value:e.off_delay_minutes,onChange:e=>C.mutate({off_delay_minutes:e}),fallback:5,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]}):(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.tempThreshold`)}),(0,Y.jsx)(ct,{min:30,max:100,value:e.off_temp_threshold,onChange:e=>C.mutate({off_temp_threshold:e}),fallback:70,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`smartPlugs.tempThresholdDescription`)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOffAfterDrying`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffAfterDryingDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.auto_off_after_drying,onChange:e=>C.mutate({auto_off_after_drying:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off_after_drying&&(0,Y.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.delayAfterDryingMinutes`)}),(0,Y.jsx)(ct,{min:0,max:120,value:e.off_delay_after_drying_minutes,onChange:e=>C.mutate({off_delay_after_drying_minutes:e}),fallback:10,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2 pt-2`,children:[(0,Y.jsxs)(K,{size:`sm`,variant:`secondary`,onClick:()=>t(e),className:`flex-1`,children:[(0,Y.jsx)(se,{className:`w-4 h-4`}),n(`smartPlugs.edit`)]}),(0,Y.jsx)(K,{size:`sm`,variant:`secondary`,onClick:()=>s(!0),className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300`,children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]})]})]})}),o&&(0,Y.jsx)(Tt,{title:n(`smartPlugs.deleteSmartPlug`),message:n(`smartPlugs.deleteConfirm`,{name:e.name}),confirmText:n(`smartPlugs.delete`),variant:`danger`,onConfirm:()=>{T.mutate(),s(!1)},onCancel:()=>s(!1)}),c&&(0,Y.jsx)(Tt,{title:n(`smartPlugs.turnOnSmartPlug`),message:n(`smartPlugs.turnOnConfirm`,{name:e.name}),confirmText:n(`smartPlugs.turnOn`),variant:`default`,onConfirm:()=>{S.mutate(`on`),p(!1)},onCancel:()=>p(!1)}),m&&(0,Y.jsx)(Tt,{title:n(`smartPlugs.turnOffSmartPlug`),message:n(`smartPlugs.turnOffConfirm`,{name:e.name}),confirmText:n(`smartPlugs.turnOff`),variant:`danger`,onConfirm:()=>{S.mutate(`off`),h(!1)},onCancel:()=>h(!1)})]})}function fr({plug:e,onClose:t}){let{t:n}=l(),i=u(),a=!!e,[o,s]=(0,X.useState)(e?.plug_type||`tasmota`),[c,p]=(0,X.useState)(e?.name||``),[m,h]=(0,X.useState)(e?.ip_address||``),[g,_]=(0,X.useState)(e?.username||``),[v,y]=(0,X.useState)(e?.password||``),[b,x]=(0,X.useState)(e?.ha_entity_id||``),[S,C]=(0,X.useState)(e?.mqtt_power_topic||e?.mqtt_topic||``),[w,T]=(0,X.useState)(e?.mqtt_power_path||``),[E,D]=(0,X.useState)((e?.mqtt_power_multiplier??e?.mqtt_multiplier??1).toString()),[O,k]=(0,X.useState)(e?.mqtt_energy_topic||``),[A,ee]=(0,X.useState)(e?.mqtt_energy_path||``),[te,M]=(0,X.useState)((e?.mqtt_energy_multiplier??1).toString()),[N,ne]=(0,X.useState)(e?.mqtt_state_topic||``),[re,ie]=(0,X.useState)(e?.mqtt_state_path||``),[ae,oe]=(0,X.useState)(e?.mqtt_state_on_value||``),[P,I]=(0,X.useState)(e?.rest_on_url||``),[R,se]=(0,X.useState)(e?.rest_on_body||``),[ce,z]=(0,X.useState)(e?.rest_off_url||``),[B,le]=(0,X.useState)(e?.rest_off_body||``),[V,ue]=(0,X.useState)(e?.rest_method||`POST`),[de,fe]=(0,X.useState)(e?.rest_headers||``),[pe,me]=(0,X.useState)(e?.rest_status_url||``),[he,ge]=(0,X.useState)(e?.rest_status_path||``),[_e,ve]=(0,X.useState)(e?.rest_status_on_value||``),[ye,be]=(0,X.useState)(e?.rest_power_url||``),[H,xe]=(0,X.useState)(e?.rest_power_path||``),[Se,Ce]=(0,X.useState)((e?.rest_power_multiplier??1).toString()),[we,Te]=(0,X.useState)(e?.rest_energy_url||``),[Ee,De]=(0,X.useState)(e?.rest_energy_path||``),[Oe,ke]=(0,X.useState)((e?.rest_energy_multiplier??1).toString()),[je,Me]=(0,X.useState)(e?.rest_energy_total_path||``),[Ne,Pe]=(0,X.useState)((e?.rest_energy_total_multiplier??1).toString()),[Fe,Ie]=(0,X.useState)(e?.ha_power_entity||``),[Le,U]=(0,X.useState)(e?.ha_energy_today_entity||``),[W,ze]=(0,X.useState)(e?.ha_energy_total_entity||``),[G,Be]=(0,X.useState)(``),[Ve,He]=(0,X.useState)(``),[Ue,We]=(0,X.useState)(!1),Ge=(0,X.useRef)(null),[Ke,q]=(0,X.useState)(``),[qe,Je]=(0,X.useState)(!1),Xe=(0,X.useRef)(null),[Ze,Qe]=(0,X.useState)(``),[$e,et]=(0,X.useState)(!1),tt=(0,X.useRef)(null),[nt,it]=(0,X.useState)(``),[at,ot]=(0,X.useState)(!1),st=(0,X.useRef)(null),[ct,ut]=(0,X.useState)(e?.printer_id||null),[ft,pt]=(0,X.useState)(e?.controls_printer_power??!0),[gt,vt]=(0,X.useState)(null),[yt,bt]=(0,X.useState)(null),[xt,St]=(0,X.useState)(e?.power_alert_enabled||!1),[wt,Tt]=(0,X.useState)(e?.power_alert_high?.toString()||``),[Et,Dt]=(0,X.useState)(e?.power_alert_low?.toString()||``),[Ot,kt]=(0,X.useState)(e?.schedule_enabled||!1),[At,jt]=(0,X.useState)(e?.schedule_on_time||``),[Mt,Nt]=(0,X.useState)(e?.schedule_off_time||``),[Pt,It]=(0,X.useState)(e?.show_in_switchbar||!1),[Lt,Rt]=(0,X.useState)(e?.show_on_printer_card??!0),[Bt,Vt]=(0,X.useState)(!1),[Ht,Ut]=(0,X.useState)({scanned:0,total:0}),[Wt,Gt]=(0,X.useState)([]),Kt=(0,X.useRef)(null),{data:qt}=d({queryKey:[`printers`],queryFn:r.getPrinters}),{data:Jt}=d({queryKey:[`smart-plugs`],queryFn:r.getSmartPlugs}),{data:Yt}=d({queryKey:[`settings`],queryFn:r.getSettings}),Xt=!!(Yt?.ha_enabled&&Yt?.ha_url&&Yt?.ha_token);(0,X.useEffect)(()=>{let e=setTimeout(()=>{He(G)},300);return()=>clearTimeout(e)},[G]),(0,X.useEffect)(()=>{let e=e=>{Ge.current&&!Ge.current.contains(e.target)&&We(!1),Xe.current&&!Xe.current.contains(e.target)&&Je(!1),tt.current&&!tt.current.contains(e.target)&&et(!1),st.current&&!st.current.contains(e.target)&&ot(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let{data:Zt,isLoading:Qt,error:$t}=d({queryKey:[`ha-entities`,Ve],queryFn:()=>r.getHAEntities(Ve||void 0),enabled:o===`homeassistant`&&Xt,retry:!1,staleTime:0}),{data:tn}=d({queryKey:[`ha-sensor-entities`],queryFn:r.getHASensorEntities,enabled:o===`homeassistant`&&Xt,retry:!1,staleTime:0});(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e),Kt.current&&clearInterval(Kt.current)}},[t]);let nn=async()=>{Vt(!0),Gt([]),Ut({scanned:0,total:0}),bt(null);try{await r.startTasmotaScan();let e=async()=>{try{let e=await r.getTasmotaScanStatus();Ut({scanned:e.scanned,total:e.total}),Gt(await r.getDiscoveredTasmotaDevices()),e.running||(Vt(!1),Kt.current&&=(clearInterval(Kt.current),null))}catch(e){console.error(`Polling error:`,e)}};await e(),Kt.current=setInterval(e,500)}catch(e){Vt(!1),bt((e instanceof Error?e.message:typeof e==`string`?e:JSON.stringify(e))||n(`smartPlugs.failedToStartScan`))}},rn=async()=>{try{await r.stopTasmotaScan()}catch{}Vt(!1),Kt.current&&=(clearInterval(Kt.current),null)},an=e=>{h(e.ip_address),p(e.name),vt(null)},on=f({mutationFn:()=>r.testSmartPlugConnection(m,g||null,v||null),onSuccess:e=>{vt(e),bt(null),!c&&e.device_name&&p(e.device_name)},onError:e=>{vt(null),bt(e.message)}}),sn=f({mutationFn:e=>r.createSmartPlug(e),onSuccess:()=>{i.invalidateQueries({queryKey:[`smart-plugs`]}),i.invalidateQueries({queryKey:[`scriptPlugsByPrinter`]}),t()},onError:e=>{bt(e.message)}}),cn=f({mutationFn:t=>r.updateSmartPlug(e.id,t),onSuccess:()=>{i.invalidateQueries({queryKey:[`smart-plugs`]}),i.invalidateQueries({queryKey:[`scriptPlugsByPrinter`]}),t()},onError:e=>{bt(e.message)}}),ln=qt?.filter(t=>o===`tasmota`?!Jt?.some(n=>n.printer_id===t.id&&n.id!==e?.id&&n.plug_type===`tasmota`):!0),un=e=>{if(e.preventDefault(),bt(null),!c.trim()){bt(n(`smartPlugs.nameRequired`));return}if(o===`tasmota`&&!m.trim()){bt(`IP address is required for Tasmota plugs`);return}if(o===`homeassistant`&&!b){bt(n(`smartPlugs.entityRequired`));return}if(o===`mqtt`){let e=S.trim(),t=O.trim(),r=N.trim();if(!e&&!t&&!r){bt(n(`smartPlugs.mqttTopicRequired`));return}}if(o===`rest`&&!P.trim()&&!ce.trim()){bt(n(`smartPlugs.restUrlRequired`));return}let t={name:c.trim(),plug_type:o,ip_address:o===`tasmota`?m.trim():null,ha_entity_id:o===`homeassistant`?b:null,ha_power_entity:o===`homeassistant`&&Fe||null,ha_energy_today_entity:o===`homeassistant`&&Le||null,ha_energy_total_entity:o===`homeassistant`&&W||null,mqtt_power_topic:o===`mqtt`&&S.trim()||null,mqtt_power_path:o===`mqtt`&&w.trim()||null,mqtt_power_multiplier:o===`mqtt`&&parseFloat(E)||1,mqtt_energy_topic:o===`mqtt`&&O.trim()||null,mqtt_energy_path:o===`mqtt`&&A.trim()||null,mqtt_energy_multiplier:o===`mqtt`&&parseFloat(te)||1,mqtt_state_topic:o===`mqtt`&&N.trim()||null,mqtt_state_path:o===`mqtt`&&re.trim()||null,mqtt_state_on_value:o===`mqtt`&&ae.trim()||null,rest_on_url:o===`rest`&&P.trim()||null,rest_on_body:o===`rest`&&R.trim()||null,rest_off_url:o===`rest`&&ce.trim()||null,rest_off_body:o===`rest`&&B.trim()||null,rest_method:o===`rest`?V:null,rest_headers:o===`rest`&&de.trim()||null,rest_status_url:o===`rest`&&pe.trim()||null,rest_status_path:o===`rest`&&he.trim()||null,rest_status_on_value:o===`rest`&&_e.trim()||null,rest_power_url:o===`rest`&&ye.trim()||null,rest_power_path:o===`rest`&&H.trim()||null,rest_power_multiplier:o===`rest`&&parseFloat(Se)||1,rest_energy_url:o===`rest`&&we.trim()||null,rest_energy_path:o===`rest`&&Ee.trim()||null,rest_energy_multiplier:o===`rest`&&parseFloat(Oe)||1,rest_energy_total_path:o===`rest`&&je.trim()||null,rest_energy_total_multiplier:o===`rest`&&parseFloat(Ne)||1,username:o===`tasmota`&&g.trim()||null,password:o===`tasmota`&&v.trim()||null,printer_id:ct,controls_printer_power:ft,power_alert_enabled:xt,power_alert_high:wt?parseFloat(wt):null,power_alert_low:Et?parseFloat(Et):null,schedule_enabled:Ot,schedule_on_time:At||null,schedule_off_time:Mt||null,show_in_switchbar:Pt,show_on_printer_card:Lt};a?cn.mutate(t):sn.mutate(t)},J=sn.isPending||cn.isPending;return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(a?`smartPlugs.editTitle`:`smartPlugs.addTitle`)}),(0,Y.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:un,className:`p-6 space-y-4 overflow-y-auto`,children:[yt&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-400 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:yt}),!a&&(0,Y.jsxs)(`div`,{className:`flex gap-2 mb-2`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{s(`tasmota`),vt(null),bt(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${o===`tasmota`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(dt,{className:`w-4 h-4`}),`Tasmota`]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{s(`homeassistant`),vt(null),bt(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${o===`homeassistant`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(Ft,{className:`w-4 h-4`}),`HA`]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{s(`mqtt`),vt(null),bt(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${o===`mqtt`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(en,{className:`w-4 h-4`}),`MQTT`]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{s(`rest`),vt(null),bt(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${o===`rest`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(zt,{className:`w-4 h-4`}),`REST`]})]}),!a&&o===`tasmota`&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[Bt?(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,onClick:rn,className:`w-full`,children:[(0,Y.jsx)(Re,{className:`w-4 h-4`}),n(`smartPlugs.stopScanning`)]}):(0,Y.jsxs)(K,{type:`button`,variant:`primary`,onClick:nn,className:`w-full`,children:[(0,Y.jsx)(Ae,{className:`w-4 h-4`}),n(`smartPlugs.discoverTasmota`)]}),Bt&&Ht.total>0&&(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between text-xs text-bambu-gray`,children:[(0,Y.jsx)(`span`,{children:n(`smartPlugs.addSmartPlug.scanningNetwork`)}),(0,Y.jsxs)(`span`,{children:[Ht.scanned,` / `,Ht.total]})]}),(0,Y.jsx)(`div`,{className:`w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,Y.jsx)(`div`,{className:`bg-bambu-green h-2 rounded-full transition-all duration-300`,style:{width:`${Ht.scanned/Ht.total*100}%`}})})]}),Wt.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.foundDevices`,{count:Wt.length})}),(0,Y.jsx)(`div`,{className:`max-h-40 overflow-y-auto space-y-1`,children:Wt.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>an(e),className:`w-full flex items-center justify-between p-2 bg-bambu-dark hover:bg-bambu-dark-tertiary rounded-lg transition-colors text-left border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(dt,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:e.name}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.ip_address})]})]}),e.state&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs ${e.state===`ON`?`text-bambu-green`:`text-bambu-gray`}`,children:[(0,Y.jsx)(Ct,{className:`w-3 h-3`}),e.state]})]},e.ip_address))})]}),!Bt&&Wt.length===0&&Ht.total>0&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray text-center py-2`,children:n(`smartPlugs.noDevicesFound`)})]}),o===`homeassistant`&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[!Xt&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[n(`smartPlugs.haNotConfigured`),` `,(0,Y.jsx)(`span`,{className:`font-medium`,children:n(`smartPlugs.haSettingsPath`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 opacity-50`,children:n(`smartPlugs.selectEntity`)}),(0,Y.jsx)(`select`,{disabled:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray cursor-not-allowed opacity-50`,children:(0,Y.jsx)(`option`,{children:n(`smartPlugs.addSmartPlug.chooseEntity`)})})]})]}),Xt&&(0,Y.jsxs)(Y.Fragment,{children:[Qt&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-4 text-bambu-gray`,children:[(0,Y.jsx)(L,{className:`w-5 h-5 animate-spin mr-2`}),n(`smartPlugs.loadingEntities`)]}),$t&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-400 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:n(`smartPlugs.failedToLoadEntities`,{error:$t.message})}),(()=>{let t=Jt?.filter(t=>t.ha_entity_id&&t.id!==e?.id).map(e=>e.ha_entity_id)||[],r=(Zt||[]).filter(e=>!t.includes(e.entity_id)),i=Zt?.find(e=>e.entity_id===b);return(0,Y.jsxs)(`div`,{ref:Ge,className:`relative`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.selectEntity`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,Y.jsx)(`input`,{type:`text`,value:Ue?G:i?`${i.friendly_name} (${i.entity_id})`:``,onChange:e=>{Be(e.target.value),Ue||We(!0)},onFocus:()=>{We(!0),Be(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEntities`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),b&&!Ue&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{x(``),Be(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,Y.jsx)(Re,{className:`w-4 h-4 text-bambu-gray hover:text-white`})}),Qt&&(0,Y.jsx)(L,{className:`absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray animate-spin`})]}),Ue&&(0,Y.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-60 overflow-y-auto`,children:[Qt&&(0,Y.jsxs)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray flex items-center gap-2`,children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}),n(`smartPlugs.loading`)]}),!Qt&&r.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:Ve?n(`smartPlugs.noEntitiesMatching`,{search:Ve}):n(`smartPlugs.noEntitiesAvailable`)}),!Qt&&r.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{x(e.entity_id),We(!1),Be(``),c||p(e.friendly_name)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary transition-colors ${e.entity_id===b?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{children:e.entity_id}),(0,Y.jsx)(`span`,{className:e.state===`on`?`text-bambu-green`:``,children:e.state})]})]},e.entity_id))]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(Ve?`smartPlugs.searchingEntities`:`smartPlugs.showingEntities`,{count:r.length})})]})})(),b&&tn&&tn.length>0&&(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4 mt-4 space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white font-medium mb-1`,children:n(`smartPlugs.energyMonitoringOptional`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:n(`smartPlugs.energyMonitoringHint`)})]}),(()=>{let e=tn.filter(e=>e.unit_of_measurement===`W`||e.unit_of_measurement===`kW`||e.unit_of_measurement===`mW`),t=Ke?e.filter(e=>e.entity_id.toLowerCase().includes(Ke.toLowerCase())||e.friendly_name.toLowerCase().includes(Ke.toLowerCase())):e,r=tn.find(e=>e.entity_id===Fe);return(0,Y.jsxs)(`div`,{ref:Xe,className:`relative`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.powerSensorW`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,Y.jsx)(`input`,{type:`text`,value:qe?Ke:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{q(e.target.value),qe||Je(!0)},onFocus:()=>{Je(!0),q(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchPowerSensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),Fe&&!qe&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{Ie(``),q(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,Y.jsx)(Re,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),qe&&(0,Y.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{Ie(``),Je(!1),q(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{Ie(e.entity_id),Je(!1),q(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===Fe?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})(),(()=>{let e=tn.filter(e=>e.unit_of_measurement===`kWh`||e.unit_of_measurement===`Wh`||e.unit_of_measurement===`MWh`),t=Ze?e.filter(e=>e.entity_id.toLowerCase().includes(Ze.toLowerCase())||e.friendly_name.toLowerCase().includes(Ze.toLowerCase())):e,r=tn.find(e=>e.entity_id===Le);return(0,Y.jsxs)(`div`,{ref:tt,className:`relative`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.energyTodayKwh`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,Y.jsx)(`input`,{type:`text`,value:$e?Ze:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{Qe(e.target.value),$e||et(!0)},onFocus:()=>{et(!0),Qe(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEnergySensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),Le&&!$e&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{U(``),Qe(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,Y.jsx)(Re,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),$e&&(0,Y.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{U(``),et(!1),Qe(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{U(e.entity_id),et(!1),Qe(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===Le?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})(),(()=>{let e=tn.filter(e=>e.unit_of_measurement===`kWh`||e.unit_of_measurement===`Wh`||e.unit_of_measurement===`MWh`),t=nt?e.filter(e=>e.entity_id.toLowerCase().includes(nt.toLowerCase())||e.friendly_name.toLowerCase().includes(nt.toLowerCase())):e,r=tn.find(e=>e.entity_id===W);return(0,Y.jsxs)(`div`,{ref:st,className:`relative`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.totalEnergyKwh`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,Y.jsx)(`input`,{type:`text`,value:at?nt:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{it(e.target.value),at||ot(!0)},onFocus:()=>{ot(!0),it(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEnergySensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),W&&!at&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{ze(``),it(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,Y.jsx)(Re,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),at&&(0,Y.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{ze(``),ot(!1),it(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{ze(e.entity_id),ot(!1),it(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===W?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})()]})]})]}),o===`mqtt`&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[!Yt?.mqtt_broker&&(0,Y.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[n(`smartPlugs.mqttNotConfigured`),` `,(0,Y.jsx)(`span`,{className:`font-medium`,children:n(`smartPlugs.mqttSettingsPath`)}),` `,n(`smartPlugs.mqttNotConfiguredSuffix`)]}),Yt?.mqtt_broker&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`p-3 bg-blue-50 dark:bg-blue-500/10 border border-blue-300 dark:border-blue-500/30 rounded-lg text-sm text-blue-700 dark:text-blue-300`,children:[(0,Y.jsx)(`p`,{className:`font-medium mb-1`,children:n(`smartPlugs.monitorOnly`)}),(0,Y.jsx)(`p`,{className:`text-xs opacity-80`,children:n(`smartPlugs.mqttMonitorOnlyDescription`)})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium text-sm`,children:n(`smartPlugs.powerMonitoring`)}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,Y.jsx)(`input`,{type:`text`,value:S,onChange:e=>C(e.target.value),placeholder:`zigbee2mqtt/shelly-working-room`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:`power_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.multiplier`)}),(0,Y.jsx)(`input`,{type:`text`,value:E,onChange:e=>D(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttPowerHint`)})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.energyMonitoring`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,Y.jsx)(`input`,{type:`text`,value:O,onChange:e=>k(e.target.value),placeholder:`Same as power topic, or different`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:A,onChange:e=>ee(e.target.value),placeholder:`energy_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.multiplier`)}),(0,Y.jsx)(`input`,{type:`text`,value:te,onChange:e=>M(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttEnergyHint`)})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.stateMonitoring`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,Y.jsx)(`input`,{type:`text`,value:N,onChange:e=>ne(e.target.value),placeholder:`Same as power topic, or different`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:re,onChange:e=>ie(e.target.value),placeholder:`state_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.onValue`)}),(0,Y.jsx)(`input`,{type:`text`,value:ae,onChange:e=>oe(e.target.value),placeholder:n(`smartPlugs.addSmartPlug.placeholders.mqttStateOnValue`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttStateHint`)})]})]})]}),o===`rest`&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium text-sm`,children:n(`smartPlugs.restControl`)}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restMethod`)}),(0,Y.jsxs)(`select`,{value:V,onChange:e=>ue(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`GET`,children:`GET`}),(0,Y.jsx)(`option`,{value:`POST`,children:`POST`}),(0,Y.jsx)(`option`,{value:`PUT`,children:`PUT`}),(0,Y.jsx)(`option`,{value:`PATCH`,children:`PATCH`})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restOnUrl`)}),(0,Y.jsx)(`input`,{type:`text`,value:P,onChange:e=>{I(e.target.value),vt(null)},placeholder:`http://openhab:8080/rest/items/MyPlug`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restOnBody`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsx)(`input`,{type:`text`,value:R,onChange:e=>se(e.target.value),placeholder:n(`smartPlugs.restBodyHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restOffUrl`)}),(0,Y.jsx)(`input`,{type:`text`,value:ce,onChange:e=>{z(e.target.value),vt(null)},placeholder:`http://openhab:8080/rest/items/MyPlug`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restOffBody`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsx)(`input`,{type:`text`,value:B,onChange:e=>le(e.target.value),placeholder:n(`smartPlugs.restBodyHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.restHeaders`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsx)(`div`,{children:(0,Y.jsx)(`textarea`,{value:de,onChange:e=>fe(e.target.value),placeholder:n(`smartPlugs.restHeadersHint`),rows:2,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none font-mono text-sm`})})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.stateMonitoring`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusUrl`)}),(0,Y.jsx)(`input`,{type:`text`,value:pe,onChange:e=>me(e.target.value),placeholder:n(`smartPlugs.restStatusHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:he,onChange:e=>ge(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusOnValue`)}),(0,Y.jsx)(`input`,{type:`text`,value:_e,onChange:e=>ve(e.target.value),placeholder:`ON`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.energyMonitoring`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restPowerUrl`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsx)(`input`,{type:`text`,value:ye,onChange:e=>be(e.target.value),placeholder:n(`smartPlugs.restPowerUrlHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restPowerPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:H,onChange:e=>xe(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restPowerMultiplier`)}),(0,Y.jsx)(`input`,{type:`text`,value:Se,onChange:e=>Ce(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restEnergyUrl`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsx)(`input`,{type:`text`,value:we,onChange:e=>Te(e.target.value),placeholder:n(`smartPlugs.restEnergyUrlHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:Ee,onChange:e=>De(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyMultiplier`)}),(0,Y.jsx)(`input`,{type:`text`,value:Oe,onChange:e=>ke(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.restEnergyHint`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyTotalPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:je,onChange:e=>Me(e.target.value),placeholder:n(`smartPlugs.restEnergyTotalPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyTotalMultiplier`)}),(0,Y.jsx)(`input`,{type:`text`,value:Ne,onChange:e=>Pe(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.restEnergyTotalHint`)})]}),(P.trim()||ce.trim())&&(0,Y.jsx)(`div`,{className:`flex gap-2`,children:(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,onClick:async()=>{vt(null);try{let e=P.trim()||ce.trim(),t=await r.testRESTConnection(e,V,de.trim()||null);vt({success:t.success}),t.success||bt(t.error||n(`smartPlugs.addSmartPlug.connectionFailed`))}catch{vt({success:!1}),bt(n(`smartPlugs.addSmartPlug.connectionFailed`))}},className:`w-full`,children:[(0,Y.jsx)(ht,{className:`w-4 h-4`}),n(`smartPlugs.testConnection`)]})}),gt&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm ${gt.success?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:[gt.success?(0,Y.jsx)(j,{className:`w-4 h-4`}):(0,Y.jsx)(Ye,{className:`w-4 h-4`}),gt.success?n(`smartPlugs.connectionSuccess`):n(`smartPlugs.addSmartPlug.connectionFailed`)]})]}),o===`tasmota`&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.ipAddress`)}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`text`,value:m,onChange:e=>{h(e.target.value),vt(null)},placeholder:`192.168.1.100`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,onClick:()=>on.mutate(),disabled:!m.trim()||on.isPending,children:[on.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(ht,{className:`w-4 h-4`}),n(`smartPlugs.test`)]})]})]}),o===`tasmota`&&gt&&(0,Y.jsx)(`div`,{className:`p-3 rounded-lg flex items-center gap-2 ${gt.success?`bg-bambu-green/20 border border-bambu-green/50 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 border border-red-400 dark:border-red-500/50 text-red-700 dark:text-red-400`}`,children:gt.success?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(j,{className:`w-5 h-5`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`font-medium`,children:n(`smartPlugs.connectedResult`)}),(0,Y.jsxs)(`p`,{className:`text-sm opacity-80`,children:[gt.device_name&&n(`smartPlugs.deviceLabel`,{name:gt.device_name}),n(`smartPlugs.stateLabel`,{state:gt.state})]})]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Ye,{className:`w-5 h-5`}),(0,Y.jsx)(`span`,{children:n(`smartPlugs.addSmartPlug.connectionFailed`)})]})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.nameLabel`)}),(0,Y.jsx)(`input`,{type:`text`,value:c,onChange:e=>p(e.target.value),placeholder:n(`smartPlugs.addSmartPlug.placeholders.plugName`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),o===`tasmota`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.username`)}),(0,Y.jsx)(`input`,{type:`text`,value:g,onChange:e=>_(e.target.value),placeholder:`admin`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.password`)}),(0,Y.jsx)(`input`,{type:`password`,value:v,onChange:e=>y(e.target.value),placeholder:`********`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray -mt-2`,children:n(`smartPlugs.authHint`)})]}),o!==`mqtt`&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.linkToPrinter`)}),(0,Y.jsxs)(`select`,{value:ct??``,onChange:e=>ut(e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`smartPlugs.noPrinter`)}),ln?.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`smartPlugs.linkingDescription`)}),ct!==null&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mt-3`,children:[(0,Y.jsxs)(`div`,{className:`pr-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.controlsPrinterPower`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.controlsPrinterPowerDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer shrink-0`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:ft,onChange:e=>pt(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]}),(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(rt,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.powerAlerts`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:xt,onChange:e=>St(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),xt&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.alertAbove`)}),(0,Y.jsx)(`input`,{type:`number`,value:wt,onChange:e=>Tt(e.target.value),placeholder:`e.g. 200`,min:`0`,max:`5000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.alertBelow`)}),(0,Y.jsx)(`input`,{type:`number`,value:Et,onChange:e=>Dt(e.target.value),placeholder:`e.g. 10`,min:`0`,max:`5000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.alertDescription`)})]})]}),o!==`mqtt`&&(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(lt,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.dailySchedule`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Ot,onChange:e=>kt(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),Ot&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.turnOnAt`)}),(0,Y.jsx)(`input`,{type:`time`,value:At,onChange:e=>jt(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.turnOffAt`)}),(0,Y.jsx)(`input`,{type:`time`,value:Mt,onChange:e=>Nt(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.scheduleDescription`)})]})]}),(0,Y.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(F,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.showInSwitchbar`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.quickAccessSidebar`)})]})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Pt,onChange:e=>It(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})}),o===`homeassistant`&&(0,Y.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(mt,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.showOnPrinterCard`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.displayOnPrinterCard`)})]})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Lt,onChange:e=>Rt(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})}),(0,Y.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`smartPlugs.cancel`)}),(0,Y.jsxs)(K,{type:`submit`,disabled:J,className:`flex-1`,children:[J?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(_t,{className:`w-4 h-4`}),n(a?`smartPlugs.save`:`smartPlugs.add`)]})]})]})]})})}function pr({sensor:e,printers:t,onClose:n}){let{t:i}=l(),a=u(),{showToast:o}=ee(),s=!!e,[c,p]=(0,X.useState)(e?.printer_id??t[0]?.id??``),[m,h]=(0,X.useState)(e?.entity_id??``),[g,_]=(0,X.useState)(e?.kind??`binary`),[v,y]=(0,X.useState)(e?.device_class??null),[b,S]=(0,X.useState)(e?.unit??null),[C,w]=(0,X.useState)(e?.name??``),[T,E]=(0,X.useState)(e?.alert_state??``),[D,O]=(0,X.useState)(e?.alert_above?.toString()??``),[k,A]=(0,X.useState)(e?.alert_below?.toString()??``),[j,te]=(0,X.useState)(e?.show_on_printer_card??!0),[M,N]=(0,X.useState)(e?.notify_on_alert??!1),[ne,re]=(0,X.useState)(e?.block_print??!1),[ae,oe]=(0,X.useState)(``),[P,F]=(0,X.useState)(null);(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let{data:I}=d({queryKey:[`settings`],queryFn:r.getSettings}),R=!!(I?.ha_enabled&&I?.ha_url&&I?.ha_token),{data:se,isLoading:ce,error:z}=d({queryKey:[`bindableHAEntities`],queryFn:()=>r.getBindableHAEntities(),enabled:R}),B=(0,X.useMemo)(()=>{let e=ae.trim().toLowerCase(),t=se??[];return e?t.filter(t=>t.entity_id.toLowerCase().includes(e)||t.friendly_name.toLowerCase().includes(e)):t},[se,ae]),le=e=>{h(e.entity_id),y(e.device_class),S(e.unit_of_measurement);let t=e.domain===`binary_sensor`?`binary`:`numeric`;_(t),t===`numeric`?E(``):(O(``),A(``)),C.trim()||w(e.friendly_name.slice(0,100))},V=()=>{a.invalidateQueries({queryKey:[`haSensors`]}),a.invalidateQueries({queryKey:[`haSensorReadings`]})},ue=f({mutationFn:()=>{let t={name:C.trim(),entity_id:m,kind:g,device_class:v,unit:b,alert_state:g===`binary`&&T?T:null,alert_above:g===`numeric`&&D!==``?Number(D):null,alert_below:g===`numeric`&&k!==``?Number(k):null,block_print:ne,notify_on_alert:M,show_on_printer_card:j};return s?r.updateHASensor(e.id,t):r.createHASensor({...t,printer_id:Number(c)})},onSuccess:()=>{V(),o(i(s?`haSensors.toast.updated`:`haSensors.toast.created`),`success`),n()},onError:e=>F(e.message)}),de=f({mutationFn:()=>r.deleteHASensor(e.id),onSuccess:()=>{V(),o(i(`haSensors.toast.deleted`),`success`),n()},onError:e=>F(e.message)}),fe=g===`binary`?T!==``:D!==``||k!==``,pe=e=>{if(e.preventDefault(),F(null),!m)return F(i(`haSensors.error.pickEntity`));if(!C.trim())return F(i(`haSensors.error.nameRequired`));if(c===``)return F(i(`haSensors.error.printerRequired`));if((ne||M)&&!fe)return F(i(`haSensors.error.alertRequired`));ue.mutate()},me=x[v??``],he=e=>{let t=me?.[e]??e;return i(`haSensors.states.${t}`,{defaultValue:t})},ge=ue.isPending||de.isPending;return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,Y.jsx)(ie,{className:`w-5 h-5`})}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(s?`haSensors.editTitle`:`haSensors.addTitle`)})]}),(0,Y.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:pe,className:`p-6 space-y-4`,children:[P&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:P}),!s&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`haSensors.printer`)}),(0,Y.jsx)(`select`,{value:c,onChange:e=>p(e.target.value===``?``:Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:t.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),!R&&(0,Y.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[i(`smartPlugs.haNotConfigured`),` `,(0,Y.jsx)(`span`,{className:`font-medium`,children:i(`smartPlugs.haSettingsPath`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 ${R?``:`opacity-50`}`,children:i(`haSensors.entity`)}),z&&(0,Y.jsx)(`div`,{className:`p-3 mb-2 bg-red-100 dark:bg-red-500/20 rounded-lg text-sm text-red-700 dark:text-red-400`,children:z.message}),(0,Y.jsxs)(`div`,{className:`relative mb-2`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Y.jsx)(`input`,{type:`text`,value:ae,onChange:e=>oe(e.target.value),placeholder:i(`haSensors.searchPlaceholder`),disabled:!R,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:opacity-50 disabled:cursor-not-allowed`})]}),(0,Y.jsxs)(`div`,{className:`max-h-44 overflow-y-auto rounded-lg border border-bambu-dark-tertiary ${R?``:`opacity-50`}`,children:[!R&&(0,Y.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:i(`haSensors.noEntities`)}),R&&ce&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 p-3 text-sm text-bambu-gray`,children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}),i(`common.loading`)]}),R&&!ce&&B.length===0&&(0,Y.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:i(`haSensors.noEntities`)}),R&&!ce&&B.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>le(e),className:`w-full text-left px-3 py-2 text-sm transition-colors ${e.entity_id===m?`bg-bambu-green/20 text-bambu-green`:`text-white hover:bg-bambu-dark`}`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,e.state!==null&&` — ${e.state}`,e.unit_of_measurement?` ${e.unit_of_measurement}`:``]})]},e.entity_id))]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`haSensors.name`)}),(0,Y.jsx)(`input`,{type:`text`,value:C,onChange:e=>w(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`haSensors.alertWhen`)}),g===`binary`?(0,Y.jsxs)(`select`,{value:T,onChange:e=>E(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:[(0,Y.jsx)(`option`,{value:``,children:i(`haSensors.alertNever`)}),(0,Y.jsx)(`option`,{value:`on`,children:he(`on`)}),(0,Y.jsx)(`option`,{value:`off`,children:he(`off`)})]}):(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[i(`haSensors.alertAbove`),` `,b??``]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:D,onChange:e=>O(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[i(`haSensors.alertBelow`),` `,b??``]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:k,onChange:e=>A(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]})]}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:i(`haSensors.alertHint`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:j,onChange:e=>te(e.target.checked),className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:i(`haSensors.showOnCard`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:M,onChange:e=>N(e.target.checked),disabled:!fe,className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm ${fe?`text-white`:`text-bambu-gray`}`,children:i(`haSensors.notifyOnAlert`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-start gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:ne,onChange:e=>re(e.target.checked),disabled:!fe,className:`w-4 h-4 mt-0.5`}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`span`,{className:`block text-sm ${fe?`text-white`:`text-bambu-gray`}`,children:i(`haSensors.blockPrint`)}),(0,Y.jsx)(`span`,{className:`block text-xs text-bambu-gray`,children:i(`haSensors.blockPrintHint`)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pt-2`,children:[s?(0,Y.jsx)(K,{type:`button`,variant:`danger`,onClick:()=>de.mutate(),disabled:ge,children:i(`common.delete`)}):(0,Y.jsx)(`span`,{}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:n,disabled:ge,children:i(`common.cancel`)}),(0,Y.jsxs)(K,{type:`submit`,disabled:ge||!R&&!s,children:[ge?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(_t,{className:`w-4 h-4`}),i(`common.save`)]})]})]})]})]})})}function mr(e){return e===`temperature`?`temperature`:e===`humidity`?`humidity`:e===`battery`?`battery`:null}var hr={temperature:`temperature`,humidity:`humidity`,battery:`battery`};function gr(e,t,n){let r=hr[t];if(!e.toLowerCase().endsWith(r))return[];let i=e.slice(0,e.length-r.length),a=[];return Object.keys(hr).forEach(e=>{if(e===t)return;let r=`${i}${hr[e]}`.toLowerCase(),o=n.find(e=>e.entity_id.toLowerCase()===r);o&&a.push(o)}),a}function _r({sensor:e,locations:t,onClose:n}){let{t:i}=l(),a=u(),{showToast:o}=ee(),s=!!e,[c,p]=(0,X.useState)(e?.location_id??t[0]?.id??``),[m,h]=(0,X.useState)(e?.entity_id??``),[g,_]=(0,X.useState)(e?.kind??`numeric`),[v,y]=(0,X.useState)(e?.device_class??null),[b,S]=(0,X.useState)(e?.unit??null),[C,w]=(0,X.useState)(e?.name??``),T=(0,X.useRef)(e?.name??``),[E,D]=(0,X.useState)(e?.alert_state??``),[O,k]=(0,X.useState)(e?.alert_above?.toString()??``),[A,j]=(0,X.useState)(e?.alert_below?.toString()??``),[te,M]=(0,X.useState)(e?.notify_on_alert??!1),[N,ne]=(0,X.useState)(e?.show_on_card??!0),[re,ae]=(0,X.useState)(``),[oe,P]=(0,X.useState)(null),[F,I]=(0,X.useState)(!1),[R,se]=(0,X.useState)(!1),[ce,z]=(0,X.useState)(null),[B,le]=(0,X.useState)(!1),[ue,de]=(0,X.useState)([]),[fe,pe]=(0,X.useState)({}),{data:me}=d({queryKey:[`settings`],queryFn:r.getSettings}),ge=!!(me?.ha_enabled&&me?.ha_url&&me?.ha_token),{data:_e,isLoading:ve,error:ye}=d({queryKey:[`bindableLocationHAEntities`],queryFn:()=>r.getBindableLocationHAEntities(),enabled:ge}),be=(0,X.useMemo)(()=>(_e??[]).filter(e=>mr(e.device_class)!==null),[_e]),{data:H}=d({queryKey:[`locationHaSensors`],queryFn:()=>r.getLocationHASensors()}),xe=be.find(e=>e.entity_id===m),Se=(0,X.useMemo)(()=>{let e=re.trim().toLowerCase(),t=be??[],n=e?t.filter(t=>t.entity_id.toLowerCase().includes(e)||t.friendly_name.toLowerCase().includes(e)):t;return!xe||n[0]?.entity_id===xe.entity_id?n:[xe,...n.filter(e=>e.entity_id!==xe.entity_id)]},[be,re,xe]),Ce=e=>{h(e.entity_id),y(e.device_class),S(e.unit_of_measurement?.slice(0,16)??null);let t=e.domain===`binary_sensor`?`binary`:`numeric`;if(_(t),t===`numeric`?D(``):(k(``),j(``)),C===T.current){let t=e.friendly_name.slice(0,100);w(t),T.current=t}if(!s){let n=mr(e.device_class);if(n){let e=he(me?.location_sensor_alert_defaults)[n];t===`numeric`&&(k(n===`battery`?``:e.alertAbove),j(e.alertBelow)),M(e.notifyOnAlert),ne(e.showOnCard)}}},we=()=>{a.invalidateQueries({queryKey:[`locationHaSensors`]}),a.invalidateQueries({queryKey:[`locationHaSensorReadings`]})},Te=()=>({name:C.trim(),entity_id:m,kind:g,device_class:v,unit:b,alert_state:g===`binary`&&E?E:null,alert_above:g===`numeric`&&mr(v)!==`battery`&&O!==``?Number(O):null,alert_below:g===`numeric`&&A!==``?Number(A):null,notify_on_alert:te,show_on_card:N}),Ee=f({mutationFn:()=>{let t=Te();return s?r.updateLocationHASensor(e.id,t):r.createLocationHASensor({...t,location_id:Number(c)})},onSuccess:()=>{we(),o(i(s?`locationHaSensors.toast.updated`:`locationHaSensors.toast.created`),`success`),n()},onError:e=>P(e.message)}),De=f({mutationFn:async()=>{let e=Number(c);await r.createLocationHASensor({...Te(),location_id:e});let t=he(me?.location_sensor_alert_defaults),n=ue.filter(e=>fe[e.entity_id]);for(let i of n){let n=mr(i.device_class),a=n?t[n]:null;await r.createLocationHASensor({name:i.friendly_name.slice(0,100),entity_id:i.entity_id,kind:i.domain===`binary_sensor`?`binary`:`numeric`,device_class:i.device_class,unit:i.unit_of_measurement?.slice(0,16)??null,alert_state:null,alert_above:n!==`battery`&&a&&a.alertAbove!==``?Number(a.alertAbove):null,alert_below:a&&a.alertBelow!==``?Number(a.alertBelow):null,notify_on_alert:a?.notifyOnAlert??!1,show_on_card:a?.showOnCard??N,location_id:e})}return n},onSuccess:e=>{we(),le(!1),e.length>0?o(i(`locationHaSensors.autoAdd.added`,{names:e.map(e=>e.entity_id).join(`, `)}),`success`):o(i(`locationHaSensors.toast.created`),`success`),n()},onError:e=>{we(),le(!1),P(e.message)}}),Oe=f({mutationFn:()=>r.deleteLocationHASensor(e.id),onSuccess:()=>{we(),o(i(`locationHaSensors.toast.deleted`),`success`),n()},onError:e=>P(e.message)}),ke=f({mutationFn:()=>r.updateLocationHASensor(ce.id,Te()),onSuccess:()=>{we(),se(!1),z(null),o(i(`locationHaSensors.toast.updated`),`success`),n()},onError:e=>{se(!1),z(null),P(e.message)}}),je=g===`binary`?E!==``:O!==``||A!==``,Me=e=>{if(e.preventDefault(),P(null),!m)return P(i(`haSensors.error.pickEntity`));if(!C.trim())return P(i(`haSensors.error.nameRequired`));if(c===``)return P(i(`locationHaSensors.error.locationRequired`));if(te&&!je)return P(i(`haSensors.error.alertRequired`));if(!s){let e=(H??[]).filter(e=>e.location_id===Number(c)),t=mr(v);if(t){let n=e.find(e=>mr(e.device_class)===t);if(n){z(n),se(!0);return}}if(e.length===0&&t){let e=gr(m,t,be);if(e.length>0){de(e),pe(Object.fromEntries(e.map(e=>[e.entity_id,!0]))),le(!0);return}o(i(`locationHaSensors.autoAdd.noneFound`),`info`)}}Ee.mutate()},Ne=x[v??``],Pe=e=>{let t=Ne?.[e]??e;return i(`haSensors.states.${t}`,{defaultValue:t})},Fe=Ee.isPending||Oe.isPending||ke.isPending||De.isPending,Ie=t.find(e=>e.id===Number(c));return(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!Fe&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n,Fe]),(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>{Fe||n()},children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,Y.jsx)(ie,{className:`w-5 h-5`})}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(s?`locationHaSensors.editTitle`:`locationHaSensors.addTitle`)})]}),(0,Y.jsx)(`button`,{onClick:n,disabled:Fe,className:`text-bambu-gray hover:text-white transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:Me,className:`p-6 space-y-4`,children:[oe&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:oe}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`locationHaSensors.location`)}),s?(0,Y.jsx)(`div`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:t.find(t=>t.id===e.location_id)?.name??i(`locationHaSensors.unknownLocation`)}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`select`,{value:c,onChange:e=>p(e.target.value===``?``:Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:t.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>I(!0),className:`p-2 rounded-lg bg-bambu-dark-tertiary hover:bg-bambu-gray-dark text-white transition-colors shrink-0`,title:i(`locations.add`),"aria-label":i(`locations.add`),children:(0,Y.jsx)(wt,{className:`w-4 h-4`})})]})]}),!ge&&(0,Y.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[i(`smartPlugs.haNotConfigured`),` `,(0,Y.jsx)(`span`,{className:`font-medium`,children:i(`smartPlugs.haSettingsPath`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 ${ge?``:`opacity-50`}`,children:i(`haSensors.entity`)}),ye&&(0,Y.jsx)(`div`,{className:`p-3 mb-2 bg-red-100 dark:bg-red-500/20 rounded-lg text-sm text-red-700 dark:text-red-400`,children:ye.message}),(0,Y.jsxs)(`div`,{className:`relative mb-2`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Y.jsx)(`input`,{type:`text`,value:re,onChange:e=>ae(e.target.value),placeholder:i(`haSensors.searchPlaceholder`),disabled:!ge,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:opacity-50 disabled:cursor-not-allowed`})]}),(0,Y.jsxs)(`div`,{className:`max-h-44 overflow-y-auto rounded-lg border border-bambu-dark-tertiary ${ge?``:`opacity-50`}`,children:[m&&!xe&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm bg-bambu-green/10 text-bambu-green border-b border-bambu-dark-tertiary`,children:i(`locationHaSensors.currentlyBound`,{entity:m})}),!ge&&(0,Y.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:i(`haSensors.noEntities`)}),ge&&ve&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 p-3 text-sm text-bambu-gray`,children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}),i(`common.loading`)]}),ge&&!ve&&Se.length===0&&(0,Y.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:i(`haSensors.noEntities`)}),ge&&!ve&&Se.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>Ce(e),className:`w-full text-left px-3 py-2 text-sm transition-colors ${e.entity_id===m?`bg-bambu-green/20 text-bambu-green`:`text-white hover:bg-bambu-dark`}`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,e.state!==null&&` — ${e.state}`,e.unit_of_measurement?` ${e.unit_of_measurement}`:``]})]},e.entity_id))]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,htmlFor:`location-ha-sensor-name`,children:i(`haSensors.name`)}),(0,Y.jsx)(`input`,{id:`location-ha-sensor-name`,type:`text`,value:C,onChange:e=>w(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),m&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`haSensors.alertWhen`)}),g===`binary`?(0,Y.jsxs)(`select`,{value:E,onChange:e=>D(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:[(0,Y.jsx)(`option`,{value:``,children:i(`haSensors.alertNever`)}),(0,Y.jsx)(`option`,{value:`on`,children:Pe(`on`)}),(0,Y.jsx)(`option`,{value:`off`,children:Pe(`off`)})]}):mr(v)===`battery`?(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[i(`haSensors.alertBelow`),` `,b??``]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:A,onChange:e=>j(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}):(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[i(`haSensors.alertAbove`),` `,b??``]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:O,onChange:e=>k(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[i(`haSensors.alertBelow`),` `,b??``]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:A,onChange:e=>j(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]})]}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:i(`haSensors.alertHint`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:N,onChange:e=>ne(e.target.checked),className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:i(`locationHaSensors.showOnCard`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:te,onChange:e=>M(e.target.checked),disabled:!je,className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm ${je?`text-white`:`text-bambu-gray`}`,children:i(`haSensors.notifyOnAlert`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pt-2`,children:[s?(0,Y.jsx)(K,{type:`button`,variant:`danger`,onClick:()=>Oe.mutate(),disabled:Fe,children:i(`common.delete`)}):(0,Y.jsx)(`span`,{}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:n,disabled:Fe,children:i(`common.cancel`)}),(0,Y.jsxs)(K,{type:`submit`,disabled:Fe||!ge&&!s,children:[Fe?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(_t,{className:`w-4 h-4`}),i(`common.save`)]})]})]})]})]})}),R&&ce&&(0,Y.jsx)(Tt,{title:i(`locationHaSensors.overwriteConfirm.title`),message:i(`locationHaSensors.overwriteConfirm.message${mr(ce.device_class)===`humidity`?`Humidity`:mr(ce.device_class)===`battery`?`Battery`:`Temperature`}`,{location:Ie?.name??``,name:ce.name}),variant:`warning`,overlayZIndex:`z-[110]`,isLoading:ke.isPending,onConfirm:()=>ke.mutate(),onCancel:()=>{se(!1),z(null)}}),B&&ue.length>0&&(0,Y.jsx)(Tt,{title:i(`locationHaSensors.autoAdd.confirmTitle`),message:i(`locationHaSensors.autoAdd.confirmMessage`),overlayZIndex:`z-[110]`,isLoading:De.isPending,confirmDisabled:!ue.some(e=>fe[e.entity_id]),onConfirm:()=>De.mutate(),cancelText:i(`locationHaSensors.autoAdd.onlyThisOne`),onCancel:()=>{le(!1),de([]),pe({}),Ee.mutate()},children:(0,Y.jsx)(`div`,{className:`space-y-2`,children:ue.map(e=>(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:fe[e.entity_id]??!0,onChange:t=>pe(n=>({...n,[e.entity_id]:t.target.checked})),className:`w-4 h-4`}),(0,Y.jsxs)(`span`,{className:`text-sm text-white`,children:[e.friendly_name,(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,e.entity_id]})]})]},e.entity_id))})}),F&&(0,Y.jsx)(V,{open:F,onClose:()=>I(!1),onPickLocation:e=>{p(e),I(!1)},startCreating:!0})]})}var vr=60,yr=120,br={temperature:Fe,humidity:y,battery:_},xr={temperature:`°C`,humidity:`%`,battery:`%`};function Sr(e){return e===`temperature`?`temperature`:e===`humidity`?`humidity`:e===`battery`?`battery`:null}function Cr({category:e,state:t,onChange:n}){let{t:r}=l(),i=br[e],a=xr[e],o=t.alertAbove!==``||t.alertBelow!==``;return(0,Y.jsxs)(`div`,{className:`p-3 border border-bambu-dark-tertiary rounded-lg space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm text-white font-medium`,children:[(0,Y.jsx)(i,{className:`w-4 h-4`}),r(`inventory.${e}`)]}),e===`battery`?(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertBelow`),` `,a]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:t.alertBelow,onChange:e=>n({alertBelow:e.target.value}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}):(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertAbove`),` `,a]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:t.alertAbove,onChange:e=>n({alertAbove:e.target.value}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertBelow`),` `,a]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:t.alertBelow,onChange:e=>n({alertBelow:e.target.value}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:t.showOnCard,onChange:e=>n({showOnCard:e.target.checked}),className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:r(`locationHaSensors.showOnCard`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:t.notifyOnAlert,onChange:e=>n({notifyOnAlert:e.target.checked}),disabled:!o,className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm ${o?`text-white`:`text-bambu-gray`}`,children:r(`haSensors.notifyOnAlert`)})]})]})}function wr({onClose:e}){let{t}=l(),{showToast:n}=ee(),i=u(),[a,o]=(0,X.useState)(()=>he()),[s,c]=(0,X.useState)(()=>ce()),[p,m]=(0,X.useState)(()=>me()),[h,g]=(0,X.useState)(()=>_e()),[_,v]=(0,X.useState)(()=>de()),[y,b]=(0,X.useState)(!1),{data:x}=d({queryKey:[`settings`],queryFn:r.getSettings}),[S,C]=(0,X.useState)(yr),w=(0,X.useRef)(!1),T=(0,X.useRef)(new Set);(0,X.useEffect)(()=>{if(!x||w.current)return;w.current=!0,T.current.has(`pollInterval`)||C(x.location_sensor_poll_interval);let e=he(x.location_sensor_alert_defaults);o(t=>{let n={...e};return Object.keys(n).forEach(e=>{T.current.has(e)&&(n[e]=t[e])}),n})},[x]);let E=(e,t)=>{T.current.add(e),o(n=>({...n,[e]:{...n[e],...t}}))},D=e=>{T.current.add(`pollInterval`),C(e)},O=async()=>{let e=Math.max(vr,S),t=pe({...a,battery:{...a.battery,alertAbove:``}}),n={};x&&e!==x.location_sensor_poll_interval&&(n.location_sensor_poll_interval=e),x&&t!==x.location_sensor_alert_defaults&&(n.location_sensor_alert_defaults=t),Object.keys(n).length>0&&(await r.updateSettings(n),i.invalidateQueries({queryKey:[`settings`]})),ge(a),le(s),fe(p),be(h),B(_)},k=f({mutationFn:O,onSuccess:()=>{n(t(`locationHaSensors.options.saved`),`success`),e()},onError:e=>{n(e.message||t(`locationHaSensors.options.saveFailed`),`error`)}}),A=e=>{e.preventDefault(),k.mutate()},j=f({mutationFn:async()=>{let[e,t]=await Promise.all([r.getLocationHASensors(),r.getBindableLocationHAEntities()]),n=new Map(t.map(e=>[e.entity_id,e.friendly_name])),i=e.filter(e=>Sr(e.device_class)!==null);return await Promise.all(i.map(e=>{let t=Sr(e.device_class),i=a[t],o=n.get(e.entity_id);return r.updateLocationHASensor(e.id,{...o?{name:o.slice(0,100)}:{},alert_above:t!==`battery`&&i.alertAbove!==``?Number(i.alertAbove):null,alert_below:i.alertBelow===``?null:Number(i.alertBelow),notify_on_alert:i.notifyOnAlert,show_on_card:i.showOnCard})})),await O(),i.length},onSuccess:r=>{i.invalidateQueries({queryKey:[`locationHaSensors`]}),i.invalidateQueries({queryKey:[`locationHaSensorReadings`]}),n(t(`locationHaSensors.options.resetDone`,{count:r}),`success`),b(!1),e()},onError:e=>{n(e.message||t(`locationHaSensors.options.resetFailed`),`error`),b(!1)}});return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:e,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,Y.jsx)(je,{className:`w-5 h-5`})}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t(`locationHaSensors.options.title`)})]}),(0,Y.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:A,className:`px-6 pb-6 pt-3 space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`locationHaSensors.options.description`)}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(Cr,{category:`temperature`,state:a.temperature,onChange:e=>E(`temperature`,e)}),(0,Y.jsx)(Cr,{category:`humidity`,state:a.humidity,onChange:e=>E(`humidity`,e)}),(0,Y.jsx)(Cr,{category:`battery`,state:a.battery,onChange:e=>E(`battery`,e)})]}),(0,Y.jsxs)(`div`,{className:`p-3 border border-bambu-dark-tertiary rounded-lg space-y-3`,children:[(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked),className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:t(`locationHaSensors.options.colorizeValues`)})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-3 gap-x-3 gap-y-1 items-end ${s?``:`opacity-50`}`,children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray`,htmlFor:`location-sensor-below-color`,children:t(`locationHaSensors.options.belowColor`)}),(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray`,htmlFor:`location-sensor-optimal-color`,children:t(`locationHaSensors.options.optimalColor`)}),(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray`,htmlFor:`location-sensor-above-color`,children:t(`locationHaSensors.options.aboveColor`)}),(0,Y.jsx)(`select`,{id:`location-sensor-below-color`,value:h,onChange:e=>g(e.target.value),disabled:!s,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:cursor-not-allowed`,children:ye.map(e=>(0,Y.jsx)(`option`,{value:e,children:t(`locationHaSensors.options.colors.${e}`)},e))}),(0,Y.jsx)(`select`,{id:`location-sensor-optimal-color`,value:_,onChange:e=>v(e.target.value),disabled:!s,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:cursor-not-allowed`,children:ye.map(e=>(0,Y.jsx)(`option`,{value:e,children:t(`locationHaSensors.options.colors.${e}`)},e))}),(0,Y.jsx)(`select`,{id:`location-sensor-above-color`,value:p,onChange:e=>m(e.target.value),disabled:!s,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:cursor-not-allowed`,children:ye.map(e=>(0,Y.jsx)(`option`,{value:e,children:t(`locationHaSensors.options.colors.${e}`)},e))})]})]}),(0,Y.jsx)(`div`,{className:`pt-4 mt-4 border-t border-bambu-dark-tertiary`,children:(0,Y.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider mb-3`,children:t(`locationHaSensors.options.generalSettings`)})}),(0,Y.jsxs)(`div`,{className:`p-3 border border-bambu-dark-tertiary rounded-lg space-y-2`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-white`,htmlFor:`location-sensor-poll-interval`,children:t(`locationHaSensors.options.pollInterval`)}),(0,Y.jsx)(`input`,{id:`location-sensor-poll-interval`,type:`number`,min:vr,step:`1`,value:S,onChange:e=>D(Number(e.target.value)),onBlur:()=>D(Math.max(vr,S||yr)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`locationHaSensors.options.pollIntervalHint`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 pt-2`,children:[(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,onClick:()=>b(!0),children:[(0,Y.jsx)(nt,{className:`w-4 h-4`}),t(`locationHaSensors.options.reset`)]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:e,children:t(`common.cancel`)}),(0,Y.jsxs)(K,{type:`submit`,disabled:k.isPending,children:[(0,Y.jsx)(_t,{className:`w-4 h-4`}),t(`common.save`)]})]})]})]})]})}),y&&(0,Y.jsx)(Tt,{title:t(`locationHaSensors.options.resetConfirm.title`),message:t(`locationHaSensors.options.resetConfirm.message`),confirmText:t(`locationHaSensors.options.reset`),variant:`danger`,overlayZIndex:`z-[60]`,isLoading:j.isPending,onConfirm:()=>j.mutate(),onCancel:()=>b(!1)})]})}function Tr({provider:e,onEdit:t}){let{t:n}=l(),i=u(),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(!1),[p,m]=(0,X.useState)(null),{data:h}=d({queryKey:[`printers`],queryFn:r.getPrinters}),g=h?.find(t=>t.id===e.printer_id),_=f({mutationFn:t=>r.updateNotificationProvider(e.id,t),onSuccess:()=>{i.invalidateQueries({queryKey:[`notification-providers`]})}}),v=f({mutationFn:()=>r.deleteNotificationProvider(e.id),onSuccess:()=>{i.invalidateQueries({queryKey:[`notification-providers`]})}}),y=f({mutationFn:()=>r.testNotificationProvider(e.id),onSuccess:e=>{m(e),i.invalidateQueries({queryKey:[`notification-providers`]})},onError:e=>{m({success:!1,message:e.message})}}),b=e=>e||``;return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(G,{className:`relative`,children:(0,Y.jsxs)(W,{className:`p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between ${e.enabled?`mb-3`:`mb-0`}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded-lg ${e.enabled?`bg-bambu-green/20`:`bg-bambu-dark`}`,children:(0,Y.jsx)(rt,{className:`w-5 h-5 ${e.enabled?`text-bambu-green`:`text-bambu-gray`}`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`font-medium text-white`,children:e.name}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.providerTypes.${e.provider_type}`,e.provider_type)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e.last_success&&(0,Y.jsx)(`span`,{className:`text-xs text-status-ok hidden sm:inline`,children:n(`notifications.lastSuccess`,{date:He(e.last_success)})}),e.last_error&&e.last_error_at&&(!e.last_success||(We(e.last_error_at)?.getTime()||0)>(We(e.last_success)?.getTime()||0))&&(0,Y.jsx)(`span`,{className:`text-xs text-status-error`,title:e.last_error,children:n(`notifications.error`)}),(0,Y.jsx)(J,{checked:e.enabled,onChange:e=>_.mutate({enabled:e})})]})]}),e.enabled&&(0,Y.jsxs)(Y.Fragment,{children:[g&&(0,Y.jsxs)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:[(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[n(`notifications.printer`),` `]}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:g.name})]}),!g&&!e.printer_id&&(0,Y.jsx)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.allPrinters`)})}),(0,Y.jsxs)(`div`,{className:`mb-3 flex flex-wrap gap-1`,children:[e.on_print_start&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 text-xs rounded`,children:n(`notifications.start`)}),e.on_plate_not_empty&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-100 dark:bg-rose-600/20 text-rose-700 dark:text-rose-300 text-xs rounded`,children:n(`notifications.plateCheck`)}),e.on_print_complete&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded`,children:n(`notifications.complete`)}),e.on_plate_clear_required&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 text-xs rounded`,children:n(`notifications.plateClear`)}),e.on_print_confirm_request&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-xs rounded`,children:n(`notifications.printConfirmRequest`)}),e.provider_type===`telegram`&&e.on_print_confirm_request&&e.telegram_verdict_mode===`reactions`&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-sky-100 dark:bg-sky-500/20 text-sky-700 dark:text-sky-400 text-xs rounded`,children:n(`notifications.telegramVerdictBadgeReactions`)}),e.provider_type===`telegram`&&e.on_print_confirm_request&&e.telegram_verdict_mode===`both`&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-sky-100 dark:bg-sky-500/20 text-sky-700 dark:text-sky-400 text-xs rounded`,children:n(`notifications.telegramVerdictBadgeBoth`)}),e.on_print_failed&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 text-xs rounded`,children:n(`notifications.failed`)}),e.on_print_stopped&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400 text-xs rounded`,children:n(`notifications.stopped`)}),e.on_billing_charge_failed&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-red-100 dark:bg-red-600/20 text-red-700 dark:text-red-300 text-xs rounded`,children:n(`notifications.billingChargeFailedLabel`)}),e.on_print_progress&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-xs rounded`,children:n(`notifications.progress`)}),e.on_printer_offline&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded`,children:n(`notifications.offline`)}),e.on_printer_error&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-100 dark:bg-rose-500/20 text-rose-700 dark:text-rose-400 text-xs rounded`,children:n(`notifications.error`)}),e.on_ai_failure_detection&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-fuchsia-100 dark:bg-fuchsia-500/20 text-fuchsia-700 dark:text-fuchsia-300 text-xs rounded`,children:n(`notifications.aiFailureDetection`)}),e.on_ha_sensor_alert&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-300 text-xs rounded`,children:n(`notifications.haSensorAlert`)}),e.on_location_ha_sensor_alert&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-300 text-xs rounded`,children:n(`notifications.locationHaSensorAlert`)}),e.on_filament_low&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-400 text-xs rounded`,children:n(`notifications.lowFilament`)}),e.on_maintenance_due&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400 text-xs rounded`,children:n(`notifications.maintenance`)}),e.on_ams_humidity_high&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-blue-100 dark:bg-blue-600/20 text-blue-700 dark:text-blue-300 text-xs rounded`,children:n(`notifications.amsHumidity`)}),e.on_ams_temperature_high&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-orange-100 dark:bg-orange-600/20 text-orange-700 dark:text-orange-300 text-xs rounded`,children:n(`notifications.amsTemp`)}),e.on_ams_drying_suspended&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-100 dark:bg-rose-600/20 text-rose-700 dark:text-rose-300 text-xs rounded`,children:n(`notifications.amsDryingSuspended`)}),e.on_ams_ht_humidity_high&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-cyan-100 dark:bg-cyan-600/20 text-cyan-700 dark:text-cyan-300 text-xs rounded`,children:n(`notifications.amsHtHumidity`)}),e.on_ams_ht_temperature_high&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-100 dark:bg-amber-600/20 text-amber-700 dark:text-amber-300 text-xs rounded`,children:n(`notifications.amsHtTemp`)}),e.on_bed_cooled&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-xs rounded`,children:n(`notifications.bedCooled`)}),e.on_first_layer_complete&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-emerald-100 dark:bg-emerald-600/20 text-emerald-700 dark:text-emerald-300 text-xs rounded`,children:n(`notifications.firstLayer`)}),e.on_app_message&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-sky-100 dark:bg-sky-500/20 text-sky-700 dark:text-sky-400 text-xs rounded`,children:n(`notifications.appMessagesBadge`)}),e.on_print_missing_spool_assignment&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-300 text-xs rounded`,children:n(`notifications.missingSpoolAssignmentLabel`)}),e.on_stock_reorder_alert&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-lime-100 dark:bg-lime-500/20 text-lime-700 dark:text-lime-400 text-xs rounded`,children:n(`notifications.stockReorderAlert`)}),e.on_stock_break_alert&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-red-100 dark:bg-red-600/20 text-red-700 dark:text-red-300 text-xs rounded`,children:n(`notifications.stockBreakAlert`)}),e.quiet_hours_enabled&&(0,Y.jsxs)(`span`,{className:`px-2 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-400 text-xs rounded flex items-center gap-1`,children:[(0,Y.jsx)(Jt,{className:`w-3 h-3`}),n(`notifications.quiet`)]}),e.daily_digest_enabled&&(0,Y.jsxs)(`span`,{className:`px-2 py-0.5 bg-emerald-100 dark:bg-emerald-500/20 text-emerald-700 dark:text-emerald-400 text-xs rounded flex items-center gap-1`,children:[(0,Y.jsx)(w,{className:`w-3 h-3`}),n(`notifications.digest`,{time:e.daily_digest_time})]}),e.attach_photo===!1&&(0,Y.jsxs)(`span`,{className:`px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded flex items-center gap-1`,children:[(0,Y.jsx)(vn,{className:`w-3 h-3`}),n(`notifications.noPhoto`)]})]}),(0,Y.jsx)(`div`,{className:`mb-3`,children:(0,Y.jsxs)(K,{size:`sm`,variant:`secondary`,disabled:y.isPending,onClick:()=>{m(null),y.mutate()},className:`w-full`,children:[y.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Sn,{className:`w-4 h-4`}),n(`notifications.sendTestNotification`)]})}),p&&(0,Y.jsxs)(`div`,{className:`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${p.success?`bg-bambu-green/20 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`}`,children:[p.success?(0,Y.jsx)(j,{className:`w-4 h-4`}):(0,Y.jsx)(O,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{children:p.message})]})]}),(0,Y.jsxs)(`button`,{onClick:()=>c(!s),className:`w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors ${e.enabled?`border-t border-bambu-dark-tertiary`:`mt-2 border-t border-bambu-dark-tertiary`}`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(je,{className:`w-4 h-4`}),n(`notifications.eventSettings`)]}),s?(0,Y.jsx)(D,{className:`w-4 h-4`}):(0,Y.jsx)(E,{className:`w-4 h-4`})]}),s&&(0,Y.jsxs)(`div`,{className:`pt-3 border-t border-bambu-dark-tertiary space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.enabled`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.sendFromProvider`)})]}),(0,Y.jsx)(J,{checked:e.enabled,onChange:e=>_.mutate({enabled:e})})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printEvents`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printStarted`)}),(0,Y.jsx)(J,{checked:e.on_print_start,onChange:e=>_.mutate({on_print_start:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.plateNotEmpty`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.plateNotEmptyDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_plate_not_empty??!0,onChange:e=>_.mutate({on_plate_not_empty:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printCompleted`)}),(0,Y.jsx)(J,{checked:e.on_print_complete,onChange:e=>_.mutate({on_print_complete:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.plateClearRequired`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.plateClearRequiredDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_plate_clear_required??!1,onChange:e=>_.mutate({on_plate_clear_required:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printConfirmRequest`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.printConfirmRequestDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_print_confirm_request??!0,onChange:e=>_.mutate({on_print_confirm_request:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.bedCooledLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.bedCooledDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_bed_cooled??!1,onChange:e=>_.mutate({on_bed_cooled:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.firstLayerCompleteLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.firstLayerCompleteDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_first_layer_complete??!1,onChange:e=>_.mutate({on_first_layer_complete:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.missingSpoolAssignmentLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.missingSpoolAssignmentDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_print_missing_spool_assignment??!1,onChange:e=>_.mutate({on_print_missing_spool_assignment:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printFailed`)}),(0,Y.jsx)(J,{checked:e.on_print_failed,onChange:e=>_.mutate({on_print_failed:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printStopped`)}),(0,Y.jsx)(J,{checked:e.on_print_stopped,onChange:e=>_.mutate({on_print_stopped:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.billingChargeFailedLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.billingChargeFailedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_billing_charge_failed??!0,onChange:e=>_.mutate({on_billing_charge_failed:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.progressMilestones`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.progressMilestonesDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_print_progress,onChange:e=>_.mutate({on_print_progress:e})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printerStatus`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printerOffline`)}),(0,Y.jsx)(J,{checked:e.on_printer_offline,onChange:e=>_.mutate({on_printer_offline:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printerError`)}),(0,Y.jsx)(J,{checked:e.on_printer_error,onChange:e=>_.mutate({on_printer_error:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.aiFailureDetection`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.aiFailureDetectionDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ai_failure_detection??!1,onChange:e=>_.mutate({on_ai_failure_detection:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.haSensorAlert`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.haSensorAlertDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ha_sensor_alert??!1,onChange:e=>_.mutate({on_ha_sensor_alert:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.locationHaSensorAlert`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.locationHaSensorAlertDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_location_ha_sensor_alert??!1,onChange:e=>_.mutate({on_location_ha_sensor_alert:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.lowFilamentLabel`)}),(0,Y.jsx)(J,{checked:e.on_filament_low,onChange:e=>_.mutate({on_filament_low:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.maintenanceDue`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.maintenanceDueDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_maintenance_due??!1,onChange:e=>_.mutate({on_maintenance_due:e})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.amsAlarms`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHumidityHigh`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHumidityHighDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ams_humidity_high??!1,onChange:e=>_.mutate({on_ams_humidity_high:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsTemperatureHigh`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsTemperatureHighDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ams_temperature_high??!1,onChange:e=>_.mutate({on_ams_temperature_high:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsDryingSuspendedTitle`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsDryingSuspendedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ams_drying_suspended??!1,onChange:e=>_.mutate({on_ams_drying_suspended:e})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.amsHtAlarms`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHtHumidityHigh`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHtHumidityHighDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ams_ht_humidity_high??!1,onChange:e=>_.mutate({on_ams_ht_humidity_high:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHtTemperatureHigh`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHtTemperatureHighDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ams_ht_temperature_high??!1,onChange:e=>_.mutate({on_ams_ht_temperature_high:e})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.inventoryAlerts`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.stockReorderAlert`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.stockReorderAlertDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_stock_reorder_alert??!1,onChange:e=>_.mutate({on_stock_reorder_alert:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.stockBreakAlert`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.stockBreakAlertDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_stock_break_alert??!1,onChange:e=>_.mutate({on_stock_break_alert:e})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printQueue`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobAdded`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobAddedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_job_added??!1,onChange:e=>_.mutate({on_queue_job_added:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobAssigned`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobAssignedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_job_assigned??!1,onChange:e=>_.mutate({on_queue_job_assigned:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobStarted`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobStartedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_job_started??!1,onChange:e=>_.mutate({on_queue_job_started:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobWaiting`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobWaitingDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_job_waiting??!0,onChange:e=>_.mutate({on_queue_job_waiting:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobSkipped`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobSkippedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_job_skipped??!0,onChange:e=>_.mutate({on_queue_job_skipped:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobFailed`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobFailedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_job_failed??!0,onChange:e=>_.mutate({on_queue_job_failed:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.queueComplete`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.queueCompleteDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_completed??!1,onChange:e=>_.mutate({on_queue_completed:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.appMessages`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.appMessagesDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_app_message??!1,onChange:e=>_.mutate({on_app_message:e})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Jt,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.quietHours`)})]}),(0,Y.jsx)(J,{checked:e.quiet_hours_enabled,onChange:e=>_.mutate({quiet_hours_enabled:e})})]}),e.quiet_hours_enabled&&(0,Y.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.noNotificationsDuring`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(lt,{className:`w-4 h-4 text-bambu-gray`}),(0,Y.jsxs)(`span`,{className:`text-sm text-white`,children:[b(e.quiet_hours_start)||`22:00`,` - `,b(e.quiet_hours_end)||`07:00`]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.editProviderToChangeQuietHours`)})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(w,{className:`w-4 h-4 text-emerald-600 dark:text-emerald-400`}),(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.dailyDigest`)})]}),(0,Y.jsx)(J,{checked:e.daily_digest_enabled,onChange:e=>_.mutate({daily_digest_enabled:e})})]}),e.daily_digest_enabled&&(0,Y.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.batchNotifications`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(lt,{className:`w-4 h-4 text-bambu-gray`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.sendAt`,{time:b(e.daily_digest_time)||`08:00`})})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.editProviderToChangeDigestTime`)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ut,{className:`w-4 h-4 text-bambu-gray`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.attachPhotoLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.attachPhotoDescription`)})]})]}),(0,Y.jsx)(J,{checked:e.attach_photo??!0,onChange:e=>_.mutate({attach_photo:e})})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2 pt-2`,children:[(0,Y.jsxs)(K,{size:`sm`,variant:`secondary`,onClick:()=>t(e),className:`flex-1`,children:[(0,Y.jsx)(se,{className:`w-4 h-4`}),n(`notifications.edit`)]}),(0,Y.jsx)(K,{size:`sm`,variant:`secondary`,onClick:()=>o(!0),className:`text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300`,children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]})]})]})}),a&&(0,Y.jsx)(Tt,{title:n(`notifications.deleteProvider`),message:n(`notifications.deleteConfirm`,{name:e.name}),confirmText:n(`notifications.delete`),variant:`danger`,onConfirm:()=>{v.mutate(),o(!1)},onCancel:()=>o(!1)})]})}var Er=[`email`,`telegram`,`discord`,`ntfy`,`pushover`,`bark`,`gotify`,`callmebot`,`webhook`,`homeassistant`];function Dr({provider:e,onClose:t}){let{t:n,i18n:i}=l(),a=u(),o=!!e,[s,c]=(0,X.useState)(e?.name||``),[p,m]=(0,X.useState)(e?.provider_type||`email`),[h,g]=(0,X.useState)(e?.printer_id||null),[_,v]=(0,X.useState)(e?.attach_photo??!0),[y,b]=(0,X.useState)(e?.quiet_hours_enabled||!1),[x,S]=(0,X.useState)(e?.quiet_hours_start||`22:00`),[C,w]=(0,X.useState)(e?.quiet_hours_end||`07:00`),[T,E]=(0,X.useState)(e?.daily_digest_enabled||!1),[D,k]=(0,X.useState)(e?.daily_digest_time||`08:00`),[A,ee]=(0,X.useState)(e?.on_print_start??!1),[te,M]=(0,X.useState)(e?.on_print_complete??!0),[N,ne]=(0,X.useState)(e?.on_print_failed??!0),[re,ie]=(0,X.useState)(e?.on_print_stopped??!0),[ae,oe]=(0,X.useState)(e?.on_print_progress??!1),[P,F]=(0,X.useState)(e?.on_billing_charge_failed??!0),[I,R]=(0,X.useState)(e?.on_printer_offline??!1),[se,ce]=(0,X.useState)(e?.on_printer_error??!1),[z,B]=(0,X.useState)(e?.on_ai_failure_detection??!1),[le,V]=(0,X.useState)(e?.on_filament_low??!1),[ue,de]=(0,X.useState)(e?.on_maintenance_due??!1),[fe,pe]=(0,X.useState)(e?.on_stock_reorder_alert??!1),[me,he]=(0,X.useState)(e?.on_stock_break_alert??!1),[ge,_e]=(0,X.useState)(e?.on_plate_clear_required??!1),[ve,ye]=(0,X.useState)(e?.on_print_confirm_request??!0),[be,H]=(0,X.useState)(e?.telegram_verdict_mode??`buttons`),[xe,Se]=(0,X.useState)(e?.on_bed_cooled??!1),[Ce,we]=(0,X.useState)(e?.on_ha_sensor_alert??!1),[Te,Ee]=(0,X.useState)(e?.on_location_ha_sensor_alert??!1),[De,Oe]=(0,X.useState)(e?.on_first_layer_complete??!1),[ke,Ae]=(0,X.useState)(e?.on_app_message??!1),[je,Me]=(0,X.useState)(e?.config?Object.fromEntries(Object.entries(e.config).filter(([e])=>e!==`event_priorities`).map(([e,t])=>[e,String(t)])):{}),[Ne,Pe]=(0,X.useState)((()=>{let t=e?.config?.event_priorities;if(!t||typeof t!=`object`)return{};let n={};for(let[e,r]of Object.entries(t)){let t=Number(r);Number.isInteger(t)&&t>=1&&t<=5&&(n[e]=t)}return n})()),[Fe,Ie]=(0,X.useState)(null),[Le,U]=(0,X.useState)(null),{data:W}=d({queryKey:[`printers`],queryFn:r.getPrinters});(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let ze=f({mutationFn:()=>r.testNotificationConfig({provider_type:p,config:je,attach_photo:_}),onSuccess:e=>{Ie(e),U(null)},onError:e=>{Ie({success:!1,message:e.message})}}),G=f({mutationFn:e=>r.createNotificationProvider(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`notification-providers`]}),t()},onError:e=>{U(e.message)}}),Be=f({mutationFn:t=>r.updateNotificationProvider(e.id,t),onSuccess:()=>{a.invalidateQueries({queryKey:[`notification-providers`]}),t()},onError:e=>{U(e.message)}}),Ve=e=>{if(e.preventDefault(),U(null),!s.trim()){U(n(`notifications.nameRequired`));return}let t=We(p);for(let e of t)if(!je[e.key]?.trim()){U(n(`notifications.fieldRequired`,{field:e.label}));return}if(p===`homeassistant`&&je.data?.trim()){let e;try{e=JSON.parse(je.data)}catch{U(n(`notifications.haDataInvalid`));return}if(typeof e!=`object`||!e||Array.isArray(e)){U(n(`notifications.haDataInvalid`));return}}if(p===`telegram`&&je.message_thread_id?.trim()&&!/^\d+$/.test(je.message_thread_id.trim())){U(n(`notifications.telegramThreadIdInvalid`));return}let r=(p===`ntfy`||p===`gotify`)&&Object.keys(Ne).length>0?{...je,event_priorities:Ne}:je,i={name:s.trim(),provider_type:p,config:r,printer_id:h,attach_photo:_,quiet_hours_enabled:y,quiet_hours_start:y?x:null,quiet_hours_end:y?C:null,daily_digest_enabled:T,daily_digest_time:T?D:null,on_print_start:A,on_print_complete:te,on_print_failed:N,on_print_stopped:re,on_print_progress:ae,on_billing_charge_failed:P,on_printer_offline:I,on_printer_error:se,on_ai_failure_detection:z,on_filament_low:le,on_maintenance_due:ue,on_stock_reorder_alert:fe,on_stock_break_alert:me,on_plate_clear_required:ge,on_print_confirm_request:ve,telegram_verdict_mode:p===`telegram`?be:`buttons`,on_bed_cooled:xe,on_ha_sensor_alert:Ce,on_location_ha_sensor_alert:Te,on_first_layer_complete:De,on_app_message:ke};o?Be.mutate(i):G.mutate(i)},He=G.isPending||Be.isPending,Ue=e=>{switch(e){case`callmebot`:return[{key:`phone`,label:`Phone Number`,placeholder:`+1234567890`,type:`text`,required:!0},{key:`apikey`,label:`API Key`,placeholder:`Your CallMeBot API key`,type:`text`,required:!0}];case`ntfy`:return[{key:`server`,label:`Server URL`,placeholder:`https://ntfy.sh`,type:`text`,required:!1},{key:`topic`,label:`Topic`,placeholder:`my-bambuddy`,type:`text`,required:!0},{key:`auth_token`,label:`Auth Token`,placeholder:`Optional authentication`,type:`password`,required:!1}];case`pushover`:return[{key:`user_key`,label:`User Key`,placeholder:`Your Pushover user key`,type:`text`,required:!0},{key:`app_token`,label:`App Token`,placeholder:`Your Pushover app token`,type:`text`,required:!0},{key:`priority`,label:`Priority`,placeholder:`0 (normal)`,type:`number`,required:!1},{key:`retry`,label:n(`notifications.pushoverRetry`),placeholder:`60`,type:`number`,required:!1,showIf:e=>e.priority===`2`},{key:`expire`,label:n(`notifications.pushoverExpire`),placeholder:`3600`,type:`number`,required:!1,showIf:e=>e.priority===`2`}];case`telegram`:return[{key:`bot_token`,label:`Bot Token`,placeholder:`Bot token from @BotFather`,type:`password`,required:!0},{key:`chat_id`,label:`Chat ID`,placeholder:`Your chat or group ID`,type:`text`,required:!0},{key:`message_thread_id`,label:n(`notifications.telegramThreadId`),placeholder:`123`,type:`number`,required:!1,help:n(`notifications.telegramThreadIdHelp`)}];case`email`:return[{key:`smtp_server`,label:`SMTP Server`,placeholder:`smtp.gmail.com`,type:`text`,required:!0},{key:`smtp_port`,label:`SMTP Port`,placeholder:`587`,type:`number`,required:!1},{key:`security`,label:`Security`,type:`select`,required:!1,options:[{value:`starttls`,label:`STARTTLS (Port 587)`},{value:`ssl`,label:`SSL/TLS (Port 465)`},{value:`none`,label:`None (Port 25)`}]},{key:`auth_enabled`,label:`Authentication`,type:`select`,required:!1,options:[{value:`true`,label:`Enabled`},{value:`false`,label:`Disabled`}]},{key:`username`,label:`Username`,placeholder:`your@email.com`,type:`text`,required:!1},{key:`password`,label:`Password`,placeholder:`App password`,type:`password`,required:!1},{key:`from_email`,label:`From Email`,placeholder:`your@email.com`,type:`text`,required:!0},{key:`to_email`,label:`To Email`,placeholder:`recipient@email.com`,type:`text`,required:!0}];case`discord`:return[{key:`webhook_url`,label:`Webhook URL`,placeholder:`https://discord.com/api/webhooks/...`,type:`text`,required:!0}];case`webhook`:return[{key:`webhook_url`,label:`Webhook URL`,placeholder:`https://example.com/webhook`,type:`text`,required:!0},{key:`payload_format`,label:`Payload Format`,type:`select`,required:!1,options:[{value:`generic`,label:`Generic JSON`},{value:`slack`,label:`Slack / Mattermost`}]},{key:`auth_header`,label:`Authorization`,placeholder:`Bearer token (optional)`,type:`password`,required:!1},{key:`field_title`,label:`Title Field Name`,placeholder:`title`,type:`text`,required:!1,showIf:e=>e.payload_format!==`slack`},{key:`field_message`,label:`Message Field Name`,placeholder:`message`,type:`text`,required:!1,showIf:e=>e.payload_format!==`slack`}];case`homeassistant`:return[{key:`service`,label:`Home Assistant Service`,placeholder:`notify.mobile_app_myphone`,type:`text`,required:!1,help:n(`notifications.haServiceHelp`)},{key:`data`,label:`Data (JSON, optional)`,placeholder:`{"priority": "high", "ttl": 0, "channel": "3D Printing"}`,type:`textarea`,required:!1}];case`bark`:return[{key:`device_key`,label:`Device Key`,placeholder:`Your Bark device key`,type:`text`,required:!0},{key:`server`,label:`Server URL`,placeholder:`https://api.day.app`,type:`text`,required:!1},{key:`group`,label:`Group`,placeholder:`Bambuddy`,type:`text`,required:!1},{key:`sound`,label:`Sound`,placeholder:`minuet`,type:`text`,required:!1},{key:`level`,label:`Interruption Level`,type:`select`,required:!1,options:[{value:``,label:`Default`},{value:`active`,label:`Active`},{value:`timeSensitive`,label:`Time Sensitive`},{value:`critical`,label:`Critical (bypasses Silent/Focus)`},{value:`passive`,label:`Passive (no sound)`}]}];case`gotify`:return[{key:`server`,label:`Server URL`,placeholder:`https://gotify.example.com`,type:`text`,required:!0},{key:`app_token`,label:`App Token`,placeholder:`Token of a Gotify application`,type:`password`,required:!0}];default:return[]}},We=e=>Ue(e).filter(e=>e.required),Ge=Ue(p);return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto`,onClick:t,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg my-8 max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(o?`notifications.editTitle`:`notifications.addTitle`)}),(0,Y.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:Ve,className:`p-6 space-y-4`,children:[Le&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:Le}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.nameLabel`)}),(0,Y.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:n(`notifications.namePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.providerTypeLabel`)}),(0,Y.jsx)(`select`,{value:p,onChange:e=>{m(e.target.value),Me({}),Ie(null)},disabled:o,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`,children:Er.map(e=>({value:e,label:n(`notifications.providerTypes.${e}`,e)})).sort((e,t)=>e.label.localeCompare(t.label,i.language,{sensitivity:`base`})).map(({value:e,label:t})=>(0,Y.jsx)(`option`,{value:e,children:t},e))}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.providerDescriptions.${p}`,``)})]}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.configuration`)}),Ge.filter(e=>!(`showIf`in e)||e.showIf?.(je)!==!1).map(e=>(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[e.label,` `,e.required&&`*`]}),e.type===`select`&&`options`in e&&e.options?(0,Y.jsx)(`select`,{value:je[e.key]||e.options[0]?.value||``,onChange:t=>{Me({...je,[e.key]:t.target.value}),Ie(null)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:e.options.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))}):e.type===`textarea`?(0,Y.jsx)(`textarea`,{value:je[e.key]||``,onChange:t=>{Me({...je,[e.key]:t.target.value}),Ie(null)},placeholder:e.placeholder,rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono text-sm`}):(0,Y.jsx)(`input`,{type:e.type,value:je[e.key]||``,onChange:t=>{Me({...je,[e.key]:t.target.value}),Ie(null)},placeholder:e.placeholder,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),`help`in e&&e.help&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e.help})]},e.key)),p===`telegram`&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`telegram-verdict-mode`,className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.telegramVerdictMode`)}),(0,Y.jsxs)(`select`,{id:`telegram-verdict-mode`,value:be,onChange:e=>H(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`buttons`,children:n(`notifications.telegramVerdictModeButtons`)}),(0,Y.jsx)(`option`,{value:`reactions`,children:n(`notifications.telegramVerdictModeReactions`)}),(0,Y.jsx)(`option`,{value:`both`,children:n(`notifications.telegramVerdictModeBoth`)})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.telegramVerdictModeHelp`)})]})]}),(0,Y.jsx)(`div`,{className:`flex gap-2`,children:(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,onClick:()=>{Ie(null),ze.mutate()},disabled:ze.isPending||We(p).length>0&&!je[We(p)[0]?.key],className:`flex-1`,children:[ze.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Sn,{className:`w-4 h-4`}),n(`notifications.testConfiguration`)]})}),Fe&&(0,Y.jsx)(`div`,{className:`p-3 rounded-lg flex items-center gap-2 ${Fe.success?`bg-bambu-green/20 border border-bambu-green/50 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 text-red-700 dark:text-red-400`}`,children:Fe.success?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(j,{className:`w-5 h-5`}),(0,Y.jsx)(`span`,{children:Fe.message})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(O,{className:`w-5 h-5`}),(0,Y.jsx)(`span`,{children:Fe.message})]})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.printerFilter`)}),(0,Y.jsxs)(`select`,{value:h??``,onChange:e=>g(e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`notifications.allPrinters`)}),W?.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.onlyFromPrinter`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-sm text-white`,children:n(`notifications.attachPhotoLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.attachPhotoDescription`)})]}),(0,Y.jsx)(J,{checked:_,onChange:v})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`label`,{className:`text-sm text-white`,children:n(`notifications.quietHoursDnd`)}),(0,Y.jsx)(J,{checked:y,onChange:b})]}),y&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.quietStart`)}),(0,Y.jsx)(`input`,{type:`time`,value:x,onChange:e=>S(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.quietEnd`)}),(0,Y.jsx)(`input`,{type:`time`,value:C,onChange:e=>w(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-sm text-white`,children:n(`notifications.dailyDigestLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.batchNotifications`)})]}),(0,Y.jsx)(J,{checked:T,onChange:E})]}),T&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.sendDigestAt`)}),(0,Y.jsx)(`input`,{type:`time`,value:D,onChange:e=>k(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.digestCollected`)})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.notificationEvents`)}),(0,Y.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.printEvents`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.start`)}),(0,Y.jsx)(J,{checked:A,onChange:ee})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.complete`)}),(0,Y.jsx)(J,{checked:te,onChange:M})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.failed`)}),(0,Y.jsx)(J,{checked:N,onChange:ne})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stopped`)}),(0,Y.jsx)(J,{checked:re,onChange:ie})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.progress`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.progressPercent`)})]}),(0,Y.jsx)(J,{checked:ae,onChange:oe})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.billingChargeFailedLabel`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.billingChargeFailedDescription`)})]}),(0,Y.jsx)(J,{checked:P,onChange:F})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.plateClearRequired`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.plateClearRequiredDescription`)})]}),(0,Y.jsx)(J,{checked:ge,onChange:_e})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.printConfirmRequest`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.printConfirmRequestDescription`)})]}),(0,Y.jsx)(J,{checked:ve,onChange:ye})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.bedCooled`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.bedCooledAfterPrint`)})]}),(0,Y.jsx)(J,{checked:xe,onChange:Se})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.firstLayerCompleteLabel`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.firstLayerCompleteDescription`)})]}),(0,Y.jsx)(J,{checked:De,onChange:Oe})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.printerStatus`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.offline`)}),(0,Y.jsx)(J,{checked:I,onChange:R})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.haSensorAlert`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.haSensorAlertDescription`)})]}),(0,Y.jsx)(J,{checked:Ce,onChange:we})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.locationHaSensorAlert`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.locationHaSensorAlertDescription`)})]}),(0,Y.jsx)(J,{checked:Te,onChange:Ee})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.error`)}),(0,Y.jsx)(J,{checked:se,onChange:ce})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.aiFailureDetection`)}),(0,Y.jsx)(J,{checked:z,onChange:B})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.lowFilament`)}),(0,Y.jsx)(J,{checked:le,onChange:V})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.maintenance`)}),(0,Y.jsx)(J,{checked:ue,onChange:de})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.inventoryAlerts`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stockReorderAlert`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.stockReorderAlertDescription`)})]}),(0,Y.jsx)(J,{checked:fe,onChange:pe})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stockBreakAlert`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.stockBreakAlertDescription`)})]}),(0,Y.jsx)(J,{checked:me,onChange:he})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.connectedApps`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.appMessages`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.appMessagesDescription`)})]}),(0,Y.jsx)(J,{checked:ke,onChange:Ae})]})]}),(p===`ntfy`||p===`gotify`)&&(()=>{let e=[];return A&&e.push({key:`on_print_start`,label:n(`notifications.start`)}),te&&e.push({key:`on_print_complete`,label:n(`notifications.complete`)}),N&&e.push({key:`on_print_failed`,label:n(`notifications.failed`)}),re&&e.push({key:`on_print_stopped`,label:n(`notifications.stopped`)}),ae&&e.push({key:`on_print_progress`,label:n(`notifications.progress`)}),P&&e.push({key:`on_billing_charge_failed`,label:n(`notifications.billingChargeFailedLabel`)}),ge&&e.push({key:`on_plate_clear_required`,label:n(`notifications.plateClearRequired`)}),ve&&e.push({key:`on_print_confirm_request`,label:n(`notifications.printConfirmRequest`)}),xe&&e.push({key:`on_bed_cooled`,label:n(`notifications.bedCooled`)}),De&&e.push({key:`on_first_layer_complete`,label:n(`notifications.firstLayerCompleteLabel`)}),I&&e.push({key:`on_printer_offline`,label:n(`notifications.offline`)}),se&&e.push({key:`on_printer_error`,label:n(`notifications.error`)}),Ce&&e.push({key:`on_ha_sensor_alert`,label:n(`notifications.haSensorAlert`)}),Te&&e.push({key:`on_location_ha_sensor_alert`,label:n(`notifications.locationHaSensorAlert`)}),z&&e.push({key:`on_ai_failure_detection`,label:n(`notifications.aiFailureDetection`)}),le&&e.push({key:`on_filament_low`,label:n(`notifications.lowFilament`)}),ue&&e.push({key:`on_maintenance_due`,label:n(`notifications.maintenance`)}),fe&&e.push({key:`on_stock_reorder_alert`,label:n(`notifications.stockReorderAlert`)}),me&&e.push({key:`on_stock_break_alert`,label:n(`notifications.stockBreakAlert`)}),e.length===0?null:(0,Y.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-1`,children:n(p===`gotify`?`notifications.eventPriority.sectionTitleGotify`:`notifications.eventPriority.sectionTitle`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(p===`gotify`?`notifications.eventPriority.helpGotify`:`notifications.eventPriority.helpNtfy`)}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:e.label}),(0,Y.jsxs)(`select`,{value:Ne[e.key]??3,onChange:t=>{let n=Number(t.target.value);Pe(t=>({...t,[e.key]:n}))},className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:1,children:n(`notifications.eventPriority.min`)}),(0,Y.jsx)(`option`,{value:2,children:n(`notifications.eventPriority.low`)}),(0,Y.jsx)(`option`,{value:3,children:n(`notifications.eventPriority.default`)}),(0,Y.jsx)(`option`,{value:4,children:n(`notifications.eventPriority.high`)}),(0,Y.jsx)(`option`,{value:5,children:n(`notifications.eventPriority.urgent`)})]})]},e.key))})]})})()]}),(0,Y.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`notifications.cancel`)}),(0,Y.jsxs)(K,{type:`submit`,disabled:He,className:`flex-1`,children:[He?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(_t,{className:`w-4 h-4`}),n(o?`notifications.save`:`notifications.add`)]})]})]})]})})}function Or({template:e,onClose:t}){let{t:n}=l(),i=u(),a=(0,X.useRef)(null),[o,s]=(0,X.useState)(e.title_template),[c,p]=(0,X.useState)(e.body_template),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(!0),{data:v}=d({queryKey:[`template-variables`],queryFn:r.getTemplateVariables}),y=v?.find(t=>t.event_type===e.event_type),{data:b,isLoading:x}=d({queryKey:[`template-preview`,e.event_type,o,c],queryFn:()=>r.previewTemplate({event_type:e.event_type,title_template:o,body_template:c}),enabled:g&&o.length>0&&c.length>0});(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let S=f({mutationFn:t=>r.updateNotificationTemplate(e.id,t),onSuccess:()=>{i.invalidateQueries({queryKey:[`notification-templates`]}),t()},onError:e=>{h(e.message)}}),C=f({mutationFn:()=>r.resetNotificationTemplate(e.id),onSuccess:e=>{s(e.title_template),p(e.body_template),i.invalidateQueries({queryKey:[`notification-templates`]})},onError:e=>{h(e.message)}}),w=e=>{if(e.preventDefault(),h(null),!o.trim()){h(n(`notifications.titleRequired`));return}if(!c.trim()){h(n(`notifications.bodyRequired`));return}S.mutate({title_template:o,body_template:c})},T=e=>{let t=a.current;if(!t)return;let n=t.selectionStart,r=t.selectionEnd,i=c,o=i.substring(0,n),s=i.substring(r);p(o+`{${e}}`+s),setTimeout(()=>{t.focus();let r=n+e.length+2;t.setSelectionRange(r,r)},0)},E=o!==e.title_template||c!==e.body_template;return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`notifications.editTemplate`,{name:e.name})}),(0,Y.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,children:(0,Y.jsx)(Re,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,Y.jsxs)(`form`,{onSubmit:w,className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[m&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded text-red-700 dark:text-red-400 text-sm`,children:m}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:n(`notifications.titleLabel`)}),(0,Y.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green`,placeholder:n(`notifications.titlePlaceholder`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:n(`notifications.bodyLabel`)}),(0,Y.jsx)(`textarea`,{ref:a,value:c,onChange:e=>p(e.target.value),rows:4,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green font-mono text-sm resize-none`,placeholder:n(`notifications.bodyPlaceholder`)})]}),y&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-2`,children:n(`notifications.availableVariables`)}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:y.variables.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>T(e),className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,Y.jsx)(wt,{className:`w-3 h-3`}),e]},e))}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray/60 mt-1`,children:n(`notifications.clickToInsert`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsxs)(`label`,{className:`text-sm font-medium text-bambu-gray flex items-center gap-2`,children:[(0,Y.jsx)(mt,{className:`w-4 h-4`}),n(`notifications.livePreview`)]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>_(!g),className:`text-xs text-bambu-green hover:text-bambu-green-light`,children:n(g?`notifications.hide`:`notifications.show`)})]}),g&&(0,Y.jsx)(`div`,{className:`bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2`,children:x?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm`,children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}),n(`notifications.loadingPreview`)]}):b?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.titlePreview`)}),(0,Y.jsx)(`div`,{className:`text-white font-medium`,children:b.title})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.bodyPreview`)}),(0,Y.jsx)(`div`,{className:`text-white whitespace-pre-wrap text-sm`,children:b.body})]}),y?.supports_photo&&(0,Y.jsxs)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary/60 flex items-center gap-3`,children:[(0,Y.jsx)(`img`,{src:`/img/screenshot-desktop.png`,alt:n(`notifications.photoPreview`),className:`w-24 h-14 object-cover rounded border border-bambu-dark-tertiary shrink-0`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.event_type.startsWith(`user_`)?n(`notifications.photoPreviewNoteEmailOnly`):y.variables.includes(`finish_photo_url`)?n(`notifications.photoPreviewNoteWithEmail`):n(`notifications.photoPreviewNote`)})]})]}):(0,Y.jsx)(`div`,{className:`text-bambu-gray text-sm`,children:n(`notifications.enterTemplateContent`)})})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0`,children:[(0,Y.jsxs)(K,{type:`button`,variant:`ghost`,onClick:()=>C.mutate(),disabled:C.isPending,className:`text-orange-600 dark:text-orange-400 hover:text-orange-700 dark:hover:text-orange-300`,children:[C.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin mr-2`}):(0,Y.jsx)(nt,{className:`w-4 h-4 mr-2`}),n(`notifications.resetToDefault`)]}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:t,children:n(`notifications.cancel`)}),(0,Y.jsxs)(K,{onClick:w,disabled:S.isPending||!E,children:[S.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin mr-2`}):(0,Y.jsx)(_t,{className:`w-4 h-4 mr-2`}),n(`notifications.save`)]})]})]})]})})}var kr={print_start:`text-blue-700 dark:text-blue-400`,print_complete:`text-bambu-green`,print_failed:`text-red-700 dark:text-red-400`,print_stopped:`text-orange-700 dark:text-orange-400`,print_progress:`text-yellow-700 dark:text-yellow-400`,printer_offline:`text-gray-400`,printer_error:`text-rose-700 dark:text-rose-400`,filament_low:`text-cyan-700 dark:text-cyan-400`,maintenance_due:`text-purple-700 dark:text-purple-400`,test:`text-bambu-gray`};function Ar({onClose:e}){let{t}=l(),n=u(),{showToast:i}=ee(),[a,o]=(0,X.useState)(7),[s,c]=(0,X.useState)(null),[p,m]=(0,X.useState)(!1),{data:h}=d({queryKey:[`settings`],queryFn:r.getSettings}),g=h?.time_format||`system`,{data:_,isLoading:v,refetch:y,isRefetching:b}=d({queryKey:[`notification-logs`,a,p],queryFn:()=>r.getNotificationLogs({days:a,limit:100,success:p?!1:void 0})}),{data:x}=d({queryKey:[`notification-log-stats`,a],queryFn:()=>r.getNotificationLogStats(a)}),S=f({mutationFn:()=>r.clearNotificationLogs(30),onSuccess:e=>{i(e.message,`success`),n.invalidateQueries({queryKey:[`notification-logs`]}),n.invalidateQueries({queryKey:[`notification-log-stats`]})},onError:e=>{i(`Failed to clear logs: ${e.message}`,`error`)}}),C=e=>{let n=We(e);if(!n)return``;let r=new Date().getTime()-n.getTime();return r<6e4?t(`notifications.justNow`):r<36e5?`${Math.floor(r/6e4)}m ago`:r<864e5?`${Math.floor(r/36e5)}h ago`:n.toLocaleDateString()+` `+Ve(n,g)};return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg w-full max-w-3xl max-h-[85vh] flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(P,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t(`notifications.notificationLog`)})]}),(0,Y.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:`×`})]}),x&&(0,Y.jsx)(`div`,{className:`px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-6 text-sm`,children:[(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[t(`notifications.statsSummary`,{days:a}),` `,(0,Y.jsx)(`span`,{className:`text-white font-medium`,children:x.total}),` `,t(`notifications.statsNotifications`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-green`,children:[(0,Y.jsx)(j,{className:`w-4 h-4`}),t(`notifications.statsSent`,{count:x.success_count})]}),x.failure_count>0&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,Y.jsx)(O,{className:`w-4 h-4`}),t(`notifications.statsFailed`,{count:x.failure_count})]})]})}),(0,Y.jsxs)(`div`,{className:`px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4`,children:[(0,Y.jsxs)(`select`,{value:a,onChange:e=>o(Number(e.target.value)),className:`px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green`,children:[(0,Y.jsx)(`option`,{value:1,children:t(`notifications.last24Hours`)}),(0,Y.jsx)(`option`,{value:7,children:t(`notifications.last7Days`)}),(0,Y.jsx)(`option`,{value:30,children:t(`notifications.last30Days`)}),(0,Y.jsx)(`option`,{value:90,children:t(`notifications.last90Days`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:p,onChange:e=>m(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),t(`notifications.showFailedOnly`)]}),(0,Y.jsx)(`div`,{className:`flex-1`}),(0,Y.jsxs)(K,{size:`sm`,variant:`secondary`,onClick:()=>y(),disabled:b,children:[b?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(at,{className:`w-4 h-4`}),t(`notifications.refresh`)]}),(0,Y.jsxs)(K,{size:`sm`,variant:`secondary`,onClick:()=>S.mutate(),disabled:S.isPending,className:`text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300`,children:[S.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(qe,{className:`w-4 h-4`}),t(`notifications.clearOld`)]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:v?(0,Y.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,Y.jsx)(L,{className:`w-6 h-6 text-bambu-green animate-spin`})}):_&&_.length>0?(0,Y.jsx)(`div`,{className:`space-y-2`,children:_.map(e=>(0,Y.jsx)(jr,{log:e,isExpanded:s===e.id,onToggle:()=>c(s===e.id?null:e.id),formatDate:C,formatFullDate:e=>Be(e,g)},e.id))}):(0,Y.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,Y.jsx)(P,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:t(p?`notifications.noFailedNotifications`:`notifications.noNotificationsLogged`)})]})})]})})}function jr({log:e,isExpanded:t,onToggle:n,formatDate:r,formatFullDate:i}){let{t:a}=l();return(0,Y.jsxs)(`div`,{className:`border rounded-lg overflow-hidden transition-colors ${e.success?`border-bambu-dark-tertiary bg-bambu-dark/30`:`border-red-500/30 bg-red-500/5`}`,children:[(0,Y.jsxs)(`button`,{className:`w-full px-3 py-2 flex items-center gap-3 text-left hover:bg-bambu-dark/50 transition-colors`,onClick:n,children:[e.success?(0,Y.jsx)(j,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,Y.jsx)(O,{className:`w-4 h-4 text-red-600 dark:text-red-400 shrink-0`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium ${kr[e.event_type]||`text-bambu-gray`}`,children:a(`notifications.eventTypes.${e.event_type}`,e.event_type)}),(0,Y.jsx)(`span`,{className:`text-sm text-white truncate flex-1`,children:e.provider_name||a(`notifications.unknownProvider`)}),e.printer_name&&(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.printer_name}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:r(e.created_at)}),t?(0,Y.jsx)(D,{className:`w-4 h-4 text-bambu-gray shrink-0`}):(0,Y.jsx)(E,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),t&&(0,Y.jsxs)(`div`,{className:`px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:a(`notifications.logTitle`)}),(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:e.title})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:a(`notifications.logMessage`)}),(0,Y.jsx)(`p`,{className:`text-sm text-white whitespace-pre-wrap`,children:e.message})]}),!e.success&&e.error_message&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mb-1`,children:a(`notifications.logError`)}),(0,Y.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300`,children:e.error_message})]}),(0,Y.jsxs)(`div`,{className:`flex gap-4 text-xs text-bambu-gray pt-1`,children:[(0,Y.jsx)(`span`,{children:a(`notifications.logProvider`,{type:e.provider_type})}),(0,Y.jsx)(`span`,{children:a(`notifications.logTime`,{time:i(e.created_at)})})]})]})]})}var Mr=Object.defineProperty,Nr=Object.getOwnPropertySymbols,Pr=Object.prototype.hasOwnProperty,Fr=Object.prototype.propertyIsEnumerable,Ir=(e,t,n)=>t in e?Mr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Lr=(e,t)=>{for(var n in t||={})Pr.call(t,n)&&Ir(e,n,t[n]);if(Nr)for(var n of Nr(t))Fr.call(t,n)&&Ir(e,n,t[n]);return e},Rr=(e,t)=>{var n={};for(var r in e)Pr.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Nr)for(var r of Nr(e))t.indexOf(r)<0&&Fr.call(e,r)&&(n[r]=e[r]);return n},zr;(e=>{let t=class t{constructor(e,n,r,a){if(this.version=e,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],e<t.MIN_VERSION||e>t.MAX_VERSION)throw RangeError(`Version value out of range`);if(a<-1||a>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let o=[];for(let e=0;e<this.size;e++)o.push(!1);for(let e=0;e<this.size;e++)this.modules.push(o.slice()),this.isFunction.push(o.slice());this.drawFunctionPatterns();let s=this.addEccAndInterleave(r);if(this.drawCodewords(s),a==-1){let e=1e9;for(let t=0;t<8;t++){this.applyMask(t),this.drawFormatBits(t);let n=this.getPenaltyScore();n<e&&(a=t,e=n),this.applyMask(t)}}i(0<=a&&a<=7),this.mask=a,this.applyMask(a),this.drawFormatBits(a),this.isFunction=[]}static encodeText(n,r){let i=e.QrSegment.makeSegments(n);return t.encodeSegments(i,r)}static encodeBinary(n,r){let i=e.QrSegment.makeBytes(n);return t.encodeSegments([i],r)}static encodeSegments(e,r,a=1,s=40,c=-1,l=!0){if(!(t.MIN_VERSION<=a&&a<=s&&s<=t.MAX_VERSION)||c<-1||c>7)throw RangeError(`Invalid value`);let u,d;for(u=a;;u++){let n=t.getNumDataCodewords(u,r)*8,i=o.getTotalBits(e,u);if(i<=n){d=i;break}if(u>=s)throw RangeError(`Data too long`)}for(let e of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])l&&d<=t.getNumDataCodewords(u,e)*8&&(r=e);let f=[];for(let t of e){n(t.mode.modeBits,4,f),n(t.numChars,t.mode.numCharCountBits(u),f);for(let e of t.getData())f.push(e)}i(f.length==d);let p=t.getNumDataCodewords(u,r)*8;i(f.length<=p),n(0,Math.min(4,p-f.length),f),n(0,(8-f.length%8)%8,f),i(f.length%8==0);for(let e=236;f.length<p;e^=253)n(e,8,f);let m=[];for(;m.length*8<f.length;)m.push(0);return f.forEach((e,t)=>m[t>>>3]|=e<<7-(t&7)),new t(u,r,m,c)}getModule(e,t){return 0<=e&&e<this.size&&0<=t&&t<this.size&&this.modules[t][e]}getModules(){return this.modules}drawFunctionPatterns(){for(let e=0;e<this.size;e++)this.setFunctionModule(6,e,e%2==0),this.setFunctionModule(e,6,e%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);let e=this.getAlignmentPatternPositions(),t=e.length;for(let n=0;n<t;n++)for(let r=0;r<t;r++)n==0&&r==0||n==0&&r==t-1||n==t-1&&r==0||this.drawAlignmentPattern(e[n],e[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){let t=this.errorCorrectionLevel.formatBits<<3|e,n=t;for(let e=0;e<10;e++)n=n<<1^(n>>>9)*1335;let a=(t<<10|n)^21522;i(a>>>15==0);for(let e=0;e<=5;e++)this.setFunctionModule(8,e,r(a,e));this.setFunctionModule(8,7,r(a,6)),this.setFunctionModule(8,8,r(a,7)),this.setFunctionModule(7,8,r(a,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,r(a,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,r(a,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,r(a,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;i(t>>>18==0);for(let e=0;e<18;e++){let n=r(t,e),i=this.size-11+e%3,a=Math.floor(e/3);this.setFunctionModule(i,a,n),this.setFunctionModule(a,i,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;0<=a&&a<this.size&&0<=o&&o<this.size&&this.setFunctionModule(a,o,i!=2&&i!=4)}}drawAlignmentPattern(e,t){for(let n=-2;n<=2;n++)for(let r=-2;r<=2;r++)this.setFunctionModule(e+r,t+n,Math.max(Math.abs(r),Math.abs(n))!=1)}setFunctionModule(e,t,n){this.modules[t][e]=n,this.isFunction[t][e]=!0}addEccAndInterleave(e){let n=this.version,r=this.errorCorrectionLevel;if(e.length!=t.getNumDataCodewords(n,r))throw RangeError(`Invalid argument`);let a=t.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][n],o=t.ECC_CODEWORDS_PER_BLOCK[r.ordinal][n],s=Math.floor(t.getNumRawDataModules(n)/8),c=a-s%a,l=Math.floor(s/a),u=[],d=t.reedSolomonComputeDivisor(o);for(let n=0,r=0;n<a;n++){let i=e.slice(r,r+l-o+(n<c?0:1));r+=i.length;let a=t.reedSolomonComputeRemainder(i,d);n<c&&i.push(0),u.push(i.concat(a))}let f=[];for(let e=0;e<u[0].length;e++)u.forEach((t,n)=>{(e!=l-o||n>=c)&&f.push(t[e])});return i(f.length==s),f}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw RangeError(`Invalid argument`);let n=0;for(let t=this.size-1;t>=1;t-=2){t==6&&(t=5);for(let i=0;i<this.size;i++)for(let a=0;a<2;a++){let o=t-a,s=t+1&2?i:this.size-1-i;!this.isFunction[s][o]&&n<e.length*8&&(this.modules[s][o]=r(e[n>>>3],7-(n&7)),n++)}}i(n==e.length*8)}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t<this.size;t++)for(let n=0;n<this.size;n++){let r;switch(e){case 0:r=(n+t)%2==0;break;case 1:r=t%2==0;break;case 2:r=n%3==0;break;case 3:r=(n+t)%3==0;break;case 4:r=(Math.floor(n/3)+Math.floor(t/2))%2==0;break;case 5:r=n*t%2+n*t%3==0;break;case 6:r=(n*t%2+n*t%3)%2==0;break;case 7:r=((n+t)%2+n*t%3)%2==0;break;default:throw Error(`Unreachable`)}!this.isFunction[t][n]&&r&&(this.modules[t][n]=!this.modules[t][n])}}getPenaltyScore(){let e=0;for(let n=0;n<this.size;n++){let r=!1,i=0,a=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[n][o]==r?(i++,i==5?e+=t.PENALTY_N1:i>5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[n][o],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n<this.size;n++){let r=!1,i=0,a=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[o][n]==r?(i++,i==5?e+=t.PENALTY_N1:i>5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[o][n],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n<this.size-1;n++)for(let r=0;r<this.size-1;r++){let i=this.modules[n][r];i==this.modules[n][r+1]&&i==this.modules[n+1][r]&&i==this.modules[n+1][r+1]&&(e+=t.PENALTY_N2)}let n=0;for(let e of this.modules)n=e.reduce((e,t)=>e+ +!!t,n);let r=this.size*this.size,a=Math.ceil(Math.abs(n*20-r*10)/r)-1;return i(0<=a&&a<=9),e+=a*t.PENALTY_N4,i(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(this.version==1)return[];{let e=Math.floor(this.version/7)+2,t=this.version==32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.length<e;r-=t)n.splice(1,0,r);return n}}static getNumRawDataModules(e){if(e<t.MIN_VERSION||e>t.MAX_VERSION)throw RangeError(`Version number out of range`);let n=(16*e+128)*e+64;if(e>=2){let t=Math.floor(e/7)+2;n-=(25*t-10)*t-55,e>=7&&(n-=36)}return i(208<=n&&n<=29648),n}static getNumDataCodewords(e,n){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let n=[];for(let t=0;t<e-1;t++)n.push(0);n.push(1);let r=1;for(let i=0;i<e;i++){for(let e=0;e<n.length;e++)n[e]=t.reedSolomonMultiply(n[e],r),e+1<n.length&&(n[e]^=n[e+1]);r=t.reedSolomonMultiply(r,2)}return n}static reedSolomonComputeRemainder(e,n){let r=n.map(e=>0);for(let i of e){let e=i^r.shift();r.push(0),n.forEach((n,i)=>r[i]^=t.reedSolomonMultiply(n,e))}return r}static reedSolomonMultiply(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return i(n>>>8==0),n}finderPenaltyCountPatterns(e){let t=e[1];i(t<=this.size*3);let n=t>0&&e[2]==t&&e[3]==t*3&&e[4]==t&&e[5]==t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]==0&&(e+=this.size),t.pop(),t.unshift(e)}};t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function r(e,t){return(e>>>t&1)!=0}function i(e){if(!e)throw Error(`Assertion error`)}let a=class e{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}static makeBytes(t){let r=[];for(let e of t)n(e,8,r);return new e(e.Mode.BYTE,t.length,r)}static makeNumeric(t){if(!e.isNumeric(t))throw RangeError(`String contains non-numeric characters`);let r=[];for(let e=0;e<t.length;){let i=Math.min(t.length-e,3);n(parseInt(t.substring(e,e+i),10),i*3+1,r),e+=i}return new e(e.Mode.NUMERIC,t.length,r)}static makeAlphanumeric(t){if(!e.isAlphanumeric(t))throw RangeError(`String contains unencodable characters in alphanumeric mode`);let r=[],i;for(i=0;i+2<=t.length;i+=2){let a=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i))*45;a+=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i+1)),n(a,11,r)}return i<t.length&&n(e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i)),6,r),new e(e.Mode.ALPHANUMERIC,t.length,r)}static makeSegments(t){return t==``?[]:e.isNumeric(t)?[e.makeNumeric(t)]:e.isAlphanumeric(t)?[e.makeAlphanumeric(t)]:[e.makeBytes(e.toUtf8ByteArray(t))]}static makeEci(t){let r=[];if(t<0)throw RangeError(`ECI assignment value out of range`);if(t<128)n(t,8,r);else if(t<16384)n(2,2,r),n(t,14,r);else if(t<1e6)n(6,3,r),n(t,21,r);else throw RangeError(`ECI assignment value out of range`);return new e(e.Mode.ECI,0,r)}static isNumeric(t){return e.NUMERIC_REGEX.test(t)}static isAlphanumeric(t){return e.ALPHANUMERIC_REGEX.test(t)}getData(){return this.bitData.slice()}static getTotalBits(e,t){let n=0;for(let r of e){let e=r.mode.numCharCountBits(t);if(r.numChars>=1<<e)return 1/0;n+=4+e+r.bitData.length}return n}static toUtf8ByteArray(e){e=encodeURI(e);let t=[];for(let n=0;n<e.length;n++)e.charAt(n)==`%`?(t.push(parseInt(e.substring(n+1,n+3),16)),n+=2):t.push(e.charCodeAt(n));return t}};a.NUMERIC_REGEX=/^[0-9]*$/,a.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,a.ALPHANUMERIC_CHARSET=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`;let o=a;e.QrSegment=a})(zr||={}),(e=>{(e=>{let t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})(e.QrCode||={})})(zr||={}),(e=>{(e=>{let t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||={})})(zr||={});var Br=zr,Vr={L:Br.QrCode.Ecc.LOW,M:Br.QrCode.Ecc.MEDIUM,Q:Br.QrCode.Ecc.QUARTILE,H:Br.QrCode.Ecc.HIGH},Z=128,Hr=`L`,Ur=`#FFFFFF`,Wr=`#000000`,Gr=!1,Kr=1,qr=4,Jr=0,Yr=.1;function Xr(e,t=0){let n=[];return e.forEach(function(e,r){let i=null;e.forEach(function(a,o){if(!a&&i!==null){n.push(`M${i+t} ${r+t}h${o-i}v1H${i+t}z`),i=null;return}if(o===e.length-1){if(!a)return;i===null?n.push(`M${o+t},${r+t} h1v1H${o+t}z`):n.push(`M${i+t},${r+t} h${o+1-i}v1H${i+t}z`);return}a&&i===null&&(i=o)})}),n.join(``)}function Zr(e,t){return e.slice().map((e,n)=>n<t.y||n>=t.y+t.h?e:e.map((e,n)=>n<t.x||n>=t.x+t.w?e:!1))}function Qr(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*Yr),o=i/t,s=(r.width||a)*o,c=(r.height||a)*o,l=r.x==null?e.length/2-s/2:r.x*o,u=r.y==null?e.length/2-c/2:r.y*o,d=r.opacity==null?1:r.opacity,f=null;if(r.excavate){let e=Math.floor(l),t=Math.floor(u);f={x:e,y:t,w:Math.ceil(s+l-e),h:Math.ceil(c+u-t)}}let p=r.crossOrigin;return{x:l,y:u,h:c,w:s,excavation:f,opacity:d,crossOrigin:p}}function $r(e,t){return t==null?e?qr:Jr:Math.max(Math.floor(t),0)}function ei({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:a,size:o,boostLevel:s}){let c=X.useMemo(()=>{let r=(Array.isArray(e)?e:[e]).reduce((e,t)=>(e.push(...Br.QrSegment.makeSegments(t)),e),[]);return Br.QrCode.encodeSegments(r,Vr[t],n,void 0,void 0,s)},[e,t,n,s]),{cells:l,margin:u,numCells:d,calculatedImageSettings:f}=X.useMemo(()=>{let e=c.getModules(),t=$r(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:Qr(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var ti=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),ni=X.forwardRef(function(e,t){let n=e,{value:r,size:i=Z,level:a=Hr,bgColor:o=Ur,fgColor:s=Wr,includeMargin:c=Gr,minVersion:l=Kr,boostLevel:u,marginSize:d,imageSettings:f}=n,p=Rr(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=Rr(p,[`style`]),g=f?.src,_=X.useRef(null),v=X.useRef(null),y=X.useCallback(e=>{_.current=e,typeof t==`function`?t(e):t&&(t.current=e)},[t]),[b,x]=X.useState(!1),{margin:S,cells:C,numCells:w,calculatedImageSettings:T}=ei({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:d,imageSettings:f,size:i});X.useEffect(()=>{if(_.current!=null){let e=_.current,t=e.getContext(`2d`);if(!t)return;let n=C,r=v.current,a=T!=null&&r!==null&&r.complete&&r.naturalHeight!==0&&r.naturalWidth!==0;a&&T.excavation!=null&&(n=Zr(C,T.excavation));let c=window.devicePixelRatio||1;e.height=e.width=i*c;let l=i/w*c;t.scale(l,l),t.fillStyle=o,t.fillRect(0,0,w,w),t.fillStyle=s,ti?t.fill(new Path2D(Xr(n,S))):C.forEach(function(e,n){e.forEach(function(e,r){e&&t.fillRect(r+S,n+S,1,1)})}),T&&(t.globalAlpha=T.opacity),a&&t.drawImage(r,T.x+S,T.y+S,T.w,T.h)}}),X.useEffect(()=>{x(!1)},[g]);let E=Lr({height:i,width:i},m),D=null;return g!=null&&(D=X.createElement(`img`,{src:g,key:g,style:{display:`none`},onLoad:()=>{x(!0)},ref:v,crossOrigin:T?.crossOrigin})),X.createElement(X.Fragment,null,X.createElement(`canvas`,Lr({style:E,height:i,width:i,ref:y,role:`img`},h)),D)});ni.displayName=`QRCodeCanvas`;var ri=X.forwardRef(function(e,t){let n=e,{value:r,size:i=Z,level:a=Hr,bgColor:o=Ur,fgColor:s=Wr,includeMargin:c=Gr,minVersion:l=Kr,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=Rr(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:_,calculatedImageSettings:v}=ei({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:f,imageSettings:p,size:i}),y=g,b=null;p!=null&&v!=null&&(v.excavation!=null&&(y=Zr(g,v.excavation)),b=X.createElement(`image`,{href:p.src,height:v.h,width:v.w,x:v.x+h,y:v.y+h,preserveAspectRatio:`none`,opacity:v.opacity,crossOrigin:v.crossOrigin}));let x=Xr(y,h);return X.createElement(`svg`,Lr({height:i,width:i,viewBox:`0 0 ${_} ${_}`,ref:t,role:`img`},m),!!d&&X.createElement(`title`,null,d),X.createElement(`path`,{fill:o,d:`M0,0 h${_}v${_}H0z`,shapeRendering:`crispEdges`}),X.createElement(`path`,{fill:s,d:x,shapeRendering:`crispEdges`}),b)});ri.displayName=`QRCodeSVG`;function ii(e,t){return`bambuddy://config?v=1&url=${encodeURIComponent(e)}&key=${encodeURIComponent(t)}`}function ai({apiKey:e,baseUrl:t,onClose:n}){let{t:r}=l(),i=ii(t??window.location.origin,e);return(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-sm`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`settings.apiKeyQrTitle`)}),(0,Y.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,"aria-label":r(`common.close`),children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`div`,{className:`p-6 flex flex-col items-center`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 text-center`,children:r(`settings.apiKeyQrCaption`)}),(0,Y.jsx)(`div`,{className:`bg-white p-4 rounded-lg mb-4`,children:(0,Y.jsx)(ri,{value:i,size:256})}),(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-xs text-amber-700 dark:text-amber-400 mb-4`,children:[(0,Y.jsx)(Ie,{className:`w-4 h-4 flex-shrink-0 mt-0.5`}),(0,Y.jsx)(`span`,{children:r(`settings.apiKeyQrWarning`)})]}),(0,Y.jsx)(K,{onClick:n,className:`w-full`,children:r(`common.close`)})]})]})})}var oi=300,si=2;function ci({onSuccess:e}){let{t}=l(),n=u(),[i,a]=(0,X.useState)(``),[o,s]=(0,X.useState)(``),[c,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(null);(0,X.useEffect)(()=>{let e=i.trim();if(e.length<si){s(``);return}let t=setTimeout(()=>s(e),oi);return()=>clearTimeout(t)},[i]),(0,X.useEffect)(()=>{p(null),h(null)},[o]);let g=d({queryKey:[`ldap-search`,o],queryFn:()=>r.searchLDAPDirectory(o),enabled:o.length>=si,staleTime:3e4}),_=f({mutationFn:e=>r.provisionLDAPUser(e),onSuccess:t=>{n.invalidateQueries({queryKey:[`users`]}),e(t)},onError:e=>{h(e.message||t(`users.modal.ldapErrorProvision`))}}),v=(0,X.useMemo)(()=>g.data?.find(e=>e.dn===c)??null,[g.data,c]),y=i.trim().length>0&&i.trim().length<si,b=g.isFetching&&o.length>=si,x=!!g.data&&g.data.length>0,S=!b&&!!g.data&&g.data.length===0&&o.length>=si;return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:t(`users.modal.ldapSearchLabel`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ae,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2`}),(0,Y.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),className:`w-full pl-9 pr-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`users.modal.ldapSearchPlaceholder`),autoComplete:`off`})]}),y&&(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:t(`users.modal.ldapMinChars`)})]}),(0,Y.jsxs)(`div`,{className:`min-h-[8rem] max-h-64 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[b&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin mr-2`}),(0,Y.jsx)(`span`,{children:t(`users.modal.ldapSearching`)})]}),S&&(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray text-sm`,children:t(`users.modal.ldapNoResults`)}),g.isError&&(0,Y.jsx)(`div`,{className:`px-3 py-4 text-sm text-red-700 dark:text-red-400`,children:g.error instanceof Error?g.error.message:t(`users.modal.ldapSearchError`)}),!b&&x&&(0,Y.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary`,children:g.data.map(e=>(0,Y.jsx)(li,{result:e,selected:c===e.dn,onSelect:()=>p(e.dn)},e.dn))}),!b&&!g.data&&!g.isError&&(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray text-sm`,children:t(`users.modal.ldapTypeToSearch`)})]}),v&&(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-1`,children:[(0,Y.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[t(`users.modal.ldapSelectedLabel`),`: `]}),(0,Y.jsx)(`span`,{className:`font-medium`,children:v.username}),v.display_name&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,v.display_name]})]}),v.email&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:v.email}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray break-all`,children:v.dn})]}),m&&(0,Y.jsx)(`div`,{className:`bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg p-3`,children:(0,Y.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:m})}),(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsx)(K,{onClick:()=>{!v||v.already_provisioned||(h(null),_.mutate(v.username))},disabled:!v||v.already_provisioned||_.isPending,children:_.isPending?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}),t(`users.modal.ldapProvisioning`)]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),t(`users.modal.ldapProvision`)]})})})]})}function li({result:e,selected:t,onSelect:n}){let{t:r}=l(),i=e.already_provisioned;return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,onClick:n,disabled:i,className:`w-full text-left px-3 py-2 flex items-center gap-3 transition-colors ${i?`opacity-50 cursor-not-allowed`:t?`bg-bambu-green/10`:`hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`p`,{className:`text-sm text-white truncate`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:e.username}),e.display_name&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,e.display_name]})]}),e.email&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.email})]}),i&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray whitespace-nowrap`,children:[(0,Y.jsx)(q,{className:`w-3.5 h-3.5`}),r(`users.modal.ldapAlreadyProvisioned`)]})]})})}function ui({formData:e,setFormData:t,groups:n,onClose:r,onCreate:i,isCreating:a,isCreateButtonDisabled:o,ldapEnabled:s=!1,onLdapProvisioned:c}){let{t:u}=l(),[d,f]=(0,X.useState)(`local`);(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]);let p=n=>{t({...e,group_ids:e.group_ids.includes(n)?e.group_ids.filter(e=>e!==n):[...e.group_ids,n]})};return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:r,children:(0,Y.jsxs)(G,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Ze,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:u(`users.modal.createUser`)})]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray ml-7`,children:u(`users.modal.advancedAuthSubtitle`)||`with Advanced Authentication`})]}),(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:r,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]})}),(0,Y.jsxs)(W,{children:[s&&(0,Y.jsxs)(`div`,{className:`mb-4 flex items-center gap-1 p-1 bg-bambu-dark-secondary rounded-lg`,role:`tablist`,"aria-label":u(`users.modal.tabsAriaLabel`),children:[(0,Y.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":d===`local`,onClick:()=>f(`local`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${d===`local`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:u(`users.modal.localTab`)}),(0,Y.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":d===`ldap`,onClick:()=>f(`ldap`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${d===`ldap`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:u(`users.modal.ldapTab`)})]}),d===`ldap`&&s?(0,Y.jsx)(ci,{onSuccess:e=>{c?.(e)}}):(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[u(`users.form.username`),` `,(0,Y.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,Y.jsx)(`input`,{type:`text`,value:e.username,onChange:n=>t({...e,username:n.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:u(`users.form.usernamePlaceholder`),autoComplete:`username`,required:!0})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[u(`users.form.email`)||`Email`,` `,(0,Y.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,Y.jsx)(`input`,{type:`email`,value:e.email,onChange:n=>t({...e,email:n.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:u(`users.form.emailPlaceholder`)||`user@example.com`,required:!0})]}),(0,Y.jsx)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3`,children:(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:u(`users.form.autoGeneratedPassword`)||`A secure password will be automatically generated and emailed to the user.`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:u(`users.form.groups`)}),(0,Y.jsxs)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[n.map(t=>(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.group_ids.includes(t.id),onChange:()=>p(t.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:t.name}),t.is_system&&(0,Y.jsxs)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400`,children:[`(`,u(`users.system`),`)`]})]},t.id)),n.length===0&&(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:u(`users.noGroupsAvailable`)})]})]})]}),(0,Y.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:r,children:u(`users.modal.cancel`)}),d===`local`&&(0,Y.jsx)(K,{onClick:i,disabled:o,children:a?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}),u(`users.modal.creating`)]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),u(`users.modal.createUser`)]})})]})]})]})})}function di(){let{t:e}=l(),t=u(),{showToast:n}=ee(),[i,a]=(0,X.useState)(!1),[o,c]=(0,X.useState)(``),[p,m]=(0,X.useState)(`auto`),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(!0),[y,b]=(0,X.useState)(!0),[x,S]=(0,X.useState)(`all`),[C,w]=(0,X.useState)(!1),[D,O]=(0,X.useState)(!1),[k,j]=(0,X.useState)(!1),[te,M]=(0,X.useState)(!1),{data:N,isLoading:ne}=d({queryKey:[`spoolman-settings`],queryFn:r.getSpoolmanSettings}),{data:re,isLoading:ie,refetch:ae}=d({queryKey:[`spoolman-status`],queryFn:r.getSpoolmanStatus,refetchInterval:3e4}),{data:oe}=d({queryKey:[`printers`],queryFn:r.getPrinters});(0,X.useEffect)(()=>{N&&(a(N.spoolman_enabled===`true`),c(N.spoolman_url||``),m(N.spoolman_sync_mode||`auto`),g(N.spoolman_disable_weight_sync===`true`),v(N.spoolman_report_partial_usage!==`false`),b(N.auto_add_unknown_rfid!==`false`),w(!0))},[N]),(0,X.useEffect)(()=>{if(!(!C||!N)&&(N.spoolman_enabled===`true`!==i||(N.spoolman_url||``)!==o||(N.spoolman_sync_mode||`auto`)!==p||N.spoolman_disable_weight_sync===`true`!==h||N.spoolman_report_partial_usage!==`false`!==_||N.auto_add_unknown_rfid!==`false`!==y)){let e=setTimeout(()=>{P.mutate()},500);return()=>clearTimeout(e)}},[i,o,p,h,_,y,C]);let P=f({mutationFn:()=>r.updateSpoolmanSettings({spoolman_enabled:i?`true`:`false`,spoolman_url:o,spoolman_sync_mode:p,spoolman_disable_weight_sync:h?`true`:`false`,spoolman_report_partial_usage:_?`true`:`false`,auto_add_unknown_rfid:y?`true`:`false`}),onSuccess:()=>{t.invalidateQueries({queryKey:[`spoolman-settings`]}),t.invalidateQueries({queryKey:[`spoolman-status`]}),t.invalidateQueries({queryKey:[`spool-assignments`]}),t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`spoolman-inventory-filaments`]}),n(e(`settings.toast.settingsSaved`))},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),F=f({mutationFn:r.connectSpoolman,onSuccess:()=>{ae()},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),R=f({mutationFn:r.syncAllPrintersAms,onSuccess:t=>{n(e(`settings.spoolmanAmsSyncSuccess`,{synced:t.synced_count,skipped:0}),`success`)},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),se=f({mutationFn:e=>r.syncPrinterAms(e),onSuccess:t=>{n(e(`settings.spoolmanAmsSyncSuccess`,{synced:t.synced_count,skipped:0}),`success`)},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),ce=()=>{x===`all`?R.mutate():se.mutate(x)},z=f({mutationFn:r.syncWeightsFromAms,onSuccess:r=>{t.invalidateQueries({queryKey:[`spools`]}),t.invalidateQueries({queryKey:[`inventory-spools`]}),n(e(`settings.amsSyncSuccess`,{synced:r.synced,skipped:r.skipped}),`success`),j(!1)},onError:()=>{n(e(`settings.amsSyncError`),`error`),j(!1)}}),B=f({mutationFn:r.syncSpoolmanAmsWeights,onSuccess:r=>{t.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),n(e(`settings.spoolmanAmsSyncSuccess`,{synced:r.synced,skipped:r.skipped}),`success`),M(!1)},onError:t=>{t instanceof s&&t.status===503?n(e(`settings.spoolmanAmsSyncErrorUnreachable`),`error`):t instanceof s&&t.status===400?n(e(`settings.spoolmanAmsSyncErrorNotConfigured`),`error`):n(e(`settings.spoolmanAmsSyncError`),`error`),M(!1)}}),le=R.isPending||se.isPending,V=x===`all`?R.data:se.data,ue=x===`all`?R.isSuccess:se.isSuccess;return ne?(0,Y.jsxs)(G,{id:`card-spoolman`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(gt,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.filamentTracking`)})]})}),(0,Y.jsx)(W,{children:(0,Y.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,Y.jsx)(L,{className:`w-6 h-6 text-bambu-green animate-spin`})})})]}):(0,Y.jsxs)(G,{id:`card-spoolman`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(gt,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.filamentTracking`)})]}),P.isPending&&(0,Y.jsx)(L,{className:`w-4 h-4 text-bambu-green animate-spin`})]})}),(0,Y.jsxs)(W,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.filamentTrackingDesc`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>a(!1),className:`p-3 rounded-lg border-2 text-left transition-colors ${i?`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50`:`border-bambu-green bg-bambu-green/10`}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,Y.jsx)(Ee,{className:`w-4 h-4 ${i?`text-bambu-gray`:`text-bambu-green`}`}),(0,Y.jsx)(`span`,{className:`text-sm font-medium ${i?`text-bambu-gray`:`text-white`}`,children:e(`settings.trackingModeBuiltIn`)})]}),(0,Y.jsx)(`p`,{className:`text-xs ${i?`text-bambu-gray/60`:`text-bambu-gray`}`,children:e(`settings.trackingModeBuiltInDesc`)}),!i&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,Y.jsx)(T,{className:`w-3 h-3 text-bambu-green`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-green`,children:e(`common.enabled`)})]})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>a(!0),className:`p-3 rounded-lg border-2 text-left transition-colors ${i?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50`}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,Y.jsx)(Je,{className:`w-4 h-4 ${i?`text-bambu-green`:`text-bambu-gray`}`}),(0,Y.jsx)(`span`,{className:`text-sm font-medium ${i?`text-white`:`text-bambu-gray`}`,children:`Spoolman`})]}),(0,Y.jsx)(`p`,{className:`text-xs ${i?`text-bambu-gray`:`text-bambu-gray/60`}`,children:e(`settings.trackingModeSpoolmanDesc`)}),i&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,Y.jsx)(T,{className:`w-3 h-3 text-bambu-green`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-green`,children:e(`common.enabled`)})]})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`pr-4`,children:[(0,Y.jsx)(`p`,{className:`text-white`,children:e(`settings.autoAddUnknownRfid`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.autoAddUnknownRfidDesc`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:y,onChange:e=>b(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),!i&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(`div`,{className:`p-3 bg-bambu-green/5 border border-bambu-green/20 rounded-lg`,children:(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(A,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-0.5`}),(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,Y.jsxs)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:[(0,Y.jsx)(`li`,{children:e(`settings.builtInFeatureRfid`)}),(0,Y.jsx)(`li`,{children:e(`settings.builtInFeatureUsage`)}),(0,Y.jsx)(`li`,{children:e(`settings.builtInFeatureCatalog`)}),(0,Y.jsx)(`li`,{children:e(`settings.builtInFeatureThirdParty`)})]})})]})}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:()=>j(!0),disabled:z.isPending,children:[z.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 mr-2 animate-spin`}):(0,Y.jsx)(at,{className:`w-4 h-4 mr-2`}),e(`settings.amsSyncButton`)]})]}),i&&(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(`div`,{className:`p-3 bg-blue-50 dark:bg-blue-500/10 border border-blue-300 dark:border-blue-500/30 rounded-lg`,children:(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(A,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{className:`text-xs text-blue-700 dark:text-blue-300`,children:[(0,Y.jsx)(`p`,{className:`font-medium mb-1`,children:e(`settings.howSyncWorks`)}),(0,Y.jsxs)(`ul`,{className:`list-disc list-inside space-y-0.5 text-blue-700/90 dark:text-blue-300/80`,children:[(0,Y.jsx)(`li`,{children:e(`settings.syncInfoRfidOnly`)}),(0,Y.jsx)(`li`,{children:e(`settings.syncInfoAutoCreate`)}),(0,Y.jsx)(`li`,{children:e(`settings.syncInfoThirdPartySkipped`)})]}),(0,Y.jsx)(`p`,{className:`font-medium mt-2 mb-1`,children:e(`settings.linkingExistingSpools`)}),(0,Y.jsx)(`p`,{className:`text-blue-700/90 dark:text-blue-300/80`,children:e(`settings.linkingExistingSpoolsDesc`)})]})]})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`settings.spoolmanUrl`)}),(0,Y.jsx)(`input`,{type:`text`,placeholder:`http://192.168.1.100:7912`,value:o,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.spoolmanUrlHint`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`settings.syncMode`)}),(0,Y.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`auto`,children:e(`settings.syncModeAuto`)}),(0,Y.jsx)(`option`,{value:`manual`,children:e(`settings.syncModeManual`)})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(p===`auto`?`settings.syncModeAutoDesc`:`settings.syncModeManualDesc`)})]}),p===`auto`&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:e(`spoolman.disableWeightSync`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`spoolman.disableWeightSyncDesc`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),h&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:e(`spoolman.reportPartialUsage`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`spoolman.reportPartialUsageDesc`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:_,onChange:e=>v(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`settings.status`),`:`]}),ie?(0,Y.jsx)(L,{className:`w-4 h-4 text-bambu-gray animate-spin`}):re?.connected?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-sm text-green-500`,children:[(0,Y.jsx)(T,{className:`w-4 h-4`}),e(`settings.spoolmanConnected`)]}):(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-sm text-red-500`,children:[(0,Y.jsx)(Re,{className:`w-4 h-4`}),e(`settings.spoolmanDisconnected`)]})]}),(0,Y.jsx)(`div`,{className:`flex gap-2`,children:!re?.connected&&(0,Y.jsxs)(K,{size:`sm`,onClick:()=>F.mutate(),disabled:F.isPending||!o,children:[F.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(I,{className:`w-4 h-4`}),e(`settings.connect`)]})})]}),F.isError&&(0,Y.jsx)(`div`,{className:`mb-3 p-2 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded text-sm text-red-700 dark:text-red-400`,children:F.error.message}),re?.connected&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.syncAmsData`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.syncAmsDataDesc`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Y.jsxs)(`select`,{value:x,onChange:e=>S(e.target.value===`all`?`all`:Number(e.target.value)),className:`w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,Y.jsx)(`option`,{value:`all`,children:e(`settings.allPrinters`)}),oe?.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,Y.jsx)(E,{className:`absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:ce,disabled:le,children:[le?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(at,{className:`w-4 h-4`}),e(`spoolman.sync`)]})]})]}),re?.connected&&(0,Y.jsx)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.spoolmanAmsSyncButton`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.spoolmanAmsSyncMessage`)})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:()=>M(!0),disabled:B.isPending,children:[B.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(at,{className:`w-4 h-4`}),B.isPending?e(`settings.spoolmanAmsSyncing`):e(`settings.spoolmanAmsSyncButton`)]})]})}),ue&&V&&(0,Y.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded text-sm ${V.success?`bg-green-100 dark:bg-green-500/20 border border-green-300 dark:border-green-500/50 text-green-700 dark:text-green-400`:`bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-300 dark:border-yellow-500/50 text-yellow-700 dark:text-yellow-400`}`,children:V.success?`Synced ${V.synced_count} spool${V.synced_count===1?``:`s`} successfully`:`Synced ${V.synced_count} spool${V.synced_count===1?``:`s`} with ${V.errors.length} error${V.errors.length===1?``:`s`}`}),V.skipped_count>0&&(0,Y.jsxs)(`div`,{className:`p-2 bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded text-sm`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-amber-700 dark:text-amber-400 mb-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(Ie,{className:`w-3.5 h-3.5`}),(0,Y.jsxs)(`span`,{className:`font-medium`,children:[V.skipped_count,` spool`,V.skipped_count===1?``:`s`,` skipped`]})]}),V.skipped_count>5&&(0,Y.jsx)(`button`,{onClick:()=>O(!D),className:`text-xs text-amber-700 dark:text-amber-400 hover:text-amber-800 dark:hover:text-amber-300 underline`,children:D?`Show less`:`Show all`})]}),(0,Y.jsxs)(`ul`,{className:`text-xs text-amber-700/90 dark:text-amber-300/80 space-y-0.5`,children:[(D?V.skipped:V.skipped.slice(0,5)).map((e,t)=>(0,Y.jsxs)(`li`,{className:`flex items-center gap-2`,children:[e.color&&(0,Y.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:`#${e.color}`}}),(0,Y.jsx)(`span`,{children:e.location}),(0,Y.jsxs)(`span`,{className:`text-amber-700/70 dark:text-amber-300/60`,children:[`- `,e.reason]})]},t)),!D&&V.skipped_count>5&&(0,Y.jsxs)(`li`,{className:`text-amber-700/70 dark:text-amber-300/60 italic`,children:[`...and `,V.skipped_count-5,` more`]})]})]}),V.errors.length>0&&(0,Y.jsxs)(`div`,{className:`p-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded text-sm`,children:[(0,Y.jsx)(`div`,{className:`text-red-700 dark:text-red-400 font-medium mb-1`,children:`Errors:`}),(0,Y.jsx)(`ul`,{className:`text-xs text-red-700/90 dark:text-red-300/80 space-y-0.5`,children:V.errors.map((e,t)=>(0,Y.jsx)(`li`,{children:e},t))})]})]})]})]})]}),k&&(0,Y.jsx)(Tt,{title:e(`settings.amsSyncTitle`),message:e(`settings.amsSyncMessage`),confirmText:e(`settings.amsSyncButton`),variant:`warning`,isLoading:z.isPending,loadingText:e(`settings.amsSyncing`),onConfirm:()=>z.mutate(),onCancel:()=>j(!1)}),te&&(0,Y.jsx)(Tt,{title:e(`settings.spoolmanAmsSyncTitle`),message:e(`settings.spoolmanAmsSyncMessage`),confirmText:e(`settings.spoolmanAmsSyncButton`),variant:`warning`,isLoading:B.isPending,loadingText:e(`settings.spoolmanAmsSyncing`),onConfirm:()=>B.mutate(),onCancel:()=>M(!1)})]})}function fi(){let{t:e}=l(),{showToast:t}=ee(),[n,i]=(0,X.useState)([]),[a,o]=(0,X.useState)(!0),[s,c]=(0,X.useState)(``),u=(0,X.useRef)(null),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)(``),[_,v]=(0,X.useState)(``),[y,b]=(0,X.useState)(!1),[x,S]=(0,X.useState)(new Set),[C,w]=(0,X.useState)(!1),[E,D]=(0,X.useState)(null),[O,k]=(0,X.useState)(!1),A=(0,X.useCallback)(async()=>{try{i(await r.getSpoolCatalog())}catch(n){console.error(`SpoolCatalogSettings.loadCatalog failed:`,n),t(e(`settings.catalog.loadFailed`),`error`)}finally{o(!1)}},[t,e]);(0,X.useEffect)(()=>{A()},[A]);let j=n.filter(e=>e.name.toLowerCase().includes(s.toLowerCase())),te=async()=>{if(!h.trim()||!_){t(e(`settings.catalog.nameWeightRequired`),`error`);return}b(!0);try{let n=await r.addCatalogEntry({name:h.trim(),weight:parseInt(_)});i(e=>[...e,n].sort((e,t)=>e.name.localeCompare(t.name))),f(!1),g(``),v(``),t(e(`settings.catalog.entryAdded`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleAdd failed:`,n),t(e(`settings.catalog.addFailed`),`error`)}finally{b(!1)}},M=e=>{m(e.id),g(e.name),v(e.weight.toString())},N=()=>{m(null),g(``),v(``)},ne=async n=>{if(!h.trim()||!_){t(e(`settings.catalog.nameWeightRequired`),`error`);return}b(!0);try{let a=await r.updateCatalogEntry(n,{name:h.trim(),weight:parseInt(_)});i(e=>e.map(e=>e.id===n?a:e).sort((e,t)=>e.name.localeCompare(t.name))),m(null),g(``),v(``),t(e(`settings.catalog.entryUpdated`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleUpdate failed:`,n),t(e(`settings.catalog.updateFailed`),`error`)}finally{b(!1)}},re=async()=>{if(E)try{await r.deleteCatalogEntry(E.id),i(e=>e.filter(e=>e.id!==E.id)),t(e(`settings.catalog.entryDeleted`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleDelete failed:`,n),t(e(`settings.catalog.deleteFailed`),`error`)}finally{D(null)}},ie=async()=>{k(!1),o(!0);try{await r.resetSpoolCatalog(),await A(),t(e(`settings.catalog.resetSuccess`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleReset failed:`,n),t(e(`settings.catalog.resetFailed`),`error`),o(!1)}},ae=e=>{S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,Y.jsxs)(G,{id:`card-spool-catalog`,children:[(0,Y.jsxs)(U,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Y.jsx)(gt,{className:`w-5 h-5 text-bambu-gray`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.catalog.spoolCatalog`)}),(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,n.length,`)`]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsxs)(`button`,{onClick:()=>{let r=n.map(({name:e,weight:t})=>({name:e,weight:t})),i=new Blob([JSON.stringify(r,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`spool-catalog.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a),t(e(`settings.catalog.exported`,{count:n.length}),`success`)},className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.exportTooltip`),children:[(0,Y.jsx)(sn,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.export`)})]}),(0,Y.jsxs)(`button`,{onClick:()=>u.current?.click(),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.importTooltip`),children:[(0,Y.jsx)(Wt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.import`)})]}),(0,Y.jsx)(`input`,{ref:u,type:`file`,accept:`.json`,className:`hidden`,onChange:async a=>{let o=a.target.files?.[0];if(o){try{let a=await o.text(),s=JSON.parse(a);if(!Array.isArray(s))throw Error(`Invalid format`);let c=0,l=0;for(let e of s){if(!e.name||typeof e.weight!=`number`){l++;continue}if(n.some(t=>t.name.toLowerCase()===e.name.toLowerCase())){l++;continue}try{let t=await r.addCatalogEntry({name:e.name,weight:e.weight});i(e=>[...e,t].sort((e,t)=>e.name.localeCompare(t.name))),c++}catch(e){console.error(`SpoolCatalogSettings import item failed:`,e),l++}}t(e(`settings.catalog.imported`,{added:c,skipped:l}),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleImport failed:`,n),t(e(`settings.catalog.importFailed`),`error`)}u.current&&(u.current.value=``)}}}),(0,Y.jsxs)(`button`,{onClick:()=>k(!0),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.resetTooltip`),children:[(0,Y.jsx)(nt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.reset`)})]}),(0,Y.jsxs)(`button`,{onClick:()=>f(!0),className:`px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5`,children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.add`)})]})]}),x.size>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 px-3 py-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-red-700 dark:text-red-400`,children:e(`settings.catalog.selectedCount`,{count:x.size})}),(0,Y.jsxs)(`button`,{onClick:()=>w(!0),className:`ml-auto px-3 py-1.5 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-1.5`,children:[(0,Y.jsx)(qe,{className:`w-4 h-4`}),e(`settings.catalog.deleteSelected`)]}),(0,Y.jsx)(`button`,{onClick:()=>S(new Set),className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors`,children:e(`common.cancel`)})]})]}),(0,Y.jsxs)(W,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.catalog.spoolCatalogDescription`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Y.jsx)(`input`,{type:`text`,className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.catalog.searchCatalog`),value:s,onChange:e=>c(e.target.value)})]}),d&&(0,Y.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e(`settings.catalog.addNewEntry`)}),(0,Y.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,Y.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.catalog.namePlaceholder`),value:h,onChange:e=>g(e.target.value)})}),(0,Y.jsx)(`input`,{type:`number`,className:`w-20 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-center focus:border-bambu-green focus:outline-none`,placeholder:`g`,value:_,onChange:e=>v(e.target.value)}),(0,Y.jsx)(`span`,{className:`text-bambu-gray shrink-0`,children:`g`}),(0,Y.jsxs)(`button`,{onClick:te,disabled:y,className:`px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center gap-1 shrink-0`,children:[y?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(T,{className:`w-4 h-4`}),e(`common.add`)]}),(0,Y.jsx)(`button`,{onClick:()=>{f(!1),g(``),v(``)},className:`p-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:(0,Y.jsx)(Re,{className:`w-4 h-4`})})]})]}),a?(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,Y.jsx)(L,{className:`w-5 h-5 animate-spin mr-2`}),e(`common.loading`)]}):(0,Y.jsx)(`div`,{className:`max-h-[600px] overflow-y-auto border border-bambu-dark-tertiary rounded-lg`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-2 py-2 w-10`,children:(0,Y.jsx)(`input`,{type:`checkbox`,checked:j.length>0&&x.size===j.length,onChange:()=>{x.size===j.length?S(new Set):S(new Set(j.map(e=>e.id)))},className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-left text-bambu-gray font-medium`,children:e(`common.name`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-right text-bambu-gray font-medium w-24`,children:e(`settings.catalog.weight`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-center text-bambu-gray font-medium w-20`,children:e(`settings.catalog.type`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 w-24`})]})}),(0,Y.jsx)(`tbody`,{children:j.length===0?(0,Y.jsx)(`tr`,{children:(0,Y.jsx)(`td`,{colSpan:5,className:`px-4 py-8 text-center text-bambu-gray`,children:e(s?`settings.catalog.noMatch`:`settings.catalog.empty`)})}):j.map(t=>(0,Y.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${x.has(t.id)?`bg-bambu-dark`:``}`,children:p===t.id?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`td`,{className:`px-2 py-2`,children:(0,Y.jsx)(`input`,{type:`checkbox`,checked:x.has(t.id),onChange:()=>ae(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white focus:border-bambu-green focus:outline-none`,value:h,onChange:e=>g(e.target.value)})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsx)(`input`,{type:`number`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-right focus:border-bambu-green focus:outline-none`,value:_,onChange:e=>v(e.target.value)})}),(0,Y.jsx)(`td`,{className:`px-4 py-2 text-center`,children:(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`-`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,Y.jsx)(`button`,{onClick:()=>ne(t.id),disabled:y,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:y?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(T,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:N,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,Y.jsx)(Re,{className:`w-4 h-4`})})]})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`td`,{className:`px-2 py-2`,children:(0,Y.jsx)(`input`,{type:`checkbox`,checked:x.has(t.id),onChange:()=>ae(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2 text-white`,children:t.name}),(0,Y.jsxs)(`td`,{className:`px-4 py-2 text-right font-mono text-white`,children:[t.weight,`g`]}),(0,Y.jsx)(`td`,{className:`px-4 py-2 text-center`,children:t.is_default?(0,Y.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray`,children:e(`settings.catalog.default`)}):(0,Y.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:e(`settings.catalog.custom`)})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,Y.jsx)(`button`,{onClick:()=>M(t),className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,Y.jsx)(Ke,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>D(t),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]})})]})},t.id))})]})})]}),E&&(0,Y.jsx)(Tt,{title:e(`settings.catalog.deleteEntry`),message:e(`settings.catalog.deleteConfirm`,{name:E.name}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:re,onCancel:()=>D(null)}),C&&(0,Y.jsx)(Tt,{title:e(`settings.catalog.deleteSelected`),message:e(`settings.catalog.bulkDeleteConfirm`,{count:x.size}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:async()=>{if(w(!1),x.size!==0)try{let n=await r.bulkDeleteCatalogEntries([...x]);i(e=>e.filter(e=>!x.has(e.id))),S(new Set),t(e(`settings.catalog.bulkDeleted`,{count:n.deleted}),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleBulkDelete failed:`,n),t(e(`settings.catalog.bulkDeleteFailed`),`error`)}},onCancel:()=>w(!1)}),O&&(0,Y.jsx)(Tt,{title:e(`settings.catalog.resetCatalog`),message:e(`settings.catalog.resetConfirm`),confirmText:e(`common.reset`),variant:`danger`,onConfirm:ie,onCancel:()=>k(!1)})]})}function pi(){let{t:e}=l(),{showToast:t}=ee(),[n,i]=(0,X.useState)([]),[a,s]=(0,X.useState)(!0),[c,u]=(0,X.useState)(``),[d,f]=(0,X.useState)(``),p=(0,X.useRef)(null),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(``),[b,x]=(0,X.useState)(``),[S,C]=(0,X.useState)(`#FFFFFF`),[w,E]=(0,X.useState)(``),[D,O]=(0,X.useState)(``),[k,A]=(0,X.useState)(``),[j,te]=(0,X.useState)(!1),[M,N]=(0,X.useState)(new Set),[ne,re]=(0,X.useState)(!1),[ie,ae]=(0,X.useState)(!1),[oe,P]=(0,X.useState)(null),[F,I]=(0,X.useState)(null),[R,se]=(0,X.useState)(!1),ce=(0,X.useCallback)(async()=>{try{i(await r.getColorCatalog())}catch{t(e(`settings.colorCatalog.loadFailed`),`error`)}finally{s(!1)}},[t,e]);(0,X.useEffect)(()=>{ce()},[ce]);let z=[...new Set(n.map(e=>e.manufacturer))].sort(),B=n.filter(e=>{let t=c===``||e.manufacturer.toLowerCase().includes(c.toLowerCase())||e.color_name.toLowerCase().includes(c.toLowerCase())||(e.material?.toLowerCase().includes(c.toLowerCase())??!1),n=d===``||e.manufacturer===d;return t&&n}),le=()=>{y(``),x(``),C(`#FFFFFF`),E(``),O(``),A(``)},V=async()=>{if(!v.trim()||!b.trim()||!S){t(e(`settings.colorCatalog.fieldsRequired`),`error`);return}te(!0);try{let n=await r.addColorEntry({manufacturer:v.trim(),color_name:b.trim(),hex_color:S,material:w.trim()||null,extra_colors:D.trim()||null,effect_type:k.trim()||null});i(e=>[...e,n].sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),h(!1),le(),t(e(`settings.colorCatalog.colorAdded`),`success`)}catch{t(e(`settings.colorCatalog.addFailed`),`error`)}finally{te(!1)}},ue=e=>{_(e.id),y(e.manufacturer),x(e.color_name),C(e.hex_color),E(e.material||``),O(e.extra_colors||``),A(e.effect_type||``)},de=()=>{_(null),le()},fe=async n=>{if(!v.trim()||!b.trim()||!S){t(e(`settings.colorCatalog.fieldsRequired`),`error`);return}te(!0);try{let a=await r.updateColorEntry(n,{manufacturer:v.trim(),color_name:b.trim(),hex_color:S,material:w.trim()||null,extra_colors:D.trim()||null,effect_type:k.trim()||null});i(e=>e.map(e=>e.id===n?a:e).sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),_(null),le(),t(e(`settings.colorCatalog.colorUpdated`),`success`)}catch{t(e(`settings.colorCatalog.updateFailed`),`error`)}finally{te(!1)}},pe=async()=>{if(F)try{await r.deleteColorEntry(F.id),i(e=>e.filter(e=>e.id!==F.id)),t(e(`settings.colorCatalog.colorDeleted`),`success`)}catch{t(e(`settings.colorCatalog.deleteFailed`),`error`)}finally{I(null)}},me=async()=>{se(!1),s(!0);try{await r.resetColorCatalog(),await ce(),t(e(`settings.colorCatalog.resetSuccess`),`success`)}catch{t(e(`settings.colorCatalog.resetFailed`),`error`),s(!1)}},he=async()=>{ae(!0),P(null);try{let n={},r=o();r&&(n.Authorization=`Bearer ${r}`);let i=await fetch(`/api/v1/inventory/colors/sync`,{method:`POST`,headers:n});if(!i.ok)throw Error(`Failed to start sync`);let a=i.body?.getReader();if(!a)throw Error(`No response body`);let s=new TextDecoder,c=``;for(;;){let{done:n,value:r}=await a.read();if(n)break;c+=s.decode(r,{stream:!0});let i=c.split(`
  2. `);c=i.pop()||``;for(let n of i)if(n.startsWith(`data: `))try{let r=JSON.parse(n.slice(6));r.type===`progress`?P({fetched:r.total_fetched,total:r.total_available}):r.type===`complete`?r.added===0?t(e(`settings.colorCatalog.syncUpToDate`,{count:r.total_fetched}),`success`):t(e(`settings.colorCatalog.syncComplete`,{added:r.added,skipped:r.skipped}),`success`):r.type===`error`&&t(`${e(`settings.colorCatalog.syncError`)}: ${r.error}`,`error`)}catch{}}await ce()}catch{t(e(`settings.colorCatalog.syncFailed`),`error`)}finally{ae(!1),P(null)}},ge=e=>{N(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,Y.jsxs)(G,{id:`card-color-catalog`,children:[(0,Y.jsxs)(U,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Y.jsx)(Nt,{className:`w-5 h-5 text-bambu-gray`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.colorCatalog.title`)}),(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,n.length,`)`]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsxs)(`button`,{onClick:()=>{let r=n.map(({manufacturer:e,color_name:t,hex_color:n,material:r,extra_colors:i,effect_type:a})=>({manufacturer:e,color_name:t,hex_color:n,material:r,extra_colors:i,effect_type:a})),i=new Blob([JSON.stringify(r,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`color-catalog.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a),t(e(`settings.colorCatalog.exported`,{count:n.length}),`success`)},className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,Y.jsx)(sn,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.export`)})]}),(0,Y.jsxs)(`button`,{onClick:()=>p.current?.click(),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,Y.jsx)(Wt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.import`)})]}),(0,Y.jsx)(`input`,{ref:p,type:`file`,accept:`.json`,className:`hidden`,onChange:async a=>{let o=a.target.files?.[0];if(o){try{let a=await o.text(),s=JSON.parse(a);if(!Array.isArray(s))throw Error(`Invalid format`);let c=0,l=0;for(let e of s){if(!e.manufacturer||!e.color_name||!e.hex_color){l++;continue}if(n.some(t=>t.manufacturer.toLowerCase()===e.manufacturer.toLowerCase()&&t.color_name.toLowerCase()===e.color_name.toLowerCase()&&(t.material||``).toLowerCase()===(e.material||``).toLowerCase())){l++;continue}try{let t=await r.addColorEntry({manufacturer:e.manufacturer,color_name:e.color_name,hex_color:e.hex_color,material:e.material||null,extra_colors:e.extra_colors||null,effect_type:e.effect_type||null});i(e=>[...e,t].sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),c++}catch{l++}}t(e(`settings.colorCatalog.imported`,{added:c,skipped:l}),`success`)}catch{t(e(`settings.colorCatalog.importFailed`),`error`)}p.current&&(p.current.value=``)}}}),(0,Y.jsxs)(`button`,{onClick:he,disabled:ie,className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.colorCatalog.syncTooltip`),children:[ie?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Xe,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:ie?oe?`${Math.min(oe.fetched,oe.total)} / ${oe.total}`:e(`settings.colorCatalog.starting`):e(`settings.colorCatalog.sync`)})]}),(0,Y.jsxs)(`button`,{onClick:()=>se(!0),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,Y.jsx)(nt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.reset`)})]}),(0,Y.jsxs)(`button`,{onClick:()=>h(!0),className:`px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5`,children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.add`)})]})]}),M.size>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 px-3 py-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-red-700 dark:text-red-400`,children:e(`settings.colorCatalog.selectedCount`,{count:M.size})}),(0,Y.jsxs)(`button`,{onClick:()=>re(!0),className:`ml-auto px-3 py-1.5 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-1.5`,children:[(0,Y.jsx)(qe,{className:`w-4 h-4`}),e(`settings.colorCatalog.deleteSelected`)]}),(0,Y.jsx)(`button`,{onClick:()=>N(new Set),className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors`,children:e(`common.cancel`)})]})]}),(0,Y.jsxs)(W,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.colorCatalog.description`)}),(0,Y.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 min-w-[200px]`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Y.jsx)(`input`,{type:`text`,className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.searchColors`),value:c,onChange:e=>u(e.target.value)})]}),(0,Y.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:d,onChange:e=>f(e.target.value),children:[(0,Y.jsx)(`option`,{value:``,children:e(`settings.colorCatalog.allManufacturers`)}),z.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]})]}),m&&(0,Y.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e(`settings.colorCatalog.addNewColor`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-2 items-end`,children:[(0,Y.jsx)(`input`,{type:`text`,className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.manufacturer`),value:v,onChange:e=>y(e.target.value)}),(0,Y.jsx)(`input`,{type:`text`,className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.colorName`),value:b,onChange:e=>x(e.target.value)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`input`,{type:`color`,className:`w-20 h-10 rounded cursor-pointer border border-bambu-dark-tertiary`,value:S,onChange:e=>C(e.target.value)}),(0,Y.jsx)(`input`,{type:`text`,className:`w-32 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:`#FFFFFF`,value:S,onChange:e=>C(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`input`,{type:`text`,className:`flex-1 max-w-lg min-w-[200px] px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.materialOptional`),value:w,onChange:e=>E(e.target.value)}),(0,Y.jsxs)(`button`,{onClick:V,disabled:j,className:`w-24 px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center justify-center gap-3`,children:[j?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(T,{className:`w-4 h-4`}),e(`common.add`)]}),(0,Y.jsx)(`button`,{onClick:()=>{h(!1),le()},className:`p-2 ml-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:(0,Y.jsx)(Re,{className:`w-4 h-4`})})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2 mt-2`,children:[(0,Y.jsx)(`input`,{type:`text`,className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`inventory.extraColorsPlaceholder`),value:D,onChange:e=>O(e.target.value)}),(0,Y.jsx)(`select`,{className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,value:k,onChange:e=>A(e.target.value),children:Ge.map(t=>(0,Y.jsx)(`option`,{value:t.value,children:e(t.labelKey)},t.value||`none`))})]})]}),(c||d)&&(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:e(`settings.colorCatalog.showing`,{filtered:B.length,total:n.length})}),a?(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,Y.jsx)(L,{className:`w-5 h-5 animate-spin mr-2`}),e(`common.loading`)]}):(0,Y.jsx)(`div`,{className:`max-h-[600px] overflow-auto border border-bambu-dark-tertiary rounded-lg`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-2 py-2 w-10`,children:(0,Y.jsx)(`input`,{type:`checkbox`,checked:B.length>0&&M.size===B.length,onChange:()=>{M.size===B.length?N(new Set):N(new Set(B.map(e=>e.id)))},className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium w-12`}),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`settings.colorCatalog.manufacturer`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`inventory.material`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`settings.colorCatalog.colorName`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium w-24`,children:e(`settings.colorCatalog.hex`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 w-16`})]})}),(0,Y.jsx)(`tbody`,{children:B.length===0?(0,Y.jsx)(`tr`,{children:(0,Y.jsx)(`td`,{colSpan:7,className:`px-3 py-8 text-center text-bambu-gray`,children:e(c||d?`settings.colorCatalog.noMatch`:`settings.colorCatalog.empty`)})}):B.map(t=>(0,Y.jsxs)(X.Fragment,{children:[(0,Y.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${M.has(t.id)?`bg-bambu-dark`:``}`,children:g===t.id?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`td`,{className:`px-2 py-2`,children:(0,Y.jsx)(`input`,{type:`checkbox`,checked:M.has(t.id),onChange:()=>ge(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsx)(`input`,{type:`color`,className:`w-8 h-8 rounded cursor-pointer border border-bambu-dark-tertiary`,value:S,onChange:e=>C(e.target.value)})}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:v,onChange:e=>y(e.target.value)})}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:w,onChange:e=>E(e.target.value)})}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:b,onChange:e=>x(e.target.value)})}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:S,onChange:e=>C(e.target.value)})}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,Y.jsx)(`button`,{onClick:()=>fe(t.id),disabled:j,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:j?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(T,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:de,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,Y.jsx)(Re,{className:`w-4 h-4`})})]})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`td`,{className:`px-2 py-2`,children:(0,Y.jsx)(`input`,{type:`checkbox`,checked:M.has(t.id),onChange:()=>ge(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsx)(on,{rgba:t.hex_color.replace(/^#/,``)+(t.hex_color.length===7?`FF`:``),extraColors:t.extra_colors,effectType:t.effect_type,className:`w-8 h-8`,shape:`square`,title:t.hex_color,effectSize:`table`})}),(0,Y.jsx)(`td`,{className:`px-3 py-2 text-white`,children:t.manufacturer}),(0,Y.jsx)(`td`,{className:`px-3 py-2 text-bambu-gray`,children:t.material||`-`}),(0,Y.jsx)(`td`,{className:`px-3 py-2 text-white`,children:t.color_name}),(0,Y.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs text-bambu-gray`,children:t.hex_color}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,Y.jsx)(`button`,{onClick:()=>ue(t),className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,Y.jsx)(Ke,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>I(t),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]})})]})}),g===t.id&&(0,Y.jsxs)(`tr`,{className:`border-t border-bambu-dark-tertiary/50 bg-bambu-dark`,children:[(0,Y.jsx)(`td`,{colSpan:2}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,colSpan:2,children:(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`,placeholder:e(`inventory.extraColorsPlaceholder`),value:D,onChange:e=>O(e.target.value)})}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,colSpan:2,children:(0,Y.jsx)(`select`,{className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:k,onChange:e=>A(e.target.value),children:Ge.map(t=>(0,Y.jsx)(`option`,{value:t.value,children:e(t.labelKey)},t.value||`none`))})}),(0,Y.jsx)(`td`,{})]})]},t.id))})]})})]}),F&&(0,Y.jsx)(Tt,{title:e(`settings.colorCatalog.deleteColor`),message:e(`settings.colorCatalog.deleteConfirm`,{name:`${F.manufacturer} - ${F.color_name}`}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:pe,onCancel:()=>I(null)}),ne&&(0,Y.jsx)(Tt,{title:e(`settings.colorCatalog.deleteSelected`),message:e(`settings.colorCatalog.bulkDeleteConfirm`,{count:M.size}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:async()=>{if(re(!1),M.size!==0)try{let n=await r.bulkDeleteColorEntries([...M]);i(e=>e.filter(e=>!M.has(e.id))),N(new Set),t(e(`settings.colorCatalog.bulkDeleted`,{count:n.deleted}),`success`)}catch{t(e(`settings.colorCatalog.bulkDeleteFailed`),`error`)}},onCancel:()=>re(!1)}),R&&(0,Y.jsx)(Tt,{title:e(`settings.colorCatalog.resetCatalog`),message:e(`settings.colorCatalog.resetConfirm`),confirmText:e(`common.reset`),variant:`danger`,onConfirm:me,onCancel:()=>se(!1)})]})}function mi({link:e,onClose:t}){let{t:n}=l(),i=u(),a=!!e,o=(0,X.useRef)(null),[s,c]=(0,X.useState)(e?.name||``),[d,p]=(0,X.useState)(e?.url||``),[m,h]=(0,X.useState)(e?.icon||`link`),[g,_]=(0,X.useState)(e?.open_in_new_tab||!1),[v,y]=(0,X.useState)(!!e?.custom_icon),[b,x]=(0,X.useState)(e?.custom_icon?r.getExternalLinkIconUrl(e.id):null),[S,C]=(0,X.useState)(null),[w,T]=(0,X.useState)(null);(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let E=f({mutationFn:async e=>{let t=await r.createExternalLink(e);return S?await r.uploadExternalLinkIcon(t.id,S):t},onSuccess:()=>{i.invalidateQueries({queryKey:[`external-links`]}),t()},onError:e=>{T(e.message)}}),D=f({mutationFn:async t=>{let n=await r.updateExternalLink(e.id,t);return S?n=await r.uploadExternalLinkIcon(e.id,S):!v&&e?.custom_icon&&(n=await r.deleteExternalLinkIcon(e.id)),n},onSuccess:()=>{i.invalidateQueries({queryKey:[`external-links`]}),t()},onError:e=>{T(e.message)}}),O=e=>{let t=e.target.files?.[0];if(t){if(![`image/png`,`image/jpeg`,`image/gif`,`image/svg+xml`,`image/webp`,`image/x-icon`].includes(t.type)){T(`Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)`);return}if(t.size>1024*1024){T(`Image file must be less than 1MB`);return}C(t),y(!0);let e=new FileReader;e.onload=e=>{x(e.target?.result)},e.readAsDataURL(t)}},k=()=>{C(null),x(null),y(!1),o.current&&(o.current.value=``)},A=e=>{if(e.preventDefault(),T(null),!s.trim()){T(`Name is required`);return}if(!d.trim()){T(`URL is required`);return}if(!d.startsWith(`http://`)&&!d.startsWith(`https://`)){T(`URL must start with http:// or https://`);return}let t={name:s.trim(),url:d.trim(),icon:m,open_in_new_tab:g};a?D.mutate(t):E.mutate(t)},ee=E.isPending||D.isPending,j=Lt(m);return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:v&&b?(0,Y.jsx)(`img`,{src:b,alt:``,className:`w-5 h-5 rounded`}):(0,Y.jsx)(j,{className:`w-5 h-5`})}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a?`Edit Link`:`Add External Link`})]}),(0,Y.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:A,className:`p-6 space-y-4`,children:[w&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:w}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Name *`}),(0,Y.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`My Link`,maxLength:50,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`URL *`}),(0,Y.jsx)(`input`,{type:`text`,value:d,onChange:e=>p(e.target.value),placeholder:`https://example.com`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`label`,{className:`text-sm text-bambu-gray`,children:n(`externalLinks.openInNewTab`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>_(!g),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${g?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,Y.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${g?`translate-x-6`:`translate-x-1`}`})})]}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray`,children:`Icon`}),(0,Y.jsxs)(`div`,{className:`p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:`Custom Icon`}),(0,Y.jsx)(`input`,{ref:o,type:`file`,accept:`image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon`,className:`hidden`,onChange:O}),v&&b?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`img`,{src:b,alt:`Custom icon`,className:`w-8 h-8 rounded border border-bambu-dark-tertiary`}),(0,Y.jsx)(`button`,{type:`button`,onClick:k,className:`p-1 text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 transition-colors`,title:`Remove custom icon`,children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]}):(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>o.current?.click(),children:[(0,Y.jsx)(Wt,{className:`w-4 h-4`}),`Upload`]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:`PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB.`})]}),!v&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray block mb-2`,children:`Or choose a preset icon`}),(0,Y.jsx)(Bt,{value:m,onChange:h})]})]}),(0,Y.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:`Cancel`}),(0,Y.jsxs)(K,{type:`submit`,disabled:ee,className:`flex-1`,children:[ee?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(_t,{className:`w-4 h-4`}),a?`Save`:`Add`]})]})]})]})})}function hi(){let{t:e}=l(),t=u(),{authEnabled:n,hasPermission:i}=un(),{showToast:a}=ee(),[o,s]=(0,X.useState)(!1),[c,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(jt),[S,C]=(0,X.useState)(()=>Pt(kt.map(e=>e.id))),{data:w,isLoading:T}=d({queryKey:[`external-links`],queryFn:r.getExternalLinks}),E=f({mutationFn:e=>r.deleteExternalLink(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`external-links`]})}}),{data:D}=d({queryKey:[`settings`],queryFn:r.getSettings,enabled:n&&i(`settings:update`)}),O=f({mutationFn:e=>r.updateSettings({default_sidebar_order:e}),onSuccess:(n,r)=>{t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`default-sidebar-order`]}),a(e(r?`settings.sidebarDefaultSet`:`settings.sidebarDefaultCleared`),`success`)},onError:()=>{a(e(`settings.sidebarDefaultFailed`),`error`)}}),k=(0,X.useMemo)(()=>{let e=new Map(kt.map(e=>[e.id,e])),t=new Map((w||[]).map(e=>[`ext-${e.id}`,e])),n=[],r=new Set,i=i=>{if(r.has(i))return;let a=e.get(i);if(a){n.push({type:`system`,id:i,navItem:a}),r.add(i);return}let o=t.get(i);o&&(n.push({type:`external`,id:i,link:o}),r.add(i))};return S.forEach(i),kt.forEach(e=>i(e.id)),(w||[]).forEach(e=>i(`ext-${e.id}`)),n},[w,S]),A=e=>{C(e),qt(e)},j=(e,t)=>{_(t),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t)},te=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`,y(t)},M=(e,t)=>{if(e.preventDefault(),g===null||g===t){_(null),y(null);return}let n=k.map(e=>e.id),r=n.indexOf(g),i=n.indexOf(t);if(r===-1||i===-1){_(null),y(null);return}n.splice(r,1),n.splice(i,0,g),A(n),_(null),y(null)},N=()=>{_(null),y(null)},ne=e=>{h(e)},ie=()=>{m&&(E.mutate(m.id),h(null))},oe=()=>{let e=[...kt.map(e=>e.id),...(w||[]).map(e=>`ext-${e.id}`)];x([]),C(e),Qt([]),qt(e)},P=e=>{let t=k.map(e=>e.id);O.mutate(e?JSON.stringify({order:t,hiddenSystemItemIds:b}):``)},F=e=>{if(e===`settings`)return;let t=b.includes(e)?b.filter(t=>t!==e):[...b,e];x(t),Qt(t)},R=n&&i(`settings:update`),se=!!D?.default_sidebar_order;return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(G,{id:`card-sidebar-links`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-y-2 gap-x-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(I,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`externalLinks.sidebarLayout`)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[R&&(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Y.jsx)(`span`,{children:e(`settings.setDefault`)}),(0,Y.jsx)(J,{checked:se,onChange:P,disabled:O.isPending})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:oe,className:`whitespace-nowrap`,children:[(0,Y.jsx)(nt,{className:`w-4 h-4`}),e(`settings.reset`)]}),(0,Y.jsxs)(K,{size:`sm`,onClick:()=>s(!0),className:`whitespace-nowrap`,children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),`Add Link`]})]})]})}),(0,Y.jsxs)(W,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`externalLinks.sidebarLayoutDescription`)}),T?(0,Y.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,Y.jsx)(L,{className:`w-6 h-6 text-bambu-green animate-spin`})}):(0,Y.jsx)(`div`,{className:`space-y-2`,children:k.map(t=>{let n=t.type===`system`&&b.includes(t.id),i=t.id===`settings`;if(t.type===`system`){let r=t.navItem.icon;return(0,Y.jsxs)(`div`,{draggable:!0,onDragStart:e=>j(e,t.id),onDragOver:e=>te(e,t.id),onDragLeave:()=>y(null),onDrop:e=>M(e,t.id),onDragEnd:N,className:`relative flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${g===t.id?`opacity-50`:n?`opacity-60`:``} ${v===t.id&&g!==t.id?`before:absolute before:left-3 before:right-3 before:top-0 before:h-0.5 before:bg-bambu-green`:``}`,children:[(0,Y.jsx)(ae,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0`}),(0,Y.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray`,children:(0,Y.jsx)(r,{className:`w-4 h-4`})}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`text-white font-medium truncate block`,children:e(t.navItem.labelKey)}),(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray truncate block`,children:e(i?`externalLinks.requiredInSidebar`:n?`externalLinks.hiddenFromSidebar`:`externalLinks.visibleInSidebar`)})]}),(0,Y.jsx)(`button`,{onClick:()=>F(t.id),disabled:i,className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors flex-shrink-0 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-bambu-gray`,title:e(i?`externalLinks.settingsCannotBeHidden`:n?`externalLinks.showPage`:`externalLinks.hidePage`),"aria-label":e(i?`externalLinks.settingsCannotBeHidden`:n?`externalLinks.showPage`:`externalLinks.hidePage`),children:n?(0,Y.jsx)(re,{className:`w-4 h-4`}):(0,Y.jsx)(mt,{className:`w-4 h-4`})})]},t.id)}let a=t.link,o=Lt(a.icon);return(0,Y.jsxs)(`div`,{draggable:!0,onDragStart:e=>j(e,t.id),onDragOver:e=>te(e,t.id),onDragLeave:()=>y(null),onDrop:e=>M(e,t.id),onDragEnd:N,className:`relative flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${g===t.id?`opacity-50`:``} ${v===t.id&&g!==t.id?`before:absolute before:left-3 before:right-3 before:top-0 before:h-0.5 before:bg-bambu-green`:``}`,children:[(0,Y.jsx)(ae,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0`}),(0,Y.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray`,children:a.custom_icon?(0,Y.jsx)(`img`,{src:r.getExternalLinkIconUrl(a.id),alt:``,className:`w-4 h-4`}):(0,Y.jsx)(o,{className:`w-4 h-4`})}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-white font-medium truncate`,children:a.name}),(0,Y.jsx)(Je,{className:`w-3 h-3 text-bambu-gray flex-shrink-0`})]}),(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray truncate block`,children:a.url})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[(0,Y.jsx)(`button`,{onClick:()=>p(a),className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,title:e(`common.edit`),children:(0,Y.jsx)(Ke,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>ne(a),disabled:E.isPending,className:`p-2 rounded-lg hover:bg-red-100 dark:hover:bg-red-500/20 text-bambu-gray hover:text-red-900 dark:hover:text-red-400 transition-colors disabled:opacity-50`,title:e(`externalLinks.deleteLink`),children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]})]},t.id)})})]})]}),(o||c)&&(0,Y.jsx)(mi,{link:c,onClose:()=>{s(!1),p(null)}}),m&&(0,Y.jsx)(Tt,{title:`Delete Link`,message:`Are you sure you want to delete "${m.name}"? This action cannot be undone.`,confirmText:`Delete`,cancelText:`Cancel`,variant:`danger`,onConfirm:ie,onCancel:()=>h(null)})]})}async function gi(e){if(navigator.clipboard&&window.isSecureContext)try{return await navigator.clipboard.writeText(e),!0}catch{}let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{return t.select(),document.execCommand(`copy`)}catch{return!1}finally{t.parentNode&&t.parentNode.removeChild(t)}}function _i(e,t,n=`text/plain`){let r=new Blob([e],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i)}function vi({status:e}){return e===`pass`?(0,Y.jsx)(q,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}):e===`fail`?(0,Y.jsx)(O,{className:`w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0`}):e===`warn`?(0,Y.jsx)(Ie,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 flex-shrink-0`}):(0,Y.jsx)(Ut,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`})}function yi({vpId:e,vpName:t,onClose:n}){let{t:r}=l(),i=f({mutationFn:()=>a.diagnose(e)});(0,X.useEffect)(()=>{i.mutate()},[]),(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let o=i.data,s=o?.overall===`ok`?`bg-bambu-green/10 border-bambu-green/30 text-bambu-green`:o?.overall===`warnings`?`bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-300`:`bg-red-50 dark:bg-red-500/10 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300`;return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg flex flex-col max-h-[85vh]`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,Y.jsx)(et,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:r(`vpDiagnostic.title`,{name:t})})]}),(0,Y.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:r(`common.close`),children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`div`,{className:`p-6 space-y-4 overflow-y-auto`,children:[i.isPending&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}),(0,Y.jsx)(`span`,{children:r(`vpDiagnostic.running`)})]}),i.isError&&(0,Y.jsx)(`div`,{className:`rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 px-4 py-3 text-sm text-red-700 dark:text-red-300`,children:r(`vpDiagnostic.runFailed`,{error:i.error.message})}),o&&(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(`ol`,{className:`space-y-2`,children:o.checks.map(e=>{let t=r(`vpDiagnostic.check.${e.id}.${e.status}`,{...e.params,defaultValue:``});return(0,Y.jsxs)(`li`,{className:`flex items-start gap-3 bg-bambu-dark rounded-lg px-4 py-2.5 ${e.status===`skip`?`opacity-60`:``}`,children:[(0,Y.jsx)(`div`,{className:`mt-0.5`,children:(0,Y.jsx)(vi,{status:e.status})}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-sm text-white`,children:r(`vpDiagnostic.check.${e.id}.title`,e.params)}),t&&(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mt-0.5`,children:t})]})]},e.id)})}),(0,Y.jsx)(`div`,{className:`rounded-lg border px-4 py-3 text-sm ${s}`,children:r(`vpDiagnostic.overall.${o.overall}`)})]})]}),(0,Y.jsxs)(`div`,{className:`px-6 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,Y.jsx)(`button`,{onClick:()=>i.mutate(),disabled:i.isPending,className:`px-4 py-2 bg-bambu-dark hover:bg-bambu-dark-tertiary disabled:opacity-50 text-white text-sm rounded-lg transition-colors`,children:r(`vpDiagnostic.retry`)}),(0,Y.jsx)(`button`,{onClick:n,className:`px-4 py-2 bg-bambu-green hover:bg-bambu-green/90 text-white text-sm rounded-lg transition-colors`,children:r(`common.close`)})]})]})})}var bi={archive:`archive`,review:`review`,queue:`queue`,proxy:`proxy`};function xi(e){return e===`immediate`?`archive`:e===`print_queue`||e===`queue`?`queue`:e===`archive`||e===`review`||e===`proxy`?e:`archive`}function Si({printer:e,models:t}){let{t:n}=l(),i=u(),{showToast:o}=ee(),[s,c]=(0,X.useState)(!0),[p,m]=(0,X.useState)(e.enabled),[h,g]=(0,X.useState)(e.name),[_,v]=(0,X.useState)(``),[y,b]=(0,X.useState)(xi(e.mode)),[x,S]=(0,X.useState)(e.target_printer_id),[C,w]=(0,X.useState)(e.bind_ip||``),[D,O]=(0,X.useState)(e.remote_interface_ip||``),[k,j]=(0,X.useState)(e.model||``),[te,N]=(0,X.useState)(e.auto_dispatch??!0),[ne,ie]=(0,X.useState)(e.queue_force_color_match??!1),[ae,oe]=(0,X.useState)(e.save_ams_mapping??!1),[P,F]=(0,X.useState)(e.gcode_injection??!1),[I,R]=(0,X.useState)(e.tailscale_disabled??!0),[se,ce]=(0,X.useState)(!1),[z,B]=(0,X.useState)(null),[le,V]=(0,X.useState)(!1),[ue,de]=(0,X.useState)(!1),[fe,pe]=(0,X.useState)(!1),{data:me}=d({queryKey:[`tailscale-status`],queryFn:a.getTailscaleStatus,enabled:!I,staleTime:6e4}),he=me?.available?me.fqdn:``,ge=me?.available?me.tailscale_ips?.[0]??``:``,_e=async e=>{e.stopPropagation();let t=he;t&&(await gi(t)?(pe(!0),o(n(`printers.copied`)),setTimeout(()=>pe(!1),2e3)):o(n(`virtualPrinter.toast.copyFailed`),`error`))};(0,X.useEffect)(()=>{z||(m(e.enabled),b(xi(e.mode)),g(e.name),S(e.target_printer_id),w(e.bind_ip||``),O(e.remote_interface_ip||``),j(e.model||``),N(e.auto_dispatch??!0),ie(e.queue_force_color_match??!1),oe(e.save_ams_mapping??!1),F(e.gcode_injection??!1),R(e.tailscale_disabled??!0))},[e,z]);let{data:ve}=d({queryKey:[`printers`],queryFn:r.getPrinters}),{data:ye}=d({queryKey:[`network-interfaces`],queryFn:()=>r.getNetworkInterfaces().then(e=>e.interfaces)}),be=f({mutationFn:t=>a.update(e.id,t),onSuccess:()=>{i.invalidateQueries({queryKey:[`virtual-printers`]}),o(n(`virtualPrinter.toast.updated`)),B(null)},onError:t=>{o(t.message||n(`virtualPrinter.toast.failedToUpdate`),`error`),m(e.enabled),b(xi(e.mode)),S(e.target_printer_id),w(e.bind_ip||``),R(e.tailscale_disabled??!0),ie(e.queue_force_color_match??!1),oe(e.save_ams_mapping??!1),F(e.gcode_injection??!1),B(null)}}),H=f({mutationFn:()=>a.remove(e.id),onSuccess:()=>{i.invalidateQueries({queryKey:[`virtual-printers`]}),o(n(`virtualPrinter.toast.deleted`)),V(!1)},onError:e=>{o(e.message||n(`virtualPrinter.toast.failedToDelete`),`error`),V(!1)}}),xe=t=>{t.stopPropagation();let r=!p;if(r){if(!C){o(n(`virtualPrinter.toast.bindIpRequired`),`error`);return}if(y===`proxy`){if(!x){o(n(`virtualPrinter.toast.targetPrinterRequired`),`error`);return}}else if(!_&&!e.access_code_set){o(n(`virtualPrinter.toast.accessCodeRequired`),`error`);return}}m(r),B(`toggle`),be.mutate({enabled:r})},Se=()=>{h.trim()&&(B(`name`),be.mutate({name:h.trim()}))},Ce=()=>{if(!_){o(n(`virtualPrinter.toast.accessCodeEmpty`),`error`);return}if(_.length!==8){o(n(`virtualPrinter.toast.accessCodeLength`),`error`);return}B(`accessCode`),be.mutate({access_code:_}),v(``)},we=e=>{b(e),B(`mode`),be.mutate({mode:e})},Te=e=>{j(e),B(`model`),be.mutate({model:e})},Ee=e=>{let t=Ae?.access_code,r=ve?.find(t=>t.id===e)?.access_code;S(e),B(`targetPrinter`),be.mutate({target_printer_id:e},{onSuccess:()=>{t&&r&&t!==r&&o(n(`virtualPrinter.toast.targetCodeChangedRebind`),`info`)}})},De=e=>{O(e),B(`remoteInterface`),be.mutate({remote_interface_ip:e})},Oe=e.status?.running||!1,ke=n(`virtualPrinter.mode.${bi[y]||`archive`}`),Ae=ve?.find(e=>e.id===x),je=Ae?.name,Me=!!x,Ne=Me?Ae?.access_code??``:``;return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(G,{className:`overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`px-4 py-3 flex items-center gap-3 cursor-pointer select-none`,onClick:()=>c(!s),children:[(0,Y.jsx)(`button`,{className:`text-bambu-gray flex-shrink-0`,children:s?(0,Y.jsx)(E,{className:`w-4 h-4`}):(0,Y.jsx)(st,{className:`w-4 h-4`})}),(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full flex-shrink-0 ${Oe?`bg-green-400 animate-pulse`:`bg-gray-500`}`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,Y.jsx)(`span`,{className:`text-white font-medium truncate max-w-full`,children:e.name}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0`,children:ke}),e.model_name&&(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0`,children:e.model_name}),je&&(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray truncate max-w-full`,children:[y===`proxy`&&(0,Y.jsx)(_n,{className:`w-3 h-3 inline mr-1`}),je]}),C&&(0,Y.jsx)(`span`,{className:`text-[10px] text-bambu-gray flex-shrink-0 font-mono`,children:C}),D&&(0,Y.jsx)(`span`,{className:`text-[10px] text-bambu-gray flex-shrink-0 font-mono`,children:D})]}),(0,Y.jsx)(`div`,{className:`ml-auto flex items-center gap-2 flex-shrink-0`,onClick:e=>e.stopPropagation(),children:(0,Y.jsx)(`button`,{onClick:xe,disabled:z===`toggle`,className:`relative w-10 h-5 rounded-full transition-colors ${p?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${z===`toggle`?`opacity-50`:``}`,children:(0,Y.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${p?`translate-x-5`:``}`})})})]}),s&&(0,Y.jsxs)(W,{className:`pt-0 space-y-4`,children:[(0,Y.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`input`,{type:`text`,value:h,onChange:e=>g(e.target.value),onBlur:Se,onKeyDown:e=>e.key===`Enter`&&Se(),className:`flex-1 text-sm text-white bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`button`,{onClick:()=>de(!0),className:`p-1.5 text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:n(`vpDiagnostic.runButton`),children:(0,Y.jsx)(et,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>V(!0),className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors flex-shrink-0`,title:n(`common.delete`),children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 -mt-2`,children:[he&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700/80 dark:text-green-400/70 min-w-0`,children:[(0,Y.jsx)(Cn,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,Y.jsx)(`span`,{className:`font-mono text-xs truncate`,children:ge?`${ge} (${he})`:he}),(0,Y.jsx)(`button`,{onClick:_e,className:`p-0.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors flex-shrink-0`,title:n(fe?`printers.copied`:`printers.copyToClipboard`),children:fe?(0,Y.jsx)(T,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,Y.jsx)(M,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray font-mono ml-auto flex-shrink-0`,children:e.serial})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium mb-2`,children:n(`virtualPrinter.mode.title`)}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:[`archive`,`review`,`queue`,`proxy`].map(e=>(0,Y.jsxs)(`button`,{onClick:()=>we(e),disabled:z===`mode`,className:`p-2 rounded-lg border text-left transition-colors ${y===e?e===`proxy`?`border-blue-500 bg-blue-500/10`:`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-white text-xs font-medium`,children:[e===`proxy`&&(0,Y.jsx)(_n,{className:`w-3 h-3`}),n(`virtualPrinter.mode.${bi[e]}`)]}),(0,Y.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.mode.${bi[e]}Desc`)})]},e))})]}),y===`queue`&&(0,Y.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.autoDispatch.title`)}),(0,Y.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.autoDispatch.description`)})]}),(0,Y.jsx)(`button`,{onClick:()=>{let e=!te;N(e),B(`autoDispatch`),be.mutate({auto_dispatch:e})},disabled:z===`autoDispatch`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${te?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${z===`autoDispatch`?`opacity-50`:``}`,children:(0,Y.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${te?`translate-x-5`:``}`})})]})}),y===`queue`&&(0,Y.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.queueForceColorMatch.title`)}),(0,Y.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.queueForceColorMatch.description`)})]}),(0,Y.jsx)(`button`,{onClick:()=>{let e=!ne;ie(e),B(`queueForceColorMatch`),be.mutate({queue_force_color_match:e})},disabled:z===`queueForceColorMatch`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${ne?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${z===`queueForceColorMatch`?`opacity-50`:``}`,children:(0,Y.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${ne?`translate-x-5`:``}`})})]})}),y===`queue`&&(0,Y.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.saveAmsMapping.title`)}),(0,Y.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.saveAmsMapping.description`)})]}),(0,Y.jsx)(`button`,{onClick:()=>{let e=!ae;oe(e),B(`saveAmsMapping`),be.mutate({save_ams_mapping:e})},disabled:z===`saveAmsMapping`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${ae?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${z===`saveAmsMapping`?`opacity-50`:``}`,children:(0,Y.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${ae?`translate-x-5`:``}`})})]})}),y===`queue`&&(0,Y.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.gcodeInjection.title`)}),(0,Y.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.gcodeInjection.description`)})]}),(0,Y.jsx)(`button`,{onClick:()=>{let e=!P;F(e),B(`gcodeInjection`),be.mutate({gcode_injection:e})},disabled:z===`gcodeInjection`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${P?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${z===`gcodeInjection`?`opacity-50`:``}`,children:(0,Y.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${P?`translate-x-5`:``}`})})]})}),(0,Y.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.tailscaleDisabled.title`)}),(0,Y.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.tailscaleDisabled.description`)})]}),(0,Y.jsx)(`button`,{onClick:()=>{let e=!I;R(e),B(`tailscaleDisabled`),be.mutate({tailscale_disabled:e})},disabled:z===`tailscaleDisabled`,className:`relative w-10 h-5 rounded-full transition-colors shrink-0 ${I?`bg-bambu-dark-tertiary`:`bg-bambu-green`} ${z===`tailscaleDisabled`?`opacity-50`:``}`,children:(0,Y.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${I?``:`translate-x-5`}`})})]})}),y!==`proxy`&&(0,Y.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium mb-1`,children:n(`virtualPrinter.model.title`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`virtualPrinter.model.description`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`select`,{value:k,onChange:e=>Te(e.target.value),disabled:z===`model`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:Object.entries(t).map(([e,t])=>(0,Y.jsxs)(`option`,{value:e,children:[t,` (`,e,`)`]},e))}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),y===`proxy`&&(0,Y.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 p-2 rounded bg-blue-50 border border-blue-300 dark:bg-blue-500/10 dark:border-blue-500/30`,children:[(0,Y.jsx)(A,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0 mt-0.5`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`virtualPrinter.proxy.accessCodeHint`)})]})}),y!==`proxy`&&(0,Y.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.accessCode.title`)}),Me?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-blue-700 dark:text-blue-400`,children:[(0,Y.jsx)(A,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.inheritedFromTarget`)]}):e.access_code_set?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-green-700 dark:text-green-400`,children:[(0,Y.jsx)(T,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.isSet`)]}):(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-yellow-700 dark:text-yellow-400`,children:[(0,Y.jsx)(Ie,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.notSet`)]})]}),Me?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`input`,{type:se?`text`:`password`,value:Ne,readOnly:!0,"aria-label":n(`virtualPrinter.accessCode.title`),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm pr-10 font-mono opacity-90 cursor-default`}),(0,Y.jsx)(`button`,{onClick:()=>ce(!se),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,"aria-label":n(se?`virtualPrinter.accessCode.hide`:`virtualPrinter.accessCode.reveal`),children:se?(0,Y.jsx)(re,{className:`w-4 h-4`}):(0,Y.jsx)(mt,{className:`w-4 h-4`})})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`virtualPrinter.accessCode.derivedFromTargetHint`)})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Y.jsx)(`input`,{type:se?`text`:`password`,value:_,onChange:e=>v(e.target.value),placeholder:e.access_code_set?n(`virtualPrinter.accessCode.placeholderChange`):n(`virtualPrinter.accessCode.placeholder`),maxLength:8,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm placeholder-bambu-gray pr-10 font-mono`}),(0,Y.jsx)(`button`,{onClick:()=>ce(!se),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:se?(0,Y.jsx)(re,{className:`w-4 h-4`}):(0,Y.jsx)(mt,{className:`w-4 h-4`})})]}),(0,Y.jsx)(K,{onClick:Ce,disabled:!_||z===`accessCode`,variant:`primary`,children:z===`accessCode`?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]}),_&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:(0,Y.jsx)(`span`,{className:_.length===8?`text-green-700 dark:text-green-400`:`text-yellow-700 dark:text-yellow-400`,children:n(`virtualPrinter.accessCode.charCount`,{count:_.length})})})]})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium mb-2`,children:n(`virtualPrinter.targetPrinter.title`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsxs)(`select`,{value:x??``,onChange:e=>{let t=parseInt(e.target.value,10);isNaN(t)||Ee(t)},disabled:z===`targetPrinter`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`virtualPrinter.targetPrinter.placeholder`)}),ve?.map(e=>(0,Y.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.ip_address,`)`]},e.id))]}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium mb-1`,children:n(`virtualPrinter.bindIp.title`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsxs)(`select`,{value:C,onChange:e=>{w(e.target.value),B(`bindIp`),be.mutate({bind_ip:e.target.value})},disabled:z===`bindIp`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`virtualPrinter.bindIp.placeholder`)}),ye?.map(e=>(0,Y.jsxs)(`option`,{value:e.ip,children:[e.name,` (`,e.ip,`)`,e.is_alias?` [alias]`:``,` - `,e.subnet]},e.ip))]}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`virtualPrinter.bindIp.hint`)})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.remoteInterface.title`)}),D?(0,Y.jsx)(`span`,{className:`flex items-center gap-1 text-xs text-green-700 dark:text-green-400`,children:(0,Y.jsx)(T,{className:`w-3 h-3`})}):(0,Y.jsx)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray`,title:n(`virtualPrinter.remoteInterface.optional`),children:(0,Y.jsx)(A,{className:`w-3 h-3`})})]}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsxs)(`select`,{value:D,onChange:e=>De(e.target.value),disabled:z===`remoteInterface`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`virtualPrinter.remoteInterface.placeholder`)}),ye?.map(e=>(0,Y.jsxs)(`option`,{value:e.ip,children:[e.name,` (`,e.ip,`) - `,e.subnet]},e.ip))]}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]})]})]}),le&&(0,Y.jsx)(Tt,{title:n(`virtualPrinter.deleteConfirm.title`),message:n(`virtualPrinter.deleteConfirm.message`,{name:e.name}),variant:`danger`,confirmText:n(`common.delete`),isLoading:H.isPending,onConfirm:()=>H.mutate(),onCancel:()=>V(!1)}),ue&&(0,Y.jsx)(yi,{vpId:e.id,vpName:e.name,onClose:()=>de(!1)})]})}var Ci={archive:`archive`,review:`review`,queue:`queue`,proxy:`proxy`};function wi({onClose:e}){let{t}=l(),n=u(),{showToast:i}=ee(),[o,s]=(0,X.useState)(``),[c,p]=(0,X.useState)(`archive`),[m,h]=(0,X.useState)(null),{data:g}=d({queryKey:[`printers`],queryFn:r.getPrinters}),_=f({mutationFn:()=>a.create({name:o.trim()||`Bambuddy`,mode:c,target_printer_id:c===`proxy`?m??void 0:void 0}),onSuccess:()=>{n.invalidateQueries({queryKey:[`virtual-printers`]}),i(t(`virtualPrinter.toast.created`)),e()},onError:e=>{i(e.message||t(`virtualPrinter.toast.failedToCreate`),`error`)}});return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:e,children:(0,Y.jsx)(G,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,Y.jsxs)(W,{className:`p-6 space-y-4`,children:[(0,Y.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:t(`virtualPrinter.addDialog.title`)}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.addDialog.name`)}),(0,Y.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`Bambuddy`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm placeholder-bambu-gray`,autoFocus:!0})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.mode.title`)}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:[`archive`,`review`,`queue`,`proxy`].map(e=>(0,Y.jsxs)(`button`,{onClick:()=>p(e),className:`p-2 rounded-lg border text-left transition-colors ${c===e?e===`proxy`?`border-blue-500 bg-blue-500/10`:`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-white text-xs font-medium`,children:[e===`proxy`&&(0,Y.jsx)(_n,{className:`w-3 h-3`}),t(`virtualPrinter.mode.${Ci[e]}`)]}),(0,Y.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:t(`virtualPrinter.mode.${Ci[e]}Desc`)})]},e))})]}),c===`proxy`&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.targetPrinter.title`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsxs)(`select`,{value:m??``,onChange:e=>{let t=parseInt(e.target.value,10);h(isNaN(t)?null:t)},className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm appearance-none cursor-pointer pr-10`,children:[(0,Y.jsx)(`option`,{value:``,children:t(`virtualPrinter.targetPrinter.placeholder`)}),g?.map(e=>(0,Y.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.ip_address,`)`]},e.id))]}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`virtualPrinter.addDialog.hint`)}),(0,Y.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:e,className:`flex-1`,disabled:_.isPending,children:t(`common.cancel`)}),(0,Y.jsx)(K,{variant:`primary`,onClick:()=>_.mutate(),className:`flex-1`,disabled:_.isPending,children:_.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):t(`virtualPrinter.addDialog.create`)})]})]})})})}function Ti(){let{t:e}=l(),t=u(),{showToast:n}=ee(),[r,o]=(0,X.useState)(!1),{data:s,isLoading:c}=d({queryKey:[`virtual-printers`],queryFn:a.list,refetchInterval:1e4}),{data:p}=d({queryKey:[`virtual-printer-settings`],queryFn:i.getSettings}),m=f({mutationFn:e=>i.updateSettings({archive_name_source:e}),onSuccess:()=>{t.invalidateQueries({queryKey:[`virtual-printer-settings`]}),n(e(`virtualPrinter.toast.updated`))},onError:t=>{n(t.message||e(`virtualPrinter.toast.failedToUpdate`),`error`)}}),h=p?.archive_name_source===`filename`,{data:g}=d({queryKey:[`vp-ca-certificate`],queryFn:a.getCaCertificate,staleTime:1/0}),[_,v]=(0,X.useState)(!1),y=async()=>{g&&(await gi(g.pem)?(v(!0),n(e(`virtualPrinter.caCert.copied`)),setTimeout(()=>v(!1),2e3)):n(e(`virtualPrinter.toast.copyFailed`),`error`))},b=()=>{g&&_i(g.pem,`bambuddy-virtual-printer-ca.crt`,`application/x-pem-file`)};if(c)return(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-8 flex justify-center`,children:(0,Y.jsx)(L,{className:`w-6 h-6 animate-spin text-bambu-green`})})});let x=s?.printers||[],S=s?.models||{};return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4 items-stretch`,children:[(0,Y.jsx)(G,{className:`border-l-4 border-l-yellow-500`,children:(0,Y.jsx)(W,{className:`py-3 px-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(Ie,{className:`w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{className:`text-xs`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium`,children:e(`virtualPrinter.setupRequired.title`)}),(0,Y.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`virtualPrinter.setupRequired.description`)}),(0,Y.jsxs)(`a`,{href:`https://wiki.bambuddy.cool/features/virtual-printer/`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1.5 mt-2 px-3 py-1.5 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-500/50 rounded text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/30 transition-colors text-xs`,children:[(0,Y.jsx)(Je,{className:`w-3 h-3`}),e(`virtualPrinter.setupRequired.readGuide`)]})]})]})})}),(0,Y.jsx)(G,{className:`lg:col-span-2`,children:(0,Y.jsx)(W,{className:`py-3 px-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(A,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`virtualPrinter.howItWorks.title`)}),(0,Y.jsxs)(`ul`,{className:`space-y-1 list-disc list-inside`,children:[(0,Y.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step1`)}),(0,Y.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step2`)}),(0,Y.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step3`)})]})]})]})})})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4 items-stretch`,children:[(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-3 px-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(Cn,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-1`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`virtualPrinter.caCert.title`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,Y.jsxs)(`button`,{onClick:y,disabled:!g,className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded bg-bambu-dark-secondary border border-bambu-dark-tertiary text-white hover:border-bambu-gray disabled:opacity-50 transition-colors`,children:[_?(0,Y.jsx)(T,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,Y.jsx)(M,{className:`w-3.5 h-3.5`}),e(_?`virtualPrinter.caCert.copied`:`virtualPrinter.caCert.copy`)]}),(0,Y.jsxs)(`button`,{onClick:b,disabled:!g,className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded bg-bambu-dark-secondary border border-bambu-dark-tertiary text-white hover:border-bambu-gray disabled:opacity-50 transition-colors`,children:[(0,Y.jsx)(sn,{className:`w-3.5 h-3.5`}),e(`virtualPrinter.caCert.download`)]})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`virtualPrinter.caCert.description`)}),g&&(0,Y.jsxs)(`p`,{className:`text-[10px] text-bambu-gray font-mono mt-1 truncate`,title:g.fingerprint_sha256,children:[e(`virtualPrinter.caCert.fingerprint`),`: `,g.fingerprint_sha256]})]})]})})}),(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-3 px-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(ln,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-1`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`virtualPrinter.archiveNameSource.title`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,Y.jsx)(`span`,{className:`text-xs ${h?`text-bambu-gray`:`text-white`}`,children:e(`virtualPrinter.archiveNameSource.metadata`)}),(0,Y.jsx)(J,{checked:h,onChange:e=>m.mutate(e?`filename`:`metadata`),disabled:m.isPending}),(0,Y.jsx)(`span`,{className:`text-xs ${h?`text-white`:`text-bambu-gray`}`,children:e(`virtualPrinter.archiveNameSource.filename`)})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`virtualPrinter.archiveNameSource.description`)})]})]})})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(it,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`virtualPrinter.list.title`)}),(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,x.length,`)`]})]}),(0,Y.jsxs)(K,{variant:`primary`,onClick:()=>o(!0),children:[(0,Y.jsx)(wt,{className:`w-4 h-4 mr-1`}),e(`virtualPrinter.list.add`)]})]}),x.length===0?(0,Y.jsx)(G,{children:(0,Y.jsxs)(W,{className:`py-8 text-center`,children:[(0,Y.jsx)(it,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3`}),(0,Y.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`virtualPrinter.list.empty`)}),(0,Y.jsxs)(K,{variant:`primary`,onClick:()=>o(!0),children:[(0,Y.jsx)(wt,{className:`w-4 h-4 mr-1`}),e(`virtualPrinter.list.addFirst`)]})]})}):(0,Y.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 items-start`,children:x.map(e=>(0,Y.jsx)(Si,{printer:e,models:S},e.id))}),r&&(0,Y.jsx)(wi,{onClose:()=>o(!1)})]})}function Ei(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60),r=t%60;if(n<24)return r?`${n}h ${r}m`:`${n}h`;let i=Math.floor(n/24),a=n%24;return a?`${i}d ${a}h`:`${i}d`}function Di(e){return e==null?`—`:e>=1024?`${(e/1024).toFixed(1)} GB`:`${Math.round(e)} MB`}function Oi({device:e,onUnregister:t,isDeleting:n}){let{t:r}=l(),{showToast:i}=ee(),a=e.system_stats,o=a?.memory,s=a?.disk,u=e.online,[d,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(null),h=async t=>{m(t);try{t===`update`?await c.triggerUpdate(e.device_id):await c.systemCommand(e.device_id,t),i(r(`settings.spoolbuddy.commandQueued`),`success`)}catch(e){i(e instanceof Error?e.message:r(`settings.spoolbuddy.commandError`),`error`)}finally{m(null),f(null)}},g=[{key:`update`,label:r(`settings.spoolbuddy.update`),icon:sn},{key:`restart_browser`,label:r(`settings.spoolbuddy.restartBrowser`),icon:tn},{key:`restart_daemon`,label:r(`settings.spoolbuddy.restartDaemon`),icon:at},{key:`reboot`,label:r(`settings.spoolbuddy.reboot`),icon:xt},{key:`shutdown`,label:r(`settings.spoolbuddy.shutdown`),icon:Ct,variant:`danger`}],_={update:r(`settings.spoolbuddy.updateConfirmTitle`),restart_browser:r(`settings.spoolbuddy.restartBrowserConfirmTitle`),restart_daemon:r(`settings.spoolbuddy.restartDaemonConfirmTitle`),reboot:r(`settings.spoolbuddy.rebootConfirmTitle`),shutdown:r(`settings.spoolbuddy.shutdownConfirmTitle`)},v={update:r(`settings.spoolbuddy.updateConfirmBody`,{hostname:e.hostname}),restart_browser:r(`settings.spoolbuddy.restartBrowserConfirmBody`,{hostname:e.hostname}),restart_daemon:r(`settings.spoolbuddy.restartDaemonConfirmBody`,{hostname:e.hostname}),reboot:r(`settings.spoolbuddy.rebootConfirmBody`,{hostname:e.hostname}),shutdown:r(`settings.spoolbuddy.shutdownConfirmBody`,{hostname:e.hostname})};return(0,Y.jsxs)(G,{children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3 flex-wrap`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`h3`,{className:`text-base font-semibold text-white truncate`,children:e.hostname}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${u?`bg-green-500/15 text-green-400 border border-green-500/40`:`bg-gray-500/15 text-gray-400 border border-gray-500/40`}`,children:[u?(0,Y.jsx)(ht,{className:`w-3 h-3`}):(0,Y.jsx)(Ye,{className:`w-3 h-3`}),r(u?`settings.spoolbuddy.online`:`settings.spoolbuddy.offline`)]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray font-mono mt-1 truncate`,children:e.device_id})]}),(0,Y.jsxs)(K,{variant:`danger`,size:`sm`,onClick:()=>t(e),disabled:n,"aria-label":r(`settings.spoolbuddy.unregister`),children:[(0,Y.jsx)(qe,{className:`w-3.5 h-3.5`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:r(`settings.spoolbuddy.unregister`)})]})]})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3 text-xs`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.ipAddress`)}),(0,Y.jsx)(`div`,{className:`text-white font-mono`,children:e.ip_address})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.firmware`)}),(0,Y.jsx)(`div`,{className:`text-white`,children:e.firmware_version??`—`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`text-bambu-gray flex items-center gap-1`,children:[(0,Y.jsx)(lt,{className:`w-3 h-3`}),r(`settings.spoolbuddy.lastSeen`)]}),(0,Y.jsx)(`div`,{className:`text-white`,children:e.last_seen?Ue(e.last_seen):r(`settings.spoolbuddy.never`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.daemonUptime`)}),(0,Y.jsx)(`div`,{className:`text-white`,children:Ei(e.uptime_s)})]})]}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:g.map(({key:e,label:t,icon:n,variant:r})=>(0,Y.jsxs)(K,{variant:r??`secondary`,size:`sm`,onClick:()=>f(e),disabled:!u||p!==null,"aria-label":t,children:[p===e?(0,Y.jsx)(L,{className:`w-3.5 h-3.5 animate-spin`}):(0,Y.jsx)(n,{className:`w-3.5 h-3.5`}),(0,Y.jsx)(`span`,{children:t})]},e))}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 text-xs flex-wrap`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[e.nfc_ok?(0,Y.jsx)(q,{className:`w-3.5 h-3.5 text-green-400`}):(0,Y.jsx)(O,{className:`w-3.5 h-3.5 text-red-400`}),r(`settings.spoolbuddy.nfc`),e.nfc_reader_type&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[`(`,e.nfc_reader_type,`)`]})]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[e.scale_ok?(0,Y.jsx)(q,{className:`w-3.5 h-3.5 text-green-400`}):(0,Y.jsx)(O,{className:`w-3.5 h-3.5 text-red-400`}),r(`settings.spoolbuddy.scale`)]})]}),a&&(0,Y.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3 text-xs`,children:[a.cpu_temp_c!==void 0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Fe,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.cpuTemp`)}),(0,Y.jsxs)(`div`,{className:`text-white`,children:[a.cpu_temp_c.toFixed(1),`°C`]})]})]}),a.load_avg&&a.load_avg.length>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(S,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.cpuLoad`)}),(0,Y.jsxs)(`div`,{className:`text-white`,children:[a.load_avg[0].toFixed(2),a.cpu_count?` / ${a.cpu_count} (${Math.round(a.load_avg[0]/a.cpu_count*100)}%)`:``]})]})]}),o&&o.percent!==void 0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(N,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.memory`)}),(0,Y.jsxs)(`div`,{className:`text-white`,children:[o.percent.toFixed(0),`% (`,Di(o.used_mb),` / `,Di(o.total_mb),`)`]})]})]}),s&&s.percent!==void 0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(oe,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.disk`)}),(0,Y.jsxs)(`div`,{className:`text-white`,children:[s.percent.toFixed(0),`% (`,s.used_gb?.toFixed(1),` / `,s.total_gb?.toFixed(1),` GB)`]})]})]}),a.system_uptime_s!==void 0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(lt,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.systemUptime`)}),(0,Y.jsx)(`div`,{className:`text-white`,children:Ei(a.system_uptime_s)})]})]})]}),a.os&&(0,Y.jsx)(`div`,{className:`mt-3 text-xs text-bambu-gray font-mono truncate`,children:[a.os.os,a.os.kernel,a.os.arch,a.os.python&&`Python ${a.os.python}`].filter(Boolean).join(` · `)})]})]}),d&&(0,Y.jsx)(Tt,{variant:d===`shutdown`||d===`reboot`?`danger`:`default`,title:_[d],message:v[d],confirmText:r(`settings.spoolbuddy.commandConfirm`),isLoading:p!==null,onConfirm:()=>h(d),onCancel:()=>f(null)})]})}function ki(){let{t:e}=l(),t=u(),{showToast:n}=ee(),[r,i]=(0,X.useState)(null),{data:a=[],isLoading:o}=d({queryKey:[`spoolbuddy-devices`],queryFn:()=>c.getDevices(),refetchInterval:15e3}),s=f({mutationFn:e=>c.deleteDevice(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`spoolbuddy-devices`]}),n(e(`settings.spoolbuddy.unregisterSuccess`),`success`),i(null)},onError:t=>{n(t.message||e(`settings.spoolbuddy.unregisterError`),`error`)}});if(o)return(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-8 flex justify-center`,children:(0,Y.jsx)(L,{className:`w-6 h-6 animate-spin text-bambu-green`})})});let p=a.length>1;return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-3 px-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-xs`,children:[(0,Y.jsx)(A,{className:`w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`settings.spoolbuddy.infoTitle`)}),(0,Y.jsx)(`p`,{children:e(`settings.spoolbuddy.infoBody`)})]})]})})}),p&&(0,Y.jsx)(G,{className:`border-l-4 border-l-yellow-500`,children:(0,Y.jsx)(W,{className:`py-3 px-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-xs`,children:[(0,Y.jsx)(Ie,{className:`w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`settings.spoolbuddy.duplicatesTitle`,{count:a.length})}),(0,Y.jsx)(`p`,{children:e(`settings.spoolbuddy.duplicatesBody`)})]})]})})}),a.length===0?(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-8 text-center text-bambu-gray text-sm`,children:e(`settings.spoolbuddy.empty`)})}):(0,Y.jsx)(`div`,{className:`space-y-3`,children:a.map(e=>(0,Y.jsx)(Oi,{device:e,onUnregister:i,isDeleting:s.isPending&&s.variables===e.device_id},e.id))}),r&&(0,Y.jsx)(Tt,{variant:`danger`,title:e(`settings.spoolbuddy.confirmTitle`),message:e(`settings.spoolbuddy.confirmBody`,{hostname:r.hostname,deviceId:r.device_id}),confirmText:e(`settings.spoolbuddy.unregister`),isLoading:s.isPending,onConfirm:()=>s.mutate(r.device_id),onCancel:()=>i(null)})]})}function Ai(e,t,n,r,i){return n?e(`backup.restoreFromGit.${t}.${n}`,{...r??{},defaultValue:i??n}):i}var ji=[{id:`archives`,labelKey:`backup.printArchives`,icon:(0,Y.jsx)(ot,{className:`w-4 h-4`})},{id:`spools`,labelKey:`backup.spoolInventory`,icon:(0,Y.jsx)(Nt,{className:`w-4 h-4`})},{id:`settings`,labelKey:`backup.appSettings`,icon:(0,Y.jsx)(yt,{className:`w-4 h-4`})},{id:`kprofiles`,labelKey:`backup.kProfiles`,icon:(0,Y.jsx)(Fe,{className:`w-4 h-4`})}],Mi=Object.fromEntries(ji.map(e=>[e.id,e.labelKey])),Ni=`HEAD`;function Pi({onClose:e}){let{t}=l(),n=u(),[i,a]=(0,X.useState)(Ni),[o,s]=(0,X.useState)({}),[c,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(null),v=d({queryKey:[`github-backup-commits`],queryFn:()=>r.getGitHubBackupCommits(20)}),y=d({queryKey:[`github-restore-preview`,i],queryFn:()=>r.getGitHubRestorePreview(i)}),b=y.data?.success?y.data.ref:i,x=(0,X.useMemo)(()=>{let e={};return y.data?.categories?.forEach(n=>{e[n.category]={available:n.available,itemCount:n.item_count,detail:Ai(t,`details`,n.detail_code,n.detail_params,n.detail)}}),e},[y.data,t]),S=(0,X.useMemo)(()=>ji.filter(e=>o[e.id]&&x[e.id]?.available).map(e=>e.id),[o,x]),C=S.length,w=!c&&S.includes(`kprofiles`),T=f({mutationFn:()=>r.restoreFromGitHub({ref:b,categories:S,overwrite_existing:c}),onSuccess:e=>{h(!1);let t=Object.keys(e.results??{}).length>0;(e.success||t)&&(_(e),n.invalidateQueries({queryKey:[`spools`]}),n.invalidateQueries({queryKey:[`archives`]}),n.invalidateQueries({queryKey:[`settings`]})),n.invalidateQueries({queryKey:[`github-backup-logs`]}),n.invalidateQueries({queryKey:[`github-backup-status`]})},onError:()=>h(!1)}),E=T.isPending,D=!!(g&&`settings`in g.results),O=(0,X.useCallback)(()=>{if(D){window.location.reload();return}e()},[D,e]);(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!E&&!m&&O()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[O,E,m]),(0,X.useEffect)(()=>{if(!E)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[E]),(0,X.useEffect)(()=>{y.data&&s(e=>{let t={};return ji.forEach(n=>{t[n.id]=!!e[n.id]&&!!x[n.id]?.available}),t})},[y.data,x]);let k=v.data?.commits??[],ee=(e,t,n)=>{let r=(t||``).split(`
  3. `)[0],i=n?new Date(n).toLocaleString():``;return`${e.slice(0,7)} — ${i}${r?` — ${r}`:``}`},j=e=>e.isError?e.error?.message||t(`backup.restoreFromGit.loadFailed`):null,te=j(y)??(y.data&&!y.data.success?y.data.message:null),M=j(v)??(v.data&&!v.data.success?v.data.message:null);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:E?void 0:O,children:(0,Y.jsx)(G,{className:`w-full max-w-lg`,onClick:e=>e.stopPropagation(),children:(0,Y.jsxs)(W,{className:`p-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,Y.jsx)(nt,{className:`w-5 h-5`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:t(`backup.restoreFromGit.title`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t(`backup.restoreFromGit.subtitle`)})]})]}),(0,Y.jsx)(`button`,{onClick:O,disabled:E,"aria-label":t(`common.close`),className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors disabled:opacity-50`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),g?(0,Y.jsxs)(`div`,{className:`p-4 space-y-3 max-h-[400px] overflow-y-auto`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[g.success?(0,Y.jsx)(q,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}):(0,Y.jsx)(Ie,{className:`w-4 h-4 text-yellow-500 mt-0.5 flex-shrink-0`}),(0,Y.jsx)(`span`,{className:`text-white`,children:g.message})]}),!g.success&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`backup.restoreFromGit.partialHint`)}),Object.entries(g.results).map(([e,n])=>(0,Y.jsxs)(`div`,{className:`p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium text-white`,children:Mi[e]?t(Mi[e]):e}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t(`backup.restoreFromGit.tally`,{restored:n.restored,skipped:n.skipped,failed:n.failed})})]}),n.notes.length>0&&(0,Y.jsx)(`ul`,{className:`mt-2 space-y-1`,children:n.notes.map(e=>(0,Y.jsxs)(`li`,{className:`text-xs text-bambu-gray flex items-start gap-1.5`,children:[(0,Y.jsx)(A,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,Y.jsx)(`span`,{children:Ai(t,`notes`,e.code,e.params,e.message)})]},`${e.code}:${JSON.stringify(e.params)}`))})]},e)),(0,Y.jsx)(`div`,{className:`p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,Y.jsx)(`p`,{className:`text-xs text-yellow-700 dark:text-yellow-200`,children:t(`backup.restoreFromGit.reloadHint`)})})]}):(0,Y.jsxs)(`div`,{className:`p-4 space-y-4 max-h-[400px] overflow-y-auto ${E?`opacity-50 pointer-events-none`:``}`,children:[T.isError&&(0,Y.jsx)(`div`,{className:`p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,Y.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:T.error?.message||t(`backup.restoreFromGit.failed`)})}),T.data&&!T.data.success&&(0,Y.jsx)(`div`,{className:`p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,Y.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:T.data.message})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`restore-commit`,className:`block text-sm font-medium text-white mb-1`,children:t(`backup.restoreFromGit.commitLabel`)}),(0,Y.jsxs)(`select`,{id:`restore-commit`,value:i,onChange:e=>{a(e.target.value),T.reset()},disabled:E||v.isLoading,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,children:[(0,Y.jsx)(`option`,{value:Ni,children:t(`backup.restoreFromGit.latestCommit`)}),k.map(e=>(0,Y.jsx)(`option`,{value:e.sha,children:ee(e.sha,e.message,e.date)},e.sha))]}),M&&(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-500 dark:text-red-400`,children:M})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-white mb-2`,children:t(`backup.restoreFromGit.categoriesLabel`)}),y.isLoading?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray p-3`,children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}),t(`backup.restoreFromGit.inspecting`)]}):te?(0,Y.jsx)(`div`,{className:`p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,Y.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:te})}):(0,Y.jsx)(`div`,{className:`space-y-2`,children:ji.map(e=>{let n=x[e.id],r=!!n?.available,i=!!o[e.id]&&r;return(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 p-3 rounded-lg transition-colors ${r?`cursor-pointer`:`cursor-not-allowed opacity-50`} ${i?`bg-bambu-green/10 border border-bambu-green/30`:`bg-bambu-dark hover:bg-bambu-dark-tertiary border border-transparent`}`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:i,disabled:!r||E,onChange:()=>s(t=>({...t,[e.id]:!t[e.id]})),className:`w-4 h-4 rounded border-bambu-gray bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0`}),(0,Y.jsx)(`div`,{className:i?`text-bambu-green`:`text-bambu-gray`,children:e.icon}),(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsxs)(`div`,{className:`text-white text-sm font-medium`,children:[t(e.labelKey),r&&n?.itemCount?(0,Y.jsx)(`span`,{className:`ml-2 text-xs text-bambu-gray`,children:t(`backup.restoreFromGit.itemCount`,{count:n.itemCount})}):null]}),n?.detail&&(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:n.detail}),e.id===`kprofiles`&&i&&w&&(0,Y.jsx)(`div`,{className:`text-xs text-yellow-700 dark:text-yellow-200`,children:t(`backup.restoreFromGit.kprofilesOverwriteCaveat`)})]})]},e.id)})})]}),(0,Y.jsx)(`div`,{className:`p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-white`,children:t(`backup.restoreFromGit.overwriteLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(c?`backup.restoreFromGit.overwriteOn`:`backup.restoreFromGit.overwriteOff`)})]}),(0,Y.jsx)(J,{checked:c,onChange:p,disabled:E})]})})]}),(0,Y.jsx)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary`,children:g?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{}),(0,Y.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:O,children:t(`common.close`)}),(0,Y.jsx)(K,{onClick:()=>window.location.reload(),className:`bg-bambu-green hover:bg-bambu-green-dark`,children:t(`backup.reloadNow`)})]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:t(`backup.restoreFromGit.selectedCount`,{count:C})}),(0,Y.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:O,disabled:E,children:t(`common.cancel`)}),(0,Y.jsx)(K,{onClick:()=>h(!0),disabled:C===0||E,className:`bg-bambu-green hover:bg-bambu-green-dark disabled:opacity-50 disabled:cursor-not-allowed min-w-[100px]`,children:E?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(L,{className:`w-4 h-4 mr-2 animate-spin`}),t(`backup.restoreFromGit.restoring`)]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(nt,{className:`w-4 h-4 mr-2`}),t(`backup.restore`)]})})]})]})})]})})}),m&&(0,Y.jsx)(Tt,{variant:`danger`,overlayZIndex:`z-[110]`,title:t(`backup.restoreFromGit.confirmTitle`),message:c?t(`backup.restoreFromGit.confirmMessageOverwrite`):w?`${t(`backup.restoreFromGit.confirmMessage`)} ${t(`backup.restoreFromGit.kprofilesOverwriteCaveat`)}`:t(`backup.restoreFromGit.confirmMessage`),confirmText:t(`backup.restore`),isLoading:E,loadingText:t(`backup.restoreFromGit.restoring`),onConfirm:()=>T.mutate(),onCancel:()=>h(!1)})]})}function Fi(e){if(!e)return`-`;let t=We(e);return t?t.toLocaleString():`-`}function Ii({status:e}){if(!e)return null;let t={success:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,failed:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`,skipped:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,running:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`},n={success:(0,Y.jsx)(j,{className:`w-3 h-3`}),failed:(0,Y.jsx)(O,{className:`w-3 h-3`}),skipped:(0,Y.jsx)(Ne,{className:`w-3 h-3`}),running:(0,Y.jsx)(L,{className:`w-3 h-3 animate-spin`})};return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium ${t[e]||`bg-gray-500/20 text-gray-400`}`,children:[n[e],e.charAt(0).toUpperCase()+e.slice(1)]})}var Li={github:`backup.repoUrlPlaceholderGitHub`,gitea:`backup.repoUrlPlaceholderGitea`,forgejo:`backup.repoUrlPlaceholderForgejo`,gitlab:`backup.repoUrlPlaceholderGitLab`},Ri={github:`ghp_xxxxxxxxxxxx`,gitea:`your_access_token`,forgejo:`your_access_token`,gitlab:`glpat-xxxxxxxxxxxx`},zi={github:`backup.tokenHintGitHub`,gitea:`backup.tokenHintGitea`,forgejo:`backup.tokenHintForgejo`,gitlab:`backup.tokenHintGitLab`};function Bi(e){return JSON.stringify(e)}function Vi(e,t){if(!t)return e;let n={};for(let r of Object.keys(e))e[r]!==t[r]&&(n[r]=e[r]);return n}function Hi(){let e=u(),{showToast:t}=ee(),{t:n}=l(),{hasPermission:i}=un(),a=i(`github:restore`),[o,s]=(0,X.useState)(``),[c,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(`main`),[_,v]=(0,X.useState)(`github`),[y,b]=(0,X.useState)(!1),[x,S]=(0,X.useState)(`daily`),[C,w]=(0,X.useState)(!0),[T,E]=(0,X.useState)(!0),[D,k]=(0,X.useState)(!1),[A,te]=(0,X.useState)(!1),[M,N]=(0,X.useState)(!1),[ne,re]=(0,X.useState)(!1),[ie,ae]=(0,X.useState)(!0),[oe,F]=(0,X.useState)(!1),[I,R]=(0,X.useState)(!1),[se,ce]=(0,X.useState)(``),[z,B]=(0,X.useState)(!1),[le,V]=(0,X.useState)(null),[ue,de]=(0,X.useState)(null),fe=(0,X.useRef)(null),[pe,me]=(0,X.useState)(!1),[he,ge]=(0,X.useState)(null),[_e,ve]=(0,X.useState)(null),[ye,be]=(0,X.useState)(``),{data:H,refetch:xe}=d({queryKey:[`local-backup-status`],queryFn:r.getLocalBackupStatus,refetchInterval:e=>e.state.data?.is_running?1e3:1e4}),{data:Se,refetch:Ce}=d({queryKey:[`local-backup-files`],queryFn:r.getLocalBackups,refetchInterval:3e4}),{data:we,refetch:Te}=d({queryKey:[`local-backup-path-check`],queryFn:r.checkLocalBackupPath,enabled:H?.enabled===!0,refetchOnWindowFocus:!1});(0,X.useEffect)(()=>{H?.path!==void 0&&be(H.path)},[H?.path]);let Ee=f({mutationFn:r.triggerLocalBackup,onSuccess:e=>{e.success?t(n(`backup.scheduledBackupComplete`)):t(e.message,`error`),xe(),Ce(),Te()},onError:()=>t(n(`backup.scheduledBackupFailed`),`error`)}),Oe=f({mutationFn:e=>r.deleteLocalBackup(e),onSuccess:()=>{Ce(),ge(null)}}),ke=f({mutationFn:async e=>(ve(null),R(!0),de(null),ce(n(`backup.restoring`)),r.restoreLocalBackup(e)),onSuccess:e=>{R(!1),ce(``),e.success?(de({success:!0,message:e.message}),t(n(`backup.backupRestoredRestart`),`success`)):(de({success:!1,message:e.message}),t(e.message,`error`))},onError:e=>{R(!1),ce(``);let r=e instanceof Error?e.message:n(`backup.failedToRestore`);de({success:!1,message:r}),t(r,`error`)}});(0,X.useEffect)(()=>{if(oe||I){let e=e=>(e.preventDefault(),e.returnValue=`A backup operation is in progress. Are you sure you want to leave?`,e.returnValue);return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)}},[oe,I]);let[Ae,je]=(0,X.useState)(!1),[Me,Ne]=(0,X.useState)(null),[Pe,Fe]=(0,X.useState)(null),Le=(0,X.useRef)(null),Re=(0,X.useRef)(null),ze=(0,X.useRef)(null),Be=(0,X.useRef)(null),Ve=(0,X.useRef)(``),[He,We]=(0,X.useState)(!1),Ge=(0,X.useMemo)(()=>({repository_url:o,branch:h,provider:_,allow_insecure_http:ne,schedule_enabled:y,schedule_type:x,backup_kprofiles:C,backup_cloud_profiles:T,backup_settings:D,backup_spools:A,backup_archives:M,enabled:ie}),[o,h,_,ne,y,x,C,T,D,A,M,ie]),Ke=(0,X.useMemo)(()=>Bi(Ge),[Ge]),{data:q,isLoading:Ye}=d({queryKey:[`github-backup-config`],queryFn:r.getGitHubBackupConfig}),{data:Xe}=d({queryKey:[`github-backup-status`],queryFn:r.getGitHubBackupStatus,refetchInterval:e=>e.state.data?.is_running?500:1e4}),{data:Ze}=d({queryKey:[`github-backup-logs`],queryFn:()=>r.getGitHubBackupLogs(20)}),{data:Qe}=d({queryKey:[`cloud-status`],queryFn:r.getCloudStatus}),{data:$e}=d({queryKey:[`github-backup-cloud-accounts`],queryFn:r.getGitHubBackupCloudAccounts,staleTime:6e4}),et=($e?.bambu??0)+($e?.orca??0),tt=$e?et>0:!!Qe?.is_authenticated,{data:rt}=d({queryKey:[`printers`],queryFn:r.getPrinters}),it=p({queries:(rt??[]).map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>r.getPrinterStatus(e.id),staleTime:1e4,refetchInterval:3e4}))}),ot=(rt??[]).map((e,t)=>({printer:e,connected:it[t]?.data?.connected??!1})),st=ot.length,ut=ot.filter(e=>e.connected).length,dt=st>0&&ut===0,ft=ut>0&&ut<st;(0,X.useEffect)(()=>(ze.current&&clearTimeout(ze.current),q?(We(!1),Be.current={repository_url:q.repository_url,branch:q.branch,provider:q.provider??`github`,allow_insecure_http:q.allow_insecure_http??!1,schedule_enabled:q.schedule_enabled,schedule_type:q.schedule_type,backup_kprofiles:q.backup_kprofiles,backup_cloud_profiles:q.backup_cloud_profiles,backup_settings:q.backup_settings,backup_spools:q.backup_spools,backup_archives:q.backup_archives,enabled:q.enabled},s(q.repository_url),g(q.branch),v(q.provider??`github`),b(q.schedule_enabled),S(q.schedule_type),w(q.backup_kprofiles),E(q.backup_cloud_profiles),k(q.backup_settings),te(q.backup_spools),N(q.backup_archives),re(q.allow_insecure_http??!1),ae(q.enabled),m(``),ze.current=setTimeout(()=>{We(!0)},100)):(We(!1),Be.current=null,m(``)),()=>{ze.current&&clearTimeout(ze.current)}),[q]);let pt=(0,X.useCallback)(async(i=!1)=>{if(q)try{i&&c?(await r.saveGitHubBackupConfig({...Ge,access_token:c}),m(``),Fe(null),t(n(`backup.tokenUpdated`)),Ve.current=``):(await r.updateGitHubBackupConfig(Vi(Ge,Be.current)),Fe(null),t(n(`backup.settingsSaved`))),Be.current=Ge,e.invalidateQueries({queryKey:[`github-backup-config`]}),e.invalidateQueries({queryKey:[`github-backup-status`]})}catch(e){Fe(e.message)}},[q,c,Ge,e,t,n]),mt=(0,X.useRef)(pt);(0,X.useEffect)(()=>{mt.current=pt},[pt]),(0,X.useEffect)(()=>{if(!(!He||!q)&&!(Be.current&&Ke===Bi(Be.current)))return Le.current&&clearTimeout(Le.current),Le.current=setTimeout(()=>{pt(!1)},500),()=>{Le.current&&clearTimeout(Le.current)}},[He,q,Ke,pt]),(0,X.useEffect)(()=>{if(!(!He||!q||!c)&&c!==Ve.current)return Ve.current=c,Re.current&&clearTimeout(Re.current),Re.current=setTimeout(()=>{mt.current(!0)},1e3),()=>{Re.current&&clearTimeout(Re.current)}},[He,c,q]);let ht=f({mutationFn:e=>r.saveGitHubBackupConfig(e),onMutate:()=>{Fe(null)},onSuccess:()=>{e.invalidateQueries({queryKey:[`github-backup-config`]}),e.invalidateQueries({queryKey:[`github-backup-status`]}),t(n(`backup.githubBackupEnabled`)),m(``),We(!0)},onError:e=>{Fe(e.message)}}),_t=f({mutationFn:r.triggerGitHubBackup,onSuccess:r=>{e.invalidateQueries({queryKey:[`github-backup-status`]}),e.invalidateQueries({queryKey:[`github-backup-logs`]}),r.success?r.files_changed>0?t(n(`backup.backupCompleteFiles`,{count:r.files_changed})):t(n(`backup.backupSkippedNoChanges`)):t(n(`backup.backupFailed2`,{message:r.message}),`error`)},onError:e=>{t(n(`backup.backupFailed2`,{message:e.message}),`error`)}}),vt=f({mutationFn:()=>r.clearGitHubBackupLogs(0),onSuccess:r=>{e.invalidateQueries({queryKey:[`github-backup-logs`]}),t(n(`backup.clearedLogs`,{count:r.deleted}))},onError:e=>{t(n(`backup.failedToClearLogs`,{message:e.message}),`error`)}}),yt=async()=>{je(!0),Ne(null);try{let e;if(c){if(!o){t(n(`backup.enterRepoUrl`),`error`),je(!1);return}e=await r.testGitHubConnection(o,c,_)}else if(q?.has_token)e=await r.testGitHubStoredConnection();else{t(n(`backup.enterRepoAndToken`),`error`),je(!1);return}Ne({success:e.success,message:e.message,isPrivate:e.is_private})}catch(e){Ne({success:!1,message:e.message,isPrivate:null})}finally{je(!1)}};return Ye?(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,Y.jsx)(L,{className:`w-8 h-8 animate-spin text-bambu-green`})}):(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-6`,children:[(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsxs)(G,{id:`card-backup-github`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(It,{className:`w-5 h-5 text-gray-400`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.githubBackup`)})]}),q&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`backup.enabled`)}),(0,Y.jsx)(J,{checked:ie,onChange:ae})]})]})}),(0,Y.jsxs)(W,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.githubDescription`)}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`git-provider-select`,className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.provider`)}),(0,Y.jsxs)(`select`,{id:`git-provider-select`,value:_,onChange:e=>{v(e.target.value),Ne(null),Fe(null)},className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`github`,children:n(`backup.providerGitHub`)}),(0,Y.jsx)(`option`,{value:`gitlab`,children:n(`backup.providerGitLab`)}),(0,Y.jsx)(`option`,{value:`gitea`,children:n(`backup.providerGitea`)}),(0,Y.jsx)(`option`,{value:`forgejo`,children:n(`backup.providerForgejo`)})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.repositoryUrl`)}),(0,Y.jsx)(`input`,{type:`text`,value:o,onChange:e=>{s(e.target.value),Ne(null),Fe(null)},placeholder:n(Li[_]),className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,Y.jsxs)(`label`,{className:`flex items-start gap-2 mt-2 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:ne,onChange:e=>{re(e.target.checked),Ne(null)},className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`backup.allowInsecureHttp`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.allowInsecureHttpHint`)})]})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`backup.personalAccessToken`),` `,q?.has_token&&(0,Y.jsx)(`span`,{className:`text-green-700 dark:text-green-400`,children:n(`backup.tokenSaved`)})]}),(0,Y.jsx)(`input`,{type:`password`,value:c,onChange:e=>{m(e.target.value),Ne(null),Fe(null)},placeholder:q?.has_token?n(`backup.enterNewToken`):Ri[_],className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(zi[_])})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.branch`)}),(0,Y.jsx)(`input`,{type:`text`,value:h,onChange:e=>g(e.target.value),placeholder:`main`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.autoBackup`)}),(0,Y.jsxs)(`select`,{value:y?x:`disabled`,onChange:e=>{e.target.value===`disabled`?b(!1):(b(!0),S(e.target.value))},className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`disabled`,children:n(`backup.manualOnly`)}),(0,Y.jsx)(`option`,{value:`hourly`,children:n(`backup.hourly`)}),(0,Y.jsx)(`option`,{value:`daily`,children:n(`backup.daily`)}),(0,Y.jsx)(`option`,{value:`weekly`,children:n(`backup.weekly`)})]})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:n(`backup.includeInBackup`)}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`label`,{className:`flex items-start gap-2 ${dt?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:C,onChange:e=>w(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`,disabled:dt}),(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm ${dt?`text-bambu-gray`:`text-white`}`,children:n(`backup.kProfiles`)}),dt&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:[(0,Y.jsx)(Ie,{className:`w-3 h-3`}),n(`backup.noPrintersConnected`)]}),ft&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:[(0,Y.jsx)(Ie,{className:`w-3 h-3`}),n(`backup.printersConnected`,{connected:ut,total:st})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.kProfilesDescription`)})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-start gap-2 ${tt?`cursor-pointer`:`cursor-not-allowed opacity-60`}`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:T,onChange:e=>E(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`,disabled:!tt}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm ${tt?`text-white`:`text-bambu-gray`}`,children:n(`backup.cloudProfiles`)}),!tt&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:[(0,Y.jsx)(Ie,{className:`w-3 h-3`}),n(`backup.cloudLoginRequiredShort`)]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.cloudProfilesDescription`)}),et>0&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:n(`backup.cloudProfilesAccounts`,{bambu:$e?.bambu??0,orca:$e?.orca??0})})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:D,onChange:e=>k(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.appSettings`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.appSettingsDescription`)})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:A,onChange:e=>te(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.spoolInventory`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.spoolInventoryDescription`)})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:M,onChange:e=>N(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.printArchives`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.printArchivesDescription`)})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4 space-y-3`,children:[Xe?.configured&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,Y.jsx)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:Xe.last_backup_at?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`span`,{children:[n(`backup.lastBackupAt`),` `,Ue(Xe.last_backup_at,`system`,n)]}),(0,Y.jsx)(Ii,{status:Xe.last_backup_status})]}):(0,Y.jsx)(`span`,{children:n(`backup.noBackupsYet`)})}),Xe.next_scheduled_run&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[(0,Y.jsx)(lt,{className:`w-3 h-3 inline mr-1`}),n(`backup.next`),` `,Ue(Xe.next_scheduled_run,`system`,n)]})]}),Pe&&(0,Y.jsxs)(`div`,{className:`text-sm text-red-700 dark:text-red-400 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded p-3 flex items-start gap-2`,children:[(0,Y.jsx)(O,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,Y.jsx)(`div`,{className:`flex-1 leading-relaxed whitespace-pre-wrap break-words`,children:Pe}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>Fe(null),className:`text-bambu-gray hover:text-white shrink-0`,"aria-label":n(`common.dismiss`,`Dismiss`),children:(0,Y.jsx)(O,{className:`w-4 h-4`})})]}),Me&&(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`text-sm flex items-center gap-1 ${Me.success?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:[Me.success?(0,Y.jsx)(j,{className:`w-4 h-4`}):(0,Y.jsx)(O,{className:`w-4 h-4`}),Me.message]}),Me.success&&Me.isPrivate===!0&&(0,Y.jsxs)(`div`,{className:`text-xs flex items-center gap-1 text-green-700 dark:text-green-400`,children:[(0,Y.jsx)(j,{className:`w-3.5 h-3.5`}),n(`backup.repoIsPrivate`,`Repository is private — safe to back up to.`)]}),Me.success&&Me.isPrivate===!1&&(0,Y.jsxs)(`div`,{className:`text-xs text-red-700 dark:text-red-400 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded p-2 flex items-start gap-1.5`,children:[(0,Y.jsx)(O,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,Y.jsx)(`span`,{children:n(`backup.repoIsPublicWarning`,`Repository is PUBLIC. Bambuddy backups include MQTT credentials, Home Assistant tokens, Prometheus tokens, your Bambu Cloud email, and printer access codes via K-profiles. Saving is blocked until you make the repository private in your provider's settings.`)})]}),Me.success&&Me.isPrivate===null&&(0,Y.jsxs)(`div`,{className:`text-xs text-yellow-700 dark:text-yellow-400 bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded p-2 flex items-start gap-1.5`,children:[(0,Y.jsx)(O,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,Y.jsx)(`span`,{children:n(`backup.repoVisibilityUnknown`,`Could not determine repository visibility. Bambuddy refuses to back up to anything not confirmed private; saving will be blocked.`)})]})]}),(0,Y.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:Xe?.configured?(0,Y.jsx)(Y.Fragment,{children:_t.isPending||Xe.is_running?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-green`,children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}),(0,Y.jsx)(`span`,{className:`text-sm`,children:Xe.progress||n(`backup.startingBackup`)})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(K,{variant:`primary`,size:`sm`,onClick:()=>_t.mutate(),disabled:!q?.enabled,children:[(0,Y.jsx)(De,{className:`w-4 h-4`}),n(`backup.backupNow`)]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:yt,disabled:Ae,children:[Ae?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(at,{className:`w-4 h-4`}),n(`backup.test`)]}),a&&(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:()=>me(!0),disabled:Xe.restore_running,children:[(0,Y.jsx)(nt,{className:`w-4 h-4`}),n(`backup.restoreFromGit.button`)]})]})}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(K,{variant:`primary`,size:`sm`,onClick:()=>{if(!o){t(n(`backup.repoRequired`),`error`);return}if(!c){t(n(`backup.tokenRequired`),`error`);return}ht.mutate({repository_url:o,access_token:c,branch:h,provider:_,allow_insecure_http:ne,schedule_enabled:y,schedule_type:x,backup_kprofiles:C,backup_cloud_profiles:T,backup_settings:D,backup_spools:A,backup_archives:M,enabled:ie})},disabled:ht.isPending||!o||!c,children:[ht.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(j,{className:`w-4 h-4`}),n(`backup.enableBackup`)]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:yt,disabled:Ae||!o||!c,children:[Ae?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(at,{className:`w-4 h-4`}),n(`backup.testConnection`)]})]})})]})]})]}),Ze&&Ze.length>0&&(0,Y.jsxs)(G,{id:`card-backup-history`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(P,{className:`w-5 h-5 text-gray-400`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.history`)})]}),(0,Y.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>vt.mutate(),disabled:vt.isPending,children:[(0,Y.jsx)(qe,{className:`w-4 h-4`}),n(`backup.clear`)]})]})}),(0,Y.jsx)(W,{children:(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.date`)}),(0,Y.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.trigger`)}),(0,Y.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.status`)}),(0,Y.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.commit`)})]})}),(0,Y.jsx)(`tbody`,{children:Ze.slice(0,10).map(e=>(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-secondary`,children:[(0,Y.jsx)(`td`,{className:`py-2 px-2 text-white`,children:Fi(e.started_at)}),(0,Y.jsx)(`td`,{className:`py-2 px-2 text-bambu-gray`,children:n(`backup.triggers.${e.trigger}`,{defaultValue:e.trigger})}),(0,Y.jsx)(`td`,{className:`py-2 px-2`,children:(0,Y.jsx)(Ii,{status:e.status})}),(0,Y.jsx)(`td`,{className:`py-2 px-2`,children:e.commit_sha?(0,Y.jsxs)(`a`,{href:`${q?.repository_url}/commit/${e.commit_sha}`,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline inline-flex items-center gap-1`,children:[e.commit_sha.substring(0,7),(0,Y.jsx)(Je,{className:`w-3 h-3`})]}):(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:`-`})})]},e.id))})]})})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsxs)(G,{id:`card-backup-local`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(gt,{className:`w-5 h-5 text-gray-400`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.localBackup`)})]})}),(0,Y.jsxs)(W,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.localBackupDescription`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:n(`backup.downloadBackupLabel`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.completeBackupZip`)})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,disabled:oe||I,onClick:async()=>{F(!0),ce(n(`backup.preparingBackup`));try{ce(n(`backup.creatingArchive`));let{blob:e,filename:i}=await r.exportBackup();ce(n(`backup.downloadingFile`));let a=URL.createObjectURL(e),o=document.createElement(`a`);o.href=a,o.download=i,o.click(),URL.revokeObjectURL(a),t(n(`backup.backupDownloaded`))}catch(e){t(n(`backup.failedToCreateBackup`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}finally{F(!1),ce(``)}},children:[(0,Y.jsx)(sn,{className:`w-4 h-4`}),n(`backup.download`)]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:n(`backup.restoreBackup`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.restoreDescription`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.restoreNote`)})]}),(0,Y.jsx)(`input`,{ref:fe,type:`file`,accept:`.zip`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&(V(t),B(!0)),e.target.value=``}}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,disabled:I||oe,onClick:()=>fe.current?.click(),children:[(0,Y.jsx)(Wt,{className:`w-4 h-4`}),n(`backup.restore`)]})]}),ue&&(0,Y.jsx)(`div`,{className:`p-3 rounded-lg ${ue.success?`bg-green-50 dark:bg-green-500/10 border border-green-300 dark:border-green-500/30`:`bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`}`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[ue.success?(0,Y.jsx)(j,{className:`w-4 h-4 text-green-600 dark:text-green-400 mt-0.5 flex-shrink-0`}):(0,Y.jsx)(O,{className:`w-4 h-4 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:ue.success?`text-green-800 dark:text-green-200`:`text-red-800 dark:text-red-200`,children:[ue.message,ue.success&&(0,Y.jsx)(`div`,{className:`mt-2`,children:(0,Y.jsxs)(K,{size:`sm`,onClick:()=>window.location.reload(),children:[(0,Y.jsx)(nt,{className:`w-3 h-3`}),n(`backup.reloadNow`)]})})]})]})}),(0,Y.jsx)(`div`,{className:`p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,Y.jsx)(Ie,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:`text-yellow-800 dark:text-yellow-200`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:n(`backup.restoreReplacesAll`)}),` `,(0,Y.jsx)(`span`,{className:`text-yellow-800/80 dark:text-yellow-200/70`,children:n(`backup.restoreReplacesAllDetail`)})]})]})})]})]}),(0,Y.jsxs)(G,{id:`card-backup-scheduled`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(xn,{className:`w-5 h-5 text-gray-400`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.scheduledBackup`)})]}),(0,Y.jsx)(J,{checked:H?.enabled??!1,onChange:async i=>{try{await r.updateSettings({local_backup_enabled:i}),e.invalidateQueries({queryKey:[`settings`]}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}xe()}})]})}),(0,Y.jsxs)(W,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.scheduledBackupDescription`)}),H?.enabled&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.frequency`)}),(0,Y.jsxs)(`select`,{value:H?.schedule??`daily`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onChange:async e=>{try{await r.updateSettings({local_backup_schedule:e.target.value}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}xe()},children:[(0,Y.jsx)(`option`,{value:`hourly`,children:n(`backup.hourly`)}),(0,Y.jsx)(`option`,{value:`daily`,children:n(`backup.daily`)}),(0,Y.jsx)(`option`,{value:`weekly`,children:n(`backup.weekly`)})]})]}),(H?.schedule??`daily`)!==`hourly`&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.backupTime`)}),(0,Y.jsx)(`input`,{type:`time`,value:H?.time??`03:00`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onChange:async e=>{try{await r.updateSettings({local_backup_time:e.target.value}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}xe()}}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.localTimeHint`,{tz:H?.timezone||`UTC`})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.retention`)}),(0,Y.jsx)(ct,{min:1,max:100,value:H?.retention??5,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onChange:async e=>{try{await r.updateSettings({local_backup_retention:e}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}xe()},fallback:5}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.retentionDescription`)})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.outputPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:ye,onChange:e=>be(e.target.value),className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onBlur:async()=>{try{await r.updateSettings({local_backup_path:ye}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}xe(),Ce(),Te()},onKeyDown:e=>{e.key===`Enter`&&e.target.blur()}}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:ye?n(`backup.outputPathDescription`):(0,Y.jsxs)(Y.Fragment,{children:[n(`backup.defaultPathLabel`),` `,(0,Y.jsx)(`code`,{className:`text-bambu-gray`,children:H?.default_path||`...`})]})}),we&&!we.writable&&(0,Y.jsx)(`div`,{className:`mt-2 p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,Y.jsx)(Ie,{className:`w-4 h-4 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 text-red-800 dark:text-red-200`,children:[(0,Y.jsx)(`p`,{className:`font-medium`,children:n(`backup.pathCheck.title`)}),(0,Y.jsx)(`p`,{className:`mt-1 text-red-800/80 dark:text-red-200/80`,children:n(`backup.pathCheck.${we.code}`,{path:we.path,defaultValue:we.message})}),we.remedy&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`p`,{className:`mt-2 font-medium`,children:n(`backup.pathCheck.howToFix`)}),(0,Y.jsx)(`pre`,{className:`mt-1 p-2 rounded bg-black/10 dark:bg-black/40 text-xs whitespace-pre-wrap break-words`,children:we.remedy})]}),we.detail&&(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-red-800/60 dark:text-red-200/60 break-words`,children:we.detail})]})]})}),we?.writable&&we.warning===`container_ephemeral`&&(0,Y.jsx)(`div`,{className:`mt-2 p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,Y.jsx)(Ie,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 text-yellow-800 dark:text-yellow-200`,children:[(0,Y.jsx)(`p`,{className:`font-medium`,children:n(`backup.pathCheck.ephemeralTitle`)}),(0,Y.jsx)(`p`,{className:`mt-1 text-yellow-800/80 dark:text-yellow-200/80`,children:n(`backup.pathCheck.container_ephemeral`,{path:we.path})}),we.remedy&&(0,Y.jsx)(`pre`,{className:`mt-1 p-2 rounded bg-black/10 dark:bg-black/40 text-xs whitespace-pre-wrap break-words`,children:we.remedy})]})]})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`text-sm`,children:[H?.last_backup_at&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,Y.jsxs)(`span`,{children:[n(`backup.lastBackup`),`:`]}),(0,Y.jsx)(Ii,{status:H.last_status}),(0,Y.jsx)(`span`,{children:Ue(H.last_backup_at)})]}),H?.next_run&&(0,Y.jsxs)(`div`,{className:`text-bambu-gray mt-1`,children:[(0,Y.jsxs)(`span`,{children:[n(`backup.nextBackup`),`: `]}),(0,Y.jsx)(`span`,{children:Fi(H.next_run)})]})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,disabled:H?.is_running||Ee.isPending,onClick:()=>Ee.mutate(),children:[H?.is_running||Ee.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(De,{className:`w-4 h-4`}),H?.is_running?n(`backup.backupRunning`):n(`backup.runNow`)]})]}),Se&&Se.length>0&&(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-medium text-white mb-2`,children:n(`backup.backupFiles`)}),(0,Y.jsx)(`div`,{className:`space-y-1`,children:Se.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between py-1.5 px-2 rounded hover:bg-bambu-dark-tertiary/50 text-sm`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`text-white truncate block`,children:e.filename}),(0,Y.jsxs)(`span`,{className:`text-bambu-gray text-xs`,children:[(e.size/1024/1024).toFixed(1),` MB · `,Fi(e.created_at)]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[(0,Y.jsx)(`button`,{className:`text-bambu-gray hover:text-bambu-green p-1`,title:n(`backup.download`),onClick:async()=>{try{let{blob:t,filename:n}=await r.downloadLocalBackup(e.filename),i=URL.createObjectURL(t),a=document.createElement(`a`);a.href=i,a.download=n,a.click(),URL.revokeObjectURL(i)}catch{t(n(`backup.scheduledBackupFailed`),`error`)}},children:(0,Y.jsx)(sn,{className:`w-3.5 h-3.5`})}),(0,Y.jsx)(`button`,{className:`text-bambu-gray hover:text-yellow-600 dark:hover:text-yellow-400 p-1`,title:n(`backup.restore`),onClick:()=>ve(e.filename),children:(0,Y.jsx)(nt,{className:`w-3.5 h-3.5`})}),(0,Y.jsx)(`button`,{className:`text-bambu-gray hover:text-red-600 dark:hover:text-red-400 p-1`,onClick:()=>ge(e.filename),title:n(`backup.deleteBackup`),children:(0,Y.jsx)(qe,{className:`w-3.5 h-3.5`})})]})]},e.filename))})]}),Se&&Se.length===0&&(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-3 border-t border-bambu-dark-tertiary`,children:n(`backup.noScheduledBackups`)})]})]})]})]}),pe&&(0,Y.jsx)(Pi,{onClose:()=>me(!1)}),he&&(0,Y.jsx)(Tt,{title:n(`backup.deleteBackup`),message:n(`backup.deleteBackupConfirm`),confirmText:n(`backup.deleteBackup`),variant:`danger`,onConfirm:()=>Oe.mutate(he),onCancel:()=>ge(null)}),_e&&(0,Y.jsx)(Tt,{title:n(`backup.restoreConfirmTitle`),message:n(`backup.restoreConfirmMessage`,{filename:_e}),confirmText:n(`backup.restoreConfirmButton`),variant:`danger`,onConfirm:()=>ke.mutate(_e),onCancel:()=>ve(null)}),z&&le&&(0,Y.jsx)(Tt,{title:n(`backup.restoreConfirmTitle`),message:n(`backup.restoreConfirmMessage`,{filename:le.name}),confirmText:n(`backup.restoreConfirmButton`),variant:`danger`,onConfirm:async()=>{B(!1),R(!0),de(null);try{ce(n(`backup.uploadingFile`));let e=await r.importBackup(le);de(e),e.success?t(n(`backup.backupRestoredRestart`),`success`):t(e.message||n(`backup.failedToRestore`),`error`)}catch(e){let r=e instanceof Error?e.message:n(`backup.failedToRestore`);de({success:!1,message:r}),t(r,`error`)}finally{R(!1),ce(``),V(null)}},onCancel:()=>{B(!1),V(null)}}),(oe||I)&&(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-[100]`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-8 max-w-md w-full mx-4 text-center`,children:[(0,Y.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`div`,{className:`w-16 h-16 border-4 border-bambu-dark-tertiary rounded-full`}),(0,Y.jsx)(`div`,{className:`w-16 h-16 border-4 border-bambu-green border-t-transparent rounded-full absolute inset-0 animate-spin`})]})}),(0,Y.jsx)(`h3`,{className:`text-xl font-semibold text-white mb-2`,children:n(oe?`backup.creatingBackup`:`backup.restoringBackup`)}),(0,Y.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:se||n(oe?`backup.preparing`:`backup.processing`)}),(0,Y.jsx)(`div`,{className:`p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,Y.jsx)(Ie,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,Y.jsx)(`p`,{className:`text-yellow-800 dark:text-yellow-200 text-left`,children:n(`backup.doNotClosePage`)})]})})]})})]})}function Ui(){let{t:e}=l(),t=u(),{showToast:n}=ee(),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(``),[c,p]=(0,X.useState)(``),[m,h]=(0,X.useState)(`medium`),[g,_]=(0,X.useState)(`notify`),[v,y]=(0,X.useState)(10),[b,x]=(0,X.useState)(null),[S,C]=(0,X.useState)(null),[w,E]=(0,X.useState)(!1),{data:D}=d({queryKey:[`settings`],queryFn:r.getSettings}),{data:O,refetch:k}=d({queryKey:[`obico-status`],queryFn:r.getObicoStatus,refetchInterval:1e4}),{data:j}=d({queryKey:[`printers`],queryFn:r.getPrinters});(0,X.useEffect)(()=>{if(D){a(D.obico_enabled??!1),s(D.obico_ml_url??``),p(D.obico_ml_token??``),h(D.obico_sensitivity??`medium`),_(D.obico_action??`notify`),y(D.obico_poll_interval??10);try{let e=D.obico_enabled_printers?JSON.parse(D.obico_enabled_printers):null;x(Array.isArray(e)?e:null)}catch{x(null)}E(!0)}},[D]);let te=f({mutationFn:()=>r.updateSettings({obico_enabled:i,obico_ml_url:o,obico_ml_token:c,obico_sensitivity:m,obico_action:g,obico_poll_interval:v,obico_enabled_printers:b===null?``:JSON.stringify(b)}),onSuccess:()=>{t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`obico-status`]}),t.invalidateQueries({queryKey:[`obico-printer-status`]}),n(e(`settings.toast.settingsSaved`))}}),M=(0,X.useMemo)(()=>!w||!D?!1:D.obico_enabled!==i||D.obico_ml_url!==o||(D.obico_ml_token??``)!==c||D.obico_sensitivity!==m||D.obico_action!==g||D.obico_poll_interval!==v||D.obico_enabled_printers!==(b===null?``:JSON.stringify(b)),[D,w,i,o,c,m,g,v,b]);(0,X.useEffect)(()=>{if(!M)return;let e=setTimeout(()=>te.mutate(),500);return()=>clearTimeout(e)},[M,i,o,c,m,g,v,b]);let N=async()=>{C(null);try{M&&await te.mutateAsync();let t=await r.testObicoConnection(o,c);t.ok?C({ok:!0,message:t.auth_ok===null?e(`failureDetection.testSuccessTokenUnknown`):e(`failureDetection.testSuccess`)}):C({ok:!1,message:t.error||`HTTP ${t.status_code??`?`} — ${t.body??e(`failureDetection.testFailed`)}`})}catch(e){C({ok:!1,message:e instanceof Error?e.message:String(e)})}},ne=(e,t)=>{if(b===null){let n=j?.map(e=>e.id)??[];x(t?n:n.filter(t=>t!==e));return}x(t?[...b,e]:b.filter(t=>t!==e))};return(0,Y.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,Y.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,Y.jsxs)(G,{id:`card-fd-ml`,children:[(0,Y.jsxs)(U,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Se,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.title`)})]}),(0,Y.jsx)(J,{checked:i,onChange:a})]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:e(`failureDetection.description`)})]}),(0,Y.jsxs)(W,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.mlUrl`)}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`http://192.168.1.10:3333`,className:`flex-1 bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,disabled:!i}),(0,Y.jsx)(K,{onClick:N,disabled:!o||te.isPending,variant:`secondary`,children:e(`failureDetection.test`)})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.mlUrlHint`)}),(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 mt-3`,children:e(`failureDetection.mlToken`)}),(0,Y.jsx)(`input`,{type:`password`,value:c,onChange:e=>p(e.target.value),autoComplete:`off`,placeholder:e(`failureDetection.mlTokenPlaceholder`),className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,disabled:!i}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.mlTokenHint`)}),S&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 mt-2 text-sm ${S.ok?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:[S.ok?(0,Y.jsx)(T,{className:`w-4 h-4 mt-0.5`}):(0,Y.jsx)(Re,{className:`w-4 h-4 mt-0.5`}),(0,Y.jsx)(`span`,{children:S.message})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.sensitivity`)}),(0,Y.jsxs)(`select`,{value:m,onChange:e=>h(e.target.value),disabled:!i,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,children:[(0,Y.jsx)(`option`,{value:`low`,children:e(`failureDetection.sensitivityLow`)}),(0,Y.jsx)(`option`,{value:`medium`,children:e(`failureDetection.sensitivityMedium`)}),(0,Y.jsx)(`option`,{value:`high`,children:e(`failureDetection.sensitivityHigh`)})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.sensitivityHint`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.action`)}),(0,Y.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),disabled:!i,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,children:[(0,Y.jsx)(`option`,{value:`notify`,children:e(`failureDetection.actionNotify`)}),(0,Y.jsx)(`option`,{value:`pause`,children:e(`failureDetection.actionPause`)}),(0,Y.jsx)(`option`,{value:`pause_and_off`,children:e(`failureDetection.actionPauseOff`)})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.pollInterval`)}),(0,Y.jsx)(ct,{value:v,onChange:y,fallback:10,min:5,max:120,disabled:!i,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.pollIntervalHint`)})]}),O&&!O.external_url_configured&&i&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 p-3 bg-amber-50 dark:bg-amber-900/30 border border-amber-300 dark:border-amber-700 rounded text-sm text-amber-800 dark:text-amber-200`,children:[(0,Y.jsx)(Ie,{className:`w-4 h-4 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e(`failureDetection.externalUrlMissing`)}),(0,Y.jsx)(`div`,{className:`text-xs mt-1`,children:e(`failureDetection.externalUrlHint`)})]})]})]})]}),(0,Y.jsxs)(G,{id:`card-fd-perprinter`,children:[(0,Y.jsxs)(U,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.perPrinterTitle`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`failureDetection.perPrinterHint`)})]}),(0,Y.jsxs)(W,{className:`space-y-2`,children:[(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:b===null,onChange:e=>x(e.target.checked?null:j?.map(e=>e.id)??[]),disabled:!i}),(0,Y.jsx)(`span`,{className:`text-white`,children:e(`failureDetection.monitorAll`)})]}),b!==null&&j&&(0,Y.jsx)(`div`,{className:`pl-5 space-y-1 border-l border-gray-700`,children:j.map(e=>(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:b.includes(e.id),onChange:t=>ne(e.id,t.target.checked),disabled:!i}),(0,Y.jsx)(`span`,{className:`text-white`,children:e.name})]},e.id))})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,Y.jsxs)(G,{id:`card-fd-status`,children:[(0,Y.jsx)(U,{children:(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.statusTitle`)})}),(0,Y.jsx)(W,{children:O?(0,Y.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:e(`failureDetection.serviceRunning`)}),(0,Y.jsx)(`span`,{className:O.is_running?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`,children:O.is_running?e(`common.yes`):e(`common.no`)})]}),(0,Y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:e(`failureDetection.thresholds`)}),(0,Y.jsxs)(`span`,{className:`text-white font-mono`,children:[O.thresholds.low.toFixed(2),` / `,O.thresholds.high.toFixed(2)]})]}),O.last_error&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-red-700 dark:text-red-400`,children:[(0,Y.jsx)(Re,{className:`w-4 h-4 mt-0.5 flex-shrink-0`}),(0,Y.jsx)(`span`,{className:`break-words`,children:O.last_error})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-bambu-gray mb-1`,children:e(`failureDetection.activePrinters`)}),Object.keys(O.per_printer).length===0?(0,Y.jsx)(`div`,{className:`text-bambu-gray italic text-xs`,children:e(`failureDetection.noActivePrints`)}):(0,Y.jsx)(`div`,{className:`space-y-1`,children:Object.entries(O.per_printer).map(([e,t])=>{let n=j?.find(t=>String(t.id)===e),r=t.class===`failure`?`text-red-700 dark:text-red-400`:t.class===`warning`?`text-amber-700 dark:text-amber-400`:`text-green-700 dark:text-green-400`;return(0,Y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-white`,children:n?.name??`Printer ${e}`}),(0,Y.jsxs)(`span`,{className:`font-mono ${r}`,children:[t.class,` (`,t.score.toFixed(3),`, `,t.frame_count,`f)`]})]},e)})})]})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}),(0,Y.jsx)(`span`,{children:e(`common.loading`)})]})})]}),(0,Y.jsxs)(G,{id:`card-fd-history`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.historyTitle`)}),(0,Y.jsx)(`button`,{onClick:()=>k(),className:`text-xs text-bambu-gray hover:text-white`,children:e(`common.refresh`)})]})}),(0,Y.jsx)(W,{children:!O||O.history.length===0?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm`,children:[(0,Y.jsx)(A,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{children:e(`failureDetection.noHistory`)})]}):(0,Y.jsx)(`div`,{className:`space-y-1 max-h-96 overflow-y-auto text-xs font-mono`,children:O.history.map((e,t)=>{let n=j?.find(t=>t.id===e.printer_id),r=e.class===`failure`?`text-red-700 dark:text-red-400`:e.class===`warning`?`text-amber-700 dark:text-amber-400`:`text-bambu-gray`;return(0,Y.jsxs)(`div`,{className:`flex justify-between gap-2 py-1 border-b border-gray-800`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:new Date(e.timestamp).toLocaleTimeString()}),(0,Y.jsx)(`span`,{className:`text-white truncate`,children:n?.name??`#${e.printer_id}`}),(0,Y.jsxs)(`span`,{className:r,children:[e.class,` `,e.score.toFixed(3)]})]},t)})})})]})]})]})}var Wi={starttls:587,ssl:465,none:25},Gi={587:`starttls`,465:`ssl`,25:`none`};function Ki(){let{t:e}=l(),{showToast:t}=ee(),n=u(),[i,a]=(0,X.useState)({smtp_host:``,smtp_port:587,smtp_username:``,smtp_password:``,smtp_security:`starttls`,smtp_auth_enabled:!0,smtp_from_email:``,smtp_from_name:`BamBuddy`}),[o,s]=(0,X.useState)(``),{data:c,isLoading:p}=d({queryKey:[`smtpSettings`],queryFn:()=>r.getSMTPSettings()}),{authEnabled:m}=un(),{data:g}=d({queryKey:[`advancedAuthStatus`],queryFn:()=>r.getAdvancedAuthStatus()});(0,X.useEffect)(()=>{c&&a({...c,smtp_password:``})},[c]);let _=e=>{a({...i,smtp_security:e,smtp_port:Wi[e]})},v=e=>{let t=Gi[e];a({...i,smtp_port:e,...t?{smtp_security:t}:{}})},y=e=>{a({...i,smtp_auth_enabled:e,...e?{}:{smtp_username:``,smtp_password:``}})},b=f({mutationFn:e=>r.saveSMTPSettings(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`smtpSettings`]}),n.invalidateQueries({queryKey:[`advancedAuthStatus`]}),t(e(`settings.email.success.settingsSaved`),`success`)},onError:e=>{t(e.message,`error`)}}),x=f({mutationFn:e=>r.testSMTP(e),onSuccess:e=>{t(e.message,e.success?`success`:`error`)},onError:e=>{t(e.message,`error`)}}),S=f({mutationFn:e=>e?r.enableAdvancedAuth():r.disableAdvancedAuth(),onSuccess:e=>{n.invalidateQueries({queryKey:[`advancedAuthStatus`]}),t(e.message,`success`)},onError:e=>{t(e.message,`error`)}}),C=()=>{if(!i.smtp_host||!i.smtp_from_email){t(e(`settings.email.errors.requiredFields`),`error`);return}if(i.smtp_auth_enabled&&!i.smtp_username){t(e(`settings.email.errors.usernameRequired`),`error`);return}b.mutate(i)},w=()=>{if(!o){t(e(`settings.email.errors.enterTestEmail`),`error`);return}x.mutate({test_recipient:o})},T=()=>{if(!m){t(e(`settings.email.errors.enableAuthFirst`),`error`);return}if(!g?.advanced_auth_enabled&&!g?.smtp_configured){t(e(`settings.email.errors.configureSmtpFirst`),`error`);return}S.mutate(!g?.advanced_auth_enabled)};if(p)return(0,Y.jsx)(`div`,{className:`flex items-center justify-center p-12`,children:(0,Y.jsx)(L,{className:`w-8 h-8 animate-spin text-bambu-green`})});let E=g?.advanced_auth_enabled??!1,D=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,O=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white/40 placeholder-bambu-gray/40 cursor-not-allowed`;return(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(G,{id:`card-email-advanced-auth`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Vt,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.advancedAuth`)||`Advanced Authentication`})]}),(0,Y.jsx)(K,{onClick:T,disabled:S.isPending,variant:E?`danger`:`primary`,children:E?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(h,{className:`w-4 h-4`}),e(`settings.email.disable`)||`Disable`]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(R,{className:`w-4 h-4`}),e(`settings.email.enable`)||`Enable`]})})]})}),(0,Y.jsx)(W,{children:(0,Y.jsx)(`div`,{className:`space-y-3`,children:E?(0,Y.jsx)(`div`,{className:`bg-green-50 dark:bg-green-500/10 border border-green-300 dark:border-green-500/30 rounded-lg p-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(j,{className:`w-5 h-5 text-green-600 dark:text-green-400 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.email.advancedAuthEnabled`)||`Advanced Authentication is enabled`}),(0,Y.jsxs)(`ul`,{className:`text-sm text-green-700 dark:text-green-300 space-y-1 list-disc list-inside`,children:[(0,Y.jsx)(`li`,{children:e(`settings.email.feature1`)||`Passwords are auto-generated and emailed to new users`}),(0,Y.jsx)(`li`,{children:e(`settings.email.feature2`)||`Users can login with username or email`}),(0,Y.jsx)(`li`,{children:e(`settings.email.feature3`)||`Forgot password feature is available`}),(0,Y.jsx)(`li`,{children:e(`settings.email.feature4`)||`Admins can reset user passwords via email`})]})]})]})}):(0,Y.jsx)(`div`,{className:`bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded-lg p-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(Ie,{className:`w-5 h-5 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.email.advancedAuthDisabled`)||`Advanced Authentication is disabled`}),(0,Y.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-300`,children:e(`settings.email.advancedAuthDisabledDesc`)||`Enable advanced authentication to activate email-based features for user management.`})]})]})})})})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,Y.jsx)(`div`,{className:`lg:col-span-2`,children:(0,Y.jsxs)(G,{id:`card-smtp-config`,children:[(0,Y.jsx)(U,{children:(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.smtpSettings`)||`SMTP Configuration`})}),(0,Y.jsx)(W,{children:(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.authentication`)||`Authentication`}),(0,Y.jsxs)(`select`,{value:i.smtp_auth_enabled?`true`:`false`,onChange:e=>y(e.target.value===`true`),className:D,children:[(0,Y.jsx)(`option`,{value:`true`,children:e(`settings.email.authOptions.enabled`)}),(0,Y.jsx)(`option`,{value:`false`,children:e(`settings.email.authOptions.disabled`)})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 transition-opacity ${i.smtp_auth_enabled?``:`opacity-40 pointer-events-none`}`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.username`)||`Username`}),(0,Y.jsx)(`input`,{type:`text`,value:i.smtp_username||``,onChange:e=>a({...i,smtp_username:e.target.value}),placeholder:`your.email@gmail.com`,disabled:!i.smtp_auth_enabled,className:i.smtp_auth_enabled?D:O})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.password`)||`Password`}),(0,Y.jsx)(`input`,{type:`password`,value:i.smtp_password||``,onChange:e=>a({...i,smtp_password:e.target.value}),placeholder:c?`••••••••`:`App password`,disabled:!i.smtp_auth_enabled,className:i.smtp_auth_enabled?D:O})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:[e(`settings.email.smtpHost`)||`SMTP Server`,` *`]}),(0,Y.jsx)(`input`,{type:`text`,value:i.smtp_host,onChange:e=>a({...i,smtp_host:e.target.value}),placeholder:`smtp.gmail.com`,className:D})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.smtpPort`)||`SMTP Port`}),(0,Y.jsx)(ct,{value:i.smtp_port,onChange:v,min:1,max:65535,fallback:587,placeholder:`587`,className:D})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.security`)||`Security`}),(0,Y.jsxs)(`select`,{value:i.smtp_security,onChange:e=>_(e.target.value),className:D,children:[(0,Y.jsx)(`option`,{value:`starttls`,children:e(`settings.email.securityOptions.starttls`)}),(0,Y.jsx)(`option`,{value:`ssl`,children:e(`settings.email.securityOptions.ssl`)}),(0,Y.jsx)(`option`,{value:`none`,children:e(`settings.email.securityOptions.none`)})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:[e(`settings.email.fromEmail`)||`From Email`,` *`]}),(0,Y.jsx)(`input`,{type:`email`,value:i.smtp_from_email,onChange:e=>a({...i,smtp_from_email:e.target.value}),placeholder:`your@email.com`,className:D})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.fromName`)||`From Name`}),(0,Y.jsx)(`input`,{type:`text`,value:i.smtp_from_name,onChange:e=>a({...i,smtp_from_name:e.target.value}),placeholder:`BamBuddy`,className:D})]})]}),(0,Y.jsx)(`div`,{className:`flex gap-2`,children:(0,Y.jsx)(K,{onClick:C,disabled:b.isPending,className:`flex-1`,children:b.isPending?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}),e(`settings.email.saving`)||`Saving...`]}):e(`settings.email.save`)||`Save Settings`})})]})})]})}),(0,Y.jsx)(`div`,{children:(0,Y.jsxs)(G,{id:`card-email-test`,children:[(0,Y.jsx)(U,{children:(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.testConnection`)||`Test SMTP Connection`})}),(0,Y.jsx)(W,{children:(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.testRecipient`)||`Test Recipient Email`}),(0,Y.jsx)(`input`,{type:`email`,value:o,onChange:e=>s(e.target.value),placeholder:`test@example.com`,className:D})]}),(0,Y.jsx)(K,{onClick:w,disabled:x.isPending,variant:`secondary`,children:x.isPending?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}),e(`settings.email.sending`)||`Sending...`]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Sn,{className:`w-4 h-4`}),e(`settings.email.sendTest`)||`Send Test Email`]})})]})})]})})]})]})}var qi={starttls:`389`,ldaps:`636`};function Ji(){let{t:e}=l(),{showToast:t}=ee(),n=u(),{authEnabled:i}=un(),[a,o]=(0,X.useState)({ldap_server_url:``,ldap_bind_dn:``,ldap_bind_password:``,ldap_search_base:``,ldap_user_filter:`(sAMAccountName={username})`,ldap_security:`starttls`,ldap_group_mapping:``,ldap_auto_provision:!1,ldap_default_group:``}),{data:s,isLoading:c}=d({queryKey:[`settings`],queryFn:()=>r.getSettings()}),{data:p}=d({queryKey:[`ldapStatus`],queryFn:()=>r.getLDAPStatus()}),{data:m=[]}=d({queryKey:[`groups`],queryFn:()=>r.getGroups()});(0,X.useEffect)(()=>{s&&o({ldap_server_url:s.ldap_server_url||``,ldap_bind_dn:s.ldap_bind_dn||``,ldap_bind_password:``,ldap_search_base:s.ldap_search_base||``,ldap_user_filter:s.ldap_user_filter||`(sAMAccountName={username})`,ldap_security:s.ldap_security||`starttls`,ldap_group_mapping:s.ldap_group_mapping||``,ldap_auto_provision:s.ldap_auto_provision??!1,ldap_default_group:s.ldap_default_group||``})},[s]);let g=f({mutationFn:e=>r.updateSettings(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`settings`]}),n.invalidateQueries({queryKey:[`ldapStatus`]}),t(e(`settings.ldap.settingsSaved`)||`LDAP settings saved`,`success`)},onError:e=>{t(e.message,`error`)}}),_=f({mutationFn:e=>r.updateSettings({ldap_enabled:e}),onSuccess:()=>{n.invalidateQueries({queryKey:[`settings`]}),n.invalidateQueries({queryKey:[`ldapStatus`]}),t(p?.ldap_enabled?e(`settings.ldap.disabled`)||`LDAP authentication disabled`:e(`settings.ldap.enabled`)||`LDAP authentication enabled`,`success`)},onError:e=>{t(e.message,`error`)}}),v=f({mutationFn:()=>r.testLDAP(),onSuccess:e=>{t(e.message,e.success?`success`:`error`)},onError:e=>{t(e.message,`error`)}}),y=()=>{if(!a.ldap_server_url){t(e(`settings.ldap.errors.serverRequired`)||`LDAP server URL is required`,`error`);return}if(!a.ldap_search_base){t(e(`settings.ldap.errors.searchBaseRequired`)||`Search base DN is required`,`error`);return}let n={ldap_server_url:a.ldap_server_url,ldap_bind_dn:a.ldap_bind_dn,ldap_search_base:a.ldap_search_base,ldap_user_filter:a.ldap_user_filter,ldap_security:a.ldap_security,ldap_group_mapping:a.ldap_group_mapping,ldap_auto_provision:a.ldap_auto_provision,ldap_default_group:a.ldap_default_group};a.ldap_bind_password&&(n.ldap_bind_password=a.ldap_bind_password),g.mutate(n)},b=()=>{if(!i){t(e(`settings.ldap.errors.enableAuthFirst`)||`Enable authentication first`,`error`);return}if(!p?.ldap_enabled&&!p?.ldap_configured){t(e(`settings.ldap.errors.configureLdapFirst`)||`Save LDAP settings first`,`error`);return}_.mutate(!p?.ldap_enabled)};if(c)return(0,Y.jsx)(`div`,{className:`flex items-center justify-center p-12`,children:(0,Y.jsx)(L,{className:`w-8 h-8 animate-spin text-bambu-green`})});let x=p?.ldap_enabled??!1,S=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`;return(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(G,{id:`card-ldap-toggle`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Me,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.ldap.title`)||`LDAP Authentication`})]}),(0,Y.jsx)(K,{onClick:b,disabled:_.isPending,variant:x?`danger`:`primary`,children:x?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(h,{className:`w-4 h-4`}),e(`common.disable`)||`Disable`]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(R,{className:`w-4 h-4`}),e(`common.enable`)||`Enable`]})})]})}),(0,Y.jsx)(W,{children:x?(0,Y.jsx)(`div`,{className:`bg-green-50 dark:bg-green-500/10 border border-green-300 dark:border-green-500/30 rounded-lg p-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(j,{className:`w-5 h-5 text-green-600 dark:text-green-400 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.ldap.enabledDesc`)||`LDAP authentication is enabled`}),(0,Y.jsxs)(`ul`,{className:`text-sm text-green-700 dark:text-green-300 space-y-1 list-disc list-inside`,children:[(0,Y.jsx)(`li`,{children:e(`settings.ldap.feature1`)||`Users can login with LDAP credentials`}),(0,Y.jsx)(`li`,{children:e(`settings.ldap.feature2`)||`Local admin account remains as fallback`}),(0,Y.jsx)(`li`,{children:e(`settings.ldap.feature3`)||`LDAP groups are mapped to BamBuddy groups on login`})]})]})]})}):(0,Y.jsx)(`div`,{className:`bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded-lg p-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(Ie,{className:`w-5 h-5 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.ldap.disabledDesc`)||`LDAP authentication is disabled`}),(0,Y.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-300 mt-1`,children:e(`settings.ldap.disabledHint`)||`Configure and save LDAP settings below, then enable.`})]})]})})})]}),(0,Y.jsxs)(G,{id:`card-ldap-server`,children:[(0,Y.jsx)(U,{children:(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.ldap.serverConfig`)||`LDAP Server Configuration`})}),(0,Y.jsx)(W,{children:(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-3`,children:[(0,Y.jsxs)(`div`,{className:`md:col-span-2`,children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.serverUrl`)||`Server URL`}),(0,Y.jsx)(`input`,{type:`text`,className:S,placeholder:`ldaps://ldap.example.com:636`,value:a.ldap_server_url,onChange:e=>o({...a,ldap_server_url:e.target.value})}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.serverUrlHint`)||`Use ldaps:// for SSL or ldap:// with StartTLS`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.security`)||`Security`}),(0,Y.jsx)(`div`,{className:`flex gap-2`,children:[`starttls`,`ldaps`].map(e=>(0,Y.jsx)(`button`,{onClick:()=>o({...a,ldap_security:e}),className:`flex-1 px-2 py-2 rounded-lg text-sm font-medium transition-colors ${a.ldap_security===e?`bg-bambu-green text-black`:`bg-bambu-dark-secondary text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:e===`starttls`?`StartTLS`:`LDAPS`},e))}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.securityHint`)||`Default port: ${qi[a.ldap_security]}`})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.bindDn`)||`Bind DN (Service Account)`}),(0,Y.jsx)(`input`,{type:`text`,className:S,placeholder:`cn=service-account,ou=service,dc=example,dc=com`,value:a.ldap_bind_dn,onChange:e=>o({...a,ldap_bind_dn:e.target.value})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.bindPassword`)||`Bind Password`}),(0,Y.jsx)(`input`,{type:`password`,className:S,placeholder:s?.ldap_bind_dn?`••••••••`:``,value:a.ldap_bind_password,onChange:e=>o({...a,ldap_bind_password:e.target.value})})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.searchBase`)||`Search Base DN`}),(0,Y.jsx)(`input`,{type:`text`,className:S,placeholder:`ou=users,dc=example,dc=com`,value:a.ldap_search_base,onChange:e=>o({...a,ldap_search_base:e.target.value})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.userFilter`)||`User Search Filter`}),(0,Y.jsx)(`input`,{type:`text`,className:S,placeholder:`(sAMAccountName={username})`,value:a.ldap_user_filter,onChange:e=>o({...a,ldap_user_filter:e.target.value})})]})]}),(0,Y.jsx)(Rt,{summary:(0,Y.jsx)(`span`,{className:`text-sm font-medium text-bambu-gray`,children:e(`settings.ldap.advanced`)||`Advanced`}),className:`border-t border-bambu-dark-tertiary pt-3`,summaryClassName:`py-1`,children:(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white`,children:e(`settings.ldap.autoProvision`)||`Auto-provision users`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e(`settings.ldap.autoProvisionHint`)||`Automatically create a BamBuddy account on first LDAP login`})]}),(0,Y.jsx)(`button`,{onClick:()=>o({...a,ldap_auto_provision:!a.ldap_auto_provision}),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors flex-shrink-0 ${a.ldap_auto_provision?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,Y.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${a.ldap_auto_provision?`translate-x-6`:`translate-x-1`}`})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.defaultGroup`)||`Default group`}),(0,Y.jsxs)(`select`,{className:S,value:a.ldap_default_group,onChange:e=>o({...a,ldap_default_group:e.target.value}),children:[(0,Y.jsx)(`option`,{value:``,children:e(`settings.ldap.defaultGroupNone`)||`— None (reject login) —`}),m.map(e=>(0,Y.jsx)(`option`,{value:e.name,children:e.name},e.id))]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.defaultGroupHint`)||`Fallback group assigned when an LDAP user authenticates but is not listed in any mapped group. Leave empty to leave unmapped users without permissions.`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.groupMapping`)||`Group Mapping (JSON)`}),(0,Y.jsx)(`textarea`,{className:`${S} font-mono text-sm`,rows:4,placeholder:`{
  4. "CN=PrintFarm_Admins,OU=Groups,DC=example,DC=com": "Administrators",
  5. "CN=PrintFarm_Users,OU=Groups,DC=example,DC=com": "Operators"
  6. }`,value:a.ldap_group_mapping,onChange:e=>o({...a,ldap_group_mapping:e.target.value})}),(0,Y.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[e(`settings.ldap.groupMappingHint`)||`Map LDAP group DNs to BamBuddy groups. Available groups: `,m.map(e=>e.name).join(`, `)]})]})]})}),(0,Y.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,Y.jsxs)(K,{onClick:y,disabled:g.isPending,children:[g.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(j,{className:`w-4 h-4`}),e(`common.save`)||`Save`]}),(0,Y.jsxs)(K,{variant:`secondary`,onClick:()=>v.mutate(),disabled:v.isPending,children:[v.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Sn,{className:`w-4 h-4`}),e(`settings.ldap.testConnection`)||`Test Connection`]})]})]})})]})]})}var Yi=`__none__`,Xi=60,Zi=`px-3 py-2 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,Qi=e=>e.is_system&&e.name===`Administrators`,$i=e=>({restrict:e.restrict_printers,printerIds:[...e.printer_ids].sort((e,t)=>e-t),locations:[...e.locations??[]].sort()}),ea=(e,t)=>e.restrict===t.restrict&&e.printerIds.length===t.printerIds.length&&e.printerIds.every((e,n)=>e===t.printerIds[n])&&e.locations.length===t.locations.length&&e.locations.every((e,n)=>e===t.locations[n]),ta=e=>e.location||Yi;function na(e,t){return t.location&&e.locations.includes(t.location)?`location`:e.printerIds.includes(t.id)?`picked`:null}function ra(){let{t:e}=l(),t=u(),{showToast:n}=ee(),[i,a]=bt(),o=i.get(`view`)===`printers`?`printers`:`groups`,s=Number(i.get(`group`))||null,c=Number(i.get(`printer`))||null,p=e=>{a(t=>{let n=new URLSearchParams(t);for(let[t,r]of Object.entries(e))r===null?n.delete(t):n.set(t,r);return n},{replace:!0})},[m,h]=(0,X.useState)({}),[g,_]=(0,X.useState)(``),[v,y]=(0,X.useState)(`all`),[b,x]=(0,X.useState)(``),[S,C]=(0,X.useState)(`all`),[w,T]=(0,X.useState)(`all`),[D,O]=(0,X.useState)(`all`),[k,A]=(0,X.useState)({}),{data:j,isLoading:te}=d({queryKey:[`groups`],queryFn:()=>r.getGroups()}),{data:M,isLoading:N}=d({queryKey:[`printers`],queryFn:()=>r.getPrinters()}),{data:ne}=d({queryKey:[`users`],queryFn:()=>r.getUsers()}),re=e=>m[e.id]??$i(e),ie=(e,t)=>{h(n=>{let r=t(n[e.id]??$i(e)),i={restrict:r.restrict,printerIds:[...new Set(r.printerIds)].sort((e,t)=>e-t),locations:[...new Set(r.locations)].sort()},a={...n};return ea(i,$i(e))?delete a[e.id]:a[e.id]=i,a})},ae=(0,X.useMemo)(()=>(j??[]).filter(e=>m[e.id]!==void 0),[j,m]),oe=ae.length>0;(0,X.useEffect)(()=>{if(!oe)return;let e=e=>{e.preventDefault()};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[oe]);let P=f({mutationFn:async()=>{for(let e of ae){let t=m[e.id];await r.updateGroup(e.id,{restrict_printers:t.restrict,printer_ids:t.printerIds,locations:t.locations}),h(t=>{let n={...t};return delete n[e.id],n})}},onSuccess:()=>n(e(`printerAccess.saved`)),onError:e=>n(e.message,`error`),onSettled:()=>{t.invalidateQueries({queryKey:[`groups`]}),t.invalidateQueries({queryKey:[`group`]})}}),F=(0,X.useMemo)(()=>[...M??[]].sort((e,t)=>e.name.localeCompare(t.name)),[M]),I=(0,X.useMemo)(()=>{let e=new Set;for(let t of F)t.location&&e.add(t.location);return[...e].sort((e,t)=>e.localeCompare(t))},[F]),R=F.some(e=>!e.location),se=(0,X.useMemo)(()=>{let e=new Set;for(let t of F)t.model&&e.add(t.model);return[...e].sort()},[F]),ce=(0,X.useMemo)(()=>{let e=new Map;for(let t of F){let n=ta(t);e.set(n,[...e.get(n)??[],t])}return e},[F]),z=(0,X.useMemo)(()=>{let e=b.trim().toLowerCase();return F.filter(t=>S!==`all`&&ta(t)!==S||w!==`all`&&t.model!==w?!1:e?t.name.toLowerCase().includes(e)||(t.model??``).toLowerCase().includes(e)||t.serial_number.toLowerCase().includes(e)||(t.location??``).toLowerCase().includes(e):!0)},[F,b,S,w]),B=(0,X.useMemo)(()=>[...j??[]].sort((e,t)=>e.name.localeCompare(t.name)),[j]),le=g.trim().toLowerCase(),V=B.filter(e=>{if(le&&!e.name.toLowerCase().includes(le))return!1;let t=!Qi(e)&&re(e).restrict;return v===`limited`?t:v===`open`?!t:!0}),ue=B.filter(e=>!Qi(e)&&re(e).restrict),de=e=>F.filter(t=>na(e,t)!==null).length;if(te||N)return(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,Y.jsx)(L,{className:`w-8 h-8 text-bambu-green animate-spin`})});let fe=B.find(e=>e.id===s)??null,pe=t=>(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 min-w-[12rem]`,children:[(0,Y.jsx)(Ae,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,Y.jsx)(`input`,{type:`text`,value:b,onChange:e=>x(e.target.value),placeholder:e(`printerAccess.searchPrinters`),"aria-label":e(`printerAccess.searchPrinters`),className:`${Zi} w-full pl-9`})]}),(0,Y.jsxs)(`select`,{value:S,onChange:e=>C(e.target.value),"aria-label":e(`printerAccess.allLocations`),className:Zi,children:[(0,Y.jsx)(`option`,{value:`all`,children:e(`printerAccess.allLocations`)}),I.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e)),R&&(0,Y.jsx)(`option`,{value:Yi,children:e(`printerAccess.noLocation`)})]}),se.length>1&&(0,Y.jsxs)(`select`,{value:w,onChange:e=>T(e.target.value),"aria-label":e(`printerAccess.allModels`),className:Zi,children:[(0,Y.jsx)(`option`,{value:`all`,children:e(`printerAccess.allModels`)}),se.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]}),t&&(0,Y.jsxs)(`select`,{value:D,onChange:e=>O(e.target.value),"aria-label":e(`printerAccess.accessFilter`),className:Zi,children:[(0,Y.jsx)(`option`,{value:`all`,children:e(`printerAccess.accessAll`)}),(0,Y.jsx)(`option`,{value:`with`,children:e(`printerAccess.accessWith`)}),(0,Y.jsx)(`option`,{value:`without`,children:e(`printerAccess.accessWithout`)})]})]});return(0,Y.jsxs)(`div`,{className:`space-y-4 max-w-6xl`,id:`card-printer-access`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`printerAccess.intro`)}),(0,Y.jsx)(`div`,{className:`flex gap-1 p-1 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary w-fit`,children:[`groups`,`printers`].map(t=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>p({view:t===`groups`?null:`printers`}),className:`px-3 py-1.5 text-sm rounded-md transition-colors ${o===t?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:e(t===`groups`?`printerAccess.byGroup`:`printerAccess.byPrinter`)},t))}),o===`groups`?(0,Y.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 items-start`,children:[(0,Y.jsxs)(G,{className:`lg:w-80 shrink-0 flex flex-col lg:max-h-[calc(100vh-14rem)]`,children:[(0,Y.jsxs)(`div`,{className:`p-3 space-y-2 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ae,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,Y.jsx)(`input`,{type:`text`,value:g,onChange:e=>_(e.target.value),placeholder:e(`printerAccess.searchGroups`),"aria-label":e(`printerAccess.searchGroups`),className:`${Zi} w-full pl-9`})]}),(0,Y.jsx)(`div`,{className:`flex gap-1`,children:[`all`,`limited`,`open`].map(t=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>y(t),className:`flex-1 px-2 py-1 text-xs rounded-md transition-colors ${v===t?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:e(`printerAccess.groupFilter.${t}`)},t))})]}),(0,Y.jsx)(`div`,{className:`overflow-y-auto p-1`,children:V.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray p-3`,children:e(`printerAccess.noGroupsMatch`)}):V.map(t=>{let n=re(t),r=Qi(t),i=r?e(`printerAccess.alwaysAll`):n.restrict?e(`printerAccess.reachShort`,{count:de(n),total:F.length}):e(`printerAccess.notLimited`);return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>p({group:String(t.id)}),className:`w-full text-left px-3 py-2 rounded-lg transition-colors ${t.id===s?`bg-bambu-dark-tertiary`:`hover:bg-bambu-dark-tertiary/60`}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white truncate flex-1`,children:t.name}),m[t.id]&&(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-yellow-400 shrink-0`,title:e(`printerAccess.unsaved`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray mt-0.5`,children:[(0,Y.jsx)(Ze,{className:`w-3 h-3 shrink-0`}),(0,Y.jsx)(`span`,{children:t.user_count}),(0,Y.jsx)(`span`,{children:`·`}),(0,Y.jsx)(`span`,{className:!r&&n.restrict?`text-bambu-green`:``,children:i})]})]},t.id)})})]}),(()=>{if(!fe)return(0,Y.jsx)(G,{className:`flex-1 p-8 text-center text-sm text-bambu-gray`,children:e(`printerAccess.pickGroup`)});let t=fe,n=re(t),r=de(n),i=z.filter(e=>{let t=na(n,e);return D===`with`?t!==null:D===`without`?t===null:!0}),a=new Map;for(let e of i){let t=ta(e);a.set(t,[...a.get(t)??[],e])}let o=[...a.keys()].sort((e,t)=>e===Yi?1:t===Yi?-1:e.localeCompare(t)),s=n.locations.filter(e=>!ce.has(e)),c=i.length>Xi&&!b.trim(),l=e=>k[e]??!c,u=(e,n)=>ie(t,t=>({...t,locations:n?[...t.locations,e]:t.locations.filter(t=>t!==e)})),d=(e,n)=>ie(t,t=>({...t,printerIds:n?[...t.printerIds,e]:t.printerIds.filter(t=>t!==e)})),f=e=>{let r=i.filter(e=>na(n,e)!==`location`).map(e=>e.id);ie(t,t=>({...t,printerIds:e?[...t.printerIds,...r]:t.printerIds.filter(e=>!r.includes(e))}))};return(0,Y.jsx)(G,{className:`flex-1 min-w-0`,children:(0,Y.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`h3`,{className:`text-white font-medium truncate`,children:t.name}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e(`printerAccess.memberCount`,{count:t.user_count})})]}),(0,Y.jsxs)(ft,{to:`/groups/${t.id}/edit`,className:`flex items-center gap-1.5 text-xs text-bambu-gray hover:text-white shrink-0`,children:[(0,Y.jsx)(Ke,{className:`w-3.5 h-3.5`}),e(`printerAccess.editGroup`)]})]}),Qi(t)?(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`printerAccess.adminsSeeAll`)}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:e(`printerAccess.limit`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`printerAccess.limitHint`)})]}),(0,Y.jsx)(J,{checked:n.restrict,onChange:e=>ie(t,t=>({...t,restrict:e}))})]}),n.restrict&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`printerAccess.reach`,{count:r,total:F.length})}),r===0&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5 text-xs text-yellow-700 dark:text-yellow-400`,children:[(0,Y.jsx)(Ie,{className:`w-3.5 h-3.5 shrink-0`}),e(`printerAccess.noneGranted`)]})]}),F.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`printerAccess.noPrinters`)}):(0,Y.jsxs)(Y.Fragment,{children:[pe(!0),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(K,{size:`sm`,variant:`ghost`,onClick:()=>f(!0),disabled:i.length===0,children:e(`printerAccess.tickShown`)}),(0,Y.jsx)(K,{size:`sm`,variant:`ghost`,onClick:()=>f(!1),disabled:i.length===0,children:e(`printerAccess.untickShown`)})]}),s.map(t=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-3 py-2 rounded-lg border border-dashed border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-2 text-sm text-bambu-gray min-w-0`,children:[(0,Y.jsx)(H,{className:`w-4 h-4 shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate`,children:t}),(0,Y.jsxs)(`span`,{className:`text-xs`,children:[`(`,e(`printerAccess.emptyLocation`),`)`]})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-bambu-gray cursor-pointer shrink-0`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:!0,onChange:()=>u(t,!1),"aria-label":e(`printerAccess.wholeLocationHint`,{location:t}),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary`}),e(`printerAccess.wholeLocation`)]})]},`stale-${t}`)),o.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray py-4 text-center`,children:e(`printerAccess.noPrintersMatch`)}):(0,Y.jsx)(`div`,{className:`space-y-2`,children:o.map(t=>{let r=a.get(t)??[],i=ce.get(t)??[],o=i.filter(e=>na(n,e)!==null).length,s=t!==Yi,c=s&&n.locations.includes(t),f=l(t);return(0,Y.jsxs)(`div`,{className:`rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>A(e=>({...e,[t]:!f})),className:`flex items-center gap-2 flex-1 min-w-0 text-left`,"aria-expanded":f,children:[f?(0,Y.jsx)(E,{className:`w-4 h-4 text-bambu-gray shrink-0`}):(0,Y.jsx)(st,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,Y.jsx)(H,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,Y.jsx)(`span`,{className:`text-sm text-white truncate`,children:s?t:e(`printerAccess.noLocation`)}),(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray tabular-nums shrink-0`,children:[o,`/`,i.length]})]}),s&&(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-bambu-gray cursor-pointer shrink-0`,title:e(`printerAccess.wholeLocationHint`,{location:t}),children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:c,onChange:e=>u(t,e.target.checked),"aria-label":e(`printerAccess.wholeLocationHint`,{location:t}),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary`}),e(`printerAccess.wholeLocation`)]})]}),f&&(0,Y.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-1 px-2 pb-2`,children:r.map(t=>{let r=na(n,t);return(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded ${r===`location`?`cursor-default`:`cursor-pointer hover:bg-bambu-dark-tertiary/60`}`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:r!==null,disabled:r===`location`,onChange:e=>d(t.id,e.target.checked),"aria-label":t.name,className:`w-4 h-4 shrink-0 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary disabled:opacity-60`}),(0,Y.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`span`,{className:`block text-sm text-white truncate`,children:t.name}),(0,Y.jsx)(`span`,{className:`block text-xs text-bambu-gray truncate`,children:[t.model,t.serial_number].filter(Boolean).join(` · `)})]}),r===`location`&&(0,Y.jsx)(`span`,{className:`text-xs text-bambu-green shrink-0`,children:e(`printerAccess.viaLocation`)})]},t.id)})})]},t)})})]})]})]})]})})})()]}):(()=>{let t=new Set(ue.map(e=>e.id)),n=(ne??[]).filter(e=>e.is_active&&!e.is_admin&&!e.groups.some(e=>t.has(e.id))),r=c?F.filter(e=>e.id===c):z;return(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(G,{children:(0,Y.jsxs)(`div`,{className:`p-4 space-y-1 text-sm`,children:[(0,Y.jsx)(`p`,{className:`text-bambu-gray`,children:e(`printerAccess.alsoVisible`)}),ne&&(0,Y.jsx)(`p`,{className:n.length>0?`text-yellow-700 dark:text-yellow-400`:`text-bambu-gray`,children:n.length>0?e(`printerAccess.openUsers`,{names:n.slice(0,10).map(e=>e.username).join(`, `)+(n.length>10?` +${n.length-10}`:``)}):e(`printerAccess.noOpenUsers`)})]})}),ue.length===0&&(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`printerAccess.noLimitedGroups`)}),c?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Y.jsx)(`span`,{children:e(`printerAccess.showingOne`)}),(0,Y.jsx)(K,{size:`sm`,variant:`ghost`,onClick:()=>p({printer:null}),children:e(`printerAccess.showAll`)})]}):pe(!1),r.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray py-4 text-center`,children:F.length===0?e(`printerAccess.noPrinters`):e(`printerAccess.noPrintersMatch`)}):(0,Y.jsx)(G,{children:(0,Y.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:r.map(t=>{let n=ue.map(e=>({group:e,reach:na(re(e),t)})).filter(e=>e.reach!==null),r=ue.filter(e=>na(re(e),t)===null);return(0,Y.jsxs)(`div`,{className:`flex flex-col md:flex-row md:items-center gap-2 md:gap-4 px-4 py-3`,children:[(0,Y.jsxs)(`div`,{className:`md:w-64 shrink-0 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(it,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,Y.jsx)(`span`,{className:`text-sm text-white truncate`,children:t.name})]}),(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray truncate pl-6`,children:[t.model,t.location||e(`printerAccess.noLocation`)].filter(Boolean).join(` · `)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 flex-1 min-w-0`,children:[n.map(({group:n,reach:r})=>r===`location`?(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>p({view:null,group:String(n.id),printer:null}),title:e(`printerAccess.viaLocationTitle`,{location:t.location}),className:`flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-green/10 text-bambu-green border border-bambu-green/30`,children:[(0,Y.jsx)(H,{className:`w-3 h-3`}),n.name]},n.id):(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 pl-2 pr-1 py-0.5 rounded-full text-xs bg-bambu-green/20 text-bambu-green`,children:[n.name,(0,Y.jsx)(`button`,{type:`button`,onClick:()=>ie(n,e=>({...e,printerIds:e.printerIds.filter(e=>e!==t.id)})),"aria-label":e(`printerAccess.removeGroup`,{group:n.name}),className:`p-0.5 rounded-full hover:bg-bambu-green/30`,children:(0,Y.jsx)(Re,{className:`w-3 h-3`})})]},n.id)),n.length===0&&ue.length>0&&(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e(`printerAccess.noLimitedGroupReaches`)})]}),r.length>0&&(0,Y.jsxs)(`select`,{value:``,onChange:e=>{let n=ue.find(t=>t.id===Number(e.target.value));n&&ie(n,e=>({...e,printerIds:[...e.printerIds,t.id]}))},"aria-label":e(`printerAccess.addGroup`),className:`${Zi} md:w-48 shrink-0`,children:[(0,Y.jsx)(`option`,{value:``,children:e(`printerAccess.addGroup`)}),r.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]},t.id)})})})]})})(),oe&&(0,Y.jsxs)(`div`,{className:`sticky bottom-0 z-20 flex flex-wrap items-center justify-between gap-3 px-4 py-3 rounded-xl bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-lg`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:e(`printerAccess.changedGroups`,{names:ae.map(e=>e.name).join(`, `)})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:()=>h({}),disabled:P.isPending,children:e(`printerAccess.discard`)}),(0,Y.jsxs)(K,{onClick:()=>P.mutate(),disabled:P.isPending,children:[P.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(_t,{className:`w-4 h-4`}),e(`common.save`)]})]})]})]})}function ia({value:e,onChange:t,placeholder:n,maxLength:r=6}){return(0,Y.jsx)(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value.toUpperCase().replace(/\s/g,``)),maxLength:r,className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors font-mono tracking-widest text-center`,placeholder:n,autoComplete:`one-time-code`})}function aa({codes:e,onDone:t}){let{t:n}=l(),[r,i]=(0,X.useState)(!1);return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(`div`,{className:`bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded-lg p-4`,children:(0,Y.jsx)(`p`,{className:`text-amber-700 dark:text-amber-400 text-sm font-medium`,children:n(`settings.twoFa.backupCodesWarning`)})}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:e.map((e,t)=>(0,Y.jsx)(`code`,{className:`bg-bambu-dark-secondary rounded px-3 py-2 text-center font-mono text-sm text-white tracking-widest`,children:e},t))}),(0,Y.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:()=>{navigator.clipboard.writeText(e.join(`
  7. `)),i(!0),setTimeout(()=>i(!1),2e3)},className:`flex items-center gap-2`,children:[(0,Y.jsx)(M,{className:`w-4 h-4`}),n(r?`common.copied`:`common.copy`)]}),(0,Y.jsx)(K,{variant:`primary`,size:`sm`,onClick:t,className:`flex-1`,children:n(`settings.twoFa.savedCodes`)})]})]})}function oa({onDone:e}){let{t}=l(),n=u(),{showToast:i}=ee(),[a,o]=(0,X.useState)(`qr`),[s,c]=(0,X.useState)(``),[p,m]=(0,X.useState)([]),[h,g]=(0,X.useState)(!1),{data:_,isLoading:v}=d({queryKey:[`totp-setup`],queryFn:()=>r.setupTOTP(),staleTime:1/0}),y=f({mutationFn:e=>r.enableTOTP(e),onSuccess:e=>{m(e.backup_codes),o(`backup`),n.invalidateQueries({queryKey:[`2fa-status`]})},onError:()=>i(t(`settings.twoFa.invalidCode`),`error`)});return v||!_?(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,Y.jsx)(at,{className:`w-6 h-6 animate-spin text-bambu-green`})}):a===`qr`?(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:t(`settings.twoFa.setupInstructions`)}),(0,Y.jsx)(`div`,{className:`flex justify-center`,children:(0,Y.jsx)(`img`,{src:`data:image/png;base64,${_.qr_code_b64}`,alt:`TOTP QR Code`,className:`w-48 h-48 rounded-lg`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:t(`settings.twoFa.manualEntry`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 bg-bambu-dark-secondary rounded-lg px-3 py-2`,children:[(0,Y.jsx)(`code`,{className:`text-white text-xs font-mono flex-1 break-all`,children:h?_.secret:`••••••••••••••••`}),(0,Y.jsx)(`button`,{onClick:()=>g(!h),className:`text-bambu-gray hover:text-white`,children:h?(0,Y.jsx)(re,{className:`w-4 h-4`}):(0,Y.jsx)(mt,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(_.secret)},className:`text-bambu-gray hover:text-white`,children:(0,Y.jsx)(M,{className:`w-4 h-4`})})]})]}),(0,Y.jsx)(K,{variant:`primary`,className:`w-full`,onClick:()=>o(`confirm`),children:t(`settings.twoFa.scannedContinue`)})]}):a===`confirm`?(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:t(`settings.twoFa.enterCodeToConfirm`)}),(0,Y.jsx)(ia,{value:s,onChange:c,placeholder:`000000`}),(0,Y.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:()=>o(`qr`),className:`flex-1`,children:t(`common.back`)}),(0,Y.jsx)(K,{variant:`primary`,className:`flex-1`,disabled:s.length!==6||y.isPending,onClick:()=>y.mutate(s),children:y.isPending?t(`common.saving`):t(`settings.twoFa.activate`)})]})]}):(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(`h3`,{className:`text-white font-medium`,children:t(`settings.twoFa.backupCodesTitle`)}),(0,Y.jsx)(aa,{codes:p,onDone:e})]})}function sa(){let{t:e}=l(),t=u(),{showToast:n}=ee(),{user:i}=un(),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(!1),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(``),[_,v]=(0,X.useState)(``),[y,b]=(0,X.useState)(null),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(``),[T,E]=(0,X.useState)(!1),[D,O]=(0,X.useState)(``),[k,A]=(0,X.useState)(!1),{data:j,isLoading:te}=d({queryKey:[`2fa-status`],queryFn:()=>r.get2FAStatus()}),{data:M}=d({queryKey:[`oidc-links`],queryFn:()=>r.getOIDCLinks()}),N=f({mutationFn:()=>r.enableEmailOTP(),onSuccess:e=>{S(e.setup_token),n(e.message,`success`)},onError:t=>{let r=t.message??``;r.toLowerCase().includes(`smtp`)?n(e(`settings.twoFa.smtpRequired`),`error`):n(r,`error`)}}),ne=f({mutationFn:()=>r.confirmEnableEmailOTP(x,C),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),S(null),w(``),n(e(`settings.twoFa.emailOtpEnabled`),`success`)},onError:e=>n(e.message,`error`)}),ie=f({mutationFn:e=>r.disableEmailOTP(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),E(!1),O(``),n(e(`settings.twoFa.emailOtpDisabled`),`success`)},onError:e=>n(e.message,`error`)}),ae=f({mutationFn:e=>r.disableTOTP(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),c(!1),g(``),n(e(`settings.twoFa.totpDisabled`),`success`)},onError:()=>n(e(`settings.twoFa.invalidCode`),`error`)}),oe=f({mutationFn:e=>r.regenerateBackupCodes(e),onSuccess:e=>{t.invalidateQueries({queryKey:[`2fa-status`]}),m(!1),v(``),b(e.backup_codes)},onError:()=>n(e(`settings.twoFa.invalidCode`),`error`)}),P=f({mutationFn:e=>r.deleteOIDCLink(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-links`]}),n(e(`settings.twoFa.oidcUnlinked`),`success`)},onError:e=>n(e.message,`error`)});if(te)return(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,Y.jsx)(at,{className:`w-6 h-6 animate-spin text-bambu-green`})});let F=!!i?.email;return(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsxs)(G,{id:`card-2fa-totp`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${j?.totp_enabled?`bg-green-100 dark:bg-green-500/20`:`bg-gray-500/20`}`,children:(0,Y.jsx)(Pe,{className:`w-5 h-5 ${j?.totp_enabled?`text-green-600 dark:text-green-400`:`text-gray-400`}`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.totpTitle`)}),(0,Y.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.twoFa.totpDesc`)})]}),(0,Y.jsx)(`div`,{className:`ml-auto`,children:j?.totp_enabled?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700 dark:text-green-400 text-sm font-medium`,children:[(0,Y.jsx)(Cn,{className:`w-4 h-4`}),` `,e(`common.enabled`)]}):(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray text-sm`,children:[(0,Y.jsx)(wn,{className:`w-4 h-4`}),` `,e(`common.disabled`)]})})]})}),(0,Y.jsx)(W,{children:a?(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsx)(`h4`,{className:`text-white font-medium`,children:e(`settings.twoFa.setupAuthApp`)}),(0,Y.jsx)(`button`,{onClick:()=>{o(!1),t.removeQueries({queryKey:[`totp-setup`]})},className:`text-bambu-gray hover:text-white`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsx)(oa,{onDone:()=>{o(!1),t.removeQueries({queryKey:[`totp-setup`]})}})]}):s?(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.disableConfirmHint`)}),(0,Y.jsx)(ia,{value:h,onChange:g,placeholder:`000000 or XXXXXXXX`,maxLength:8}),(0,Y.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:()=>{c(!1),g(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,Y.jsx)(K,{variant:`danger`,className:`flex-1`,disabled:h.length<6||ae.isPending,onClick:()=>ae.mutate(h),children:ae.isPending?e(`common.saving`):e(`settings.twoFa.disableTotp`)})]})]}):p?(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.regenBackupHint`)}),(0,Y.jsx)(ia,{value:_,onChange:v,placeholder:`000000 or XXXXXXXX`,maxLength:8}),(0,Y.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:()=>{m(!1),v(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,Y.jsx)(K,{variant:`primary`,className:`flex-1`,disabled:_.length<6||oe.isPending,onClick:()=>oe.mutate(_),children:oe.isPending?e(`common.saving`):e(`settings.twoFa.regenBackup`)})]})]}):y?(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(`h4`,{className:`text-white font-medium`,children:e(`settings.twoFa.newBackupCodes`)}),(0,Y.jsx)(aa,{codes:y,onDone:()=>b(null)})]}):(0,Y.jsx)(`div`,{className:`space-y-3`,children:j?.totp_enabled?(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray-light`,children:[(0,Y.jsx)(Kt,{className:`w-4 h-4`}),e(`settings.twoFa.backupCodesRemaining`,{count:j.backup_codes_remaining})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:()=>m(!0),className:`flex items-center gap-2`,children:[(0,Y.jsx)(at,{className:`w-4 h-4`}),e(`settings.twoFa.regenBackup`)]}),(0,Y.jsxs)(K,{variant:`danger`,size:`sm`,onClick:()=>c(!0),className:`flex items-center gap-2`,children:[(0,Y.jsx)(qe,{className:`w-4 h-4`}),e(`settings.twoFa.disableTotp`)]})]}):(0,Y.jsxs)(K,{variant:`primary`,onClick:()=>o(!0),className:`flex items-center gap-2`,children:[(0,Y.jsx)(Pe,{className:`w-4 h-4`}),e(`settings.twoFa.setupTotp`)]})})})]}),(0,Y.jsxs)(G,{id:`card-2fa-emailotp`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${j?.email_otp_enabled?`bg-green-100 dark:bg-green-500/20`:`bg-gray-500/20`}`,children:(0,Y.jsx)(Vt,{className:`w-5 h-5 ${j?.email_otp_enabled?`text-green-600 dark:text-green-400`:`text-gray-400`}`})}),(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.emailOtpTitle`)}),(0,Y.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:F?e(`settings.twoFa.emailOtpDesc`,{email:i?.email}):e(`settings.twoFa.emailOtpNoEmail`)})]}),(0,Y.jsx)(`div`,{className:`ml-auto`,children:j?.email_otp_enabled?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700 dark:text-green-400 text-sm font-medium`,children:[(0,Y.jsx)(Cn,{className:`w-4 h-4`}),` `,e(`common.enabled`)]}):(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray text-sm`,children:[(0,Y.jsx)(wn,{className:`w-4 h-4`}),` `,e(`common.disabled`)]})})]})}),(0,Y.jsx)(W,{children:F?x?(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.emailSetupEnterCode`)}),(0,Y.jsx)(ia,{value:C,onChange:w,placeholder:`000000`}),(0,Y.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:()=>{S(null),w(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,Y.jsx)(K,{variant:`primary`,className:`flex-1`,disabled:C.length!==6||ne.isPending,onClick:()=>ne.mutate(),children:ne.isPending?e(`common.saving`):e(`settings.twoFa.verifyAndEnable`)})]})]}):T?(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.emailDisablePasswordHint`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`input`,{type:k?`text`:`password`,value:D,onChange:e=>O(e.target.value),placeholder:e(`settings.twoFa.passwordPlaceholder`),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>A(!k),className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:k?(0,Y.jsx)(re,{className:`w-5 h-5`}):(0,Y.jsx)(mt,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:()=>{E(!1),O(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,Y.jsx)(K,{variant:`danger`,className:`flex-1`,disabled:!D||ie.isPending,onClick:()=>ie.mutate(D),children:ie.isPending?e(`common.saving`):e(`settings.twoFa.disableEmailOtp`)})]})]}):(0,Y.jsx)(`div`,{className:`flex gap-3`,children:j?.email_otp_enabled?(0,Y.jsxs)(K,{variant:`danger`,size:`sm`,onClick:()=>E(!0),className:`flex items-center gap-2`,children:[(0,Y.jsx)(qe,{className:`w-4 h-4`}),e(`settings.twoFa.disableEmailOtp`)]}):(0,Y.jsxs)(K,{variant:`primary`,disabled:!F||N.isPending,onClick:()=>N.mutate(),className:`flex items-center gap-2`,children:[(0,Y.jsx)(Vt,{className:`w-4 h-4`}),N.isPending?e(`common.saving`):e(`settings.twoFa.enableEmailOtp`)]})}):(0,Y.jsx)(`p`,{className:`text-amber-700 dark:text-amber-400 text-sm`,children:e(`settings.twoFa.addEmailFirst`)})})]}),M&&M.length>0&&(0,Y.jsxs)(G,{id:`card-2fa-linked`,children:[(0,Y.jsxs)(U,{children:[(0,Y.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.linkedAccounts`)}),(0,Y.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.twoFa.linkedAccountsDesc`)})]}),(0,Y.jsx)(W,{children:(0,Y.jsx)(`div`,{className:`space-y-3`,children:M.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between py-2 border-b border-bambu-dark-tertiary last:border-0`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white text-sm font-medium`,children:e.provider_name}),e.provider_email&&(0,Y.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:e.provider_email})]}),(0,Y.jsx)(K,{variant:`danger`,size:`sm`,onClick:()=>P.mutate(e.provider_id),disabled:P.isPending,children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]},e.id))})})]})]})}var ca={name:``,issuer_url:``,client_id:``,client_secret:``,scopes:`openid email profile`,is_enabled:!0,auto_create_users:!1,auto_link_existing_accounts:!1,email_claim:`email`,require_email_verified:!0,group_claim:`groups`,group_mapping:{},icon_url:void 0,default_group_id:null,is_autologin:!1};function la({initial:e,isEdit:t=!1,groups:n=[],onSave:r,onCancel:i,isPending:a}){let{t:o}=l(),[s,c]=(0,X.useState)(e),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(()=>Object.entries(e.group_mapping??{}).map(([e,t])=>({idpGroup:e,bambuddyGroup:t}))),m=()=>p(e=>[...e,{idpGroup:``,bambuddyGroup:``}]),h=e=>p(t=>t.filter((t,n)=>n!==e)),g=(e,t)=>p(n=>n.map((n,r)=>r===e?{...n,...t}:n)),_=(e,t)=>c(n=>({...n,[e]:t})),v=`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors text-sm`,y=`block text-sm font-medium text-white mb-1`,b=()=>{let e={...s};t&&!u&&delete e.client_secret,(!e.group_claim||!e.group_claim.trim())&&(e.group_claim=`groups`);let n={};for(let e of f){let t=e.idpGroup.trim();t&&e.bambuddyGroup&&(n[t]=e.bambuddyGroup)}e.group_mapping=n,r(e)},x=new Set(n.map(e=>e.name)),S=f.map((e,t)=>{let n=e.idpGroup.trim();if(!n&&!e.bambuddyGroup)return null;if(!n||!e.bambuddyGroup)return`incomplete`;let r=n.toLowerCase();return f.slice(0,t).some(e=>e.idpGroup.trim().toLowerCase()===r)?`duplicate`:null}),C=S.some(e=>e!==null),w=s.auto_link_existing_accounts===!0,T=s.require_email_verified??!0,E;return E=w?o(`settings.oidc.form.requireEmailVerifiedAutoLink`):T?o(`settings.oidc.form.requireEmailVerifiedDesc`):(0,Y.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:o(`settings.oidc.form.requireEmailVerifiedWarning`)}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:y,children:[o(`settings.oidc.form.name`),` `,(0,Y.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,Y.jsx)(`input`,{className:v,value:s.name,onChange:e=>_(`name`,e.target.value),placeholder:`Google`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:y,children:[o(`settings.oidc.form.issuerUrl`),` `,(0,Y.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,Y.jsx)(`input`,{className:v,value:s.issuer_url,onChange:e=>_(`issuer_url`,e.target.value),placeholder:`https://accounts.google.com`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:y,children:[o(`settings.oidc.form.clientId`),` `,(0,Y.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,Y.jsx)(`input`,{className:v,value:s.client_id,onChange:e=>_(`client_id`,e.target.value),placeholder:`your-client-id`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:y,children:[o(`settings.oidc.form.clientSecret`),!t&&(0,Y.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:` *`}),t&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray text-xs ml-1`,children:[`(`,o(`settings.oidc.form.secretHint`),`)`]})]}),(0,Y.jsx)(`input`,{className:v,type:`password`,value:u?s.client_secret:``,placeholder:t&&!u?`••••••••`:o(`settings.oidc.form.secretPlaceholder`),onChange:e=>{d(!0),_(`client_secret`,e.target.value)}})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:y,children:o(`settings.oidc.form.scopes`)}),(0,Y.jsx)(`input`,{className:v,value:s.scopes,onChange:e=>_(`scopes`,e.target.value),placeholder:`openid email profile`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:y,children:o(`settings.oidc.form.iconUrl`)}),(0,Y.jsx)(`input`,{className:v,value:s.icon_url??``,onChange:e=>_(`icon_url`,e.target.value===``?null:e.target.value),placeholder:`https://...`})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-6 pt-2`,children:[(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(J,{checked:s.is_enabled??!0,onChange:e=>_(`is_enabled`,e)}),(0,Y.jsx)(`span`,{className:`text-white text-sm`,children:o(`settings.oidc.form.enabled`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(J,{checked:s.auto_create_users??!1,onChange:e=>_(`auto_create_users`,e)}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.autoCreate`)}),(0,Y.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:o(`settings.oidc.form.autoCreateDesc`)})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer w-full`,children:[(0,Y.jsx)(J,{checked:s.auto_link_existing_accounts??!1,onChange:e=>_(`auto_link_existing_accounts`,e)}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.autoLink`)}),(0,Y.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:o(`settings.oidc.form.autoLinkDesc`)})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer w-full`,children:[(0,Y.jsx)(J,{checked:T,onChange:e=>_(`require_email_verified`,e),disabled:w}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.requireEmailVerified`)}),(0,Y.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:E})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer w-full`,children:[(0,Y.jsx)(J,{checked:s.is_autologin??!1,onChange:e=>_(`is_autologin`,e)}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.autologin`)}),(0,Y.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:o(`settings.oidc.form.autologinDesc`)})]})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:y,children:o(`settings.oidc.form.emailClaim`)}),(0,Y.jsx)(`input`,{className:v,value:s.email_claim,onChange:e=>_(`email_claim`,e.target.value||`email`),placeholder:o(`settings.oidc.form.emailClaimPlaceholder`)}),(0,Y.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:o(`settings.oidc.form.emailClaimDesc`)}),w&&s.email_claim!==`email`&&(0,Y.jsx)(`p`,{className:`text-yellow-700 dark:text-yellow-400 text-xs mt-1`,children:o(`settings.oidc.form.emailClaimCustomClaimAutoLinkWarning`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:y,children:o(`settings.oidc.form.defaultGroup`)}),(0,Y.jsxs)(`select`,{className:v,value:s.default_group_id??``,onChange:e=>_(`default_group_id`,e.target.value?Number(e.target.value):null),children:[(0,Y.jsx)(`option`,{value:``,children:o(`settings.oidc.form.defaultGroupViewersFallback`)}),n.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,Y.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:o(`settings.oidc.form.defaultGroupDesc`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:y,children:o(`settings.oidc.form.groupClaim`)}),(0,Y.jsx)(`input`,{className:v,value:s.group_claim??`groups`,onChange:e=>_(`group_claim`,e.target.value),placeholder:`groups`}),(0,Y.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:o(`settings.oidc.form.groupClaimDesc`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:y,children:o(`settings.oidc.form.groupMapping`)}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[f.map((e,t)=>{let r=e.bambuddyGroup!==``&&!x.has(e.bambuddyGroup);return(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`input`,{className:v,value:e.idpGroup,onChange:e=>g(t,{idpGroup:e.target.value}),placeholder:o(`settings.oidc.form.groupMappingIdpGroupPlaceholder`)}),(0,Y.jsx)(`span`,{className:`text-bambu-gray text-sm shrink-0`,children:`→`}),(0,Y.jsxs)(`select`,{className:`${v} ${r?`border-red-700 dark:border-red-400 text-red-700 dark:text-red-400`:``}`,value:e.bambuddyGroup,onChange:e=>g(t,{bambuddyGroup:e.target.value}),children:[(0,Y.jsx)(`option`,{value:``,children:o(`settings.oidc.form.groupMappingSelectGroup`)}),r&&(0,Y.jsx)(`option`,{value:e.bambuddyGroup,children:o(`settings.oidc.form.groupMappingDeletedGroupOption`,{group:e.bambuddyGroup})}),n.map(e=>(0,Y.jsx)(`option`,{value:e.name,children:e.name},e.id))]}),(0,Y.jsx)(K,{variant:`secondary`,size:`sm`,onClick:()=>h(t),title:o(`common.remove`),children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]}),r&&(0,Y.jsx)(`p`,{className:`text-red-700 dark:text-red-400 text-xs mt-1`,children:o(`settings.oidc.form.groupMappingDeletedGroupWarning`)}),S[t]&&(0,Y.jsx)(`p`,{className:`text-red-700 dark:text-red-400 text-xs mt-1`,children:S[t]===`incomplete`?o(`settings.oidc.form.groupMappingIncompleteRow`):o(`settings.oidc.form.groupMappingDuplicateRow`)})]},t)}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:m,className:`inline-flex items-center gap-2`,children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),o(`settings.oidc.form.groupMappingAddRow`)]})]}),(0,Y.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:o(`settings.oidc.form.groupMappingDesc`)})]}),(0,Y.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:i,className:`flex-1`,children:o(`common.cancel`)}),(0,Y.jsx)(K,{variant:`primary`,className:`flex-1`,disabled:!s.name||!s.issuer_url||!s.client_id||!t&&!s.client_secret||t&&u&&!s.client_secret||C||a,onClick:b,children:o(a?`common.saving`:`common.save`)})]})]})}function ua({provider:e}){let[t,n]=(0,X.useState)(!1);return e.has_icon&&!t?(0,Y.jsx)(`img`,{src:r.oidcProviderIconUrl(e.id),alt:e.name,className:`w-8 h-8 rounded object-contain`,onError:()=>n(!0)}):(0,Y.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,Y.jsx)(zt,{className:`w-4 h-4 text-bambu-gray`})})}function da(){let{t:e}=l(),t=u(),{showToast:n}=ee(),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(null),[c,p]=(0,X.useState)(null),{data:m,isLoading:h}=d({queryKey:[`oidc-providers-all`],queryFn:()=>r.getOIDCProvidersAll()}),{data:g=[]}=d({queryKey:[`groups`],queryFn:()=>r.getGroups()}),_=f({mutationFn:e=>r.createOIDCProvider(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),a(!1),n(e(`settings.oidc.created`),`success`)},onError:e=>n(e.message,`error`)}),v=f({mutationFn:({id:e,data:t})=>r.updateOIDCProvider(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),s(null),n(e(`settings.oidc.updated`),`success`)},onError:e=>n(e.message,`error`)}),y=f({mutationFn:e=>r.deleteOIDCProvider(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),p(null),n(e(`settings.oidc.deleted`),`success`)},onError:e=>n(e.message,`error`)}),b=f({mutationFn:e=>r.refreshOIDCProviderIcon(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),t.invalidateQueries({queryKey:[`oidc-providers`]}),n(e(`settings.oidc.iconRefreshed`),`success`)},onError:t=>n(t.message||e(`settings.oidc.iconFetchFailed`),`error`)}),x=f({mutationFn:e=>r.deleteOIDCProviderIcon(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),t.invalidateQueries({queryKey:[`oidc-providers`]}),n(e(`settings.oidc.iconRemoved`),`success`)},onError:e=>n(e.message,`error`)}),S=e=>v.mutate({id:e.id,data:{is_enabled:!e.is_enabled}});return h?(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,Y.jsx)(at,{className:`w-6 h-6 animate-spin text-bambu-green`})}):(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsxs)(G,{id:`card-oidc`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.oidc.title`)}),(0,Y.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.oidc.desc`)})]}),!i&&(0,Y.jsxs)(K,{variant:`primary`,size:`sm`,onClick:()=>a(!0),className:`flex items-center gap-2`,children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),e(`settings.oidc.addProvider`)]})]})}),i&&(0,Y.jsx)(W,{children:(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,Y.jsx)(`h4`,{className:`text-white font-medium mb-4`,children:e(`settings.oidc.newProvider`)}),(0,Y.jsx)(la,{initial:ca,groups:g,onSave:e=>_.mutate(e),onCancel:()=>a(!1),isPending:_.isPending})]})})]}),m&&m.length===0&&!i&&(0,Y.jsx)(G,{id:`card-oidc-empty`,children:(0,Y.jsx)(W,{children:(0,Y.jsxs)(`div`,{className:`text-center py-8 space-y-3`,children:[(0,Y.jsx)(zt,{className:`w-12 h-12 text-bambu-gray mx-auto`}),(0,Y.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.oidc.empty`)}),(0,Y.jsxs)(K,{variant:`primary`,size:`sm`,onClick:()=>a(!0),className:`inline-flex items-center gap-2`,children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),e(`settings.oidc.addProvider`)]})]})})}),m?.map(t=>(0,Y.jsxs)(G,{children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(ua,{provider:t}),(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`h4`,{className:`text-white font-medium`,children:t.name}),t.is_enabled?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-green-700 dark:text-green-400 bg-green-50 dark:bg-green-400/10 px-2 py-0.5 rounded-full`,children:[(0,Y.jsx)(T,{className:`w-3 h-3`}),` `,e(`common.enabled`)]}):(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-0.5 rounded-full`,children:[(0,Y.jsx)(Re,{className:`w-3 h-3`}),` `,e(`common.disabled`)]}),t.is_env_managed&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-green`,children:[(0,Y.jsx)(R,{className:`w-3 h-3`}),` `,e(`settings.environmentManagedLabel`)]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-bambu-gray text-xs mt-0.5`,children:[(0,Y.jsx)(Je,{className:`w-3 h-3`}),(0,Y.jsx)(`span`,{children:t.issuer_url})]})]}),(0,Y.jsx)(`div`,{className:`flex items-center gap-2`,children:!t.is_env_managed&&(0,Y.jsxs)(Y.Fragment,{children:[t.icon_url&&(0,Y.jsx)(K,{variant:`secondary`,size:`sm`,onClick:()=>b.mutate(t.id),disabled:b.isPending,title:e(`settings.oidc.refreshIcon`),"data-testid":`refresh-icon-${t.id}`,children:(0,Y.jsx)(at,{className:`w-4 h-4 ${b.isPending?`animate-spin`:``}`})}),t.has_icon&&(0,Y.jsx)(K,{variant:`secondary`,size:`sm`,onClick:()=>x.mutate(t.id),disabled:x.isPending,title:e(`settings.oidc.removeIcon`),"data-testid":`remove-icon-${t.id}`,children:(0,Y.jsx)(Mt,{className:`w-4 h-4`})}),(0,Y.jsx)(J,{checked:t.is_enabled,onChange:()=>S(t),disabled:v.isPending}),(0,Y.jsx)(K,{variant:`secondary`,size:`sm`,onClick:()=>s(o===t.id?null:t.id),"data-testid":`edit-provider-${t.id}`,children:(0,Y.jsx)(se,{className:`w-4 h-4`})}),(0,Y.jsx)(K,{variant:`danger`,size:`sm`,onClick:()=>p(t),"data-testid":`delete-provider-${t.id}`,children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]})})]})}),o===t.id&&(0,Y.jsx)(W,{children:(0,Y.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,Y.jsx)(la,{isEdit:!0,groups:g,initial:{name:t.name,issuer_url:t.issuer_url,client_id:t.client_id,client_secret:``,scopes:t.scopes,is_enabled:t.is_enabled,auto_create_users:t.auto_create_users,auto_link_existing_accounts:t.auto_link_existing_accounts,email_claim:t.email_claim,require_email_verified:t.require_email_verified,group_claim:t.group_claim??`groups`,group_mapping:t.group_mapping??{},icon_url:t.icon_url??void 0,default_group_id:t.default_group_id??null,is_autologin:t.is_autologin},onSave:e=>v.mutate({id:t.id,data:e}),onCancel:()=>s(null),isPending:v.isPending})})}),o!==t.id&&(0,Y.jsx)(W,{children:(0,Y.jsxs)(`dl`,{className:`grid grid-cols-2 sm:grid-cols-3 gap-x-6 gap-y-2 text-sm`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.clientId`)}),(0,Y.jsx)(`dd`,{className:`text-white font-mono truncate`,children:t.client_id})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.scopes`)}),(0,Y.jsx)(`dd`,{className:`text-white`,children:t.scopes})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.autoCreate`)}),(0,Y.jsx)(`dd`,{className:t.auto_create_users?`text-green-700 dark:text-green-400`:`text-bambu-gray`,children:t.auto_create_users?e(`common.yes`):e(`common.no`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.autoLink`)}),(0,Y.jsx)(`dd`,{className:t.auto_link_existing_accounts?`text-green-700 dark:text-green-400`:`text-bambu-gray`,children:t.auto_link_existing_accounts?e(`common.yes`):e(`common.no`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.emailClaim`)}),(0,Y.jsx)(`dd`,{className:`text-white font-mono`,children:t.email_claim})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.groupClaim`)}),(0,Y.jsx)(`dd`,{className:`text-white font-mono`,children:t.group_claim??`groups`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.requireEmailVerified`)}),(0,Y.jsx)(`dd`,{className:t.require_email_verified?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`,children:t.require_email_verified?e(`common.yes`):e(`common.no`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.defaultGroup`)}),(0,Y.jsx)(`dd`,{className:`text-white`,children:t.default_group_id?g.find(e=>e.id===t.default_group_id)?.name??e(`settings.oidc.form.defaultGroupViewersFallback`):e(`settings.oidc.form.defaultGroupViewersFallback`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.groupSync`)}),(0,Y.jsx)(`dd`,{className:t.group_mapping&&Object.keys(t.group_mapping).length>0?`text-green-700 dark:text-green-400`:`text-bambu-gray`,children:t.group_mapping&&Object.keys(t.group_mapping).length>0?e(`settings.oidc.form.groupSyncOn`):e(`common.off`)})]})]})})]},t.id)),c&&(0,Y.jsx)(Tt,{title:e(`settings.oidc.deleteTitle`),message:e(`settings.oidc.deleteMessage`,{name:c.name}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:()=>y.mutate(c.id),onCancel:()=>p(null)})]})}var fa=new Map;function Q(e){fa.set(e.anchor,e)}function pa(){return Array.from(fa.values())}Q({labelKey:`settings.encryption.title`,labelFallback:`MFA Encryption Status`,tab:`users`,subTab:`security`,keywords:`mfa encryption status security backup totp oidc fernet`,anchor:`card-mfa-encryption`});function ma(){let{t:e}=l(),{data:t,isLoading:n,isError:i,refetch:a}=d({queryKey:[`encryptionStatus`],queryFn:()=>r.getEncryptionStatus(),refetchInterval:e=>{if(!e.state.error)return 3e4;let t=e.state.fetchFailureCount??0;return t<=3?Math.min(5e3*Math.max(1,t),3e4):!1}});if(n)return(0,Y.jsxs)(G,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Me,{className:`text-bambu-gray`,size:20}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,Y.jsx)(W,{children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,"data-testid":`encryption-loading`,children:[(0,Y.jsx)(L,{className:`animate-spin`,size:16}),(0,Y.jsx)(`span`,{children:e(`common.loading`)})]})})]});if(i||!t)return(0,Y.jsxs)(G,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Me,{className:`text-bambu-gray`,size:20}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,Y.jsxs)(W,{children:[(0,Y.jsx)(`div`,{className:`text-red-700 dark:text-red-400`,"data-testid":`encryption-error`,children:e(`common.errorLoading`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>a(),className:`mt-2 text-sm text-blue-700 dark:text-blue-400 underline hover:text-blue-800 dark:hover:text-blue-300`,"data-testid":`encryption-retry-button`,children:e(`common.retry`)})]})]});let o=t.legacy_plaintext_rows.oidc_providers+t.legacy_plaintext_rows.user_totp,s=t.encrypted_rows.oidc_providers+t.encrypted_rows.user_totp,c,u,f,p;t.decryption_broken?(c=`bg-red-100 dark:bg-red-500/20 border-red-400 dark:border-red-500/50 text-red-700 dark:text-red-400`,u=(0,Y.jsx)(O,{className:`text-red-600 dark:text-red-400`,size:20}),f=e(`settings.encryption.decryptionBrokenTitle`),p=e(`settings.encryption.decryptionBrokenError`,{count:s})):t.key_source===`generated`?(c=`bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,u=(0,Y.jsx)(Cn,{className:`text-amber-600 dark:text-amber-400`,size:20}),f=e(`settings.encryption.enabledGenerated`),p=e(`settings.encryption.backupHint`)):o>0?(c=`bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,u=(0,Y.jsx)(Ie,{className:`text-amber-600 dark:text-amber-400`,size:20}),f=t.key_source===`env`?e(`settings.encryption.enabledFromEnv`):e(`settings.encryption.enabledFromFile`),p=e(`settings.encryption.legacyRowsWarning`,{count:o})):t.key_configured?(c=`bg-green-100 dark:bg-green-500/20 border-green-300 dark:border-green-500/30 text-green-700 dark:text-green-400`,u=(0,Y.jsx)(Cn,{className:`text-green-600 dark:text-green-400`,size:20}),f=t.key_source===`env`?e(`settings.encryption.enabledFromEnv`):e(`settings.encryption.enabledFromFile`),p=e(`settings.encryption.allEncrypted`)):(c=`bg-gray-500/20 border-gray-500/30 text-gray-400`,u=(0,Y.jsx)(wn,{className:`text-gray-400`,size:20}),f=e(`settings.encryption.notConfigured`),p=e(`settings.encryption.notConfiguredDesc`));let m=t.key_source===`generated`&&o>0;return(0,Y.jsxs)(G,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[u,(0,Y.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,Y.jsxs)(W,{children:[(0,Y.jsxs)(`div`,{className:`p-3 border rounded-lg ${c}`,"data-testid":`encryption-status`,children:[(0,Y.jsx)(`p`,{className:`font-medium mb-1`,children:f}),(0,Y.jsx)(`p`,{className:`text-sm`,children:p})]}),m&&(0,Y.jsx)(`div`,{className:`mt-2 p-3 border rounded-lg bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,"data-testid":`encryption-legacy-warning`,children:(0,Y.jsx)(`p`,{className:`text-sm`,children:e(`settings.encryption.legacyRowsWarning`,{count:o})})}),t.migration_error_count>0&&(0,Y.jsx)(`div`,{className:`mt-2 p-3 border rounded-lg bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,"data-testid":`encryption-migration-warning`,children:(0,Y.jsx)(`p`,{className:`text-sm`,children:e(`settings.encryption.migrationErrorWarning`,{count:t.migration_error_count})})}),(0,Y.jsxs)(`div`,{className:`mt-4 grid grid-cols-2 gap-4 text-sm`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.encryption.encryptedRowsLabel`)}),(0,Y.jsxs)(`p`,{className:`font-medium`,children:[`OIDC: `,t.encrypted_rows.oidc_providers,` · TOTP: `,t.encrypted_rows.user_totp]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.encryption.legacyRowsLabel`)}),(0,Y.jsxs)(`p`,{className:`font-medium`,children:[`OIDC: `,t.legacy_plaintext_rows.oidc_providers,` · TOTP: `,t.legacy_plaintext_rows.user_totp]})]})]})]})]})}var ha={get:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 border-blue-300 dark:border-blue-500/30`,post:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400 border-green-300 dark:border-green-500/30`,put:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 border-yellow-300 dark:border-yellow-500/30`,patch:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400 border-orange-300 dark:border-orange-500/30`,delete:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 border-red-300 dark:border-red-500/30`};function ga(e,t){let n=t.replace(`#/`,``).split(`/`),r=e;for(let e of n)r=r[e];return r}function _a(e,t,n=0){if(n>5)return`...`;if(t.$ref)return _a(e,ga(e,t.$ref),n+1);if(t.allOf){let r={};for(let i of t.allOf){let t=_a(e,i,n+1);typeof t==`object`&&t&&Object.assign(r,t)}return r}if(t.example!==void 0)return t.example;if(t.default!==void 0)return t.default;switch(t.type){case`string`:return t.enum?t.enum[0]:`string`;case`integer`:case`number`:return 0;case`boolean`:return!1;case`array`:return t.items?[_a(e,t.items,n+1)]:[];case`object`:if(t.properties){let r={};for(let[i,a]of Object.entries(t.properties))r[i]=_a(e,a,n+1);return r}return{};default:return null}}function va({path:e,method:t,spec:n,schema:r,apiKey:i}){let[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)({}),[l,u]=(0,X.useState)(``),[d,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1);(0,X.useEffect)(()=>{if(a&&n.parameters){let e={};for(let t of n.parameters)t.schema?.default!==void 0&&(e[t.name]=String(t.schema.default));c(t=>({...e,...t}))}},[a,n.parameters]),(0,X.useEffect)(()=>{if(a&&n.requestBody?.content?.[`application/json`]?.schema&&!l){let e=n.requestBody.content[`application/json`].schema,t=_a(r,e);u(JSON.stringify(t,null,2))}},[a,n.requestBody,r,l]);let _=(()=>{let e=[];for(let t of n.parameters||[])if(t.in===`path`||t.required){let n=s[t.name];(n===void 0||n===``)&&e.push(t.name)}return e})(),v=async()=>{if(_.length>0){f({status:0,statusText:`Validation Error`,headers:{},body:`Missing required parameters: ${_.join(`, `)}`,duration:0});return}m(!0),f(null);try{let r=e,a=new URLSearchParams;for(let e of n.parameters||[]){let t=s[e.name];t!==void 0&&t!==``&&(e.in===`path`?r=r.replace(`{${e.name}}`,encodeURIComponent(t)):e.in===`query`&&a.append(e.name,t))}let o=a.toString(),c=`${r}${o?`?${o}`:``}`,u={"Content-Type":`application/json`};i&&(u[`X-API-Key`]=i);let d={method:t.toUpperCase(),headers:u};[`post`,`put`,`patch`].includes(t)&&l&&(d.body=l);let p=performance.now(),m=await fetch(c,d),h=Math.round(performance.now()-p),g={};m.headers.forEach((e,t)=>{g[t]=e});let _;_=m.headers.get(`content-type`)?.includes(`application/json`)?await m.json():await m.text(),f({status:m.status,statusText:m.statusText,headers:g,body:_,duration:h})}catch(e){f({status:0,statusText:`Network Error`,headers:{},body:e instanceof Error?e.message:`Unknown error`,duration:0})}finally{m(!1)}},y=async()=>{if(d){let e=typeof d.body==`string`?d.body:JSON.stringify(d.body,null,2);try{await navigator.clipboard.writeText(e),g(!0),setTimeout(()=>g(!1),2e3)}catch{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.left=`-999999px`,document.body.appendChild(t),t.select(),document.execCommand(`copy`),document.body.removeChild(t),g(!0),setTimeout(()=>g(!1),2e3)}}},b=(n.parameters||[]).filter(e=>e.in===`path`),x=(n.parameters||[]).filter(e=>e.in===`query`),S=[`post`,`put`,`patch`].includes(t)&&n.requestBody;return(0,Y.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,Y.jsxs)(`button`,{onClick:()=>o(!a),className:`w-full flex items-center gap-3 p-3 hover:bg-bambu-dark-tertiary/50 transition-colors text-left`,children:[a?(0,Y.jsx)(E,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}):(0,Y.jsx)(st,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,Y.jsx)(`span`,{className:`px-2 py-0.5 text-xs font-mono font-semibold uppercase rounded border ${ha[t]||`bg-gray-500/20 text-gray-400`}`,children:t}),(0,Y.jsx)(`code`,{className:`text-sm text-white font-mono flex-1 truncate`,children:e}),n.summary&&(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray truncate max-w-[40%]`,children:n.summary})]}),a&&(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary p-4 space-y-4 bg-bambu-dark/50`,children:[n.description&&(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n.description}),b.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Path Parameters`}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:b.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`label`,{className:`text-sm text-bambu-gray w-32 flex-shrink-0`,children:[e.name,e.required&&(0,Y.jsx)(`span`,{className:`text-red-700 dark:text-red-400 ml-1`,children:`*`})]}),(0,Y.jsx)(`input`,{type:`text`,value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),placeholder:e.description||e.schema?.type||`value`,className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`})]},e.name))})]}),x.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Query Parameters`}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`label`,{className:`text-sm text-bambu-gray w-32 flex-shrink-0`,children:[e.name,e.required&&(0,Y.jsx)(`span`,{className:`text-red-700 dark:text-red-400 ml-1`,children:`*`})]}),e.schema?.enum?(0,Y.jsxs)(`select`,{value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:``,children:`-- Select --`}),e.schema.enum.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]}):(0,Y.jsx)(`input`,{type:`text`,value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),placeholder:e.description||e.schema?.type||`value`,className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`})]},e.name))})]}),S&&(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Request Body`}),(0,Y.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),rows:8,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono focus:border-bambu-green focus:outline-none resize-y`,placeholder:`JSON request body...`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(K,{onClick:v,disabled:p,children:[p?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(De,{className:`w-4 h-4`}),`Execute`]}),_.length>0&&(0,Y.jsxs)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400 flex items-center gap-1`,children:[(0,Y.jsx)(k,{className:`w-3 h-3`}),`Fill in: `,_.join(`, `)]})]}),d&&(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`h4`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[`Response`,(0,Y.jsxs)(`span`,{className:`px-2 py-0.5 text-xs rounded ${d.status>=200&&d.status<300?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`:d.status>=400?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`}`,children:[d.status,` `,d.statusText]}),(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[d.duration,`ms`]})]}),(0,Y.jsx)(K,{variant:`secondary`,size:`sm`,onClick:y,children:h?(0,Y.jsx)(j,{className:`w-3 h-3 text-green-600 dark:text-green-400`}):(0,Y.jsx)(M,{className:`w-3 h-3`})})]}),(0,Y.jsx)(`pre`,{className:`p-3 bg-bambu-dark rounded-lg text-sm font-mono text-white overflow-auto max-h-96 border border-bambu-dark-tertiary`,children:typeof d.body==`string`?d.body:JSON.stringify(d.body,null,2)})]})]})]})}function ya({apiKey:e=``}){let[t,n]=(0,X.useState)(null),[r,i]=(0,X.useState)(!0),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(new Set),[l,u]=(0,X.useState)(``);if((0,X.useEffect)(()=>{async function e(){try{let e=await fetch(`/openapi.json`);if(!e.ok)throw Error(`Failed to fetch OpenAPI schema`);n(await e.json())}catch(e){o(e instanceof Error?e.message:`Unknown error`)}finally{i(!1)}}e()},[]),r)return(0,Y.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,Y.jsx)(L,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(a||!t)return(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-8`,children:(0,Y.jsxs)(`div`,{className:`text-center text-red-700 dark:text-red-400`,children:[(0,Y.jsx)(k,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,Y.jsx)(`p`,{children:`Failed to load API schema`}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:a})]})})});let d={};for(let[e,n]of Object.entries(t.paths))for(let[t,r]of Object.entries(n)){if(t===`parameters`)continue;let n=r.tags||[`Other`];for(let i of n)d[i]||(d[i]=[]),d[i].push({path:e,method:t,spec:r})}let f=Object.entries(d).map(([e,t])=>l?{tag:e,endpoints:t.filter(({path:e,method:t,spec:n})=>{let r=l.toLowerCase();return e.toLowerCase().includes(r)||t.toLowerCase().includes(r)||(n.summary?.toLowerCase()||``).includes(r)||(n.description?.toLowerCase()||``).includes(r)})}:{tag:e,endpoints:t}).filter(({endpoints:e})=>e.length>0).sort((e,t)=>e.tag.localeCompare(t.tag)),p=e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Y.jsx)(`div`,{className:`flex-1`,children:(0,Y.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:`Search endpoints...`,className:`w-full max-w-md px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(K,{variant:`secondary`,size:`sm`,onClick:()=>{c(new Set(f.map(e=>e.tag)))},children:`Expand All`}),(0,Y.jsx)(K,{variant:`secondary`,size:`sm`,onClick:()=>{c(new Set)},children:`Collapse All`}),(0,Y.jsxs)(`a`,{href:`/docs`,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 text-sm text-bambu-green hover:underline`,children:[(0,Y.jsx)(Je,{className:`w-4 h-4`}),`Swagger UI`]})]})]}),(0,Y.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[f.reduce((e,t)=>e+t.endpoints.length,0),` endpoints in `,f.length,` categories`]}),(0,Y.jsx)(`div`,{className:`space-y-3`,children:f.map(({tag:n,endpoints:r})=>(0,Y.jsxs)(G,{children:[(0,Y.jsx)(`button`,{onClick:()=>p(n),className:`w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/30 transition-colors text-left`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[s.has(n)?(0,Y.jsx)(E,{className:`w-5 h-5 text-bambu-gray`}):(0,Y.jsx)(st,{className:`w-5 h-5 text-bambu-gray`}),(0,Y.jsx)(`h3`,{className:`text-base font-semibold text-white capitalize`,children:n.replace(/-/g,` `)}),(0,Y.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-2 py-0.5 rounded-full text-bambu-gray`,children:r.length})]})}),s.has(n)&&(0,Y.jsx)(W,{className:`pt-0 space-y-2`,children:r.map(({path:n,method:r,spec:i})=>(0,Y.jsx)(va,{path:n,method:r,spec:i,schema:t,apiKey:e},`${r}-${n}`))})]},n))})]})}var ba=[{id:`sidecar`,labelKey:`settings.sliceEngineSidecar`,descriptionKey:`settings.sliceEngineSidecarHint`,available:!0},{id:`browser`,labelKey:`settings.sliceEngineBrowser`,descriptionKey:`settings.sliceEngineBrowserHint`,available:!1}];function xa(){return ba.filter(e=>e.available)}function Sa(){return xa().length>1}function Ca(e){return xa().find(t=>t.id===e)?.id??`sidecar`}function wa({printers:e,onPick:t,label:n,disabled:r}){let{t:i}=l(),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(``),u=(0,X.useRef)(null);(0,X.useEffect)(()=>{if(!a)return;let e=e=>{u.current&&!u.current.contains(e.target)&&o(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[a]);let d=s.trim().toLowerCase(),f=e.filter(e=>!d||e.name.toLowerCase().includes(d)||(e.location??``).toLowerCase().includes(d)),p=()=>{o(!1),c(``)};return(0,Y.jsxs)(`div`,{ref:u,className:`relative inline-block`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>a?p():o(!0),disabled:r||e.length===0,"aria-expanded":a,className:`inline-flex items-center gap-1 px-2 py-1 rounded border border-dashed border-bambu-dark-tertiary text-xs text-bambu-gray hover:text-white hover:border-bambu-green disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,Y.jsx)(wt,{className:`w-3.5 h-3.5`}),n]}),a&&(0,Y.jsxs)(`div`,{className:`absolute left-0 z-20 mt-1 w-64 max-w-[calc(100vw-2rem)] rounded-lg border border-bambu-dark-tertiary bg-bambu-dark-secondary shadow-lg`,onKeyDown:e=>{e.key===`Escape`&&p()},children:[(0,Y.jsxs)(`div`,{className:`relative p-2 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsx)(Ae,{className:`w-3.5 h-3.5 text-bambu-gray absolute left-4 top-1/2 -translate-y-1/2`}),(0,Y.jsx)(`input`,{type:`search`,autoFocus:!0,value:s,onChange:e=>c(e.target.value),placeholder:i(`settings.printerPickerSearch`),"aria-label":i(`settings.printerPickerSearch`),className:`w-full pl-7 pr-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`ul`,{className:`max-h-60 overflow-y-auto py-1`,role:`listbox`,"aria-label":n,children:[f.length===0&&(0,Y.jsx)(`li`,{className:`px-3 py-2 text-xs text-bambu-gray italic`,children:i(`settings.printerPickerNoMatch`)}),f.map(e=>(0,Y.jsx)(`li`,{role:`option`,"aria-selected":!1,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{t(e),p()},className:`w-full text-left px-3 py-1.5 text-sm text-white hover:bg-bambu-dark-tertiary`,children:[(0,Y.jsx)(`span`,{className:`block truncate`,children:e.name}),e.location&&(0,Y.jsx)(`span`,{className:`block truncate text-[11px] text-bambu-gray`,children:e.location})]})},e.id))]})]})]})}var Ta=[`general`,`plugs`,`sensors`,`notifications`,`queue`,`filament`,`camera`,`network`,`apikeys`,`virtual-printer`,`spoolbuddy`,`failure-detection`,`users`,`backup`];Q({labelKey:`settings.general`,tab:`general`,keywords:`language date time format printer model printers cards`,anchor:`card-general`}),Q({labelKey:`settings.appearance`,tab:`general`,keywords:`theme dark light mode colors`,anchor:`card-appearance`}),Q({labelKey:`settings.archiveSettings`,tab:`general`,keywords:`archive auto save thumbnails captures`,anchor:`card-archive`}),Q({labelKey:`settings.camera`,tab:`camera`,keywords:`camera external video stream rtsp mjpeg usb snapshot rotation chamber light led lamp`,anchor:`card-camera`}),Q({labelKey:`settings.costTracking`,tab:`general`,keywords:`currency filament cost energy kwh price`,anchor:`card-cost`}),Q({labelKey:`settings.fileManager`,tab:`general`,keywords:`file manager archive mode disk warning storage`,anchor:`card-filemanager`}),Q({labelKey:`settings.updates`,tab:`general`,keywords:`updates version firmware beta check`,anchor:`card-updates`}),Q({labelKey:`settings.dataManagement`,tab:`general`,keywords:`data reset clear logs notifications preferences`,anchor:`card-data`}),Q({labelKey:`settings.smartPlugs`,tab:`plugs`,keywords:`smart plug energy power automation tapo kasa tplink shelly`,anchor:`card-plugs`}),Q({labelKey:`haSensors.sectionTitle`,tab:`sensors`,keywords:`home assistant sensor printer temperature humidity alert notify block print`,anchor:`card-ha-sensors`}),Q({labelKey:`locationHaSensors.sectionTitle`,tab:`sensors`,keywords:`home assistant sensor location storage box temperature humidity battery alert notify`,anchor:`card-location-sensors`}),Q({labelKey:`settings.providers`,tab:`notifications`,keywords:`telegram discord email notification providers webhook`,anchor:`card-providers`}),Q({labelKey:`settings.messageTemplates`,tab:`notifications`,keywords:`message templates notification text edit`,anchor:`card-templates`}),Q({labelKey:`settings.defaultPrintOptions`,labelFallback:`Default Print Options`,tab:`queue`,keywords:`print bed leveling flow calibration vibration first layer timelapse`,anchor:`card-print-options`}),Q({labelKey:`settings.tempFanPresetsTitle`,labelFallback:`Temperature & Fan Presets`,tab:`queue`,keywords:`temperature fan presets nozzle bed chamber quick buttons popover`,anchor:`card-temp-fan-presets`}),Q({labelKey:`settings.staggeredStart`,labelFallback:`Staggered Start`,tab:`queue`,keywords:`staggered batch delay start queue group`,anchor:`card-staggered`}),Q({labelKey:`settings.plateClear`,labelFallback:`Plate-Clear Confirmation`,tab:`queue`,keywords:`plate clear confirm auto queue`,anchor:`card-plate`}),Q({labelKey:`settings.concurrentUploadsTitle`,labelFallback:`Concurrent Uploads`,tab:`queue`,keywords:`concurrent parallel upload transfer ftp queue slow farm simultaneous`,anchor:`card-concurrent-uploads`}),Q({labelKey:`settings.gcodeInjection`,labelFallback:`G-code Injection`,tab:`queue`,keywords:`gcode injection start end autoprint farmloop swapmod autoclear printflow`,anchor:`card-gcode`}),Q({labelKey:`settings.slicerCard`,labelFallback:`Slicer`,tab:`queue`,keywords:`slicer orcaslicer bambustudio orca bambu api sidecar url docker preferred`,anchor:`card-slicer`}),Q({labelKey:`settings.queueDrying`,tab:`queue`,keywords:`drying presets temperature time humidity ams`,anchor:`card-drying`}),Q({labelKey:`settings.filamentChecks`,tab:`filament`,keywords:`filament check warning runout remaining`,anchor:`card-filamentchecks`}),Q({labelKey:`settings.printModal`,tab:`filament`,keywords:`print modal custom mapping`,anchor:`card-printmodal`}),Q({labelKey:`settings.amsDisplayThresholds`,tab:`filament`,keywords:`ams humidity temperature threshold history retention`,anchor:`card-amsthresholds`}),Q({labelKey:`settings.externalUrl`,tab:`network`,keywords:`external url reverse proxy public notification link`,anchor:`card-externalurl`}),Q({labelKey:`settings.ftpRetry`,tab:`network`,keywords:`ftp retry upload retries backoff`,anchor:`card-ftpretry`}),Q({labelKey:`settings.homeAssistant`,tab:`network`,keywords:`home assistant ha hass mqtt integration`,anchor:`card-ha`}),Q({labelKey:`settings.mqttPublishing`,tab:`network`,keywords:`mqtt publish broker topic`,anchor:`card-mqtt`}),Q({labelKey:`settings.prometheusMetrics`,tab:`network`,keywords:`prometheus metrics grafana monitoring bearer token`,anchor:`card-prometheus`}),Q({labelKey:`settings.createNewApiKey`,tab:`apikeys`,keywords:`api key create permission scope`,anchor:`card-createapi`}),Q({labelKey:`settings.webhookEndpoints`,tab:`apikeys`,keywords:`webhook endpoint post http`,anchor:`card-webhooks`}),Q({labelKey:`settings.apiBrowser`,tab:`apikeys`,keywords:`api browser endpoint documentation test`,anchor:`card-apibrowser`}),Q({labelKey:`connectedApps.title`,tab:`apikeys`,keywords:`connected app sign in single sign-on sso oauth login orders`,anchor:`card-connected-apps`}),Q({labelKey:`cameraTokens.title`,tab:`camera`,keywords:`camera token long-lived home assistant frigate kiosk stream cam wall`,anchor:`card-camera-tokens`}),Q({labelKey:`streamOverlay.builder.title`,labelFallback:`Streaming Overlay`,tab:`camera`,keywords:`streaming overlay obs browser source stream url token`,anchor:`card-stream-overlay`}),Q({labelKey:`settings.tabs.virtualPrinter`,tab:`virtual-printer`,keywords:`virtual printer proxy archive slicer bambustudio orcaslicer ip bind`,anchor:`card-vp`}),Q({labelKey:`settings.tabs.spoolbuddy`,tab:`spoolbuddy`,keywords:`spoolbuddy device scale nfc rfid kiosk unregister`,anchor:`card-spoolbuddy`}),Q({labelKey:`settings.currentUser`,tab:`users`,subTab:`users`,keywords:`current user profile password change`,anchor:`card-currentuser`}),Q({labelKey:`settings.users`,tab:`users`,subTab:`users`,keywords:`users accounts list`,anchor:`card-users`}),Q({labelKey:`settings.groups`,tab:`users`,subTab:`users`,keywords:`groups roles permissions administrators operators viewers`,anchor:`card-groups`}),Q({labelKey:`printerAccess.tab`,tab:`users`,subTab:`printer-access`,keywords:`printer access groups teams locations limit restrict scope who can see`,anchor:`card-printer-access`}),Q({labelKey:`settings.sessionPolicy.title`,labelFallback:`Session Policy`,tab:`users`,subTab:`users`,keywords:`session timeout expiry logout remember me jwt token lifetime`,anchor:`card-session-policy`}),Q({labelKey:`settings.email.smtpSettings`,labelFallback:`SMTP Configuration`,tab:`users`,subTab:`email`,keywords:`smtp email send server port password auth starttls ssl`,anchor:`card-smtp`}),Q({labelKey:`settings.ldap.title`,labelFallback:`LDAP Authentication`,tab:`users`,subTab:`ldap`,keywords:`ldap active directory ad authentication bind dn search base group mapping`,anchor:`card-ldap`}),Q({labelKey:`settings.tabs.backup`,tab:`backup`,keywords:`backup github restore download cloud sync profiles archives`,anchor:`card-backup`}),Q({labelKey:`externalLinks.sidebarLayout`,labelFallback:`Sidebar`,tab:`general`,keywords:`sidebar layout links pages hide show external custom navigation url add`,anchor:`card-sidebar-links`}),Q({labelKey:`settings.filamentTracking`,tab:`filament`,keywords:`spoolman filament tracking inventory sync remote integration`,anchor:`card-spoolman`}),Q({labelKey:`settings.catalog.spoolCatalog`,labelFallback:`Spool Catalog`,tab:`filament`,keywords:`spool catalog entries brand material reset import export`,anchor:`card-spool-catalog`}),Q({labelKey:`settings.colorCatalog.title`,labelFallback:`Color Catalog`,tab:`filament`,keywords:`color catalog hex swatch palette sync reset`,anchor:`card-color-catalog`}),Q({labelKey:`settings.tabs.failureDetection`,labelFallback:`Failure Detection`,tab:`failure-detection`,keywords:`failure detection ai ml obico spaghetti detect monitoring`,anchor:`card-fd-ml`}),Q({labelKey:`failureDetection.perPrinterTitle`,labelFallback:`Per-Printer Settings`,tab:`failure-detection`,keywords:`failure detection per printer enable per-printer sensitivity`,anchor:`card-fd-perprinter`}),Q({labelKey:`failureDetection.statusTitle`,labelFallback:`Detection Status`,tab:`failure-detection`,keywords:`failure detection status running connection`,anchor:`card-fd-status`}),Q({labelKey:`failureDetection.historyTitle`,labelFallback:`Detection History`,tab:`failure-detection`,keywords:`failure detection history log events`,anchor:`card-fd-history`}),Q({labelKey:`settings.email.advancedAuth`,labelFallback:`Advanced Email Authentication`,tab:`users`,subTab:`email`,keywords:`email authentication advanced password reset self-service forgot`,anchor:`card-email-advanced-auth`}),Q({labelKey:`settings.email.testConnection`,labelFallback:`Test SMTP Connection`,tab:`users`,subTab:`email`,keywords:`email smtp test connection send check`,anchor:`card-email-test`}),Q({labelKey:`settings.twoFa.totpTitle`,labelFallback:`Authenticator App (TOTP)`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa totp authenticator app google authy otp`,anchor:`card-2fa-totp`}),Q({labelKey:`settings.twoFa.emailOtpTitle`,labelFallback:`Email One-Time Codes`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa email otp one time code`,anchor:`card-2fa-emailotp`}),Q({labelKey:`settings.twoFa.linkedAccounts`,labelFallback:`Linked Accounts`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa linked accounts sso oidc provider google github`,anchor:`card-2fa-linked`}),Q({labelKey:`settings.oidc.title`,labelFallback:`Single Sign-On (OIDC)`,tab:`users`,subTab:`oidc`,keywords:`sso oidc openid single sign-on pocketid authentik keycloak google okta azure provider`,anchor:`card-oidc`}),Q({labelKey:`settings.ldap.serverConfig`,labelFallback:`LDAP Server Configuration`,tab:`users`,subTab:`ldap`,keywords:`ldap server url bind dn user search base group filter tls`,anchor:`card-ldap-server`}),Q({labelKey:`backup.githubBackup`,labelFallback:`GitHub Backup`,tab:`backup`,keywords:`github backup cloud remote sync profiles token`,anchor:`card-backup-github`}),Q({labelKey:`backup.history`,labelFallback:`Backup History`,tab:`backup`,keywords:`backup history log runs github commits`,anchor:`card-backup-history`}),Q({labelKey:`backup.localBackup`,labelFallback:`Local Backup`,tab:`backup`,keywords:`local backup download zip manual export`,anchor:`card-backup-local`}),Q({labelKey:`backup.scheduledBackup`,labelFallback:`Scheduled Backups`,tab:`backup`,keywords:`scheduled backup automatic hourly daily weekly retention local path`,anchor:`card-backup-scheduled`});var Ea=20,Da={database:`bg-blue-600`,library_files:`bg-green-500`,library_thumbnails:`bg-teal-500`,library_other:`bg-emerald-700`,archive_timelapses:`bg-red-500`,archive_thumbnails:`bg-amber-500`,archive_files:`bg-sky-500`,virtual_printer_uploads:`bg-purple-500`,virtual_printer_upload_cache:`bg-fuchsia-500`,virtual_printer_certs:`bg-violet-500`,virtual_printer_other:`bg-purple-700`,downloads:`bg-cyan-500`,plate_calibration:`bg-lime-500`,logs:`bg-orange-500`,other_data:`bg-yellow-500`},Oa=[`bg-blue-500`,`bg-green-500`,`bg-yellow-500`,`bg-red-500`,`bg-orange-500`,`bg-teal-500`,`bg-cyan-500`,`bg-purple-500`],ka=(e,t)=>Da[e]||Oa[t%Oa.length],Aa={temperature:0,humidity:1,battery:2};function ja(e,t){return e?v(e,t,{decimals:2}):null}var Ma=[`off`,`all`,`selected`];function Na(e){let t=(e.external_camera_type||`mjpeg`).toUpperCase(),n=e.external_camera_url||``;if(!n)return t;let r=n;try{r=new URL(n).host||n}catch{}return`${t} · ${r}`}function Pa(){let[e,t]=(0,X.useState)(0),n=u(),a=vt(),[o,s]=bt(),{t:m,i18n:_}=l(),{showToast:v}=ee(),{authEnabled:x,user:S,isAdmin:T,refreshAuth:D,hasPermission:k,loading:N}=un(),{mode:re,resolvedMode:ae,darkStyle:oe,darkBackground:F,darkAccent:ce,lightStyle:B,lightBackground:le,lightAccent:V,setMode:de,setDarkStyle:fe,setDarkBackground:pe,setDarkAccent:me,setLightStyle:he,setLightBackground:ge,setLightAccent:_e,progressInTitle:ye,setProgressInTitle:be}=an(),[H,Ee]=(0,X.useState)(null),[De,je]=(0,X.useState)({}),[Ne,Pe]=(0,X.useState)(null),[Be,Ve]=(0,X.useState)(!1),[Ue,We]=(0,X.useState)(null),[Ge,q]=(0,X.useState)(!1),[Ye,Xe]=(0,X.useState)(null),[et,ot]=(0,X.useState)(!1),[st,lt]=(0,X.useState)(null),[ut,ft]=(0,X.useState)(!1),{colorize:mt,aboveColor:xt,belowColor:jt,optimalColor:Mt}=ue(),[Pt,It]=(0,X.useState)(null),[Lt,Bt]=(0,X.useState)(!1),[Ut,Wt]=(0,X.useState)(null),[qt,Jt]=(0,X.useState)(null),[Qt,en]=(0,X.useState)(``),[tn,on]=(0,X.useState)(``),[J,dn]=(0,X.useState)(!1),[fn,pn]=(0,X.useState)(!1),[mn,hn]=(0,X.useState)(!1),[gn,_n]=(0,X.useState)(Gt()),vn=o.get(`tab`),xn=vn===`email`,Cn=k(`api_keys:read`)||k(`settings:update`),wn=vn===`apikeys`&&[`#card-camera-tokens`,`#card-stream-overlay`].includes(window.location.hash),[En,Dn]=(0,X.useState)(xn?`users`:wn?`camera`:vn&&Ta.includes(vn)?vn:`general`),[On,kn]=(0,X.useState)(xn?`email`:vn===`users`&&o.get(`sub`)===`printer-access`?`printer-access`:`users`),jn=e=>{if(kn(e),e===`printer-access`)o.set(`sub`,`printer-access`);else for(let e of[`sub`,`view`,`group`,`printer`])o.delete(e);s(o,{replace:!0})},Mn=On===`printer-access`&&!(x&&T)?`users`:On,[Pn,Fn]=(0,X.useState)(vn===`queue`&&o.get(`sub`)===`pipelines`?`pipelines`:`dispatch`),In=e=>{Dn(e),e===`users`&&kn(`users`);for(let e of[`sub`,`view`,`group`,`printer`])o.delete(e);e===`queue`&&Fn(`dispatch`),e===`general`?o.delete(`tab`):o.set(`tab`,e),s(o,{replace:!0})};(0,X.useEffect)(()=>{!N&&En===`apikeys`&&!Cn&&In(`camera`)},[N,En,Cn]);let Ln=e=>{Fn(e),e===`pipelines`?o.set(`sub`,`pipelines`):o.delete(`sub`),s(o,{replace:!0})},[Rn,zn]=(0,X.useState)(!1),[Bn,Vn]=(0,X.useState)(``),[Hn,Un]=(0,X.useState)({can_queue:!0,can_control_printer:!1,can_read_status:!0,can_manage_library:!0,can_manage_inventory:!0,can_manage_maintenance:!0,can_manage_archives:!0,can_manage_projects:!0,can_access_cloud:!1,can_update_energy_cost:!1,can_send_notifications:!1}),[Wn,Gn]=(0,X.useState)(null),[qn,Jn]=(0,X.useState)(!1),[Yn,Xn]=(0,X.useState)(null),[Zn,Qn]=(0,X.useState)(``),[er,tr]=(0,X.useState)(!1),[nr,rr]=(0,X.useState)(!1),[ir,ar]=(0,X.useState)(null),[or,sr]=(0,X.useState)(!1),[cr,ur]=(0,X.useState)(!1),[mr,hr]=(0,X.useState)(!1),[gr,vr]=(0,X.useState)({currentPassword:``,newPassword:``,confirmPassword:``}),[yr,br]=(0,X.useState)(!1),[xr,Sr]=(0,X.useState)(!1),[Cr,Er]=(0,X.useState)(!1),[kr,jr]=(0,X.useState)(`local`),[Mr,Nr]=(0,X.useState)(!1),[Pr,Fr]=(0,X.useState)(null),[Ir,Lr]=(0,X.useState)(null),[Rr,zr]=(0,X.useState)(null),[Br,Vr]=(0,X.useState)(!1),[Z,Hr]=(0,X.useState)({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),[Ur,Wr]=(0,X.useState)(null),[Gr,Kr]=(0,X.useState)(null),[qr,Jr]=(0,X.useState)(!1),[Yr,Xr]=(0,X.useState)({}),[Zr,Qr]=(0,X.useState)({}),$r=e=>{_n(e),rn(e),v(m(`settings.toast.settingsSaved`),`success`)},{data:ei,isLoading:ti}=d({queryKey:[`settings`],queryFn:r.getSettings}),{data:ni,isLoading:ri,isFetching:ii}=d({queryKey:[`storage-usage`],queryFn:()=>r.getStorageUsage(),enabled:En===`general`,staleTime:1/0,refetchInterval:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1}),{data:oi}=d({queryKey:[`ha-price-entities`],queryFn:async()=>(await r.getBindableHAEntities()).filter(e=>e.domain===`sensor`&&/\/\s*[km]?wh$/i.test(e.unit_of_measurement??``)),enabled:En===`general`&&ei?.energy_price_source===`homeassistant`&&!!ei?.ha_enabled,staleTime:6e4,retry:!1}),si=async()=>{Sr(!0);try{let e=await r.getStorageUsage({refresh:!0});n.setQueryData([`storage-usage`],e)}catch(e){v(e instanceof Error?e.message:`Failed to refresh storage usage`,`error`)}finally{Sr(!1)}},{data:li,isLoading:mi}=d({queryKey:[`smart-plugs`],queryFn:r.getSmartPlugs}),{data:gi,isLoading:_i}=d({queryKey:[`smart-plugs-energy`,li?.map(e=>e.id)],queryFn:async()=>{if(!li||li.length===0)return null;let e=await Promise.all(li.filter(e=>e.enabled).map(async e=>{try{return{plug:e,status:await r.getSmartPlugStatus(e.id)}}catch{return{plug:e,status:null}}})),t=0,n=0,i=0,a=0,o=0;for(let{plug:r,status:s}of e){let e=r.plug_type===`mqtt`&&s?.energy?.power!=null;(s?.reachable||e)&&(o++,s?.energy?.power!=null&&(t+=s.energy.power),s?.energy?.today!=null&&(n+=s.energy.today),s?.energy?.yesterday!=null&&(i+=s.energy.yesterday),s?.energy?.total!=null&&(a+=s.energy.total))}return{totalPower:t,totalToday:n,totalYesterday:i,totalLifetime:a,reachableCount:o,totalPlugs:li.filter(e=>e.enabled).length}},enabled:En===`plugs`&&!!li&&li.length>0,refetchInterval:En===`plugs`?1e4:!1}),{data:vi,isLoading:yi}=d({queryKey:[`notification-providers`],queryFn:r.getNotificationProviders}),{data:bi,isLoading:xi}=d({queryKey:[`api-keys`],queryFn:r.getAPIKeys}),Si=f({mutationFn:e=>r.createAPIKey(e),onSuccess:e=>{Gn(e.key||null),zn(!1),Vn(``),n.invalidateQueries({queryKey:[`api-keys`]}),v(m(`settings.toast.apiKeyCreated`))},onError:e=>{v(`Failed to create API key: ${e.message}`,`error`)}}),Ci=f({mutationFn:e=>r.deleteAPIKey(e),onSuccess:(e,t)=>{n.setQueryData([`api-keys`],e=>(e??[]).filter(e=>e.id!==t)),v(m(`settings.toast.apiKeyDeleted`))},onError:e=>{v(`Failed to delete API key: ${e.message}`,`error`)}}),{data:wi}=d({queryKey:[`printers`],queryFn:r.getPrinters}),{data:Ei}=d({queryKey:[`haSensors`],queryFn:()=>r.getHASensors()}),{data:Di}=d({queryKey:[`locationHaSensors`],queryFn:()=>r.getLocationHASensors()}),{data:Oi}=d({queryKey:Xt,queryFn:r.getLocations,enabled:En===`sensors`}),Ai=p({queries:(0,X.useMemo)(()=>Array.from(new Set((Di??[]).map(e=>e.location_id))),[Di]).map(e=>({queryKey:[`locationHaSensorReadings`,e],queryFn:()=>r.getLocationHASensorReadings(e,!1),enabled:En===`sensors`,refetchInterval:En===`sensors`?(ei?.location_sensor_poll_interval||120)*1e3:!1}))}),ji=(0,X.useMemo)(()=>{let e=new Map;for(let t of Ai)for(let n of t.data??[])e.set(n.id,n);return e},[Ai]),Mi=f({mutationFn:async e=>{for(let t of e)await r.deleteLocationHASensor(t)},onSuccess:()=>{v(m(`locationHaSensors.toast.deleted`),`success`)},onError:e=>{v(e.message,`error`)},onSettled:()=>{n.invalidateQueries({queryKey:[`locationHaSensors`]}),n.invalidateQueries({queryKey:[`locationHaSensorReadings`]}),It(null)}}),Ni=Yt(wi?.length??0),{data:Pi,isLoading:Fi}=d({queryKey:[`notification-templates`],queryFn:r.getNotificationTemplates}),{data:Ii}=d({queryKey:[`virtual-printer-settings`],queryFn:i.getSettings,refetchInterval:1e4}),Li=Ii?.status?.running??!1,{data:Ri}=d({queryKey:[`spoolbuddy-devices`],queryFn:()=>c.getDevices(),refetchInterval:15e3}),zi=Ri?.length??0,Bi=Ri?.some(e=>e.online)??!1,{data:Vi}=d({queryKey:[`obico-status`],queryFn:r.getObicoStatus,refetchInterval:15e3}),Wi=!!(Vi?.is_running&&Vi?.enabled),{data:Gi}=d({queryKey:[`ffmpeg-status`],queryFn:r.checkFfmpeg}),{data:qi}=d({queryKey:[`version`],queryFn:r.getVersion}),Yi=!x||k(`library:purge`),{data:Xi}=d({queryKey:[`library-trash-settings`],queryFn:()=>r.getLibraryTrashSettings(),enabled:Yi}),Zi=f({mutationFn:e=>r.updateLibraryTrashSettings(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`library-trash-settings`]}),v(m(`settings.toast.settingsSaved`),`success`)},onError:e=>v(e.message||m(`libraryAutoPurge.saveFailed`),`error`)}),Qi=e=>{Xi&&Zi.mutate({retention_days:Xi.retention_days,auto_purge_enabled:Xi.auto_purge_enabled,auto_purge_days:Xi.auto_purge_days,auto_purge_include_never_printed:Xi.auto_purge_include_never_printed,...e})},$i=!x||k(`archives:purge`),{data:ea}=d({queryKey:[`archive-purge-settings`],queryFn:()=>r.getArchivePurgeSettings(),enabled:$i}),ta=f({mutationFn:e=>r.updateArchivePurgeSettings(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`archive-purge-settings`]}),v(m(`settings.toast.settingsSaved`),`success`)},onError:e=>v(e.message||m(`archiveAutoPurge.saveFailed`),`error`)}),na=e=>{ea&&ta.mutate({enabled:ea.enabled,days:ea.days,purge_stats:ea.purge_stats,...e})},{data:ia,refetch:aa,isRefetching:oa}=d({queryKey:[`updateCheck`],queryFn:r.checkForUpdates,enabled:ei?.check_updates!==!1,staleTime:300*1e3}),{data:ca,refetch:la}=d({queryKey:[`updateStatus`],queryFn:r.getUpdateStatus,refetchInterval:e=>{let t=e.state.data;return t?.status===`downloading`||t?.status===`installing`?1e3:!1}}),{data:ua}=d({queryKey:[`mqtt-status`],queryFn:r.getMQTTStatus,refetchInterval:En===`network`?5e3:!1}),{data:fa}=d({queryKey:[`github-backup-status`],queryFn:r.getGitHubBackupStatus}),{data:Q}=d({queryKey:[`cloud-status`],queryFn:r.getCloudStatus}),{data:ha={advanced_auth_enabled:!1,smtp_configured:!1,local_login_enabled:!0,autologin_provider_id:null}}=d({queryKey:[`advancedAuthStatus`],queryFn:()=>r.getAdvancedAuthStatus()}),{data:ga}=d({queryKey:[`ldapStatus`],queryFn:()=>r.getLDAPStatus()}),{data:_a}=d({queryKey:[`twoFAStatus`],queryFn:()=>r.get2FAStatus()}),{data:va=[]}=d({queryKey:[`oidcProvidersAll`],queryFn:()=>r.getOIDCProvidersAll(),enabled:T}),{data:ba=[],isLoading:Da}=d({queryKey:[`users`],queryFn:()=>r.getUsers(),enabled:x&&k(`users:read`)}),{data:Oa=[],isLoading:Pa}=d({queryKey:[`groups`],queryFn:()=>r.getGroups(),enabled:x&&k(`groups:read`)}),Fa=f({mutationFn:e=>r.createUser(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`users`]}),n.invalidateQueries({queryKey:[`groups`]}),Er(!1),Hr({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),v(m(`settings.toast.userCreated`))},onError:e=>{v(e.message,`error`)}}),Ia=f({mutationFn:({id:e,data:t})=>r.updateUser(e,t),onSuccess:()=>{n.invalidateQueries({queryKey:[`users`]}),n.invalidateQueries({queryKey:[`groups`]}),Nr(!1),Fr(null),Hr({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),v(m(`settings.toast.userUpdated`))},onError:e=>{v(e.message,`error`)}}),La=f({mutationFn:({id:e,deleteItems:t})=>r.deleteUser(e,t),onSuccess:()=>{n.invalidateQueries({queryKey:[`users`]}),v(m(`settings.toast.userDeleted`)),Lr(null),zr(null)},onError:e=>{v(e.message,`error`)}}),Ra=f({mutationFn:e=>r.resetUserPassword({user_id:e}),onSuccess:e=>{v(e.message,`success`)},onError:e=>{v(e.message,`error`)}}),za=async e=>{Lr(e),Vr(!0);try{zr(await r.getUserItemsCount(e))}catch{zr({archives:0,queue_items:0,library_files:0})}finally{Vr(!1)}},Ba=f({mutationFn:e=>r.deleteGroup(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`groups`]}),v(m(`settings.toast.groupDeleted`))},onError:e=>{v(e.message,`error`)}}),Va=()=>{let e=ha?.advanced_auth_enabled||!1;if(!Z.username){v(m(`settings.toast.fillRequiredFields`),`error`);return}if(e&&!Z.email){v(`Email is required when advanced authentication is enabled`,`error`);return}if(!e){if(!Z.password){v(m(`settings.toast.fillRequiredFields`),`error`);return}if(Z.password!==Z.confirmPassword){v(m(`settings.toast.passwordsDoNotMatch`),`error`);return}let e=Tn(Z.password);if(e){v(m({tooShort:`settings.toast.passwordTooShort`,needsUppercase:`settings.toast.passwordNeedsUppercase`,needsLowercase:`settings.toast.passwordNeedsLowercase`,needsDigit:`settings.toast.passwordNeedsDigit`,needsSpecial:`settings.toast.passwordNeedsSpecial`}[e]),`error`);return}}Fa.mutate({username:Z.username,password:e?void 0:Z.password,email:Z.email||void 0,role:Z.role,group_ids:Z.group_ids.length>0?Z.group_ids:void 0})},Ha=e=>{if(Z.password){if(Z.password!==Z.confirmPassword){v(m(`settings.toast.passwordsDoNotMatch`),`error`);return}let e=Tn(Z.password);if(e){v(m({tooShort:`settings.toast.passwordTooShort`,needsUppercase:`settings.toast.passwordNeedsUppercase`,needsLowercase:`settings.toast.passwordNeedsLowercase`,needsDigit:`settings.toast.passwordNeedsDigit`,needsSpecial:`settings.toast.passwordNeedsSpecial`}[e]),`error`);return}}let t={username:Z.username||void 0,password:Z.password||void 0,email:Z.email||void 0,role:Z.role,group_ids:Z.group_ids};t.password||delete t.password,Ia.mutate({id:e,data:t})},Ua=e=>{Fr(e.id),Hr({username:e.username,password:``,email:e.email||``,confirmPassword:``,role:e.role,group_ids:e.groups?.map(e=>e.id)||[]}),Nr(!0)},Wa=e=>{Hr(t=>({...t,group_ids:t.group_ids.includes(e)?t.group_ids.filter(t=>t!==e):[...t.group_ids,e]}))},Ga=f({mutationFn:r.applyUpdate,onSuccess:e=>{e.is_ha_addon||e.is_docker||e.is_windows_installer?v(e.message,`error`):la()}}),[Ka,qa]=(0,X.useState)(null),Ja=f({mutationFn:r.testAllNotificationProviders,onSuccess:e=>{qa(e),n.invalidateQueries({queryKey:[`notification-providers`]}),e.failed===0?v(`All ${e.tested} providers tested successfully!`,`success`):v(`${e.success}/${e.tested} providers succeeded`,e.failed>0?`error`:`success`)},onError:e=>{v(`Failed to test providers: ${e.message}`,`error`)}}),Ya=f({mutationFn:async e=>{if(!li)return{success:0,failed:0};let t=li.filter(e=>e.enabled),n=await Promise.all(t.map(async t=>{try{return await r.controlSmartPlug(t.id,e),{success:!0}}catch{return{success:!1}}}));return{success:n.filter(e=>e.success).length,failed:n.filter(e=>!e.success).length}},onSuccess:(e,t)=>{n.invalidateQueries({queryKey:[`smart-plugs`]}),n.invalidateQueries({queryKey:[`smart-plugs-energy`]}),e.failed===0?v(`All ${e.success} plugs turned ${t}`,`success`):v(`${e.success} plugs turned ${t}, ${e.failed} failed`,`error`)},onError:e=>{v(`Failed: ${e.message}`,`error`)}}),Xa=(0,X.useRef)(null),Za=(0,X.useRef)(null),Qa=(0,X.useRef)(!1),$a=(0,X.useRef)(!0),eo=(0,X.useRef)(null);(0,X.useEffect)(()=>{if(ei&&!H){let e={...ei,external_url:ei.external_url||window.location.origin};eo.current=ei,Ee(e),setTimeout(()=>{$a.current=!1},100)}},[ei,H]),(0,X.useEffect)(()=>{let e=eo.current;if(!ei||!H||!e||ei===e)return;let t={};for(let n of Object.keys(ei))ei[n]!==e[n]&&H[n]===e[n]&&(t[n]=ei[n]);eo.current=ei,Object.keys(t).length>0&&Ee(e=>e&&{...e,...t})},[ei,H]);let to=f({mutationFn:r.updateSettings,onSuccess:e=>{eo.current=e,n.setQueryData([`settings`],e),e.energy_price_source===`homeassistant`&&Ee(t=>t&&{...t,energy_cost_per_kwh:e.energy_cost_per_kwh}),n.invalidateQueries({queryKey:[`archiveStats`]}),n.invalidateQueries({queryKey:[`ui-flags`]}),n.invalidateQueries({queryKey:[`announcements`]}),v(m(`settings.toast.settingsSaved`),`success`)},onError:e=>{v(`Failed to save: ${e.message}`,`error`)},onSettled:()=>{Qa.current=!1}}),no=f({mutationFn:({id:e,data:t})=>r.updatePrinter(e,t),onSuccess:()=>{n.invalidateQueries({queryKey:[`printers`]}),v(m(`settings.toast.cameraSettingsSaved`),`success`)},onError:e=>{v(`Failed to update printer: ${e.message}`,`error`)}});(0,X.useEffect)(()=>{let e=eo.current;if(!($a.current||!H||!ei||!e)&&!(x&&!k(`settings:update`))&&(e.auto_archive!==H.auto_archive||e.save_thumbnails!==H.save_thumbnails||e.capture_finish_photo!==H.capture_finish_photo||(e.finish_photo_restore_plate??!0)!==(H.finish_photo_restore_plate??!0)||e.default_filament_cost!==H.default_filament_cost||e.currency!==H.currency||H.energy_price_source!==`homeassistant`&&e.energy_cost_per_kwh!==H.energy_cost_per_kwh||e.energy_tracking_mode!==H.energy_tracking_mode||(e.energy_price_source??`fixed`)!==(H.energy_price_source??`fixed`)||(e.energy_price_ha_entity??``)!==(H.energy_price_ha_entity??``)||e.check_updates!==H.check_updates||(e.check_printer_firmware??!0)!==(H.check_printer_firmware??!0)||(e.include_beta_updates??!1)!==(H.include_beta_updates??!1)||(e.announcements_enabled??!0)!==(H.announcements_enabled??!0)||(e.announcements_all_users??!1)!==(H.announcements_all_users??!1)||(e.local_login_enabled??!0)!==(H.local_login_enabled??!0)||e.notification_language!==H.notification_language||(e.bed_cooled_threshold??35)!==(H.bed_cooled_threshold??35)||e.ams_humidity_good!==H.ams_humidity_good||e.ams_humidity_fair!==H.ams_humidity_fair||e.ams_temp_good!==H.ams_temp_good||e.ams_temp_fair!==H.ams_temp_fair||(e.ams_temp_alarm??null)!==(H.ams_temp_alarm??null)||e.ams_history_retention_days!==H.ams_history_retention_days||e.disable_filament_warnings!==H.disable_filament_warnings||e.prefer_lowest_filament!==H.prefer_lowest_filament||(e.queue_drying_enabled??!1)!==(H.queue_drying_enabled??!1)||(e.queue_drying_block??!1)!==(H.queue_drying_block??!1)||(e.ambient_drying_enabled??!1)!==(H.ambient_drying_enabled??!1)||(e.ambient_drying_sustained_minutes??0)!==(H.ambient_drying_sustained_minutes??0)||(e.print_drying_enabled??!1)!==(H.print_drying_enabled??!1)||(e.drying_presets??``)!==(H.drying_presets??``)||(e.ams_humidity_thresholds??``)!==(H.ams_humidity_thresholds??``)||e.per_printer_mapping_expanded!==H.per_printer_mapping_expanded||e.date_format!==H.date_format||e.time_format!==H.time_format||e.default_printer_id!==H.default_printer_id||e.ftp_retry_enabled!==H.ftp_retry_enabled||e.ftp_retry_count!==H.ftp_retry_count||e.ftp_retry_delay!==H.ftp_retry_delay||e.ftp_timeout!==H.ftp_timeout||e.mqtt_enabled!==H.mqtt_enabled||e.mqtt_broker!==H.mqtt_broker||e.mqtt_port!==H.mqtt_port||e.mqtt_username!==H.mqtt_username||e.mqtt_password!==H.mqtt_password||e.mqtt_topic_prefix!==H.mqtt_topic_prefix||e.mqtt_use_tls!==H.mqtt_use_tls||e.external_url!==H.external_url||e.ha_enabled!==H.ha_enabled||e.ha_url!==H.ha_url||e.ha_token!==H.ha_token||(e.library_archive_mode??`ask`)!==(H.library_archive_mode??`ask`)||Number(e.library_disk_warning_gb??5)!==Number(H.library_disk_warning_gb??5)||(e.camera_light_mode??`off`)!==(H.camera_light_mode??`off`)||Number(e.camera_light_delay??2)!==Number(H.camera_light_delay??2)||(e.preferred_slicer??`bambu_studio`)!==(H.preferred_slicer??`bambu_studio`)||Ca(e.slice_engine)!==Ca(H.slice_engine)||(e.open_in_slicer??null)!==(H.open_in_slicer??null)||(e.use_slicer_api??!1)!==(H.use_slicer_api??!1)||(e.orcaslicer_api_url??``)!==(H.orcaslicer_api_url??``)||(e.slicer_stall_timeout_minutes??15)!==(H.slicer_stall_timeout_minutes??15)||(e.bambu_studio_api_url??``)!==(H.bambu_studio_api_url??``)||e.prometheus_enabled!==H.prometheus_enabled||e.prometheus_token!==H.prometheus_token||(e.user_notifications_enabled??!0)!==(H.user_notifications_enabled??!0)||(e.default_bed_levelling??`auto`)!==(H.default_bed_levelling??`auto`)||(e.default_flow_cali??`auto`)!==(H.default_flow_cali??`auto`)||(e.default_vibration_cali??!0)!==(H.default_vibration_cali??!0)||(e.default_layer_inspect??!1)!==(H.default_layer_inspect??!1)||(e.default_timelapse??!1)!==(H.default_timelapse??!1)||(e.default_nozzle_offset_cali??`auto`)!==(H.default_nozzle_offset_cali??`auto`)||(e.default_confirm_outcome??!1)!==(H.default_confirm_outcome??!1)||(e.confirm_outcome_external_prints??!1)!==(H.confirm_outcome_external_prints??!1)||(e.confirm_default_good_on_plate_clear??!1)!==(H.confirm_default_good_on_plate_clear??!1)||(e.stagger_group_size??2)!==(H.stagger_group_size??2)||(e.stagger_interval_minutes??5)!==(H.stagger_interval_minutes??5)||(e.require_plate_clear??!1)!==(H.require_plate_clear??!1)||(e.queue_max_concurrent_uploads??4)!==(H.queue_max_concurrent_uploads??4)||(e.preheat_enabled??!1)!==(H.preheat_enabled??!1)||(e.preheat_filament_targets??``)!==(H.preheat_filament_targets??``)||(e.preheat_max_wait_seconds??900)!==(H.preheat_max_wait_seconds??900)||(e.preheat_soak_seconds??300)!==(H.preheat_soak_seconds??300)||(e.queue_keep_bed_warm??!1)!==(H.queue_keep_bed_warm??!1)||(e.queue_keep_warm_bed_temp??90)!==(H.queue_keep_warm_bed_temp??90)||(e.queue_keep_warm_max_minutes??120)!==(H.queue_keep_warm_max_minutes??120)||(e.nozzle_temp_presets??``)!==(H.nozzle_temp_presets??``)||(e.bed_temp_presets??``)!==(H.bed_temp_presets??``)||(e.chamber_temp_presets??``)!==(H.chamber_temp_presets??``)||(e.fan_speed_presets??``)!==(H.fan_speed_presets??``)||(e.session_max_hours??24)!==(H.session_max_hours??24)||(e.billing_enabled??!1)!==(H.billing_enabled??!1)||(e.printer_kill_switch_enabled??!1)!==(H.printer_kill_switch_enabled??!1)||(e.finance_budget_reset_day??1)!==(H.finance_budget_reset_day??1)||(e.finance_budget_reset_timezone??`UTC`)!==(H.finance_budget_reset_timezone??`UTC`))&&!Qa.current)return Xa.current&&clearTimeout(Xa.current),Xa.current=setTimeout(()=>{if(Qa.current)return;Qa.current=!0;let e={auto_archive:H.auto_archive,save_thumbnails:H.save_thumbnails,capture_finish_photo:H.capture_finish_photo,finish_photo_restore_plate:H.finish_photo_restore_plate??!0,default_filament_cost:H.default_filament_cost,currency:H.currency,...H.energy_price_source===`homeassistant`?{}:{energy_cost_per_kwh:H.energy_cost_per_kwh},energy_tracking_mode:H.energy_tracking_mode,energy_price_source:H.energy_price_source===`homeassistant`?`homeassistant`:`fixed`,energy_price_ha_entity:H.energy_price_ha_entity??``,check_updates:H.check_updates,check_printer_firmware:H.check_printer_firmware,include_beta_updates:H.include_beta_updates,announcements_enabled:H.announcements_enabled??!0,announcements_all_users:H.announcements_all_users??!1,local_login_enabled:H.local_login_enabled,notification_language:H.notification_language,bed_cooled_threshold:H.bed_cooled_threshold,ams_humidity_good:H.ams_humidity_good,ams_humidity_fair:H.ams_humidity_fair,ams_temp_good:H.ams_temp_good,ams_temp_fair:H.ams_temp_fair,ams_temp_alarm:H.ams_temp_alarm??null,ams_history_retention_days:H.ams_history_retention_days,disable_filament_warnings:H.disable_filament_warnings,prefer_lowest_filament:H.prefer_lowest_filament,queue_drying_enabled:H.queue_drying_enabled,queue_drying_block:H.queue_drying_block,ambient_drying_enabled:H.ambient_drying_enabled,ambient_drying_sustained_minutes:H.ambient_drying_sustained_minutes,print_drying_enabled:H.print_drying_enabled,drying_presets:H.drying_presets,ams_humidity_thresholds:H.ams_humidity_thresholds,per_printer_mapping_expanded:H.per_printer_mapping_expanded,date_format:H.date_format,time_format:H.time_format,default_printer_id:H.default_printer_id,ftp_retry_enabled:H.ftp_retry_enabled,ftp_retry_count:H.ftp_retry_count,ftp_retry_delay:H.ftp_retry_delay,ftp_timeout:H.ftp_timeout,mqtt_enabled:H.mqtt_enabled,mqtt_broker:H.mqtt_broker,mqtt_port:H.mqtt_port,mqtt_username:H.mqtt_username,mqtt_password:H.mqtt_password,mqtt_topic_prefix:H.mqtt_topic_prefix,mqtt_use_tls:H.mqtt_use_tls,external_url:H.external_url,ha_enabled:H.ha_enabled,ha_url:H.ha_url,ha_token:H.ha_token,library_archive_mode:H.library_archive_mode,library_disk_warning_gb:H.library_disk_warning_gb,camera_light_mode:H.camera_light_mode,camera_light_delay:H.camera_light_delay,preferred_slicer:H.preferred_slicer,slice_engine:H.slice_engine,open_in_slicer:H.open_in_slicer,use_slicer_api:H.use_slicer_api,orcaslicer_api_url:H.orcaslicer_api_url,slicer_stall_timeout_minutes:H.slicer_stall_timeout_minutes,bambu_studio_api_url:H.bambu_studio_api_url,prometheus_enabled:H.prometheus_enabled,prometheus_token:H.prometheus_token,user_notifications_enabled:H.user_notifications_enabled,default_bed_levelling:H.default_bed_levelling,default_flow_cali:H.default_flow_cali,default_vibration_cali:H.default_vibration_cali,default_layer_inspect:H.default_layer_inspect,default_timelapse:H.default_timelapse,default_nozzle_offset_cali:H.default_nozzle_offset_cali,default_confirm_outcome:H.default_confirm_outcome,confirm_outcome_external_prints:H.confirm_outcome_external_prints,confirm_default_good_on_plate_clear:H.confirm_default_good_on_plate_clear,stagger_group_size:H.stagger_group_size,stagger_interval_minutes:H.stagger_interval_minutes,require_plate_clear:H.require_plate_clear,queue_max_concurrent_uploads:H.queue_max_concurrent_uploads,preheat_enabled:H.preheat_enabled,preheat_filament_targets:H.preheat_filament_targets,preheat_max_wait_seconds:H.preheat_max_wait_seconds,preheat_soak_seconds:H.preheat_soak_seconds,queue_keep_bed_warm:H.queue_keep_bed_warm,queue_keep_warm_bed_temp:H.queue_keep_warm_bed_temp,queue_keep_warm_max_minutes:H.queue_keep_warm_max_minutes,nozzle_temp_presets:H.nozzle_temp_presets,bed_temp_presets:H.bed_temp_presets,chamber_temp_presets:H.chamber_temp_presets,fan_speed_presets:H.fan_speed_presets,session_max_hours:H.session_max_hours,billing_enabled:H.billing_enabled,printer_kill_switch_enabled:H.printer_kill_switch_enabled,finance_budget_reset_day:H.finance_budget_reset_day,finance_budget_reset_timezone:H.finance_budget_reset_timezone};to.mutate(e)},500),()=>{Xa.current&&clearTimeout(Xa.current)}},[H,ei,to,x,k,v,m]);let $=(0,X.useCallback)((e,t)=>{if(x&&!k(`settings:update`)){v(m(`settings.toast.noPermissionUpdate`),`error`);return}Ee(n=>n?{...n,[e]:t}:null)},[x,k,v,m]),ro=async(e,t,n)=>{if(!t){v(m(`settings.toast.enterCameraUrl`),`error`);return}Qr(t=>({...t,[e]:!0})),Xr(t=>({...t,[e]:null}));try{let i=await r.testExternalCamera(e,t,n);Xr(t=>({...t,[e]:i})),i.success?v(i.coalesced?m(`settings.toast.cameraConnectedCoalesced`,{resolution:i.resolution||``}):m(`settings.toast.cameraConnected`,{resolution:i.resolution||``}),`success`):v(i.error||m(`settings.toast.connectionFailed`),`error`)}catch(t){let n=t instanceof Error?t.message:m(`settings.toast.testFailed`);Xr(t=>({...t,[e]:{success:!1,error:n}})),v(n,`error`)}finally{Qr(t=>({...t,[e]:!1}))}},[io,ao]=(0,X.useState)({}),oo=(0,X.useRef)({}),so=(0,X.useRef)(new Set),[co,lo]=(0,X.useState)({}),uo=(0,X.useRef)({}),[fo,po]=(0,X.useState)(null),mo=(0,X.useRef)(new Set);(0,X.useEffect)(()=>{if(wi){let e={},t={};wi.forEach(n=>{n.external_camera_url&&!so.current.has(n.id)&&(e[n.id]=n.external_camera_url,so.current.add(n.id)),n.external_camera_snapshot_url&&!mo.current.has(n.id)&&(t[n.id]=n.external_camera_snapshot_url,mo.current.add(n.id))}),Object.keys(e).length>0&&ao(t=>({...t,...e})),Object.keys(t).length>0&&lo(e=>({...e,...t}))}},[wi]);let ho=(e,t)=>{ao(n=>({...n,[e]:t})),oo.current[e]&&clearTimeout(oo.current[e]),oo.current[e]=setTimeout(()=>{no.mutate({id:e,data:{external_camera_url:t||null}})},800)},go=(e,t)=>{lo(n=>({...n,[e]:t})),uo.current[e]&&clearTimeout(uo.current[e]),uo.current[e]=setTimeout(()=>{no.mutate({id:e,data:{external_camera_snapshot_url:t||null}})},800)},_o=(e,t)=>{let n={};t.type!==void 0&&(n.external_camera_type=t.type||null),t.enabled!==void 0&&(n.external_camera_enabled=t.enabled),t.rotation!==void 0&&(n.camera_rotation=t.rotation),t.lightAuto!==void 0&&(n.camera_light_auto=t.lightAuto),no.mutate({id:e,data:n})};if(ti||!H)return(0,Y.jsx)(`div`,{className:`p-4 md:p-8 flex justify-center`,children:(0,Y.jsx)(L,{className:`w-8 h-8 text-bambu-green animate-spin`})});let vo=pa().map(e=>({...e,label:m(e.labelKey,e.labelFallback??e.labelKey)})),yo=tn.trim().toLowerCase(),bo=yo?vo.filter(e=>e.label.toLowerCase().includes(yo)||e.keywords.toLowerCase().includes(yo)).slice(0,8):[],xo=e=>{In(e.tab),e.subTab&&jn(e.subTab),on(``),setTimeout(()=>{let t=document.getElementById(e.anchor);t&&(t.scrollIntoView({behavior:`smooth`,block:`start`}),t.classList.add(`ring-2`,`ring-bambu-green`),setTimeout(()=>t.classList.remove(`ring-2`,`ring-bambu-green`),1500))},50)},So=(H?.docker_compose_dir??``).trim()||(ia?.compose_dir_detected??``),Co=So?`cd ${/\s/.test(So)?`"${So}"`:So} && docker compose pull && docker compose up -d`:`docker compose pull && docker compose up -d`,wo=H.camera_light_mode??`off`,To=(wi??[]).filter(e=>e.camera_light_auto),Eo=(wi??[]).filter(e=>e.external_camera_enabled),Do=e=>e>0&&(0,Y.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full shrink-0`,children:e}),Oo=e=>(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0 ${e?`bg-green-400`:`bg-gray-500`}`}),ko=(Ei?.length??0)+(Di?.length??0),Ao={tab:`general`,icon:yt,label:m(`settings.tabs.general`)},jo=[{tab:`plugs`,icon:dt,label:m(`settings.tabs.smartPlugs`),extra:Do(li?.length??0)},{tab:`sensors`,icon:ie,label:m(`settings.tabs.sensors`),extra:Do(ko)},{tab:`notifications`,icon:rt,label:m(`settings.tabs.notifications`),extra:Do(vi?.length??0)},{tab:`queue`,icon:Zt,label:m(`settings.tabs.queue`,`Workflow`)},{tab:`filament`,icon:bn,label:m(`settings.tabs.filament`)},{tab:`camera`,icon:$e,label:m(`settings.tabs.camera`)},{tab:`network`,icon:ht,label:m(`settings.tabs.network`),extra:Oo(!!ua?.enabled)},...Cn?[{tab:`apikeys`,icon:Kt,label:m(`settings.tabs.apiKeys`),extra:Do(bi?.length??0)}]:[],{tab:`virtual-printer`,icon:it,label:m(`settings.tabs.virtualPrinter`),extra:Oo(!!Li)},{tab:`spoolbuddy`,icon:ke,label:m(`settings.tabs.spoolbuddy`),extra:(0,Y.jsxs)(Y.Fragment,{children:[Do(zi),Oo(!!Bi)]})},{tab:`failure-detection`,icon:Se,label:m(`settings.tabs.failureDetection`),extra:Oo(!!Wi)},{tab:`users`,icon:Ze,label:m(`settings.tabs.users`),extra:x&&(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0 bg-green-400`})},{tab:`backup`,icon:gt,label:m(`settings.tabs.backup`),extra:Oo(!!(Q?.is_authenticated&&fa?.configured&&fa?.enabled||ei?.local_backup_enabled))}].sort((e,t)=>e.label.localeCompare(t.label,_.language));return(0,Y.jsx)(ze,{density:`dense`,children:(0,Y.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,Y.jsxs)(`div`,{className:`mb-4 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,Y.jsx)(yt,{className:`w-7 h-7 text-bambu-green`}),m(`settings.title`)]}),(0,Y.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:m(`settings.configureBambuddy`)})]}),(0,Y.jsxs)(`div`,{className:`relative sm:w-72`,children:[(0,Y.jsx)(Ae,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none`}),(0,Y.jsx)(`input`,{type:`text`,value:tn,onChange:e=>on(e.target.value),placeholder:m(`settings.searchPlaceholder`,`Search settings…`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),tn&&(0,Y.jsx)(`button`,{onClick:()=>on(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-bambu-gray hover:text-white`,"aria-label":`Clear`,children:(0,Y.jsx)(Re,{className:`w-3.5 h-3.5`})}),bo.length>0&&(0,Y.jsx)(`div`,{className:`absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-30 overflow-hidden`,children:bo.map(e=>(0,Y.jsxs)(`button`,{onClick:()=>xo(e),className:`w-full px-3 py-2 text-left hover:bg-bambu-dark-tertiary transition-colors border-b border-bambu-dark-tertiary last:border-b-0`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:e.label}),(0,Y.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[m(`settings.tabs.${e.tab===`virtual-printer`?`virtualPrinter`:e.tab===`failure-detection`?`failureDetection`:e.tab}`),e.subTab?` › ${m(`settings.tabs.${e.subTab}`,e.subTab)}`:``]})]},e.anchor))}),yo&&bo.length===0&&(0,Y.jsx)(`div`,{className:`absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-30 p-3`,children:(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray italic`,children:m(`settings.noSearchResults`,`No matching settings.`)})})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,Y.jsx)(`nav`,{className:`flex flex-wrap gap-1 border-b border-bambu-dark-tertiary lg:flex-col lg:flex-nowrap lg:gap-0 lg:border-b-0 lg:border-r lg:w-60 lg:flex-shrink-0 lg:self-start lg:sticky lg:top-4`,children:[Ao,...jo].map(({tab:e,icon:t,label:n,extra:r})=>(0,Y.jsxs)(`button`,{onClick:()=>In(e),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${En===e?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,Y.jsx)(t,{className:`w-4 h-4 shrink-0`}),n,r]},e))}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[En===`general`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`a`,{href:nn(Ni,`app-settings`),target:`_blank`,rel:`noopener noreferrer`,className:`group block mb-4 lg:mb-6 rounded-xl border border-bambu-green/30 bg-gradient-to-br from-bambu-green/15 via-bambu-green/5 to-transparent hover:border-bambu-green/50 hover:from-bambu-green/20 transition-colors`,children:(0,Y.jsxs)(`div`,{className:`flex flex-col md:flex-row items-start md:items-center gap-4 p-4 md:p-5`,children:[(0,Y.jsx)(`div`,{className:`p-3 rounded-lg bg-bambu-green/20 text-bambu-green flex-shrink-0`,children:Ni===`business`?(0,Y.jsx)(C,{className:`w-6 h-6`}):(0,Y.jsx)($t,{className:`w-6 h-6`})}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`p`,{className:`text-base font-semibold text-white`,children:Ni===`business`?m(`sponsors.businessTitle`,`Bambuddy for business`):m(`sponsors.sectionTitle`,`Independent & community-funded`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-0.5`,children:Ni===`business`?m(`sponsors.businessTagline`,`You're running {{count}} printers. Priority support, commercial licensing and invoicing are available for teams and print farms.`,{count:wi?.length??0}):m(`sponsors.tagline`,`Bambuddy is free and stays that way because people choose to support it. No VC, no cloud lock-in.`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 rounded-lg bg-bambu-green/20 text-bambu-green group-hover:bg-bambu-green/30 text-sm font-medium whitespace-nowrap self-start md:self-auto`,children:[Ni===`business`?m(`sponsors.businessCta`,`Bambuddy for business`):m(`sponsors.viewSupporters`,`View supporters`),(0,Y.jsx)(Je,{className:`w-4 h-4`})]})]})}),(0,Y.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,Y.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,Y.jsxs)(G,{id:`card-general`,children:[(0,Y.jsx)(U,{children:(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:m(`settings.general`)})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,Y.jsx)(zt,{className:`w-4 h-4 inline mr-1`}),m(`settings.language`)]}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`select`,{value:_.language,onChange:e=>{let t=e.target.value;if(x&&!k(`settings:update`)){v(m(`settings.toast.noPermissionUpdate`),`error`);return}_.changeLanguage(t),to.mutate({language:t})},className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:tt.map(e=>(0,Y.jsxs)(`option`,{value:e.code,children:[e.nativeName,` (`,e.name,`)`]},e.code))}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.languageDescription`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.defaultView`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`select`,{value:gn,onChange:e=>$r(e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:kt.map(e=>(0,Y.jsx)(`option`,{value:e.to,children:m(e.labelKey)},e.id))}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.defaultViewDescription`)})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.dateFormat`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsxs)(`select`,{value:H.date_format||`system`,onChange:e=>$(`date_format`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,Y.jsx)(`option`,{value:`system`,children:m(`settings.systemDefault`)}),(0,Y.jsx)(`option`,{value:`us`,children:m(`settings.dateFormatUs`)}),(0,Y.jsx)(`option`,{value:`eu`,children:m(`settings.dateFormatEu`)}),(0,Y.jsx)(`option`,{value:`iso`,children:m(`settings.dateFormatIso`)})]}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.timeFormat`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsxs)(`select`,{value:H.time_format||`system`,onChange:e=>$(`time_format`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,Y.jsx)(`option`,{value:`system`,children:m(`settings.systemDefault`)}),(0,Y.jsx)(`option`,{value:`12h`,children:m(`settings.timeFormat12`)}),(0,Y.jsx)(`option`,{value:`24h`,children:m(`settings.timeFormat24`)})]}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.defaultPrinter`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsxs)(`select`,{value:H.default_printer_id??``,onChange:e=>$(`default_printer_id`,e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,Y.jsx)(`option`,{value:``,children:m(`settings.noDefaultPrinter`)}),wi?.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.defaultPrinterDescription`)})]})]})]}),(0,Y.jsxs)(G,{id:`card-appearance`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(Nt,{className:`w-5 h-5`}),m(`settings.appearance`)]})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,Y.jsxs)(`label`,{className:`text-sm text-bambu-gray`,children:[m(`settings.theme`),`:`]}),(0,Y.jsx)(`div`,{className:`flex gap-1`,children:[{id:`dark`,label:m(`settings.themeDark`)},{id:`light`,label:m(`settings.themeLight`)},{id:`system`,label:m(`settings.themeSystem`)}].map(({id:e,label:t})=>(0,Y.jsx)(`button`,{onClick:()=>{de(e),v(m(`settings.toast.settingsSaved`),`success`)},className:`px-3 py-1 text-xs rounded-lg border transition-colors ${re===e?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-gray-300 dark:border-bambu-dark-tertiary text-gray-500 dark:text-bambu-gray hover:text-gray-900 dark:hover:text-white cursor-pointer`}`,children:t},e))})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-4 rounded-lg border ${ae===`dark`?`border-bambu-green bg-bambu-green/5`:`border-bambu-dark-tertiary`}`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[m(`settings.darkMode`),ae===`dark`&&(0,Y.jsx)(`span`,{className:`text-xs text-bambu-green`,children:m(`settings.active`)})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:m(`settings.background`)}),(0,Y.jsxs)(`select`,{value:F,onChange:e=>{pe(e.target.value),v(m(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`neutral`,children:m(`settings.bgNeutral`)}),(0,Y.jsx)(`option`,{value:`warm`,children:m(`settings.bgWarm`)}),(0,Y.jsx)(`option`,{value:`cool`,children:m(`settings.bgCool`)}),(0,Y.jsx)(`option`,{value:`oled`,children:m(`settings.bgOled`)}),(0,Y.jsx)(`option`,{value:`slate`,children:m(`settings.bgSlate`)}),(0,Y.jsx)(`option`,{value:`forest`,children:m(`settings.bgForest`)})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:m(`settings.accent`)}),(0,Y.jsxs)(`select`,{value:ce,onChange:e=>{me(e.target.value),v(m(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`green`,children:m(`settings.accentGreen`)}),(0,Y.jsx)(`option`,{value:`teal`,children:m(`settings.accentTeal`)}),(0,Y.jsx)(`option`,{value:`blue`,children:m(`settings.accentBlue`)}),(0,Y.jsx)(`option`,{value:`orange`,children:m(`settings.accentOrange`)}),(0,Y.jsx)(`option`,{value:`purple`,children:m(`settings.accentPurple`)}),(0,Y.jsx)(`option`,{value:`red`,children:m(`settings.accentRed`)})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:m(`settings.style`)}),(0,Y.jsxs)(`select`,{value:oe,onChange:e=>{fe(e.target.value),v(m(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`classic`,children:m(`settings.styleClassic`)}),(0,Y.jsx)(`option`,{value:`glow`,children:m(`settings.styleGlow`)}),(0,Y.jsx)(`option`,{value:`vibrant`,children:m(`settings.styleVibrant`)})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-4 rounded-lg border ${ae===`light`?`border-bambu-green bg-bambu-green/5`:`border-bambu-dark-tertiary`}`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[m(`settings.lightMode`),ae===`light`&&(0,Y.jsx)(`span`,{className:`text-xs text-bambu-green`,children:m(`settings.active`)})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:m(`settings.background`)}),(0,Y.jsxs)(`select`,{value:le,onChange:e=>{ge(e.target.value),v(m(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`neutral`,children:m(`settings.bgNeutral`)}),(0,Y.jsx)(`option`,{value:`warm`,children:m(`settings.bgWarm`)}),(0,Y.jsx)(`option`,{value:`cool`,children:m(`settings.bgCool`)})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:m(`settings.accent`)}),(0,Y.jsxs)(`select`,{value:V,onChange:e=>{_e(e.target.value),v(m(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`green`,children:m(`settings.accentGreen`)}),(0,Y.jsx)(`option`,{value:`teal`,children:m(`settings.accentTeal`)}),(0,Y.jsx)(`option`,{value:`blue`,children:m(`settings.accentBlue`)}),(0,Y.jsx)(`option`,{value:`orange`,children:m(`settings.accentOrange`)}),(0,Y.jsx)(`option`,{value:`purple`,children:m(`settings.accentPurple`)}),(0,Y.jsx)(`option`,{value:`red`,children:m(`settings.accentRed`)})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:m(`settings.style`)}),(0,Y.jsxs)(`select`,{value:B,onChange:e=>{he(e.target.value),v(m(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`classic`,children:m(`settings.styleClassic`)}),(0,Y.jsx)(`option`,{value:`glow`,children:m(`settings.styleGlow`)}),(0,Y.jsx)(`option`,{value:`vibrant`,children:m(`settings.styleVibrant`)})]})]})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.themeToggleHint`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.progressInTitle`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.progressInTitleDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:ye,onChange:e=>{be(e.target.checked),v(m(`settings.toast.settingsSaved`),`success`)},className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]})]}),(0,Y.jsxs)(G,{id:`card-archive`,children:[(0,Y.jsx)(U,{children:(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:m(`settings.archiveSettings`)})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.autoArchivePrints`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.autoArchiveDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.auto_archive,onChange:e=>$(`auto_archive`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.saveThumbnails`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.saveThumbnailsDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.save_thumbnails,onChange:e=>$(`save_thumbnails`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.captureFinishPhoto`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.captureFinishPhotoDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.capture_finish_photo,onChange:e=>$(`capture_finish_photo`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),H.capture_finish_photo&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.finishPhotoRestorePlate`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.finishPhotoRestorePlateDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.finish_photo_restore_plate??!0,onChange:e=>$(`finish_photo_restore_plate`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),H.capture_finish_photo&&Gi&&!Gi.installed&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg`,children:[(0,Y.jsx)(Ie,{className:`w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{className:`text-sm`,children:[(0,Y.jsx)(`p`,{className:`text-yellow-500 font-medium`,children:m(`settings.ffmpegNotInstalled`)}),(0,Y.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:m(`settings.ffmpegRequired`)})]})]}),$i&&ea&&(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`archiveAutoPurge.enableLabel`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`archiveAutoPurge.enableDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:ea.enabled,onChange:e=>na({enabled:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`archiveAutoPurge.ageLabel`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`input`,{type:`number`,min:7,max:3650,disabled:!ea.enabled,value:ea.days,onChange:e=>na({days:Math.max(7,Math.min(3650,parseInt(e.target.value||`0`,10)||0))}),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:m(`archiveAutoPurge.days`)})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`archiveAutoPurge.ageDescription`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,disabled:!ea.enabled,checked:ea.purge_stats,onChange:e=>na({purge_stats:e.target.checked}),className:`mt-0.5 shrink-0 disabled:opacity-50`}),(0,Y.jsxs)(`span`,{className:`text-sm`,children:[(0,Y.jsx)(`span`,{className:`text-white block`,children:m(`archiveAutoPurge.purgeStatsLabel`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray block mt-0.5`,children:m(`archiveAutoPurge.purgeStatsDescription`)})]})]})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-md`,children:[(0,Y.jsxs)(G,{id:`card-cost`,children:[(0,Y.jsx)(U,{children:(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:m(`settings.costTracking`)})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.currency`)}),(0,Y.jsx)(`select`,{value:H.currency,onChange:e=>$(`currency`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:Ht.map(e=>(0,Y.jsx)(`option`,{value:e.code,children:e.label},e.code))})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.defaultFilamentCost`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:Et(H.currency)}),(0,Y.jsx)(ct,{step:`0.01`,min:0,value:H.default_filament_cost,onChange:e=>$(`default_filament_cost`,e),integer:!1,fallback:0,style:{paddingLeft:`${Math.max(2,Et(H.currency).length*.6+1)}rem`},className:`w-full pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.energyPriceSource`)}),(0,Y.jsxs)(`select`,{value:H.energy_price_source===`homeassistant`?`homeassistant`:`fixed`,onChange:e=>$(`energy_price_source`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`fixed`,children:m(`settings.energyPriceSourceFixed`)}),(0,Y.jsx)(`option`,{value:`homeassistant`,children:m(`settings.energyPriceSourceHomeAssistant`)})]}),H.energy_price_source===`homeassistant`&&!H.ha_enabled&&(0,Y.jsx)(`p`,{className:`text-xs text-yellow-500 mt-1`,children:m(`settings.energyPriceHaNotConfigured`)})]}),H.energy_price_source===`homeassistant`&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.energyPriceHaEntity`)}),(0,Y.jsx)(`input`,{type:`text`,list:`ha-price-entities`,value:H.energy_price_ha_entity??``,onChange:e=>$(`energy_price_ha_entity`,e.target.value.trim()),placeholder:`sensor.electricity_price`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`datalist`,{id:`ha-price-entities`,children:(oi??[]).map(e=>(0,Y.jsx)(`option`,{value:e.entity_id,children:`${e.friendly_name} (${e.state??`?`} ${e.unit_of_measurement??``})`},e.entity_id))})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:H.energy_price_source===`homeassistant`?m(`settings.energyPriceLastRead`):m(`settings.electricityCost`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:Et(H.currency)}),(0,Y.jsx)(ct,{step:`0.001`,min:0,value:H.energy_cost_per_kwh,onChange:e=>$(`energy_cost_per_kwh`,e),integer:!1,fallback:0,disabled:H.energy_price_source===`homeassistant`,style:{paddingLeft:`${Math.max(2,Et(H.currency).length*.6+1)}rem`},className:`w-full pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-60`})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:H.energy_price_source===`homeassistant`?m(`settings.energyPriceHaHint`):m(`settings.energyPriceFixedHint`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.energyDisplayMode`)}),(0,Y.jsxs)(`select`,{value:H.energy_tracking_mode||`total`,onChange:e=>$(`energy_tracking_mode`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`print`,children:m(`settings.printsOnly`)}),(0,Y.jsx)(`option`,{value:`total`,children:m(`settings.totalConsumption`)})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:H.energy_tracking_mode===`print`?m(`settings.energyModePrintDescription`):m(`settings.energyModeTotalDescription`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.billingEnabled`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.billingEnabledDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.billing_enabled??!1,onChange:e=>$(`billing_enabled`,e.target.checked),className:`peer sr-only`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary rounded-full peer-checked:bg-bambu-green peer-checked:after:translate-x-5 after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border after:rounded-full after:h-5 after:w-5 after:transition-all`})]})]}),H.billing_enabled&&(0,Y.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-4 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark px-4 py-3`,children:[(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.printerKillSwitch`,`Unauthorized print kill switch`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.printerKillSwitchDescription`,`Immediately stop prints that start without authorization.`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.printer_kill_switch_enabled??!1,onChange:e=>$(`printer_kill_switch_enabled`,e.target.checked),className:`peer sr-only`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary rounded-full peer-checked:bg-bambu-green peer-checked:after:translate-x-5 after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border after:rounded-full after:h-5 after:w-5 after:transition-all`})]})]}),H.billing_enabled&&(0,Y.jsxs)(`div`,{className:`mt-4 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-4`,children:[(0,Y.jsx)(`div`,{className:`mb-3`,children:(0,Y.jsxs)(`h4`,{className:`text-base font-medium text-white flex items-center gap-2`,children:[(0,Y.jsx)(w,{className:`w-4 h-4 text-bambu-green`}),m(`settings.financeBudgetReset`,`Finance Monthly Budget Reset`)]})}),(0,Y.jsxs)(`div`,{className:`flex gap-4`,children:[(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:m(`settings.financeBudgetResetDay`,`Reset Day`)}),(0,Y.jsx)(`input`,{type:`number`,min:1,max:31,value:H.finance_budget_reset_day??1,onChange:e=>$(`finance_budget_reset_day`,Math.max(1,Math.min(31,parseInt(e.target.value,10)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.financeBudgetResetDayHelp`,`For short months, reset uses the last day of the month.`)})]}),(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:m(`settings.financeBudgetResetTimezone`,`Reset timezone`)}),(0,Y.jsxs)(`select`,{value:H.finance_budget_reset_timezone??`UTC`,onChange:e=>$(`finance_budget_reset_timezone`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,children:[(0,Y.jsx)(`option`,{value:`UTC`,children:`UTC`}),(0,Y.jsx)(`option`,{value:`Europe/Berlin`,children:`Europe/Berlin`}),(0,Y.jsx)(`option`,{value:`Europe/Vienna`,children:`Europe/Vienna`}),(0,Y.jsx)(`option`,{value:`Europe/Zurich`,children:`Europe/Zurich`}),(0,Y.jsx)(`option`,{value:`America/New_York`,children:`America/New_York`}),(0,Y.jsx)(`option`,{value:`America/Chicago`,children:`America/Chicago`}),(0,Y.jsx)(`option`,{value:`America/Denver`,children:`America/Denver`}),(0,Y.jsx)(`option`,{value:`America/Los_Angeles`,children:`America/Los_Angeles`}),(0,Y.jsx)(`option`,{value:`Asia/Tokyo`,children:`Asia/Tokyo`}),(0,Y.jsx)(`option`,{value:`Asia/Singapore`,children:`Asia/Singapore`}),(0,Y.jsx)(`option`,{value:`Australia/Sydney`,children:`Australia/Sydney`})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.financeBudgetResetTimezoneHelp`,`Budget window start is calculated in this timezone.`)})]})]})]}),H.billing_enabled&&T&&(0,Y.jsxs)(`div`,{className:`mt-3`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:()=>pn(!0),disabled:mn,children:mn?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(L,{className:`w-4 h-4 mr-2 animate-spin`}),m(`settings.rebuildLedgerInProgress`,`Starting...`)]}):m(`settings.rebuildLedger`,`Rebuild wallet ledger`)}),fn&&(0,Y.jsx)(Tt,{title:m(`settings.rebuildLedgerConfirmTitle`,`Rebuild wallet ledger?`),message:m(`settings.rebuildLedgerConfirmMessage`,`This will rebuild the wallet ledger to repair historical balance values. Run this only if you know what you are doing.`),confirmText:m(`common.run`,`Run`),cancelText:m(`common.cancel`,`Cancel`),isLoading:mn,loadingText:m(`common.running`,`Running`),variant:`warning`,onCancel:()=>pn(!1),onConfirm:async()=>{hn(!0);try{await r.rebuildBalanceLedger(),v(m(`settings.rebuildLedgerStarted`,`Ledger rebuild started`),`success`),pn(!1)}catch(e){v(e.message||`Failed to start ledger rebuild`,`error`)}finally{hn(!1)}}})]})]})]})]}),(0,Y.jsxs)(G,{id:`card-filemanager`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(ln,{className:`w-5 h-5 text-bambu-green`}),m(`settings.fileManager`)]})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.createArchiveEntry`)}),(0,Y.jsxs)(`select`,{value:H.library_archive_mode??`ask`,onChange:e=>$(`library_archive_mode`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`always`,children:m(`settings.archiveMode.always`)}),(0,Y.jsx)(`option`,{value:`never`,children:m(`settings.archiveMode.never`)}),(0,Y.jsx)(`option`,{value:`ask`,children:m(`settings.archiveMode.ask`)})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.createArchiveEntryDescription`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.lowDiskSpaceWarning`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ct,{min:.5,max:100,step:`0.5`,value:H.library_disk_warning_gb??5,onChange:e=>$(`library_disk_warning_gb`,e),integer:!1,fallback:5,className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:`GB`})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.lowDiskSpaceDescription`)})]}),Yi&&Xi&&(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`libraryAutoPurge.enableLabel`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`libraryAutoPurge.enableDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Xi.auto_purge_enabled,onChange:e=>Qi({auto_purge_enabled:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`libraryAutoPurge.ageLabel`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`input`,{type:`number`,min:7,max:3650,disabled:!Xi.auto_purge_enabled,value:Xi.auto_purge_days,onChange:e=>Qi({auto_purge_days:Math.max(7,Math.min(3650,parseInt(e.target.value||`0`,10)||0))}),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:m(`libraryAutoPurge.days`)})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`libraryAutoPurge.ageDescription`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-white cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,disabled:!Xi.auto_purge_enabled,checked:Xi.auto_purge_include_never_printed,onChange:e=>Qi({auto_purge_include_never_printed:e.target.checked}),className:`rounded border-gray-300 disabled:opacity-50`}),m(`libraryAutoPurge.includeNeverPrinted`)]})]})]})]}),(0,Y.jsxs)(G,{id:`card-data`,children:[(0,Y.jsx)(U,{children:(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:m(`settings.dataManagement`)})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.clearNotificationLogs`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.clearNotificationLogsDescription`)})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:()=>tr(!0),children:[(0,Y.jsx)(qe,{className:`w-4 h-4`}),m(`common.clear`)]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.resetUiPreferences`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.resetUiPreferencesDescription`)})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:()=>rr(!0),children:[(0,Y.jsx)(qe,{className:`w-4 h-4`}),m(`settings.reset`)]})]}),(0,Y.jsxs)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.storageUsage`,`Storage Usage`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.storageUsageDescription`,`Breakdown of data usage by category`)})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:si,disabled:ii||xr,children:[(0,Y.jsx)(at,{className:`w-4 h-4 ${ii||xr?`animate-spin`:``}`}),m(`common.refresh`,`Refresh`)]})]}),(0,Y.jsx)(`div`,{className:`mt-3`,children:ri?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}),m(`common.loading`,`Loading`)]}):ni?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`w-full h-3 bg-bambu-dark rounded-full overflow-hidden flex`,children:ni.categories.filter(e=>e.bytes>0).map((e,t)=>(0,Y.jsx)(`div`,{className:`${ka(e.key,t)} h-full`,style:{width:`${e.percent_of_total}%`},title:`${e.label}: ${e.formatted}`},e.key))}),(0,Y.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-3`,children:ni.categories.filter(e=>e.bytes>0).map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,Y.jsx)(`span`,{className:`w-3 h-3 rounded-full ${ka(e.key,t)}`}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:e.label}),(0,Y.jsx)(`span`,{className:`text-white`,children:e.formatted}),(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.percent_of_total.toFixed(1),`%)`]})]},e.key))}),(0,Y.jsxs)(`div`,{className:`mt-2 text-xs text-bambu-gray`,children:[m(`settings.storageUsageTotal`,`Total`),`: `,(0,Y.jsx)(`span`,{className:`text-white`,children:ni.total_formatted}),ni.scan_errors>0&&(0,Y.jsxs)(`span`,{className:`ml-2 text-amber-700 dark:text-amber-400`,children:[m(`settings.storageUsageErrors`,`Scan errors`),`: `,ni.scan_errors]})]}),ni.other_breakdown?.length>0&&(0,Y.jsxs)(`div`,{className:`mt-4`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:m(`settings.storageUsageOtherBreakdown`,`Other breakdown`)}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:ni.other_breakdown.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-white`,children:e.label}),(0,Y.jsx)(`span`,{className:`px-2 py-0.5 rounded-full border ${e.kind===`system`?`border-slate-500 text-slate-300`:`border-bambu-green text-bambu-green`}`,children:e.kind===`system`?m(`settings.storageUsageSystem`,`System`):m(`settings.storageUsageData`,`Data`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,Y.jsx)(`span`,{className:`text-white`,children:e.formatted}),(0,Y.jsxs)(`span`,{children:[`(`,e.percent_of_total.toFixed(1),`%)`]})]})]},`${e.bucket}-${e.kind}`))})]})]}):(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.storageUsageUnavailable`,`Storage usage data is unavailable`)})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pt-4 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.backupRestore`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.backupRestoreDescription`)})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:()=>In(`backup`),children:[(0,Y.jsx)(gt,{className:`w-4 h-4`}),m(`settings.goToBackup`)]})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-sm`,children:[(0,Y.jsxs)(G,{id:`card-updates`,children:[(0,Y.jsx)(U,{children:(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:m(`settings.updates`)})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider`,children:m(`settings.printerFirmware`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.checkPrinterFirmware`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.checkFirmwareDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.check_printer_firmware??!0,onChange:e=>$(`check_printer_firmware`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,Y.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider mb-4`,children:m(`settings.bambuddySoftware`)})}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.checkForUpdatesLabel`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.autoCheckDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.check_updates,onChange:e=>$(`check_updates`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between ${H.check_updates?``:`opacity-50`}`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.includeBetaUpdates`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.includeBetaUpdatesDesc`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.include_beta_updates??!1,onChange:e=>$(`include_beta_updates`,e.target.checked),disabled:!H.check_updates,className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.currentVersion`)}),(0,Y.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`v`,qi?.version||`...`]})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:()=>aa(),disabled:oa,children:[oa?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(at,{className:`w-4 h-4`}),m(`settings.checkNow`)]})]}),ia?.update_available?(0,Y.jsxs)(`div`,{className:`mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`p`,{className:`text-bambu-green font-medium`,children:[`Update available: v`,ia.latest_version]}),ia.release_name&&ia.release_name!==ia.latest_version&&(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:ia.release_name})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[ia.release_notes&&(0,Y.jsx)(`button`,{onClick:()=>sr(!0),className:`text-bambu-gray hover:text-white transition-colors text-sm underline`,children:m(`settings.releaseNotes`)}),ia.release_url&&(0,Y.jsx)(`a`,{href:ia.release_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-white transition-colors`,title:m(`settings.viewReleaseOnGitHub`),children:(0,Y.jsx)(Je,{className:`w-4 h-4`})})]})]}),ca?.status===`downloading`||ca?.status===`installing`?(0,Y.jsxs)(`div`,{className:`mt-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}),(0,Y.jsx)(`span`,{children:ca.message})]}),(0,Y.jsx)(`div`,{className:`mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,Y.jsx)(`div`,{className:`bg-bambu-green h-2 rounded-full transition-all duration-300`,style:{width:`${ca.progress}%`}})})]}):ca?.status===`complete`?(0,Y.jsx)(`div`,{className:`mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green`,children:ca.message}):ca?.status===`error`?(0,Y.jsx)(`div`,{className:`mt-3 p-2 bg-red-100 dark:bg-red-500/20 rounded text-sm text-red-700 dark:text-red-400`,children:ca.error||ca.message}):ia?.is_ha_addon?(0,Y.jsx)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.updateViaHomeAssistant`)})}):ia?.is_docker?(0,Y.jsxs)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:m(`settings.updateViaDocker`)}),(0,Y.jsxs)(`div`,{className:`flex items-start gap-1`,children:[(0,Y.jsx)(`code`,{className:`flex-1 block text-xs bg-bambu-dark p-2 rounded text-bambu-green font-mono break-all select-all`,children:Co}),(0,Y.jsx)(we,{value:Co,titleKey:`settings.copyUpdateCommand`,copiedTitleKey:`printers.copied`,className:`ml-0 p-2 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors flex-shrink-0`,iconClassName:`w-4 h-4`})]}),(0,Y.jsxs)(`label`,{className:`block mt-3`,children:[(0,Y.jsx)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:m(`settings.composeDirectory`)}),(0,Y.jsx)(`input`,{type:`text`,value:H?.docker_compose_dir??``,onChange:e=>$(`docker_compose_dir`,e.target.value),placeholder:ia?.compose_dir_detected||`/opt/bambuddy`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white font-mono placeholder:text-bambu-gray/60 focus:outline-none focus:border-bambu-green`}),(0,Y.jsx)(`span`,{className:`block text-xs text-bambu-gray mt-1`,children:m(`settings.composeDirectoryHint`)})]})]}):ia?.update_method===`windows_installer`?(0,Y.jsxs)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:m(`settings.updateViaWindowsInstaller`)}),(0,Y.jsxs)(`a`,{href:ia.installer_download_url||ia.release_url||`https://github.com/maziggy/bambuddy/releases/tag/v${ia.latest_version}`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center justify-center font-medium rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-bambu-dark disabled:opacity-50 bg-bambu-green hover:bg-bambu-green-light text-white focus:ring-bambu-green px-4 py-2 text-sm gap-2 min-h-[44px] md:min-h-0`,children:[(0,Y.jsx)(sn,{className:`w-4 h-4`}),m(`settings.downloadWindowsInstaller`,{version:ia.latest_version})]})]}):(0,Y.jsxs)(K,{className:`mt-3`,onClick:()=>Ga.mutate(),disabled:Ga.isPending,children:[Ga.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(sn,{className:`w-4 h-4`}),m(`settings.installUpdate`)]})]}):ia?.error?(0,Y.jsx)(`div`,{className:`mt-2 p-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded text-sm text-red-700 dark:text-red-400`,children:m(`settings.failedToCheckUpdates`,{error:ia.error})}):ia&&!ia.update_available?(0,Y.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:m(`settings.latestVersionRunning`)}):null]}),(0,Y.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,Y.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider mb-4`,children:m(`announcements.title`)})}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.announcementsEnabled`)}),(0,Y.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[m(`settings.announcementsEnabledDesc`),` `,(0,Y.jsx)(`a`,{href:`https://wiki.bambuddy.cool/features/announcements/`,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline`,children:m(`settings.announcementsLearnMore`)})]})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.announcements_enabled??!0,onChange:e=>$(`announcements_enabled`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between ${H.announcements_enabled===!1?`opacity-50`:``}`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.announcementsAllUsers`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.announcementsAllUsersDesc`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.announcements_all_users??!1,onChange:e=>$(`announcements_all_users`,e.target.checked),disabled:H.announcements_enabled===!1,className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]})]}),(0,Y.jsx)(hi,{})]})]})]}),En===`network`&&H&&(0,Y.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-6`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 lg:max-w-xl space-y-3`,children:[(0,Y.jsxs)(G,{id:`card-externalurl`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(zt,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),m(`settings.externalUrl`)]})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.externalUrlDescription`)}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.bambuddyUrl`)}),(0,Y.jsx)(`input`,{type:`text`,value:H.external_url??``,onChange:e=>$(`external_url`,e.target.value),placeholder:`http://192.168.1.100:8000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.externalUrlHint`)})]})]})]}),(0,Y.jsxs)(G,{id:`card-ftpretry`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(at,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),m(`settings.ftpRetry`)]})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.ftpRetryDescription`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.enableRetry`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.autoRetryDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.ftp_retry_enabled??!0,onChange:e=>$(`ftp_retry_enabled`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),H.ftp_retry_enabled&&(0,Y.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.retryAttempts`)}),(0,Y.jsxs)(`div`,{className:`relative w-44`,children:[(0,Y.jsx)(`select`,{value:H.ftp_retry_count??3,onChange:e=>$(`ftp_retry_count`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[1,2,3,4,5,6,7,8,9,10].map(e=>(0,Y.jsx)(`option`,{value:e,children:m(`settings.time`,{count:e})},e))}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.retryDelay`)}),(0,Y.jsxs)(`div`,{className:`relative w-44`,children:[(0,Y.jsx)(`select`,{value:H.ftp_retry_delay??2,onChange:e=>$(`ftp_retry_delay`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[1,2,3,5,10,15,20,30].map(e=>(0,Y.jsx)(`option`,{value:e,children:m(`settings.second`,{count:e})},e))}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.connectionTimeout`)}),(0,Y.jsxs)(`div`,{className:`relative w-44`,children:[(0,Y.jsx)(`select`,{value:H.ftp_timeout??30,onChange:e=>$(`ftp_timeout`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[10,15,20,30,45,60,90,120,180,300].map(e=>(0,Y.jsx)(`option`,{value:e,children:m(`settings.nSeconds`,{count:e})},e))}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.increaseForWeakWifi`)})]})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 lg:max-w-xl space-y-3`,children:[(0,Y.jsxs)(G,{id:`card-ha`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(Ft,{className:`w-5 h-5 text-bambu-green`}),m(`settings.homeAssistant`)]}),H.ha_enabled&&Gr&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${Gr.success?`bg-green-400`:`bg-red-400`}`}),(0,Y.jsx)(`span`,{className:`text-sm ${Gr.success?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:Gr.success?m(`settings.connected`):m(`settings.disconnected`)})]})]})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.homeAssistantFullDescription`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.enableHomeAssistant`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.homeAssistantDescription`)}),H.ha_env_managed&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 mt-1`,children:[(0,Y.jsx)(R,{className:`w-3 h-3 text-bambu-green`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-green`,children:m(`settings.autoEnabledViaEnv`)})]})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.ha_enabled??!1,onChange:e=>$(`ha_enabled`,e.target.checked),disabled:H.ha_env_managed,className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green ${H.ha_env_managed?`opacity-60 cursor-not-allowed`:``}`})]})]}),H.ha_enabled&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[m(`settings.homeAssistantUrl`),H.ha_url_from_env&&(0,Y.jsx)(`span`,{className:`ml-2 text-xs text-bambu-green`,children:m(`settings.environmentManagedLabel`)})]}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`input`,{type:`text`,value:H.ha_url??``,onChange:e=>$(`ha_url`,e.target.value),placeholder:`http://192.168.1.100:8123`,disabled:H.ha_url_from_env,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${H.ha_url_from_env?`opacity-60 cursor-not-allowed`:``}`}),H.ha_url_from_env&&(0,Y.jsx)(R,{className:`absolute right-3 top-2.5 w-4 h-4 text-bambu-gray`})]}),H.ha_url_from_env&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.urlFromEnvReadOnly`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[m(`settings.longLivedAccessToken`),H.ha_token_from_env&&(0,Y.jsx)(`span`,{className:`ml-2 text-xs text-bambu-green`,children:m(`settings.environmentManagedLabel`)})]}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`input`,{type:`password`,value:H.ha_token??``,onChange:e=>$(`ha_token`,e.target.value),placeholder:`eyJ0eXAiOiJKV1QiLC...`,disabled:H.ha_token_from_env,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${H.ha_token_from_env?`opacity-60 cursor-not-allowed`:``}`}),H.ha_token_from_env&&(0,Y.jsx)(R,{className:`absolute right-3 top-2.5 w-4 h-4 text-bambu-gray`})]}),H.ha_token_from_env?(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.tokenFromEnvReadOnly`)}):(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.haTokenHint`)})]}),H.ha_url&&H.ha_token&&(0,Y.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,disabled:qr,onClick:async()=>{Jr(!0),Kr(null);try{Kr(await r.testHAConnection(H.ha_url,H.ha_token))}catch(e){Kr({success:!1,message:null,error:e instanceof Error?e.message:m(`common.unknownError`)})}finally{Jr(!1)}},children:[qr?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(ht,{className:`w-4 h-4`}),m(`settings.testConnection`)]})})]})]})]}),(0,Y.jsxs)(G,{id:`card-mqtt`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(ht,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),m(`settings.mqttPublishing`)]}),ua?.enabled&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${ua.connected?`bg-green-400`:`bg-red-400`}`}),(0,Y.jsx)(`span`,{className:`text-sm ${ua.connected?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:ua.connected?m(`settings.connected`):m(`settings.disconnected`)})]})]})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.mqttDescription`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.enableMqtt`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.mqttEnableDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.mqtt_enabled??!1,onChange:e=>$(`mqtt_enabled`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),H.mqtt_enabled&&(0,Y.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.brokerHostname`)}),(0,Y.jsx)(`input`,{type:`text`,value:H.mqtt_broker??``,onChange:e=>$(`mqtt_broker`,e.target.value),placeholder:`mqtt.example.com or 192.168.1.100`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`flex items-end gap-4`,children:[(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.port`)}),(0,Y.jsx)(ct,{min:1,max:65535,value:H.mqtt_port??1883,onChange:e=>$(`mqtt_port`,e),fallback:1883,className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 pb-2`,children:[(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.mqtt_use_tls??!1,onChange:e=>{let t=e.target.checked;$(`mqtt_use_tls`,t);let n=H.mqtt_port??1883;t&&n===1883?$(`mqtt_port`,8883):!t&&n===8883&&$(`mqtt_port`,1883)},className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]}),(0,Y.jsx)(`span`,{className:`text-white text-sm`,children:m(`settings.useTls`)})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.usernameOptional`)}),(0,Y.jsx)(`input`,{type:`text`,value:H.mqtt_username??``,onChange:e=>$(`mqtt_username`,e.target.value),placeholder:m(`settings.leaveEmptyForAnonymous`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.passwordOptional`)}),(0,Y.jsx)(`input`,{type:`password`,value:H.mqtt_password??``,onChange:e=>$(`mqtt_password`,e.target.value),placeholder:m(`settings.leaveEmptyForAnonymous`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.topicPrefix`)}),(0,Y.jsx)(`input`,{type:`text`,value:H.mqtt_topic_prefix??`bambuddy`,onChange:e=>$(`mqtt_topic_prefix`,e.target.value),placeholder:`bambuddy`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.topicPrefixHint`,{prefix:H.mqtt_topic_prefix||`bambuddy`})})]}),ua&&(0,Y.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full ${ua.connected?`bg-green-400`:`bg-red-400`}`}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:ua.connected?(0,Y.jsxs)(Y.Fragment,{children:[m(`settings.mqttConnectedTo`),` `,(0,Y.jsxs)(`span`,{className:`text-white`,children:[ua.broker,`:`,ua.port]})]}):m(`settings.spoolmanDisconnected`)})]})})]})]})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 lg:max-w-md space-y-3`,children:(0,Y.jsxs)(G,{id:`card-prometheus`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(g,{className:`w-5 h-5 text-orange-600 dark:text-orange-400`}),m(`settings.prometheusMetrics`)]})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.prometheusEndpointDescription`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.enableMetricsEndpoint`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.prometheusDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.prometheus_enabled??!1,onChange:e=>$(`prometheus_enabled`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),H.prometheus_enabled&&(0,Y.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.bearerTokenOptional`)}),(0,Y.jsx)(`input`,{type:`password`,value:H.prometheus_token??``,onChange:e=>$(`prometheus_token`,e.target.value),placeholder:m(`settings.leaveEmptyForNoAuth`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.bearerTokenHint`)})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white mb-2`,children:m(`settings.availableMetrics`)}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray space-y-1`,children:[(0,Y.jsxs)(`p`,{children:[(0,Y.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_printer_connected`}),` - `,m(`settings.metricsConnectionStatus`)]}),(0,Y.jsxs)(`p`,{children:[(0,Y.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_printer_state`}),` - `,m(`settings.metricsPrinterState`)]}),(0,Y.jsxs)(`p`,{children:[(0,Y.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_print_progress`}),` - `,m(`settings.metricsPrintProgress`)]}),(0,Y.jsxs)(`p`,{children:[(0,Y.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_bed_temp_celsius`}),` - `,m(`settings.metricsBedTemp`)]}),(0,Y.jsxs)(`p`,{children:[(0,Y.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_nozzle_temp_celsius`}),` - `,m(`settings.metricsNozzleTemp`)]}),(0,Y.jsxs)(`p`,{children:[(0,Y.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_prints_total`}),` - `,m(`settings.metricsPrintsTotal`)]}),(0,Y.jsx)(`p`,{className:`text-bambu-gray/70 italic`,children:m(`settings.metricsMore`)})]})]})]})]})]})})]}),Gr&&(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full mx-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[Gr.success?(0,Y.jsx)(j,{className:`w-8 h-8 text-green-600 dark:text-green-400`}):(0,Y.jsx)(O,{className:`w-8 h-8 text-red-600 dark:text-red-400`}),(0,Y.jsx)(`h3`,{className:`text-lg font-medium text-white`,children:Gr.success?m(`settings.connectionSuccessful`):m(`settings.connectionFailed`)})]}),(0,Y.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:Gr.success?Gr.message||m(`settings.haConnectionSuccess`):Gr.error||m(`settings.haConnectionFailed`)}),(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsx)(K,{variant:`primary`,onClick:()=>Kr(null),children:m(`settings.ok`)})})]})}),En===`plugs`&&(0,Y.jsxs)(`div`,{id:`card-plugs`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between mb-6`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(dt,{className:`w-5 h-5 text-bambu-green`}),m(`settings.smartPlugs`)]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:m(`settings.smartPlugsDescription`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-1 shrink-0`,children:[li&&li.filter(e=>e.enabled).length>1&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,className:`whitespace-nowrap`,onClick:()=>ar(`on`),disabled:Ya.isPending,title:m(`settings.turnAllPlugsOn`),children:[Ya.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Ct,{className:`w-4 h-4 text-bambu-green`}),m(`settings.allOn`)]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,className:`whitespace-nowrap`,onClick:()=>ar(`off`),disabled:Ya.isPending,title:m(`settings.turnAllPlugsOff`),children:[Ya.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(St,{className:`w-4 h-4 text-red-600 dark:text-red-400`}),m(`settings.allOff`)]})]}),(0,Y.jsxs)(K,{className:`whitespace-nowrap`,onClick:()=>{We(null),Ve(!0)},children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),m(`settings.addSmartPlug`)]})]})]}),li&&li.length>0&&(0,Y.jsxs)(G,{className:`mb-6`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(Ot,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`}),m(`settings.energySummary`),_i&&(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin text-bambu-gray ml-2`})]})}),(0,Y.jsx)(W,{children:gi?(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,Y.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,Y.jsx)(Ot,{className:`w-3 h-3`}),m(`settings.currentPower`)]}),(0,Y.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[gi.totalPower.toFixed(1),(0,Y.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`W`})]}),(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.plugsOnline`,{reachable:gi.reachableCount,total:gi.totalPlugs})})]}),(0,Y.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,Y.jsx)(w,{className:`w-3 h-3`}),m(`settings.today`)]}),(0,Y.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[gi.totalToday.toFixed(3),(0,Y.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(H?.energy_cost_per_kwh??0)>0&&(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,(gi.totalToday*(H?.energy_cost_per_kwh??0)).toFixed(2),` `,Et(H?.currency||`USD`)]})]}),(0,Y.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,Y.jsx)(g,{className:`w-3 h-3`}),m(`settings.yesterday`)]}),(0,Y.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[gi.totalYesterday.toFixed(3),(0,Y.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(H?.energy_cost_per_kwh??0)>0&&(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,(gi.totalYesterday*(H?.energy_cost_per_kwh??0)).toFixed(2),` `,Et(H?.currency||`USD`)]})]}),(0,Y.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,Y.jsx)(ne,{className:`w-3 h-3`}),m(`settings.total`)]}),(0,Y.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[gi.totalLifetime.toFixed(1),(0,Y.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(H?.energy_cost_per_kwh??0)>0&&(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,(gi.totalLifetime*(H?.energy_cost_per_kwh??0)).toFixed(2),` `,Et(H?.currency||`USD`)]})]})]}):_i?null:(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.enablePlugsForSummary`)})})]}),mi?(0,Y.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,Y.jsx)(L,{className:`w-8 h-8 text-bambu-green animate-spin`})}):li&&li.length>0?(0,Y.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:li.map(e=>(0,Y.jsx)(dr,{plug:e,onEdit:e=>{We(e),Ve(!0)}},e.id))}):(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-12`,children:(0,Y.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,Y.jsx)(dt,{className:`w-16 h-16 mx-auto mb-4 opacity-30`}),(0,Y.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:m(`settings.noSmartPlugsTitle`)}),(0,Y.jsx)(`p`,{className:`text-sm mb-4`,children:m(`settings.noSmartPlugsDescription`)}),(0,Y.jsxs)(K,{onClick:()=>{We(null),Ve(!0)},children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),m(`settings.addFirstSmartPlug`)]})]})})})]}),En===`sensors`&&(0,Y.jsxs)(`div`,{id:`card-sensors`,children:[(0,Y.jsxs)(`div`,{id:`card-ha-sensors`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(ie,{className:`w-5 h-5 text-bambu-green`}),m(`haSensors.sectionTitle`)]}),(0,Y.jsxs)(K,{className:`whitespace-nowrap`,disabled:!wi?.length,onClick:()=>{Xe(null),q(!0)},children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),m(`haSensors.add`)]})]}),Ei&&Ei.length>0?(0,Y.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:Ei.map(e=>{let t=wi?.find(t=>t.id===e.printer_id);return(0,Y.jsx)(G,{children:(0,Y.jsxs)(W,{className:`py-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-white font-medium truncate`,children:e.name}),(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray truncate`,children:e.entity_id}),(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:t?.name??m(`haSensors.unknownPrinter`)})]}),(0,Y.jsx)(K,{size:`sm`,variant:`secondary`,onClick:()=>{Xe(e),q(!0)},children:m(`common.edit`)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[e.block_print&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 text-xs rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,children:m(`haSensors.badgeBlocks`)}),e.notify_on_alert&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 text-xs rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:m(`haSensors.badgeNotifies`)}),!e.show_on_printer_card&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:m(`haSensors.badgeHidden`)})]})]})},e.id)})}):(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-8`,children:(0,Y.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,Y.jsx)(ie,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:m(`haSensors.empty`)})]})})})]}),(0,Y.jsxs)(`div`,{id:`card-location-sensors`,className:`mt-8`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-[20px] mb-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(ie,{className:`w-5 h-5 text-bambu-green`}),m(`locationHaSensors.sectionTitle`)]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:m(`locationHaSensors.sectionDescription`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-1 shrink-0`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>ft(!0),className:`p-2 rounded-lg bg-bambu-dark-tertiary hover:bg-bambu-gray-dark text-white transition-colors`,title:m(`locationHaSensors.options.buttonLabel`),"aria-label":m(`locationHaSensors.options.buttonLabel`),children:(0,Y.jsx)(te,{className:`w-4 h-4`})}),(0,Y.jsxs)(K,{className:`whitespace-nowrap`,disabled:!Oi?.length,onClick:()=>{lt(null),ot(!0)},children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),m(`locationHaSensors.add`)]})]})]}),Di&&Di.length>0?(0,Y.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(()=>{let e=new Map((Oi??[]).map((e,t)=>[e.id,t])),t=Di.reduce((e,t)=>{let n=e.get(t.location_id)??[];return n.push(t),e.set(t.location_id,n),e},new Map);return Array.from(t.entries()).sort(([t],[n])=>(e.get(t)??2**53-1)-(e.get(n)??2**53-1))})().map(([e,t])=>{let n=Oi?.find(t=>t.id===e),r=e=>b({device_class:e.device_class,state:e.last_state,kind:e.kind}),i=[...t].sort((e,t)=>(Aa[e.device_class??``]??99)-(Aa[t.device_class??``]??99));return(0,Y.jsx)(G,{children:(0,Y.jsxs)(W,{className:`py-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Y.jsx)(`div`,{className:`text-white font-medium truncate`,children:n?.name??m(`locationHaSensors.unknownLocation`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>It({locationName:n?.name??m(`locationHaSensors.unknownLocation`),sensorIds:i.map(e=>e.id)}),className:`p-1 text-bambu-gray hover:text-red-500 rounded transition-colors shrink-0`,title:m(`common.delete`),"aria-label":m(`common.delete`),children:(0,Y.jsx)(qe,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsx)(`div`,{className:`mt-2 space-y-1.5`,children:i.map(e=>{let t=r(e),n=ji.get(e.id),i=ja(n,m),a=z(mt&&n?ve(n):null,xt,jt,Mt)||`text-white`;return(0,Y.jsxs)(`div`,{className:`flex items-center min-w-0 text-xs text-bambu-gray`,children:[(0,Y.jsx)(t,{className:`w-3.5 h-3.5 shrink-0 mr-1.5`}),i&&(0,Y.jsx)(`span`,{className:`${a} shrink-0 w-[52px] text-center`,children:i}),i&&(0,Y.jsx)(`span`,{className:`shrink-0 mr-1.5`,children:`-`}),(0,Y.jsx)(`span`,{className:`truncate mr-1.5`,title:e.name,children:e.entity_id}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{lt(e),ot(!0)},className:`p-1 text-bambu-gray hover:text-white rounded transition-colors shrink-0`,title:m(`common.edit`),"aria-label":m(`common.edit`),children:(0,Y.jsx)(Ke,{className:`w-3.5 h-3.5`})})]},e.id)})}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[(()=>{let e=i.filter(e=>e.notify_on_alert);return e.length?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 text-xs rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:[m(`haSensors.badgeNotifies`),e.map(e=>(0,Y.jsx)(r(e),{className:`w-3 h-3`},e.id))]}):null})(),(()=>{let e=i.filter(e=>!e.show_on_card);return e.length?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:[m(`haSensors.badgeHidden`),e.map(e=>(0,Y.jsx)(r(e),{className:`w-3 h-3`},e.id))]}):null})()]})]})},e)})}):(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-8`,children:(0,Y.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,Y.jsx)(ie,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:m(`locationHaSensors.empty`)})]})})})]})]}),En===`notifications`&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-providers`,children:[(0,Y.jsx)(rt,{className:`w-5 h-5 text-bambu-green`}),m(`settings.providers`)]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(K,{size:`sm`,variant:`secondary`,onClick:()=>dn(!0),children:[(0,Y.jsx)(P,{className:`w-4 h-4`}),m(`settings.log`)]}),vi&&vi.length>0&&(0,Y.jsxs)(K,{size:`sm`,variant:`secondary`,onClick:()=>{qa(null),Ja.mutate()},disabled:Ja.isPending,children:[Ja.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Sn,{className:`w-4 h-4`}),m(`settings.testAll`)]}),(0,Y.jsxs)(K,{size:`sm`,onClick:()=>{Wt(null),Bt(!0)},children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),m(`settings.addNotificationProvider`)]})]})]}),(0,Y.jsx)(G,{className:`mb-4`,children:(0,Y.jsx)(W,{className:`py-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white text-sm font-medium`,children:m(`settings.notificationLanguage`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.notificationLanguageDescription`)})]}),(0,Y.jsx)(`select`,{value:H.notification_language||`en`,onChange:e=>$(`notification_language`,e.target.value),className:`px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green`,children:tt.map(e=>(0,Y.jsx)(`option`,{value:e.code,children:e.nativeName},e.code))})]})})}),(0,Y.jsx)(G,{className:`mb-4`,children:(0,Y.jsx)(W,{className:`py-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white text-sm font-medium`,children:m(`settings.bedCooledThreshold`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.bedCooledThresholdDescription`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`input`,{type:`number`,min:20,max:80,step:1,value:H.bed_cooled_threshold??35,onChange:e=>$(`bed_cooled_threshold`,Number(e.target.value)),className:`w-16 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm text-center focus:outline-none focus:ring-1 focus:ring-bambu-green`}),(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`°C`})]})]})})}),(0,Y.jsx)(G,{className:`mb-4`,children:(0,Y.jsx)(W,{className:`py-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between ${ha?.advanced_auth_enabled?``:`opacity-50`}`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white text-sm font-medium`,children:m(`settings.userNotificationsEnabled`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:ha?.advanced_auth_enabled?m(`settings.userNotificationsEnabledDescription`):m(`settings.userNotificationsDisabledHint`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`sr-only peer`,checked:H.user_notifications_enabled??!0,disabled:!ha?.advanced_auth_enabled,onChange:e=>$(`user_notifications_enabled`,e.target.checked)}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green peer-disabled:cursor-not-allowed`})]})]})})}),Ka&&(0,Y.jsx)(G,{className:`mb-4`,children:(0,Y.jsxs)(W,{className:`py-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium text-white`,children:m(`settings.testResults`)}),(0,Y.jsx)(`button`,{onClick:()=>qa(null),className:`text-bambu-gray hover:text-white text-xs`,children:m(`common.dismiss`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-4 text-sm mb-2`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-green`,children:[(0,Y.jsx)(j,{className:`w-4 h-4`}),m(`settings.testPassedCount`,{count:Ka.success})]}),Ka.failed>0&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,Y.jsx)(O,{className:`w-4 h-4`}),m(`settings.testFailedCount`,{count:Ka.failed})]})]}),Ka.results.filter(e=>!e.success).length>0&&(0,Y.jsx)(`div`,{className:`space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary`,children:Ka.results.filter(e=>!e.success).map(e=>(0,Y.jsxs)(`div`,{className:`text-xs text-red-700 dark:text-red-400`,children:[(0,Y.jsxs)(`span`,{className:`font-medium`,children:[e.provider_name,`:`]}),` `,e.message]},e.provider_id))})]})}),yi?(0,Y.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,Y.jsx)(L,{className:`w-6 h-6 text-bambu-green animate-spin`})}):vi&&vi.length>0?(0,Y.jsx)(`div`,{className:`space-y-3`,children:vi.map(e=>(0,Y.jsx)(Tr,{provider:e,onEdit:e=>{Wt(e),Bt(!0)}},e.id))}):(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-8`,children:(0,Y.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,Y.jsx)(rt,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,Y.jsx)(`p`,{className:`text-sm font-medium text-white mb-2`,children:m(`settings.noProvidersTitle`)}),(0,Y.jsx)(`p`,{className:`text-xs mb-3`,children:m(`settings.noProvidersDescription`)}),(0,Y.jsxs)(K,{size:`sm`,onClick:()=>{Wt(null),Bt(!0)},children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),m(`settings.addProvider`)]})]})})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-2`,id:`card-templates`,children:[(0,Y.jsx)(ln,{className:`w-5 h-5 text-bambu-green`}),m(`settings.messageTemplates`)]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:m(`settings.messageTemplatesDescription`)}),(0,Y.jsxs)(`div`,{className:`relative mb-3`,children:[(0,Y.jsx)(Ae,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none`}),(0,Y.jsx)(`input`,{type:`text`,value:Qt,onChange:e=>en(e.target.value),placeholder:m(`settings.filterTemplates`,`Filter templates…`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),Qt&&(0,Y.jsx)(`button`,{onClick:()=>en(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-bambu-gray hover:text-white`,"aria-label":`Clear filter`,children:(0,Y.jsx)(Re,{className:`w-3.5 h-3.5`})})]}),Fi?(0,Y.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,Y.jsx)(L,{className:`w-6 h-6 text-bambu-green animate-spin`})}):Pi&&Pi.length>0?(()=>{let e=Qt.trim().toLowerCase(),t=[...Pi].sort((e,t)=>e.name.localeCompare(t.name)).filter(t=>!e||t.name.toLowerCase().includes(e)||(t.title_template||``).toLowerCase().includes(e));return t.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray italic text-center py-6`,children:m(`settings.noTemplatesMatch`,`No templates match your filter.`)}):(0,Y.jsx)(`div`,{className:`space-y-2`,children:t.map(e=>(0,Y.jsx)(G,{className:`cursor-pointer hover:border-bambu-green/50 transition-colors`,onClick:()=>Jt(e),children:(0,Y.jsx)(W,{className:`py-2.5 px-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium text-sm truncate`,children:e.name}),(0,Y.jsx)(`p`,{className:`text-bambu-gray text-xs truncate mt-0.5`,children:e.title_template})]}),(0,Y.jsx)(`button`,{className:`p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2`,onClick:t=>{t.stopPropagation(),Jt(e)},children:(0,Y.jsx)(se,{className:`w-4 h-4 text-bambu-gray`})})]})})},e.id))})})():(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-8`,children:(0,Y.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,Y.jsx)(ln,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:m(`settings.noTemplatesAvailable`)})]})})})]})]}),En===`camera`&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 space-y-6`,children:[(0,Y.jsxs)(G,{id:`card-camera`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)($e,{className:`w-5 h-5 text-bambu-green`}),m(`settings.camera`)]})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsxs)(`section`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:m(`settings.cameraLight`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.cameraLightHint`)})]}),(0,Y.jsx)(`div`,{role:`radiogroup`,"aria-label":m(`settings.cameraLight`),className:`inline-flex rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:Ma.map(e=>(0,Y.jsxs)(`label`,{className:`cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`radio`,name:`camera-light-mode`,value:e,checked:wo===e,onChange:()=>$(`camera_light_mode`,e),className:`sr-only peer`}),(0,Y.jsx)(`span`,{className:`block px-3 py-1.5 text-xs text-bambu-gray peer-checked:bg-bambu-green peer-checked:text-white peer-focus-visible:ring-2 peer-focus-visible:ring-inset peer-focus-visible:ring-white hover:text-white`,children:m(`settings.cameraLightMode_${e}`)})]},e))}),wo!==`off`&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`label`,{htmlFor:`camera-light-delay`,className:`text-xs text-bambu-gray`,children:m(`settings.cameraLightDelay`)}),(0,Y.jsx)(ct,{id:`camera-light-delay`,min:0,max:5,step:`0.5`,integer:!1,fallback:2,value:H.camera_light_delay??2,onChange:e=>$(`camera_light_delay`,e),className:`w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs text-center focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:m(`settings.cameraLightDelayUnit`)})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray opacity-75 mt-1`,children:m(`settings.cameraLightDelayHint`)})]}),wo===`selected`&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,"data-testid":`camera-light-printers`,children:[To.length===0&&(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray italic`,children:m(`settings.cameraLightNoneSelected`)}),To.map(e=>(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 pl-2 pr-1 py-0.5 rounded-full bg-bambu-dark-tertiary text-xs text-white`,children:[e.name,(0,Y.jsx)(`button`,{type:`button`,onClick:()=>_o(e.id,{lightAuto:!1}),"aria-label":m(`settings.cameraLightRemovePrinter`,{name:e.name}),className:`p-0.5 rounded-full text-bambu-gray hover:text-white`,children:(0,Y.jsx)(Re,{className:`w-3 h-3`})})]},e.id)),(0,Y.jsx)(wa,{printers:(wi??[]).filter(e=>!e.camera_light_auto),onPick:e=>_o(e.id,{lightAuto:!0}),label:m(`settings.cameraLightAddPrinter`)})]})]}),(0,Y.jsxs)(`section`,{className:`space-y-2 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:m(`settings.externalCameras`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.externalCamerasDescription`)})]}),Eo.length>0&&(0,Y.jsx)(`div`,{className:`rounded-lg border border-bambu-dark-tertiary`,"data-testid":`external-camera-list`,children:Eo.map(e=>{let t=fo===e.id,n=Na(e);return(0,Y.jsxs)(`div`,{className:`border-b border-bambu-dark-tertiary last:border-b-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>po(t?null:e.id),"aria-expanded":t,"aria-label":`${m(`settings.cameraShowSettings`)}: ${e.name}`,className:`flex flex-1 min-w-0 items-center gap-2 text-left`,children:[(0,Y.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`span`,{className:`block text-sm text-white truncate`,children:e.name}),(0,Y.jsx)(`span`,{className:`block text-[11px] text-bambu-gray truncate`,title:n,children:n})]}),(0,Y.jsx)(E,{className:`w-4 h-4 shrink-0 text-bambu-gray transition-transform ${t?`rotate-180`:``}`})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{_o(e.id,{enabled:!1}),t&&po(null)},"aria-label":m(`settings.externalCameraRemove`,{name:e.name}),title:m(`settings.externalCameraRemove`,{name:e.name}),className:`p-1 rounded text-bambu-gray hover:text-red-400`,children:(0,Y.jsx)(qe,{className:`w-3.5 h-3.5`})})]}),t&&(0,Y.jsxs)(`div`,{className:`space-y-2 px-2 pb-3 pt-1 bg-bambu-dark/40`,children:[(0,Y.jsx)(`input`,{type:`text`,"aria-label":`${m(`settings.cameraPlaceholderUrl`)}: ${e.name}`,placeholder:e.external_camera_type===`usb`?m(`settings.cameraPlaceholderUsb`):m(`settings.cameraPlaceholderUrl`),value:io[e.id]??e.external_camera_url??``,onChange:t=>ho(e.id,t.target.value),className:`w-full px-2 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(`select`,{value:e.external_camera_type||`mjpeg`,onChange:t=>_o(e.id,{type:t.target.value}),className:`flex-1 min-w-0 px-2 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`mjpeg`,children:m(`settings.cameraTypeMjpeg`)}),(0,Y.jsx)(`option`,{value:`rtsp`,children:m(`settings.cameraTypeRtsp`)}),(0,Y.jsx)(`option`,{value:`snapshot`,children:m(`settings.cameraTypeSnapshot`)}),(0,Y.jsx)(`option`,{value:`usb`,children:m(`settings.cameraTypeUsb`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-1 text-xs text-bambu-gray`,children:[m(`settings.cameraRotation`),(0,Y.jsxs)(`select`,{value:e.camera_rotation||0,onChange:t=>_o(e.id,{rotation:parseInt(t.target.value)}),className:`px-1.5 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:0,children:`0°`}),(0,Y.jsx)(`option`,{value:90,children:`90°`}),(0,Y.jsx)(`option`,{value:180,children:`180°`}),(0,Y.jsx)(`option`,{value:270,children:`270°`})]})]}),(0,Y.jsx)(K,{size:`sm`,variant:`secondary`,onClick:()=>ro(e.id,io[e.id]??e.external_camera_url??``,e.external_camera_type||`mjpeg`),disabled:Zr[e.id]||!(io[e.id]??e.external_camera_url),children:Zr[e.id]?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):m(`settings.test`)})]}),Yr[e.id]&&(0,Y.jsx)(`div`,{className:`text-xs flex items-center gap-1 ${Yr[e.id]?.success?`text-green-500`:`text-red-500`}`,children:Yr[e.id]?.success?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(j,{className:`w-3 h-3`}),m(`settings.connected`),Yr[e.id]?.resolution&&` (${Yr[e.id]?.resolution})`]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(O,{className:`w-3 h-3`}),Yr[e.id]?.error||m(`settings.toast.connectionFailed`)]})}),(e.external_camera_type===`mjpeg`||e.external_camera_type===`rtsp`||e.external_camera_type===`usb`)&&(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`label`,{className:`text-xs text-bambu-gray flex items-center gap-1`,children:[m(`settings.cameraSnapshotUrl`,`Snapshot URL (optional)`),(0,Y.jsx)(`span`,{title:m(`settings.cameraSnapshotUrlHelp`),className:`cursor-help`,"aria-label":m(`settings.cameraSnapshotUrlHelp`),children:(0,Y.jsx)(A,{className:`w-3 h-3`})})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`text`,placeholder:m(`settings.cameraSnapshotUrlPlaceholder`,`http://192.168.1.61:1984/api/frame.jpeg?src=printer`),value:co[e.id]??e.external_camera_snapshot_url??``,onChange:t=>go(e.id,t.target.value),className:`flex-1 min-w-0 px-2 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(K,{size:`sm`,variant:`secondary`,onClick:()=>ro(e.id,co[e.id]??e.external_camera_snapshot_url??``,`snapshot`),disabled:Zr[e.id]||!(co[e.id]??e.external_camera_snapshot_url),children:Zr[e.id]?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):m(`settings.test`)})]})]})]})]},e.id)})}),wi&&wi.length>0?(0,Y.jsx)(wa,{printers:wi.filter(e=>!e.external_camera_enabled),onPick:e=>{_o(e.id,{enabled:!0}),po(e.id)},label:m(`settings.externalCameraAdd`)}):(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray italic`,children:m(`settings.noPrintersConfigured`)})]})]})]}),(0,Y.jsxs)(G,{children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-camera-tokens`,children:[(0,Y.jsx)($e,{className:`w-4 h-4 text-bambu-green`}),m(`cameraTokens.title`,`Camera API Tokens`)]})}),(0,Y.jsx)(W,{children:(0,Y.jsx)(Kn,{},e)})]})]}),(0,Y.jsx)(`div`,{className:`min-w-0`,children:(0,Y.jsxs)(G,{children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-stream-overlay`,children:[(0,Y.jsx)(Te,{className:`w-4 h-4 text-bambu-green`}),m(`streamOverlay.builder.title`,`Streaming Overlay`)]})}),(0,Y.jsx)(W,{children:(0,Y.jsx)(lr,{onTokenCreated:()=>t(e=>e+1)})})]})})]}),En===`apikeys`&&(0,Y.jsxs)(`div`,{className:k(`api_keys:read`)?`grid grid-cols-1 lg:grid-cols-2 gap-4`:`grid grid-cols-1 gap-4`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[k(`api_keys:read`)&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-4 mb-6`,children:[(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-createapi`,children:[(0,Y.jsx)(Kt,{className:`w-5 h-5 text-bambu-green`}),m(`settings.apiKeys`)]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:m(`settings.apiKeysDescription`)})]}),(0,Y.jsxs)(K,{size:`sm`,onClick:()=>zn(!0),className:`flex-shrink-0`,children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),m(`settings.createKey`)]})]}),Wn&&(0,Y.jsx)(G,{className:`mb-6 border-bambu-green`,children:(0,Y.jsx)(W,{className:`py-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(j,{className:`w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium mb-1`,children:m(`settings.apiKeyCreated`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:m(`settings.apiKeyCopyWarning`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 bg-bambu-dark rounded-lg p-2`,children:[(0,Y.jsx)(`code`,{className:`flex-1 text-sm text-bambu-green font-mono break-all`,children:Wn}),(0,Y.jsx)(K,{variant:`secondary`,size:`sm`,onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(Wn);else{let e=document.createElement(`textarea`);e.value=Wn,e.style.position=`fixed`,e.style.left=`-999999px`,document.body.appendChild(e),e.select(),document.execCommand(`copy`),document.body.removeChild(e)}v(m(`settings.toast.keyCopied`))}catch{v(m(`settings.toast.copyFailed`),`error`)}},children:(0,Y.jsx)(M,{className:`w-4 h-4`})})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2 mt-3`,children:[(0,Y.jsx)(K,{variant:`secondary`,size:`sm`,onClick:()=>{Qn(Wn),v(m(`settings.toast.keyAddedToBrowser`))},children:m(`settings.useInApiBrowser`)}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:()=>Jn(!0),children:[(0,Y.jsx)(Oe,{className:`w-4 h-4`}),m(`settings.apiKeyQrButton`)]}),(0,Y.jsx)(K,{variant:`secondary`,size:`sm`,onClick:()=>{Jn(!1),Gn(null)},children:m(`common.dismiss`)})]})]})]})})}),qn&&Wn&&(0,Y.jsx)(ai,{apiKey:Wn,baseUrl:H?.external_url||void 0,onClose:()=>Jn(!1)}),Rn&&(0,Y.jsxs)(G,{className:`mb-6`,children:[(0,Y.jsx)(U,{children:(0,Y.jsx)(`h3`,{className:`text-base font-semibold text-white`,children:m(`settings.createNewApiKey`)})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.keyName`)}),(0,Y.jsx)(`input`,{type:`text`,value:Bn,onChange:e=>Vn(e.target.value),placeholder:m(`settings.keyNamePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:m(`common.permissions`)}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Hn.can_read_status,onChange:e=>Un(t=>({...t,can_read_status:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white`,children:m(`settings.readStatus`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.readStatusDescription`)})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Hn.can_queue,onChange:e=>Un(t=>({...t,can_queue:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white`,children:m(`settings.manageQueue`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.manageQueueDescription`)})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Hn.can_control_printer,onChange:e=>Un(t=>({...t,can_control_printer:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white`,children:m(`settings.controlPrinter`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.controlPrinterDescription`)})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Hn.can_manage_library,onChange:e=>Un(t=>({...t,can_manage_library:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white`,children:m(`settings.manageLibrary`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.manageLibraryDescription`)})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Hn.can_manage_inventory,onChange:e=>Un(t=>({...t,can_manage_inventory:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white`,children:m(`settings.manageInventory`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.manageInventoryDescription`)})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Hn.can_manage_maintenance,onChange:e=>Un(t=>({...t,can_manage_maintenance:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white`,children:m(`settings.manageMaintenance`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.manageMaintenanceDescription`)})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Hn.can_manage_archives,onChange:e=>Un(t=>({...t,can_manage_archives:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white`,children:m(`settings.manageArchives`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.manageArchivesDescription`)})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Hn.can_manage_projects,onChange:e=>Un(t=>({...t,can_manage_projects:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white`,children:m(`settings.manageProjects`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.manageProjectsDescription`)})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Hn.can_access_cloud,onChange:e=>Un(t=>({...t,can_access_cloud:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white`,children:m(`settings.cloudAccess`,`Allow cloud access`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.cloudAccessDescription`,`Read Bambu Cloud presets and filaments on your behalf. Requires you to be signed into Bambu Cloud.`)})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Hn.can_update_energy_cost,onChange:e=>Un(t=>({...t,can_update_energy_cost:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white`,children:m(`settings.updateEnergyCost`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.updateEnergyCostDescription`)})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Hn.can_send_notifications,onChange:e=>Un(t=>({...t,can_send_notifications:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white`,children:m(`settings.sendNotifications`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.sendNotificationsDescription`)})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-2`,children:[(0,Y.jsxs)(K,{onClick:()=>Si.mutate({name:Bn||m(`settings.unnamedKey`),...Hn}),disabled:Si.isPending,children:[Si.isPending?(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(wt,{className:`w-4 h-4`}),m(`settings.createKey`)]}),(0,Y.jsx)(K,{variant:`secondary`,onClick:()=>zn(!1),children:m(`common.cancel`)})]})]})]}),xi?(0,Y.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,Y.jsx)(L,{className:`w-8 h-8 text-bambu-green animate-spin`})}):bi&&bi.length>0?(0,Y.jsx)(`div`,{className:`space-y-3`,children:bi.map(e=>(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(Kt,{className:`w-5 h-5 ${e.enabled?`text-bambu-green`:`text-bambu-gray`}`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white font-medium`,children:e.name}),(0,Y.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[e.key_prefix,`••••••••`,e.last_used&&` · ${m(`settings.lastUsed`)}: ${He(e.last_used)}`]})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex gap-1 text-xs flex-wrap justify-end`,children:[e.can_read_status&&(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 rounded`,children:m(`settings.read`)}),e.can_queue&&(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400 rounded`,children:m(`queue.title`)}),e.can_control_printer&&(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400 rounded`,children:m(`settings.control`)}),e.can_manage_library&&(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-400 rounded`,children:m(`settings.libraryBadge`)}),e.can_manage_inventory&&(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 bg-pink-100 dark:bg-pink-500/20 text-pink-700 dark:text-pink-400 rounded`,children:m(`settings.inventoryBadge`)}),e.can_manage_maintenance&&(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 rounded`,children:m(`settings.maintenanceBadge`)}),e.can_manage_archives&&(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-400 rounded`,children:m(`settings.archivesBadge`)}),e.can_manage_projects&&(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 bg-lime-100 dark:bg-lime-500/20 text-lime-700 dark:text-lime-400 rounded`,children:m(`settings.projectsBadge`)}),e.can_access_cloud&&(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400 rounded`,children:m(`settings.cloudBadge`,`Cloud`)}),e.can_update_energy_cost&&(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 rounded`,children:m(`settings.energyCostBadge`)}),e.can_send_notifications&&(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 bg-sky-100 dark:bg-sky-500/20 text-sky-700 dark:text-sky-400 rounded`,children:m(`settings.sendNotificationsBadge`)}),e.user_id===null&&(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 rounded`,title:m(`settings.legacyKeyTooltip`,`Created before per-user ownership; recreate to use cloud access`),children:m(`settings.legacyKey`,`Legacy`)})]}),(0,Y.jsx)(K,{variant:`secondary`,size:`sm`,onClick:()=>Xn(e.id),children:(0,Y.jsx)(qe,{className:`w-4 h-4 text-red-600 dark:text-red-400`})})]})]})})},e.id))}):(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-12`,children:(0,Y.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,Y.jsx)(Kt,{className:`w-16 h-16 mx-auto mb-4 opacity-30`}),(0,Y.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:m(`settings.apiKeysEmptyTitle`)}),(0,Y.jsx)(`p`,{className:`text-sm mb-4`,children:m(`settings.apiKeysEmptyDescription`)}),(0,Y.jsxs)(K,{onClick:()=>zn(!0),children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),m(`settings.createFirstKey`)]})]})})}),(0,Y.jsxs)(G,{className:`mt-6`,children:[(0,Y.jsx)(U,{children:(0,Y.jsx)(`h3`,{className:`text-base font-semibold text-white`,id:`card-webhooks`,children:m(`settings.webhookEndpoints`)})}),(0,Y.jsxs)(W,{className:`space-y-3 text-sm`,children:[(0,Y.jsx)(`p`,{className:`text-bambu-gray`,children:m(`settings.webhookApiKeyHint`)}),(0,Y.jsxs)(`div`,{className:`space-y-2 font-mono text-xs`,children:[(0,Y.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,Y.jsx)(`span`,{className:`text-blue-700 dark:text-blue-400`,children:`GET`}),` `,(0,Y.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/status`}),(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,m(`settings.webhook.getAllStatus`)]})]}),(0,Y.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,Y.jsx)(`span`,{className:`text-blue-700 dark:text-blue-400`,children:`GET`}),` `,(0,Y.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/status/:id`}),(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,m(`settings.webhook.getSpecificStatus`)]})]}),(0,Y.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,Y.jsx)(`span`,{className:`text-green-700 dark:text-green-400`,children:`POST`}),` `,(0,Y.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/queue`}),(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,m(`settings.webhook.addToQueue`)]})]}),(0,Y.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,Y.jsx)(`span`,{className:`text-orange-700 dark:text-orange-400`,children:`POST`}),` `,(0,Y.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/pause`}),(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,m(`settings.webhook.pausePrint`)]})]}),(0,Y.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,Y.jsx)(`span`,{className:`text-orange-700 dark:text-orange-400`,children:`POST`}),` `,(0,Y.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/resume`}),(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,m(`settings.webhook.resumePrint`)]})]}),(0,Y.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,Y.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`POST`}),` `,(0,Y.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/stop`}),(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,m(`settings.webhook.stopPrint`)]})]})]})]})]})]}),k(`settings:update`)&&(0,Y.jsxs)(G,{className:`mt-6`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-connected-apps`,children:[(0,Y.jsx)(I,{className:`w-4 h-4 text-bambu-green`}),m(`connectedApps.title`)]})}),(0,Y.jsx)(W,{children:(0,Y.jsx)($n,{})})]})]}),k(`api_keys:read`)&&(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`mb-6`,children:[(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-apibrowser`,children:[(0,Y.jsx)(zt,{className:`w-5 h-5 text-bambu-green`}),m(`settings.apiBrowser`)]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:m(`settings.apiBrowserDescription`)})]}),(0,Y.jsx)(G,{className:`mb-4`,children:(0,Y.jsxs)(W,{className:`py-3`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:m(`settings.apiKeyForTesting`)}),(0,Y.jsx)(`input`,{type:`text`,value:Zn,onChange:e=>Qn(e.target.value),placeholder:m(`settings.apiKeyPlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:m(`settings.apiKeyHint`)})]})}),(0,Y.jsx)(ya,{apiKey:Zn})]})]}),En===`virtual-printer`&&(0,Y.jsx)(`div`,{id:`card-vp`,children:(0,Y.jsx)(Ti,{})}),En===`spoolbuddy`&&(0,Y.jsx)(`div`,{id:`card-spoolbuddy`,children:(0,Y.jsx)(ki,{})}),En===`queue`&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex gap-1 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`button`,{onClick:()=>Ln(`dispatch`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Pn===`dispatch`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,Y.jsx)(Zt,{className:`w-4 h-4`}),m(`settings.tabs.queueDispatch`,`Queue & Dispatch`)]}),(0,Y.jsxs)(`button`,{onClick:()=>Ln(`pipelines`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Pn===`pipelines`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,Y.jsx)(Le,{className:`w-4 h-4`}),m(`settings.tabs.queuePipelines`,`Pipelines`)]})]}),Pn===`pipelines`&&(0,Y.jsx)(Nn,{}),Pn===`dispatch`&&H&&(0,Y.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,Y.jsxs)(`div`,{className:`lg:w-1/2 space-y-3`,children:[(0,Y.jsxs)(G,{id:`card-print-options`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(Zt,{className:`w-4 h-4 text-bambu-green`}),m(`settings.defaultPrintOptions`,`Default Print Options`)]})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.defaultPrintOptionsDescription`,`Set default values for print options when starting new prints. These can be overridden per print in the print dialog.`)}),[{key:`default_bed_levelling`,label:m(`settings.defaultBedLevelling`,`Bed Levelling`),desc:m(`settings.defaultBedLevellingDesc`,`Auto-level bed before print`),fallback:!0,dualNozzleOnly:!1,tristate:!0},{key:`default_flow_cali`,label:m(`settings.defaultFlowCali`,`Flow Calibration`),desc:m(`settings.defaultFlowCaliDesc`,`Calibrate extrusion flow`),fallback:!1,dualNozzleOnly:!1,tristate:!0},{key:`default_vibration_cali`,label:m(`settings.defaultVibrationCali`,`Vibration Calibration`),desc:m(`settings.defaultVibrationCaliDesc`,`Reduce ringing artifacts`),fallback:!0,dualNozzleOnly:!1,tristate:!1},{key:`default_layer_inspect`,label:m(`settings.defaultLayerInspect`,`First Layer Inspection`),desc:m(`settings.defaultLayerInspectDesc`,`AI inspection of first layer`),fallback:!1,dualNozzleOnly:!1,tristate:!1},{key:`default_timelapse`,label:m(`settings.defaultTimelapse`,`Timelapse`),desc:m(`settings.defaultTimelapseDesc`,`Record timelapse video`),fallback:!1,dualNozzleOnly:!1,tristate:!1},{key:`default_nozzle_offset_cali`,label:m(`settings.defaultNozzleOffsetCali`,`Nozzle Offset Calibration`),desc:m(`settings.defaultNozzleOffsetCaliDesc`,`Calibrate nozzle offsets between extruders`),fallback:!0,dualNozzleOnly:!0,tristate:!0},{key:`default_confirm_outcome`,label:m(`settings.defaultConfirmOutcome`,`Ask for Outcome`),desc:m(`settings.defaultConfirmOutcomeDesc`,`Ask whether the print came out well after it completes`),fallback:!1,dualNozzleOnly:!1,tristate:!1}].filter(({dualNozzleOnly:e})=>!e||(wi||[]).some(e=>e.nozzle_count===2)).map(({key:e,label:t,desc:n,fallback:r,tristate:i})=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:t}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:n})]}),i?(0,Y.jsx)(`div`,{className:`flex gap-1 shrink-0`,children:cn.map(t=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>$(e,t),className:`px-2.5 py-1 text-xs rounded transition-colors ${(H[e]??`auto`)===t?pt[t]:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:m(`settings.calibrationMode_${t}`)},t))}):(0,Y.jsx)(`div`,{className:`flex gap-1 shrink-0`,children:[`off`,`on`].map(t=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>$(e,t===`on`),className:`px-2.5 py-1 text-xs rounded transition-colors ${(H[e]??r?`on`:`off`)===t?pt[t]:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:m(`settings.calibrationMode_${t}`)},t))})]},e)),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:m(`settings.confirmOutcomeExternalPrints`,`Also ask for prints started outside Bambuddy`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:m(`settings.confirmOutcomeExternalPrintsDesc`,`Prints started at the printer, in Bambu Studio or in the Handy app are archived by Bambuddy too. With this on, they get the same outcome prompt as queued prints.`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer shrink-0`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.confirm_outcome_external_prints??!1,onChange:e=>$(`confirm_outcome_external_prints`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]})]}),(0,Y.jsxs)(G,{id:`card-plate`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(Me,{className:`w-4 h-4 text-bambu-green`}),m(`settings.plateClear`,`Plate-Clear Confirmation`)]})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:m(`settings.requirePlateClear`,`Require plate-clear confirmation`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.requirePlateClearDescription`,`When enabled, the scheduler waits for per-printer plate-clear confirmation before starting queued prints on printers with finished jobs. Disabling this also hides the plate status badge and the "Mark plate as cleared" button on printer cards.`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.require_plate_clear??!1,onChange:e=>$(`require_plate_clear`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:m(`settings.confirmDefaultGoodOnPlateClear`,`Count unanswered outcomes as good on plate release`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.confirmDefaultGoodOnPlateClearDescription`,`When the plate is released (manually or by the next queued print) and the print's outcome prompt is still unanswered, record it as a good part automatically. The print then counts as good as soon as the plate is released; a Telegram or link answer after that only shows the recorded result.`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.confirm_default_good_on_plate_clear??!1,onChange:e=>$(`confirm_default_good_on_plate_clear`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]})]}),(0,Y.jsxs)(G,{id:`card-temp-fan-presets`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(Fe,{className:`w-4 h-4 text-bambu-green`}),m(`settings.tempFanPresetsTitle`,`Temperature & Fan Presets`)]})}),(0,Y.jsxs)(W,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.tempFanPresetsDescription`,`Customize the quick-select values shown in printer-card temperature and fan-speed popovers. The Off button is always shown.`)}),Ce.map(e=>{let t=xe(H?.[e.key]??``,e.defaults,e.lo,e.hi),n=e.unit===`C`?`°C`:`%`;return(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,Y.jsxs)(`label`,{className:`text-sm text-white`,children:[m(`settings.${{nozzle_temp_presets:`tempFanPresetsNozzle`,bed_temp_presets:`tempFanPresetsBed`,chamber_temp_presets:`tempFanPresetsChamber`,fan_speed_presets:`tempFanPresetsFan`}[e.key]}`,{nozzle_temp_presets:`Nozzle temperature`,bed_temp_presets:`Bed temperature`,chamber_temp_presets:`Chamber temperature`,fan_speed_presets:`Fan speed`}[e.key]),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray text-xs`,children:[`(`,n,` · `,e.lo,`–`,e.hi,`)`]})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>$(e.key,``),title:m(`settings.tempFanPresetsReset`,`Reset to defaults`),className:`text-bambu-gray hover:text-white transition-colors p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,Y.jsx)(nt,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsx)(`div`,{className:`flex gap-2`,children:[0,1,2].map(n=>(0,Y.jsx)(`input`,{type:`number`,min:e.lo,max:e.hi,value:t[n],onChange:r=>{let i=[t[0],t[1],t[2]],a=parseInt(r.target.value,10);i[n]=Math.max(e.lo,Math.min(e.hi,Number.isFinite(a)?a:e.lo)),$(e.key,JSON.stringify(i))},className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`},n))})]},e.key)})]})]}),(0,Y.jsxs)(G,{id:`card-staggered`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(At,{className:`w-4 h-4 text-bambu-green`}),m(`settings.staggeredStart`,`Staggered Start`)]})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.staggeredStartDescription`,`Default group size and interval when staggering multi-printer batch starts. Can be overridden per batch in the print modal.`)}),(0,Y.jsxs)(`div`,{className:`flex gap-4`,children:[(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:m(`settings.staggerGroupSize`,`Group size`)}),(0,Y.jsx)(ct,{min:1,max:50,value:H.stagger_group_size??2,onChange:e=>$(`stagger_group_size`,e),fallback:1,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.staggerGroupSizeHelp`,`Printers to start simultaneously per group`)})]}),(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:m(`settings.staggerInterval`,`Interval (minutes)`)}),(0,Y.jsx)(ct,{min:1,max:60,value:H.stagger_interval_minutes??5,onChange:e=>$(`stagger_interval_minutes`,e),fallback:1,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.staggerIntervalHelp`,`Delay between each group starting`)})]})]})]})]}),(0,Y.jsxs)(G,{id:`card-concurrent-uploads`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(yn,{className:`w-4 h-4 text-bambu-green`}),m(`settings.concurrentUploadsTitle`,`Concurrent Uploads`)]})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.concurrentUploadsDescription`,`How many printers the queue may send files to at the same time. Printers receive files slowly (a large print can take several minutes), and each one waits its turn — so on a bigger fleet, raising this is what stops the last printer in a batch from waiting out every transfer before it. Lower it if your network or Bambuddy host struggles with parallel transfers.`)}),(0,Y.jsxs)(`div`,{className:`w-full sm:w-1/2`,children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:m(`settings.concurrentUploadsLabel`,`Printers uploaded to at once`)}),(0,Y.jsx)(ct,{min:1,max:16,value:H.queue_max_concurrent_uploads??4,onChange:e=>$(`queue_max_concurrent_uploads`,e),fallback:1,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.concurrentUploadsHelp`,`1 sends to one printer at a time (the old behaviour). Default is 4.`)})]})]})]}),(0,Y.jsxs)(G,{id:`card-preheat`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(Dt,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),m(`settings.preheatTitle`,`Preheat & Heat Soak`)]})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.preheatDescription`,`Heat the bed (and chamber, if supported) and hold at temperature before each queued print starts. Helpful for engineering filaments (PA, ABS) on printers without an active chamber heater — the bed warms the chamber by radiation while the soak timer runs. The bed target is read from the print file; chamber behaviour depends on printer model.`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:m(`settings.preheatEnabled`,`Enable preheat & soak`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:m(`settings.preheatEnabledDesc`,`When off, queued prints dispatch immediately.`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.preheat_enabled??!1,onChange:e=>$(`preheat_enabled`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 pt-1`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:m(`settings.preheatMaxWait`,`Max wait (seconds)`)}),(0,Y.jsx)(ct,{min:60,max:3600,value:H.preheat_max_wait_seconds??900,onChange:e=>$(`preheat_max_wait_seconds`,e),fallback:900,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green disabled:opacity-50`,disabled:!(H.preheat_enabled??!1)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.preheatMaxWaitHelp`,`Cap on the chamber warm-up phase before falling through.`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:m(`settings.preheatSoak`,`Soak (seconds)`)}),(0,Y.jsx)(ct,{min:0,max:1800,value:H.preheat_soak_seconds??300,onChange:e=>$(`preheat_soak_seconds`,e),fallback:0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green disabled:opacity-50`,disabled:!(H.preheat_enabled??!1)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.preheatSoakHelp`,`Hold time after target reached or max-wait elapsed.`)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pt-2 border-t border-bambu-dark-tertiary/50`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:m(`settings.keepBedWarm`,`Keep bed warm between prints`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:m(`settings.keepBedWarmDesc`,`While awaiting plate-clear, hold the bed at the keep-warm temperature below so the chamber stays hot — or at the next print's own bed temperature when that is higher. Only applies when the next print needs chamber heating (ASA, ABS, PA, PC etc.). Requires plate-clear confirmation to be enabled.`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.queue_keep_bed_warm??!1,onChange:e=>$(`queue_keep_bed_warm`,e.target.checked),className:`sr-only peer`,disabled:!(H.preheat_enabled??!1)||!(H.require_plate_clear??!1)}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green peer-disabled:opacity-50 peer-disabled:cursor-not-allowed`})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mt-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:m(`settings.keepWarmBedTemp`,`Keep-warm bed temperature (°C)`)}),(0,Y.jsx)(ct,{min:40,max:110,value:H.queue_keep_warm_bed_temp??90,onChange:e=>$(`queue_keep_warm_bed_temp`,e),fallback:90,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green disabled:opacity-50`,disabled:!(H.preheat_enabled??!1)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.keepWarmBedTempHelp`,`Used whenever the bed's job is to heat the chamber — the keep-warm hold, and preheat when the print file carries no bed temperature. A higher bed temperature from the print file always wins.`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:m(`settings.keepWarmMaxMinutes`,`Stop keeping warm after (minutes)`)}),(0,Y.jsx)(ct,{min:5,max:480,value:H.queue_keep_warm_max_minutes??120,onChange:e=>$(`queue_keep_warm_max_minutes`,e),fallback:120,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green disabled:opacity-50`,disabled:!(H.queue_keep_bed_warm??!1)||!(H.preheat_enabled??!1)||!(H.require_plate_clear??!1)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.keepWarmMaxMinutesHelp`,`If the plate is not cleared within this time, the heaters are switched off rather than held indefinitely.`)})]})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary/50`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,Y.jsx)(`label`,{className:`text-sm text-white`,children:m(`settings.preheatFilamentTargetsLabel`,`Per-filament chamber target (°C)`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>$(`preheat_filament_targets`,``),title:m(`settings.preheatFilamentTargetsReset`,`Reset to defaults`),className:`text-bambu-gray hover:text-white transition-colors p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,Y.jsx)(nt,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:m(`settings.preheatFilamentTargetsHint`,`Bambuddy picks the highest target across the loaded AMS slots; PLA-only prints derive 0 and skip the chamber phase automatically.`)}),(0,Y.jsx)(An,{value:H.preheat_filament_targets??``,onChange:e=>$(`preheat_filament_targets`,e),disabled:!(H.preheat_enabled??!1)})]}),(0,Y.jsxs)(`p`,{className:`text-xs text-bambu-gray pt-1 border-t border-bambu-dark-tertiary/50`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-bambu-gray/90`,children:m(`settings.preheatHardwareTitle`,`Per-printer behaviour:`)}),` `,m(`settings.preheatHardwareDetail`,`H2C/H2D/H2D Pro/H2S/X2D/X1E actively heat the chamber via M141. X1C/P2S read chamber temp but rely on bed-radiation heating. P1S/P1P/A1/A1 Mini have no chamber sensor — only the soak timer applies.`)]})]})]})]}),(0,Y.jsxs)(`div`,{className:`lg:w-1/2 space-y-3`,children:[(0,Y.jsxs)(G,{id:`card-pipelines`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(Le,{className:`w-4 h-4 text-bambu-green`}),m(`settings.pipelineLimits.title`,`Slicer Pipeline limits`)]})}),(0,Y.jsx)(W,{className:`space-y-2`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:m(`settings.pipelineLimits.maxCopiesLabel`,`Max copies per run`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:m(`settings.pipelineLimits.maxCopiesDesc`,`Upper bound on the copies operators can request when running a pipeline. Server-side hard cap is 1000.`)})]}),(0,Y.jsx)(`input`,{type:`number`,min:1,max:1e3,value:H.pipeline_max_copies??50,onChange:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||$(`pipeline_max_copies`,Math.max(1,Math.min(1e3,t)))},"aria-label":m(`settings.pipelineLimits.maxCopiesLabel`,`Max copies per run`),className:`w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`})]})})]}),(0,Y.jsxs)(G,{id:`card-slicer`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(te,{className:`w-4 h-4 text-bambu-green`}),m(`settings.slicerCard`,`Slicer`)]})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[Sa()&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.sliceEngine`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`select`,{value:Ca(H.slice_engine),onChange:e=>$(`slice_engine`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:xa().map(e=>(0,Y.jsx)(`option`,{value:e.id,children:m(e.labelKey)},e.id))}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(xa().find(e=>e.id===Ca(H.slice_engine))?.descriptionKey??`settings.sliceEngineSidecarHint`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.preferredSlicer`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsxs)(`select`,{value:H.preferred_slicer??`bambu_studio`,onChange:e=>$(`preferred_slicer`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,Y.jsx)(`option`,{value:`bambu_studio`,children:m(`settings.slicerBambuStudio`)}),(0,Y.jsx)(`option`,{value:`orcaslicer`,children:m(`settings.slicerOrcaSlicer`)})]}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.preferredSlicerDescription`)}),(H.preferred_slicer??`bambu_studio`)===`orcaslicer`&&(0,Y.jsx)(`div`,{role:`alert`,className:`text-xs text-amber-800 dark:text-amber-200 bg-amber-50 dark:bg-amber-900/20 border border-amber-300 dark:border-amber-700/40 rounded p-2 mt-2`,children:m(`settings.orcaslicerKnownIssuesWarning`,`OrcaSlicer 2.3.2 / 2.4.0-dev have known CLI bugs that block slicing many Bambu-authored 3MFs — see upstream issues #12426 (segfault on painted multi-extruder files) and #13386 (parameter-range strict-validation reject). Bambu Studio is recommended until the upstream fixes land.`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.openInSlicerLabel`,`Open in Slicer`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsxs)(`select`,{value:H.open_in_slicer??``,onChange:e=>$(`open_in_slicer`,e.target.value===``?null:e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,Y.jsx)(`option`,{value:``,children:m(`settings.openInSlicerInherit`,`Same as API slicer`)}),(0,Y.jsx)(`option`,{value:`bambu_studio`,children:m(`settings.slicerBambuStudio`)}),(0,Y.jsx)(`option`,{value:`orcaslicer`,children:m(`settings.slicerOrcaSlicer`)})]}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.openInSlicerDescription`,`Desktop slicer used by the 'Open in Slicer' button. Leave on 'Same as API slicer' to inherit, or pick a different slicer to use locally.`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.useSlicerApi`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.useSlicerApiDescription`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center cursor-pointer shrink-0`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.use_slicer_api??!1,onChange:e=>$(`use_slicer_api`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`relative w-11 h-6 bg-bambu-dark-tertiary rounded-full peer peer-checked:bg-bambu-green peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-bambu-green/50 transition-colors after:content-[''] after:absolute after:top-0.5 after:left-0.5 after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-transform peer-checked:after:translate-x-5`})]})]}),(H.use_slicer_api??!1)&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:(H.preferred_slicer??`bambu_studio`)===`orcaslicer`?m(`settings.orcaslicerApiUrl`,`OrcaSlicer sidecar URL`):m(`settings.bambuStudioApiUrl`,`Bambu Studio sidecar URL`)}),(0,Y.jsx)(`input`,{type:`text`,value:((H.preferred_slicer??`bambu_studio`)===`orcaslicer`?H.orcaslicer_api_url:H.bambu_studio_api_url)??``,onChange:e=>$((H.preferred_slicer??`bambu_studio`)===`orcaslicer`?`orcaslicer_api_url`:`bambu_studio_api_url`,e.target.value),placeholder:(H.preferred_slicer??`bambu_studio`)===`orcaslicer`?`http://localhost:3003`:`http://localhost:3001`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none placeholder:text-bambu-gray/40`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.slicerApiUrlDescription`,`URL of the slicer-API sidecar container. Leave blank to use the SLICER_API_URL / BAMBU_STUDIO_API_URL env var defaults.`)})]}),(H.use_slicer_api??!1)&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.slicerStallTimeout`)}),(0,Y.jsx)(`input`,{type:`number`,min:1,max:240,value:H.slicer_stall_timeout_minutes??15,onChange:e=>$(`slicer_stall_timeout_minutes`,Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`settings.slicerStallTimeoutDescription`)})]})]})]}),(0,Y.jsxs)(G,{children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-drying`,children:[(0,Y.jsx)(Dt,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),m(`settings.queueDrying`)]})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.queueDryingDescription`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-white`,children:m(`settings.queueDryingEnabled`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:m(`settings.queueDryingEnabledDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.queue_drying_enabled??!1,onChange:e=>$(`queue_drying_enabled`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),H.queue_drying_enabled&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-white`,children:m(`settings.queueDryingBlock`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:m(`settings.queueDryingBlockDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.queue_drying_block??!1,onChange:e=>$(`queue_drying_block`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-amber-500`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-white`,children:m(`settings.ambientDryingEnabled`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:m(`settings.ambientDryingEnabledDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.ambient_drying_enabled??!1,onChange:e=>{Pe(null),$(`ambient_drying_enabled`,e.target.checked)},className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),H.ambient_drying_enabled&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-white`,children:m(`settings.ambientDryingSustainedEnabled`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:m(`settings.ambientDryingSustainedDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:(H.ambient_drying_sustained_minutes??0)>0,onChange:e=>{Pe(null),$(`ambient_drying_sustained_minutes`,e.target.checked?15:0)},className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),H.ambient_drying_enabled&&(H.ambient_drying_sustained_minutes??0)>0&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.ambientDryingSustainedMinutes`)}),(0,Y.jsx)(`input`,{type:`number`,min:`5`,max:`240`,value:Ne??String(H.ambient_drying_sustained_minutes??15),onChange:e=>Pe(e.target.value),onBlur:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||$(`ambient_drying_sustained_minutes`,Math.max(5,Math.min(240,t))),Pe(null)},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-white`,children:m(`settings.printDryingEnabled`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:m(`settings.printDryingEnabledDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.print_drying_enabled??!1,onChange:e=>$(`print_drying_enabled`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white font-medium`,children:m(`settings.dryingPresets`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.dryingPresetsDescription`)}),(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`th`,{className:`text-left py-1.5`,children:m(`settings.dryingFilament`)}),(0,Y.jsx)(`th`,{className:`text-center py-1.5`,colSpan:2,children:`AMS 2 Pro`}),(0,Y.jsx)(`th`,{className:`text-center py-1.5`,colSpan:2,children:`AMS-HT`})]})}),(0,Y.jsx)(`tbody`,{children:(()=>{let e={PLA:{n3f:45,n3s:45,n3f_hours:12,n3s_hours:12},PETG:{n3f:65,n3s:65,n3f_hours:12,n3s_hours:12},TPU:{n3f:65,n3s:75,n3f_hours:12,n3s_hours:18},ABS:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},ASA:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:12},PC:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PVA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:18}},t={...e};try{if(H.drying_presets){let n=JSON.parse(H.drying_presets);typeof n==`object`&&n&&(t={...e,...n})}}catch{}let n=(e,n,r)=>{let i={...t,[e]:{...t[e],[n]:r}};$(`drying_presets`,JSON.stringify(i))};return Object.entries(t).map(([e,t])=>(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50`,children:[(0,Y.jsx)(`td`,{className:`py-1.5 pr-2 text-white font-medium`,children:e}),(0,Y.jsx)(`td`,{className:`py-1 px-1`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,Y.jsx)(ct,{min:30,max:65,value:t.n3f,onChange:t=>n(e,`n3f`,t),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})}),(0,Y.jsx)(`td`,{className:`py-1 px-1`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(ct,{min:1,max:24,value:t.n3f_hours,onChange:t=>n(e,`n3f_hours`,t),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:`h`})]})}),(0,Y.jsx)(`td`,{className:`py-1 px-1`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,Y.jsx)(ct,{min:30,max:85,value:t.n3s,onChange:t=>n(e,`n3s`,t),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})}),(0,Y.jsx)(`td`,{className:`py-1 px-1`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(ct,{min:1,max:24,value:t.n3s_hours,onChange:t=>n(e,`n3s_hours`,t),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:`h`})]})})]},e))})()})]})})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white font-medium`,children:m(`settings.humidityThresholds`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.humidityThresholdsDescription`)}),(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`th`,{className:`text-left py-1.5`,children:m(`settings.dryingFilament`)}),(0,Y.jsx)(`th`,{className:`text-right py-1.5 pr-2`,children:m(`settings.humidityThresholdCol`)})]})}),(0,Y.jsx)(`tbody`,{children:(()=>{let e=H.ams_humidity_fair??60,t=[`PLA`,`PETG`,`TPU`,`ABS`,`ASA`,`PA`,`PC`,`PVA`],n={};try{if(H.ams_humidity_thresholds){let e=JSON.parse(H.ams_humidity_thresholds);typeof e==`object`&&e&&(n=e)}}catch{}let r=[{key:`default`,label:m(`settings.humidityThresholdDefault`),value:Number(n.default??e),isDefault:!0},...t.map(t=>({key:t,label:t,value:Number(n[t]??n.default??e),isDefault:!1}))],i=(e,t)=>{if(t.trim()===``){let t={...n};delete t[e],$(`ams_humidity_thresholds`,JSON.stringify(t));return}let r=parseInt(t,10);if(Number.isNaN(r))return;let i=Math.max(5,Math.min(95,r)),a={...n,[e]:i};$(`ams_humidity_thresholds`,JSON.stringify(a))};return r.map(e=>{let t=De[e.key],n=t===void 0?String(e.value):t;return(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50`,children:[(0,Y.jsx)(`td`,{className:`py-1.5 pr-2 font-medium ${e.isDefault?`text-bambu-gray italic`:`text-white`}`,children:e.label}),(0,Y.jsx)(`td`,{className:`py-1 pr-2`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,Y.jsx)(`input`,{type:`number`,min:5,max:95,value:n,onChange:t=>je(n=>({...n,[e.key]:t.target.value})),onBlur:t=>{i(e.key,t.target.value),je(t=>{let n={...t};return delete n[e.key],n})},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()},className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:`%`})]})})]},e.key)})})()})]})})]})]})]}),(0,Y.jsxs)(G,{id:`card-gcode`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(Qe,{className:`w-4 h-4 text-bambu-green`}),m(`settings.gcodeInjection`,`G-code Injection`)]})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.gcodeInjectionDescription`,`Configure custom G-code to inject at the start and/or end of prints for auto-print systems like Farmloop, SwapMod, AutoClear, and Printflow 3D. Snippets are configured per printer model and applied when "Inject G-code" is enabled on a queue item.`)}),(()=>{let e=(()=>{try{return H.gcode_snippets?JSON.parse(H.gcode_snippets):{}}catch{return{}}})(),t=[...new Set((wi||[]).filter(e=>e.model).map(e=>e.model))].sort(),n=(t,n,r)=>{let i={...e};i[t]||(i[t]={start_gcode:``,end_gcode:``}),i[t][n]=r,!i[t].start_gcode&&!i[t].end_gcode&&delete i[t];let a=Object.keys(i).length>0?JSON.stringify(i):``;Ee(e=>e?{...e,gcode_snippets:a}:null),Za.current=a},r=()=>{Za.current!==null&&(to.mutate({gcode_snippets:Za.current}),Za.current=null)};return t.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:m(`settings.gcodeInjectionNoPrinters`,`No printers found. Add printers to configure G-code snippets.`)}):t.map(t=>{let i=e[t]||{start_gcode:``,end_gcode:``},a=!!(i.start_gcode||i.end_gcode);return(0,Y.jsx)(Rt,{defaultOpen:a,className:`border border-bambu-dark-tertiary rounded-lg px-3 py-2`,summary:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:t}),a&&(0,Y.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:m(`settings.gcodeConfigured`,`Configured`)})]}),children:(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:m(`settings.gcodeStartLabel`,`Start G-code`)}),(0,Y.jsx)(`textarea`,{value:i.start_gcode,onChange:e=>n(t,`start_gcode`,e.target.value),onBlur:r,placeholder:m(`settings.gcodeStartPlaceholder`,`G-code prepended before the print starts...`),rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:outline-none focus:border-bambu-green resize-y`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:m(`settings.gcodeEndLabel`,`End G-code`)}),(0,Y.jsx)(`textarea`,{value:i.end_gcode,onChange:e=>n(t,`end_gcode`,e.target.value),onBlur:r,placeholder:m(`settings.gcodeEndPlaceholder`,`G-code appended after the print ends...`),rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:outline-none focus:border-bambu-green resize-y`})]})]})},t)})})()]})]})]})]})]}),En===`filament`&&H&&(0,Y.jsx)(Y.Fragment,{children:(0,Y.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,Y.jsxs)(`div`,{className:`lg:w-1/3 space-y-3`,children:[(0,Y.jsx)(di,{}),(0,Y.jsxs)(G,{id:`card-filamentchecks`,children:[(0,Y.jsx)(U,{children:(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:m(`settings.filamentChecks`)})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.disableFilamentWarnings`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.disableFilamentWarningsDesc`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.disable_filament_warnings,onChange:e=>$(`disable_filament_warnings`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.preferLowestFilament`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.preferLowestFilamentDesc`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:m(`settings.preferLowestFilamentBackupNote`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.prefer_lowest_filament,onChange:e=>$(`prefer_lowest_filament`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]})]}),(0,Y.jsxs)(G,{id:`card-printmodal`,children:[(0,Y.jsx)(U,{children:(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:m(`settings.printModal`)})}),(0,Y.jsx)(W,{className:`space-y-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.expandCustomMapping`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.expandCustomMappingDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.per_printer_mapping_expanded??!1,onChange:e=>$(`per_printer_mapping_expanded`,e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})})]}),(0,Y.jsxs)(G,{id:`card-amsthresholds`,children:[(0,Y.jsx)(U,{children:(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:m(`settings.amsDisplayThresholds`)})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.amsThresholdsDescription`)}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-white`,children:[(0,Y.jsx)(y,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,Y.jsx)(`span`,{className:`font-medium`,children:m(`settings.humidity`)})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[m(`settings.goodGreen`),` ≤`]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ct,{min:0,max:100,value:H.ams_humidity_good??40,onChange:e=>$(`ams_humidity_good`,e),fallback:40,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:`%`})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[m(`settings.fairOrange`),` ≤`]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ct,{min:0,max:100,value:H.ams_humidity_fair??60,onChange:e=>$(`ams_humidity_fair`,e),fallback:60,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:`%`})]})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.aboveFairBad`)}),(0,Y.jsx)(`p`,{className:`text-xs text-amber-700/80 dark:text-amber-400/70`,children:m(`settings.fairAlsoDryingThreshold`)}),(H.ams_humidity_fair??60)<Ea&&(0,Y.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:m(`settings.fairBelowDryingFloor`,{floor:Ea})})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-white`,children:[(0,Y.jsx)(Fe,{className:`w-4 h-4 text-orange-600 dark:text-orange-400`}),(0,Y.jsx)(`span`,{className:`font-medium`,children:m(`settings.temperature`)})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[m(`settings.goodBlue`),` ≤`]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ct,{step:`0.5`,min:0,max:60,value:H.ams_temp_good??28,onChange:e=>$(`ams_temp_good`,e),integer:!1,fallback:28,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[m(`settings.fairOrange`),` ≤`]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ct,{step:`0.5`,min:0,max:60,value:H.ams_temp_fair??35,onChange:e=>$(`ams_temp_fair`,e),integer:!1,fallback:35,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.aboveFairHot`)}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.tempAlarmThreshold`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`input`,{type:`number`,step:`0.5`,min:`0.5`,max:`120`,value:H.ams_temp_alarm??``,placeholder:String(H.ams_temp_fair??35),onChange:e=>{let t=e.target.value.trim(),n=parseFloat(t);$(`ams_temp_alarm`,t===``||Number.isNaN(n)?null:n)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})]}),(H.ams_temp_alarm??1)<=0&&(0,Y.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:m(`settings.tempAlarmMustBePositive`)}),(0,Y.jsx)(`p`,{className:`text-xs text-amber-700/80 dark:text-amber-400/70`,children:m(`settings.tempAlarmSeparateFromBand`)})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-white`,children:[(0,Y.jsx)(gt,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,Y.jsx)(`span`,{className:`font-medium`,children:m(`settings.historyRetention`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`settings.keepSensorHistory`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ct,{min:1,max:365,value:H.ams_history_retention_days??30,onChange:e=>$(`ams_history_retention_days`,e),fallback:30,className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:m(`common.days`)})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m(`settings.historyRetentionDescription`)})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`lg:w-2/3 space-y-3`,children:[(0,Y.jsx)(fi,{}),(0,Y.jsx)(pi,{})]})]})}),Yn!==null&&(0,Y.jsx)(Tt,{title:m(`settings.deleteApiKeyTitle`),message:m(`settings.deleteApiKeyMessage`),confirmText:m(`settings.deleteKey`),variant:`danger`,onConfirm:()=>{Ci.mutate(Yn),Xn(null)},onCancel:()=>Xn(null)}),Be&&(0,Y.jsx)(fr,{plug:Ue,onClose:()=>{Ve(!1),We(null)}}),Ge&&(0,Y.jsx)(pr,{sensor:Ye,printers:wi??[],onClose:()=>{q(!1),Xe(null)}}),et&&(0,Y.jsx)(_r,{sensor:st,locations:Oi??[],onClose:()=>{ot(!1),lt(null)}}),ut&&(0,Y.jsx)(wr,{onClose:()=>ft(!1)}),Pt&&(0,Y.jsx)(Tt,{title:m(`locationHaSensors.deleteAllConfirm.title`),message:m(`locationHaSensors.deleteAllConfirm.message`,{location:Pt.locationName,count:Pt.sensorIds.length}),variant:`danger`,isLoading:Mi.isPending,onConfirm:()=>Mi.mutate(Pt.sensorIds),onCancel:()=>It(null)}),Lt&&(0,Y.jsx)(Dr,{provider:Ut,onClose:()=>{Bt(!1),Wt(null)}}),qt&&(0,Y.jsx)(Or,{template:qt,onClose:()=>Jt(null)}),J&&(0,Y.jsx)(Ar,{onClose:()=>dn(!1)}),er&&(0,Y.jsx)(Tt,{title:m(`settings.clearNotificationLogs`),message:m(`settings.clearLogsMessage`),confirmText:m(`settings.clearLogs`),variant:`warning`,onConfirm:async()=>{tr(!1);try{v((await r.clearNotificationLogs(30)).message,`success`)}catch{v(m(`settings.toast.clearLogsFailed`),`error`)}},onCancel:()=>tr(!1)}),nr&&(0,Y.jsx)(Tt,{title:m(`settings.resetUiPreferences`),message:m(`settings.resetUiPreferencesMessage`),confirmText:m(`settings.resetPreferences`),variant:`default`,onConfirm:()=>{rr(!1),localStorage.clear(),v(m(`settings.toast.uiPreferencesReset`),`success`),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>rr(!1)}),ir&&(0,Y.jsx)(Tt,{title:`Turn All Plugs ${ir===`on`?`On`:`Off`}`,message:`This will turn ${ir===`on`?`ON`:`OFF`} all ${li?.filter(e=>e.enabled).length||0} enabled smart plugs. ${ir===`off`?`Any running printers may be affected!`:``}`,confirmText:`Turn All ${ir===`on`?`On`:`Off`}`,variant:ir===`off`?`danger`:`warning`,onConfirm:()=>{let e=ir;ar(null),Ya.mutate(e)},onCancel:()=>ar(null)}),or&&ia?.release_notes&&(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:()=>sr(!1),children:(0,Y.jsxs)(G,{className:`w-full max-w-2xl max-h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(U,{className:`flex flex-row items-center justify-between shrink-0`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[`Release Notes - v`,ia.latest_version]}),ia.release_name&&ia.release_name!==ia.latest_version&&(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:ia.release_name})]}),(0,Y.jsx)(`button`,{onClick:()=>sr(!1),className:`p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsx)(W,{className:`overflow-y-auto flex-1`,children:(0,Y.jsx)(`pre`,{className:`text-sm text-bambu-gray whitespace-pre-wrap font-sans`,children:ia.release_notes})}),(0,Y.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary shrink-0 flex gap-2`,children:[ia.release_url&&(0,Y.jsx)(`a`,{href:ia.release_url,target:`_blank`,rel:`noopener noreferrer`,className:`flex-1`,children:(0,Y.jsxs)(K,{variant:`secondary`,className:`w-full`,children:[(0,Y.jsx)(Je,{className:`w-4 h-4`}),`View on GitHub`]})}),(0,Y.jsx)(K,{onClick:()=>sr(!1),className:`flex-1`,children:`Close`})]})]})}),En===`users`&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex gap-1 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`button`,{onClick:()=>jn(`users`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${Mn===`users`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,Y.jsx)(Ze,{className:`w-4 h-4`}),m(`settings.tabs.users`)]}),x&&T&&(0,Y.jsxs)(`button`,{onClick:()=>jn(`printer-access`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Mn===`printer-access`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,Y.jsx)(it,{className:`w-4 h-4`}),m(`printerAccess.tab`)]}),(0,Y.jsxs)(`button`,{onClick:()=>jn(`email`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${Mn===`email`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,Y.jsx)(Vt,{className:`w-4 h-4`}),m(`settings.tabs.emailAuth`)||`Email Authentication`,ha?.advanced_auth_enabled&&(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,Y.jsxs)(`button`,{onClick:()=>jn(`ldap`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${Mn===`ldap`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,Y.jsx)(Me,{className:`w-4 h-4`}),m(`settings.tabs.ldap`)||`LDAP`,ga?.ldap_enabled&&(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,Y.jsxs)(`button`,{onClick:()=>jn(`twofa`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Mn===`twofa`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,Y.jsx)(Me,{className:`w-4 h-4`}),m(`settings.tabs.twoFa`),(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full ${_a?.totp_enabled||_a?.email_otp_enabled?`bg-green-400`:`bg-bambu-gray/40`}`})]}),T&&(0,Y.jsxs)(`button`,{onClick:()=>jn(`oidc`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Mn===`oidc`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,Y.jsx)(zt,{className:`w-4 h-4`}),m(`settings.tabs.oidc`),(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full ${va.some(e=>e.is_enabled)?`bg-green-400`:`bg-bambu-gray/40`}`})]}),T&&(0,Y.jsxs)(`button`,{onClick:()=>jn(`security`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Mn===`security`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,Y.jsx)(Me,{className:`w-4 h-4`}),m(`settings.tabs.security`)]})]}),Mn===`users`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${x?`bg-green-500/20`:`bg-gray-500/20`}`,children:x?(0,Y.jsx)(R,{className:`w-5 h-5 text-green-600 dark:text-green-400`}):(0,Y.jsx)(h,{className:`w-5 h-5 text-gray-400`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-white font-medium`,children:m(`settings.authentication`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(x?`settings.authEnabledDescription`:`settings.authDisabledDescription`)})]})]}),x?S?.is_admin&&(0,Y.jsxs)(K,{variant:`secondary`,onClick:()=>ur(!0),children:[(0,Y.jsx)(h,{className:`w-4 h-4`}),m(`common.disable`)]}):(0,Y.jsxs)(K,{onClick:()=>a(`/setup`),children:[(0,Y.jsx)(R,{className:`w-4 h-4`}),m(`common.enable`)]})]})})}),ha?.advanced_auth_enabled&&(0,Y.jsx)(G,{className:`border-blue-500/30 bg-blue-500/5`,children:(0,Y.jsx)(W,{className:`py-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center bg-blue-500/20 flex-shrink-0`,children:(0,Y.jsx)(Vt,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-white font-medium`,children:m(`settings.email.advancedAuthEnabled`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:m(`settings.email.advancedAuthEnabledDesc`)})]})]})})}),x&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-6`,children:[(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(G,{id:`card-session-policy`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(R,{className:`w-5 h-5 text-bambu-green`}),m(`settings.sessionPolicy.title`)]})}),(0,Y.jsxs)(W,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:m(`settings.sessionPolicy.description`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2 mb-4`,children:[[{hours:24,labelKey:`settings.sessionPolicy.preset24h`},{hours:168,labelKey:`settings.sessionPolicy.preset7d`},{hours:720,labelKey:`settings.sessionPolicy.preset30d`}].map(e=>{let t=(H?.session_max_hours??24)===e.hours;return(0,Y.jsx)(`button`,{type:`button`,onClick:()=>$(`session_max_hours`,e.hours),disabled:x&&!k(`settings:update`),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors ${t?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark`} disabled:opacity-50 disabled:cursor-not-allowed`,children:m(e.labelKey)},e.hours)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`input`,{type:`number`,min:1,max:720,value:H?.session_max_hours??24,onChange:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||$(`session_max_hours`,Math.max(1,Math.min(720,t)))},disabled:x&&!k(`settings:update`),"aria-label":m(`settings.sessionPolicy.customHoursLabel`),className:`w-20 px-2 py-2 bg-bambu-dark-tertiary text-white text-sm rounded-lg border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:m(`settings.sessionPolicy.hoursSuffix`)})]})]}),(H?.session_max_hours??24)>24&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:[(0,Y.jsx)(Ie,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 flex-shrink-0 mt-0.5`}),(0,Y.jsx)(`p`,{className:`text-xs text-yellow-800 dark:text-yellow-200`,children:m(`settings.sessionPolicy.warning`)})]})]})]}),S&&(0,Y.jsxs)(G,{children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-currentuser`,children:[(0,Y.jsx)(Ze,{className:`w-5 h-5 text-bambu-green`}),m(`settings.currentUser`)]}),S.auth_source!==`ldap`&&(0,Y.jsxs)(K,{size:`sm`,variant:`ghost`,onClick:()=>hr(!0),children:[(0,Y.jsx)(Kt,{className:`w-4 h-4`}),m(`settings.changePassword`)]})]})}),(0,Y.jsx)(W,{children:(0,Y.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white font-medium text-lg`,children:S.username}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-2`,children:[S.is_admin&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`,children:m(`settings.admin`)}),S.groups?.map(e=>(0,Y.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium ${e.name===`Administrators`?`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`:e.name===`Operators`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300`:e.name===`Viewers`?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-300`:`bg-gray-500/20 text-gray-300`}`,children:e.name},e.id))]})]})})})]}),(0,Y.jsxs)(G,{children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-users`,children:[(0,Y.jsx)(Ze,{className:`w-5 h-5 text-bambu-green`}),m(`settings.users`)]}),k(`users:create`)&&(0,Y.jsxs)(K,{size:`sm`,onClick:()=>{Er(!0),Hr({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),m(`settings.addUser`)]})]})}),(0,Y.jsx)(W,{children:Da?(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,Y.jsx)(L,{className:`w-6 h-6 text-bambu-green animate-spin`})}):ba.length===0?(0,Y.jsx)(`p`,{className:`text-center text-bambu-gray py-8`,children:m(`settings.noUsersFound`)}):(0,Y.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:ba.map(e=>(0,Y.jsxs)(`div`,{className:`py-3 flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.username}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:[e.auth_source===`ldap`&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-300`,children:`LDAP`}),e.is_admin&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`,children:m(`settings.admin`)}),e.groups?.map(e=>(0,Y.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium ${e.name===`Administrators`?`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`:e.name===`Operators`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300`:e.name===`Viewers`?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-300`:`bg-gray-500/20 text-gray-300`}`,children:e.name},e.id))]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 ml-4`,children:[k(`users:update`)&&(0,Y.jsx)(K,{size:`sm`,variant:`ghost`,onClick:()=>Ua(e),children:(0,Y.jsx)(se,{className:`w-4 h-4`})}),k(`users:delete`)&&e.id!==S?.id&&(0,Y.jsx)(K,{size:`sm`,variant:`ghost`,onClick:()=>za(e.id),children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]})]},e.id))})})]})]}),(0,Y.jsx)(`div`,{children:(0,Y.jsxs)(G,{children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-groups`,children:[(0,Y.jsx)(Me,{className:`w-5 h-5 text-bambu-green`}),m(`settings.groups`)]}),k(`groups:create`)&&(0,Y.jsxs)(K,{size:`sm`,onClick:()=>a(`/groups/new`),children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),m(`settings.addGroup`)]})]})}),(0,Y.jsx)(W,{children:Pa?(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,Y.jsx)(L,{className:`w-6 h-6 text-bambu-green animate-spin`})}):Oa.length===0?(0,Y.jsx)(`p`,{className:`text-center text-bambu-gray py-8`,children:m(`settings.noGroupsFound`)}):(0,Y.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:Oa.map(e=>(0,Y.jsxs)(`div`,{className:`py-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Me,{className:`w-4 h-4 ${e.name===`Administrators`?`text-purple-600 dark:text-purple-400`:e.name===`Operators`?`text-blue-600 dark:text-blue-400`:e.name===`Viewers`?`text-green-600 dark:text-green-400`:`text-bambu-gray`}`}),(0,Y.jsx)(`span`,{className:`text-white font-medium`,children:e.name}),e.is_system&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:m(`settings.system`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[k(`groups:update`)&&(0,Y.jsx)(K,{size:`sm`,variant:`ghost`,onClick:()=>a(`/groups/${e.id}/edit`),children:(0,Y.jsx)(se,{className:`w-4 h-4`})}),k(`groups:delete`)&&!e.is_system&&(0,Y.jsx)(K,{size:`sm`,variant:`ghost`,onClick:()=>Wr(e.id),children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]})]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1 ml-6`,children:e.description||m(`settings.noDescription`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-4 mt-2 ml-6 text-xs text-bambu-gray`,children:[(0,Y.jsx)(`span`,{children:m(`settings.userCount`,{count:e.user_count})}),(0,Y.jsx)(`span`,{children:m(`settings.permissionCount`,{count:e.permissions.length})})]})]},e.id))})})]})})]}),!x&&(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-6`,children:(0,Y.jsxs)(`div`,{className:`text-center`,children:[(0,Y.jsx)(h,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Y.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:m(`settings.authDisabledTitle`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 max-w-md mx-auto`,children:m(`settings.authDisabledMessage`)}),(0,Y.jsxs)(`ul`,{className:`space-y-2 text-sm text-bambu-gray mb-6 text-left max-w-xs mx-auto`,children:[(0,Y.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(j,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,Y.jsx)(`span`,{children:m(`settings.authDisabledFeature1`)})]}),(0,Y.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(j,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,Y.jsx)(`span`,{children:m(`settings.authDisabledFeature2`)})]}),(0,Y.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(j,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,Y.jsx)(`span`,{children:m(`settings.authDisabledFeature3`)})]})]}),(0,Y.jsxs)(K,{onClick:()=>a(`/setup`),children:[(0,Y.jsx)(R,{className:`w-4 h-4`}),m(`settings.enableAuthentication`)]})]})})})]}),Mn===`printer-access`&&(0,Y.jsx)(ra,{}),Mn===`email`&&(0,Y.jsx)(`div`,{className:`max-w-5xl`,id:`card-smtp`,children:(0,Y.jsx)(Ki,{})}),Mn===`ldap`&&(0,Y.jsx)(`div`,{className:`max-w-5xl`,id:`card-ldap`,children:(0,Y.jsx)(Ji,{})}),Mn===`twofa`&&(0,Y.jsx)(`div`,{className:`max-w-2xl`,children:(0,Y.jsx)(sa,{})}),Mn===`oidc`&&T&&(0,Y.jsxs)(`div`,{className:`max-w-3xl space-y-4`,children:[(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`space-y-3 p-4`,children:(0,Y.jsxs)(`label`,{className:`flex items-start gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:H.local_login_enabled===!1,onChange:e=>$(`local_login_enabled`,!e.target.checked),className:`mt-1 h-4 w-4 rounded border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green/50 cursor-pointer`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-white`,children:m(`settings.localLogin.disable`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:m(`settings.localLogin.disableHint`)})]})]})})}),(0,Y.jsx)(da,{})]}),Mn===`security`&&T&&(0,Y.jsx)(`div`,{className:`max-w-3xl`,children:(0,Y.jsx)(ma,{})})]}),Cr&&!ha?.advanced_auth_enabled&&(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black flex items-center justify-center z-50 p-4`,onClick:()=>{Er(!1),Hr({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,Y.jsxs)(G,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Ze,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:m(`settings.createUser`)})]}),(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>{Er(!1),Hr({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]})}),(0,Y.jsxs)(W,{children:[ga?.ldap_enabled&&(0,Y.jsxs)(`div`,{className:`mb-4 flex items-center gap-1 p-1 bg-bambu-dark-secondary rounded-lg`,role:`tablist`,"aria-label":m(`users.modal.tabsAriaLabel`),children:[(0,Y.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":kr===`local`,onClick:()=>jr(`local`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${kr===`local`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:m(`users.modal.localTab`)}),(0,Y.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":kr===`ldap`,onClick:()=>jr(`ldap`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${kr===`ldap`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:m(`users.modal.ldapTab`)})]}),kr===`ldap`&&ga?.ldap_enabled?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(ci,{onSuccess:e=>{Er(!1),jr(`local`),Hr({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),v(m(`users.toast.ldapProvisioned`,{username:e.username}))}}),(0,Y.jsx)(`div`,{className:`mt-6 flex justify-end`,children:(0,Y.jsx)(K,{variant:`secondary`,onClick:()=>{Er(!1),jr(`local`),Hr({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:m(`common.cancel`)})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:m(`settings.username`)}),(0,Y.jsx)(`input`,{type:`text`,value:Z.username,onChange:e=>Hr({...Z,username:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:m(`settings.enterUsername`),autoComplete:`username`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:m(`settings.password`)}),(0,Y.jsx)(`input`,{type:`password`,value:Z.password,onChange:e=>Hr({...Z,password:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:m(`settings.enterPassword`),autoComplete:`new-password`,minLength:8}),(0,Y.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:m(`settings.passwordRequirements`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:m(`settings.confirmPassword`)}),(0,Y.jsx)(`input`,{type:`password`,value:Z.confirmPassword,onChange:e=>Hr({...Z,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${Z.confirmPassword&&Z.password!==Z.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:m(`settings.confirmPasswordPlaceholder`),autoComplete:`new-password`,minLength:6}),Z.confirmPassword&&Z.password!==Z.confirmPassword&&(0,Y.jsx)(`p`,{className:`text-red-700 dark:text-red-400 text-xs mt-1`,children:m(`settings.passwordsDoNotMatch`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:m(`settings.groups`)}),(0,Y.jsxs)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[Oa.map(e=>(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Z.group_ids.includes(e.id),onChange:()=>Wa(e.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:e.name}),e.is_system&&(0,Y.jsx)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400`,children:m(`settings.systemBadge`)})]},e.id)),Oa.length===0&&(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`settings.noGroupsAvailable`)})]})]})]}),(0,Y.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:()=>{Er(!1),Hr({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:m(`common.cancel`)}),(0,Y.jsx)(K,{onClick:Va,disabled:Fa.isPending||!Z.username||!Z.password||Z.password!==Z.confirmPassword||Tn(Z.password)!==null,children:Fa.isPending?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}),m(`settings.creating`)]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),m(`settings.createUser`)]})})]})]})]})]})}),Cr&&ha?.advanced_auth_enabled&&(0,Y.jsx)(ui,{formData:Z,setFormData:Hr,groups:Oa,onClose:()=>{Er(!1),Hr({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},onCreate:Va,isCreating:Fa.isPending,isCreateButtonDisabled:Fa.isPending||!Z.username||!Z.email,ldapEnabled:ga?.ldap_enabled,onLdapProvisioned:e=>{Er(!1),Hr({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),v(m(`users.toast.ldapProvisioned`,{username:e.username}))}}),Mr&&Pr!==null&&(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black flex items-center justify-center z-50 p-4`,onClick:()=>{Nr(!1),Fr(null),Hr({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,Y.jsxs)(G,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(se,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:m(`settings.editUser`)})]}),(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>{Nr(!1),Fr(null),Hr({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]})}),(0,Y.jsxs)(W,{children:[(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[m(`settings.username`),` `,ha?.advanced_auth_enabled&&(0,Y.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,Y.jsx)(`input`,{type:`text`,value:Z.username,onChange:e=>Hr({...Z,username:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:m(`settings.enterUsername`),autoComplete:`username`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[m(`users.form.email`)||`Email`,` `,ha?.advanced_auth_enabled?(0,Y.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`}):(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,m(`users.form.optional`)||`optional`,`)`]})]}),(0,Y.jsx)(`input`,{type:`email`,value:Z.email,onChange:e=>Hr({...Z,email:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:m(`users.form.emailPlaceholder`)||`user@example.com`,required:ha?.advanced_auth_enabled})]}),!ha?.advanced_auth_enabled&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[m(`users.form.password`)||`Password`,` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,m(`users.form.leaveBlankToKeep`)||`leave blank to keep current`,`)`]})]}),(0,Y.jsx)(`input`,{type:`password`,value:Z.password,onChange:e=>Hr({...Z,password:e.target.value,confirmPassword:``}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:m(`settings.enterNewPassword`),autoComplete:`new-password`,minLength:8}),(0,Y.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:m(`settings.passwordRequirements`)})]}),Z.password&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:m(`settings.confirmPassword`)}),(0,Y.jsx)(`input`,{type:`password`,value:Z.confirmPassword,onChange:e=>Hr({...Z,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${Z.confirmPassword&&Z.password!==Z.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:m(`settings.confirmNewPassword`),autoComplete:`new-password`,minLength:6}),Z.confirmPassword&&Z.password!==Z.confirmPassword&&(0,Y.jsx)(`p`,{className:`text-red-700 dark:text-red-400 text-xs mt-1`,children:m(`settings.passwordsDoNotMatch`)})]})]}),ha?.advanced_auth_enabled&&(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`users.form.passwordManagedByAdvancedAuth`)||`Password is managed by Advanced Authentication. Use "Reset Password" to send a new password to the user via email.`}),(0,Y.jsx)(K,{variant:`secondary`,size:`sm`,onClick:()=>Pr&&Ra.mutate(Pr),disabled:Ra.isPending||!Z.email,className:`w-full`,children:Ra.isPending?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}),m(`users.form.resettingPassword`)||`Resetting Password...`]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(nt,{className:`w-4 h-4`}),m(`users.form.resetPassword`)||`Reset Password`]})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:m(`users.form.groups`)||`Groups`}),(0,Y.jsx)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:Oa.map(e=>(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Z.group_ids.includes(e.id),onChange:()=>Wa(e.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:e.name}),e.is_system&&(0,Y.jsxs)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400`,children:[`(`,m(`users.system`)||`System`,`)`]})]},e.id))})]})]}),(0,Y.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:()=>{Nr(!1),Fr(null),Hr({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:m(`users.modal.cancel`)||`Cancel`}),(0,Y.jsx)(K,{onClick:()=>Ha(Pr),disabled:Ia.isPending||!Z.username||ha?.advanced_auth_enabled&&!Z.email||!!(!ha?.advanced_auth_enabled&&Z.password&&(Z.password!==Z.confirmPassword||Tn(Z.password)!==null)),children:Ia.isPending?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}),m(`users.modal.saving`)||`Saving...`]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(_t,{className:`w-4 h-4`}),m(`users.modal.saveChanges`)||`Save Changes`]})})]})]})]})}),Ir!==null&&(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,onClick:()=>{Lr(null),zr(null)},children:(0,Y.jsxs)(G,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400`,children:[(0,Y.jsx)(qe,{className:`w-5 h-5`}),(0,Y.jsx)(`h3`,{className:`text-lg font-semibold`,children:m(`settings.deleteUserTitle`)})]})}),(0,Y.jsx)(W,{className:`space-y-3`,children:Br?(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,Y.jsx)(`div`,{className:`animate-spin rounded-full h-6 w-6 border-2 border-bambu-green border-t-transparent`})}):Rr&&Rr.archives+Rr.queue_items+Rr.library_files>0?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.userHasCreated`)}),(0,Y.jsxs)(`ul`,{className:`list-disc list-inside text-bambu-gray space-y-1`,children:[Rr.archives>0&&(0,Y.jsxs)(`li`,{children:[Rr.archives,` archive`,Rr.archives===1?``:`s`]}),Rr.queue_items>0&&(0,Y.jsxs)(`li`,{children:[Rr.queue_items,` queue item`,Rr.queue_items===1?``:`s`]}),Rr.library_files>0&&(0,Y.jsxs)(`li`,{children:[Rr.library_files,` library file`,Rr.library_files===1?``:`s`]})]}),(0,Y.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:m(`settings.userItemsQuestion`)}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(K,{variant:`danger`,onClick:()=>La.mutate({id:Ir,deleteItems:!0}),disabled:La.isPending,className:`justify-center`,children:m(`settings.deleteUserAndItems`)}),(0,Y.jsx)(K,{variant:`secondary`,onClick:()=>La.mutate({id:Ir,deleteItems:!1}),disabled:La.isPending,className:`justify-center`,children:m(`settings.deleteUserKeepItems`)}),(0,Y.jsx)(K,{variant:`ghost`,onClick:()=>{Lr(null),zr(null)},disabled:La.isPending,className:`justify-center`,children:m(`common.cancel`)})]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:m(`settings.deleteUserConfirm`)}),(0,Y.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:m(`settings.actionCannotBeUndone`)}),(0,Y.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,Y.jsx)(K,{variant:`ghost`,onClick:()=>{Lr(null),zr(null)},disabled:La.isPending,children:m(`common.cancel`)}),(0,Y.jsx)(K,{variant:`danger`,onClick:()=>La.mutate({id:Ir,deleteItems:!1}),disabled:La.isPending,children:m(`settings.deleteUserTitle`)})]})]})})]})}),Ur!==null&&(0,Y.jsx)(Tt,{title:m(`settings.deleteGroupTitle`),message:m(`settings.deleteGroupMessage`),confirmText:m(`settings.deleteGroup`),variant:`danger`,onConfirm:()=>{Ba.mutate(Ur),Wr(null)},onCancel:()=>Wr(null)}),En===`failure-detection`&&(0,Y.jsx)(`div`,{id:`card-failure-detection`,children:(0,Y.jsx)(Ui,{})}),En===`backup`&&(0,Y.jsxs)(`div`,{id:`card-backup`,children:[(0,Y.jsxs)(`div`,{className:`mb-4 p-3 bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded-lg flex items-start gap-2`,children:[(0,Y.jsx)(Me,{className:`text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`,size:16}),(0,Y.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-400`,children:m(`backup.includesEncryptionKey`)})]}),(0,Y.jsx)(Hi,{})]}),cr&&(0,Y.jsx)(Tt,{title:m(`settings.disableAuthenticationTitle`),message:m(`settings.disableAuthenticationMessage`),confirmText:m(`settings.disableAuthentication`),variant:`danger`,onConfirm:async()=>{try{await r.disableAuth(),v(m(`settings.toast.authDisabled`),`success`),await D(),ur(!1),window.location.href=`/`}catch(e){v(e instanceof Error?e.message:m(`settings.toast.authDisableFailed`),`error`)}},onCancel:()=>ur(!1)}),mr&&(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>{hr(!1),vr({currentPassword:``,newPassword:``,confirmPassword:``})},children:(0,Y.jsxs)(G,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Kt,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:m(`settings.changePassword`)})]}),(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>{hr(!1),vr({currentPassword:``,newPassword:``,confirmPassword:``})},children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]})}),(0,Y.jsxs)(W,{children:[(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`Current Password`}),(0,Y.jsx)(`input`,{type:`password`,value:gr.currentPassword,onChange:e=>vr({...gr,currentPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:m(`settings.enterCurrentPassword`),autoComplete:`current-password`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`New Password`}),(0,Y.jsx)(`input`,{type:`password`,value:gr.newPassword,onChange:e=>vr({...gr,newPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:m(`settings.enterNewPasswordMin6`),autoComplete:`new-password`,minLength:6})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`Confirm New Password`}),(0,Y.jsx)(`input`,{type:`password`,value:gr.confirmPassword,onChange:e=>vr({...gr,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${gr.confirmPassword&&gr.newPassword!==gr.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:m(`settings.confirmNewPassword`),autoComplete:`new-password`,minLength:6}),gr.confirmPassword&&gr.newPassword!==gr.confirmPassword&&(0,Y.jsx)(`p`,{className:`text-red-700 dark:text-red-400 text-xs mt-1`,children:m(`settings.passwordsDoNotMatch`)})]})]}),(0,Y.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:()=>{hr(!1),vr({currentPassword:``,newPassword:``,confirmPassword:``})},children:m(`common.cancel`)}),(0,Y.jsx)(K,{onClick:async()=>{if(gr.newPassword!==gr.confirmPassword){v(m(`settings.toast.passwordsDoNotMatch`),`error`);return}if(gr.newPassword.length<6){v(m(`settings.toast.passwordTooShort`),`error`);return}br(!0);try{await r.changePassword(gr.currentPassword,gr.newPassword),v(m(`settings.toast.passwordChanged`),`success`),hr(!1),vr({currentPassword:``,newPassword:``,confirmPassword:``})}catch(e){v(e instanceof Error?e.message:`Failed to change password`,`error`)}finally{br(!1)}},disabled:yr||!gr.currentPassword||!gr.newPassword||gr.newPassword!==gr.confirmPassword||gr.newPassword.length<6,children:yr?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(L,{className:`w-4 h-4 animate-spin`}),m(`settings.changing`)]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Kt,{className:`w-4 h-4`}),m(`settings.changePassword`)]})})]})]})]})})]})]})]})})}export{Pa as SettingsPage};