From a4006408a2de6840e78c28e449fc603d3403bcff Mon Sep 17 00:00:00 2001 From: maziggy Date: Tue, 17 Mar 2026 13:08:04 +0100 Subject: [PATCH] Fix white filament color swatches invisible in light theme (#726) Changed filament color circle borders from border-white/20 to border-black/20 across all views so white spools are distinguishable against light backgrounds. --- CHANGELOG.md | 1 + frontend/src/components/AssignSpoolModal.tsx | 4 ++-- frontend/src/components/CalendarView.tsx | 2 +- frontend/src/components/ConfigureAmsSlotModal.tsx | 8 ++++---- frontend/src/components/FilamentTrends.tsx | 2 +- frontend/src/components/LinkSpoolModal.tsx | 2 +- frontend/src/components/LocalProfilesView.tsx | 2 +- frontend/src/components/SpoolmanSettings.tsx | 2 +- frontend/src/pages/ArchivesPage.tsx | 6 +++--- frontend/src/pages/InventoryPage.tsx | 2 +- frontend/src/pages/ProjectsPage.tsx | 2 +- .../{index-qEYzdY9E.js => index-DfydSnCI.js} | 14 +++++++------- static/assets/index-Dq3gZWq6.css | 1 - static/assets/index-hKLgfdEQ.css | 1 + static/index.html | 4 ++-- 15 files changed, 27 insertions(+), 26 deletions(-) rename static/assets/{index-qEYzdY9E.js => index-DfydSnCI.js} (99%) delete mode 100644 static/assets/index-Dq3gZWq6.css create mode 100644 static/assets/index-hKLgfdEQ.css diff --git a/CHANGELOG.md b/CHANGELOG.md index 07b42ae6c..af1d548de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to Bambuddy will be documented in this file. - **Per-User Email Notifications** ([#693](https://github.com/maziggy/bambuddy/pull/693)) — When Advanced Authentication is enabled, individual users can now receive email notifications for their own print jobs. A new "Notifications" page lets each user toggle notifications for print start, complete, failed, and stopped events. Only prints submitted by that user trigger their email — other users' prints are not affected. Requires SMTP to be configured and the "User Notifications" toggle enabled in Settings → Notifications. Administrators and Operators have access by default; Viewers do not. Contributed by @cadtoolbox. ### Fixed +- **White Filament Color Swatches Invisible in Light Theme** ([#726](https://github.com/maziggy/bambuddy/issues/726)) — Filament color circles used a white border that was invisible against light theme backgrounds, making white spools indistinguishable. Changed to a dark border (`border-black/20`) across all views: Inventory, Archives, Assign Spool, Configure AMS Slot, Calendar, Projects, Filament Trends, Local Profiles, Link Spool, and Spoolman Settings. Reported by user. - **Webhook Notifications Missing Camera Snapshot** ([#679](https://github.com/maziggy/bambuddy/issues/679)) — Webhook notification providers did not include camera snapshots (e.g. from First Layer Complete notifications), even though providers like Telegram, Pushover, ntfy, and Discord already attached them. The webhook payload now includes a base64-encoded `image` field when a snapshot is available (generic format only, not Slack format). Reported by @Arn0uDz. - **Mobile Sidebar Not Scrollable** — On mobile devices with many navigation items, the sidebar did not scroll, making bottom items unreachable. Added overflow scrolling to the nav section while keeping the logo and footer pinned. - **User Notification Ruff/Lint Fixes** ([#693](https://github.com/maziggy/bambuddy/pull/693)) — Fixed missing `timezone` import in email timestamp, unused lambda argument, PEP 8 blank line spacing for `mark_printer_stopped_by_user`, and SQLAlchemy forward reference in `UserEmailPreference` model. diff --git a/frontend/src/components/AssignSpoolModal.tsx b/frontend/src/components/AssignSpoolModal.tsx index 76c12e498..b6b420206 100644 --- a/frontend/src/components/AssignSpoolModal.tsx +++ b/frontend/src/components/AssignSpoolModal.tsx @@ -222,7 +222,7 @@ export function AssignSpoolModal({ isOpen, onClose, printerId, amsId, trayId, tr
{trayInfo.color && ( )} @@ -268,7 +268,7 @@ export function AssignSpoolModal({ isOpen, onClose, printerId, amsId, trayId, tr
{spool.rgba && ( )} diff --git a/frontend/src/components/CalendarView.tsx b/frontend/src/components/CalendarView.tsx index 7409b5441..085f4576e 100644 --- a/frontend/src/components/CalendarView.tsx +++ b/frontend/src/components/CalendarView.tsx @@ -265,7 +265,7 @@ export function CalendarView({ archives, onArchiveClick, highlightedArchiveId }: {archive.filament_color.split(',').map((color, i) => (
))} diff --git a/frontend/src/components/ConfigureAmsSlotModal.tsx b/frontend/src/components/ConfigureAmsSlotModal.tsx index b643b1863..40892d0c8 100644 --- a/frontend/src/components/ConfigureAmsSlotModal.tsx +++ b/frontend/src/components/ConfigureAmsSlotModal.tsx @@ -841,7 +841,7 @@ export function ConfigureAmsSlotModal({ | {slotInfo.trayColor && ( )} @@ -882,7 +882,7 @@ export function ConfigureAmsSlotModal({
{slotInfo.trayColor && ( )} @@ -1034,7 +1034,7 @@ export function ConfigureAmsSlotModal({ title={entry.color_name} > {entry.color_name} @@ -1269,7 +1269,7 @@ export function ConfigureAmsSlotModal({ title={entry.color_name} > {entry.color_name} diff --git a/frontend/src/components/FilamentTrends.tsx b/frontend/src/components/FilamentTrends.tsx index 694f0ddfe..478baf156 100644 --- a/frontend/src/components/FilamentTrends.tsx +++ b/frontend/src/components/FilamentTrends.tsx @@ -476,7 +476,7 @@ export function FilamentTrends({ archives, currency = '$', dateFrom, dateTo }: F const percent = colorTotal > 0 ? ((entry.value / colorTotal) * 100).toFixed(0) : 0; return (
-
{percent}% diff --git a/frontend/src/components/LinkSpoolModal.tsx b/frontend/src/components/LinkSpoolModal.tsx index 458b6460b..d1c471761 100644 --- a/frontend/src/components/LinkSpoolModal.tsx +++ b/frontend/src/components/LinkSpoolModal.tsx @@ -123,7 +123,7 @@ export function LinkSpoolModal({ isOpen, onClose, tagUid, trayUuid, printerId, a className="w-full flex items-center gap-3 p-3 rounded-lg hover:bg-white/5 transition-colors text-left" >
diff --git a/frontend/src/components/LocalProfilesView.tsx b/frontend/src/components/LocalProfilesView.tsx index 5e835ed35..5dfe23fa1 100644 --- a/frontend/src/components/LocalProfilesView.tsx +++ b/frontend/src/components/LocalProfilesView.tsx @@ -107,7 +107,7 @@ function PresetCard({ {/* 1) Color dot — always shown for filament presets, dimmed if no explicit colour */} {preset.preset_type === 'filament' && (
{s.color && ( )} diff --git a/frontend/src/pages/ArchivesPage.tsx b/frontend/src/pages/ArchivesPage.tsx index 4c83ede3c..ea5a79820 100644 --- a/frontend/src/pages/ArchivesPage.tsx +++ b/frontend/src/pages/ArchivesPage.tsx @@ -1006,7 +1006,7 @@ function ArchiveCard({ {archive.filament_color.split(',').map((color, i) => (
@@ -1962,7 +1962,7 @@ function ArchiveListRow({ {archive.filament_color.split(',').map((color, i) => (
@@ -3508,7 +3508,7 @@ export function ArchivesPage() {
{entry.filament_color && ( )} diff --git a/frontend/src/pages/InventoryPage.tsx b/frontend/src/pages/InventoryPage.tsx index 171fa3864..ef7286852 100644 --- a/frontend/src/pages/InventoryPage.tsx +++ b/frontend/src/pages/InventoryPage.tsx @@ -178,7 +178,7 @@ const columnCells: Record ReactNode> = { rgba: ({ spool }) => (
diff --git a/frontend/src/pages/ProjectsPage.tsx b/frontend/src/pages/ProjectsPage.tsx index 6f9f033cc..2b4491982 100644 --- a/frontend/src/pages/ProjectsPage.tsx +++ b/frontend/src/pages/ProjectsPage.tsx @@ -367,7 +367,7 @@ function ProjectCard({ project, onClick, onEdit, onDelete, hasPermission, t }: P {colors.slice(0, 5).map((col) => (
diff --git a/static/assets/index-qEYzdY9E.js b/static/assets/index-DfydSnCI.js similarity index 99% rename from static/assets/index-qEYzdY9E.js rename to static/assets/index-DfydSnCI.js index 06bddd112..8f75c3c83 100644 --- a/static/assets/index-qEYzdY9E.js +++ b/static/assets/index-DfydSnCI.js @@ -8503,11 +8503,11 @@ void main() { border-l-[5px] border-l-transparent border-r-[5px] border-r-transparent border-t-[5px] border-t-bambu-dark-tertiary - `})]})]})}function Aqe({isOpen:t,onClose:e,tagUid:n,trayUuid:r,printerId:a,amsId:s,trayId:o}){const{t:l}=Ft(),c=an(),{showToast:u}=fn(),[d,m]=w.useState(""),p=r||n,{data:f,isLoading:y}=et({queryKey:["unlinked-spools"],queryFn:be.getUnlinkedSpools,enabled:t}),v=w.useMemo(()=>f?f.filter(g=>{if(!d)return!0;const _=d.toLowerCase();return g.filament_name&&g.filament_name.toLowerCase().includes(_)||g.filament_material&&g.filament_material.toLowerCase().includes(_)||String(g.id).includes(_)}):[],[f,d]),x=pt({mutationFn:g=>be.linkSpool(g,{spoolTag:p,printerId:a,amsId:s,trayId:o}),onSuccess:()=>{c.invalidateQueries({queryKey:["unlinked-spools"]}),c.invalidateQueries({queryKey:["linked-spools"]}),u(l("spoolman.linkSuccess"),"success"),e()},onError:g=>{u(g.message||l("spoolman.linkFailed"),"error")}});return t?i.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[i.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),i.jsxs("div",{className:"relative bg-bambu-dark-secondary rounded-xl shadow-xl w-full max-w-md mx-4 max-h-[80vh] flex flex-col border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-white/10",children:[i.jsxs("div",{children:[i.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Ox,{className:"w-5 h-5 text-bambu-green"}),l("spoolman.selectSpool")]}),i.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["AMS ",s," T",o," · Printer #",a]})]}),i.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"p-4 border-b border-white/10",children:[i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:d,onChange:g=>m(g.target.value),placeholder:l("inventory.searchSpools"),className:"w-full pl-9 pr-3 py-2 bg-bambu-dark rounded-lg border border-white/10 text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green"})]}),(r||n)&&i.jsxs("p",{className:"text-xs text-bambu-gray mt-2 font-mono truncate",title:r||n,children:["Tag: ",r||n]})]}),i.jsx("div",{className:"flex-1 overflow-y-auto p-2 min-h-0",children:y?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 animate-spin text-bambu-green"})}):v.length===0?i.jsx("p",{className:"text-center text-bambu-gray py-8 text-sm",children:l("inventory.noSpoolsMatch")}):v.map(g=>i.jsxs("button",{onClick:()=>x.mutate(g.id),disabled:x.isPending||!p,className:"w-full flex items-center gap-3 p-3 rounded-lg hover:bg-white/5 transition-colors text-left",children:[i.jsx("span",{className:"w-6 h-6 rounded-full border border-white/20 flex-shrink-0",style:{backgroundColor:g.filament_color_hex?`#${g.filament_color_hex}`:"#808080"}}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm text-white font-medium truncate",children:g.filament_name||l("spoolman.spoolId")}),i.jsxs("div",{className:"text-xs text-bambu-gray truncate",children:[g.filament_material||"Unknown"," · #",g.id]})]}),i.jsx("span",{className:"text-xs text-bambu-gray",children:g.remaining_weight!=null?`${Math.round(g.remaining_weight)}g`:"—"})]},g.id))}),i.jsx("div",{className:"p-4 border-t border-white/10 flex justify-end",children:i.jsx(Oe,{variant:"ghost",onClick:e,children:l("inventory.cancel")||"Cancel"})})]})]}):null}function Pqe({isOpen:t,onClose:e,printerId:n,amsId:r,trayId:a,trayInfo:s}){const{t:o}=Ft(),l=an(),{showToast:c}=fn(),[u,d]=w.useState(null),[m,p]=w.useState(""),[f,y]=w.useState(null),[v,x]=w.useState(!1),[g,_]=w.useState(null),{data:N,isLoading:T}=et({queryKey:["inventory-spools"],queryFn:()=>be.getSpools(),enabled:t}),{data:C}=et({queryKey:["spool-assignments"],queryFn:()=>be.getAssignments(),enabled:t}),{data:A}=et({queryKey:["settings"],queryFn:()=>be.getSettings(),enabled:t}),k=pt({mutationFn:X=>be.assignSpool({spool_id:X,printer_id:n,ams_id:r,tray_id:a}),onSuccess:X=>{l.setQueryData(["spool-assignments"],me=>{const he=(me||[]).filter(ge=>!(ge.printer_id===n&&ge.ams_id===r&&ge.tray_id===a));return he.push(X),he}),l.invalidateQueries({queryKey:["spool-assignments"]}),c(o("inventory.assignSuccess"),"success"),x(!1),y(null),_(null),e()},onError:X=>{c(`${o("inventory.assignFailed")}: ${X.message}`,"error")}}),R=X=>(X??"").trim().toUpperCase(),P=(X,me)=>{const he=R(X),ge=R(me);return!he||!ge?"none":he===ge?"exact":ge.includes(he)||he.includes(ge)?"partial":"none"},D=(X,me)=>{const he=R(X),ge=R(me);return!he||!ge?!1:he===ge};if(!t)return null;const H=new Set((C||[]).filter(X=>!(X.printer_id===n&&X.ams_id===r&&X.tray_id===a)).map(X=>X.spool_id)),z=r===254||r===255,G=N?.filter(X=>!H.has(X.id)&&(z||!X.tag_uid&&!X.tray_uuid)),I=G?.filter(X=>{if(!m)return!0;const me=m.toLowerCase();return X.material.toLowerCase().includes(me)||(X.brand?.toLowerCase().includes(me)??!1)||(X.color_name?.toLowerCase().includes(me)??!1)||(X.subtype?.toLowerCase().includes(me)??!1)}),ee=()=>{if(!u)return;const X=N?.find(me=>me.id===u);if(!X){c(o("inventory.assignFailed"),"error");return}if(!A?.disable_filament_warnings&&s){const me=s.material||s.type,he=P(X.material,me),ge=X.slicer_filament_name||X.slicer_filament,Y=s.profile||s.type,oe=D(ge,Y);if(he!=="exact"||!oe){let le="profile";he==="none"&&!oe?le="material_profile":he==="partial"&&!oe?le="partial_profile":he==="none"?le="material":he==="partial"&&(le="partial"),y(u),_({type:le,spoolMaterial:X.material||"",trayMaterial:me||"",spoolProfile:ge||void 0,trayProfile:Y||void 0}),x(!0);return}}k.mutate(u)},ie=()=>{f&&(k.mutate(f),x(!1),y(null))};return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[i.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),i.jsxs("div",{className:"relative w-full max-w-2xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Wi,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:o("inventory.assignSpool")})]}),i.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[s&&i.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("p",{className:"text-xs text-bambu-gray mb-1",children:[o("inventory.selectSpool"),":"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[s.color&&i.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20",style:{backgroundColor:`#${s.color}`}}),i.jsx("span",{className:"text-white font-medium",children:s.type||o("ams.emptySlot")}),i.jsxs("span",{className:"text-bambu-gray",children:["(",s.location,")"]})]})]}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:m,onChange:X=>p(X.target.value),placeholder:o("inventory.searchSpools"),className:"w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green"})]}),i.jsx("div",{children:T?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})}):I&&I.length>0?i.jsx("div",{className:"max-h-96 overflow-y-auto grid grid-cols-2 sm:grid-cols-3 gap-2",children:I.map(X=>i.jsxs("button",{onClick:()=>d(X.id),className:`p-2.5 rounded-lg border text-left transition-colors ${u===X.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[i.jsxs("p",{className:"text-white text-sm font-medium truncate",children:[X.brand?`${X.brand} `:"",X.material,X.subtype?` ${X.subtype}`:""]}),i.jsxs("div",{className:"flex items-center gap-1.5 mt-1",children:[X.rgba&&i.jsx("span",{className:"w-3 h-3 rounded-full border border-white/20 flex-shrink-0",style:{backgroundColor:`#${X.rgba.substring(0,6)}`}}),i.jsx("span",{className:"text-xs text-bambu-gray truncate",children:X.color_name||""})]}),X.label_weight&&i.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:[Math.max(0,Math.round(X.label_weight-X.weight_used))," / ",X.label_weight,"g"]})]},X.id))}):G&&G.length===0?i.jsx("div",{className:"text-center py-8 text-bambu-gray",children:i.jsx("p",{children:o("inventory.noManualSpools")})}):i.jsx("div",{className:"text-center py-8 text-bambu-gray",children:i.jsx("p",{children:o("inventory.noSpoolsMatch")})})})]}),i.jsxs("div",{className:"flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary",children:[i.jsx(Oe,{variant:"secondary",onClick:e,children:o("common.cancel")}),i.jsx(Oe,{onClick:ee,disabled:!u||k.isPending,children:k.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),o("inventory.assigning")]}):i.jsxs(i.Fragment,{children:[i.jsx(Wi,{className:"w-4 h-4"}),o("inventory.assignSpool")]})})]}),k.isError&&i.jsx("div",{className:"mx-4 mb-4 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:k.error.message})]})]}),v&&s&&u&&g&&(()=>{let X="";return g.type==="material"?X=o("inventory.assignMismatchMessage",{spoolMaterial:g.spoolMaterial,trayMaterial:g.trayMaterial,location:s.location}):g.type==="partial"?X=o("inventory.assignPartialMismatchMessage",{spoolMaterial:g.spoolMaterial,trayMaterial:g.trayMaterial,location:s.location}):g.type==="material_profile"?X=`${o("inventory.assignMismatchMessage",{spoolMaterial:g.spoolMaterial,trayMaterial:g.trayMaterial,location:s.location})} + `})]})]})}function Aqe({isOpen:t,onClose:e,tagUid:n,trayUuid:r,printerId:a,amsId:s,trayId:o}){const{t:l}=Ft(),c=an(),{showToast:u}=fn(),[d,m]=w.useState(""),p=r||n,{data:f,isLoading:y}=et({queryKey:["unlinked-spools"],queryFn:be.getUnlinkedSpools,enabled:t}),v=w.useMemo(()=>f?f.filter(g=>{if(!d)return!0;const _=d.toLowerCase();return g.filament_name&&g.filament_name.toLowerCase().includes(_)||g.filament_material&&g.filament_material.toLowerCase().includes(_)||String(g.id).includes(_)}):[],[f,d]),x=pt({mutationFn:g=>be.linkSpool(g,{spoolTag:p,printerId:a,amsId:s,trayId:o}),onSuccess:()=>{c.invalidateQueries({queryKey:["unlinked-spools"]}),c.invalidateQueries({queryKey:["linked-spools"]}),u(l("spoolman.linkSuccess"),"success"),e()},onError:g=>{u(g.message||l("spoolman.linkFailed"),"error")}});return t?i.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[i.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),i.jsxs("div",{className:"relative bg-bambu-dark-secondary rounded-xl shadow-xl w-full max-w-md mx-4 max-h-[80vh] flex flex-col border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-white/10",children:[i.jsxs("div",{children:[i.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Ox,{className:"w-5 h-5 text-bambu-green"}),l("spoolman.selectSpool")]}),i.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["AMS ",s," T",o," · Printer #",a]})]}),i.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"p-4 border-b border-white/10",children:[i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:d,onChange:g=>m(g.target.value),placeholder:l("inventory.searchSpools"),className:"w-full pl-9 pr-3 py-2 bg-bambu-dark rounded-lg border border-white/10 text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green"})]}),(r||n)&&i.jsxs("p",{className:"text-xs text-bambu-gray mt-2 font-mono truncate",title:r||n,children:["Tag: ",r||n]})]}),i.jsx("div",{className:"flex-1 overflow-y-auto p-2 min-h-0",children:y?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 animate-spin text-bambu-green"})}):v.length===0?i.jsx("p",{className:"text-center text-bambu-gray py-8 text-sm",children:l("inventory.noSpoolsMatch")}):v.map(g=>i.jsxs("button",{onClick:()=>x.mutate(g.id),disabled:x.isPending||!p,className:"w-full flex items-center gap-3 p-3 rounded-lg hover:bg-white/5 transition-colors text-left",children:[i.jsx("span",{className:"w-6 h-6 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:g.filament_color_hex?`#${g.filament_color_hex}`:"#808080"}}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm text-white font-medium truncate",children:g.filament_name||l("spoolman.spoolId")}),i.jsxs("div",{className:"text-xs text-bambu-gray truncate",children:[g.filament_material||"Unknown"," · #",g.id]})]}),i.jsx("span",{className:"text-xs text-bambu-gray",children:g.remaining_weight!=null?`${Math.round(g.remaining_weight)}g`:"—"})]},g.id))}),i.jsx("div",{className:"p-4 border-t border-white/10 flex justify-end",children:i.jsx(Oe,{variant:"ghost",onClick:e,children:l("inventory.cancel")||"Cancel"})})]})]}):null}function Pqe({isOpen:t,onClose:e,printerId:n,amsId:r,trayId:a,trayInfo:s}){const{t:o}=Ft(),l=an(),{showToast:c}=fn(),[u,d]=w.useState(null),[m,p]=w.useState(""),[f,y]=w.useState(null),[v,x]=w.useState(!1),[g,_]=w.useState(null),{data:N,isLoading:T}=et({queryKey:["inventory-spools"],queryFn:()=>be.getSpools(),enabled:t}),{data:C}=et({queryKey:["spool-assignments"],queryFn:()=>be.getAssignments(),enabled:t}),{data:A}=et({queryKey:["settings"],queryFn:()=>be.getSettings(),enabled:t}),k=pt({mutationFn:X=>be.assignSpool({spool_id:X,printer_id:n,ams_id:r,tray_id:a}),onSuccess:X=>{l.setQueryData(["spool-assignments"],me=>{const he=(me||[]).filter(ge=>!(ge.printer_id===n&&ge.ams_id===r&&ge.tray_id===a));return he.push(X),he}),l.invalidateQueries({queryKey:["spool-assignments"]}),c(o("inventory.assignSuccess"),"success"),x(!1),y(null),_(null),e()},onError:X=>{c(`${o("inventory.assignFailed")}: ${X.message}`,"error")}}),R=X=>(X??"").trim().toUpperCase(),P=(X,me)=>{const he=R(X),ge=R(me);return!he||!ge?"none":he===ge?"exact":ge.includes(he)||he.includes(ge)?"partial":"none"},D=(X,me)=>{const he=R(X),ge=R(me);return!he||!ge?!1:he===ge};if(!t)return null;const H=new Set((C||[]).filter(X=>!(X.printer_id===n&&X.ams_id===r&&X.tray_id===a)).map(X=>X.spool_id)),z=r===254||r===255,G=N?.filter(X=>!H.has(X.id)&&(z||!X.tag_uid&&!X.tray_uuid)),I=G?.filter(X=>{if(!m)return!0;const me=m.toLowerCase();return X.material.toLowerCase().includes(me)||(X.brand?.toLowerCase().includes(me)??!1)||(X.color_name?.toLowerCase().includes(me)??!1)||(X.subtype?.toLowerCase().includes(me)??!1)}),ee=()=>{if(!u)return;const X=N?.find(me=>me.id===u);if(!X){c(o("inventory.assignFailed"),"error");return}if(!A?.disable_filament_warnings&&s){const me=s.material||s.type,he=P(X.material,me),ge=X.slicer_filament_name||X.slicer_filament,Y=s.profile||s.type,oe=D(ge,Y);if(he!=="exact"||!oe){let le="profile";he==="none"&&!oe?le="material_profile":he==="partial"&&!oe?le="partial_profile":he==="none"?le="material":he==="partial"&&(le="partial"),y(u),_({type:le,spoolMaterial:X.material||"",trayMaterial:me||"",spoolProfile:ge||void 0,trayProfile:Y||void 0}),x(!0);return}}k.mutate(u)},ie=()=>{f&&(k.mutate(f),x(!1),y(null))};return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[i.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),i.jsxs("div",{className:"relative w-full max-w-2xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Wi,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:o("inventory.assignSpool")})]}),i.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[s&&i.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("p",{className:"text-xs text-bambu-gray mb-1",children:[o("inventory.selectSpool"),":"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[s.color&&i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20",style:{backgroundColor:`#${s.color}`}}),i.jsx("span",{className:"text-white font-medium",children:s.type||o("ams.emptySlot")}),i.jsxs("span",{className:"text-bambu-gray",children:["(",s.location,")"]})]})]}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:m,onChange:X=>p(X.target.value),placeholder:o("inventory.searchSpools"),className:"w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green"})]}),i.jsx("div",{children:T?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})}):I&&I.length>0?i.jsx("div",{className:"max-h-96 overflow-y-auto grid grid-cols-2 sm:grid-cols-3 gap-2",children:I.map(X=>i.jsxs("button",{onClick:()=>d(X.id),className:`p-2.5 rounded-lg border text-left transition-colors ${u===X.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[i.jsxs("p",{className:"text-white text-sm font-medium truncate",children:[X.brand?`${X.brand} `:"",X.material,X.subtype?` ${X.subtype}`:""]}),i.jsxs("div",{className:"flex items-center gap-1.5 mt-1",children:[X.rgba&&i.jsx("span",{className:"w-3 h-3 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:`#${X.rgba.substring(0,6)}`}}),i.jsx("span",{className:"text-xs text-bambu-gray truncate",children:X.color_name||""})]}),X.label_weight&&i.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:[Math.max(0,Math.round(X.label_weight-X.weight_used))," / ",X.label_weight,"g"]})]},X.id))}):G&&G.length===0?i.jsx("div",{className:"text-center py-8 text-bambu-gray",children:i.jsx("p",{children:o("inventory.noManualSpools")})}):i.jsx("div",{className:"text-center py-8 text-bambu-gray",children:i.jsx("p",{children:o("inventory.noSpoolsMatch")})})})]}),i.jsxs("div",{className:"flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary",children:[i.jsx(Oe,{variant:"secondary",onClick:e,children:o("common.cancel")}),i.jsx(Oe,{onClick:ee,disabled:!u||k.isPending,children:k.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),o("inventory.assigning")]}):i.jsxs(i.Fragment,{children:[i.jsx(Wi,{className:"w-4 h-4"}),o("inventory.assignSpool")]})})]}),k.isError&&i.jsx("div",{className:"mx-4 mb-4 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:k.error.message})]})]}),v&&s&&u&&g&&(()=>{let X="";return g.type==="material"?X=o("inventory.assignMismatchMessage",{spoolMaterial:g.spoolMaterial,trayMaterial:g.trayMaterial,location:s.location}):g.type==="partial"?X=o("inventory.assignPartialMismatchMessage",{spoolMaterial:g.spoolMaterial,trayMaterial:g.trayMaterial,location:s.location}):g.type==="material_profile"?X=`${o("inventory.assignMismatchMessage",{spoolMaterial:g.spoolMaterial,trayMaterial:g.trayMaterial,location:s.location})} ${o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})}`:g.type==="partial_profile"?X=`${o("inventory.assignPartialMismatchMessage",{spoolMaterial:g.spoolMaterial,trayMaterial:g.trayMaterial,location:s.location})} -${o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})}`:g.type==="profile"&&(X=o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})),i.jsx(Sn,{title:o("inventory.assignMismatchTitle"),message:X,confirmText:o("inventory.assignMismatchConfirm"),variant:"warning",isLoading:k.isPending,onConfirm:ie,onCancel:()=>{k.isPending||(x(!1),y(null),_(null))}})})()]})}function oW(t,e){if(t===255)return"External";let n,r=!1;t>=128&&t<=135?(n=t-128,r=!0):t>=0&&t<=3?(n=t,r=e===1):n=0,n=Math.max(0,Math.min(n,7));const a=String.fromCharCode(65+n);return r?`HT-${a}`:`AMS-${a}`}function k1(t){const e=t.includes("_")?t.split("_")[0]:t;return e.startsWith("GFS")?"GF"+e.slice(3):(e.startsWith("PFUS")||e.startsWith("PFSP"),e)}const Wv=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","NYLON","PVA","HIPS","PP","PET"];function lW(t){const e=t.replace(/@.+$/,"").trim(),n=e.toUpperCase(),r=n.match(/\bSUPPORT\s+FOR\s+/);if(r){const s=n.slice(r.index+r[0].length);for(const o of Wv)if(new RegExp(`\\b${o}\\b`).test(s)){const c=e.slice(0,r.index).trim();return{material:o,brand:c,variant:"Support"}}}for(const s of Wv){const o=new RegExp(`\\b${s}\\b`,"i");if(o.test(n)){const l=e.split(o),c=l[0]?.trim()||"",u=l[1]?.trim()||"";return{material:s,brand:c,variant:u}}}const a=e.split(/\s+/);return a.length>=2?{material:a[1],brand:a[0],variant:a.slice(2).join(" ")}:{material:e,brand:"",variant:""}}function Mqe(t){return!t.startsWith("GF")&&!t.startsWith("P1")}const Eqe={white:"FFFFFF",black:"000000",red:"FF0000",green:"00FF00",blue:"0000FF",yellow:"FFFF00",cyan:"00FFFF",magenta:"FF00FF",orange:"FFA500",purple:"800080",pink:"FFC0CB",brown:"8B4513",gray:"808080",grey:"808080","jade white":"FFFEF2",ivory:"FFFFF0",beige:"F5F5DC",cream:"FFFDD0",silver:"C0C0C0",gold:"FFD700",bronze:"CD7F32",copper:"B87333",navy:"000080",teal:"008080",olive:"808000",maroon:"800000",coral:"FF7F50",salmon:"FA8072",lime:"32CD32",mint:"98FF98","forest green":"228B22","sky blue":"87CEEB","royal blue":"4169E1",turquoise:"40E0D0",lavender:"E6E6FA",violet:"EE82EE",plum:"DDA0DD",tan:"D2B48C",chocolate:"D2691E",charcoal:"36454F",slate:"708090",transparent:"000000",natural:"F5F5DC",wood:"DEB887"},cW=[{name:"White",hex:"FFFFFF"},{name:"Black",hex:"000000"},{name:"Red",hex:"FF0000"},{name:"Blue",hex:"0000FF"},{name:"Green",hex:"00AA00"},{name:"Yellow",hex:"FFFF00"},{name:"Orange",hex:"FFA500"},{name:"Gray",hex:"808080"}],uW=[{name:"Cyan",hex:"00FFFF"},{name:"Magenta",hex:"FF00FF"},{name:"Purple",hex:"800080"},{name:"Pink",hex:"FFC0CB"},{name:"Brown",hex:"8B4513"},{name:"Beige",hex:"F5F5DC"},{name:"Navy",hex:"000080"},{name:"Teal",hex:"008080"},{name:"Lime",hex:"32CD32"},{name:"Gold",hex:"FFD700"},{name:"Silver",hex:"C0C0C0"},{name:"Maroon",hex:"800000"},{name:"Olive",hex:"808000"},{name:"Coral",hex:"FF7F50"},{name:"Salmon",hex:"FA8072"},{name:"Turquoise",hex:"40E0D0"},{name:"Violet",hex:"EE82EE"},{name:"Indigo",hex:"4B0082"},{name:"Chocolate",hex:"D2691E"},{name:"Tan",hex:"D2B48C"},{name:"Slate",hex:"708090"},{name:"Charcoal",hex:"36454F"},{name:"Ivory",hex:"FFFFF0"},{name:"Cream",hex:"FFFDD0"}];function dW(t){const e=t.toLowerCase().trim();return Eqe[e]||null}function jqe(t){const e=t.indexOf("@");if(e<0)return null;const r=t.slice(e+1).trim().match(/^BBL\s+(.+?)(?:\s+[\d.]+\s*nozzle)?$/i);return r?r[1].trim():null}function Xre({isOpen:t,onClose:e,printerId:n,slotInfo:r,nozzleDiameter:a="0.4",printerModel:s,onSuccess:o,fullScreen:l}){const{t:c}=Ft(),[u,d]=w.useState(""),[m,p]=w.useState(null),[f,y]=w.useState(""),[v,x]=w.useState(""),[g,_]=w.useState(""),[N,T]=w.useState(!1),[C,A]=w.useState(!1),k=w.useRef(""),{data:R,isLoading:P,isError:D}=et({queryKey:["cloudSettings"],queryFn:()=>be.getCloudSettings(),enabled:t,retry:!1}),{data:H,isLoading:z}=et({queryKey:["localPresets"],queryFn:()=>be.getLocalPresets(),enabled:t}),{data:G,isLoading:I}=et({queryKey:["builtinFilaments"],queryFn:()=>be.getBuiltinFilaments(),enabled:t,staleTime:1/0}),{data:ee,isLoading:ie}=et({queryKey:["kprofiles",n,a],queryFn:()=>be.getKProfiles(n,a),enabled:t&&!!n}),{data:X}=et({queryKey:["colorCatalog"],queryFn:()=>be.getColorCatalog(),enabled:t,staleTime:1/0}),me=pt({mutationFn:async()=>{if(!u)throw new Error("No filament preset selected");const E=u.startsWith("local_"),U=u.startsWith("builtin_"),K=E?parseInt(u.replace("local_",""),10):null,$=U?u.replace("builtin_",""):null,ne=E?H?.filament.find(Le=>Le.id===K):null,O=U?G?.find(Le=>Le.filament_id===$):null,V=!E&&!U?R?.filament.find(Le=>Le.setting_id===u):null;if(!E&&!U&&!V)throw new Error("Selected preset not found");if(E&&!ne)throw new Error("Selected local preset not found");if(U&&!O)throw new Error("Selected builtin preset not found");const J=E?ne.name:U?O.name:V.name,W=lW(J),re=m?.slot_id??-1,ue=f||r.trayColor?.slice(0,6)||"FFFFFF",fe=J.replace(/@.+$/,"").trim();let ye,ae;const L=W.material.toUpperCase();if(E){const Le=(Wv.includes(L)?L:ne?.filament_type||W.material||"").toUpperCase(),qe={PLA:"GFL99","PLA-CF":"GFL98","PLA SILK":"GFL96","PLA HIGH SPEED":"GFL95",PETG:"GFG99","PETG HF":"GFG96","PETG-CF":"GFG98",PCTG:"GFG97",ABS:"GFB99",ASA:"GFB98",PC:"GFC99",PA:"GFN99","PA-CF":"GFN98",NYLON:"GFN99",TPU:"GFU99",PVA:"GFS99",HIPS:"GFS98",PE:"GFP99",PP:"GFP97"};ye=qe[Le]||qe[Le.replace(/[-\s]?CF$/,"")]||qe[Le.replace(/\+$/,"")]||qe[Le.split(/[-\s]/)[0]]||"",ae=""}else if(U)ye=$,ae="";else if(ye=k1(u),ae=u,!u.startsWith("GFS"))try{const Le=await be.getCloudSettingDetail(u);Le.filament_id?ye=Le.filament_id:Le.base_id&&(ye=k1(Le.base_id),console.log(`Derived tray_info_idx from base_id: ${Le.base_id} -> ${ye}`))}catch(Le){console.warn("Failed to fetch preset detail for filament_id:",Le)}let F=E&&ne?.nozzle_temp_min?ne.nozzle_temp_min:190,te=E&&ne?.nozzle_temp_max?ne.nozzle_temp_max:230;if(!E||U||!ne?.nozzle_temp_min&&!ne?.nozzle_temp_max){const Le=(E?Wv.includes(L)?L:ne?.filament_type||W.material||"":W.material).toUpperCase();Le.includes("PLA")?(F=190,te=230):Le.includes("PETG")?(F=220,te=260):Le.includes("ABS")||Le.includes("ASA")?(F=240,te=280):Le.includes("TPU")?(F=200,te=240):Le==="PCTG"?(F=220,te=260):Le.includes("PC")?(F=260,te=300):(Le.includes("PA")||Le.includes("NYLON"))&&(F=250,te=290)}const ve=m?.k_value?parseFloat(m.k_value):0,pe=E?Wv.includes(L)?L:ne?.filament_type||W.material||"PLA":W.material||"PLA",de=await be.configureAmsSlot(n,r.amsId,r.trayId,{tray_info_idx:ye,tray_type:pe,tray_sub_brands:fe,tray_color:ue+"FF",nozzle_temp_min:F,nozzle_temp_max:te,cali_idx:re,nozzle_diameter:a,setting_id:ae,kprofile_filament_id:m?.filament_id,kprofile_setting_id:m?.setting_id||void 0,k_value:ve}),Ne=E?`local_${K}`:U?`builtin_${$}`:u,Se=E?"local":U?"builtin":"cloud";try{await be.saveSlotPreset(n,r.amsId,r.trayId,Ne,fe,Se)}catch(Le){console.warn("Failed to save slot preset mapping:",Le)}return de},onSuccess:()=>{T(!0),o?.(),setTimeout(()=>{T(!1),e()},1500)}}),he=pt({mutationFn:async()=>be.resetAmsSlot(n,r.amsId,r.trayId),onSuccess:()=>{T(!0),o?.(),setTimeout(()=>{T(!1),e()},1500)}}),ge=w.useMemo(()=>{const E=g.toLowerCase(),U=[],K=new Set,$=r.savedPresetId,ne=r.trayInfoIdx;if(R?.filament)for(const O of R.filament){K.add(O.setting_id);const V=$===O.setting_id||ne&&(O.setting_id===ne||k1(O.setting_id)===ne);if(!(!V&&E&&!O.name.toLowerCase().includes(E))){if(!V&&s){const J=jqe(O.name);if(J&&J.toUpperCase()!==s.toUpperCase())continue}U.push({id:O.setting_id,name:O.name,source:"cloud",isUser:Mqe(O.setting_id)})}}if(H?.filament)for(const O of H.filament){const V=`local_${O.id}`;!($===V)&&E&&!O.name.toLowerCase().includes(E)||U.push({id:V,name:O.name,source:"local",isUser:!1})}if(G)for(const O of G){if(K.has(O.filament_id))continue;const V=O.filament_id.startsWith("GF")?"GFS"+O.filament_id.slice(2):O.filament_id;K.has(V)||(!E||O.name.toLowerCase().includes(E))&&U.push({id:`builtin_${O.filament_id}`,name:O.name,source:"builtin",isUser:!1})}return U.sort((O,V)=>{const J={cloud:0,local:1,builtin:2};return O.source!==V.source?J[O.source]-J[V.source]:O.isUser&&!V.isUser?-1:!O.isUser&&V.isUser?1:O.name.localeCompare(V.name)})},[R?.filament,H?.filament,G,g,s,r.savedPresetId,r.trayInfoIdx]),Y=w.useMemo(()=>{if(!u)return null;let E=null;if(u.startsWith("local_")){const $=parseInt(u.replace("local_",""),10);E=H?.filament.find(O=>O.id===$)?.name||null}else if(u.startsWith("builtin_")){const $=u.replace("builtin_","");E=G?.find(O=>O.filament_id===$)?.name||null}else R?.filament&&(E=R.filament.find(ne=>ne.setting_id===u)?.name||null);if(!E)return null;let U=E.replace(/@.+$/,"").trim();U.startsWith("# ")&&(U=U.slice(2).trim());const K=lW(U);return{fullName:U,material:K.material,brand:K.brand}},[u,R?.filament,H?.filament,G]),oe=Y?.fullName||"",le=w.useMemo(()=>{if(!X||!Y)return[];const{fullName:E,brand:U}=Y,K=E.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,"").trim();return X.filter($=>{const ne=($.material||"").toUpperCase(),O=$.manufacturer.toUpperCase();if(!(ne===K.toUpperCase()||ne.includes(K.toUpperCase())||K.toUpperCase().includes(ne)))return!1;if(U){const J=U.toUpperCase();if(!O.includes(J)&&!J.includes(O))return!1}return!0})},[X,Y]),xe=w.useMemo(()=>{if(!ee?.profiles||!Y)return[];const{fullName:E,material:U,brand:K}=Y,$=E.toUpperCase(),ne=U.toUpperCase(),O=K.toUpperCase();if(!ne||ne.length<2)return[];const V=ee.profiles.filter(W=>{const re=W.name.toUpperCase();if(O)return!(!re.includes(O)||!re.includes(ne));if(re.includes($)||re.includes(ne))return!0;const fe={NYLON:["PA","PA-CF","PA6"],PA:["NYLON"]}[ne]||[];for(const ye of fe)if(re.includes(ye))return!0;return!1}),J=new Map;for(const W of V){const re=`${W.name}|${W.k_value}`,ue=J.get(re);ue?r.extruderId!==void 0&&W.extruder_id===r.extruderId&&ue.extruder_id!==r.extruderId&&J.set(re,W):J.set(re,W)}return Array.from(J.values())},[ee?.profiles,Y,r.extruderId]);w.useEffect(()=>{if(t){if(r.savedPresetId)d(r.savedPresetId);else if(r.trayInfoIdx&&R?.filament){let E=R.filament.find(U=>U.setting_id===r.trayInfoIdx);E||(E=R.filament.find(U=>k1(U.setting_id)===r.trayInfoIdx)),E&&d(E.setting_id)}else if(r.trayInfoIdx&&G?.length){const E=r.trayInfoIdx,U=G.find(K=>K.filament_id===E);U&&d(`builtin_${U.filament_id}`)}if(r.trayColor){const E=r.trayColor.slice(0,6);E&&y(E)}}else d(""),p(null),y(""),x(""),_(""),T(!1),k.current=""},[t,r.savedPresetId,r.trayInfoIdx,r.trayColor,R?.filament,G]),w.useEffect(()=>{if(xe.length>0){if(r.caliIdx!=null&&r.caliIdx>0){const E=xe.find(U=>U.slot_id===r.caliIdx);if(E){p(E);return}}p(xe[0])}else p(null)},[u,xe,r.caliIdx]);const Pe=w.useCallback(E=>{E.key==="Escape"&&e()},[e]);w.useEffect(()=>{if(t)return document.addEventListener("keydown",Pe),()=>document.removeEventListener("keydown",Pe)},[t,Pe]);const q=P&&!D||z||I||ie;if(w.useEffect(()=>{if(!q&&u&&u!==k.current){const E=requestAnimationFrame(()=>{const K=document.querySelector('[class*="fixed inset-0 z-50"]')?.querySelector(`[data-preset-id="${CSS.escape(u)}"]`);K&&(k.current=u,K.scrollIntoView({block:"nearest"}))});return()=>cancelAnimationFrame(E)}},[u,q]),!t)return null;const Z=u&&!me.isPending,j=f||r.trayColor?.slice(0,6)||"FFFFFF";return i.jsxs("div",{className:`fixed inset-0 z-50 flex ${l?"":"items-center justify-center"}`,children:[!l&&i.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),i.jsxs("div",{className:l?"relative w-full h-full bg-bambu-dark-secondary flex flex-col":"relative w-full max-w-lg mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(jd,{className:"w-5 h-5 text-bambu-blue"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.title")}),l&&i.jsxs("div",{className:"flex items-center gap-2 ml-4 text-sm text-bambu-gray",children:[i.jsx("span",{className:"text-white/30",children:"|"}),r.trayColor&&i.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),i.jsx("span",{className:"text-white/70",children:c("configureAmsSlot.slotLabel",{ams:oW(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&i.jsxs("span",{children:["(",r.traySubBrands,")"]})]})]}),i.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:`p-4 overflow-y-auto ${l?"flex-1 min-h-0":"space-y-4 max-h-[60vh]"}`,children:[N&&i.jsx("div",{className:"absolute inset-0 bg-bambu-dark-secondary/95 z-10 flex items-center justify-center rounded-xl",children:i.jsxs("div",{className:"text-center space-y-3",children:[i.jsx(Jc,{className:"w-16 h-16 text-bambu-green mx-auto"}),i.jsx("p",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.slotConfigured")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:c("configureAmsSlot.settingsSentToPrinter")})]})}),!l&&i.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:c("configureAmsSlot.configuringSlot")}),i.jsxs("div",{className:"flex items-center gap-2",children:[r.trayColor&&i.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),i.jsx("span",{className:"text-white font-medium",children:c("configureAmsSlot.slotLabel",{ams:oW(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&i.jsxs("span",{className:"text-bambu-gray",children:["(",r.traySubBrands,")"]})]})]}),q?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})}):l?i.jsxs("div",{className:"flex gap-4 h-full",children:[i.jsxs("div",{className:"w-1/2 flex flex-col min-h-0",children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:g,onChange:E=>_(E.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2 shrink-0"}),i.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-1",children:ge.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:R?.filament?.length===0&&!H?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):ge.map(E=>i.jsx("button",{"data-preset-id":E.id,onClick:()=>d(E.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${u===E.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-white text-sm truncate",children:E.name}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[E.source==="local"&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:c("profiles.localProfiles.badge")}),E.source==="builtin"&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:c("configureAmsSlot.builtin")}),E.isUser&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:c("configureAmsSlot.custom")})]})]})},E.id))})]}),i.jsxs("div",{className:"w-1/2 flex flex-col gap-4 min-h-0 overflow-y-auto",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),oe&&i.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:oe})})]}),xe.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:E=>{const U=xe.find(K=>K.name===E.target.value);p(U||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 appearance-none pr-10",children:[i.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),xe.map(E=>i.jsxs("option",{value:E.name,children:[E.name," (K=",E.k_value,")"]},`${E.name}-${E.extruder_id}`))]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):u?i.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:c("configureAmsSlot.noMatchingKProfiles")}):i.jsx("span",{className:"inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30",children:c("configureAmsSlot.selectFilamentFirst")}),m&&i.jsx("p",{className:"text-xs text-bambu-green mt-1",children:c("configureAmsSlot.kFromCalibration",{value:m.k_value})})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:c("configureAmsSlot.customColorLabel")}),le.length>0&&i.jsxs("div",{className:"mb-3",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:c("configureAmsSlot.presetColors",{name:Y?.fullName})}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:le.map(E=>i.jsxs("button",{onClick:()=>{const U=E.hex_color.replace("#","").toUpperCase();y(U),x(E.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===E.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:E.color_name,children:[i.jsx("span",{className:"w-4 h-4 rounded-full border border-white/30 flex-shrink-0",style:{backgroundColor:E.hex_color}}),i.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:E.color_name})]},E.id))})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[cW.map(E=>i.jsx("button",{onClick:()=>{y(E.hex),x(E.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===E.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${E.hex}`},title:E.name},E.hex)),i.jsx("button",{onClick:()=>A(!C),className:"w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs",title:c(C?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:C?"−":"+"})]}),C&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:uW.map(E=>i.jsx("button",{onClick:()=>{y(E.hex),x(E.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===E.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${E.hex}`},title:E.name},E.hex))}),i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${j}`}}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:E=>{const U=E.target.value;x(U);const K=dW(U);if(K)y(K);else{const $=U.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();$.length===6?y($):$.length===3&&y($.split("").map(ne=>ne+ne).join(""))}},className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm"}),f&&i.jsx("button",{onClick:()=>{y(""),x("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),f&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:f})})]})]})]}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:g,onChange:E=>_(E.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2"}),i.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:ge.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:R?.filament?.length===0&&!H?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):ge.map(E=>i.jsx("button",{"data-preset-id":E.id,onClick:()=>d(E.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${u===E.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-white text-sm truncate",children:E.name}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[E.source==="local"&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:c("profiles.localProfiles.badge")}),E.source==="builtin"&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:c("configureAmsSlot.builtin")}),E.isUser&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:c("configureAmsSlot.custom")})]})]})},E.id))})]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),oe&&i.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:oe})})]}),xe.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:E=>{const U=xe.find(K=>K.name===E.target.value);p(U||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 appearance-none pr-10",children:[i.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),xe.map(E=>i.jsxs("option",{value:E.name,children:[E.name," (K=",E.k_value,")"]},`${E.name}-${E.extruder_id}`))]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):u?i.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:c("configureAmsSlot.noMatchingKProfiles")}):i.jsx("span",{className:"inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30",children:c("configureAmsSlot.selectFilamentFirst")}),m&&i.jsx("p",{className:"text-xs text-bambu-green mt-1",children:c("configureAmsSlot.kFromCalibration",{value:m.k_value})})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:c("configureAmsSlot.customColorLabel")}),le.length>0&&i.jsxs("div",{className:"mb-3",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:c("configureAmsSlot.presetColors",{name:Y?.fullName})}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:le.map(E=>i.jsxs("button",{onClick:()=>{const U=E.hex_color.replace("#","").toUpperCase();y(U),x(E.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===E.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:E.color_name,children:[i.jsx("span",{className:"w-4 h-4 rounded-full border border-white/30 flex-shrink-0",style:{backgroundColor:E.hex_color}}),i.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:E.color_name})]},E.id))})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[cW.map(E=>i.jsx("button",{onClick:()=>{y(E.hex),x(E.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===E.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${E.hex}`},title:E.name},E.hex)),i.jsx("button",{onClick:()=>A(!C),className:"w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs",title:c(C?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:C?"−":"+"})]}),C&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:uW.map(E=>i.jsx("button",{onClick:()=>{y(E.hex),x(E.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===E.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${E.hex}`},title:E.name},E.hex))}),i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${j}`}}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:E=>{const U=E.target.value;x(U);const K=dW(U);if(K)y(K);else{const $=U.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();$.length===6?y($):$.length===3&&y($.split("").map(ne=>ne+ne).join(""))}},className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm"}),f&&i.jsx("button",{onClick:()=>{y(""),x("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),f&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:f})})]})]})]}),i.jsxs("div",{className:"flex justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>he.mutate(),disabled:he.isPending||me.isPending,className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:he.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.resetting")]}):i.jsxs(i.Fragment,{children:[i.jsx(bo,{className:"w-4 h-4"}),c("configureAmsSlot.resetSlot")]})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Oe,{variant:"secondary",onClick:e,children:c("configureAmsSlot.cancel")}),i.jsx(Oe,{onClick:()=>me.mutate(),disabled:!Z,children:me.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.configuring")]}):i.jsxs(i.Fragment,{children:[i.jsx(jd,{className:"w-4 h-4"}),c("configureAmsSlot.configureSlot")]})})]})]}),(me.isError||he.isError)&&i.jsx("div",{className:"mx-4 mb-4 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:me.error?.message||he.error?.message})]})]})}function Qre({folderId:t,onClose:e,onUploadComplete:n,onFileUploaded:r,autoUpload:a,validateFile:s,accept:o}){const{t:l}=Ft(),[c,u]=w.useState([]),[d,m]=w.useState(!1),[p,f]=w.useState(!1),[y,v]=w.useState(!0),[x,g]=w.useState(!1),[_,N]=w.useState(!0),[T,C]=w.useState(null),A=w.useRef(null),k=ge=>{ge.preventDefault(),m(!0)},R=ge=>{ge.preventDefault(),m(!1)},P=ge=>{ge.preventDefault(),m(!1),G(Array.from(ge.dataTransfer.files))},D=ge=>{ge.target.files&&G(Array.from(ge.target.files))},H=(ge,Y)=>{u(oe=>oe.map(le=>le.file===ge?{...le,...Y}:le))},z=async ge=>{f(!0);for(const Y of ge)if(Y.status==="pending"){H(Y.file,{status:"uploading"});try{if(Y.isZip){const oe=await be.extractZipFile(Y.file,t,y,x,_);H(Y.file,{status:oe.errors.length>0&&oe.extracted===0?"error":"success",extractedCount:oe.extracted,error:oe.errors.length>0?l("fileManager.zipFilesFailed","{{count}} files failed",{count:oe.errors.length}):void 0})}else{const oe=await be.uploadLibraryFile(Y.file,t,_);H(Y.file,{status:"success"});const le=r?.(oe);if(le){C(le),u([]),f(!1);return}}}catch(oe){H(Y.file,{status:"error",error:oe instanceof Error?oe.message:l("fileManager.uploadFailed","Upload failed")})}}f(!1),n(),e()},G=ge=>{if(C(null),s)for(const oe of ge){const le=s(oe);if(le){C(le);return}}const Y=ge.map(oe=>({file:oe,status:"pending",isZip:oe.name.toLowerCase().endsWith(".zip"),is3mf:oe.name.toLowerCase().endsWith(".3mf")}));u(oe=>[...oe,...Y]),a&&ge.length>0&&z(Y)},I=ge=>{u(Y=>Y.filter((oe,le)=>le!==ge))},ee=c.some(ge=>ge.isZip&&ge.status==="pending"),ie=c.some(ge=>ge.file.name.toLowerCase().endsWith(".stl")&&ge.status==="pending"),X=c.some(ge=>ge.is3mf&&ge.status==="pending"),me=c.filter(ge=>ge.status==="pending").length,he=c.length>0&&me===0&&!p;return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:l("fileManager.uploadFiles")}),i.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark rounded",children:i.jsx(Ht,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsxs("div",{onDragOver:k,onDragLeave:R,onDrop:P,onClick:()=>A.current?.click(),className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${d?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-green/50"}`,children:[i.jsx(xi,{className:`w-10 h-10 mx-auto mb-3 ${d?"text-bambu-green":"text-bambu-gray"}`}),i.jsx("p",{className:"text-white font-medium",children:l(d?"fileManager.dropFilesHere":"fileManager.dragDropFiles")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:l("fileManager.orClickToBrowse")}),i.jsx("p",{className:"text-xs text-bambu-gray/70 mt-2",children:l("fileManager.allFileTypesSupported")})]}),i.jsx("input",{ref:A,type:"file",multiple:!0,accept:o,className:"hidden",onChange:D}),ee&&i.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(zs,{className:"w-5 h-5 text-blue-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-blue-300 font-medium",children:l("fileManager.zipFilesDetected")}),i.jsx("p",{className:"text-xs text-blue-300/70 mt-1",children:l("fileManager.zipExtractOptions")}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:y,onChange:ge=>v(ge.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.preserveZipStructure")})]}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:x,onChange:ge=>g(ge.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.createFolderFromZip")})]})]})]})}),X&&i.jsx("div",{className:"p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Sr,{className:"w-5 h-5 text-purple-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-purple-300 font-medium",children:l("fileManager.threemfDetected")}),i.jsx("p",{className:"text-xs text-purple-300/70 mt-1",children:l("fileManager.threemfExtractionInfo")})]})]})}),(ie||ee)&&i.jsx("div",{className:"p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Ed,{className:"w-5 h-5 text-bambu-green mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-bambu-green font-medium",children:l("fileManager.stlThumbnailGeneration")}),i.jsx("p",{className:"text-xs text-bambu-green/70 mt-1",children:l(ee&&!ie?"fileManager.zipMayContainStl":"fileManager.thumbnailsCanBeGenerated")}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:_,onChange:ge=>N(ge.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.generateThumbnailsForStl")})]})]})]})}),c.length>0&&i.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:c.map((ge,Y)=>i.jsxs("div",{className:"flex items-center gap-3 p-2 bg-bambu-dark rounded-lg",children:[ge.isZip?i.jsx(zs,{className:"w-4 h-4 text-blue-400 flex-shrink-0"}):i.jsx(XC,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-sm text-white truncate",children:ge.file.name}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[(ge.file.size/1024/1024).toFixed(2)," MB",ge.isZip&&ge.status==="pending"&&i.jsxs("span",{className:"text-blue-400 ml-2",children:["• ",l("fileManager.willBeExtracted")]}),ge.extractedCount!==void 0&&i.jsxs("span",{className:"text-green-400 ml-2",children:["• ",l("fileManager.filesExtracted",{count:ge.extractedCount})]})]})]}),ge.status==="pending"&&i.jsx("button",{onClick:()=>I(Y),className:"p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(Ht,{className:"w-4 h-4 text-bambu-gray"})}),ge.status==="uploading"&&i.jsx(ht,{className:"w-4 h-4 text-bambu-green animate-spin"}),ge.status==="success"&&i.jsx(fr,{className:"w-4 h-4 text-green-500"}),ge.status==="error"&&i.jsx("span",{title:ge.error,children:i.jsx(Vi,{className:"w-4 h-4 text-red-500"})})]},Y))}),T&&i.jsx("div",{className:"p-3 bg-red-500/10 border border-red-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Vi,{className:"w-5 h-5 text-red-400 mt-0.5 flex-shrink-0"}),i.jsx("p",{className:"text-sm text-red-300",children:T})]})})]}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2",children:[i.jsx(Oe,{variant:"secondary",onClick:e,children:l("common.cancel")}),!he&&i.jsx(Oe,{onClick:()=>z(c),disabled:me===0||p,children:p?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 mr-2 animate-spin"}),l("fileManager.uploading")]}):i.jsxs(i.Fragment,{children:[i.jsx(xi,{className:"w-4 h-4 mr-2"}),l("common.upload")," ",me>0?`(${me})`:""]})})]})]})})}function mW(t){return t?`#${t.replace("#","").substring(0,6)}`:"#808080"}function Ri(t){return t?t.replace("#","").toLowerCase().substring(0,6):""}const Dqe=[["PA-CF","PA12-CF","PAHT-CF"]],Zre={};for(const t of Dqe){const e=t[0];for(const n of t)Zre[n.toUpperCase()]=e.toUpperCase()}function Yk(t){if(!t)return"";const e=t.toUpperCase();return Zre[e]??e}function qj(t,e){return Yk(t)===Yk(e)}function cu(t,e,n=40){const r=Ri(t),a=Ri(e);if(!r||!a||r.length<6||a.length<6)return!1;const s=parseInt(r.substring(0,2),16),o=parseInt(r.substring(2,4),16),l=parseInt(r.substring(4,6),16),c=parseInt(a.substring(0,2),16),u=parseInt(a.substring(2,4),16),d=parseInt(a.substring(4,6),16);return Math.abs(s-c)<=n&&Math.abs(o-u)<=n&&Math.abs(l-d)<=n}function P4(t,e,n,r){if(r)return"Ext";const a=String.fromCharCode(65+(t>=128?t-128:t));return n?`HT-${a}`:`${a}${e+1}`}function G0(t,e,n){return n?254+e:t>=128?t:t*4+e}function hW(t){if(!t)return!1;const e=Date.now()+4320*60*60*1e3;return(Jn(t)?.getTime()??0)>e}function Rqe(t,e,n){const r=Jre(e,t.nozzle_id),a=r.find(l=>!n.has(l.globalTrayId)&&qj(l.type,t.type)&&Ri(l.color)===Ri(t.color)),s=a?void 0:r.find(l=>!n.has(l.globalTrayId)&&qj(l.type,t.type)&&cu(l.color,t.color)),o=a||s?void 0:r.find(l=>!n.has(l.globalTrayId)&&qj(l.type,t.type));return a??s??o}function Jre(t,e){return t.filter(n=>e==null||n.extruderId===e)}function $w(t){const e=[],n=t?.ams_extruder_map,r=n&&Object.keys(n).length>0;t?.ams?.forEach(a=>{const s=a.tray.length===1;a.tray.forEach(o=>{if(o.tray_type){const l=mW(o.tray_color);e.push({type:o.tray_type,color:l,colorName:Td(l),amsId:a.id,trayId:o.id,isHt:s,isExternal:!1,label:P4(a.id,o.id,s,!1),globalTrayId:G0(a.id,o.id,!1),trayInfoIdx:o.tray_info_idx||"",traySubBrands:o.tray_sub_brands||"",extruderId:n?.[String(a.id)]})}})});for(const a of t?.vt_tray??[])if(a.tray_type){const s=mW(a.tray_color),o=a.id??254,l=(t?.vt_tray?.length??0)>1;e.push({type:a.tray_type,color:s,colorName:Td(s),amsId:-1,trayId:o-254,isHt:!1,isExternal:!0,label:l?o===254?"Ext-L":"Ext-R":"External",globalTrayId:o,trayInfoIdx:a.tray_info_idx||"",traySubBrands:a.tray_sub_brands||"",extruderId:r?255-o:void 0})}return e}function pW(t,e){if(!t?.filaments||t.filaments.length===0)return;const n=$w(e);if(n.length===0)return;const r=new Set,a=t.filaments.map(l=>{const c=l.tray_info_idx||"";let u=n.filter(v=>!r.has(v.globalTrayId));l.nozzle_id!=null&&(u=u.filter(v=>v.extruderId===l.nozzle_id));let d,m,p,f;if(c){const v=u.filter(x=>x.trayInfoIdx===c);v.length===1?d=v[0]:v.length>1&&(m=v.find(x=>x.type?.toUpperCase()===l.type?.toUpperCase()&&Ri(x.color)===Ri(l.color)),m||(p=v.find(x=>x.type?.toUpperCase()===l.type?.toUpperCase()&&cu(x.color,l.color))),!m&&!p&&(f=v.find(x=>x.type?.toUpperCase()===l.type?.toUpperCase())))}!d&&!m&&!p&&!f&&(m=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&Ri(v.color)===Ri(l.color)),m||(p=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&cu(v.color,l.color))),!m&&!p&&(f=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase())));const y=d||m||p||f||void 0;return y&&r.add(y.globalTrayId),{slot_id:l.slot_id,globalTrayId:y?.globalTrayId??-1}}),s=Math.max(...a.map(l=>l.slot_id||0));if(s<=0)return;const o=new Array(s).fill(-1);return a.forEach(l=>{l.slot_id&&l.slot_id>0&&(o[l.slot_id-1]=l.globalTrayId)}),o}function Fqe(t){return w.useMemo(()=>$w(t),[t])}function eie(t,e,n){const r=Fqe(e),a=w.useMemo(()=>{if(!t?.filaments||t.filaments.length===0)return[];const c=new Set(Object.values(n));return t.filaments.map(u=>{const d=u.slot_id||0;if(d>0&&n[d]!==void 0){const A=n[d],k=r.find(R=>R.globalTrayId===A);if(k){const R=k.type?.toUpperCase()===u.type?.toUpperCase(),P=Ri(k.color)===Ri(u.color)||cu(k.color,u.color);let D;return R&&P?D="match":R?D="type_only":D="mismatch",{...u,loaded:k,hasFilament:!0,typeMatch:R,colorMatch:P,status:D,isManual:!0}}}const m=u.tray_info_idx||"";let p=r.filter(A=>!c.has(A.globalTrayId));u.nozzle_id!=null&&(p=p.filter(A=>A.extruderId===u.nozzle_id));let f,y,v,x;if(m){const A=p.filter(k=>k.trayInfoIdx===m);A.length===1?f=A[0]:A.length>1&&(y=A.find(k=>k.type?.toUpperCase()===u.type?.toUpperCase()&&Ri(k.color)===Ri(u.color)),y||(v=A.find(k=>k.type?.toUpperCase()===u.type?.toUpperCase()&&cu(k.color,u.color))),!y&&!v&&(x=A.find(k=>k.type?.toUpperCase()===u.type?.toUpperCase())))}!f&&!y&&!v&&!x&&(y=p.find(A=>A.type?.toUpperCase()===u.type?.toUpperCase()&&Ri(A.color)===Ri(u.color)),y||(v=p.find(A=>A.type?.toUpperCase()===u.type?.toUpperCase()&&cu(A.color,u.color))),!y&&!v&&(x=p.find(A=>A.type?.toUpperCase()===u.type?.toUpperCase())));const g=f||y||v||x||void 0;g&&c.add(g.globalTrayId);const _=!!g,N=_,T=!!f||!!y||!!v;let C;return f||y||v?C="match":x?C="type_only":C="mismatch",{...u,loaded:g,hasFilament:_,typeMatch:N,colorMatch:T,status:C,isManual:!1}})},[t,r,n]),s=w.useMemo(()=>{if(a.length===0)return;const c=Math.max(...a.map(d=>d.slot_id||0));if(c<=0)return;const u=new Array(c).fill(-1);return a.forEach(d=>{d.slot_id&&d.slot_id>0&&(u[d.slot_id-1]=d.loaded?.globalTrayId??-1)}),u},[a]),o=a.some(c=>c.status==="mismatch"),l=a.some(c=>c.status==="type_only");return{loadedFilaments:r,filamentComparison:a,amsMapping:s,hasTypeMismatch:o,hasColorMismatch:l}}function Lqe(t,e,n){if(!t||t.length===0)return{exactMatches:0,typeOnlyMatches:0,missingTypes:0,totalSlots:0,status:"full"};let r=0,a=0,s=0;const o=new Set(Object.values(n));for(const u of t){const d=u.slot_id||0;if(d>0&&n[d]!==void 0){const x=n[d],g=e.find(_=>_.globalTrayId===x);if(g){const _=g.type?.toUpperCase()===u.type?.toUpperCase(),N=Ri(g.color)===Ri(u.color)||cu(g.color,u.color);_&&N?r++:_?a++:s++;continue}}let m=e.filter(x=>!o.has(x.globalTrayId));if(u.nozzle_id!=null){const x=m.filter(g=>g.extruderId===u.nozzle_id);x.length>0&&(m=x)}const p=m.find(x=>x.type?.toUpperCase()===u.type?.toUpperCase()&&Ri(x.color)===Ri(u.color)),f=p?void 0:m.find(x=>x.type?.toUpperCase()===u.type?.toUpperCase()&&cu(x.color,u.color)),y=p||f?void 0:m.find(x=>x.type?.toUpperCase()===u.type?.toUpperCase()),v=p??f??y;v&&o.add(v.globalTrayId),p||f?r++:y?a++:s++}const l=t.length;let c="full";return s>0?c="missing":a>0&&(c="partial"),{exactMatches:r,typeOnlyMatches:a,missingTypes:s,totalSlots:l,status:c}}function Oqe(t,e,n){if(!t?.filaments||t.filaments.length===0)return;const r=$w(e);if(r.length===0)return;const a=new Set(Object.values(n)),s=[];for(const c of t.filaments){const u=c.slot_id||0;if(u>0&&n[u]!==void 0){s.push({slot_id:u,globalTrayId:n[u]});continue}let d=r.filter(v=>!a.has(v.globalTrayId));if(c.nozzle_id!=null){const v=d.filter(x=>x.extruderId===c.nozzle_id);v.length>0&&(d=v)}const m=d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&Ri(v.color)===Ri(c.color)),p=m?void 0:d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&cu(v.color,c.color)),f=m||p?void 0:d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()),y=m??p??f;y&&a.add(y.globalTrayId),s.push({slot_id:u,globalTrayId:y?.globalTrayId??-1})}const o=Math.max(...s.map(c=>c.slot_id||0));if(o<=0)return;const l=new Array(o).fill(-1);return s.forEach(c=>{c.slot_id&&c.slot_id>0&&(l[c.slot_id-1]=c.globalTrayId)}),l}const fW={useDefault:!0,manualMappings:{},autoConfigured:!1};function Iqe(t,e,n,r,a,s){const o=Gf({queries:t.map(y=>({queryKey:["printer-status",y],queryFn:()=>be.getPrinterStatus(y),enabled:t.length>0,staleTime:5e3}))}),l=w.useMemo(()=>t.map((y,v)=>{const x=o[v],g=x?.data,N=e?.find(D=>D.id===y)?.name||`Printer ${y}`,T=$w(g),C=a[y]||fW,A=pW(n,g),k=C.useDefault?r:C.manualMappings,R=Oqe(n,g,k),P=Lqe(n?.filaments,T,k);return{printerId:y,printerName:N,status:g,isLoading:x?.isLoading??!1,loadedFilaments:T,autoMapping:A,finalMapping:R,matchStatus:P.status,exactMatches:P.exactMatches,typeOnlyMatches:P.typeOnlyMatches,missingTypes:P.missingTypes,totalSlots:P.totalSlots,config:C}}),[t,o,e,n,a,r]),c=o.some(y=>y.isLoading),u=(y,v)=>{s(x=>({...x,[y]:{...x[y]||fW,...v}}))},d=y=>{const v=l.find(_=>_.printerId===y);if(!v||!v.status||!n?.filaments)return;const x=pW(n,v.status);if(!x)return;const g={};x.forEach((_,N)=>{_!==-1&&(g[N+1]=_)}),u(y,{useDefault:!1,manualMappings:g,autoConfigured:!0})},m=()=>{for(const y of t)d(y)},p=y=>l.find(x=>x.printerId===y)?.finalMapping,f=l.every(y=>y.matchStatus!=="missing");return{printerResults:l,isLoading:c,perPrinterConfigs:a,updatePrinterConfig:u,autoConfigureAll:m,autoConfigurePrinter:d,getFinalMapping:p,allPrintersReady:f}}const tie={USD:"$",EUR:"€",GBP:"£",CHF:"Fr.",JPY:"¥",CNY:"¥",CAD:"$",AUD:"$",INR:"₹",HKD:"HK$",KRW:"₩",SEK:"kr",NOK:"kr",DKK:"kr",PLN:"zł",BRL:"R$",TWD:"NT$",SGD:"S$",NZD:"NZ$",MXN:"MX$",MYR:"RM",CZK:"Kč",THB:"฿",ZAR:"R",TRY:"₺",RUB:"₽",HUF:"Ft",ILS:"₪"};function _l(t){return tie[t.toUpperCase()]||t}const zqe=Object.entries(tie).map(([t,e])=>({code:t,label:`${t} (${e})`}));function Uqe({printerId:t,filamentReqs:e,manualMappings:n,onManualMappingChange:r,currencySymbol:a,defaultCostPerKg:s,defaultExpanded:o=!1}){const{t:l}=Ft(),c=an(),[u,d]=w.useState(!1),[m,p]=w.useState(o),{data:f}=et({queryKey:["printer-status",t],queryFn:()=>be.getPrinterStatus(t),enabled:!!t}),{data:y}=et({queryKey:["spool-assignments",t],queryFn:()=>be.getAssignments(t),enabled:!!t}),{loadedFilaments:v,filamentComparison:x,hasTypeMismatch:g,hasColorMismatch:_}=eie(e,f,n),N=w.useMemo(()=>{const z=new Map;for(const G of y||[]){const I=G.ams_id===255,ee=G0(G.ams_id,G.tray_id,I);z.set(ee,G.spool?.cost_per_kg??null)}return z},[y]),T=w.useMemo(()=>{const z=new Map;for(const G of y||[]){const I=G.ams_id===255,ee=G0(G.ams_id,G.tray_id,I),ie=G.spool;if(!ie){z.set(ee,null);continue}z.set(ee,Math.max(0,Math.round((ie.label_weight??0)-(ie.weight_used??0))))}return z},[y]),C=w.useMemo(()=>{let z=0;for(const G of x){const I=G.loaded?.globalTrayId;if(I==null)continue;const ie=N.get(I)??null??s;ie>0&&(z+=G.used_grams/1e3*ie)}return z},[x,N,s]),A=w.useMemo(()=>Array.from(N.values()).some(z=>z!=null&&z>0),[N]),k=e?.filaments&&e.filaments.length>0,R=e?.filaments?.some(z=>z.nozzle_id!=null)??!1;if(!k||!f)return null;const P=g?"#f97316":_?"#facc15":"#00ae42",D=(z,G)=>{if(z>0)if(G===""){const I={...n};delete I[z],r(I)}else r({...n,[z]:parseInt(G,10)})},H=async()=>{d(!0);try{await be.refreshPrinterStatus(t),await new Promise(z=>setTimeout(z,500)),await c.refetchQueries({queryKey:["printer-status",t]})}finally{d(!1)}};return i.jsxs("div",{className:"mb-4",children:[i.jsxs("button",{type:"button",onClick:()=>p(!m),className:"flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full",children:[i.jsx(AN,{className:"w-4 h-4",fill:P,stroke:"none"}),i.jsx("span",{children:l("printModal.filamentMapping")}),g?i.jsx("span",{className:"text-xs text-orange-400",children:"(Type not found)"}):_?i.jsx("span",{className:"text-xs text-yellow-400",children:"(Color mismatch)"}):i.jsx("span",{className:"text-xs text-bambu-green",children:"(Ready)"}),m?i.jsx(Il,{className:"w-4 h-4 ml-auto"}):i.jsx(Ln,{className:"w-4 h-4 ml-auto"})]}),m&&i.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:"Click to change slot assignment"}),i.jsxs("button",{type:"button",onClick:H,className:"flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white",disabled:u,children:[i.jsx(wr,{className:`w-3 h-3 ${u?"animate-spin":""}`}),i.jsx("span",{children:"Re-read"})]})]}),x.map((z,G)=>i.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 16px"},children:[i.jsx("span",{title:`Required: ${z.type} - ${Td(z.color)}`,children:i.jsx(AN,{className:"w-3 h-3",fill:z.color,stroke:z.color})}),i.jsxs("span",{className:"text-white truncate flex items-center gap-1",children:[R&&z.nozzle_id!=null&&i.jsx("span",{className:"inline-flex items-center justify-center w-3.5 h-3.5 rounded text-[9px] font-bold leading-none bg-bambu-gray/20 text-bambu-gray shrink-0",title:z.nozzle_id===1?l("printModal.leftNozzleTooltip"):l("printModal.rightNozzleTooltip"),children:z.nozzle_id===1?l("printModal.leftNozzle"):l("printModal.rightNozzle")}),z.type," ",i.jsxs("span",{className:"text-bambu-gray",children:["(",z.used_grams,"g)"]})]}),i.jsx("span",{className:"text-bambu-gray",children:"→"}),i.jsxs("select",{value:z.loaded?.globalTrayId??"",onChange:I=>D(z.slot_id||0,I.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${z.status==="match"?"border-bambu-green/50 text-bambu-green":z.status==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${z.isManual?"ring-1 ring-blue-400/50":""}`,title:z.isManual?"Manually selected":"Auto-matched",children:[i.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),v.filter(I=>z.nozzle_id==null||I.extruderId===z.nozzle_id).map(I=>{const ee=T.get(I.globalTrayId),ie=ee!=null?l("printModal.slotRemainingShort",{grams:ee,defaultValue:` - ${ee}g left`}):"";return i.jsxs("option",{value:I.globalTrayId,className:"bg-bambu-dark text-white",children:[I.label,": ",I.traySubBrands||I.type," (",I.colorName,")",ie]},I.globalTrayId)})]}),z.status==="match"?i.jsx(Yr,{className:"w-3 h-3 text-bambu-green"}):z.status==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(Mn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(Mn,{className:"w-3 h-3 text-orange-400"})})]},G)),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[l("printModal.totalCost")," ",i.jsx("span",{className:"text-white",children:C>0||A?`${a}${C.toFixed(2)}`:"N/A"})]}),g&&i.jsx("p",{className:"text-xs text-orange-400 mt-2",children:"Required filament type not found in printer."})]})]})}function Bqe({filamentReqs:t,availableFilaments:e,overrides:n,onChange:r,forceColorMatch:a,onForceColorMatchChange:s}){const{t:o}=Ft(),l=w.useMemo(()=>{const d={};for(const m of e){const p=Yk(m.type);d[p]||(d[p]=[]),d[p].push(m)}return d},[e]),c=t?.filaments;if(!c||c.length===0||e.length===0)return null;const u=(d,m)=>{if(m===""){const p={...n};delete p[d],r(p)}else{const[p,f]=m.split("|");r({...n,[d]:{type:p,color:f}})}};return i.jsxs("div",{className:"mb-4",children:[i.jsx("div",{className:"flex items-center gap-2 text-sm text-bambu-gray mb-2",children:i.jsx("span",{children:o("printModal.filamentOverride")})}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:o("printModal.filamentOverrideHint")}),i.jsx("div",{className:"bg-bambu-dark rounded-lg p-3 space-y-2",children:c.map(d=>{const m=n[d.slot_id],p=!!m,f=l[Yk(d.type)]||[],y=d.nozzle_id!=null?f.filter(v=>v.extruder_id==null||v.extruder_id===d.nozzle_id):f;return i.jsxs("div",{className:"space-y-1",children:[i.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 20px"},children:[i.jsx("span",{title:`${o("printModal.originalFilament")}: ${d.type} - ${Td(d.color)}`,children:i.jsx(AN,{className:"w-3 h-3",fill:d.color,stroke:d.color})}),i.jsxs("span",{className:"text-white truncate",children:[d.type," ",i.jsxs("span",{className:"text-bambu-gray",children:["(",d.used_grams,"g)"]})]}),i.jsx("span",{className:"text-bambu-gray",children:"→"}),i.jsxs("select",{value:p?`${m.type}|${m.color}`:"",onChange:v=>u(d.slot_id,v.target.value),disabled:y.length===0,className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${p?"border-blue-400/50 text-blue-400":"border-bambu-gray/30 text-bambu-gray"}`,children:[i.jsxs("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:[o("printModal.originalFilament"),": ",d.type," (",Td(d.color),")"]}),y.map((v,x)=>i.jsxs("option",{value:`${v.type}|${v.color}`,className:"bg-bambu-dark text-white",children:[v.tray_sub_brands||v.type," (",Td(v.color),")"]},`${v.type}-${v.color}-${v.tray_sub_brands}-${x}`))]}),p?i.jsx("button",{type:"button",onClick:()=>u(d.slot_id,""),className:"text-bambu-gray hover:text-white transition-colors",title:o("printModal.resetToOriginal"),children:i.jsx(bo,{className:"w-3 h-3"})}):i.jsx("span",{className:"w-3"})]}),i.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-bambu-gray cursor-pointer select-none pl-5",children:[i.jsx("input",{type:"checkbox",checked:a?.[d.slot_id]??!1,onChange:v=>s?.(d.slot_id,v.target.checked),className:"accent-bambu-green w-3 h-3"}),i.jsx(fw,{className:"w-3 h-3"}),o("printModal.forceColorMatch")]})]},d.slot_id)})})]})}function Hqe({plates:t,isMultiPlate:e,selectedPlate:n,onSelect:r,queueAll:a,onQueueAllChange:s}){const{t:o}=Ft();return!e||t.length<=1?null:i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx(Gi,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:"Select Plate to Print"}),!n&&!a&&i.jsxs("span",{className:"text-xs text-orange-400 flex items-center gap-1",children:[i.jsx(Mn,{className:"w-3 h-3"}),"Selection required"]}),s&&i.jsx("button",{type:"button",onClick:()=>s(!a),className:`ml-auto text-xs px-2 py-0.5 rounded-full border transition-colors ${a?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-gray"}`,children:o("queue.queueAllPlates",{count:t.length})})]}),i.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.map(l=>i.jsxs("button",{type:"button",onClick:()=>{a&&s&&s(!1),r(l.index)},className:`flex items-center gap-2 p-2 rounded-lg border transition-colors text-left ${a||n===l.index?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"}`,children:[l.has_thumbnail&&l.thumbnail_url!=null?i.jsx("img",{src:l.thumbnail_url,alt:`Plate ${l.index}`,className:"w-10 h-10 rounded object-cover bg-bambu-dark-tertiary"}):i.jsx("div",{className:"w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center",children:i.jsx(Gi,{className:"w-5 h-5 text-bambu-gray"})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"text-sm text-white font-medium truncate",children:l.name||`Plate ${l.index}`}),i.jsxs("p",{className:"text-xs text-bambu-gray truncate",children:[l.objects.length>0?l.objects.slice(0,3).join(", ")+(l.objects.length>3?"...":""):`${l.filaments.length} filament${l.filaments.length!==1?"s":""}`,l.print_time_seconds!=null?` • ${Rs(l.print_time_seconds)}`:""]})]}),(a||n===l.index)&&i.jsx(Yr,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]},l.index))})]})}const $qe=new Set(["IDLE","FINISH","FAILED"]);function qqe({printerResult:t,filamentReqs:e,onUpdateConfig:n}){const r=an(),[a,s]=w.useState(!1),o=(u,d)=>{if(u<=0)return;const m={...t.config.manualMappings};d===""?delete m[u]:m[u]=parseInt(d,10),n({useDefault:!1,manualMappings:m,autoConfigured:!1})},l=async()=>{s(!0);try{await be.refreshPrinterStatus(t.printerId),await new Promise(u=>setTimeout(u,500)),await r.refetchQueries({queryKey:["printer-status",t.printerId]})}finally{s(!1)}},c=e.map(u=>{const d=u.slot_id||0,m=t.config.manualMappings[d];let p,f=!1;if(m!==void 0)p=t.loadedFilaments.find(v=>v.globalTrayId===m),f=!0;else{const v=new Set(Object.values(t.config.manualMappings));p=Rqe(u,t.loadedFilaments,v)}let y="mismatch";if(p){const v=p.type?.toUpperCase()===u.type?.toUpperCase(),x=Ri(p.color)===Ri(u.color)||cu(p.color,u.color);v&&x?y="match":v&&(y="type_only")}return{req:u,loaded:p,status:y,isManual:f}});return i.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom slot mapping"}),i.jsxs("button",{type:"button",onClick:l,className:"flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white",disabled:a,children:[i.jsx(wr,{className:`w-3 h-3 ${a?"animate-spin":""}`}),i.jsx("span",{children:"Re-read"})]})]}),c.map(({req:u,loaded:d,status:m,isManual:p},f)=>i.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 16px"},children:[i.jsx("span",{title:`Required: ${u.type} - ${Td(u.color)}`,children:i.jsx(AN,{className:"w-3 h-3",fill:u.color,stroke:u.color})}),i.jsxs("span",{className:"text-white truncate",children:[u.type," ",i.jsxs("span",{className:"text-bambu-gray",children:["(",u.used_grams,"g)"]})]}),i.jsx("span",{className:"text-bambu-gray",children:"→"}),i.jsxs("select",{value:d?.globalTrayId??"",onChange:y=>o(u.slot_id||0,y.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${m==="match"?"border-bambu-green/50 text-bambu-green":m==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${p?"ring-1 ring-blue-400/50":""}`,title:p?"Manually selected":"Auto-matched",children:[i.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),Jre(t.loadedFilaments,u.nozzle_id).map(y=>i.jsxs("option",{value:y.globalTrayId,className:"bg-bambu-dark text-white",children:[y.label,": ",y.traySubBrands||y.type," (",y.colorName,")"]},y.globalTrayId))]}),m==="match"?i.jsx(Yr,{className:"w-3 h-3 text-bambu-green"}):m==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(Mn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(Mn,{className:"w-3 h-3 text-orange-400"})})]},f))]})}function Vqe({printers:t,selectedPrinterIds:e,onMultiSelect:n,isLoading:r=!1,allowMultiple:a=!1,showInactive:s=!1,disableBusy:o=!1,printerMappingResults:l,filamentReqs:c,onAutoConfigurePrinter:u,onUpdatePrinterConfig:d,assignmentMode:m="printer",onAssignmentModeChange:p,targetModel:f,onTargetModelChange:y,targetLocation:v,onTargetLocationChange:x,slicedForModel:g}){const[_,N]=w.useState(!1),T=s?t:t.filter(oe=>oe.is_active),C=Gf({queries:T.map(oe=>({queryKey:["printerStatus",oe.id],queryFn:()=>be.getPrinterStatus(oe.id),staleTime:5e3}))}),A=w.useMemo(()=>{const oe=new Map;return T.forEach((le,xe)=>{const Pe=C[xe];Pe?.data&&oe.set(le.id,Pe.data)}),oe},[T,C]),k=oe=>{const le=A.get(oe);return le?le.connected?!$qe.has(le.state??""):!0:!1},R=oe=>{const le=A.get(oe);if(!le)return null;if(!le.connected)return"Offline";const xe=le.state;return xe?xe==="RUNNING"?le.stg_cur_name||"Printing":xe==="PREPARE"?"Preparing":xe==="PAUSE"?"Paused":xe==="IDLE"?"Idle":xe==="FINISH"?"Finished":xe==="FAILED"?"Failed":xe:null},P=w.useMemo(()=>{if(m!=="printer"||!g||_)return T;const oe=T.filter(le=>le.model===g);return oe.length>0?oe:T},[T,m,g,_]),D=T.length-P.length,H=w.useMemo(()=>{const oe=T.map(le=>le.model).filter(le=>!!le);return[...new Set(oe)].sort()},[T]),z=w.useMemo(()=>{if(!f)return[];const oe=T.filter(le=>le.model===f&&le.location).map(le=>le.location).filter(le=>!!le);return[...new Set(oe)].sort()},[T,f]),G=p&&y&&H.length>0,I=a&&e.length>1&&l&&c?.filaments&&c.filaments.length>0&&u&&d;if(r)return i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(P.length===0)return i.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm mb-4",children:[i.jsx(Li,{className:"w-4 h-4"}),"No ",s?"":"active ","printers available"]});const ee=oe=>{o&&k(oe)||(a?e.includes(oe)?n(e.filter(le=>le!==oe)):n([...e,oe]):n([oe]))},ie=()=>{const oe=o?P.filter(le=>!k(le.id)):P;n(oe.map(le=>le.id))},X=()=>{n([])},me=(oe,le,xe)=>{xe.stopPropagation(),!(!u||!d)&&(le?u(oe):d(oe,{useDefault:!0,manualMappings:{},autoConfigured:!1}))},he=oe=>e.includes(oe),ge=e.length,Y=oe=>l?.find(le=>le.printerId===oe);return i.jsxs("div",{className:"space-y-2 mb-6",children:[G&&i.jsxs("div",{className:"flex gap-2 mb-4",children:[i.jsxs("button",{type:"button",onClick:()=>{p("printer"),y(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${m==="printer"?"border-bambu-green bg-bambu-green/10 text-white":"border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray"}`,children:[i.jsx(Sr,{className:"w-4 h-4"}),i.jsx("span",{className:"text-sm",children:"Specific Printer"})]}),i.jsxs("button",{type:"button",onClick:()=>{p("model"),n([]);const oe=g&&H.includes(g)?g:H[0];y(oe)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${m==="model"?"border-bambu-green bg-bambu-green/10 text-white":"border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray"}`,children:[i.jsx(Km,{className:"w-4 h-4"}),i.jsxs("span",{className:"text-sm",children:["Any ",g||"Model"]})]})]}),m==="model"&&G&&i.jsxs("div",{className:"space-y-3 mb-4",children:[!g&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Target Model"}),i.jsxs("select",{value:f||"",onChange:oe=>{y(oe.target.value||null),x&&x(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 text-sm",children:[i.jsx("option",{value:"",children:"Select a model..."}),H.map(oe=>i.jsx("option",{value:oe,children:oe},oe))]})]}),f&&z.length>0&&x&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Location Filter (optional)"}),i.jsxs("select",{value:v||"",onChange:oe=>x(oe.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 text-sm",children:[i.jsx("option",{value:"",children:"Any location"}),z.map(oe=>i.jsx("option",{value:oe,children:oe},oe))]})]}),f&&i.jsxs("p",{className:"text-xs text-bambu-gray",children:["Scheduler will assign to first available idle ",f," printer",v?` in ${v}`:""]})]}),m==="printer"&&a&&P.length>1&&i.jsxs("div",{className:"flex items-center justify-between text-xs text-bambu-gray mb-2",children:[i.jsx("span",{children:ge===0?"Select printers":`${ge} printer${ge!==1?"s":""} selected`}),i.jsxs("div",{className:"flex gap-2",children:[ge0&&i.jsx("button",{type:"button",onClick:X,className:"text-bambu-gray hover:text-white transition-colors",children:"Clear"})]})]}),m==="printer"&&P.map(oe=>{const le=he(oe.id),xe=Y(oe.id),Pe=xe&&!xe.config.useDefault,q=k(oe.id),Z=o&&q,j=R(oe.id);return i.jsxs("div",{children:[i.jsxs("button",{type:"button",onClick:()=>ee(oe.id),disabled:Z,className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${Z?"border-bambu-dark-tertiary bg-bambu-dark opacity-50 cursor-not-allowed":le?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"} ${oe.is_active?"":"opacity-60"}`,children:[i.jsx("div",{className:`p-2 rounded-lg ${Z?"bg-bambu-dark-tertiary":le?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:i.jsx(Sr,{className:`w-5 h-5 ${Z?"text-bambu-gray/50":le?"text-bambu-green":"text-bambu-gray"}`})}),i.jsxs("div",{className:"text-left flex-1",children:[i.jsxs("p",{className:`font-medium ${Z?"text-bambu-gray":"text-white"}`,children:[oe.name,!oe.is_active&&i.jsx("span",{className:"text-bambu-gray text-xs ml-2",children:"(inactive)"})]}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[oe.model||"Unknown model"," • ",oe.ip_address]})]}),j&&i.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${q?"bg-yellow-500/20 text-yellow-400":"bg-bambu-green/20 text-bambu-green"}`,children:j}),a&&i.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${Z?"border-bambu-gray/30":le?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:le&&i.jsx(Yr,{className:"w-3 h-3 text-white"})})]}),le&&I&&xe&&i.jsxs("div",{className:"ml-4 mt-2 mb-3",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",onClick:E=>E.stopPropagation(),children:[i.jsx("input",{type:"checkbox",checked:Pe,onChange:E=>me(oe.id,E.target.checked,E),className:"w-3.5 h-3.5 rounded border-bambu-gray/30 bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green focus:ring-offset-0"}),i.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom mapping"})]}),i.jsxs("span",{className:`text-xs ml-2 ${xe.matchStatus==="full"?"text-bambu-green":xe.matchStatus==="partial"?"text-yellow-400":"text-orange-400"}`,children:["(",xe.exactMatches,"/",xe.totalSlots," matched)"]}),xe.isLoading&&i.jsx(wr,{className:"w-3 h-3 text-bambu-gray animate-spin"}),Pe&&i.jsxs("button",{type:"button",onClick:E=>{E.stopPropagation(),u(oe.id)},className:"ml-auto flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white",children:[i.jsx(Ebe,{className:"w-3 h-3"}),"Auto"]})]}),Pe&&i.jsx(qqe,{printerResult:xe,filamentReqs:c.filaments,onUpdateConfig:E=>d(oe.id,E)})]})]},oe.id)}),m==="printer"&&D>0&&!_&&i.jsxs("button",{type:"button",onClick:()=>N(!0),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2 flex items-center gap-1",children:[i.jsx(Mn,{className:"w-3 h-3 text-yellow-400"}),D," other printer",D>1?"s":""," hidden (different model) —",i.jsx("span",{className:"underline",children:"show all"})]}),m==="printer"&&_&&g&&i.jsx("button",{type:"button",onClick:()=>N(!1),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2",children:i.jsxs("span",{className:"underline",children:["Show only ",g," printers"]})}),m==="printer"&&ge===0&&i.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[i.jsx(Li,{className:"w-3 h-3"}),"Select at least one printer"]}),m==="model"&&!f&&i.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[i.jsx(Li,{className:"w-3 h-3"}),"Select a target printer model"]})]})}const Gqe=[{key:"bed_levelling",label:"Bed Levelling",desc:"Auto-level bed before print"},{key:"flow_cali",label:"Flow Calibration",desc:"Calibrate extrusion flow"},{key:"vibration_cali",label:"Vibration Calibration",desc:"Reduce ringing artifacts"},{key:"layer_inspect",label:"First Layer Inspection",desc:"AI inspection of first layer"},{key:"timelapse",label:"Timelapse",desc:"Record timelapse video"}];function Wqe({options:t,onChange:e,defaultExpanded:n=!1}){const[r,a]=w.useState(n),s=o=>{e({...t,[o]:!t[o]})};return i.jsxs("div",{className:"mb-4",children:[i.jsxs("button",{type:"button",onClick:()=>a(!r),className:"flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full",children:[i.jsx(iT,{className:"w-4 h-4"}),i.jsx("span",{children:"Print Options"}),r?i.jsx(Il,{className:"w-4 h-4 ml-auto"}):i.jsx(Ln,{className:"w-4 h-4 ml-auto"})]}),r&&i.jsx("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:Gqe.map(({key:o,label:l,desc:c})=>i.jsxs("label",{className:"flex items-center justify-between cursor-pointer group",children:[i.jsxs("div",{children:[i.jsx("span",{className:"text-sm text-white",children:l}),i.jsx("p",{className:"text-xs text-bambu-gray",children:c})]}),i.jsx("div",{className:`relative w-10 h-5 rounded-full transition-colors ${t[o]?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,onClick:()=>s(o),children:i.jsx("div",{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white transition-transform ${t[o]?"translate-x-5":"translate-x-0.5"}`})})]},o))})]})}function Kqe({options:t,onChange:e,dateFormat:n="system",timeFormat:r="system",canControlPrinter:a=!0}){const[s,o]=w.useState(""),[l,c]=w.useState(""),[u,d]=w.useState(!0),[m,p]=w.useState(!0),f=w.useRef(null),y=w.useRef(!1);w.useEffect(()=>{if(t.scheduleType!=="scheduled"){y.current=!1;return}if(!y.current){y.current=!0;let C;t.scheduledTime?(C=new Date(t.scheduledTime),isNaN(C.getTime())&&(C=new Date,C.setHours(C.getHours()+1,0,0,0))):(C=new Date,C.setHours(C.getHours()+1,0,0,0),e({...t,scheduledTime:_3(C)})),o(S3(C,n)),c(Z8(C,r)),d(!0),p(!0)}},[t.scheduleType,t.scheduledTime,n,r,e,t]);const v=C=>{e({...t,scheduleType:C})},x=(C,A)=>{const k=txe(C,n),R=nxe(A);d(!!k),p(!!R),k&&R&&(k.setHours(R.hours,R.minutes,0,0),k>new Date&&e({...t,scheduledTime:_3(k)}))},g=C=>{o(C),x(C,l)},_=C=>{c(C),x(s,C)},N=C=>{const A=C.target.value;if(A){const k=new Date(A);isNaN(k.getTime())||(o(S3(k,n)),c(Z8(k,r)),d(!0),p(!0),e({...t,scheduledTime:A}))}},T=()=>{f.current?.showPicker()};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"When to print"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="asap"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>v("asap"),children:[i.jsx(er,{className:"w-4 h-4"}),"ASAP"]}),i.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="scheduled"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>v("scheduled"),children:[i.jsx(Wr,{className:"w-4 h-4"}),"Scheduled"]}),i.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="manual"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>v("manual"),children:[i.jsx(GX,{className:"w-4 h-4"}),"Queue Only"]})]})]}),t.scheduleType==="scheduled"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Date & Time"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("div",{className:"flex-1 relative",children:[i.jsx("input",{type:"text",className:`w-full px-3 py-2 pr-10 bg-bambu-dark border rounded-lg text-white focus:outline-none ${u?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:s,onChange:C=>g(C.target.value),placeholder:Zbe(n)}),i.jsx("button",{type:"button",onClick:T,className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",title:"Open calendar",children:i.jsx(Wr,{className:"w-4 h-4"})})]}),i.jsx("div",{className:"w-32",children:i.jsx("input",{type:"text",className:`w-full px-3 py-2 bg-bambu-dark border rounded-lg text-white focus:outline-none ${m?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:l,onChange:C=>_(C.target.value),placeholder:Jbe(r)})})]}),i.jsx("input",{ref:f,type:"datetime-local",className:"sr-only",value:t.scheduledTime,onChange:N,tabIndex:-1}),(!u||!m)&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:"Please enter a valid date and time"})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"checkbox",id:"requirePrevious",checked:t.requirePreviousSuccess,onChange:C=>e({...t,requirePreviousSuccess:C.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("label",{htmlFor:"requirePrevious",className:"text-sm text-bambu-gray",children:"Only start if previous print succeeded"})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"checkbox",id:"autoOffAfter",checked:t.autoOffAfter,onChange:C=>e({...t,autoOffAfter:C.target.checked}),disabled:!a,className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green disabled:opacity-50"}),i.jsxs("label",{htmlFor:"autoOffAfter",className:`text-sm flex items-center gap-1 ${a?"text-bambu-gray":"text-bambu-gray/50"}`,children:[i.jsx(Vd,{className:"w-3.5 h-3.5"}),"Power off printer when done"]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:t.scheduleType==="asap"?"Print will start as soon as the printer is idle.":t.scheduleType==="scheduled"?"Print will start at the scheduled time if the printer is idle. If busy, it will wait until the printer becomes available.":"Print will be staged but won't start automatically. Use the Start button to release it to the queue."})]})}const bb={bed_levelling:!0,flow_cali:!1,vibration_cali:!0,layer_inspect:!1,timelapse:!1},Yqe={scheduleType:"asap",scheduledTime:"",requirePreviousSuccess:!1,autoOffAfter:!1};function uu({mode:t,archiveId:e,libraryFileId:n,archiveName:r,queueItem:a,initialSelectedPrinterIds:s,onClose:o,onSuccess:l}){const{t:c}=Ft(),u=an(),{showToast:d}=fn(),{hasPermission:m}=_r(),p=!!n&&!e,[f,y]=w.useState(()=>t==="edit-queue-item"&&a?.printer_id?[a.printer_id]:s?.length?s:[]),[v,x]=w.useState(()=>t==="edit-queue-item"&&a?a.plate_id:null),[g,_]=w.useState(!1),[N,T]=w.useState(()=>t==="edit-queue-item"&&a?{bed_levelling:a.bed_levelling??bb.bed_levelling,flow_cali:a.flow_cali??bb.flow_cali,vibration_cali:a.vibration_cali??bb.vibration_cali,layer_inspect:a.layer_inspect??bb.layer_inspect,timelapse:a.timelapse??bb.timelapse}:bb),[C,A]=w.useState(()=>{if(t==="edit-queue-item"&&a){let _t="asap";a.manual_start?_t="manual":a.scheduled_time&&!hW(a.scheduled_time)&&(_t="scheduled");let Ot="";if(a.scheduled_time&&!hW(a.scheduled_time)){const Vt=Jn(a.scheduled_time)??new Date;Ot=_3(Vt)}return{scheduleType:_t,scheduledTime:Ot,requirePreviousSuccess:a.require_previous_success,autoOffAfter:a.auto_off_after}}return Yqe}),[k,R]=w.useState(()=>{if(t==="edit-queue-item"&&a?.ams_mapping&&Array.isArray(a.ams_mapping)){const _t={};return a.ams_mapping.forEach((Ot,Vt)=>{Ot!==-1&&(_t[Vt+1]=Ot)}),_t}return{}}),[P,D]=w.useState({}),[H,z]=w.useState(()=>t==="edit-queue-item"&&a?.target_model?"model":"printer"),[G,I]=w.useState(()=>t==="edit-queue-item"&&a?.target_model?a.target_model:null),[ee,ie]=w.useState(()=>t==="edit-queue-item"&&a?.target_location?a.target_location:null),[X,me]=w.useState(()=>{if(t==="edit-queue-item"&&a?.filament_overrides){const _t={};for(const Ot of a.filament_overrides)_t[Ot.slot_id]={type:Ot.type,color:Ot.color};return _t}return{}}),[he,ge]=w.useState(()=>{if(t==="edit-queue-item"&&a?.filament_overrides){const _t={};for(const Ot of a.filament_overrides)_t[Ot.slot_id]=Ot.force_color_match===!0;return _t}return{}}),[Y]=w.useState(()=>t==="edit-queue-item"&&a?.printer_id?[a.printer_id]:[]),[oe]=w.useState(()=>t==="edit-queue-item"&&a?a.plate_id:null),[le,xe]=w.useState(!1),[Pe,q]=w.useState({current:0,total:0}),[Z,j]=w.useState(null),[E,U]=w.useState(new Set),K=f.length,$=f.length>0?f[0]:null,{data:ne}=et({queryKey:["settings"],queryFn:be.getSettings}),O=_l(ne?.currency||"USD"),V=ne?.default_filament_cost??0,{data:J,isLoading:W}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:re}=et({queryKey:["spool-assignments"],queryFn:()=>be.getAssignments(),staleTime:30*1e3,enabled:(t==="reprint"||t==="add-to-queue")&&H==="printer"||p&&t==="reprint"}),{data:ue}=et({queryKey:["archive",e],queryFn:()=>be.getArchive(e),enabled:!!e&&!p}),{data:fe}=et({queryKey:["library-file",n],queryFn:()=>be.getLibraryFile(n),enabled:p&&!!n}),ye=ue?.sliced_for_model||fe?.sliced_for_model||null,{data:ae,isError:L}=et({queryKey:["archive-plates",e],queryFn:()=>be.getArchivePlates(e),enabled:!!e&&!p,retry:!1}),{data:F}=et({queryKey:["library-file-plates",n],queryFn:()=>be.getLibraryFilePlates(n),enabled:p&&!!n}),te=p?F:ae,{data:ve,isError:pe}=et({queryKey:["archive-filaments",e,v],queryFn:()=>be.getArchiveFilamentRequirements(e,v??void 0),enabled:!!e&&!p&&(v!==null||!te?.is_multi_plate),retry:!1}),{data:de}=et({queryKey:["library-file-filaments",n,v],queryFn:()=>be.getLibraryFileFilamentRequirements(n,v??void 0),enabled:p&&!!n&&(v!==null||!te?.is_multi_plate)}),Ne=!p&&(L||pe),Se=p?de:ve,Le=w.useMemo(()=>{if(!(v===null||!te?.plates?.length))return te.plates.find(_t=>_t.index===v)?.name||void 0},[te,v]),{data:qe}=et({queryKey:["available-filaments",G,ee],queryFn:()=>be.getAvailableFilaments(G,ee??void 0),enabled:H==="model"&&!!G}),{data:Ee}=et({queryKey:["printer-status",$],queryFn:()=>be.getPrinterStatus($),enabled:!!$}),{amsMapping:Te}=eie(Se,Ee,k),Ae=Iqe(f,J,Se,k,P,D);w.useEffect(()=>{te?.plates&&te.plates.length>=1&&!v&&x(te.plates[0].index)},[te,v]),w.useEffect(()=>{if(t==="edit-queue-item")return;const _t=J?.filter(Ot=>Ot.is_active)||[];_t.length===1&&f.length===0&&y([_t[0].id])},[t,J,f.length]),w.useEffect(()=>{t==="edit-queue-item"?(JSON.stringify(f.sort())!==JSON.stringify(Y.sort())||v!==oe)&&(R({}),D({}),U(new Set)):(R({}),D({}),U(new Set))},[t,f,v,Y,oe]);const[Be,je]=w.useState(G),[Xe,ce]=w.useState(v);w.useEffect(()=>{(G!==Be||v!==Xe)&&(je(G),ce(v),(t!=="edit-queue-item"||Be!==null)&&(me({}),ge({})))},[G,v,Be,Xe,t]),w.useEffect(()=>{if(!ne?.per_printer_mapping_expanded||f.length<=1)return;const _t=f.filter(Ot=>{if(E.has(Ot))return!1;const Vt=Ae.printerResults.find(Xt=>Xt.printerId===Ot);return Vt&&Vt.status&&!Vt.isLoading});_t.length>0&&(U(Ot=>{const Vt=new Set(Ot);return _t.forEach(Xt=>Vt.add(Xt)),Vt}),_t.forEach(Ot=>{Ae.autoConfigurePrinter(Ot)}))},[ne?.per_printer_mapping_expanded,f,E,Ae]),w.useEffect(()=>{const _t=Ot=>{Ot.key==="Escape"&&!le&&o()};return window.addEventListener("keydown",_t),()=>window.removeEventListener("keydown",_t)},[o,le]);const Ie=te?.is_multi_plate??!1,Ce=te?.plates??[],Ge=w.useMemo(()=>{const _t=new Map;return re&&re.forEach(Ot=>{const Vt=Ot.ams_id===255,Xt=G0(Ot.ams_id,Ot.tray_id,Vt),Qe=_t.get(Ot.printer_id)??new Map;Qe.set(Xt,Ot),_t.set(Ot.printer_id,Qe)}),_t},[re]),$e=w.useMemo(()=>{if(!Z||Z.length===0)return"";const _t=Z.map(Ot=>c("printModal.insufficientFilamentLine",{printer:Ot.printerName,slot:Ot.slotLabel,required:Math.round(Ot.requiredGrams),remaining:Math.round(Ot.remainingGrams)}));return[c("printModal.insufficientFilamentMessage"),..._t].join(` +${o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})}`:g.type==="profile"&&(X=o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})),i.jsx(Sn,{title:o("inventory.assignMismatchTitle"),message:X,confirmText:o("inventory.assignMismatchConfirm"),variant:"warning",isLoading:k.isPending,onConfirm:ie,onCancel:()=>{k.isPending||(x(!1),y(null),_(null))}})})()]})}function oW(t,e){if(t===255)return"External";let n,r=!1;t>=128&&t<=135?(n=t-128,r=!0):t>=0&&t<=3?(n=t,r=e===1):n=0,n=Math.max(0,Math.min(n,7));const a=String.fromCharCode(65+n);return r?`HT-${a}`:`AMS-${a}`}function k1(t){const e=t.includes("_")?t.split("_")[0]:t;return e.startsWith("GFS")?"GF"+e.slice(3):(e.startsWith("PFUS")||e.startsWith("PFSP"),e)}const Wv=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","NYLON","PVA","HIPS","PP","PET"];function lW(t){const e=t.replace(/@.+$/,"").trim(),n=e.toUpperCase(),r=n.match(/\bSUPPORT\s+FOR\s+/);if(r){const s=n.slice(r.index+r[0].length);for(const o of Wv)if(new RegExp(`\\b${o}\\b`).test(s)){const c=e.slice(0,r.index).trim();return{material:o,brand:c,variant:"Support"}}}for(const s of Wv){const o=new RegExp(`\\b${s}\\b`,"i");if(o.test(n)){const l=e.split(o),c=l[0]?.trim()||"",u=l[1]?.trim()||"";return{material:s,brand:c,variant:u}}}const a=e.split(/\s+/);return a.length>=2?{material:a[1],brand:a[0],variant:a.slice(2).join(" ")}:{material:e,brand:"",variant:""}}function Mqe(t){return!t.startsWith("GF")&&!t.startsWith("P1")}const Eqe={white:"FFFFFF",black:"000000",red:"FF0000",green:"00FF00",blue:"0000FF",yellow:"FFFF00",cyan:"00FFFF",magenta:"FF00FF",orange:"FFA500",purple:"800080",pink:"FFC0CB",brown:"8B4513",gray:"808080",grey:"808080","jade white":"FFFEF2",ivory:"FFFFF0",beige:"F5F5DC",cream:"FFFDD0",silver:"C0C0C0",gold:"FFD700",bronze:"CD7F32",copper:"B87333",navy:"000080",teal:"008080",olive:"808000",maroon:"800000",coral:"FF7F50",salmon:"FA8072",lime:"32CD32",mint:"98FF98","forest green":"228B22","sky blue":"87CEEB","royal blue":"4169E1",turquoise:"40E0D0",lavender:"E6E6FA",violet:"EE82EE",plum:"DDA0DD",tan:"D2B48C",chocolate:"D2691E",charcoal:"36454F",slate:"708090",transparent:"000000",natural:"F5F5DC",wood:"DEB887"},cW=[{name:"White",hex:"FFFFFF"},{name:"Black",hex:"000000"},{name:"Red",hex:"FF0000"},{name:"Blue",hex:"0000FF"},{name:"Green",hex:"00AA00"},{name:"Yellow",hex:"FFFF00"},{name:"Orange",hex:"FFA500"},{name:"Gray",hex:"808080"}],uW=[{name:"Cyan",hex:"00FFFF"},{name:"Magenta",hex:"FF00FF"},{name:"Purple",hex:"800080"},{name:"Pink",hex:"FFC0CB"},{name:"Brown",hex:"8B4513"},{name:"Beige",hex:"F5F5DC"},{name:"Navy",hex:"000080"},{name:"Teal",hex:"008080"},{name:"Lime",hex:"32CD32"},{name:"Gold",hex:"FFD700"},{name:"Silver",hex:"C0C0C0"},{name:"Maroon",hex:"800000"},{name:"Olive",hex:"808000"},{name:"Coral",hex:"FF7F50"},{name:"Salmon",hex:"FA8072"},{name:"Turquoise",hex:"40E0D0"},{name:"Violet",hex:"EE82EE"},{name:"Indigo",hex:"4B0082"},{name:"Chocolate",hex:"D2691E"},{name:"Tan",hex:"D2B48C"},{name:"Slate",hex:"708090"},{name:"Charcoal",hex:"36454F"},{name:"Ivory",hex:"FFFFF0"},{name:"Cream",hex:"FFFDD0"}];function dW(t){const e=t.toLowerCase().trim();return Eqe[e]||null}function jqe(t){const e=t.indexOf("@");if(e<0)return null;const r=t.slice(e+1).trim().match(/^BBL\s+(.+?)(?:\s+[\d.]+\s*nozzle)?$/i);return r?r[1].trim():null}function Xre({isOpen:t,onClose:e,printerId:n,slotInfo:r,nozzleDiameter:a="0.4",printerModel:s,onSuccess:o,fullScreen:l}){const{t:c}=Ft(),[u,d]=w.useState(""),[m,p]=w.useState(null),[f,y]=w.useState(""),[v,x]=w.useState(""),[g,_]=w.useState(""),[N,T]=w.useState(!1),[C,A]=w.useState(!1),k=w.useRef(""),{data:R,isLoading:P,isError:D}=et({queryKey:["cloudSettings"],queryFn:()=>be.getCloudSettings(),enabled:t,retry:!1}),{data:H,isLoading:z}=et({queryKey:["localPresets"],queryFn:()=>be.getLocalPresets(),enabled:t}),{data:G,isLoading:I}=et({queryKey:["builtinFilaments"],queryFn:()=>be.getBuiltinFilaments(),enabled:t,staleTime:1/0}),{data:ee,isLoading:ie}=et({queryKey:["kprofiles",n,a],queryFn:()=>be.getKProfiles(n,a),enabled:t&&!!n}),{data:X}=et({queryKey:["colorCatalog"],queryFn:()=>be.getColorCatalog(),enabled:t,staleTime:1/0}),me=pt({mutationFn:async()=>{if(!u)throw new Error("No filament preset selected");const E=u.startsWith("local_"),U=u.startsWith("builtin_"),K=E?parseInt(u.replace("local_",""),10):null,$=U?u.replace("builtin_",""):null,ne=E?H?.filament.find(Le=>Le.id===K):null,O=U?G?.find(Le=>Le.filament_id===$):null,V=!E&&!U?R?.filament.find(Le=>Le.setting_id===u):null;if(!E&&!U&&!V)throw new Error("Selected preset not found");if(E&&!ne)throw new Error("Selected local preset not found");if(U&&!O)throw new Error("Selected builtin preset not found");const J=E?ne.name:U?O.name:V.name,W=lW(J),re=m?.slot_id??-1,ue=f||r.trayColor?.slice(0,6)||"FFFFFF",fe=J.replace(/@.+$/,"").trim();let ye,ae;const L=W.material.toUpperCase();if(E){const Le=(Wv.includes(L)?L:ne?.filament_type||W.material||"").toUpperCase(),qe={PLA:"GFL99","PLA-CF":"GFL98","PLA SILK":"GFL96","PLA HIGH SPEED":"GFL95",PETG:"GFG99","PETG HF":"GFG96","PETG-CF":"GFG98",PCTG:"GFG97",ABS:"GFB99",ASA:"GFB98",PC:"GFC99",PA:"GFN99","PA-CF":"GFN98",NYLON:"GFN99",TPU:"GFU99",PVA:"GFS99",HIPS:"GFS98",PE:"GFP99",PP:"GFP97"};ye=qe[Le]||qe[Le.replace(/[-\s]?CF$/,"")]||qe[Le.replace(/\+$/,"")]||qe[Le.split(/[-\s]/)[0]]||"",ae=""}else if(U)ye=$,ae="";else if(ye=k1(u),ae=u,!u.startsWith("GFS"))try{const Le=await be.getCloudSettingDetail(u);Le.filament_id?ye=Le.filament_id:Le.base_id&&(ye=k1(Le.base_id),console.log(`Derived tray_info_idx from base_id: ${Le.base_id} -> ${ye}`))}catch(Le){console.warn("Failed to fetch preset detail for filament_id:",Le)}let F=E&&ne?.nozzle_temp_min?ne.nozzle_temp_min:190,te=E&&ne?.nozzle_temp_max?ne.nozzle_temp_max:230;if(!E||U||!ne?.nozzle_temp_min&&!ne?.nozzle_temp_max){const Le=(E?Wv.includes(L)?L:ne?.filament_type||W.material||"":W.material).toUpperCase();Le.includes("PLA")?(F=190,te=230):Le.includes("PETG")?(F=220,te=260):Le.includes("ABS")||Le.includes("ASA")?(F=240,te=280):Le.includes("TPU")?(F=200,te=240):Le==="PCTG"?(F=220,te=260):Le.includes("PC")?(F=260,te=300):(Le.includes("PA")||Le.includes("NYLON"))&&(F=250,te=290)}const ve=m?.k_value?parseFloat(m.k_value):0,pe=E?Wv.includes(L)?L:ne?.filament_type||W.material||"PLA":W.material||"PLA",de=await be.configureAmsSlot(n,r.amsId,r.trayId,{tray_info_idx:ye,tray_type:pe,tray_sub_brands:fe,tray_color:ue+"FF",nozzle_temp_min:F,nozzle_temp_max:te,cali_idx:re,nozzle_diameter:a,setting_id:ae,kprofile_filament_id:m?.filament_id,kprofile_setting_id:m?.setting_id||void 0,k_value:ve}),Ne=E?`local_${K}`:U?`builtin_${$}`:u,Se=E?"local":U?"builtin":"cloud";try{await be.saveSlotPreset(n,r.amsId,r.trayId,Ne,fe,Se)}catch(Le){console.warn("Failed to save slot preset mapping:",Le)}return de},onSuccess:()=>{T(!0),o?.(),setTimeout(()=>{T(!1),e()},1500)}}),he=pt({mutationFn:async()=>be.resetAmsSlot(n,r.amsId,r.trayId),onSuccess:()=>{T(!0),o?.(),setTimeout(()=>{T(!1),e()},1500)}}),ge=w.useMemo(()=>{const E=g.toLowerCase(),U=[],K=new Set,$=r.savedPresetId,ne=r.trayInfoIdx;if(R?.filament)for(const O of R.filament){K.add(O.setting_id);const V=$===O.setting_id||ne&&(O.setting_id===ne||k1(O.setting_id)===ne);if(!(!V&&E&&!O.name.toLowerCase().includes(E))){if(!V&&s){const J=jqe(O.name);if(J&&J.toUpperCase()!==s.toUpperCase())continue}U.push({id:O.setting_id,name:O.name,source:"cloud",isUser:Mqe(O.setting_id)})}}if(H?.filament)for(const O of H.filament){const V=`local_${O.id}`;!($===V)&&E&&!O.name.toLowerCase().includes(E)||U.push({id:V,name:O.name,source:"local",isUser:!1})}if(G)for(const O of G){if(K.has(O.filament_id))continue;const V=O.filament_id.startsWith("GF")?"GFS"+O.filament_id.slice(2):O.filament_id;K.has(V)||(!E||O.name.toLowerCase().includes(E))&&U.push({id:`builtin_${O.filament_id}`,name:O.name,source:"builtin",isUser:!1})}return U.sort((O,V)=>{const J={cloud:0,local:1,builtin:2};return O.source!==V.source?J[O.source]-J[V.source]:O.isUser&&!V.isUser?-1:!O.isUser&&V.isUser?1:O.name.localeCompare(V.name)})},[R?.filament,H?.filament,G,g,s,r.savedPresetId,r.trayInfoIdx]),Y=w.useMemo(()=>{if(!u)return null;let E=null;if(u.startsWith("local_")){const $=parseInt(u.replace("local_",""),10);E=H?.filament.find(O=>O.id===$)?.name||null}else if(u.startsWith("builtin_")){const $=u.replace("builtin_","");E=G?.find(O=>O.filament_id===$)?.name||null}else R?.filament&&(E=R.filament.find(ne=>ne.setting_id===u)?.name||null);if(!E)return null;let U=E.replace(/@.+$/,"").trim();U.startsWith("# ")&&(U=U.slice(2).trim());const K=lW(U);return{fullName:U,material:K.material,brand:K.brand}},[u,R?.filament,H?.filament,G]),oe=Y?.fullName||"",le=w.useMemo(()=>{if(!X||!Y)return[];const{fullName:E,brand:U}=Y,K=E.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,"").trim();return X.filter($=>{const ne=($.material||"").toUpperCase(),O=$.manufacturer.toUpperCase();if(!(ne===K.toUpperCase()||ne.includes(K.toUpperCase())||K.toUpperCase().includes(ne)))return!1;if(U){const J=U.toUpperCase();if(!O.includes(J)&&!J.includes(O))return!1}return!0})},[X,Y]),xe=w.useMemo(()=>{if(!ee?.profiles||!Y)return[];const{fullName:E,material:U,brand:K}=Y,$=E.toUpperCase(),ne=U.toUpperCase(),O=K.toUpperCase();if(!ne||ne.length<2)return[];const V=ee.profiles.filter(W=>{const re=W.name.toUpperCase();if(O)return!(!re.includes(O)||!re.includes(ne));if(re.includes($)||re.includes(ne))return!0;const fe={NYLON:["PA","PA-CF","PA6"],PA:["NYLON"]}[ne]||[];for(const ye of fe)if(re.includes(ye))return!0;return!1}),J=new Map;for(const W of V){const re=`${W.name}|${W.k_value}`,ue=J.get(re);ue?r.extruderId!==void 0&&W.extruder_id===r.extruderId&&ue.extruder_id!==r.extruderId&&J.set(re,W):J.set(re,W)}return Array.from(J.values())},[ee?.profiles,Y,r.extruderId]);w.useEffect(()=>{if(t){if(r.savedPresetId)d(r.savedPresetId);else if(r.trayInfoIdx&&R?.filament){let E=R.filament.find(U=>U.setting_id===r.trayInfoIdx);E||(E=R.filament.find(U=>k1(U.setting_id)===r.trayInfoIdx)),E&&d(E.setting_id)}else if(r.trayInfoIdx&&G?.length){const E=r.trayInfoIdx,U=G.find(K=>K.filament_id===E);U&&d(`builtin_${U.filament_id}`)}if(r.trayColor){const E=r.trayColor.slice(0,6);E&&y(E)}}else d(""),p(null),y(""),x(""),_(""),T(!1),k.current=""},[t,r.savedPresetId,r.trayInfoIdx,r.trayColor,R?.filament,G]),w.useEffect(()=>{if(xe.length>0){if(r.caliIdx!=null&&r.caliIdx>0){const E=xe.find(U=>U.slot_id===r.caliIdx);if(E){p(E);return}}p(xe[0])}else p(null)},[u,xe,r.caliIdx]);const Pe=w.useCallback(E=>{E.key==="Escape"&&e()},[e]);w.useEffect(()=>{if(t)return document.addEventListener("keydown",Pe),()=>document.removeEventListener("keydown",Pe)},[t,Pe]);const q=P&&!D||z||I||ie;if(w.useEffect(()=>{if(!q&&u&&u!==k.current){const E=requestAnimationFrame(()=>{const K=document.querySelector('[class*="fixed inset-0 z-50"]')?.querySelector(`[data-preset-id="${CSS.escape(u)}"]`);K&&(k.current=u,K.scrollIntoView({block:"nearest"}))});return()=>cancelAnimationFrame(E)}},[u,q]),!t)return null;const Z=u&&!me.isPending,j=f||r.trayColor?.slice(0,6)||"FFFFFF";return i.jsxs("div",{className:`fixed inset-0 z-50 flex ${l?"":"items-center justify-center"}`,children:[!l&&i.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),i.jsxs("div",{className:l?"relative w-full h-full bg-bambu-dark-secondary flex flex-col":"relative w-full max-w-lg mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(jd,{className:"w-5 h-5 text-bambu-blue"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.title")}),l&&i.jsxs("div",{className:"flex items-center gap-2 ml-4 text-sm text-bambu-gray",children:[i.jsx("span",{className:"text-white/30",children:"|"}),r.trayColor&&i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),i.jsx("span",{className:"text-white/70",children:c("configureAmsSlot.slotLabel",{ams:oW(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&i.jsxs("span",{children:["(",r.traySubBrands,")"]})]})]}),i.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:`p-4 overflow-y-auto ${l?"flex-1 min-h-0":"space-y-4 max-h-[60vh]"}`,children:[N&&i.jsx("div",{className:"absolute inset-0 bg-bambu-dark-secondary/95 z-10 flex items-center justify-center rounded-xl",children:i.jsxs("div",{className:"text-center space-y-3",children:[i.jsx(Jc,{className:"w-16 h-16 text-bambu-green mx-auto"}),i.jsx("p",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.slotConfigured")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:c("configureAmsSlot.settingsSentToPrinter")})]})}),!l&&i.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:c("configureAmsSlot.configuringSlot")}),i.jsxs("div",{className:"flex items-center gap-2",children:[r.trayColor&&i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),i.jsx("span",{className:"text-white font-medium",children:c("configureAmsSlot.slotLabel",{ams:oW(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&i.jsxs("span",{className:"text-bambu-gray",children:["(",r.traySubBrands,")"]})]})]}),q?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})}):l?i.jsxs("div",{className:"flex gap-4 h-full",children:[i.jsxs("div",{className:"w-1/2 flex flex-col min-h-0",children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:g,onChange:E=>_(E.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2 shrink-0"}),i.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-1",children:ge.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:R?.filament?.length===0&&!H?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):ge.map(E=>i.jsx("button",{"data-preset-id":E.id,onClick:()=>d(E.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${u===E.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-white text-sm truncate",children:E.name}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[E.source==="local"&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:c("profiles.localProfiles.badge")}),E.source==="builtin"&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:c("configureAmsSlot.builtin")}),E.isUser&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:c("configureAmsSlot.custom")})]})]})},E.id))})]}),i.jsxs("div",{className:"w-1/2 flex flex-col gap-4 min-h-0 overflow-y-auto",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),oe&&i.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:oe})})]}),xe.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:E=>{const U=xe.find(K=>K.name===E.target.value);p(U||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 appearance-none pr-10",children:[i.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),xe.map(E=>i.jsxs("option",{value:E.name,children:[E.name," (K=",E.k_value,")"]},`${E.name}-${E.extruder_id}`))]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):u?i.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:c("configureAmsSlot.noMatchingKProfiles")}):i.jsx("span",{className:"inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30",children:c("configureAmsSlot.selectFilamentFirst")}),m&&i.jsx("p",{className:"text-xs text-bambu-green mt-1",children:c("configureAmsSlot.kFromCalibration",{value:m.k_value})})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:c("configureAmsSlot.customColorLabel")}),le.length>0&&i.jsxs("div",{className:"mb-3",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:c("configureAmsSlot.presetColors",{name:Y?.fullName})}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:le.map(E=>i.jsxs("button",{onClick:()=>{const U=E.hex_color.replace("#","").toUpperCase();y(U),x(E.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===E.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:E.color_name,children:[i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:E.hex_color}}),i.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:E.color_name})]},E.id))})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[cW.map(E=>i.jsx("button",{onClick:()=>{y(E.hex),x(E.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===E.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${E.hex}`},title:E.name},E.hex)),i.jsx("button",{onClick:()=>A(!C),className:"w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs",title:c(C?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:C?"−":"+"})]}),C&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:uW.map(E=>i.jsx("button",{onClick:()=>{y(E.hex),x(E.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===E.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${E.hex}`},title:E.name},E.hex))}),i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${j}`}}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:E=>{const U=E.target.value;x(U);const K=dW(U);if(K)y(K);else{const $=U.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();$.length===6?y($):$.length===3&&y($.split("").map(ne=>ne+ne).join(""))}},className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm"}),f&&i.jsx("button",{onClick:()=>{y(""),x("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),f&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:f})})]})]})]}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:g,onChange:E=>_(E.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2"}),i.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:ge.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:R?.filament?.length===0&&!H?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):ge.map(E=>i.jsx("button",{"data-preset-id":E.id,onClick:()=>d(E.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${u===E.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-white text-sm truncate",children:E.name}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[E.source==="local"&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:c("profiles.localProfiles.badge")}),E.source==="builtin"&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:c("configureAmsSlot.builtin")}),E.isUser&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:c("configureAmsSlot.custom")})]})]})},E.id))})]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),oe&&i.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:oe})})]}),xe.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:E=>{const U=xe.find(K=>K.name===E.target.value);p(U||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 appearance-none pr-10",children:[i.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),xe.map(E=>i.jsxs("option",{value:E.name,children:[E.name," (K=",E.k_value,")"]},`${E.name}-${E.extruder_id}`))]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):u?i.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:c("configureAmsSlot.noMatchingKProfiles")}):i.jsx("span",{className:"inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30",children:c("configureAmsSlot.selectFilamentFirst")}),m&&i.jsx("p",{className:"text-xs text-bambu-green mt-1",children:c("configureAmsSlot.kFromCalibration",{value:m.k_value})})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:c("configureAmsSlot.customColorLabel")}),le.length>0&&i.jsxs("div",{className:"mb-3",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:c("configureAmsSlot.presetColors",{name:Y?.fullName})}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:le.map(E=>i.jsxs("button",{onClick:()=>{const U=E.hex_color.replace("#","").toUpperCase();y(U),x(E.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===E.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:E.color_name,children:[i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:E.hex_color}}),i.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:E.color_name})]},E.id))})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[cW.map(E=>i.jsx("button",{onClick:()=>{y(E.hex),x(E.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===E.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${E.hex}`},title:E.name},E.hex)),i.jsx("button",{onClick:()=>A(!C),className:"w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs",title:c(C?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:C?"−":"+"})]}),C&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:uW.map(E=>i.jsx("button",{onClick:()=>{y(E.hex),x(E.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===E.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${E.hex}`},title:E.name},E.hex))}),i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${j}`}}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:E=>{const U=E.target.value;x(U);const K=dW(U);if(K)y(K);else{const $=U.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();$.length===6?y($):$.length===3&&y($.split("").map(ne=>ne+ne).join(""))}},className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm"}),f&&i.jsx("button",{onClick:()=>{y(""),x("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),f&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:f})})]})]})]}),i.jsxs("div",{className:"flex justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>he.mutate(),disabled:he.isPending||me.isPending,className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:he.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.resetting")]}):i.jsxs(i.Fragment,{children:[i.jsx(bo,{className:"w-4 h-4"}),c("configureAmsSlot.resetSlot")]})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Oe,{variant:"secondary",onClick:e,children:c("configureAmsSlot.cancel")}),i.jsx(Oe,{onClick:()=>me.mutate(),disabled:!Z,children:me.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.configuring")]}):i.jsxs(i.Fragment,{children:[i.jsx(jd,{className:"w-4 h-4"}),c("configureAmsSlot.configureSlot")]})})]})]}),(me.isError||he.isError)&&i.jsx("div",{className:"mx-4 mb-4 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:me.error?.message||he.error?.message})]})]})}function Qre({folderId:t,onClose:e,onUploadComplete:n,onFileUploaded:r,autoUpload:a,validateFile:s,accept:o}){const{t:l}=Ft(),[c,u]=w.useState([]),[d,m]=w.useState(!1),[p,f]=w.useState(!1),[y,v]=w.useState(!0),[x,g]=w.useState(!1),[_,N]=w.useState(!0),[T,C]=w.useState(null),A=w.useRef(null),k=ge=>{ge.preventDefault(),m(!0)},R=ge=>{ge.preventDefault(),m(!1)},P=ge=>{ge.preventDefault(),m(!1),G(Array.from(ge.dataTransfer.files))},D=ge=>{ge.target.files&&G(Array.from(ge.target.files))},H=(ge,Y)=>{u(oe=>oe.map(le=>le.file===ge?{...le,...Y}:le))},z=async ge=>{f(!0);for(const Y of ge)if(Y.status==="pending"){H(Y.file,{status:"uploading"});try{if(Y.isZip){const oe=await be.extractZipFile(Y.file,t,y,x,_);H(Y.file,{status:oe.errors.length>0&&oe.extracted===0?"error":"success",extractedCount:oe.extracted,error:oe.errors.length>0?l("fileManager.zipFilesFailed","{{count}} files failed",{count:oe.errors.length}):void 0})}else{const oe=await be.uploadLibraryFile(Y.file,t,_);H(Y.file,{status:"success"});const le=r?.(oe);if(le){C(le),u([]),f(!1);return}}}catch(oe){H(Y.file,{status:"error",error:oe instanceof Error?oe.message:l("fileManager.uploadFailed","Upload failed")})}}f(!1),n(),e()},G=ge=>{if(C(null),s)for(const oe of ge){const le=s(oe);if(le){C(le);return}}const Y=ge.map(oe=>({file:oe,status:"pending",isZip:oe.name.toLowerCase().endsWith(".zip"),is3mf:oe.name.toLowerCase().endsWith(".3mf")}));u(oe=>[...oe,...Y]),a&&ge.length>0&&z(Y)},I=ge=>{u(Y=>Y.filter((oe,le)=>le!==ge))},ee=c.some(ge=>ge.isZip&&ge.status==="pending"),ie=c.some(ge=>ge.file.name.toLowerCase().endsWith(".stl")&&ge.status==="pending"),X=c.some(ge=>ge.is3mf&&ge.status==="pending"),me=c.filter(ge=>ge.status==="pending").length,he=c.length>0&&me===0&&!p;return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:l("fileManager.uploadFiles")}),i.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark rounded",children:i.jsx(Ht,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsxs("div",{onDragOver:k,onDragLeave:R,onDrop:P,onClick:()=>A.current?.click(),className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${d?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-green/50"}`,children:[i.jsx(xi,{className:`w-10 h-10 mx-auto mb-3 ${d?"text-bambu-green":"text-bambu-gray"}`}),i.jsx("p",{className:"text-white font-medium",children:l(d?"fileManager.dropFilesHere":"fileManager.dragDropFiles")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:l("fileManager.orClickToBrowse")}),i.jsx("p",{className:"text-xs text-bambu-gray/70 mt-2",children:l("fileManager.allFileTypesSupported")})]}),i.jsx("input",{ref:A,type:"file",multiple:!0,accept:o,className:"hidden",onChange:D}),ee&&i.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(zs,{className:"w-5 h-5 text-blue-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-blue-300 font-medium",children:l("fileManager.zipFilesDetected")}),i.jsx("p",{className:"text-xs text-blue-300/70 mt-1",children:l("fileManager.zipExtractOptions")}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:y,onChange:ge=>v(ge.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.preserveZipStructure")})]}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:x,onChange:ge=>g(ge.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.createFolderFromZip")})]})]})]})}),X&&i.jsx("div",{className:"p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Sr,{className:"w-5 h-5 text-purple-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-purple-300 font-medium",children:l("fileManager.threemfDetected")}),i.jsx("p",{className:"text-xs text-purple-300/70 mt-1",children:l("fileManager.threemfExtractionInfo")})]})]})}),(ie||ee)&&i.jsx("div",{className:"p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Ed,{className:"w-5 h-5 text-bambu-green mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-bambu-green font-medium",children:l("fileManager.stlThumbnailGeneration")}),i.jsx("p",{className:"text-xs text-bambu-green/70 mt-1",children:l(ee&&!ie?"fileManager.zipMayContainStl":"fileManager.thumbnailsCanBeGenerated")}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:_,onChange:ge=>N(ge.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.generateThumbnailsForStl")})]})]})]})}),c.length>0&&i.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:c.map((ge,Y)=>i.jsxs("div",{className:"flex items-center gap-3 p-2 bg-bambu-dark rounded-lg",children:[ge.isZip?i.jsx(zs,{className:"w-4 h-4 text-blue-400 flex-shrink-0"}):i.jsx(XC,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-sm text-white truncate",children:ge.file.name}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[(ge.file.size/1024/1024).toFixed(2)," MB",ge.isZip&&ge.status==="pending"&&i.jsxs("span",{className:"text-blue-400 ml-2",children:["• ",l("fileManager.willBeExtracted")]}),ge.extractedCount!==void 0&&i.jsxs("span",{className:"text-green-400 ml-2",children:["• ",l("fileManager.filesExtracted",{count:ge.extractedCount})]})]})]}),ge.status==="pending"&&i.jsx("button",{onClick:()=>I(Y),className:"p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(Ht,{className:"w-4 h-4 text-bambu-gray"})}),ge.status==="uploading"&&i.jsx(ht,{className:"w-4 h-4 text-bambu-green animate-spin"}),ge.status==="success"&&i.jsx(fr,{className:"w-4 h-4 text-green-500"}),ge.status==="error"&&i.jsx("span",{title:ge.error,children:i.jsx(Vi,{className:"w-4 h-4 text-red-500"})})]},Y))}),T&&i.jsx("div",{className:"p-3 bg-red-500/10 border border-red-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Vi,{className:"w-5 h-5 text-red-400 mt-0.5 flex-shrink-0"}),i.jsx("p",{className:"text-sm text-red-300",children:T})]})})]}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2",children:[i.jsx(Oe,{variant:"secondary",onClick:e,children:l("common.cancel")}),!he&&i.jsx(Oe,{onClick:()=>z(c),disabled:me===0||p,children:p?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 mr-2 animate-spin"}),l("fileManager.uploading")]}):i.jsxs(i.Fragment,{children:[i.jsx(xi,{className:"w-4 h-4 mr-2"}),l("common.upload")," ",me>0?`(${me})`:""]})})]})]})})}function mW(t){return t?`#${t.replace("#","").substring(0,6)}`:"#808080"}function Ri(t){return t?t.replace("#","").toLowerCase().substring(0,6):""}const Dqe=[["PA-CF","PA12-CF","PAHT-CF"]],Zre={};for(const t of Dqe){const e=t[0];for(const n of t)Zre[n.toUpperCase()]=e.toUpperCase()}function Yk(t){if(!t)return"";const e=t.toUpperCase();return Zre[e]??e}function qj(t,e){return Yk(t)===Yk(e)}function cu(t,e,n=40){const r=Ri(t),a=Ri(e);if(!r||!a||r.length<6||a.length<6)return!1;const s=parseInt(r.substring(0,2),16),o=parseInt(r.substring(2,4),16),l=parseInt(r.substring(4,6),16),c=parseInt(a.substring(0,2),16),u=parseInt(a.substring(2,4),16),d=parseInt(a.substring(4,6),16);return Math.abs(s-c)<=n&&Math.abs(o-u)<=n&&Math.abs(l-d)<=n}function P4(t,e,n,r){if(r)return"Ext";const a=String.fromCharCode(65+(t>=128?t-128:t));return n?`HT-${a}`:`${a}${e+1}`}function G0(t,e,n){return n?254+e:t>=128?t:t*4+e}function hW(t){if(!t)return!1;const e=Date.now()+4320*60*60*1e3;return(Jn(t)?.getTime()??0)>e}function Rqe(t,e,n){const r=Jre(e,t.nozzle_id),a=r.find(l=>!n.has(l.globalTrayId)&&qj(l.type,t.type)&&Ri(l.color)===Ri(t.color)),s=a?void 0:r.find(l=>!n.has(l.globalTrayId)&&qj(l.type,t.type)&&cu(l.color,t.color)),o=a||s?void 0:r.find(l=>!n.has(l.globalTrayId)&&qj(l.type,t.type));return a??s??o}function Jre(t,e){return t.filter(n=>e==null||n.extruderId===e)}function $w(t){const e=[],n=t?.ams_extruder_map,r=n&&Object.keys(n).length>0;t?.ams?.forEach(a=>{const s=a.tray.length===1;a.tray.forEach(o=>{if(o.tray_type){const l=mW(o.tray_color);e.push({type:o.tray_type,color:l,colorName:Td(l),amsId:a.id,trayId:o.id,isHt:s,isExternal:!1,label:P4(a.id,o.id,s,!1),globalTrayId:G0(a.id,o.id,!1),trayInfoIdx:o.tray_info_idx||"",traySubBrands:o.tray_sub_brands||"",extruderId:n?.[String(a.id)]})}})});for(const a of t?.vt_tray??[])if(a.tray_type){const s=mW(a.tray_color),o=a.id??254,l=(t?.vt_tray?.length??0)>1;e.push({type:a.tray_type,color:s,colorName:Td(s),amsId:-1,trayId:o-254,isHt:!1,isExternal:!0,label:l?o===254?"Ext-L":"Ext-R":"External",globalTrayId:o,trayInfoIdx:a.tray_info_idx||"",traySubBrands:a.tray_sub_brands||"",extruderId:r?255-o:void 0})}return e}function pW(t,e){if(!t?.filaments||t.filaments.length===0)return;const n=$w(e);if(n.length===0)return;const r=new Set,a=t.filaments.map(l=>{const c=l.tray_info_idx||"";let u=n.filter(v=>!r.has(v.globalTrayId));l.nozzle_id!=null&&(u=u.filter(v=>v.extruderId===l.nozzle_id));let d,m,p,f;if(c){const v=u.filter(x=>x.trayInfoIdx===c);v.length===1?d=v[0]:v.length>1&&(m=v.find(x=>x.type?.toUpperCase()===l.type?.toUpperCase()&&Ri(x.color)===Ri(l.color)),m||(p=v.find(x=>x.type?.toUpperCase()===l.type?.toUpperCase()&&cu(x.color,l.color))),!m&&!p&&(f=v.find(x=>x.type?.toUpperCase()===l.type?.toUpperCase())))}!d&&!m&&!p&&!f&&(m=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&Ri(v.color)===Ri(l.color)),m||(p=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&cu(v.color,l.color))),!m&&!p&&(f=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase())));const y=d||m||p||f||void 0;return y&&r.add(y.globalTrayId),{slot_id:l.slot_id,globalTrayId:y?.globalTrayId??-1}}),s=Math.max(...a.map(l=>l.slot_id||0));if(s<=0)return;const o=new Array(s).fill(-1);return a.forEach(l=>{l.slot_id&&l.slot_id>0&&(o[l.slot_id-1]=l.globalTrayId)}),o}function Fqe(t){return w.useMemo(()=>$w(t),[t])}function eie(t,e,n){const r=Fqe(e),a=w.useMemo(()=>{if(!t?.filaments||t.filaments.length===0)return[];const c=new Set(Object.values(n));return t.filaments.map(u=>{const d=u.slot_id||0;if(d>0&&n[d]!==void 0){const A=n[d],k=r.find(R=>R.globalTrayId===A);if(k){const R=k.type?.toUpperCase()===u.type?.toUpperCase(),P=Ri(k.color)===Ri(u.color)||cu(k.color,u.color);let D;return R&&P?D="match":R?D="type_only":D="mismatch",{...u,loaded:k,hasFilament:!0,typeMatch:R,colorMatch:P,status:D,isManual:!0}}}const m=u.tray_info_idx||"";let p=r.filter(A=>!c.has(A.globalTrayId));u.nozzle_id!=null&&(p=p.filter(A=>A.extruderId===u.nozzle_id));let f,y,v,x;if(m){const A=p.filter(k=>k.trayInfoIdx===m);A.length===1?f=A[0]:A.length>1&&(y=A.find(k=>k.type?.toUpperCase()===u.type?.toUpperCase()&&Ri(k.color)===Ri(u.color)),y||(v=A.find(k=>k.type?.toUpperCase()===u.type?.toUpperCase()&&cu(k.color,u.color))),!y&&!v&&(x=A.find(k=>k.type?.toUpperCase()===u.type?.toUpperCase())))}!f&&!y&&!v&&!x&&(y=p.find(A=>A.type?.toUpperCase()===u.type?.toUpperCase()&&Ri(A.color)===Ri(u.color)),y||(v=p.find(A=>A.type?.toUpperCase()===u.type?.toUpperCase()&&cu(A.color,u.color))),!y&&!v&&(x=p.find(A=>A.type?.toUpperCase()===u.type?.toUpperCase())));const g=f||y||v||x||void 0;g&&c.add(g.globalTrayId);const _=!!g,N=_,T=!!f||!!y||!!v;let C;return f||y||v?C="match":x?C="type_only":C="mismatch",{...u,loaded:g,hasFilament:_,typeMatch:N,colorMatch:T,status:C,isManual:!1}})},[t,r,n]),s=w.useMemo(()=>{if(a.length===0)return;const c=Math.max(...a.map(d=>d.slot_id||0));if(c<=0)return;const u=new Array(c).fill(-1);return a.forEach(d=>{d.slot_id&&d.slot_id>0&&(u[d.slot_id-1]=d.loaded?.globalTrayId??-1)}),u},[a]),o=a.some(c=>c.status==="mismatch"),l=a.some(c=>c.status==="type_only");return{loadedFilaments:r,filamentComparison:a,amsMapping:s,hasTypeMismatch:o,hasColorMismatch:l}}function Lqe(t,e,n){if(!t||t.length===0)return{exactMatches:0,typeOnlyMatches:0,missingTypes:0,totalSlots:0,status:"full"};let r=0,a=0,s=0;const o=new Set(Object.values(n));for(const u of t){const d=u.slot_id||0;if(d>0&&n[d]!==void 0){const x=n[d],g=e.find(_=>_.globalTrayId===x);if(g){const _=g.type?.toUpperCase()===u.type?.toUpperCase(),N=Ri(g.color)===Ri(u.color)||cu(g.color,u.color);_&&N?r++:_?a++:s++;continue}}let m=e.filter(x=>!o.has(x.globalTrayId));if(u.nozzle_id!=null){const x=m.filter(g=>g.extruderId===u.nozzle_id);x.length>0&&(m=x)}const p=m.find(x=>x.type?.toUpperCase()===u.type?.toUpperCase()&&Ri(x.color)===Ri(u.color)),f=p?void 0:m.find(x=>x.type?.toUpperCase()===u.type?.toUpperCase()&&cu(x.color,u.color)),y=p||f?void 0:m.find(x=>x.type?.toUpperCase()===u.type?.toUpperCase()),v=p??f??y;v&&o.add(v.globalTrayId),p||f?r++:y?a++:s++}const l=t.length;let c="full";return s>0?c="missing":a>0&&(c="partial"),{exactMatches:r,typeOnlyMatches:a,missingTypes:s,totalSlots:l,status:c}}function Oqe(t,e,n){if(!t?.filaments||t.filaments.length===0)return;const r=$w(e);if(r.length===0)return;const a=new Set(Object.values(n)),s=[];for(const c of t.filaments){const u=c.slot_id||0;if(u>0&&n[u]!==void 0){s.push({slot_id:u,globalTrayId:n[u]});continue}let d=r.filter(v=>!a.has(v.globalTrayId));if(c.nozzle_id!=null){const v=d.filter(x=>x.extruderId===c.nozzle_id);v.length>0&&(d=v)}const m=d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&Ri(v.color)===Ri(c.color)),p=m?void 0:d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&cu(v.color,c.color)),f=m||p?void 0:d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()),y=m??p??f;y&&a.add(y.globalTrayId),s.push({slot_id:u,globalTrayId:y?.globalTrayId??-1})}const o=Math.max(...s.map(c=>c.slot_id||0));if(o<=0)return;const l=new Array(o).fill(-1);return s.forEach(c=>{c.slot_id&&c.slot_id>0&&(l[c.slot_id-1]=c.globalTrayId)}),l}const fW={useDefault:!0,manualMappings:{},autoConfigured:!1};function Iqe(t,e,n,r,a,s){const o=Gf({queries:t.map(y=>({queryKey:["printer-status",y],queryFn:()=>be.getPrinterStatus(y),enabled:t.length>0,staleTime:5e3}))}),l=w.useMemo(()=>t.map((y,v)=>{const x=o[v],g=x?.data,N=e?.find(D=>D.id===y)?.name||`Printer ${y}`,T=$w(g),C=a[y]||fW,A=pW(n,g),k=C.useDefault?r:C.manualMappings,R=Oqe(n,g,k),P=Lqe(n?.filaments,T,k);return{printerId:y,printerName:N,status:g,isLoading:x?.isLoading??!1,loadedFilaments:T,autoMapping:A,finalMapping:R,matchStatus:P.status,exactMatches:P.exactMatches,typeOnlyMatches:P.typeOnlyMatches,missingTypes:P.missingTypes,totalSlots:P.totalSlots,config:C}}),[t,o,e,n,a,r]),c=o.some(y=>y.isLoading),u=(y,v)=>{s(x=>({...x,[y]:{...x[y]||fW,...v}}))},d=y=>{const v=l.find(_=>_.printerId===y);if(!v||!v.status||!n?.filaments)return;const x=pW(n,v.status);if(!x)return;const g={};x.forEach((_,N)=>{_!==-1&&(g[N+1]=_)}),u(y,{useDefault:!1,manualMappings:g,autoConfigured:!0})},m=()=>{for(const y of t)d(y)},p=y=>l.find(x=>x.printerId===y)?.finalMapping,f=l.every(y=>y.matchStatus!=="missing");return{printerResults:l,isLoading:c,perPrinterConfigs:a,updatePrinterConfig:u,autoConfigureAll:m,autoConfigurePrinter:d,getFinalMapping:p,allPrintersReady:f}}const tie={USD:"$",EUR:"€",GBP:"£",CHF:"Fr.",JPY:"¥",CNY:"¥",CAD:"$",AUD:"$",INR:"₹",HKD:"HK$",KRW:"₩",SEK:"kr",NOK:"kr",DKK:"kr",PLN:"zł",BRL:"R$",TWD:"NT$",SGD:"S$",NZD:"NZ$",MXN:"MX$",MYR:"RM",CZK:"Kč",THB:"฿",ZAR:"R",TRY:"₺",RUB:"₽",HUF:"Ft",ILS:"₪"};function _l(t){return tie[t.toUpperCase()]||t}const zqe=Object.entries(tie).map(([t,e])=>({code:t,label:`${t} (${e})`}));function Uqe({printerId:t,filamentReqs:e,manualMappings:n,onManualMappingChange:r,currencySymbol:a,defaultCostPerKg:s,defaultExpanded:o=!1}){const{t:l}=Ft(),c=an(),[u,d]=w.useState(!1),[m,p]=w.useState(o),{data:f}=et({queryKey:["printer-status",t],queryFn:()=>be.getPrinterStatus(t),enabled:!!t}),{data:y}=et({queryKey:["spool-assignments",t],queryFn:()=>be.getAssignments(t),enabled:!!t}),{loadedFilaments:v,filamentComparison:x,hasTypeMismatch:g,hasColorMismatch:_}=eie(e,f,n),N=w.useMemo(()=>{const z=new Map;for(const G of y||[]){const I=G.ams_id===255,ee=G0(G.ams_id,G.tray_id,I);z.set(ee,G.spool?.cost_per_kg??null)}return z},[y]),T=w.useMemo(()=>{const z=new Map;for(const G of y||[]){const I=G.ams_id===255,ee=G0(G.ams_id,G.tray_id,I),ie=G.spool;if(!ie){z.set(ee,null);continue}z.set(ee,Math.max(0,Math.round((ie.label_weight??0)-(ie.weight_used??0))))}return z},[y]),C=w.useMemo(()=>{let z=0;for(const G of x){const I=G.loaded?.globalTrayId;if(I==null)continue;const ie=N.get(I)??null??s;ie>0&&(z+=G.used_grams/1e3*ie)}return z},[x,N,s]),A=w.useMemo(()=>Array.from(N.values()).some(z=>z!=null&&z>0),[N]),k=e?.filaments&&e.filaments.length>0,R=e?.filaments?.some(z=>z.nozzle_id!=null)??!1;if(!k||!f)return null;const P=g?"#f97316":_?"#facc15":"#00ae42",D=(z,G)=>{if(z>0)if(G===""){const I={...n};delete I[z],r(I)}else r({...n,[z]:parseInt(G,10)})},H=async()=>{d(!0);try{await be.refreshPrinterStatus(t),await new Promise(z=>setTimeout(z,500)),await c.refetchQueries({queryKey:["printer-status",t]})}finally{d(!1)}};return i.jsxs("div",{className:"mb-4",children:[i.jsxs("button",{type:"button",onClick:()=>p(!m),className:"flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full",children:[i.jsx(AN,{className:"w-4 h-4",fill:P,stroke:"none"}),i.jsx("span",{children:l("printModal.filamentMapping")}),g?i.jsx("span",{className:"text-xs text-orange-400",children:"(Type not found)"}):_?i.jsx("span",{className:"text-xs text-yellow-400",children:"(Color mismatch)"}):i.jsx("span",{className:"text-xs text-bambu-green",children:"(Ready)"}),m?i.jsx(Il,{className:"w-4 h-4 ml-auto"}):i.jsx(Ln,{className:"w-4 h-4 ml-auto"})]}),m&&i.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:"Click to change slot assignment"}),i.jsxs("button",{type:"button",onClick:H,className:"flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white",disabled:u,children:[i.jsx(wr,{className:`w-3 h-3 ${u?"animate-spin":""}`}),i.jsx("span",{children:"Re-read"})]})]}),x.map((z,G)=>i.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 16px"},children:[i.jsx("span",{title:`Required: ${z.type} - ${Td(z.color)}`,children:i.jsx(AN,{className:"w-3 h-3",fill:z.color,stroke:z.color})}),i.jsxs("span",{className:"text-white truncate flex items-center gap-1",children:[R&&z.nozzle_id!=null&&i.jsx("span",{className:"inline-flex items-center justify-center w-3.5 h-3.5 rounded text-[9px] font-bold leading-none bg-bambu-gray/20 text-bambu-gray shrink-0",title:z.nozzle_id===1?l("printModal.leftNozzleTooltip"):l("printModal.rightNozzleTooltip"),children:z.nozzle_id===1?l("printModal.leftNozzle"):l("printModal.rightNozzle")}),z.type," ",i.jsxs("span",{className:"text-bambu-gray",children:["(",z.used_grams,"g)"]})]}),i.jsx("span",{className:"text-bambu-gray",children:"→"}),i.jsxs("select",{value:z.loaded?.globalTrayId??"",onChange:I=>D(z.slot_id||0,I.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${z.status==="match"?"border-bambu-green/50 text-bambu-green":z.status==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${z.isManual?"ring-1 ring-blue-400/50":""}`,title:z.isManual?"Manually selected":"Auto-matched",children:[i.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),v.filter(I=>z.nozzle_id==null||I.extruderId===z.nozzle_id).map(I=>{const ee=T.get(I.globalTrayId),ie=ee!=null?l("printModal.slotRemainingShort",{grams:ee,defaultValue:` - ${ee}g left`}):"";return i.jsxs("option",{value:I.globalTrayId,className:"bg-bambu-dark text-white",children:[I.label,": ",I.traySubBrands||I.type," (",I.colorName,")",ie]},I.globalTrayId)})]}),z.status==="match"?i.jsx(Yr,{className:"w-3 h-3 text-bambu-green"}):z.status==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(Mn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(Mn,{className:"w-3 h-3 text-orange-400"})})]},G)),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[l("printModal.totalCost")," ",i.jsx("span",{className:"text-white",children:C>0||A?`${a}${C.toFixed(2)}`:"N/A"})]}),g&&i.jsx("p",{className:"text-xs text-orange-400 mt-2",children:"Required filament type not found in printer."})]})]})}function Bqe({filamentReqs:t,availableFilaments:e,overrides:n,onChange:r,forceColorMatch:a,onForceColorMatchChange:s}){const{t:o}=Ft(),l=w.useMemo(()=>{const d={};for(const m of e){const p=Yk(m.type);d[p]||(d[p]=[]),d[p].push(m)}return d},[e]),c=t?.filaments;if(!c||c.length===0||e.length===0)return null;const u=(d,m)=>{if(m===""){const p={...n};delete p[d],r(p)}else{const[p,f]=m.split("|");r({...n,[d]:{type:p,color:f}})}};return i.jsxs("div",{className:"mb-4",children:[i.jsx("div",{className:"flex items-center gap-2 text-sm text-bambu-gray mb-2",children:i.jsx("span",{children:o("printModal.filamentOverride")})}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:o("printModal.filamentOverrideHint")}),i.jsx("div",{className:"bg-bambu-dark rounded-lg p-3 space-y-2",children:c.map(d=>{const m=n[d.slot_id],p=!!m,f=l[Yk(d.type)]||[],y=d.nozzle_id!=null?f.filter(v=>v.extruder_id==null||v.extruder_id===d.nozzle_id):f;return i.jsxs("div",{className:"space-y-1",children:[i.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 20px"},children:[i.jsx("span",{title:`${o("printModal.originalFilament")}: ${d.type} - ${Td(d.color)}`,children:i.jsx(AN,{className:"w-3 h-3",fill:d.color,stroke:d.color})}),i.jsxs("span",{className:"text-white truncate",children:[d.type," ",i.jsxs("span",{className:"text-bambu-gray",children:["(",d.used_grams,"g)"]})]}),i.jsx("span",{className:"text-bambu-gray",children:"→"}),i.jsxs("select",{value:p?`${m.type}|${m.color}`:"",onChange:v=>u(d.slot_id,v.target.value),disabled:y.length===0,className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${p?"border-blue-400/50 text-blue-400":"border-bambu-gray/30 text-bambu-gray"}`,children:[i.jsxs("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:[o("printModal.originalFilament"),": ",d.type," (",Td(d.color),")"]}),y.map((v,x)=>i.jsxs("option",{value:`${v.type}|${v.color}`,className:"bg-bambu-dark text-white",children:[v.tray_sub_brands||v.type," (",Td(v.color),")"]},`${v.type}-${v.color}-${v.tray_sub_brands}-${x}`))]}),p?i.jsx("button",{type:"button",onClick:()=>u(d.slot_id,""),className:"text-bambu-gray hover:text-white transition-colors",title:o("printModal.resetToOriginal"),children:i.jsx(bo,{className:"w-3 h-3"})}):i.jsx("span",{className:"w-3"})]}),i.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-bambu-gray cursor-pointer select-none pl-5",children:[i.jsx("input",{type:"checkbox",checked:a?.[d.slot_id]??!1,onChange:v=>s?.(d.slot_id,v.target.checked),className:"accent-bambu-green w-3 h-3"}),i.jsx(fw,{className:"w-3 h-3"}),o("printModal.forceColorMatch")]})]},d.slot_id)})})]})}function Hqe({plates:t,isMultiPlate:e,selectedPlate:n,onSelect:r,queueAll:a,onQueueAllChange:s}){const{t:o}=Ft();return!e||t.length<=1?null:i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx(Gi,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:"Select Plate to Print"}),!n&&!a&&i.jsxs("span",{className:"text-xs text-orange-400 flex items-center gap-1",children:[i.jsx(Mn,{className:"w-3 h-3"}),"Selection required"]}),s&&i.jsx("button",{type:"button",onClick:()=>s(!a),className:`ml-auto text-xs px-2 py-0.5 rounded-full border transition-colors ${a?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-gray"}`,children:o("queue.queueAllPlates",{count:t.length})})]}),i.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.map(l=>i.jsxs("button",{type:"button",onClick:()=>{a&&s&&s(!1),r(l.index)},className:`flex items-center gap-2 p-2 rounded-lg border transition-colors text-left ${a||n===l.index?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"}`,children:[l.has_thumbnail&&l.thumbnail_url!=null?i.jsx("img",{src:l.thumbnail_url,alt:`Plate ${l.index}`,className:"w-10 h-10 rounded object-cover bg-bambu-dark-tertiary"}):i.jsx("div",{className:"w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center",children:i.jsx(Gi,{className:"w-5 h-5 text-bambu-gray"})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"text-sm text-white font-medium truncate",children:l.name||`Plate ${l.index}`}),i.jsxs("p",{className:"text-xs text-bambu-gray truncate",children:[l.objects.length>0?l.objects.slice(0,3).join(", ")+(l.objects.length>3?"...":""):`${l.filaments.length} filament${l.filaments.length!==1?"s":""}`,l.print_time_seconds!=null?` • ${Rs(l.print_time_seconds)}`:""]})]}),(a||n===l.index)&&i.jsx(Yr,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]},l.index))})]})}const $qe=new Set(["IDLE","FINISH","FAILED"]);function qqe({printerResult:t,filamentReqs:e,onUpdateConfig:n}){const r=an(),[a,s]=w.useState(!1),o=(u,d)=>{if(u<=0)return;const m={...t.config.manualMappings};d===""?delete m[u]:m[u]=parseInt(d,10),n({useDefault:!1,manualMappings:m,autoConfigured:!1})},l=async()=>{s(!0);try{await be.refreshPrinterStatus(t.printerId),await new Promise(u=>setTimeout(u,500)),await r.refetchQueries({queryKey:["printer-status",t.printerId]})}finally{s(!1)}},c=e.map(u=>{const d=u.slot_id||0,m=t.config.manualMappings[d];let p,f=!1;if(m!==void 0)p=t.loadedFilaments.find(v=>v.globalTrayId===m),f=!0;else{const v=new Set(Object.values(t.config.manualMappings));p=Rqe(u,t.loadedFilaments,v)}let y="mismatch";if(p){const v=p.type?.toUpperCase()===u.type?.toUpperCase(),x=Ri(p.color)===Ri(u.color)||cu(p.color,u.color);v&&x?y="match":v&&(y="type_only")}return{req:u,loaded:p,status:y,isManual:f}});return i.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom slot mapping"}),i.jsxs("button",{type:"button",onClick:l,className:"flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white",disabled:a,children:[i.jsx(wr,{className:`w-3 h-3 ${a?"animate-spin":""}`}),i.jsx("span",{children:"Re-read"})]})]}),c.map(({req:u,loaded:d,status:m,isManual:p},f)=>i.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 16px"},children:[i.jsx("span",{title:`Required: ${u.type} - ${Td(u.color)}`,children:i.jsx(AN,{className:"w-3 h-3",fill:u.color,stroke:u.color})}),i.jsxs("span",{className:"text-white truncate",children:[u.type," ",i.jsxs("span",{className:"text-bambu-gray",children:["(",u.used_grams,"g)"]})]}),i.jsx("span",{className:"text-bambu-gray",children:"→"}),i.jsxs("select",{value:d?.globalTrayId??"",onChange:y=>o(u.slot_id||0,y.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${m==="match"?"border-bambu-green/50 text-bambu-green":m==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${p?"ring-1 ring-blue-400/50":""}`,title:p?"Manually selected":"Auto-matched",children:[i.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),Jre(t.loadedFilaments,u.nozzle_id).map(y=>i.jsxs("option",{value:y.globalTrayId,className:"bg-bambu-dark text-white",children:[y.label,": ",y.traySubBrands||y.type," (",y.colorName,")"]},y.globalTrayId))]}),m==="match"?i.jsx(Yr,{className:"w-3 h-3 text-bambu-green"}):m==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(Mn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(Mn,{className:"w-3 h-3 text-orange-400"})})]},f))]})}function Vqe({printers:t,selectedPrinterIds:e,onMultiSelect:n,isLoading:r=!1,allowMultiple:a=!1,showInactive:s=!1,disableBusy:o=!1,printerMappingResults:l,filamentReqs:c,onAutoConfigurePrinter:u,onUpdatePrinterConfig:d,assignmentMode:m="printer",onAssignmentModeChange:p,targetModel:f,onTargetModelChange:y,targetLocation:v,onTargetLocationChange:x,slicedForModel:g}){const[_,N]=w.useState(!1),T=s?t:t.filter(oe=>oe.is_active),C=Gf({queries:T.map(oe=>({queryKey:["printerStatus",oe.id],queryFn:()=>be.getPrinterStatus(oe.id),staleTime:5e3}))}),A=w.useMemo(()=>{const oe=new Map;return T.forEach((le,xe)=>{const Pe=C[xe];Pe?.data&&oe.set(le.id,Pe.data)}),oe},[T,C]),k=oe=>{const le=A.get(oe);return le?le.connected?!$qe.has(le.state??""):!0:!1},R=oe=>{const le=A.get(oe);if(!le)return null;if(!le.connected)return"Offline";const xe=le.state;return xe?xe==="RUNNING"?le.stg_cur_name||"Printing":xe==="PREPARE"?"Preparing":xe==="PAUSE"?"Paused":xe==="IDLE"?"Idle":xe==="FINISH"?"Finished":xe==="FAILED"?"Failed":xe:null},P=w.useMemo(()=>{if(m!=="printer"||!g||_)return T;const oe=T.filter(le=>le.model===g);return oe.length>0?oe:T},[T,m,g,_]),D=T.length-P.length,H=w.useMemo(()=>{const oe=T.map(le=>le.model).filter(le=>!!le);return[...new Set(oe)].sort()},[T]),z=w.useMemo(()=>{if(!f)return[];const oe=T.filter(le=>le.model===f&&le.location).map(le=>le.location).filter(le=>!!le);return[...new Set(oe)].sort()},[T,f]),G=p&&y&&H.length>0,I=a&&e.length>1&&l&&c?.filaments&&c.filaments.length>0&&u&&d;if(r)return i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(P.length===0)return i.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm mb-4",children:[i.jsx(Li,{className:"w-4 h-4"}),"No ",s?"":"active ","printers available"]});const ee=oe=>{o&&k(oe)||(a?e.includes(oe)?n(e.filter(le=>le!==oe)):n([...e,oe]):n([oe]))},ie=()=>{const oe=o?P.filter(le=>!k(le.id)):P;n(oe.map(le=>le.id))},X=()=>{n([])},me=(oe,le,xe)=>{xe.stopPropagation(),!(!u||!d)&&(le?u(oe):d(oe,{useDefault:!0,manualMappings:{},autoConfigured:!1}))},he=oe=>e.includes(oe),ge=e.length,Y=oe=>l?.find(le=>le.printerId===oe);return i.jsxs("div",{className:"space-y-2 mb-6",children:[G&&i.jsxs("div",{className:"flex gap-2 mb-4",children:[i.jsxs("button",{type:"button",onClick:()=>{p("printer"),y(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${m==="printer"?"border-bambu-green bg-bambu-green/10 text-white":"border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray"}`,children:[i.jsx(Sr,{className:"w-4 h-4"}),i.jsx("span",{className:"text-sm",children:"Specific Printer"})]}),i.jsxs("button",{type:"button",onClick:()=>{p("model"),n([]);const oe=g&&H.includes(g)?g:H[0];y(oe)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${m==="model"?"border-bambu-green bg-bambu-green/10 text-white":"border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray"}`,children:[i.jsx(Km,{className:"w-4 h-4"}),i.jsxs("span",{className:"text-sm",children:["Any ",g||"Model"]})]})]}),m==="model"&&G&&i.jsxs("div",{className:"space-y-3 mb-4",children:[!g&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Target Model"}),i.jsxs("select",{value:f||"",onChange:oe=>{y(oe.target.value||null),x&&x(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 text-sm",children:[i.jsx("option",{value:"",children:"Select a model..."}),H.map(oe=>i.jsx("option",{value:oe,children:oe},oe))]})]}),f&&z.length>0&&x&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Location Filter (optional)"}),i.jsxs("select",{value:v||"",onChange:oe=>x(oe.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 text-sm",children:[i.jsx("option",{value:"",children:"Any location"}),z.map(oe=>i.jsx("option",{value:oe,children:oe},oe))]})]}),f&&i.jsxs("p",{className:"text-xs text-bambu-gray",children:["Scheduler will assign to first available idle ",f," printer",v?` in ${v}`:""]})]}),m==="printer"&&a&&P.length>1&&i.jsxs("div",{className:"flex items-center justify-between text-xs text-bambu-gray mb-2",children:[i.jsx("span",{children:ge===0?"Select printers":`${ge} printer${ge!==1?"s":""} selected`}),i.jsxs("div",{className:"flex gap-2",children:[ge0&&i.jsx("button",{type:"button",onClick:X,className:"text-bambu-gray hover:text-white transition-colors",children:"Clear"})]})]}),m==="printer"&&P.map(oe=>{const le=he(oe.id),xe=Y(oe.id),Pe=xe&&!xe.config.useDefault,q=k(oe.id),Z=o&&q,j=R(oe.id);return i.jsxs("div",{children:[i.jsxs("button",{type:"button",onClick:()=>ee(oe.id),disabled:Z,className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${Z?"border-bambu-dark-tertiary bg-bambu-dark opacity-50 cursor-not-allowed":le?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"} ${oe.is_active?"":"opacity-60"}`,children:[i.jsx("div",{className:`p-2 rounded-lg ${Z?"bg-bambu-dark-tertiary":le?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:i.jsx(Sr,{className:`w-5 h-5 ${Z?"text-bambu-gray/50":le?"text-bambu-green":"text-bambu-gray"}`})}),i.jsxs("div",{className:"text-left flex-1",children:[i.jsxs("p",{className:`font-medium ${Z?"text-bambu-gray":"text-white"}`,children:[oe.name,!oe.is_active&&i.jsx("span",{className:"text-bambu-gray text-xs ml-2",children:"(inactive)"})]}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[oe.model||"Unknown model"," • ",oe.ip_address]})]}),j&&i.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${q?"bg-yellow-500/20 text-yellow-400":"bg-bambu-green/20 text-bambu-green"}`,children:j}),a&&i.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${Z?"border-bambu-gray/30":le?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:le&&i.jsx(Yr,{className:"w-3 h-3 text-white"})})]}),le&&I&&xe&&i.jsxs("div",{className:"ml-4 mt-2 mb-3",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",onClick:E=>E.stopPropagation(),children:[i.jsx("input",{type:"checkbox",checked:Pe,onChange:E=>me(oe.id,E.target.checked,E),className:"w-3.5 h-3.5 rounded border-bambu-gray/30 bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green focus:ring-offset-0"}),i.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom mapping"})]}),i.jsxs("span",{className:`text-xs ml-2 ${xe.matchStatus==="full"?"text-bambu-green":xe.matchStatus==="partial"?"text-yellow-400":"text-orange-400"}`,children:["(",xe.exactMatches,"/",xe.totalSlots," matched)"]}),xe.isLoading&&i.jsx(wr,{className:"w-3 h-3 text-bambu-gray animate-spin"}),Pe&&i.jsxs("button",{type:"button",onClick:E=>{E.stopPropagation(),u(oe.id)},className:"ml-auto flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white",children:[i.jsx(Ebe,{className:"w-3 h-3"}),"Auto"]})]}),Pe&&i.jsx(qqe,{printerResult:xe,filamentReqs:c.filaments,onUpdateConfig:E=>d(oe.id,E)})]})]},oe.id)}),m==="printer"&&D>0&&!_&&i.jsxs("button",{type:"button",onClick:()=>N(!0),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2 flex items-center gap-1",children:[i.jsx(Mn,{className:"w-3 h-3 text-yellow-400"}),D," other printer",D>1?"s":""," hidden (different model) —",i.jsx("span",{className:"underline",children:"show all"})]}),m==="printer"&&_&&g&&i.jsx("button",{type:"button",onClick:()=>N(!1),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2",children:i.jsxs("span",{className:"underline",children:["Show only ",g," printers"]})}),m==="printer"&&ge===0&&i.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[i.jsx(Li,{className:"w-3 h-3"}),"Select at least one printer"]}),m==="model"&&!f&&i.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[i.jsx(Li,{className:"w-3 h-3"}),"Select a target printer model"]})]})}const Gqe=[{key:"bed_levelling",label:"Bed Levelling",desc:"Auto-level bed before print"},{key:"flow_cali",label:"Flow Calibration",desc:"Calibrate extrusion flow"},{key:"vibration_cali",label:"Vibration Calibration",desc:"Reduce ringing artifacts"},{key:"layer_inspect",label:"First Layer Inspection",desc:"AI inspection of first layer"},{key:"timelapse",label:"Timelapse",desc:"Record timelapse video"}];function Wqe({options:t,onChange:e,defaultExpanded:n=!1}){const[r,a]=w.useState(n),s=o=>{e({...t,[o]:!t[o]})};return i.jsxs("div",{className:"mb-4",children:[i.jsxs("button",{type:"button",onClick:()=>a(!r),className:"flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full",children:[i.jsx(iT,{className:"w-4 h-4"}),i.jsx("span",{children:"Print Options"}),r?i.jsx(Il,{className:"w-4 h-4 ml-auto"}):i.jsx(Ln,{className:"w-4 h-4 ml-auto"})]}),r&&i.jsx("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:Gqe.map(({key:o,label:l,desc:c})=>i.jsxs("label",{className:"flex items-center justify-between cursor-pointer group",children:[i.jsxs("div",{children:[i.jsx("span",{className:"text-sm text-white",children:l}),i.jsx("p",{className:"text-xs text-bambu-gray",children:c})]}),i.jsx("div",{className:`relative w-10 h-5 rounded-full transition-colors ${t[o]?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,onClick:()=>s(o),children:i.jsx("div",{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white transition-transform ${t[o]?"translate-x-5":"translate-x-0.5"}`})})]},o))})]})}function Kqe({options:t,onChange:e,dateFormat:n="system",timeFormat:r="system",canControlPrinter:a=!0}){const[s,o]=w.useState(""),[l,c]=w.useState(""),[u,d]=w.useState(!0),[m,p]=w.useState(!0),f=w.useRef(null),y=w.useRef(!1);w.useEffect(()=>{if(t.scheduleType!=="scheduled"){y.current=!1;return}if(!y.current){y.current=!0;let C;t.scheduledTime?(C=new Date(t.scheduledTime),isNaN(C.getTime())&&(C=new Date,C.setHours(C.getHours()+1,0,0,0))):(C=new Date,C.setHours(C.getHours()+1,0,0,0),e({...t,scheduledTime:_3(C)})),o(S3(C,n)),c(Z8(C,r)),d(!0),p(!0)}},[t.scheduleType,t.scheduledTime,n,r,e,t]);const v=C=>{e({...t,scheduleType:C})},x=(C,A)=>{const k=txe(C,n),R=nxe(A);d(!!k),p(!!R),k&&R&&(k.setHours(R.hours,R.minutes,0,0),k>new Date&&e({...t,scheduledTime:_3(k)}))},g=C=>{o(C),x(C,l)},_=C=>{c(C),x(s,C)},N=C=>{const A=C.target.value;if(A){const k=new Date(A);isNaN(k.getTime())||(o(S3(k,n)),c(Z8(k,r)),d(!0),p(!0),e({...t,scheduledTime:A}))}},T=()=>{f.current?.showPicker()};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"When to print"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="asap"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>v("asap"),children:[i.jsx(er,{className:"w-4 h-4"}),"ASAP"]}),i.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="scheduled"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>v("scheduled"),children:[i.jsx(Wr,{className:"w-4 h-4"}),"Scheduled"]}),i.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="manual"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>v("manual"),children:[i.jsx(GX,{className:"w-4 h-4"}),"Queue Only"]})]})]}),t.scheduleType==="scheduled"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Date & Time"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("div",{className:"flex-1 relative",children:[i.jsx("input",{type:"text",className:`w-full px-3 py-2 pr-10 bg-bambu-dark border rounded-lg text-white focus:outline-none ${u?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:s,onChange:C=>g(C.target.value),placeholder:Zbe(n)}),i.jsx("button",{type:"button",onClick:T,className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",title:"Open calendar",children:i.jsx(Wr,{className:"w-4 h-4"})})]}),i.jsx("div",{className:"w-32",children:i.jsx("input",{type:"text",className:`w-full px-3 py-2 bg-bambu-dark border rounded-lg text-white focus:outline-none ${m?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:l,onChange:C=>_(C.target.value),placeholder:Jbe(r)})})]}),i.jsx("input",{ref:f,type:"datetime-local",className:"sr-only",value:t.scheduledTime,onChange:N,tabIndex:-1}),(!u||!m)&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:"Please enter a valid date and time"})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"checkbox",id:"requirePrevious",checked:t.requirePreviousSuccess,onChange:C=>e({...t,requirePreviousSuccess:C.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("label",{htmlFor:"requirePrevious",className:"text-sm text-bambu-gray",children:"Only start if previous print succeeded"})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"checkbox",id:"autoOffAfter",checked:t.autoOffAfter,onChange:C=>e({...t,autoOffAfter:C.target.checked}),disabled:!a,className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green disabled:opacity-50"}),i.jsxs("label",{htmlFor:"autoOffAfter",className:`text-sm flex items-center gap-1 ${a?"text-bambu-gray":"text-bambu-gray/50"}`,children:[i.jsx(Vd,{className:"w-3.5 h-3.5"}),"Power off printer when done"]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:t.scheduleType==="asap"?"Print will start as soon as the printer is idle.":t.scheduleType==="scheduled"?"Print will start at the scheduled time if the printer is idle. If busy, it will wait until the printer becomes available.":"Print will be staged but won't start automatically. Use the Start button to release it to the queue."})]})}const bb={bed_levelling:!0,flow_cali:!1,vibration_cali:!0,layer_inspect:!1,timelapse:!1},Yqe={scheduleType:"asap",scheduledTime:"",requirePreviousSuccess:!1,autoOffAfter:!1};function uu({mode:t,archiveId:e,libraryFileId:n,archiveName:r,queueItem:a,initialSelectedPrinterIds:s,onClose:o,onSuccess:l}){const{t:c}=Ft(),u=an(),{showToast:d}=fn(),{hasPermission:m}=_r(),p=!!n&&!e,[f,y]=w.useState(()=>t==="edit-queue-item"&&a?.printer_id?[a.printer_id]:s?.length?s:[]),[v,x]=w.useState(()=>t==="edit-queue-item"&&a?a.plate_id:null),[g,_]=w.useState(!1),[N,T]=w.useState(()=>t==="edit-queue-item"&&a?{bed_levelling:a.bed_levelling??bb.bed_levelling,flow_cali:a.flow_cali??bb.flow_cali,vibration_cali:a.vibration_cali??bb.vibration_cali,layer_inspect:a.layer_inspect??bb.layer_inspect,timelapse:a.timelapse??bb.timelapse}:bb),[C,A]=w.useState(()=>{if(t==="edit-queue-item"&&a){let _t="asap";a.manual_start?_t="manual":a.scheduled_time&&!hW(a.scheduled_time)&&(_t="scheduled");let Ot="";if(a.scheduled_time&&!hW(a.scheduled_time)){const Vt=Jn(a.scheduled_time)??new Date;Ot=_3(Vt)}return{scheduleType:_t,scheduledTime:Ot,requirePreviousSuccess:a.require_previous_success,autoOffAfter:a.auto_off_after}}return Yqe}),[k,R]=w.useState(()=>{if(t==="edit-queue-item"&&a?.ams_mapping&&Array.isArray(a.ams_mapping)){const _t={};return a.ams_mapping.forEach((Ot,Vt)=>{Ot!==-1&&(_t[Vt+1]=Ot)}),_t}return{}}),[P,D]=w.useState({}),[H,z]=w.useState(()=>t==="edit-queue-item"&&a?.target_model?"model":"printer"),[G,I]=w.useState(()=>t==="edit-queue-item"&&a?.target_model?a.target_model:null),[ee,ie]=w.useState(()=>t==="edit-queue-item"&&a?.target_location?a.target_location:null),[X,me]=w.useState(()=>{if(t==="edit-queue-item"&&a?.filament_overrides){const _t={};for(const Ot of a.filament_overrides)_t[Ot.slot_id]={type:Ot.type,color:Ot.color};return _t}return{}}),[he,ge]=w.useState(()=>{if(t==="edit-queue-item"&&a?.filament_overrides){const _t={};for(const Ot of a.filament_overrides)_t[Ot.slot_id]=Ot.force_color_match===!0;return _t}return{}}),[Y]=w.useState(()=>t==="edit-queue-item"&&a?.printer_id?[a.printer_id]:[]),[oe]=w.useState(()=>t==="edit-queue-item"&&a?a.plate_id:null),[le,xe]=w.useState(!1),[Pe,q]=w.useState({current:0,total:0}),[Z,j]=w.useState(null),[E,U]=w.useState(new Set),K=f.length,$=f.length>0?f[0]:null,{data:ne}=et({queryKey:["settings"],queryFn:be.getSettings}),O=_l(ne?.currency||"USD"),V=ne?.default_filament_cost??0,{data:J,isLoading:W}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:re}=et({queryKey:["spool-assignments"],queryFn:()=>be.getAssignments(),staleTime:30*1e3,enabled:(t==="reprint"||t==="add-to-queue")&&H==="printer"||p&&t==="reprint"}),{data:ue}=et({queryKey:["archive",e],queryFn:()=>be.getArchive(e),enabled:!!e&&!p}),{data:fe}=et({queryKey:["library-file",n],queryFn:()=>be.getLibraryFile(n),enabled:p&&!!n}),ye=ue?.sliced_for_model||fe?.sliced_for_model||null,{data:ae,isError:L}=et({queryKey:["archive-plates",e],queryFn:()=>be.getArchivePlates(e),enabled:!!e&&!p,retry:!1}),{data:F}=et({queryKey:["library-file-plates",n],queryFn:()=>be.getLibraryFilePlates(n),enabled:p&&!!n}),te=p?F:ae,{data:ve,isError:pe}=et({queryKey:["archive-filaments",e,v],queryFn:()=>be.getArchiveFilamentRequirements(e,v??void 0),enabled:!!e&&!p&&(v!==null||!te?.is_multi_plate),retry:!1}),{data:de}=et({queryKey:["library-file-filaments",n,v],queryFn:()=>be.getLibraryFileFilamentRequirements(n,v??void 0),enabled:p&&!!n&&(v!==null||!te?.is_multi_plate)}),Ne=!p&&(L||pe),Se=p?de:ve,Le=w.useMemo(()=>{if(!(v===null||!te?.plates?.length))return te.plates.find(_t=>_t.index===v)?.name||void 0},[te,v]),{data:qe}=et({queryKey:["available-filaments",G,ee],queryFn:()=>be.getAvailableFilaments(G,ee??void 0),enabled:H==="model"&&!!G}),{data:Ee}=et({queryKey:["printer-status",$],queryFn:()=>be.getPrinterStatus($),enabled:!!$}),{amsMapping:Te}=eie(Se,Ee,k),Ae=Iqe(f,J,Se,k,P,D);w.useEffect(()=>{te?.plates&&te.plates.length>=1&&!v&&x(te.plates[0].index)},[te,v]),w.useEffect(()=>{if(t==="edit-queue-item")return;const _t=J?.filter(Ot=>Ot.is_active)||[];_t.length===1&&f.length===0&&y([_t[0].id])},[t,J,f.length]),w.useEffect(()=>{t==="edit-queue-item"?(JSON.stringify(f.sort())!==JSON.stringify(Y.sort())||v!==oe)&&(R({}),D({}),U(new Set)):(R({}),D({}),U(new Set))},[t,f,v,Y,oe]);const[Be,je]=w.useState(G),[Xe,ce]=w.useState(v);w.useEffect(()=>{(G!==Be||v!==Xe)&&(je(G),ce(v),(t!=="edit-queue-item"||Be!==null)&&(me({}),ge({})))},[G,v,Be,Xe,t]),w.useEffect(()=>{if(!ne?.per_printer_mapping_expanded||f.length<=1)return;const _t=f.filter(Ot=>{if(E.has(Ot))return!1;const Vt=Ae.printerResults.find(Xt=>Xt.printerId===Ot);return Vt&&Vt.status&&!Vt.isLoading});_t.length>0&&(U(Ot=>{const Vt=new Set(Ot);return _t.forEach(Xt=>Vt.add(Xt)),Vt}),_t.forEach(Ot=>{Ae.autoConfigurePrinter(Ot)}))},[ne?.per_printer_mapping_expanded,f,E,Ae]),w.useEffect(()=>{const _t=Ot=>{Ot.key==="Escape"&&!le&&o()};return window.addEventListener("keydown",_t),()=>window.removeEventListener("keydown",_t)},[o,le]);const Ie=te?.is_multi_plate??!1,Ce=te?.plates??[],Ge=w.useMemo(()=>{const _t=new Map;return re&&re.forEach(Ot=>{const Vt=Ot.ams_id===255,Xt=G0(Ot.ams_id,Ot.tray_id,Vt),Qe=_t.get(Ot.printer_id)??new Map;Qe.set(Xt,Ot),_t.set(Ot.printer_id,Qe)}),_t},[re]),$e=w.useMemo(()=>{if(!Z||Z.length===0)return"";const _t=Z.map(Ot=>c("printModal.insufficientFilamentLine",{printer:Ot.printerName,slot:Ot.slotLabel,required:Math.round(Ot.requiredGrams),remaining:Math.round(Ot.remainingGrams)}));return[c("printModal.insufficientFilamentMessage"),..._t].join(` `)},[Z,c]),Ue=pt({mutationFn:_t=>be.addToQueue(_t)}),De=pt({mutationFn:_t=>be.updateQueueItem(a.id,_t),onSuccess:()=>{u.invalidateQueries({queryKey:["queue"]}),d("Queue item updated"),l?.(),o()},onError:_t=>{d(_t.message||"Failed to update queue item","error")}}),Ve=async(_t,Ot)=>{if(_t?.preventDefault(),!Ot?.skipFilamentCheck&&!ne?.disable_filament_warnings&&(t==="reprint"||t==="add-to-queue")&&H==="printer"){const Fe=[],tt=Se?.filaments??[];if(tt.length>0&&Ge.size>0){const ut=(Ze,ke)=>!Number.isFinite(Ze)||Ze<=0||!Number.isFinite(ke)||ke<0?null:Math.max(0,Ze-ke);for(const Ze of f){const ke=f.length>1?Ae.getFinalMapping(Ze):Te;if(!ke)continue;const ot=f.length>1?Ae.printerResults.find(Me=>Me.printerId===Ze)?.status:Ee,se=$w(ot),He=new Map(se.map(Me=>[Me.globalTrayId,Me.label])),Ke=Ge.get(Ze),Ye=J?.find(Me=>Me.id===Ze)?.name??`Printer ${Ze}`;Ke&&tt.forEach(Me=>{if(!Me.slot_id||Me.slot_id<=0)return;const dt=ke[Me.slot_id-1];if(!Number.isFinite(dt)||dt<0)return;const nt=Ke.get(dt)?.spool;if(!nt)return;const bt=ut(nt.label_weight,nt.weight_used);bt!==null&&(bt>=Me.used_grams||Fe.push({printerName:Ye,slotLabel:He.get(dt)??`Slot ${Me.slot_id}`,requiredGrams:Me.used_grams,remainingGrams:bt}))})}}if(Fe.length>0){j(Fe);return}}if(H==="printer"&&f.length===0){d("Please select at least one printer","error");return}if(H==="model"&&!G){d("Please select a target printer model","error");return}xe(!0);const Vt=g?Ce:[null],Xt=H==="model"?Vt.length:f.length*Vt.length;q({current:0,total:Xt});const Qe={success:0,failed:0,errors:[]},Qt=Fe=>{if(f.length>1){const tt=P[Fe];if(tt&&!tt.useDefault)return Ae.getFinalMapping(Fe)}return Te},jn=(()=>{const Fe=[];if(Se?.filaments)for(const tt of Se.filaments){const ut=X[tt.slot_id],Ze=he[tt.slot_id]??!1,ke=ut?.type??tt.type,ot=ut?.color??tt.color;(ut||Ze)&&Fe.push({slot_id:tt.slot_id,type:ke,color:ot,color_name:Td(ot),force_color_match:Ze})}else for(const[tt,{type:ut,color:Ze}]of Object.entries(X)){const ke=parseInt(tt,10),ot=he[ke]??!1;Fe.push({slot_id:ke,type:ut,color:Ze,color_name:Td(Ze),force_color_match:ot})}return Fe.length>0?Fe:void 0})(),kn=(Fe,tt)=>({printer_id:H==="printer"?Fe:null,target_model:H==="model"?G:null,target_location:H==="model"?ee:null,filament_overrides:H==="model"?jn:void 0,archive_id:p?void 0:e,library_file_id:p?n:void 0,require_previous_success:C.requirePreviousSuccess,auto_off_after:C.autoOffAfter,manual_start:C.scheduleType==="manual",ams_mapping:Fe?Qt(Fe):void 0,plate_id:tt!==void 0?tt:v,scheduled_time:C.scheduleType==="scheduled"&&C.scheduledTime?new Date(C.scheduledTime).toISOString():void 0,...N});if(H==="model"){if(t==="reprint"){d("Model-based assignment only works with queue mode","error"),xe(!1);return}let Fe=0;for(const tt of Vt){Fe++,q({current:Fe,total:Xt});const ut=tt?tt.index:v;try{if(t==="edit-queue-item"&&!tt){const Ze={printer_id:null,target_model:G,target_location:ee,filament_overrides:jn||null,require_previous_success:C.requirePreviousSuccess,auto_off_after:C.autoOffAfter,manual_start:C.scheduleType==="manual",ams_mapping:void 0,plate_id:ut,scheduled_time:C.scheduleType==="scheduled"&&C.scheduledTime?new Date(C.scheduledTime).toISOString():null,...N};await De.mutateAsync(Ze)}else await Ue.mutateAsync(kn(null,ut));Qe.success++}catch(Ze){Qe.failed++;const ke=tt?tt.name||`Plate ${tt.index}`:"";Qe.errors.push(ke?`${ke}: ${Ze.message}`:Ze.message)}}}else{let Fe=0;for(const tt of Vt){const ut=tt?tt.index:v;for(let Ze=0;ZeYe.id===ke)?.name||`Printer ${ke}`,He=tt?tt.name||`Plate ${tt.index}`:"",Ke=He?`${se} (${He})`:se;Qe.errors.push(`${Ke}: ${ot.message}`)}}}}xe(!1),Qe.failed===0?(t!=="reprint"&&(t==="edit-queue-item"?d("Queue item updated"):Qe.success===1?d(H==="model"?`Queued for any ${G}`:c("queue.printQueued")):d(c("queue.itemsQueued",{count:Qe.success}))),u.invalidateQueries({queryKey:["queue"]}),l?.(),o()):Qe.success===0?d(`Failed: ${Qe.errors[0]}`,"error"):(d(`${Qe.success} succeeded, ${Qe.failed} failed`,"error"),u.invalidateQueries({queryKey:["queue"]}))},it=le||De.isPending,xt=w.useMemo(()=>!(it||H==="printer"&&f.length===0||H==="model"&&!G||H==="model"&&t==="reprint"||Ie&&!v&&!g),[f.length,H,G,t,Ie,v,g,it]),kt=(()=>{const _t=f.length;if(t==="reprint")return{title:c(p?"queue.print":"queue.reprint"),icon:Sr,submitText:_t>1?c("queue.printToPrinters",{count:_t}):c("queue.print"),submitIcon:Sr,loadingText:Pe.total>1?c("queue.sendingProgress",{current:Pe.current,total:Pe.total}):c("queue.sending")};if(t==="add-to-queue"){let Ot=c("queue.addToQueue");return g&&Ce.length>1?Ot=c("queue.queueAllPlates",{count:Ce.length}):_t>1&&(Ot=c("queue.queueToPrinters",{count:_t})),{title:c("queue.schedulePrint"),icon:Wr,submitText:Ot,submitIcon:Wr,loadingText:Pe.total>1?c("queue.addingProgress",{current:Pe.current,total:Pe.total}):c("queue.adding")}}return{title:c("queue.editQueueItem"),icon:Yi,submitText:c("common.save"),submitIcon:Yi,loadingText:Pe.total>1?c("queue.savingProgress",{current:Pe.current,total:Pe.total}):c("common.saving")}})(),We=kt.icon,yt=kt.submitIcon,wt=$&&!g&&(p||(Ie?v!==null:!0));return i.jsxs("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:le?void 0:o,children:[i.jsx(Mt,{className:"w-full max-w-2xl max-h-[90vh] overflow-y-auto",onClick:_t=>_t.stopPropagation(),children:i.jsxs(Dt,{className:t==="reprint"?"":"p-0",children:[i.jsxs("div",{className:`flex items-center justify-between ${t==="reprint"?"mb-4":"p-4 border-b border-bambu-dark-tertiary"}`,children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(We,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:kt.title})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:o,disabled:le,children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:Ve,className:t==="reprint"?"":"p-4 space-y-4",children:[i.jsx("p",{className:`text-sm text-bambu-gray ${t==="reprint"?"mb-4":""}`,children:t==="reprint"?i.jsxs(i.Fragment,{children:["Send ",i.jsx("span",{className:"text-white",children:r})," to"," ",s?.length===1&&J?i.jsx("span",{className:"text-white",children:J.find(_t=>_t.id===s[0])?.name??"printer(s)"}):"printer(s)"]}):i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"block text-bambu-gray mb-1",children:"Print Job"}),i.jsx("span",{className:"text-white font-medium truncate block",children:r})]})}),i.jsx(Hqe,{plates:Ce,isMultiPlate:Ie,selectedPlate:v,onSelect:x,queueAll:g,onQueueAllChange:t==="add-to-queue"?_:void 0}),!s?.length&&i.jsx(Vqe,{printers:J||[],selectedPrinterIds:f,onMultiSelect:y,isLoading:W,allowMultiple:!0,showInactive:t==="edit-queue-item",disableBusy:t==="reprint",printerMappingResults:Ae.printerResults,filamentReqs:Se,onAutoConfigurePrinter:Ae.autoConfigurePrinter,onUpdatePrinterConfig:Ae.updatePrinterConfig,assignmentMode:t==="reprint"?"printer":H,onAssignmentModeChange:t!=="reprint"?z:void 0,targetModel:G,onTargetModelChange:t!=="reprint"?I:void 0,targetLocation:ee,onTargetLocationChange:t!=="reprint"?ie:void 0,slicedForModel:ye}),H==="model"&&G&&Se&&qe&&qe.length>0&&i.jsx(Bqe,{filamentReqs:Se,availableFilaments:qe,overrides:X,onChange:me,forceColorMatch:he,onForceColorMatchChange:(_t,Ot)=>ge(Vt=>({...Vt,[_t]:Ot}))}),ye&&H==="printer"&&f.length===1&&(()=>{const _t=J?.find(Ot=>Ot.id===f[0]);return _t&&_t.model&&ye!==_t.model?i.jsxs("div",{className:"p-3 mb-2 bg-yellow-500/10 border border-yellow-500/30 rounded-lg flex items-center gap-2",children:[i.jsx(Mn,{className:"w-4 h-4 text-yellow-400 flex-shrink-0"}),i.jsxs("span",{className:"text-sm text-yellow-400",children:["File was sliced for ",ye,", but printing on ",_t.model]})]}):null})(),Ne&&i.jsxs("div",{className:"flex items-start gap-2 p-3 mb-2 bg-orange-500/10 border border-orange-500/30 rounded-lg text-sm",children:[i.jsx(Li,{className:"w-4 h-4 text-orange-400 mt-0.5 flex-shrink-0"}),i.jsx("p",{className:"text-orange-400",children:"Archive data unavailable. The source file may have been deleted. Filament mapping is disabled."})]}),wt&&!Ne&&f.length===1&&i.jsx(Uqe,{printerId:$,filamentReqs:Se,manualMappings:k,onManualMappingChange:R,defaultExpanded:!!s?.length||(ne?.per_printer_mapping_expanded??!1),currencySymbol:O,defaultCostPerKg:V}),(t==="reprint"||K>0||H==="model"&&G)&&i.jsx(Wqe,{options:N,onChange:T,defaultExpanded:!!s?.length}),t!=="reprint"&&i.jsx(Kqe,{options:C,onChange:A,dateFormat:ne?.date_format||"system",timeFormat:ne?.time_format||"system",canControlPrinter:m("printers:control")}),De.isError&&i.jsx("div",{className:"mb-4 p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:De.error?.message||"Failed to complete operation"}),i.jsxs("div",{className:`flex gap-3 ${t==="reprint"?"":"pt-2"}`,children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:o,className:"flex-1",disabled:le,children:"Cancel"}),i.jsx(Oe,{type:"submit",disabled:!xt,className:"flex-1",children:it?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),kt.loadingText]}):i.jsxs(i.Fragment,{children:[i.jsx(yt,{className:"w-4 h-4"}),kt.submitText]})})]})]})]})}),Z&&Z.length>0&&i.jsx(Sn,{title:c("printModal.insufficientFilamentTitle"),message:$e,confirmText:c("printModal.printAnyway"),cancelText:c("common.cancel"),variant:"warning",onConfirm:()=>{j(null),Ve(void 0,{skipFilamentCheck:!0})},onCancel:()=>j(null)})]})}function gW({value:t}){const{t:e}=Ft(),[n,r]=w.useState(!1),a=async()=>{try{await navigator.clipboard.writeText(t),r(!0),setTimeout(()=>r(!1),2e3)}catch{}};return i.jsx("button",{onClick:a,className:"ml-2 p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",title:e(n?"printers.copied":"printers.copyToClipboard"),children:n?i.jsx(Yr,{className:"w-3.5 h-3.5 text-bambu-green"}):i.jsx(fo,{className:"w-3.5 h-3.5"})})}function Xqe({printer:t,status:e,totalPrintHours:n,onClose:r}){const{t:a}=Ft();w.useEffect(()=>{const o=l=>{l.key==="Escape"&&r()};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[r]);const s=[];if(s.push({label:a("printers.model"),value:t.model??"—"}),s.push({label:a("common.status"),value:i.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-xs font-medium ${e?.connected?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:[i.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${e?.connected?"bg-bambu-green":"bg-red-400"}`}),e?.connected?a("printers.status.available"):a("printers.status.offline")]})}),e?.state){const o={IDLE:"printers.status.idle",RUNNING:"printers.status.printing",PAUSE:"printers.status.paused",FINISH:"printers.status.finished",FAILED:"printers.status.error"};s.push({label:a("printers.state"),value:a(o[e.state]??"printers.status.unknown")})}if(s.push({label:a("printers.ipAddress"),value:i.jsxs("span",{className:"flex items-center",children:[i.jsx("span",{className:"font-mono",children:t.ip_address}),i.jsx(gW,{value:t.ip_address})]})}),s.push({label:a("printers.serialNumber"),value:i.jsxs("span",{className:"flex items-center",children:[i.jsx("span",{className:"font-mono truncate",children:t.serial_number}),i.jsx(gW,{value:t.serial_number})]})}),e?.wired_network)s.push({label:a("printers.networkLabel","Network"),value:i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(zL,{className:"w-4 h-4 text-bambu-green"}),i.jsx("span",{className:"text-bambu-green",children:a("printers.connection.ethernet","Ethernet")})]})});else if(e?.wifi_signal!=null){const o=RZ(e.wifi_signal);s.push({label:a("printers.wifiSignalLabel"),value:i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(QX,{className:`w-4 h-4 ${o.color}`}),i.jsx("span",{className:o.color,children:a(o.labelKey)}),i.jsxs("span",{className:"text-bambu-gray text-xs",children:["(",e.wifi_signal," dBm)"]})]})})}return s.push({label:a("printers.firmware"),value:e?.firmware_version??"—"}),e?.developer_mode!=null&&s.push({label:a("printers.developerMode"),value:i.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${e.developer_mode?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:e.developer_mode?a("printers.enabled"):a("printers.disabled")})}),s.push({label:a("printers.nozzleCount"),value:t.nozzle_count}),e?.sdcard!=null&&s.push({label:a("printers.sdCard"),value:i.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${e.sdcard?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:e.sdcard?a("printers.inserted"):a("printers.notInserted")})}),s.push({label:a("printers.autoArchive"),value:i.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${t.auto_archive?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:t.auto_archive?a("printers.enabled"):a("printers.disabled")})}),n!=null&&n>0&&s.push({label:a("printers.totalPrintHours"),value:`${Math.round(n)}h`}),t.location&&s.push({label:a("printers.sort.location"),value:t.location}),s.push({label:a("printers.addedOn"),value:_f(t.created_at)}),i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",role:"dialog","aria-modal":"true",onClick:r,children:i.jsx(Mt,{className:"w-full max-w-md",onClick:o=>o.stopPropagation(),children:i.jsxs(Dt,{children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:t.name}),i.jsx("button",{onClick:r,className:"p-1 hover:bg-bambu-dark rounded flex-shrink-0",children:i.jsx(Ht,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsx("div",{className:"flex justify-center mb-4",children:i.jsx("img",{src:DZ(t.model),alt:t.model??t.name,className:"h-24 object-contain"})}),i.jsx("div",{className:"space-y-0",children:s.map((o,l)=>i.jsxs("div",{className:"flex items-center justify-between gap-4 py-2.5 border-b border-bambu-dark-tertiary last:border-0",children:[i.jsx("span",{className:"text-sm text-bambu-gray whitespace-nowrap",children:o.label}),i.jsx("span",{className:"text-sm text-white text-right",children:o.value})]},l))})]})})})}function Qqe(t){if(!t||t.length<6)return!1;const e=parseInt(t.slice(0,2),16),n=parseInt(t.slice(2,4),16),r=parseInt(t.slice(4,6),16);return(.299*e+.587*n+.114*r)/255>.6}function Vj({trayColor:t,trayType:e,isEmpty:n,slotNumber:r}){return i.jsx("div",{className:"w-3.5 h-3.5 rounded-full mx-auto mb-0.5 border-2 flex items-center justify-center",style:{backgroundColor:t?`#${t}`:e?"#333":"transparent",borderColor:n?"#666":"rgba(255,255,255,0.1)",borderStyle:n?"dashed":"solid"},children:i.jsx("span",{className:"text-[6px] font-bold leading-none select-none",style:{color:t&&Qqe(t)?"#000":"#fff"},children:r})})}const bW={"A00-W1":"Jade White","A00-P0":"Beige","A00-D2":"Light Gray","A00-Y0":"Yellow","A00-Y2":"Sunflower Yellow","A00-A1":"Pumpkin Orange","A00-A0":"Orange","A00-Y4":"Gold","A00-G3":"Bright Green","A00-G1":"Bambu Green","A00-G2":"Mistletoe Green","A00-R3":"Hot Pink","A00-P6":"Magenta","A00-R0":"Red","A00-R2":"Maroon Red","A00-P5":"Purple","A00-P2":"Indigo Purple","A00-B5":"Turquoise","A00-B8":"Cyan","A00-B3":"Cobalt Blue","A00-N0":"Brown","A00-N1":"Cocoa Brown","A00-Y3":"Bronze","A00-D0":"Gray","A00-D1":"Silver","A00-B1":"Blue Grey","A00-D3":"Dark Gray","A00-K0":"Black","A00-M3":"Pink Citrus","A00-M6":"Dusk Glare","A00-M0":"Arctic Whisper","A00-M1":"Solar Breeze","A00-M5":"Blueberry Bubblegum","A00-M4":"Mint Lime","A00-M2":"Ocean to Meadow","A00-M7":"Cotton Candy Cloud","A18-K0":"Black","A18-D0":"Gray","A18-W0":"White","A18-R0":"Red","A18-Y0":"Yellow","A18-B0":"Cyan","A18-B1":"Blue","A18-P0":"Matte Beige","A01-W2":"Ivory White","A01-W3":"Bone White","A01-Y2":"Lemon Yellow","A01-A2":"Mandarin Orange","A01-P3":"Sakura Pink","A01-P4":"Lilac Purple","A01-R3":"Plum","A01-R1":"Scarlet Red","A01-R4":"Dark Red","A01-G0":"Apple Green","A01-G1":"Grass Green","A01-G7":"Dark Green","A01-B4":"Ice Blue","A01-B0":"Sky Blue","A01-B3":"Marine Blue","A01-B6":"Dark Blue","A01-Y3":"Desert Tan","A01-N1":"Latte Brown","A01-N3":"Caramel","A01-R2":"Terracotta","A01-N2":"Dark Brown","A01-N0":"Dark Chocolate","A01-D3":"Ash Gray","A01-D0":"Nardo Gray","A01-K1":"Charcoal","A12-G0":"Green","A12-R0":"Pink","A12-A0":"Orange","A12-Y0":"Yellow","A12-B0":"Blue","A07-R5":"Red Granite","A07-D4":"White Marble","A11-W0":"White","A11-K0":"Black","A08-G3":"Alpine Green Sparkle","A08-D5":"Slate Gray Sparkle","A08-B7":"Royal Purple Sparkle","A08-R2":"Crimson Red Sparkle","A08-K2":"Onyx Black Sparkle","A08-Y1":"Classic Gold Sparkle","A02-B2":"Cobalt Blue Metallic","A02-G2":"Oxide Green Metallic","A02-Y1":"Iridium Gold Metallic","A02-D2":"Iron Gray Metallic","A17-B1":"Blue","A17-A0":"Orange","A17-P0":"Purple","A06-Y1":"Gold","A06-D0":"Titan Gray","A06-D1":"Silver","A06-W0":"White","A06-R0":"Candy Red","A06-G0":"Candy Green","A06-G1":"Mint","A06-B1":"Blue","A06-B0":"Baby Blue","A06-P0":"Purple","A06-R1":"Rose Gold","A06-R2":"Pink","A06-Y0":"Champagne","A05-M8":"Dawn Radiance","A05-M4":"Aurora Purple","A05-M1":"South Beach","A05-T3":"Neon City","A05-T2":"Midnight Blaze","A05-T1":"Gilded Rose","A05-T4":"Blue Hawaii","A05-T5":"Velvet Eclipse","A15-B0":"Purple","A15-G0":"Green","A15-G1":"Nebulae","A15-R0":"Brown","A16-K0":"Black Walnut","A16-R0":"Rosewood","A16-N0":"Clay Brown","A16-G0":"Classic Birch","A16-W0":"White Oak","A16-Y0":"Ochre Yellow","A50-D6":"Lava Gray","A50-K0":"Black","A50-B6":"Royal Blue","A10-W0":"White","A10-D0":"Gray","A09-B5":"Lavender Blue","A09-B4":"Light Blue","A09-A0":"Orange","A09-D1":"Silver","A09-R3":"Vermilion Red","A09-Y0":"Yellow","G02-K0":"Black","G02-W0":"White","G02-R0":"Red","G02-D0":"Gray","G02-D1":"Dark Gray","G02-Y1":"Cream","G02-Y0":"Yellow","G02-A0":"Orange","G02-N1":"Peanut Brown","G02-G1":"Lime Green","G02-G0":"Green","G02-G2":"Forest Green","G02-B1":"Lake Blue","G02-B0":"Blue","G01-G1":"Translucent Teal","G01-B0":"Translucent Light Blue","G01-C0":"Clear","G01-D0":"Translucent Gray","G01-G0":"Translucent Olive","G01-N0":"Translucent Brown","G01-A0":"Translucent Orange","G01-P1":"Translucent Pink","G01-P0":"Translucent Purple","G50-P7":"Violet Purple","G50-K0":"Black","B00-D1":"Silver","B00-K0":"Black","B00-W0":"White","B00-G6":"Bambu Green","B00-G7":"Olive","B00-Y1":"Tangerine Yellow","B00-A0":"Orange","B00-R0":"Red","B00-B4":"Azure","B00-B0":"Blue","B00-B6":"Navy Blue","B50-A0":"Orange","B50-K0":"Black","B01-W0":"White","B01-K0":"Black","B01-D0":"Gray","B02-W0":"White","C00-C1":"Transparent","C00-C0":"Clear Black","C00-K0":"Black","C00-W0":"White","C01-K0":"Black","U02-B0":"Blue","U02-D0":"Gray","U02-K0":"Black","N04-K0":"Black","N08-K0":"Black","S02-W0":"Nature","S02-W1":"White","S05-C0":"Black","S06-W0":"White","S03-G1":"Green","S04-Y0":"Clear"},Zqe={W0:"White",W1:"Jade White",W2:"Ivory White",W3:"Bone White",Y0:"Yellow",Y1:"Gold",Y2:"Sunflower Yellow",Y3:"Bronze",Y4:"Gold",A0:"Orange",A1:"Pumpkin Orange",A2:"Mandarin Orange",R0:"Red",R1:"Scarlet Red",R2:"Maroon Red",R3:"Hot Pink",R4:"Dark Red",R5:"Red Granite",P0:"Beige",P1:"Pink",P2:"Indigo Purple",P3:"Sakura Pink",P4:"Lilac Purple",P5:"Purple",P6:"Magenta",P7:"Violet Purple",B0:"Blue",B1:"Blue Grey",B2:"Cobalt Blue",B3:"Cobalt Blue",B4:"Ice Blue",B5:"Turquoise",B6:"Navy Blue",B7:"Royal Purple",B8:"Cyan",G0:"Green",G1:"Grass Green",G2:"Mistletoe Green",G3:"Bright Green",G6:"Bambu Green",G7:"Dark Green",N0:"Brown",N1:"Peanut Brown",N2:"Dark Brown",N3:"Caramel",D0:"Gray",D1:"Silver",D2:"Light Gray",D3:"Dark Gray",D4:"White Marble",D5:"Slate Gray",D6:"Lava Gray",K0:"Black",K1:"Charcoal",K2:"Onyx Black",C0:"Clear Black",C1:"Transparent",M0:"Arctic Whisper",M1:"Solar Breeze",M2:"Ocean to Meadow",M3:"Pink Citrus",M4:"Aurora Purple",M5:"Blueberry Bubblegum",M6:"Dusk Glare",M7:"Cotton Candy Cloud",M8:"Dawn Radiance",T1:"Gilded Rose",T2:"Midnight Blaze",T3:"Neon City",T4:"Blue Hawaii",T5:"Velvet Eclipse"};function Gj(t){if(!t)return null;if(bW[t])return bW[t];const e=t.split("-");if(e.length<2)return null;const n=e[1];return Zqe[n]||null}function Wj(t){return(t??.02).toFixed(3)}function xW({side:t}){const{mode:e}=Wf(),n=e==="dark"?"#1a4d2e":"#e7f5e9";return i.jsx("span",{className:"inline-flex items-center justify-center w-4 h-4 text-[10px] font-bold rounded",style:{backgroundColor:n,color:"#00ae42"},children:t})}function nie(t,e){if(!t)return"";if(t.includes("hardened"))return e("printers.nozzleHardenedSteel");if(t.includes("stainless"))return e("printers.nozzleStainlessSteel");if(t.includes("tungsten"))return e("printers.nozzleTungstenCarbide");if(t.length>=4){const n=t.slice(2,4);if(n==="00")return e("printers.nozzleStainlessSteel");if(n==="01")return e("printers.nozzleHardenedSteel");if(n==="05")return e("printers.nozzleTungstenCarbide")}return t==="00"?e("printers.nozzleStainlessSteel"):t==="01"?e("printers.nozzleHardenedSteel"):t==="05"?e("printers.nozzleTungstenCarbide"):t.startsWith("H")?e("printers.nozzleHardenedSteel"):t}function rie(t,e){return t?t.startsWith("HH")?e("printers.nozzleHighFlow"):t.startsWith("HS")?e("printers.nozzleStandardFlow"):"":""}function iie({slot:t,index:e,activeStatus:n,filamentName:r,children:a}){const{t:s}=Ft(),[o,l]=w.useState(!1),[c,u]=w.useState("top"),d=w.useRef(null),m=w.useRef(null),p=w.useRef(null),f=!t.nozzle_diameter&&!t.nozzle_type,y=t.stat===1;w.useEffect(()=>{if(o&&d.current&&m.current){const T=d.current.getBoundingClientRect(),C=m.current.offsetHeight,k=T.top-56,R=window.innerHeight-T.bottom;kk?u("bottom"):u("top")}},[o]);const v=()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>l(!0),80)},x=()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>l(!1),100)};w.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]);const g=A4(t.filament_color),_=nie(t.nozzle_type,s),N=rie(t.nozzle_type,s);return i.jsxs("div",{ref:d,className:"relative",onMouseEnter:v,onMouseLeave:x,children:[a,o&&i.jsxs("div",{ref:m,className:` absolute left-1/2 -translate-x-1/2 z-50 ${c==="top"?"bottom-full mb-2":"top-full mt-2"} @@ -8538,7 +8538,7 @@ ${o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("co flex items-center justify-center gap-1 px-3 py-1.5 rounded-lg text-xs font-medium transition-colors ${rn&&C("printers:control")?Pt?"bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30":"bg-yellow-500/20 text-yellow-400 hover:bg-yellow-500/30":"bg-bambu-dark text-bambu-gray/50 cursor-not-allowed"} - `,title:C("printers:control")?g(Pt?"printers.resume":"printers.pause"):g("printers.permission.noControl"),children:[Pt?i.jsx(go,{className:"w-3 h-3"}):i.jsx(tT,{className:"w-3 h-3"}),g(Pt?"printers.resume":"printers.pause")]})]})]})]})})(),(ct?.length>0||Qe.vt_tray.length>0)&&r==="expanded"&&(()=>{const mt=ct.filter(rt=>rt.tray.length>1),Pt=ct.filter(rt=>rt.tray.length===1),rn=t.nozzle_count===2||Qe?.temperatures?.nozzle_2!==void 0;return i.jsxs("div",{className:"mt-3",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx("span",{className:"text-[10px] uppercase tracking-wider text-bambu-gray font-medium",children:g("printers.filaments")}),i.jsx("div",{className:"flex-1 h-px bg-bambu-dark-tertiary/30"})]}),i.jsxs("div",{className:"space-y-3",children:[mt.length>0&&i.jsx("div",{className:"grid grid-cols-2 gap-3",children:mt.map(rt=>{const un=Me[String(rt.id)],In=rt.id>=128?rt.id-128:rt.id,Vn=un!==void 0?un:In,Na=Vn===1,_o=Vn===0;return i.jsxs("div",{className:"p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary/30",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx(_W,{ams:rt,printerId:t.id,label:gl(rt.id,rt.tray.length),amsLabels:ut,canEdit:C("printers:update"),onSaved:Ze,children:i.jsx("span",{className:"text-[10px] text-white font-medium cursor-default select-none",children:ut?.[rt.id]||gl(rt.id,rt.tray.length)})}),rn&&(Na||_o)&&i.jsx(xW,{side:Na?"L":"R"})]}),(rt.humidity!=null||rt.temp!=null)&&i.jsxs("div",{className:"flex items-center gap-1.5 max-[550px]:flex-col max-[550px]:items-start",children:[rt.humidity!=null&&i.jsx(vW,{humidity:rt.humidity,goodThreshold:s?.humidityGood,fairThreshold:s?.humidityFair,onClick:()=>je({amsId:rt.id,amsLabel:gl(rt.id,rt.tray.length),mode:"humidity"}),compact:!0}),rt.temp!=null&&i.jsx(wW,{temp:rt.temp,goodThreshold:s?.tempGood,fairThreshold:s?.tempFair,onClick:()=>je({amsId:rt.id,amsLabel:gl(rt.id,rt.tray.length),mode:"temperature"}),compact:!0}),Qe.supports_drying&&(rt.module_type==="n3f"||rt.module_type==="n3s")&&C("printers:control")&&i.jsx("button",{disabled:!!(rt.dry_sf_reason?.length&&rt.dry_time===0),onClick:ln=>{if(rt.dry_time>0)$r.mutate(rt.id);else if(ue===rt.id)fe(null);else{const Cs=(rt.tray.find(Xs=>Xs.tray_type)?.tray_type||"PLA").split(" ")[0].toUpperCase(),Ts=x[Cs]||x.PLA,rl=rt.module_type;F(Cs),ve(Ts[rl]||Ts.n3f),de(rl==="n3s"?Ts.n3s_hours:Ts.n3f_hours),ae(rt.module_type),fe(rt.id);const ec=ln.currentTarget.getBoundingClientRect();Se({top:ec.bottom+4,left:Math.max(8,ec.right-240)})}},className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[9px] transition-colors ${rt.dry_time>0?"bg-amber-500/20 text-amber-400":rt.dry_sf_reason?.length?"bg-bambu-dark-tertiary/30 text-bambu-gray/50 cursor-not-allowed":"bg-bambu-dark-tertiary/50 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,title:rt.dry_time>0?g("printers.drying.stop"):rt.dry_sf_reason?.length?g("printers.drying.powerRequired"):g("printers.drying.start"),children:i.jsx(Fp,{className:"w-3 h-3"})})]})]}),rt.dry_time>0&&i.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 mb-1 bg-amber-500/10 border border-amber-500/20 rounded text-[9px]",children:[i.jsx(Fp,{className:"w-3 h-3 text-amber-400 shrink-0"}),i.jsx("span",{className:"text-amber-400 font-medium",children:g("printers.drying.active")}),i.jsx("span",{className:"text-amber-300/70",children:g("printers.drying.timeRemaining",{time:rt.dry_time>=60?`${Math.floor(rt.dry_time/60)}h ${rt.dry_time%60}m`:`${rt.dry_time}m`})}),i.jsx("button",{onClick:()=>$r.mutate(rt.id),disabled:$r.isPending,className:"ml-auto text-amber-400 hover:text-amber-300 transition-colors disabled:opacity-50",title:g("printers.drying.stop"),children:i.jsx(Ht,{className:"w-3 h-3"})})]}),i.jsx("div",{className:"grid grid-cols-4 gap-1.5",children:[0,1,2,3].map(ln=>{const zn=rt.tray[ln]||rt.tray.find(Nn=>Nn.id===ln),Cs=zn?.tray_type&&zn.remain>=0,Ts=!zn?.tray_type,rl=rt.id*4+ln,ec=Ut===rl,Xs=zn?.tray_info_idx?Fe?.[zn.tray_info_idx]:null,gi=tt?.[rl],Ia=(zn?.tray_uuid||zn?.tag_uid||xb(t.serial_number,rt.id,ln))?.toUpperCase(),tc=Ia?l?.[Ia]:void 0,za=Xj(tc),No=d?.(t.id,rt.id,ln),jc=(()=>{const Nn=No?.spool;return Nn&&Nn.label_weight>0&&Nn.weight_used!=null?Math.round(Math.max(0,Nn.label_weight-Nn.weight_used)/Nn.label_weight*100):null})(),ti=jc===0&&Cs&&zn.remain>0?null:jc,ko=za??ti??(Cs?zn.remain:null),iy=za!==null?"spoolman":ti!==null?"inventory":Cs?"ams":void 0,ni=zn?.tray_type?{vendor:Qj(zn)?"Bambu Lab":"Generic",profile:gi?.preset_name||Xs?.name||No?.spool?.slicer_filament_name||zn.tray_sub_brands||zn.tray_type,colorName:Gj(zn.tray_id_name)||dN(zn.tray_color),colorHex:zn.tray_color||null,kFactor:Wj(zn.k),fillLevel:ko,trayUuid:zn.tray_uuid||null,tagUid:zn.tag_uid||null,fillSource:iy}:null,Au=_s?.amsId===rt.id&&_s?.slotId===ln,Jh=i.jsxs("div",{className:`bg-bambu-dark-tertiary rounded p-1 text-center ${Ts?"opacity-50":""} ${ec?"ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark":""}`,children:[i.jsx(Vj,{trayColor:zn?.tray_color,trayType:zn?.tray_type,isEmpty:Ts,slotNumber:ln+1}),i.jsx("div",{className:"text-[9px] text-white font-bold truncate",children:zn?.tray_type||"—"}),i.jsx("div",{className:"mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden",children:ko!==null&&ko>=0&&zn&&i.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${ko}%`,backgroundColor:Yj(ko)}})})]});return i.jsxs("div",{className:"relative group",children:[Au&&i.jsx("div",{className:"absolute inset-0 bg-bambu-dark-tertiary/80 rounded flex items-center justify-center z-20",children:i.jsx(wr,{className:"w-4 h-4 text-bambu-green animate-spin"})}),Qe?.state!=="RUNNING"&&i.jsx("button",{onClick:Nn=>{Nn.stopPropagation(),Ni(on?.amsId===rt.id&&on?.slotId===ln?null:{amsId:rt.id,slotId:ln})},className:"absolute -top-1 -right-1 w-4 h-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity z-10 hover:bg-bambu-dark-tertiary",title:g("printers.slotOptions"),children:i.jsx(ph,{className:"w-2.5 h-2.5 text-bambu-gray"})}),Qe?.state!=="RUNNING"&&on?.amsId===rt.id&&on?.slotId===ln&&i.jsx("div",{className:"absolute top-full left-0 mt-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]",children:i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-xs flex items-center gap-2 ${C("printers:ams_rfid")?"text-white hover:bg-bambu-dark-tertiary":"text-bambu-gray/50 cursor-not-allowed"}`,onClick:Nn=>{Nn.stopPropagation(),C("printers:ams_rfid")&&(Jo.mutate({amsId:rt.id,slotId:ln}),Ni(null))},disabled:Au||!C("printers:ams_rfid"),title:C("printers:ams_rfid")?void 0:g("printers.permission.noAmsRfid"),children:[i.jsx(wr,{className:`w-3 h-3 ${Au?"animate-spin":""}`}),g("printers.rfid.reread")]})}),ni?i.jsx(Hj,{data:ni,spoolman:{enabled:o,linkedSpoolId:Ia?l?.[Ia]?.id:void 0,spoolmanUrl:c,syncMode:u,onLinkSpool:o?()=>{const Nn=(ni.trayUuid||ni.tagUid||xb(t.serial_number,rt.id,ln)).toUpperCase();ce({tagUid:ni.tagUid||Nn,trayUuid:ni.trayUuid||"",printerId:t.id,amsId:rt.id,trayId:ln})}:void 0,onUnlinkSpool:tc?.id?()=>_a.mutate(tc.id):void 0},inventory:o?void 0:(()=>{const Nn=d?.(t.id,rt.id,ln);return{assignedSpool:Nn?.spool?{id:Nn.spool.id,material:Nn.spool.material,brand:Nn.spool.brand,color_name:Nn.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(Nn.spool.label_weight-Nn.spool.weight_used))}:null,onAssignSpool:ni.vendor!=="Bambu Lab"?()=>Ce({printerId:t.id,amsId:rt.id,trayId:ln,trayInfo:{type:zn?.tray_type||ni.profile,material:zn?.tray_type??void 0,profile:ni.profile,color:ni.colorHex||"",location:`${gl(rt.id,rt.tray.length)} Slot ${ln+1}`}}):void 0,onUnassignSpool:Nn&&ni.vendor!=="Bambu Lab"?()=>m?.(t.id,rt.id,ln):void 0}})(),configureSlot:{enabled:C("printers:control"),onConfigure:()=>$e({amsId:rt.id,trayId:ln,trayCount:rt.tray.length,trayType:zn?.tray_type||void 0,trayColor:zn?.tray_color||void 0,traySubBrands:zn?.tray_sub_brands||void 0,trayInfoIdx:zn?.tray_info_idx||void 0,extruderId:un,caliIdx:zn?.cali_idx,savedPresetId:gi?.preset_id})},children:Jh}):i.jsx($j,{configureSlot:{enabled:C("printers:control"),onConfigure:()=>$e({amsId:rt.id,trayId:ln,trayCount:rt.tray.length,extruderId:un})},inventory:o?void 0:{onAssignSpool:()=>Ce({printerId:t.id,amsId:rt.id,trayId:ln,trayInfo:{type:"",color:"",location:`${gl(rt.id,rt.tray.length)} Slot ${ln+1}`}})},children:Jh})]},ln)})})]},rt.id)})}),(Pt.length>0||Qe.vt_tray.length>0)&&i.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[Pt.map(rt=>{const un=Me[String(rt.id)],In=rt.id>=128?rt.id-128:rt.id,Vn=un!==void 0?un:In,Na=Vn===1,_o=Vn===0,ln=rt.tray[0],zn=ln?.tray_type&&ln.remain>=0,Cs=!ln?.tray_type,Ts=G0(rt.id,ln?.id??0,!1),rl=Ut===Ts,ec=ln?.tray_info_idx?Fe?.[ln.tray_info_idx]:null,Xs=tt?.[Ts],gi=ln?.id??0,Ia=(ln?.tray_uuid||ln?.tag_uid||xb(t.serial_number,rt.id,gi))?.toUpperCase(),tc=Ia?l?.[Ia]:void 0,za=Xj(tc),No=d?.(t.id,rt.id,gi),jc=(()=>{const Nn=No?.spool;return Nn&&Nn.label_weight>0&&Nn.weight_used!=null?Math.round(Math.max(0,Nn.label_weight-Nn.weight_used)/Nn.label_weight*100):null})(),ti=jc===0&&zn&&ln.remain>0?null:jc,ko=za??ti??(zn?ln.remain:null),iy=za!==null?"spoolman":ti!==null?"inventory":zn?"ams":void 0,ni=ln?.tray_type?{vendor:Qj(ln)?"Bambu Lab":"Generic",profile:Xs?.preset_name||ec?.name||No?.spool?.slicer_filament_name||ln.tray_sub_brands||ln.tray_type,colorName:Gj(ln.tray_id_name)||dN(ln.tray_color),colorHex:ln.tray_color||null,kFactor:Wj(ln.k),fillLevel:ko,trayUuid:ln.tray_uuid||null,tagUid:ln.tag_uid||null,fillSource:iy}:null,Au=_s?.amsId===rt.id&&_s?.slotId===gi,Jh=i.jsxs("div",{className:`bg-bambu-dark-tertiary rounded p-1 text-center ${Cs?"opacity-50":""} ${rl?"ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark":""}`,children:[i.jsx(Vj,{trayColor:ln?.tray_color,trayType:ln?.tray_type,isEmpty:Cs,slotNumber:1}),i.jsx("div",{className:"text-[9px] text-white font-bold truncate",children:ln?.tray_type||"—"}),i.jsx("div",{className:"mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden",children:ko!==null&&ko>=0&&i.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${ko}%`,backgroundColor:Yj(ko)}})})]});return i.jsxs("div",{className:"p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary/30",children:[i.jsxs("div",{className:"flex items-center gap-1 mb-2",children:[i.jsx(_W,{ams:rt,printerId:t.id,label:gl(rt.id,rt.tray.length),amsLabels:ut,canEdit:C("printers:update"),onSaved:Ze,children:i.jsx("span",{className:"text-[10px] text-white font-medium cursor-default select-none",children:ut?.[rt.id]||gl(rt.id,rt.tray.length)})}),rn&&(Na||_o)&&i.jsx(xW,{side:Na?"L":"R"}),Qe.supports_drying&&(rt.module_type==="n3f"||rt.module_type==="n3s")&&C("printers:control")&&i.jsx("div",{className:"relative ml-auto",children:i.jsx("button",{onClick:Nn=>{if(rt.dry_time>0)$r.mutate(rt.id);else if(ue===rt.id)fe(null);else{const em=(rt.tray.find(Zw=>Zw.tray_type)?.tray_type||"PLA").split(" ")[0].toUpperCase(),tg=x[em]||x.PLA,ay=rt.module_type;F(em),ve(tg[ay]||tg.n3f),de(ay==="n3s"?tg.n3s_hours:tg.n3f_hours),ae(rt.module_type),fe(rt.id);const sy=Nn.currentTarget.getBoundingClientRect();Se({top:sy.bottom+4,left:Math.max(8,sy.right-240)})}},className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[9px] transition-colors ${rt.dry_time>0?"bg-amber-500/20 text-amber-400":"bg-bambu-dark-tertiary/50 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,title:rt.dry_time>0?g("printers.drying.stop"):g("printers.drying.start"),children:i.jsx(Fp,{className:"w-3 h-3"})})})]}),rt.dry_time>0&&i.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 mb-1 bg-amber-500/10 border border-amber-500/20 rounded text-[9px] whitespace-nowrap overflow-hidden",children:[i.jsx(Fp,{className:"w-3 h-3 text-amber-400 shrink-0"}),i.jsx("span",{className:"text-amber-300/70 text-[8px] truncate",children:rt.dry_time>=60?`${Math.floor(rt.dry_time/60)}h ${rt.dry_time%60}m`:`${rt.dry_time}m`}),i.jsx("button",{onClick:()=>$r.mutate(rt.id),disabled:$r.isPending,className:"ml-auto text-amber-400 hover:text-amber-300 transition-colors disabled:opacity-50 shrink-0",title:g("printers.drying.stop"),children:i.jsx(Ht,{className:"w-3 h-3"})})]}),i.jsxs("div",{className:"flex gap-1.5 max-[550px]:flex-col max-[550px]:items-start",children:[i.jsxs("div",{className:"relative group flex-1 max-[550px]:w-full",children:[Au&&i.jsx("div",{className:"absolute inset-0 bg-bambu-dark-tertiary/80 rounded flex items-center justify-center z-20",children:i.jsx(wr,{className:"w-4 h-4 text-bambu-green animate-spin"})}),Qe?.state!=="RUNNING"&&i.jsx("button",{onClick:Nn=>{Nn.stopPropagation(),Ni(on?.amsId===rt.id&&on?.slotId===gi?null:{amsId:rt.id,slotId:gi})},className:"absolute -top-1 -right-1 w-4 h-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity z-10 hover:bg-bambu-dark-tertiary",title:g("printers.slotOptions"),children:i.jsx(ph,{className:"w-2.5 h-2.5 text-bambu-gray"})}),Qe?.state!=="RUNNING"&&on?.amsId===rt.id&&on?.slotId===gi&&i.jsx("div",{className:"absolute top-full left-0 mt-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]",children:i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-xs flex items-center gap-2 ${C("printers:ams_rfid")?"text-white hover:bg-bambu-dark-tertiary":"text-bambu-gray/50 cursor-not-allowed"}`,onClick:Nn=>{Nn.stopPropagation(),C("printers:ams_rfid")&&(Jo.mutate({amsId:rt.id,slotId:gi}),Ni(null))},disabled:Au||!C("printers:ams_rfid"),title:C("printers:ams_rfid")?void 0:g("printers.permission.noAmsRfid"),children:[i.jsx(wr,{className:`w-3 h-3 ${Au?"animate-spin":""}`}),g("printers.rfid.reread")]})}),ni?i.jsx(Hj,{data:ni,spoolman:{enabled:o,linkedSpoolId:Ia?l?.[Ia]?.id:void 0,spoolmanUrl:c,syncMode:u,onLinkSpool:o?()=>{const Nn=(ni.trayUuid||ni.tagUid||xb(t.serial_number,rt.id,gi)).toUpperCase();ce({tagUid:ni.tagUid||Nn,trayUuid:ni.trayUuid||"",printerId:t.id,amsId:rt.id,trayId:gi})}:void 0,onUnlinkSpool:tc?.id?()=>_a.mutate(tc.id):void 0},inventory:o?void 0:(()=>{const Nn=d?.(t.id,rt.id,gi);return{assignedSpool:Nn?.spool?{id:Nn.spool.id,material:Nn.spool.material,brand:Nn.spool.brand,color_name:Nn.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(Nn.spool.label_weight-Nn.spool.weight_used))}:null,onAssignSpool:ni.vendor!=="Bambu Lab"?()=>Ce({printerId:t.id,amsId:rt.id,trayId:gi,trayInfo:{type:ln?.tray_type||ni.profile,material:ln?.tray_type??void 0,profile:ni.profile,color:ni.colorHex||"",location:gl(rt.id,rt.tray.length)}}):void 0,onUnassignSpool:Nn&&ni.vendor!=="Bambu Lab"?()=>m?.(t.id,rt.id,gi):void 0}})(),configureSlot:{enabled:C("printers:control"),onConfigure:()=>$e({amsId:rt.id,trayId:gi,trayCount:rt.tray.length,trayType:ln?.tray_type||void 0,trayColor:ln?.tray_color||void 0,traySubBrands:ln?.tray_sub_brands||void 0,trayInfoIdx:ln?.tray_info_idx||void 0,extruderId:un,caliIdx:ln?.cali_idx,savedPresetId:Xs?.preset_id})},children:Jh}):i.jsx($j,{configureSlot:{enabled:C("printers:control"),onConfigure:()=>$e({amsId:rt.id,trayId:gi,trayCount:rt.tray.length,extruderId:un})},inventory:o?void 0:{onAssignSpool:()=>Ce({printerId:t.id,amsId:rt.id,trayId:gi,trayInfo:{type:"",color:"",location:gl(rt.id,rt.tray.length)}})},children:Jh})]}),(rt.humidity!=null||rt.temp!=null)&&i.jsxs("div",{className:"flex flex-col justify-center gap-1 shrink-0 max-[550px]:w-full",children:[rt.temp!=null&&i.jsx(wW,{temp:rt.temp,goodThreshold:s?.tempGood,fairThreshold:s?.tempFair,onClick:()=>je({amsId:rt.id,amsLabel:gl(rt.id,rt.tray.length),mode:"temperature"}),compact:!0}),rt.humidity!=null&&i.jsx(vW,{humidity:rt.humidity,goodThreshold:s?.humidityGood,fairThreshold:s?.humidityFair,onClick:()=>je({amsId:rt.id,amsLabel:gl(rt.id,rt.tray.length),mode:"humidity"}),compact:!0})]})]})]},rt.id)}),Qe.vt_tray.length>0&&i.jsxs("div",{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary/30 ${Qe.vt_tray.length===1?"max-w-[50%]":""}`,children:[i.jsx("div",{className:"flex items-center gap-1 mb-2",children:i.jsx("span",{className:"text-[10px] text-white font-medium",children:g("printers.external")})}),i.jsx("div",{className:`grid ${Qe.vt_tray.length>1?"grid-cols-2":"grid-cols-1"} gap-1.5`,children:[...Qe.vt_tray].sort((rt,un)=>(rt.id??254)-(un.id??254)).map(rt=>{const un=rt.id??254,In=rn&&Ut===254?un===254&&Qe.active_extruder===1||un===255&&Qe.active_extruder===0:Ut===un,Vn=un-254,Na=rn?g(un===254?"printers.extL":"printers.extR"):"",_o=rt.tray_info_idx?Fe?.[rt.tray_info_idx]:null,ln=tt?.[1020+Vn],zn=(rt.tray_uuid||rt.tag_uid||xb(t.serial_number,255,Vn))?.toUpperCase(),Cs=zn?l?.[zn]:void 0,Ts=Xj(Cs),rl=d?.(t.id,255,Vn),ec=(()=>{const ti=rl?.spool;return ti&&ti.label_weight>0&&ti.weight_used!=null?Math.round(Math.max(0,ti.label_weight-ti.weight_used)/ti.label_weight*100):null})(),Xs=rt.tray_type&&rt.remain>=0,gi=ec===0&&Xs&&rt.remain>0?null:ec,Ia=Ts??gi??(Xs?rt.remain:null),tc=Ts!==null?"spoolman":gi!==null?"inventory":Xs?"ams":void 0,za={vendor:Qj(rt)?"Bambu Lab":"Generic",profile:ln?.preset_name||_o?.name||rl?.spool?.slicer_filament_name||rt.tray_sub_brands||rt.tray_type||"Unknown",colorName:Gj(rt.tray_id_name)||dN(rt.tray_color),colorHex:rt.tray_color||null,kFactor:Wj(rt.k),fillLevel:Ia,trayUuid:rt.tray_uuid||null,tagUid:rt.tag_uid||null,fillSource:tc},No=!rt.tray_type,jc=i.jsxs("div",{className:`bg-bambu-dark-tertiary rounded p-1 text-center ${No?"opacity-50":""} ${In?"ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark":""}`,children:[i.jsx(Vj,{trayColor:rt.tray_color,trayType:rt.tray_type,isEmpty:No,slotNumber:Vn+1}),i.jsx("div",{className:`text-[9px] font-bold truncate ${No?"text-white/40":"text-white"}`,children:rt.tray_type||"—"}),i.jsx("div",{className:"mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden",children:Ia!==null&&Ia>=0&&!No&&i.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${Ia}%`,backgroundColor:Yj(Ia)}})}),Na&&i.jsx("div",{className:"text-[7px] text-white/40 mt-0.5 truncate",children:Na})]});return i.jsx("div",{className:"relative group",children:No?i.jsx($j,{configureSlot:{enabled:C("printers:control"),onConfigure:()=>$e({amsId:255,trayId:Vn,trayCount:1,extruderId:rn?un===254?1:0:void 0})},inventory:o?void 0:{onAssignSpool:()=>Ce({printerId:t.id,amsId:255,trayId:Vn,trayInfo:{type:"",color:"",location:Na||g("printers.external")}})},children:jc}):i.jsx(Hj,{data:za,spoolman:{enabled:o,linkedSpoolId:zn?l?.[zn]?.id:void 0,spoolmanUrl:c,syncMode:u,onLinkSpool:o?()=>{const ti=(za.trayUuid||za.tagUid||xb(t.serial_number,255,Vn)).toUpperCase();ce({tagUid:za.tagUid||ti,trayUuid:za.trayUuid||"",printerId:t.id,amsId:255,trayId:Vn})}:void 0,onUnlinkSpool:Cs?.id?()=>_a.mutate(Cs.id):void 0},inventory:o?void 0:(()=>{const ti=d?.(t.id,255,Vn);return{assignedSpool:ti?.spool?{id:ti.spool.id,material:ti.spool.material,brand:ti.spool.brand,color_name:ti.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(ti.spool.label_weight-ti.spool.weight_used))}:null,onAssignSpool:()=>Ce({printerId:t.id,amsId:255,trayId:Vn,trayInfo:{type:rt.tray_type||za.profile,material:rt.tray_type??void 0,profile:za.profile,color:za.colorHex||"",location:Na||g("printers.external")}}),onUnassignSpool:ti?()=>m?.(t.id,255,Vn):void 0}})(),configureSlot:{enabled:C("printers:control"),onConfigure:()=>$e({amsId:255,trayId:Vn,trayCount:1,trayType:rt.tray_type||void 0,trayColor:rt.tray_color||void 0,traySubBrands:rt.tray_sub_brands||void 0,trayInfoIdx:rt.tray_info_idx||void 0,extruderId:rn?un===254?1:0:void 0,caliIdx:rt.cali_idx,savedPresetId:ln?.preset_id})},children:jc})},un)})})]})]})]})]})})()]}),Et&&r==="expanded"&&i.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[i.jsx(kc,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),i.jsx("span",{className:"text-sm text-white truncate",children:Et.name}),Zt&&i.jsxs("span",{className:`text-xs px-1.5 py-0.5 rounded flex-shrink-0 ${Zt.state==="ON"?"bg-bambu-green/20 text-bambu-green":Zt.state==="OFF"?"bg-red-500/20 text-red-400":"bg-bambu-gray/20 text-bambu-gray"}`,children:[Zt.state||"?",Zt.state==="ON"&&Zt.energy?.power!=null&&i.jsxs("span",{className:"text-yellow-400 ml-1.5",children:["· ",Zt.energy.power,"W"]})]})]}),i.jsx("div",{className:"flex-1"}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsxs("button",{onClick:()=>he(!0),disabled:cr.isPending||Zt?.state==="ON"||!C("smart_plugs:control"),className:`px-2 py-1 text-xs rounded transition-colors flex items-center gap-1 ${C("smart_plugs:control")?Zt?.state==="ON"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary":"bg-bambu-dark text-bambu-gray/50 cursor-not-allowed"}`,title:C("smart_plugs:control")?void 0:g("printers.permission.noSmartPlugControl"),children:[i.jsx(Vd,{className:"w-3 h-3"}),"On"]}),i.jsxs("button",{onClick:()=>Y(!0),disabled:cr.isPending||Zt?.state==="OFF"||!C("smart_plugs:control"),className:`px-2 py-1 text-xs rounded transition-colors flex items-center gap-1 ${C("smart_plugs:control")?Zt?.state==="OFF"?"bg-red-500/30 text-red-400":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary":"bg-bambu-dark text-bambu-gray/50 cursor-not-allowed"}`,title:C("smart_plugs:control")?void 0:g("printers.permission.noSmartPlugControl"),children:[i.jsx(nT,{className:"w-3 h-3"}),"Off"]})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[i.jsx("span",{className:`text-xs hidden sm:inline ${Et.auto_off_executed?"text-bambu-green":"text-bambu-gray"}`,children:Et.auto_off_executed?"Auto-off done":"Auto-off"}),i.jsx("button",{onClick:()=>li.mutate(!Et.auto_off),disabled:li.isPending||Et.auto_off_executed||!C("smart_plugs:control"),title:C("smart_plugs:control")?Et.auto_off_executed?g("printers.autoOffExecuted"):g("printers.autoOffAfterPrint"):g("printers.permission.noSmartPlugControl"),className:`relative w-9 h-5 rounded-full transition-colors flex-shrink-0 ${C("smart_plugs:control")?Et.auto_off_executed?"bg-bambu-green/50 cursor-not-allowed":Et.auto_off?"bg-bambu-green":"bg-bambu-dark-tertiary":"bg-bambu-dark-tertiary/50 cursor-not-allowed"}`,children:i.jsx("span",{className:`absolute top-[2px] left-[2px] w-4 h-4 bg-white rounded-full transition-transform ${Et.auto_off||Et.auto_off_executed?"translate-x-4":"translate-x-0"}`})})]})]}),It&&It.length>0&&i.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-bambu-dark-tertiary/50",children:[i.jsx(hw,{className:"w-3.5 h-3.5 text-blue-400 flex-shrink-0"}),i.jsx("span",{className:"text-xs text-bambu-gray",children:"HA:"}),i.jsx("div",{className:"flex flex-wrap gap-1",children:It.map(mt=>{const Pt=mt.ha_entity_id?.startsWith("script.");return i.jsxs("button",{onClick:()=>_i.mutate({id:mt.id,action:Pt?"on":"toggle"}),disabled:_i.isPending,title:`${Pt?"Run":"Toggle"} ${mt.ha_entity_id}`,className:"px-2 py-0.5 text-xs bg-blue-500/20 text-blue-400 hover:bg-blue-500/30 rounded transition-colors flex items-center gap-1",children:[i.jsx(go,{className:"w-2.5 h-2.5"}),mt.name]},mt.id)})})]})]}),r==="expanded"&&i.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary flex items-center justify-end gap-2 flex-wrap",children:[i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>Yh.mutate(!Qe?.chamber_light),disabled:!Qe?.connected||Yh.isPending||!C("printers:control"),title:C("printers:control")?Qe?.chamber_light?g("printers.chamberLightOff"):g("printers.chamberLightOn"):g("printers.permission.noControl"),className:Qe?.chamber_light?"!border-yellow-500 !text-yellow-400 hover:!bg-yellow-500/20":"",children:i.jsx(_O,{on:Qe?.chamber_light??!1,className:`w-4 h-4 ${Qe?.chamber_light?"text-yellow-400":""}`})}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>{if(f==="embedded"&&y)y(t.id,t.name);else{const mt=localStorage.getItem("cameraWindowState"),Pt=mt?JSON.parse(mt):{width:640,height:400},rn=[`width=${Pt.width}`,`height=${Pt.height}`,Pt.left!==void 0?`left=${Pt.left}`:"",Pt.top!==void 0?`top=${Pt.top}`:"","menubar=no,toolbar=no,location=no,status=no,noopener"].filter(Boolean).join(",");window.open(`/camera/${t.id}`,`camera-${t.id}`,rn)}},disabled:!Qe?.connected||!C("camera:view"),title:C("camera:view")?g(f==="embedded"?"printers.openCameraOverlay":"printers.openCameraWindow"):g("printers.permission.noCamera"),children:i.jsx(VL,{className:"w-4 h-4"})}),i.jsxs("div",{className:`inline-flex rounded-md ${t.plate_detection_enabled?"ring-1 ring-green-500":""}`,children:[i.jsx(Oe,{variant:"secondary",size:"sm",onClick:Nu,disabled:!Qe?.connected||Ss.isPending||!C("printers:update"),title:C("printers:update")?t.plate_detection_enabled?g("printers.plateDetection.enabledClick"):g("printers.plateDetection.disabledClick"):g("printers.plateDetection.noPermission"),className:`!rounded-r-none !border-r-0 ${t.plate_detection_enabled?"!border-green-500 !text-green-400 hover:!bg-green-500/20":""}`,children:Ss.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(RN,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:Zl,disabled:!Qe?.connected||xt||!C("printers:update"),title:C("printers:update")?g("printers.plateDetection.manageCalibration"):g("printers.plateDetection.noPermission"),className:`!rounded-l-none !px-1.5 ${t.plate_detection_enabled?"!border-green-500 !text-green-400 hover:!bg-green-500/20":""}`,children:xt?i.jsx(ht,{className:"w-3 h-3 animate-spin"}):i.jsx(Ln,{className:"w-3 h-3"})})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>ee(!0),disabled:!Ke||!C("printers:files"),title:C("printers:files")?g("printers.browseFiles"):g("printers.permission.noFiles"),children:[i.jsx(Lx,{className:"w-4 h-4"}),g("printers.files")]}),Ke&&Qe?.state!=="RUNNING"&&Qe?.state!=="PAUSE"&&i.jsxs(Oe,{size:"sm",onClick:()=>ne(!0),disabled:!C("printers:control"),title:C("printers:control")?g("common.print"):g("printers.permission.noControl"),className:"!bg-bambu-green hover:!bg-bambu-green/80 !text-white",children:[i.jsx(Sr,{className:"w-4 h-4"}),g("common.print")]})]})]}),I&&i.jsx(oMe,{printerId:t.id,printerName:t.name,onClose:()=>ee(!1)}),$&&i.jsx(Qre,{folderId:null,onClose:()=>ne(!1),onUploadComplete:()=>{},autoUpload:!0,accept:".gcode,.3mf",validateFile:mt=>{const Pt=mt.name.toLowerCase();if(!Pt.endsWith(".gcode")&&!Pt.includes(".gcode."))return g("printers.dropNotPrintable","Only .gcode and .gcode.3mf files can be printed")},onFileUploaded:mt=>{const Pt=mt.metadata?.sliced_for_model,rn=Kv(t.model);if(Pt&&rn&&Pt.toLowerCase()!==rn.toLowerCase())return be.deleteLibraryFile(mt.id).catch(()=>{}),g("printers.incompatibleFile","This file was sliced for {{slicedFor}}, but this printer is a {{printerModel}}",{slicedFor:Pt,printerModel:rn});re({id:mt.id,filename:mt.filename})}}),W&&i.jsx(uu,{mode:"reprint",libraryFileId:W.id,archiveName:W.filename,initialSelectedPrinterIds:[t.id],onClose:()=>re(null),onSuccess:()=>re(null)}),ie&&i.jsx(hMe,{printerId:t.id,printerName:t.name,onClose:()=>X(!1)}),O&&i.jsx(Xqe,{printer:t,status:Qe,totalPrintHours:n?.total_print_hours,onClose:J}),Ve&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:()=>Bi(),children:i.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-w-lg w-full",onClick:mt=>mt.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[Ve.needs_calibration?i.jsx(RN,{className:"w-5 h-5 text-blue-500"}):Ve.is_empty?i.jsx(fr,{className:"w-5 h-5 text-green-500"}):i.jsx(Vi,{className:"w-5 h-5 text-yellow-500"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:"Build Plate Check"}),Ve.reference_count!==void 0&&Ve.max_references&&i.jsxs("span",{className:"text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded",children:[Ve.reference_count,"/",Ve.max_references," refs"]})]}),i.jsx("button",{onClick:()=>Bi(),className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[Ve.needs_calibration?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"p-3 rounded-lg bg-blue-500/20 border border-blue-500/50",children:[i.jsx("p",{className:"font-medium text-blue-400",children:g("printers.plateDetection.calibrationRequired")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",dangerouslySetInnerHTML:{__html:g("printers.plateDetection.calibrationInstructions")}})]}),i.jsxs("div",{className:"text-sm text-bambu-gray space-y-2",children:[i.jsx("p",{children:g("printers.plateDetection.calibrationDescription")}),i.jsx("p",{dangerouslySetInnerHTML:{__html:g("printers.plateDetection.calibrationTip")}})]})]}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:`p-3 rounded-lg ${Ve.is_empty?"bg-green-500/20 border border-green-500/50":"bg-yellow-500/20 border border-yellow-500/50"}`,children:[i.jsx("p",{className:`font-medium ${Ve.is_empty?"text-green-400":"text-yellow-400"}`,children:Ve.is_empty?g("printers.plateDetection.plateEmpty"):g("printers.plateDetection.objectsDetected")}),i.jsxs("p",{className:"text-sm text-bambu-gray mt-1",children:[g("printers.plateDetection.confidence"),": ",Math.round(Ve.confidence*100),"% | ",g("printers.plateDetection.difference"),": ",Ve.difference_percent.toFixed(1),"%"]})]}),Ve.debug_image_url&&i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:g("printers.plateDetection.analysisPreview")}),i.jsx("img",{src:Ve.debug_image_url,alt:g("printers.plateDetection.analysisPreview"),className:"w-full rounded-lg border border-bambu-dark-tertiary"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:g("printers.plateDetection.analysisLegend")})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:Ve.message})]}),el&&el.references.length>0&&i.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-sm font-medium text-white mb-2",children:g("printers.plateDetection.savedReferences",{count:el.references.length,max:el.max_references})}),i.jsx("div",{className:"grid grid-cols-5 gap-2",children:el.references.map(mt=>i.jsxs("div",{className:"relative group",children:[i.jsx("img",{src:be.getPlateReferenceThumbnailUrl(t.id,mt.index),alt:mt.label||`Reference ${mt.index+1}`,className:"w-full aspect-video object-cover rounded border border-bambu-dark-tertiary"}),i.jsx("button",{onClick:()=>Qh(mt.index),className:"absolute top-1 right-1 p-0.5 bg-red-500/80 rounded opacity-0 group-hover:opacity-100 transition-opacity",title:g("printers.plateDetection.deleteReference"),children:i.jsx(Ht,{className:"w-3 h-3 text-white"})}),Ql?.index===mt.index?i.jsx("input",{type:"text",value:Ql.label,onChange:Pt=>Ys({...Ql,label:Pt.target.value}),onBlur:()=>nl(mt.index,Ql.label),onKeyDown:Pt=>{Pt.key==="Enter"&&nl(mt.index,Ql.label),Pt.key==="Escape"&&Ys(null)},className:"w-full mt-1 px-1 py-0.5 text-xs bg-bambu-dark-tertiary border border-bambu-green rounded text-white",autoFocus:!0,placeholder:g("printers.plateDetection.labelPlaceholder")}):i.jsx("p",{className:"text-xs text-bambu-gray mt-1 truncate cursor-pointer hover:text-white",onClick:()=>Ys({index:mt.index,label:mt.label}),title:mt.label?g("printers.plateDetection.clickToEdit",{label:mt.label}):g("printers.plateDetection.clickToAddLabel"),children:mt.label||i.jsx("span",{className:"italic opacity-50",children:g("printers.noLabel")})}),i.jsx("p",{className:"text-[10px] text-bambu-gray/60",children:mt.timestamp?Jn(mt.timestamp)?.toLocaleDateString()??"":""})]},mt.index))})]}),!Ve.needs_calibration&&i.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("p",{className:"text-sm font-medium text-white",children:g("printers.roi.title")}),yt?i.jsxs("div",{className:"flex gap-1",children:[i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>wt(null),disabled:_t,children:g("common.cancel")}),i.jsx(Oe,{size:"sm",onClick:ku,disabled:_t,children:_t?i.jsx(ht,{className:"w-3 h-3 animate-spin"}):g("common.save")})]}):i.jsxs(Oe,{variant:"ghost",size:"sm",onClick:()=>wt(Ve.roi||{x:.15,y:.35,w:.7,h:.55}),children:[i.jsx(Yi,{className:"w-3 h-3 mr-1"}),g("common.edit")]})]}),yt?i.jsxs("div",{className:"space-y-3 bg-bambu-dark-tertiary/50 p-3 rounded-lg",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"text-xs text-bambu-gray",children:g("printers.roi.xStart")}),i.jsx("input",{type:"range",min:"0",max:"0.9",step:"0.01",value:yt.x,onChange:mt=>wt({...yt,x:parseFloat(mt.target.value)}),className:"w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500"}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:[Math.round(yt.x*100),"%"]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"text-xs text-bambu-gray",children:g("printers.roi.yStart")}),i.jsx("input",{type:"range",min:"0",max:"0.9",step:"0.01",value:yt.y,onChange:mt=>wt({...yt,y:parseFloat(mt.target.value)}),className:"w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500"}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:[Math.round(yt.y*100),"%"]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"text-xs text-bambu-gray",children:g("printers.width")}),i.jsx("input",{type:"range",min:"0.1",max:"1",step:"0.01",value:yt.w,onChange:mt=>wt({...yt,w:parseFloat(mt.target.value)}),className:"w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500"}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:[Math.round(yt.w*100),"%"]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"text-xs text-bambu-gray",children:g("printers.height")}),i.jsx("input",{type:"range",min:"0.1",max:"1",step:"0.01",value:yt.h,onChange:mt=>wt({...yt,h:parseFloat(mt.target.value)}),className:"w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500"}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:[Math.round(yt.h*100),"%"]})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:g("printers.roi.instruction")})]}):i.jsxs("p",{className:"text-xs text-bambu-gray",children:["Current: X=",Math.round((Ve.roi?.x||.15)*100),"%, Y=",Math.round((Ve.roi?.y||.35)*100),"%, W=",Math.round((Ve.roi?.w||.7)*100),"%, H=",Math.round((Ve.roi?.h||.55)*100),"%"]})]})]}),i.jsx("div",{className:"flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary",children:Ve.needs_calibration?i.jsxs(i.Fragment,{children:[i.jsx(Oe,{variant:"ghost",onClick:()=>Bi(),children:g("common.cancel")}),i.jsx(Oe,{onClick:()=>tl(),disabled:kt,children:kt?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 mr-2 animate-spin"}),"Calibrating..."]}):"Calibrate Empty Plate"})]}):i.jsxs(i.Fragment,{children:[i.jsx(Oe,{variant:"ghost",onClick:()=>tl(),disabled:kt,children:kt?"Adding...":`Add Reference (${el?.references.length||0}/${el?.max_references||5})`}),i.jsx(Oe,{onClick:()=>Bi(),children:"Close"})]})})]})}),me&&Et&&i.jsx(Sn,{title:g("printers.confirm.powerOnTitle"),message:g("printers.confirm.powerOnMessage",{name:t.name}),confirmText:g("printers.confirm.powerOnButton"),variant:"default",onConfirm:()=>{cr.mutate("on"),he(!1)},onCancel:()=>he(!1)}),ge&&Et&&i.jsx(Sn,{title:g("printers.confirm.powerOffTitle"),message:Qe?.state==="RUNNING"?g("printers.confirm.powerOffWarning",{name:t.name}):g("printers.confirm.powerOffMessage",{name:t.name}),confirmText:g("printers.confirm.powerOffButton"),variant:"danger",onConfirm:()=>{cr.mutate("off"),Y(!1)},onCancel:()=>Y(!1)}),xe&&i.jsx(Sn,{title:g("printers.confirm.stopTitle"),message:g("printers.confirm.stopMessage",{name:t.name}),confirmText:g("printers.confirm.stopButton"),variant:"danger",onConfirm:()=>{Tr.mutate(),Pe(!1)},onCancel:()=>Pe(!1)}),q&&i.jsx(Sn,{title:g("printers.confirm.pauseTitle"),message:g("printers.confirm.pauseMessage",{name:t.name}),confirmText:g("printers.confirm.pauseButton"),variant:"default",onConfirm:()=>{zi.mutate(),Z(!1)},onCancel:()=>Z(!1)}),j&&i.jsx(Sn,{title:g("printers.confirm.resumeTitle"),message:g("printers.confirm.resumeMessage",{name:t.name}),confirmText:g("printers.confirm.resumeButton"),variant:"default",onConfirm:()=>{Zd.mutate(),E(!1)},onCancel:()=>E(!1)}),i.jsx(NO,{printerId:t.id,isOpen:U,onClose:()=>K(!1)}),oe&&i.jsx(bMe,{printerName:t.name,errors:Qe?.hms_errors||[],onClose:()=>le(!1),printerId:t.id,hasPermission:C}),Be&&i.jsx(Tqe,{isOpen:!!Be,onClose:()=>je(null),printerId:t.id,printerName:t.name,amsId:Be.amsId,amsLabel:Be.amsLabel,initialMode:Be.mode,thresholds:s}),Xe&&i.jsx(Aqe,{isOpen:!!Xe,onClose:()=>ce(null),tagUid:Xe.tagUid,trayUuid:Xe.trayUuid,printerId:Xe.printerId,amsId:Xe.amsId,trayId:Xe.trayId}),Ie&&i.jsx(Pqe,{isOpen:!!Ie,onClose:()=>Ce(null),printerId:Ie.printerId,amsId:Ie.amsId,trayId:Ie.trayId,trayInfo:Ie.trayInfo}),Ge&&i.jsx(Xre,{isOpen:!!Ge,onClose:()=>$e(null),printerId:t.id,slotInfo:Ge,printerModel:Kv(t.model)||void 0,onSuccess:()=>{_.invalidateQueries({queryKey:["slotPresets",t.id]}),_.invalidateQueries({queryKey:["printerStatus",t.id]})}}),z&&i.jsx(dVe,{printer:t,onClose:()=>G(!1)}),Ue&&Qt&&i.jsx(uVe,{printer:t,firmwareInfo:Qt,onClose:()=>De(!1)}),on&&i.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>Ni(null)}),ue!==null&&Ne&&(()=>{const mt=ye==="n3s"?85:65,Pt=35,rn=mt+10;return i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-[100]",onClick:()=>fe(null)}),i.jsxs("div",{className:"fixed z-[101] w-[240px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl overflow-hidden",style:{top:Ne.top,left:Ne.left},onClick:rt=>rt.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 border-b border-bambu-dark-tertiary",children:[i.jsx(Fp,{className:"w-3.5 h-3.5 text-amber-400"}),i.jsx("span",{className:"text-xs text-white font-medium",children:g("printers.drying.start")})]}),i.jsxs("div",{className:"px-3 py-2.5 space-y-2.5",children:[i.jsxs("div",{children:[i.jsx("label",{className:"text-[10px] text-bambu-gray mb-1 block",children:g("printers.filaments")}),i.jsx("select",{value:L,onChange:rt=>{const un=rt.target.value;F(un);const In=x[un];In&&(ve(In[ye==="n3s"?"n3s":"n3f"]),de(ye==="n3s"?In.n3s_hours:In.n3f_hours))},className:"w-full px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs focus:outline-none focus:border-amber-500/50",children:Object.keys(x).map(rt=>i.jsx("option",{value:rt,children:rt},rt))})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-1",children:[i.jsx("label",{className:"text-[10px] text-bambu-gray",children:g("printers.drying.temperature")}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("input",{type:"number",min:45,max:mt,value:te,onChange:rt=>ve(Math.min(mt,Math.max(45,Number(rt.target.value)||45))),className:"w-12 px-1 py-0.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-[11px] text-center focus:outline-none focus:border-amber-500/50 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"}),i.jsx("span",{className:"text-[10px] text-bambu-gray",children:"°C"})]})]}),i.jsx("input",{type:"range",min:Pt,max:rn,value:te,onChange:rt=>ve(Math.min(mt,Math.max(45,Number(rt.target.value)))),className:"w-full h-1 accent-amber-500 cursor-pointer"}),i.jsxs("div",{className:"flex justify-between text-[9px] text-bambu-gray/50 mt-0.5",children:[i.jsx("span",{children:"45°C"}),i.jsxs("span",{children:[mt,"°C"]})]})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-1",children:[i.jsx("label",{className:"text-[10px] text-bambu-gray",children:g("printers.drying.duration")}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("input",{type:"number",min:1,max:24,value:pe,onChange:rt=>de(Math.min(24,Math.max(1,Number(rt.target.value)||1))),className:"w-10 px-1 py-0.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-[11px] text-center focus:outline-none focus:border-amber-500/50 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"}),i.jsx("span",{className:"text-[10px] text-bambu-gray",children:g("printers.drying.hours")})]})]}),i.jsx("input",{type:"range",min:1,max:24,value:pe,onChange:rt=>de(Number(rt.target.value)),className:"w-full h-1 accent-amber-500 cursor-pointer"}),i.jsxs("div",{className:"flex justify-between text-[9px] text-bambu-gray/50 mt-0.5",children:[i.jsx("span",{children:"1h"}),i.jsx("span",{children:"24h"})]})]})]}),i.jsx("div",{className:"px-3 pb-3",children:i.jsx("button",{onClick:()=>{ue!==null&&On.mutate({amsId:ue,temp:te,duration:pe,filament:L})},disabled:On.isPending,className:"w-full py-1.5 bg-amber-500 hover:bg-amber-400 text-white text-xs font-medium rounded-lg transition-colors disabled:opacity-50",children:On.isPending?g("printers.drying.startingDrying"):g("printers.drying.start")})})]})]})})()]})}function cVe({onClose:t,onAdd:e,existingSerials:n}){const{t:r}=Ft(),[a,s]=w.useState({name:"",serial_number:"",ip_address:"",access_code:"",model:"",location:"",auto_archive:!0}),[o,l]=w.useState(!1),[c,u]=w.useState([]),[d,m]=w.useState(""),[p,f]=w.useState(!1),[y,v]=w.useState(!1),[x,g]=w.useState([]),[_,N]=w.useState(""),[T,C]=w.useState({scanned:0,total:0});w.useEffect(()=>{Oc.getInfo().then(P=>{v(P.is_docker),P.subnets.length>0&&(g(P.subnets),N(P.subnets[0]))}).catch(()=>{})},[]);const A=c.filter(P=>!n.includes(P.serial)),k=async()=>{m(""),u([]),l(!0),f(!1),C({scanned:0,total:0});try{if(y){await Oc.startSubnetScan(_);const P=setInterval(async()=>{try{const D=await Oc.getScanStatus();C({scanned:D.scanned,total:D.total});const H=await Oc.getDiscoveredPrinters();u(H),D.running||(clearInterval(P),l(!1),f(!0))}catch(D){console.error("Failed to get scan status:",D)}},500)}else{await Oc.startDiscovery(10);const P=setInterval(async()=>{try{const D=await Oc.getDiscoveredPrinters();u(D)}catch(D){console.error("Failed to get discovered printers:",D)}},1e3);setTimeout(async()=>{clearInterval(P);try{await Oc.stopDiscovery()}catch{}l(!1),f(!0);try{const D=await Oc.getDiscoveredPrinters();u(D)}catch(D){console.error("Failed to get final discovered printers:",D)}},1e4)}}catch(P){console.error("Failed to start discovery:",P),m(P instanceof Error?P.message:r("printers.discovery.failedToStart")),l(!1),f(!0)}},R=P=>{const D=P.serial.startsWith("unknown-")?"":P.serial;s({...a,name:P.name||"",serial_number:D,ip_address:P.ip_address,model:Kv(P.model)}),u([])};return w.useEffect(()=>()=>{Oc.stopDiscovery().catch(()=>{}),Oc.stopSubnetScan().catch(()=>{})},[]),w.useEffect(()=>{const P=D=>{D.key==="Escape"&&t()};return window.addEventListener("keydown",P),()=>window.removeEventListener("keydown",P)},[t]),i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",onClick:t,children:i.jsx(Mt,{className:"w-full max-w-md",onClick:P=>P.stopPropagation(),children:i.jsxs(Dt,{children:[i.jsx("h2",{className:"text-xl font-semibold mb-4",children:r("printers.addPrinter")}),i.jsxs("div",{className:"mb-4 pb-4 border-b border-bambu-dark-tertiary",children:[y&&i.jsxs("div",{className:"mb-3",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("printers.discovery.subnetToScan")}),x.length>0?i.jsx("select",{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 text-sm",value:_,onChange:P=>N(P.target.value),disabled:o,children:x.map(P=>i.jsx("option",{value:P,children:P},P))}):i.jsx("input",{type:"text",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 text-sm",value:_,onChange:P=>N(P.target.value),placeholder:"192.168.1.0/24",disabled:o}),i.jsx("p",{className:"mt-1 text-xs text-bambu-gray",children:r("printers.discovery.dockerNote")})]}),i.jsx(Oe,{type:"button",variant:"secondary",onClick:k,disabled:o,className:"w-full",children:o?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),y&&T.total>0?r("printers.discovery.scanProgress",{scanned:T.scanned,total:T.total}):r("printers.discovery.scanning")]}):i.jsxs(i.Fragment,{children:[i.jsx(jr,{className:"w-4 h-4"}),r(y?"printers.discovery.scanSubnet":"printers.discovery.discoverNetwork")]})}),d&&i.jsx("div",{className:"mt-2 text-sm text-red-400",children:d}),A.length>0&&i.jsx("div",{className:"mt-3 space-y-2 max-h-40 overflow-y-auto",children:A.map(P=>i.jsxs("div",{className:"flex items-center justify-between p-2 bg-bambu-dark rounded-lg hover:bg-bambu-dark-secondary cursor-pointer transition-colors",onClick:()=>R(P),children:[i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"font-medium text-white text-sm truncate",children:P.name||P.serial}),i.jsxs("p",{className:"text-xs text-bambu-gray truncate",children:[Kv(P.model)||r("printers.discovery.unknown")," • ",P.ip_address,P.serial.startsWith("unknown-")&&i.jsxs("span",{className:"text-yellow-500",children:[" • ",r("printers.discovery.serialRequired")]})]})]}),i.jsx(Ln,{className:"w-4 h-4 text-bambu-gray -rotate-90 flex-shrink-0 ml-2"})]},P.serial))}),o&&i.jsx("p",{className:"mt-2 text-sm text-bambu-gray text-center",children:r(y?"printers.discovery.scanningSubnet":"printers.discovery.scanningNetwork")}),p&&!o&&c.length===0&&i.jsx("p",{className:"mt-2 text-sm text-bambu-gray text-center",children:r(y?"printers.discovery.noPrintersFoundSubnet":"printers.discovery.noPrintersFoundNetwork")}),p&&!o&&c.length>0&&A.length===0&&i.jsx("p",{className:"mt-2 text-sm text-bambu-gray text-center",children:r("printers.discovery.allConfigured")})]}),i.jsxs("form",{onSubmit:P=>{P.preventDefault(),e(a)},className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("printers.name")}),i.jsx("input",{type:"text",required:!0,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",value:a.name,onChange:P=>s({...a,name:P.target.value}),placeholder:r("printers.modal.myPrinter")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("printers.ipAddress")}),i.jsx("input",{type:"text",required:!0,pattern:"(\\d{1,3}(\\.\\d{1,3}){3}|[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?)*)",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",value:a.ip_address,onChange:P=>s({...a,ip_address:P.target.value}),placeholder:"192.168.1.100 or printer.local"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("printers.serialNumber")}),i.jsx("input",{type:"text",required:!0,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",value:a.serial_number,onChange:P=>s({...a,serial_number:P.target.value}),placeholder:"01P00A000000000"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("printers.accessCode")}),i.jsx("input",{type:"password",required:!0,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",value:a.access_code,onChange:P=>s({...a,access_code:P.target.value}),placeholder:r("printers.modal.fromPrinterSettings")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("printers.modal.modelOptional")}),i.jsxs("select",{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",value:a.model||"",onChange:P=>s({...a,model:P.target.value}),children:[i.jsx("option",{value:"",children:r("printers.modal.selectModel")}),i.jsxs("optgroup",{label:"H2 Series",children:[i.jsx("option",{value:"H2C",children:"H2C"}),i.jsx("option",{value:"H2D",children:"H2D"}),i.jsx("option",{value:"H2D Pro",children:"H2D Pro"}),i.jsx("option",{value:"H2S",children:"H2S"})]}),i.jsxs("optgroup",{label:"X1 Series",children:[i.jsx("option",{value:"X1E",children:"X1E"}),i.jsx("option",{value:"X1C",children:"X1 Carbon"}),i.jsx("option",{value:"X1",children:"X1"})]}),i.jsxs("optgroup",{label:"P Series",children:[i.jsx("option",{value:"P2S",children:"P2S"}),i.jsx("option",{value:"P1S",children:"P1S"}),i.jsx("option",{value:"P1P",children:"P1P"})]}),i.jsxs("optgroup",{label:"A1 Series",children:[i.jsx("option",{value:"A1",children:"A1"}),i.jsx("option",{value:"A1 Mini",children:"A1 Mini"})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("printers.modal.locationGroup")}),i.jsx("input",{type:"text",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",value:a.location||"",onChange:P=>s({...a,location:P.target.value}),placeholder:r("printers.modal.locationPlaceholder")}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:r("printers.locationHelp")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"checkbox",id:"auto_archive",checked:a.auto_archive,onChange:P=>s({...a,auto_archive:P.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("label",{htmlFor:"auto_archive",className:"text-sm text-bambu-gray",children:r("printers.modal.autoArchiveLabel")})]}),i.jsxs("div",{className:"flex gap-3 pt-4",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:t,className:"flex-1",children:r("common.cancel")}),i.jsx(Oe,{type:"submit",className:"flex-1",children:r("printers.addPrinter")})]})]})]})})})}function uVe({printer:t,firmwareInfo:e,onClose:n}){const{t:r}=Ft(),a=an(),{showToast:s}=fn(),{hasPermission:o}=_r(),l=o("firmware:update"),[c,u]=w.useState(null),[d,m]=w.useState(!1),[p,f]=w.useState(null),{data:y,isLoading:v}=et({queryKey:["firmwarePrepare",t.id],queryFn:()=>Y1.prepareUpload(t.id),staleTime:3e4,enabled:e.update_available&&l}),x=pt({mutationFn:()=>Y1.startUpload(t.id),onSuccess:()=>{m(!0);const _=setInterval(async()=>{try{const N=await Y1.getUploadStatus(t.id);u(N),(N.status==="complete"||N.status==="error")&&(clearInterval(_),f(null),m(!1),N.status==="complete"&&(s(r("printers.firmwareModal.uploadedToast"),"success"),a.invalidateQueries({queryKey:["firmwareUpdate",t.id]})))}catch{}},2e3);f(_)},onError:_=>{s(r("printers.firmwareModal.uploadFailed",{error:_.message}),"error"),m(!1)}});w.useEffect(()=>()=>{p&&clearInterval(p)},[p]);const g=()=>{u(null),x.mutate()};return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:i.jsx(Mt,{className:"w-full max-w-md mx-4",children:i.jsxs(Dt,{children:[i.jsxs("div",{className:"flex items-start gap-3 mb-4",children:[i.jsx("div",{className:`p-2 rounded-full ${e.update_available?"bg-orange-500/20":"bg-status-ok/20"}`,children:e.update_available?i.jsx(pi,{className:"w-5 h-5 text-orange-400"}):i.jsx(fr,{className:"w-5 h-5 text-status-ok"})}),i.jsxs("div",{className:"flex-1",children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:e.update_available?r("printers.firmwareModal.title"):r("printers.firmwareModal.titleUpToDate")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:t.name})]})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3 mb-4",children:[i.jsxs("div",{className:"flex justify-between items-center text-sm",children:[i.jsx("span",{className:"text-bambu-gray",children:r("printers.firmwareModal.currentVersion")}),i.jsx("span",{className:`font-mono ${e.update_available?"text-white":"text-status-ok"}`,children:e.current_version||r("common.unknown")})]}),e.update_available&&i.jsxs("div",{className:"flex justify-between items-center text-sm mt-1",children:[i.jsx("span",{className:"text-bambu-gray",children:r("printers.firmwareModal.latestVersion")}),i.jsx("span",{className:"text-orange-400 font-mono",children:e.latest_version})]}),e.release_notes&&i.jsxs("details",{className:"mt-3 text-sm",open:!e.update_available,children:[i.jsx("summary",{className:`cursor-pointer hover:underline ${e.update_available?"text-orange-400":"text-status-ok"}`,children:r("printers.firmwareModal.releaseNotes")}),i.jsx("div",{className:"mt-2 text-bambu-gray text-xs max-h-40 overflow-y-auto whitespace-pre-wrap",children:e.release_notes})]})]}),e.update_available?v?i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-sm mb-4",children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),r("printers.firmwareModal.checkingPrereqs")]}):y&&!d&&!c?i.jsx("div",{className:"mb-4",children:y.can_proceed?i.jsxs("div",{className:"flex items-center gap-2 text-bambu-green text-sm",children:[i.jsx(ra,{className:"w-4 h-4"}),r("printers.firmwareModal.sdCardReady")]}):i.jsx("div",{className:"space-y-1",children:y.errors.map((_,N)=>i.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm",children:[i.jsx(Li,{className:"w-4 h-4 flex-shrink-0"}),_]},N))})}):null:null,(d||c)&&c&&i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center justify-between text-sm mb-1",children:[i.jsx("span",{className:"text-bambu-gray capitalize",children:c.status}),i.jsxs("span",{className:"text-white",children:[c.progress,"%"]})]}),i.jsx("div",{className:"w-full bg-bambu-dark-tertiary rounded-full h-2",children:i.jsx("div",{className:`h-2 rounded-full transition-all ${c.status==="error"?"bg-status-error":c.status==="complete"?"bg-status-ok":"bg-orange-500"} ${c.status==="uploading"?"animate-pulse":""}`,style:{width:`${c.progress}%`}})}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:c.message}),c.error&&i.jsx("p",{className:"text-xs text-red-400 mt-1",children:c.error})]}),c?.status==="complete"&&i.jsxs("div",{className:"bg-bambu-green/10 border border-bambu-green/30 rounded-lg p-3 mb-4",children:[i.jsx("p",{className:"text-sm text-bambu-green font-medium mb-2",children:r("printers.firmwareModal.uploadedSuccess")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:r("printers.firmwareModal.applyInstructions")}),i.jsxs("ol",{className:"text-xs text-bambu-gray mt-1 list-decimal list-inside space-y-1",children:[i.jsx("li",{dangerouslySetInnerHTML:{__html:r("printers.firmwareModal.step1")}}),i.jsx("li",{dangerouslySetInnerHTML:{__html:r("printers.firmwareModal.step2")}}),i.jsx("li",{dangerouslySetInnerHTML:{__html:r("printers.firmwareModal.step3")}}),i.jsx("li",{children:r("printers.firmwareModal.step4")})]})]}),i.jsxs("div",{className:"flex gap-2 justify-end",children:[i.jsx(Oe,{variant:"secondary",onClick:n,children:c?.status==="complete"?r("printers.firmwareModal.done"):r("common.cancel")}),y?.can_proceed&&!d&&c?.status!=="complete"&&l&&i.jsx(Oe,{onClick:g,disabled:x.isPending,children:x.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin mr-2"}),r("printers.firmwareModal.starting")]}):i.jsxs(i.Fragment,{children:[i.jsx(pi,{className:"w-4 h-4 mr-2"}),r("printers.firmwareModal.uploadFirmware")]})})]})]})})})}function dVe({printer:t,onClose:e}){const{t:n}=Ft(),r=an(),{showToast:a}=fn(),[s,o]=w.useState({name:t.name,ip_address:t.ip_address,access_code:"",model:t.model||"",location:t.location||"",auto_archive:t.auto_archive}),l=pt({mutationFn:u=>be.updatePrinter(t.id,u),onSuccess:()=>{r.invalidateQueries({queryKey:["printers"]}),r.invalidateQueries({queryKey:["printerStatus",t.id]}),e()},onError:u=>a(u.message||n("printers.toast.failedToUpdate"),"error")});w.useEffect(()=>{const u=d=>{d.key==="Escape"&&e()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[e]);const c=u=>{u.preventDefault();const d={name:s.name,ip_address:s.ip_address,model:s.model||void 0,location:s.location||void 0,auto_archive:s.auto_archive};s.access_code&&(d.access_code=s.access_code),l.mutate(d)};return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",onClick:e,children:i.jsx(Mt,{className:"w-full max-w-md",onClick:u=>u.stopPropagation(),children:i.jsxs(Dt,{children:[i.jsx("h2",{className:"text-xl font-semibold mb-4",children:n("printers.editPrinter")}),i.jsxs("form",{onSubmit:c,className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("printers.name")}),i.jsx("input",{type:"text",required:!0,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",value:s.name,onChange:u=>o({...s,name:u.target.value}),placeholder:n("printers.modal.myPrinter")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("printers.ipAddress")}),i.jsx("input",{type:"text",required:!0,pattern:"(\\d{1,3}(\\.\\d{1,3}){3}|[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?)*)",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",value:s.ip_address,onChange:u=>o({...s,ip_address:u.target.value}),placeholder:"192.168.1.100 or printer.local"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("printers.serialNumber")}),i.jsx("input",{type:"text",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",value:t.serial_number}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("printers.serialCannotBeChanged")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("printers.accessCode")}),i.jsx("input",{type:"password",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",value:s.access_code,onChange:u=>o({...s,access_code:u.target.value}),placeholder:n("printers.accessCodePlaceholder")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("printers.model")}),i.jsxs("select",{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",value:s.model,onChange:u=>o({...s,model:u.target.value}),children:[i.jsx("option",{value:"",children:n("printers.modal.selectModel")}),i.jsxs("optgroup",{label:"H2 Series",children:[i.jsx("option",{value:"H2C",children:"H2C"}),i.jsx("option",{value:"H2D",children:"H2D"}),i.jsx("option",{value:"H2D Pro",children:"H2D Pro"}),i.jsx("option",{value:"H2S",children:"H2S"})]}),i.jsxs("optgroup",{label:"X1 Series",children:[i.jsx("option",{value:"X1E",children:"X1E"}),i.jsx("option",{value:"X1C",children:"X1 Carbon"}),i.jsx("option",{value:"X1",children:"X1"})]}),i.jsxs("optgroup",{label:"P Series",children:[i.jsx("option",{value:"P2S",children:"P2S"}),i.jsx("option",{value:"P1S",children:"P1S"}),i.jsx("option",{value:"P1P",children:"P1P"})]}),i.jsxs("optgroup",{label:"A1 Series",children:[i.jsx("option",{value:"A1",children:"A1"}),i.jsx("option",{value:"A1 Mini",children:"A1 Mini"})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Location / Group"}),i.jsx("input",{type:"text",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",value:s.location,onChange:u=>o({...s,location:u.target.value}),placeholder:n("printers.modal.locationPlaceholder")}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("printers.locationHelp")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"checkbox",id:"edit_auto_archive",checked:s.auto_archive,onChange:u=>o({...s,auto_archive:u.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("label",{htmlFor:"edit_auto_archive",className:"text-sm text-bambu-gray",children:n("printers.modal.autoArchiveLabel")})]}),i.jsxs("div",{className:"flex gap-3 pt-4",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:n("common.cancel")}),i.jsx(Oe,{type:"submit",className:"flex-1",disabled:l.isPending,children:l.isPending?n("common.saving"):n("printers.modal.saveChanges")})]})]})]})})})}function mVe(t){const{data:e}=et({queryKey:["printerStatus",t],queryFn:()=>be.getPrinterStatus(t),refetchInterval:3e4});return!e?.connected}function hVe({printer:t,plug:e,onPowerOn:n,isPowering:r}){const a=mVe(t.id),{data:s}=et({queryKey:["smartPlugStatus",e.id],queryFn:()=>be.getSmartPlugStatus(e.id),refetchInterval:1e4});return a?i.jsxs("div",{className:"flex items-center justify-between px-3 py-2 hover:bg-gray-100 dark:hover:bg-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[i.jsx("span",{className:"text-sm text-gray-900 dark:text-white truncate",children:t.name}),s&&i.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${s.state==="ON"?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:s.state||"?"})]}),i.jsxs("button",{onClick:()=>n(e.id),disabled:r||s?.state==="ON",className:`px-2 py-1 text-xs rounded transition-colors flex items-center gap-1 ${s?.state==="ON"?"bg-bambu-green/20 text-bambu-green cursor-default":"bg-bambu-green/20 text-bambu-green hover:bg-bambu-green hover:text-white"}`,children:[i.jsx(Vd,{className:"w-3 h-3"}),r?"...":"On"]})]}):null}function pVe(){const{t}=Ft(),[e,n]=w.useState(!1),[r,a]=w.useState(()=>localStorage.getItem("hideDisconnectedPrinters")==="true"),[s,o]=w.useState(!1),[l,c]=w.useState(null),[u,d]=w.useState(()=>localStorage.getItem("printerSortBy")||"name"),[m,p]=w.useState(()=>localStorage.getItem("printerSortAsc")!=="false"),[f,y]=w.useState(()=>{const ne=localStorage.getItem("printerCardSize");return ne?parseInt(ne,10):2}),v=f===1?"compact":"expanded",x=an(),{showToast:g}=fn(),{hasPermission:_}=_r(),[N,T]=w.useState(()=>{const ne=localStorage.getItem("openEmbeddedCameras");if(ne)try{const O=JSON.parse(ne);return new Map(O.map(V=>[V.id,V]))}catch{return new Map}return new Map});w.useEffect(()=>{const ne=Array.from(N.values());ne.length>0?localStorage.setItem("openEmbeddedCameras",JSON.stringify(ne)):localStorage.removeItem("openEmbeddedCameras")},[N]);const{data:C,isLoading:A}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:k}=et({queryKey:["settings"],queryFn:be.getSettings}),R=w.useMemo(()=>{if(k?.drying_presets)try{const ne=JSON.parse(k.drying_presets);if(typeof ne=="object"&&ne!==null&&Object.keys(ne).length>0)return{...EF,...ne}}catch{}return EF},[k?.drying_presets]);w.useEffect(()=>{k?.camera_view_mode==="window"&&N.size>0&&T(new Map)},[k?.camera_view_mode,N.size]);const{data:P}=et({queryKey:["smart-plugs"],queryFn:be.getSmartPlugs}),{data:D}=et({queryKey:["maintenanceOverview"],queryFn:be.getMaintenanceOverview,staleTime:60*1e3}),{data:H}=et({queryKey:["spoolman-status"],queryFn:be.getSpoolmanStatus,staleTime:60*1e3}),z=H?.enabled&&H?.connected,{data:G}=et({queryKey:["spoolman-settings"],queryFn:be.getSpoolmanSettings,enabled:!!z,staleTime:60*1e3}),I=G?.spoolman_sync_mode,{data:ee}=et({queryKey:["unlinked-spools"],queryFn:be.getUnlinkedSpools,enabled:!!z,staleTime:30*1e3}),ie=ee&&ee.length>0,{data:X}=et({queryKey:["linked-spools"],queryFn:be.getLinkedSpools,enabled:!!z,staleTime:30*1e3}),me=X?.linked,{data:he}=et({queryKey:["spool-assignments"],queryFn:()=>be.getAssignments(),enabled:_("inventory:view_assignments"),staleTime:30*1e3}),ge=pt({mutationFn:({printerId:ne,amsId:O,trayId:V})=>be.unassignSpool(ne,O,V),onSuccess:()=>{x.invalidateQueries({queryKey:["spool-assignments"]})}}),Y=(ne,O,V)=>he?.find(J=>J.printer_id===ne&&J.ams_id===Number(O)&&J.tray_id===Number(V)),oe=D?.reduce((ne,O)=>(ne[O.printer_id]={due_count:O.due_count,warning_count:O.warning_count,total_print_hours:O.total_print_hours},ne),{})||{},le=P?.reduce((ne,O)=>(O.printer_id&&(ne[O.printer_id]=O),ne),{})||{},xe=pt({mutationFn:be.createPrinter,onSuccess:()=>{x.invalidateQueries({queryKey:["printers"]}),x.invalidateQueries({queryKey:["maintenanceOverview"]}),n(!1)},onError:ne=>g(ne.message||t("printers.toast.failedToAdd"),"error")}),Pe=pt({mutationFn:ne=>be.controlSmartPlug(ne,"on"),onSuccess:()=>{x.invalidateQueries({queryKey:["smart-plugs"]}),c(null)},onError:()=>{c(null)}}),q=()=>{const ne=!r;a(ne),localStorage.setItem("hideDisconnectedPrinters",String(ne))},Z=ne=>{d(ne),localStorage.setItem("printerSortBy",ne)},j=()=>{const ne=!m;p(ne),localStorage.setItem("printerSortAsc",String(ne))},E=()=>{switch(f){case 1:return"grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5";case 2:return"grid-cols-1 md:grid-cols-2 xl:grid-cols-3";case 3:return"grid-cols-1 lg:grid-cols-2";case 4:return"grid-cols-1";default:return"grid-cols-1 md:grid-cols-2 xl:grid-cols-3"}},U=["S","M","L","XL"],K=w.useMemo(()=>{if(!C)return[];const ne=[...C];switch(u){case"name":ne.sort((O,V)=>O.name.localeCompare(V.name));break;case"model":ne.sort((O,V)=>(O.model||"").localeCompare(V.model||""));break;case"location":ne.sort((O,V)=>{const J=O.location||"",W=V.location||"";return!J&&W?1:J&&!W?-1:J.localeCompare(W)||O.name.localeCompare(V.name)});break;case"status":ne.sort((O,V)=>{const J=x.getQueryData(["printerStatus",O.id]),W=x.getQueryData(["printerStatus",V.id]),re=ue=>ue?.connected?ue.state==="RUNNING"?0:1:2;return re(J)-re(W)});break}return m||ne.reverse(),ne},[C,u,m,x]),$=w.useMemo(()=>{if(u!=="location")return null;const ne={};return K.forEach(O=>{const V=O.location||"Ungrouped";ne[V]||(ne[V]=[]),ne[V].push(O)}),ne},[u,K]);return i.jsxs("div",{className:"p-4 md:p-8",children:[i.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6",children:[i.jsxs("div",{children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:t("printers.title")}),i.jsx(lVe,{printers:C})]}),i.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 flex-wrap",children:[i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsxs("select",{value:u,onChange:ne=>Z(ne.target.value),className:"text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg px-2 py-1.5 text-white focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"name",children:t("printers.sort.name")}),i.jsx("option",{value:"status",children:t("printers.sort.status")}),i.jsx("option",{value:"model",children:t("printers.sort.model")}),i.jsx("option",{value:"location",children:t("printers.sort.location")})]}),i.jsx("button",{onClick:j,className:"p-1.5 rounded-lg hover:bg-bambu-dark-tertiary transition-colors",title:t(m?"printers.sort.descending":"printers.sort.ascending"),children:m?i.jsx(yf,{className:"w-4 h-4 text-bambu-gray"}):i.jsx(tx,{className:"w-4 h-4 text-bambu-gray"})})]}),i.jsx("div",{className:"flex items-center bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:U.map((ne,O)=>{const V=O+1,J=f===V;return i.jsx("button",{onClick:()=>{y(V),localStorage.setItem("printerCardSize",String(V))},className:`px-2 py-1.5 text-xs font-medium transition-colors ${O===0?"rounded-l-lg":""} ${O===U.length-1?"rounded-r-lg":""} ${J?"bg-bambu-green text-white":"text-bambu-gray hover:bg-bambu-dark-tertiary hover:text-white"}`,title:t(ne==="S"?"printers.cardSize.small":ne==="M"?"printers.cardSize.medium":ne==="L"?"printers.cardSize.large":"printers.cardSize.extraLarge"),children:ne},ne)})}),i.jsx("div",{className:"w-px h-6 bg-bambu-dark-tertiary"}),i.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:r,onChange:q,className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),t("printers.hideOffline")]}),r&&Object.keys(le).length>0&&i.jsxs("div",{className:"relative",children:[i.jsxs("button",{onClick:()=>o(!s),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-white dark:bg-bambu-dark-secondary border border-gray-200 dark:border-bambu-dark-tertiary rounded-lg text-gray-600 dark:text-bambu-gray hover:text-gray-900 dark:hover:text-white hover:border-bambu-green transition-colors",children:[i.jsx(Vd,{className:"w-4 h-4"}),t("printers.powerOn"),i.jsx(Ln,{className:`w-3 h-3 transition-transform ${s?"rotate-180":""}`})]}),s&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>o(!1)}),i.jsxs("div",{className:"absolute right-0 mt-2 w-56 bg-white dark:bg-bambu-dark-secondary border border-gray-200 dark:border-bambu-dark-tertiary rounded-lg shadow-lg z-20 py-1",children:[i.jsx("div",{className:"px-3 py-2 text-xs text-gray-500 dark:text-bambu-gray border-b border-gray-200 dark:border-bambu-dark-tertiary",children:t("printers.offlinePrintersWithPlugs")}),C?.filter(ne=>le[ne.id]).map(ne=>i.jsx(hVe,{printer:ne,plug:le[ne.id],onPowerOn:O=>{c(O),Pe.mutate(O)},isPowering:l===le[ne.id]?.id},ne.id)),C?.filter(ne=>le[ne.id]).length===0&&i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No printers with smart plugs"})]})]})]}),i.jsxs(Oe,{onClick:()=>n(!0),disabled:!_("printers:create"),title:_("printers:create")?void 0:t("printers.permission.noAdd"),children:[i.jsx(ar,{className:"w-4 h-4"}),t("printers.addPrinter")]})]})]}),A?i.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("common.loading")}):C?.length===0?i.jsx(Mt,{children:i.jsxs(Dt,{className:"text-center py-12",children:[i.jsx("p",{className:"text-bambu-gray mb-4",children:t("printers.noPrintersConfigured")}),i.jsxs(Oe,{onClick:()=>n(!0),disabled:!_("printers:create"),title:_("printers:create")?void 0:t("printers.permission.noAdd"),children:[i.jsx(ar,{className:"w-4 h-4"}),t("printers.addPrinter")]})]})}):$?i.jsx("div",{className:"space-y-6",children:Object.entries($).map(([ne,O])=>i.jsxs("div",{children:[i.jsxs("h2",{className:"text-lg font-semibold text-white mb-3 flex items-center gap-2",children:[i.jsx("span",{className:"w-2 h-2 rounded-full bg-bambu-green"}),ne,i.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",O.length,")"]})]}),i.jsx("div",{className:`grid gap-4 ${f>=3?"gap-6":""} ${E()}`,children:O.map(V=>i.jsx(NW,{printer:V,hideIfDisconnected:r,maintenanceInfo:oe[V.id],viewMode:v,cardSize:f,amsThresholds:k?{humidityGood:Number(k.ams_humidity_good)||40,humidityFair:Number(k.ams_humidity_fair)||60,tempGood:Number(k.ams_temp_good)||28,tempFair:Number(k.ams_temp_fair)||35}:void 0,spoolmanEnabled:z,hasUnlinkedSpools:ie,linkedSpools:me,spoolmanUrl:H?.url,spoolmanSyncMode:I,onGetAssignment:Y,onUnassignSpool:(J,W,re)=>ge.mutate({printerId:J,amsId:W,trayId:re}),timeFormat:k?.time_format||"system",cameraViewMode:k?.camera_view_mode||"window",onOpenEmbeddedCamera:(J,W)=>T(re=>new Map(re).set(J,{id:J,name:W})),checkPrinterFirmware:k?.check_printer_firmware!==!1,dryingPresets:R},V.id))})]},ne))}):i.jsx("div",{className:`grid gap-4 ${f>=3?"gap-6":""} ${E()}`,children:K.map(ne=>i.jsx(NW,{printer:ne,hideIfDisconnected:r,maintenanceInfo:oe[ne.id],viewMode:v,cardSize:f,spoolmanEnabled:z,hasUnlinkedSpools:ie,linkedSpools:me,spoolmanUrl:H?.url,spoolmanSyncMode:I,onGetAssignment:Y,onUnassignSpool:(O,V,J)=>ge.mutate({printerId:O,amsId:V,trayId:J}),amsThresholds:k?{humidityGood:Number(k.ams_humidity_good)||40,humidityFair:Number(k.ams_humidity_fair)||60,tempGood:Number(k.ams_temp_good)||28,tempFair:Number(k.ams_temp_fair)||35}:void 0,timeFormat:k?.time_format||"system",cameraViewMode:k?.camera_view_mode||"window",onOpenEmbeddedCamera:(O,V)=>T(J=>new Map(J).set(O,{id:O,name:V})),checkPrinterFirmware:k?.check_printer_firmware!==!1,dryingPresets:R},ne.id))}),e&&i.jsx(cVe,{onClose:()=>n(!1),onAdd:ne=>xe.mutate(ne),existingSerials:C?.map(ne=>ne.serial_number)||[]}),Array.from(N.values()).map((ne,O)=>i.jsx(mMe,{printerId:ne.id,printerName:ne.name,viewerIndex:O,onClose:()=>T(V=>{const J=new Map(V);return J.delete(ne.id),J})},ne.id))]})}function fVe(){const t=navigator.userAgent.toLowerCase(),e=navigator.platform?.toLowerCase()||"";return t.includes("win")||e.includes("win")?"windows":t.includes("mac")||e.includes("mac")?"macos":t.includes("linux")||e.includes("linux")?"linux":"unknown"}function Qp(t,e="bambu_studio"){let n;e==="orcaslicer"?n=`orcaslicer://open?file=${t}`:fVe()==="macos"?n=`bambustudioopen://${encodeURIComponent(t)}`:n=`bambustudio://open?file=${t}`;const r=document.createElement("a");r.href=n,r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r)}const kW=768;function aie(){const[t,e]=w.useState(()=>typeof window<"u"?window.innerWidth{const n=window.matchMedia(`(max-width: ${kW-1}px)`),r=a=>{e(a.matches)};return e(n.matches),n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),t}function M4({archiveId:t,libraryFileId:e,title:n,fileType:r,onClose:a}){const{t:s}=Ft(),{data:o}=et({queryKey:["settings"],queryFn:be.getSettings}),l=o?.preferred_slicer||"bambu_studio",c=e!=null,[u,d]=w.useState(null),[m,p]=w.useState(null),[f,y]=w.useState(!0),[v,x]=w.useState(null),[g,_]=w.useState(!1),[N,T]=w.useState(null),[C,A]=w.useState(0),[k,R]=w.useState(!1),[P,D]=w.useState(null),[H,z]=w.useState(!1),[G,I]=w.useState(!1),ee=w.useRef(null),ie=w.useRef(null),X=10,me=160,he=240,ge=.35;w.useEffect(()=>{const ye=ae=>{ae.key==="Escape"&&a()};return window.addEventListener("keydown",ye),()=>window.removeEventListener("keydown",ye)},[a]),w.useEffect(()=>{if(y(!0),c){const ye=(r||"").toLowerCase(),ae=ye==="3mf"||ye==="stl",L=ye==="gcode"||ye==="3mf";p({has_model:ae,has_gcode:L,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),d(ae?"3d":L?"gcode":null),y(!1);return}if(!t){p(null),d(null),y(!1);return}be.getArchiveCapabilities(t).then(ye=>{p(ye),ye.has_model?d("3d"):ye.has_gcode&&d("gcode"),y(!1)}).catch(()=>{p({has_model:!0,has_gcode:!1,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),d("3d"),y(!1)})},[t,r,c]),w.useEffect(()=>{if(_(!0),T(null),A(0),c){const ye=(r||"").toLowerCase();if(!e||ye!=="3mf"){x(null),_(!1);return}be.getLibraryFilePlates(e).then(ae=>x(ae)).catch(()=>x(null)).finally(()=>_(!1));return}if(!t){x(null),_(!1);return}be.getArchivePlates(t).then(ye=>x(ye)).catch(()=>x(null)).finally(()=>_(!1))},[t,r,c,e]);const Y=w.useMemo(()=>v?.plates??[],[v]),oe=(v?.is_multi_plate??!1)&&Y.length>1,le=k&&oe,xe=N==null?null:Y.find(ye=>ye.index===N)??null,Pe=ye=>ye.object_count??ye.objects?.length??0,q=Y.reduce((ye,ae)=>ye+Pe(ae),0),Z=xe?Pe(xe):q,j=xe?s("modelViewer.plateNumber",{number:xe.index}):s("modelViewer.allPlates"),E=Y.length>0,U=w.useRef(null),K=w.useRef(null),[$,ne]=w.useState(10),[O,V]=w.useState(3),J=Y.length>$,W=Math.max(1,Math.ceil(Y.length/$)),re=J?Y.slice(C*$,(C+1)*$):Y;w.useEffect(()=>{if(!le){ne(10),V(3);return}const ye=U.current,ae=K.current;if(!ye||!ae)return;let L=0;const F=()=>{const pe=ae.clientWidth,Ne=Math.floor(pe/210),Se=Math.max(3,Math.min(5,Ne||3));V(ce=>ce===Se?ce:Se);const Le=window.getComputedStyle(ye),qe=Number.parseFloat(Le.rowGap||"0"),Te=ye.querySelector("button")?.getBoundingClientRect().height??44,Ae=ae.clientHeight,je=Math.max(1,Math.floor((Ae+qe)/(Te+qe)))*Se,Xe=Math.max(1,je-1);ne(ce=>ce===Xe?ce:Xe)},te=()=>{L&&cancelAnimationFrame(L),L=requestAnimationFrame(F)};te();const ve=new ResizeObserver(te);return ve.observe(ae),ve.observe(ye),()=>{L&&cancelAnimationFrame(L),ve.disconnect()}},[le,Y.length]),w.useEffect(()=>{if(!J){A(0);return}A(ye=>Math.min(ye,W-1))},[Y.length,J,W]),w.useEffect(()=>{if(!J||N==null)return;const ye=Y.findIndex(L=>L.index===N);if(ye<0)return;const ae=Math.floor(ye/$);A(L=>L===ae?L:ae)},[Y,$,N,J]),w.useEffect(()=>{if(!le){D(null),I(!1);return}if(G)return;const ye=ee.current,ae=ie.current;if(!ye||!ae)return;const L=ye.clientHeight;if(!L)return;const F=Math.max(he,L*ge),te=Math.max(me,L-X-F),ve=Math.min(ae.scrollHeight,te);D(Math.max(me,ve))},[le,G,Y.length,C,X,me,he,ge]),w.useEffect(()=>{if(!H)return;const ye=L=>{const F=ee.current;if(!F)return;const te=F.getBoundingClientRect(),ve=te.height;if(!ve)return;const pe=Math.max(he,ve*ge),de=Math.max(me,ve-X-pe),Ne=Math.min(de,Math.max(me,L.clientY-te.top));D(Ne)},ae=()=>{z(!1),I(!0)};return document.addEventListener("mousemove",ye),document.addEventListener("mouseup",ae),document.body.style.cursor="row-resize",document.body.style.userSelect="none",()=>{document.removeEventListener("mousemove",ye),document.removeEventListener("mouseup",ae),document.body.style.cursor="",document.body.style.userSelect=""}},[H,X,me,he,ge]);const ue=c?(r||"").toLowerCase()==="3mf":!0,fe=async()=>{if(!ue)return;const ye=n||"model";try{if(c){const{token:ae}=await be.createLibrarySlicerToken(e),L=be.getLibrarySlicerDownloadUrl(e,ae,ye);Qp(`${window.location.origin}${L}`,l)}else{const{token:ae}=await be.createArchiveSlicerToken(t),L=be.getArchiveSlicerDownloadUrl(t,ae,ye);Qp(`${window.location.origin}${L}`,l)}}catch{if(c){const ae=`${window.location.origin}${be.getLibraryFileDownloadUrl(e)}`;Qp(ae,l)}else{const ae=`${window.location.origin}${be.getArchiveForSlicer(t,ye)}`;Qp(ae,l)}}};return i.jsx("div",{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 ${k?"p-0":"p-8"}`,onClick:a,children:i.jsxs("div",{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary w-full flex flex-col ${k?"h-full max-w-none rounded-none":"h-[80vh] max-w-4xl rounded-xl"}`,onClick:ye=>ye.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1 mr-4",children:[i.jsx("h2",{className:"text-lg font-semibold text-white truncate",children:n}),E&&i.jsxs("span",{className:"text-xs text-bambu-gray bg-bambu-dark-tertiary/70 px-2 py-1 rounded whitespace-nowrap",children:[j,": ",s("modelViewer.objectCount",{count:Z})]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:fe,disabled:!ue,children:[i.jsx(Jr,{className:"w-4 h-4"}),s("modelViewer.openInSlicer")]}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>R(ye=>!ye),title:k?"Exit fullscreen":"Enter fullscreen",children:k?i.jsx(BL,{className:"w-4 h-4"}):i.jsx(eT,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:a,children:i.jsx(Ht,{className:"w-5 h-5"})})]})]}),m&&i.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary",children:[i.jsxs("button",{onClick:()=>m.has_model&&d("3d"),disabled:!m.has_model,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${u==="3d"?"text-bambu-green border-b-2 border-bambu-green":m.has_model?"text-bambu-gray hover:text-white":"text-bambu-gray/30 cursor-not-allowed"}`,children:[i.jsx(ra,{className:"w-4 h-4"}),s("modelViewer.tabs.model"),!m.has_model&&i.jsxs("span",{className:"text-xs",children:["(",s("modelViewer.notAvailable"),")"]})]}),i.jsxs("button",{onClick:()=>m.has_gcode&&d("gcode"),disabled:!m.has_gcode,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${u==="gcode"?"text-bambu-green border-b-2 border-bambu-green":m.has_gcode?"text-bambu-gray hover:text-white":"text-bambu-gray/30 cursor-not-allowed"}`,children:[i.jsx(cpe,{className:"w-4 h-4"}),s("modelViewer.tabs.gcode"),!m.has_gcode&&i.jsxs("span",{className:"text-xs",children:["(",s("modelViewer.notSliced"),")"]})]})]}),i.jsx("div",{className:"flex-1 overflow-hidden p-4",children:f?i.jsx("div",{className:"w-full h-full flex items-center justify-center",children:i.jsx(ht,{className:"w-8 h-8 animate-spin text-bambu-green"})}):u==="3d"&&m?i.jsxs("div",{ref:ee,className:`w-full h-full flex flex-col ${le?"gap-0 min-h-0":"gap-3"}`,children:[oe&&i.jsxs("div",{ref:ie,style:le&&P!=null?{height:P}:void 0,className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-3 ${le?"flex flex-col shrink-0":""}`,children:[i.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray mb-2",children:[i.jsx(Gi,{className:"w-4 h-4"}),s("modelViewer.plates"),g&&i.jsx(ht,{className:"w-3 h-3 animate-spin"})]}),i.jsxs("div",{className:le?"flex flex-col min-h-0 flex-1":void 0,children:[i.jsx("div",{ref:K,className:le?"min-h-0 overflow-hidden pr-1 flex-1":void 0,children:i.jsxs("div",{ref:U,className:le?"grid gap-2":"grid grid-cols-2 md:grid-cols-3 gap-2",style:le?{gridTemplateColumns:`repeat(${O}, minmax(0, 1fr))`}:void 0,children:[i.jsxs("button",{type:"button",onClick:()=>T(null),className:`flex items-center rounded-lg border text-left transition-colors ${le?"gap-1.5 p-1.5 w-full":"gap-2 p-2"} ${N==null?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray"}`,children:[i.jsx("div",{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${le?"w-8 h-8":"w-10 h-10"}`,children:i.jsx(Gi,{className:`${le?"w-4 h-4":"w-5 h-5"} text-bambu-gray`})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:`${le?"text-xs":"text-sm"} text-white font-medium truncate`,children:s("modelViewer.allPlates")}),i.jsx("p",{className:`${le?"text-[10px]":"text-xs"} text-bambu-gray truncate`,children:s("modelViewer.plateCount",{count:Y.length})})]}),N==null&&i.jsx(Yr,{className:`${le?"w-3.5 h-3.5":"w-4 h-4"} text-bambu-green flex-shrink-0`})]}),re.map(ye=>i.jsxs("button",{type:"button",onClick:()=>T(ye.index),className:`flex items-center rounded-lg border text-left transition-colors ${le?"gap-1.5 p-1.5 w-full":"gap-2 p-2"} ${N===ye.index?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray"}`,children:[ye.has_thumbnail&&ye.thumbnail_url?i.jsx("img",{src:ye.thumbnail_url,alt:`Plate ${ye.index}`,className:`${le?"w-8 h-8":"w-10 h-10"} rounded object-cover bg-bambu-dark-tertiary`}):i.jsx("div",{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${le?"w-8 h-8":"w-10 h-10"}`,children:i.jsx(Gi,{className:`${le?"w-4 h-4":"w-5 h-5"} text-bambu-gray`})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:`${le?"text-xs":"text-sm"} text-white font-medium truncate`,children:ye.name||s("modelViewer.plateNumber",{number:ye.index})}),i.jsx("p",{className:`${le?"text-[10px]":"text-xs"} text-bambu-gray truncate`,children:s("modelViewer.objectCount",{count:ye.object_count??ye.objects?.length??0})})]}),N===ye.index&&i.jsx(Yr,{className:`${le?"w-3.5 h-3.5":"w-4 h-4"} text-bambu-green flex-shrink-0`})]},ye.index))]})}),(xe||J)&&i.jsxs("div",{className:"mt-auto pt-3 flex items-center gap-4 text-xs text-bambu-gray overflow-x-auto",children:[xe&&i.jsxs("div",{className:"flex items-center gap-3 whitespace-nowrap",children:[i.jsx("span",{children:s("modelViewer.plateNumber",{number:xe.index})}),xe.print_time_seconds!=null&&i.jsx("span",{children:s("modelViewer.eta",{minutes:Math.round(xe.print_time_seconds/60)})}),xe.filament_used_grams!=null&&i.jsxs("span",{children:[xe.filament_used_grams.toFixed(1)," g"]}),xe.filaments.length>0&&i.jsx("span",{children:s("modelViewer.filamentCount",{count:xe.filaments.length})})]}),J&&i.jsxs("div",{className:`flex items-center gap-2 whitespace-nowrap ${xe?"ml-auto":""}`,children:[i.jsx("span",{children:s("modelViewer.pagination.pageOf",{current:C+1,total:W})}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("button",{type:"button",onClick:()=>A(ye=>Math.max(ye-1,0)),disabled:C===0,className:`px-2 py-1 rounded border text-xs ${C===0?"border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed":"border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray"}`,children:s("modelViewer.pagination.prev")}),(()=>{let ae=Math.max(0,C-Math.floor(2.5));const L=Math.min(W,ae+5);L-ae<5&&(ae=Math.max(0,L-5));const F=Array.from({length:L-ae},(te,ve)=>ae+ve);return i.jsxs(i.Fragment,{children:[ae>0&&i.jsx("button",{type:"button",onClick:()=>A(0),className:`px-2 py-1 rounded border text-xs ${C===0?"border-bambu-green text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray"}`,children:"1"}),ae>1&&i.jsx("span",{className:"px-1",children:"…"}),F.map(te=>i.jsx("button",{type:"button",onClick:()=>A(te),className:`px-2 py-1 rounded border text-xs ${C===te?"border-bambu-green text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray"}`,children:te+1},te)),LA(W-1),className:`px-2 py-1 rounded border text-xs ${C===W-1?"border-bambu-green text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray"}`,children:W})]})})(),i.jsx("button",{type:"button",onClick:()=>A(ye=>Math.min(ye+1,W-1)),disabled:C>=W-1,className:`px-2 py-1 rounded border text-xs ${C>=W-1?"border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed":"border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray"}`,children:s("modelViewer.pagination.next")})]})]})]})]})]}),le&&i.jsx("div",{role:"separator","aria-orientation":"horizontal",onMouseDown:ye=>{ye.preventDefault(),z(!0),I(!0)},className:`h-2 cursor-row-resize flex items-center justify-center ${H?"bg-bambu-dark-tertiary":"bg-bambu-dark-secondary/60 hover:bg-bambu-dark-tertiary"}`,children:i.jsx("div",{className:"w-12 h-1 rounded-full bg-bambu-gray/50"})}),i.jsx("div",{className:`flex-1 ${le?"min-h-0":""}`,children:i.jsx(XQ,{url:c?be.getLibraryFileDownloadUrl(e):m.has_source?be.getSource3mfDownloadUrl(t):be.getArchiveDownload(t),fileType:r,buildVolume:m.build_volume,filamentColors:m.filament_colors,selectedPlateId:N,className:"w-full h-full"})})]}):u==="gcode"&&m?i.jsx(jZ,{gcodeUrl:c?be.getLibraryFileGcodeUrl(e):be.getArchiveGcode(t),filamentColors:m.filament_colors,className:"w-full h-full"}):i.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:s("modelViewer.noPreview")})})]})})}function gVe({onClose:t,initialFiles:e}){const{t:n}=Ft(),r=an(),{showToast:a}=fn(),s=w.useRef(null),[o,l]=w.useState(()=>e?.filter(C=>C.name.endsWith(".3mf")).map(C=>({file:C,status:"pending"}))||[]),[c,u]=w.useState(!1),[d,m]=w.useState(null);w.useEffect(()=>{const C=A=>{A.key==="Escape"&&t()};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[t]);const p=pt({mutationFn:C=>be.uploadArchivesBulk(C),onSuccess:C=>{m(C),r.invalidateQueries({queryKey:["archives"]}),r.invalidateQueries({queryKey:["archiveStats"]}),l(A=>A.map(k=>{const R=C.results.find(D=>D.filename===k.file.name),P=C.errors.find(D=>D.filename===k.file.name);return R?{...k,status:"success",archiveId:R.id}:P?{...k,status:"error",error:P.error}:k})),C.failed===0?a(`${C.uploaded} file${C.uploaded!==1?"s":""} uploaded`):C.uploaded===0?a(`Failed to upload ${C.failed} file${C.failed!==1?"s":""}`,"error"):a(`${C.uploaded} uploaded, ${C.failed} failed`,"warning")},onError:()=>{l(C=>C.map(A=>({...A,status:"error",error:"Upload failed"}))),a("Upload failed","error")}}),f=w.useCallback(C=>{C.preventDefault(),u(!0)},[]),y=w.useCallback(C=>{C.preventDefault(),u(!1)},[]),v=w.useCallback(C=>{C.preventDefault(),u(!1);const A=Array.from(C.dataTransfer.files).filter(k=>k.name.endsWith(".3mf"));A.length>0&&l(k=>[...k,...A.map(R=>({file:R,status:"pending"}))])},[]),x=w.useCallback(C=>{const A=Array.from(C.target.files||[]).filter(k=>k.name.endsWith(".3mf"));A.length>0&&l(k=>[...k,...A.map(R=>({file:R,status:"pending"}))]),s.current&&(s.current.value="")},[]),g=w.useCallback(C=>{l(A=>A.filter((k,R)=>R!==C))},[]),_=()=>{if(o.length===0)return;const C=o.filter(A=>A.status==="pending");C.length!==0&&(l(A=>A.map(k=>k.status==="pending"?{...k,status:"uploading"}:k)),p.mutate(C.map(A=>A.file)))},N=o.filter(C=>C.status==="pending").length,T=p.isPending;return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:i.jsx(Mt,{className:"w-full max-w-2xl max-h-[90vh] flex flex-col",children:i.jsxs(Dt,{className:"p-0 flex flex-col h-full",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsx("h2",{className:"text-xl font-semibold text-white",children:n("uploadModal.title")}),i.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsx("div",{className:"p-4",children:i.jsxs("div",{className:`border-2 border-dashed rounded-lg p-8 text-center transition-colors ${c?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,onDragOver:f,onDragLeave:y,onDrop:v,children:[i.jsx(xi,{className:"w-12 h-12 mx-auto mb-4 text-bambu-gray"}),i.jsx("p",{className:"text-white mb-2",children:n("uploadModal.dragDrop")}),i.jsx("p",{className:"text-bambu-gray text-sm mb-4",children:n("uploadModal.or")}),i.jsx(Oe,{variant:"secondary",onClick:()=>s.current?.click(),disabled:T,children:n("uploadModal.browseFiles")}),i.jsx("input",{ref:s,type:"file",accept:".3mf",multiple:!0,className:"hidden",onChange:x})]})}),i.jsx("div",{className:"px-4 pb-4",children:i.jsx("p",{className:"text-xs text-bambu-gray",children:n("uploadModal.extractionInfo")})}),o.length>0&&i.jsx("div",{className:"px-4 pb-4 max-h-60 overflow-y-auto",children:i.jsx("div",{className:"space-y-2",children:o.map((C,A)=>i.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg",children:[i.jsx(XC,{className:"w-5 h-5 text-bambu-gray flex-shrink-0"}),i.jsx("span",{className:"flex-1 text-white text-sm truncate",children:C.file.name}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:[(C.file.size/(1024*1024)).toFixed(1)," MB"]}),C.status==="pending"&&i.jsx("button",{onClick:()=>g(A),className:"text-bambu-gray hover:text-red-400 transition-colors",disabled:T,children:i.jsx(Ht,{className:"w-4 h-4"})}),C.status==="uploading"&&i.jsx(ht,{className:"w-4 h-4 text-bambu-green animate-spin"}),C.status==="success"&&i.jsx(fr,{className:"w-4 h-4 text-bambu-green"}),C.status==="error"&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-xs text-red-400",children:C.error}),i.jsx(Li,{className:"w-4 h-4 text-red-400"})]})]},`${C.file.name}-${A}`))})}),d&&i.jsx("div",{className:"px-4 pb-4",children:i.jsx("div",{className:"p-3 bg-bambu-dark rounded-lg",children:i.jsxs("p",{className:"text-sm text-white",children:[i.jsx("span",{className:"text-bambu-green",children:d.uploaded})," ",n("uploadModal.uploaded"),d.failed>0&&i.jsxs(i.Fragment,{children:[", ",i.jsx("span",{className:"text-red-400",children:d.failed})," ",n("uploadModal.failed")]})]})})}),i.jsxs("div",{className:"flex gap-3 p-4 border-t border-bambu-dark-tertiary",children:[i.jsx(Oe,{variant:"secondary",onClick:t,className:"flex-1",children:n(d?"common.close":"common.cancel")}),!d&&i.jsx(Oe,{onClick:_,disabled:N===0||T,className:"flex-1",children:T?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),n("uploadModal.uploading")]}):i.jsxs(i.Fragment,{children:[i.jsx(xi,{className:"w-4 h-4"}),n("uploadModal.upload")," ",N>0&&`(${N})`]})})]})]})})})}const bVe=["adhesionFailure","spaghettiDetached","layerShift","cloggedNozzle","filamentRunout","warping","stringing","underExtrusion","powerFailure","userCancelled","other"],xVe=["completed","failed","aborted","printing"];function sie({archive:t,onClose:e,existingTags:n=[]}){const{t:r}=Ft();w.useEffect(()=>{const E=U=>{U.key==="Escape"&&e()};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[e]);const a=an(),[s,o]=w.useState(t.print_name||""),[l,c]=w.useState(t.printer_id),[u,d]=w.useState(t.project_id??null),[m,p]=w.useState(t.notes||""),[f,y]=w.useState(t.tags||""),[v,x]=w.useState(t.failure_reason||""),[g,_]=w.useState(t.status),[N,T]=w.useState(t.quantity??1),[C,A]=w.useState(t.photos||[]),[k,R]=w.useState(t.external_url||""),[P,D]=w.useState(!1),[H,z]=w.useState(!1),G=w.useRef(null),I=w.useRef(null),ee=w.useRef(null),{data:ie}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:X}=et({queryKey:["projects"],queryFn:()=>be.getProjects()}),{data:me}=et({queryKey:["tags"],queryFn:be.getTags,enabled:n.length===0}),he=n.length>0?n:me?.map(E=>E.name)||[],ge=f.split(",").map(E=>E.trim()).filter(Boolean),Y=f.includes(",")?f.substring(f.lastIndexOf(",")+1).trim().toLowerCase():f.trim().toLowerCase(),oe=he.filter(E=>!ge.includes(E)&&(Y===""||E.toLowerCase().includes(Y))),le=E=>{let U;if(Y&&!he.includes(Y)?U=f.includes(",")?f.substring(0,f.lastIndexOf(",")).split(",").map(K=>K.trim()).filter(Boolean):[]:U=ge,!U.includes(E)){const K=[...U,E].join(", ");y(K)}ee.current!==null&&clearTimeout(ee.current),G.current?.focus()},xe=E=>{const U=ge.filter(K=>K!==E).join(", ");y(U)},Pe=pt({mutationFn:E=>be.updateArchive(t.id,E),onSuccess:()=>{a.invalidateQueries({queryKey:["archives"]}),a.invalidateQueries({queryKey:["projects"]}),e()}}),q=async E=>{const U=E.target.files?.[0];if(U){D(!0);try{const K=await be.uploadArchivePhoto(t.id,U);A(K.photos),a.invalidateQueries({queryKey:["archives"]})}catch(K){console.error("Failed to upload photo:",K)}finally{D(!1),I.current&&(I.current.value="")}}},Z=async E=>{try{const U=await be.deleteArchivePhoto(t.id,E);A(U.photos||[]),a.invalidateQueries({queryKey:["archives"]})}catch(U){console.error("Failed to delete photo:",U)}},j=E=>{E.preventDefault();const U={print_name:s||void 0,printer_id:l,project_id:u,notes:m||void 0,tags:f||void 0,quantity:N,external_url:k||null};g!==t.status&&(U.status=g),g==="failed"||g==="aborted"?U.failure_reason=v||void 0:(t.status==="failed"||t.status==="aborted")&&(U.failure_reason=null),Pe.mutate(U)};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:i.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:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:r("editArchive.title")}),i.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:j,className:"p-6 space-y-4 overflow-y-auto flex-1",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("editArchive.name")}),i.jsx("input",{type:"text",value:s,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 focus:border-bambu-green focus:outline-none",placeholder:r("editArchive.namePlaceholder")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("editArchive.printer")}),i.jsxs("select",{value:l??"",onChange:E=>c(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:[i.jsx("option",{value:"",children:r("editArchive.noPrinter")}),ie?.map(E=>i.jsx("option",{value:E.id,children:E.name},E.id))]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i.jsx(fs,{className:"w-4 h-4 inline mr-1"}),r("editArchive.project")]}),i.jsxs("select",{value:u??"",onChange:E=>d(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:[i.jsx("option",{value:"",children:r("editArchive.noProject")}),X?.map(E=>i.jsx("option",{value:E.id,children:E.name},E.id))]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i.jsx(gfe,{className:"w-4 h-4 inline mr-1"}),r("editArchive.itemsPrinted")]}),i.jsx("input",{type:"number",min:1,value:N,onChange:E=>T(Math.max(1,parseInt(E.target.value)||1)),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:"1"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:r("editArchive.itemsPrintedHelp")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("editArchive.notes")}),i.jsx("textarea",{value:m,onChange:E=>p(E.target.value),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 resize-none",placeholder:r("editArchive.notesPlaceholder")})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i.jsx(Ox,{className:"w-4 h-4 inline mr-1"}),r("editArchive.externalLink")]}),i.jsx("input",{type:"url",value:k,onChange:E=>R(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",placeholder:"https://printables.com/model/..."}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:r("editArchive.externalLinkHelp")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("editArchive.tags")}),ge.length>0&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:ge.map(E=>i.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 bg-bambu-dark-tertiary rounded text-sm text-white",children:[i.jsx(Dd,{className:"w-3 h-3"}),E,i.jsx("button",{type:"button",onClick:()=>xe(E),className:"ml-0.5 text-bambu-gray hover:text-white",children:i.jsx(Ht,{className:"w-3 h-3"})})]},E))}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{ref:G,type:"text",value:f,onChange:E=>y(E.target.value),onFocus:()=>{ee.current!==null&&clearTimeout(ee.current),z(!0)},onBlur:()=>{ee.current=window.setTimeout(()=>z(!1),200)},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:ge.length>0?r("editArchive.addMoreTags"):r("editArchive.tagsPlaceholder")}),H&&oe.length>0&&i.jsxs("div",{className:"absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-10 max-h-40 overflow-y-auto",children:[i.jsxs("div",{className:"p-2 text-xs text-bambu-gray border-b border-bambu-dark-tertiary",children:[Y?r("editArchive.matchingTags",{query:Y}):r("editArchive.existingTags")," ",r("editArchive.clickToAdd")]}),i.jsx("div",{className:"p-2 flex flex-wrap gap-1.5",children:oe.map(E=>i.jsx("button",{type:"button",onClick:()=>le(E),className:"px-2 py-0.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded text-sm text-bambu-gray hover:text-white transition-colors",children:E},E))})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("editArchive.status")}),i.jsx("select",{value:g,onChange:E=>{_(E.target.value),E.target.value==="completed"&&x("")},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:xVe.map(E=>i.jsx("option",{value:E,children:r(`editArchive.statuses.${E}`)},E))})]}),(g==="failed"||g==="aborted")&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("editArchive.failureReason")}),i.jsxs("select",{value:v,onChange:E=>x(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:[i.jsx("option",{value:"",children:r("editArchive.selectReason")}),bVe.map(E=>i.jsx("option",{value:r(`editArchive.failureReasons.${E}`),children:r(`editArchive.failureReasons.${E}`)},E))]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i.jsx(rx,{className:"w-4 h-4 inline mr-1"}),r("editArchive.photos")]}),i.jsxs("div",{className:"flex flex-wrap gap-2 mb-2",children:[C.map(E=>i.jsxs("div",{className:"relative group",children:[i.jsx("img",{src:be.getArchivePhotoUrl(t.id,E),alt:r("editArchive.printResult"),className:"w-20 h-20 object-cover rounded-lg border border-bambu-dark-tertiary"}),i.jsx("button",{type:"button",onClick:()=>Z(E),className:"absolute -top-1 -right-1 p-1 bg-red-500 rounded-full opacity-0 group-hover:opacity-100 transition-opacity",children:i.jsx(Jt,{className:"w-3 h-3 text-white"})})]},E)),i.jsxs("label",{className:"w-20 h-20 flex items-center justify-center border-2 border-dashed border-bambu-dark-tertiary rounded-lg cursor-pointer hover:border-bambu-green transition-colors",children:[i.jsx("input",{ref:I,type:"file",accept:"image/jpeg,image/png,image/webp",onChange:q,className:"hidden",disabled:P}),P?i.jsx(ht,{className:"w-6 h-6 text-bambu-gray animate-spin"}):i.jsx(ar,{className:"w-6 h-6 text-bambu-gray"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:r("editArchive.photosHelp")})]}),i.jsxs("div",{className:"flex gap-3 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:r("common.cancel")}),i.jsxs(Oe,{type:"submit",disabled:Pe.isPending,className:"flex-1",children:[i.jsx(ts,{className:"w-4 h-4"}),Pe.isPending?r("common.saving"):r("common.save")]})]})]})]})})}function oie({x:t,y:e,items:n,onClose:r}){const a=w.useRef(null),[s,o]=w.useState(null),l=w.useRef(null),[c,u]=w.useState({x:t,y:e,visible:!1}),[d,m]=w.useState(!1),[p,f]=w.useState({});w.useEffect(()=>{const x=N=>{a.current&&!a.current.contains(N.target)&&r()},g=N=>{N.key==="Escape"&&r()},_=()=>{r()};return document.addEventListener("mousedown",x),document.addEventListener("keydown",g),document.addEventListener("scroll",_,!0),()=>{document.removeEventListener("mousedown",x),document.removeEventListener("keydown",g),document.removeEventListener("scroll",_,!0),l.current&&clearTimeout(l.current)}},[r]),w.useLayoutEffect(()=>{if(a.current){a.current.style.visibility="hidden",a.current.style.display="block";const x=a.current.getBoundingClientRect(),g=window.innerWidth,_=window.innerHeight,N=8;let T=t,C=e;t+x.width>g-N&&(T=Math.max(N,g-x.width-N)),T_-N&&(C=Math.max(N,_-x.height-N)),CA),u({x:T,y:C,visible:!0})}},[t,e]);const y=(x,g)=>{l.current&&(clearTimeout(l.current),l.current=null);const _=g.getBoundingClientRect(),N=window.innerHeight,T=300,k=N-_.top-8T;f(R=>({...R,[x]:k?"bottom":"top"})),o(x)},v=()=>{l.current=window.setTimeout(()=>{o(null)},150)};return i.jsx("div",{ref:a,className:"fixed z-50 min-w-[180px] max-w-[280px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1",style:{left:c.x,top:c.y,visibility:c.visible?"visible":"hidden"},children:n.map((x,g)=>{if(x.divider)return i.jsx("div",{className:"my-1 border-t border-bambu-dark-tertiary"},g);const _=x.submenu&&x.submenu.length>0;return i.jsxs("div",{className:"relative",onMouseEnter:N=>_&&y(g,N.currentTarget),onMouseLeave:()=>_&&v(),children:[i.jsxs("button",{onMouseEnter:N=>_&&y(g,N.currentTarget.parentElement),onClick:()=>{_?o(s===g?null:g):x.disabled||(x.onClick(),r())},disabled:x.disabled,title:x.title,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${x.disabled?"text-bambu-gray cursor-not-allowed":x.danger?"text-red-400 hover:bg-red-400/10":"text-white hover:bg-bambu-dark-tertiary"} ${_&&s===g?"bg-bambu-dark-tertiary":""}`,children:[x.icon&&i.jsx("span",{className:"w-4 h-4 flex-shrink-0 flex items-center justify-center",children:x.icon}),i.jsx("span",{className:"flex-1",children:x.label}),_&&i.jsx(ha,{className:"w-4 h-4 text-bambu-gray"})]}),_&&s===g&&i.jsx("div",{className:`absolute min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 overflow-hidden max-h-[300px] overflow-y-auto z-[60] ${d?"right-full mr-1":"left-full ml-1"} ${p[g]==="bottom"?"bottom-0":"top-0"}`,onMouseEnter:()=>{l.current&&(clearTimeout(l.current),l.current=null)},onMouseLeave:()=>v(),children:x.submenu.map((N,T)=>i.jsxs("button",{onClick:()=>{N.disabled||(N.onClick(),r())},disabled:N.disabled,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${N.disabled?"text-bambu-gray cursor-not-allowed":N.danger?"text-red-400 hover:bg-red-400/10":"text-white hover:bg-bambu-dark-tertiary"}`,children:[N.icon&&i.jsx("span",{className:"w-4 h-4 flex-shrink-0 flex items-center justify-center",children:N.icon}),N.label]},T))})]},g)})})}function yVe({selectedIds:t,existingTags:e,onClose:n}){const r=an(),{showToast:a}=fn(),[s,o]=w.useState(""),[l,c]=w.useState(new Set),[u,d]=w.useState("add");w.useEffect(()=>{const v=x=>{x.key==="Escape"&&n()};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[n]);const m=pt({mutationFn:async()=>{const v=Array.from(l);let x=0;for(const g of t)try{const _=await be.getArchive(g),N=_.tags?_.tags.split(",").map(C=>C.trim()).filter(Boolean):[];let T;u==="add"?T=[...new Set([...N,...v])]:T=N.filter(C=>!l.has(C)),await be.updateArchive(g,{tags:T.join(", ")}),x++}catch(_){throw console.error(`Failed to update archive ${g}:`,_),new Error(`Failed on archive ${g}: ${_ instanceof Error?_.message:"Unknown error"}`)}return{count:x,mode:u,tags:v}},onSuccess:({count:v,mode:x,tags:g})=>{r.invalidateQueries({queryKey:["archives"]}),a(`${x==="add"?"Added":"Removed"} ${g.length} tag${g.length!==1?"s":""} ${x==="add"?"to":"from"} ${v} archive${v!==1?"s":""}`),n()},onError:v=>{a(v.message||"Failed to update tags","error")}}),p=v=>{c(x=>{const g=new Set(x);return g.has(v)?g.delete(v):g.add(v),g})},f=()=>{s.trim()&&!l.has(s.trim())&&(c(v=>new Set([...v,s.trim()])),o(""))},y=v=>{v.key==="Enter"&&(v.preventDefault(),f())};return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:i.jsx(Mt,{className:"w-full max-w-md",children:i.jsxs(Dt,{className:"p-0",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Dd,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-xl font-semibold text-white",children:u==="add"?"Add Tags":"Remove Tags"})]}),i.jsx("button",{onClick:n,className:"text-bambu-gray hover:text-white transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsxs("p",{className:"text-sm text-bambu-gray",children:[u==="add"?"Add":"Remove"," tags for ",t.length," selected archive",t.length!==1?"s":""]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Oe,{size:"sm",variant:u==="add"?"primary":"secondary",onClick:()=>d("add"),children:"Add Tags"}),i.jsx(Oe,{size:"sm",variant:u==="remove"?"primary":"secondary",onClick:()=>d("remove"),children:"Remove Tags"})]}),u==="add"&&i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"text",placeholder:"Enter new tag...",className:"flex-1 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",value:s,onChange:v=>o(v.target.value),onKeyDown:y}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:f,disabled:!s.trim(),children:i.jsx(ar,{className:"w-4 h-4"})})]}),e.length>0&&i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:"Existing tags:"}),i.jsx("div",{className:"flex flex-wrap gap-2",children:e.map(v=>i.jsx("button",{onClick:()=>p(v),className:`px-2 py-1 rounded text-sm transition-colors ${l.has(v)?"bg-bambu-green text-white":"bg-bambu-dark-tertiary text-bambu-gray-light hover:bg-bambu-dark"}`,children:v},v))})]}),l.size>0&&i.jsxs("div",{children:[i.jsxs("p",{className:"text-xs text-bambu-gray mb-2",children:["Tags to ",u==="add"?"add":"remove",":"]}),i.jsx("div",{className:"flex flex-wrap gap-2",children:Array.from(l).map(v=>i.jsxs("span",{className:`px-2 py-1 rounded text-sm flex items-center gap-1 ${u==="add"?"bg-green-500/20 text-green-400":"bg-red-500/20 text-red-400"}`,children:[v,i.jsx("button",{onClick:()=>p(v),className:"hover:opacity-70",children:i.jsx(Ht,{className:"w-3 h-3"})})]},v))})]})]}),i.jsxs("div",{className:"flex gap-3 p-4 border-t border-bambu-dark-tertiary",children:[i.jsx(Oe,{variant:"secondary",onClick:n,className:"flex-1",children:"Cancel"}),i.jsx(Oe,{onClick:()=>m.mutate(),disabled:l.size===0||m.isPending,className:"flex-1",children:m.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),"Processing..."]}):i.jsxs(i.Fragment,{children:[i.jsx(Dd,{className:"w-4 h-4"}),u==="add"?"Add Tags":"Remove Tags"]})})]})]})})})}function vVe({selectedIds:t,onClose:e}){const n=an(),{showToast:r}=fn(),{data:a,isLoading:s}=et({queryKey:["projects"],queryFn:()=>be.getProjects()});w.useEffect(()=>{const d=m=>{m.key==="Escape"&&e()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[e]);const o=()=>{n.invalidateQueries({queryKey:["archives"]}),n.invalidateQueries({queryKey:["projects"]}),n.invalidateQueries({queryKey:["project"]}),n.invalidateQueries({queryKey:["project-archives"]})},l=pt({mutationFn:async d=>(await be.addArchivesToProject(d,t),d),onSuccess:d=>{const m=a?.find(p=>p.id===d);o(),r(`Added ${t.length} archive${t.length!==1?"s":""} to "${m?.name}"`),e()},onError:()=>{r("Failed to assign project","error")}}),c=pt({mutationFn:async()=>{for(const d of t)await be.updateArchive(d,{project_id:null});return t.length},onSuccess:d=>{o(),r(`Removed ${d} archive${d!==1?"s":""} from project`),e()},onError:()=>{r("Failed to remove from project","error")}}),u=l.isPending||c.isPending;return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:i.jsx(Mt,{className:"w-full max-w-md max-h-[80vh] flex flex-col",children:i.jsxs(Dt,{className:"p-0 flex flex-col min-h-0",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(fs,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-xl font-semibold text-white",children:"Assign to Project"})]}),i.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",disabled:u,children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"p-4 space-y-3 overflow-y-auto min-h-0",children:[i.jsxs("p",{className:"text-sm text-bambu-gray",children:["Assign ",t.length," selected archive",t.length!==1?"s":""," to a project"]}),s?i.jsx("div",{className:"flex items-center justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 animate-spin text-bambu-gray"})}):i.jsxs("div",{className:"space-y-2",children:[i.jsxs("button",{onClick:()=>c.mutate(),disabled:u,className:"w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary transition-colors text-left disabled:opacity-50",children:[i.jsx("div",{className:"w-8 h-8 rounded-full bg-red-500/20 flex items-center justify-center shrink-0",children:i.jsx(Vi,{className:"w-4 h-4 text-red-400"})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"text-white font-medium",children:"Remove from project"}),i.jsx("p",{className:"text-sm text-bambu-gray truncate",children:"Clear project assignment"})]}),c.isPending&&i.jsx(ht,{className:"w-4 h-4 animate-spin text-bambu-gray shrink-0"})]}),a&&a.length>0&&i.jsxs("div",{className:"flex items-center gap-2 py-2",children:[i.jsx("div",{className:"flex-1 h-px bg-bambu-dark-tertiary"}),i.jsx("span",{className:"text-xs text-bambu-gray",children:"or assign to"}),i.jsx("div",{className:"flex-1 h-px bg-bambu-dark-tertiary"})]}),a?.map(d=>i.jsxs("button",{onClick:()=>l.mutate(d.id),disabled:u,className:"w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary transition-colors text-left disabled:opacity-50",children:[i.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center shrink-0",style:{backgroundColor:d.color?`${d.color}20`:"rgb(var(--bambu-green) / 0.2)"},children:i.jsx(fs,{className:"w-4 h-4",style:{color:d.color||"rgb(var(--bambu-green))"}})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"text-white font-medium truncate",children:d.name}),i.jsxs("p",{className:"text-sm text-bambu-gray truncate",children:[d.archive_count," archive",d.archive_count!==1?"s":"",d.status&&` • ${d.status}`]})]}),l.isPending&&l.variables===d.id&&i.jsx(ht,{className:"w-4 h-4 animate-spin text-bambu-gray shrink-0"})]},d.id)),(!a||a.length===0)&&i.jsx("p",{className:"text-center text-bambu-gray py-4",children:"No projects yet. Create one from the Projects page."})]})]}),i.jsx("div",{className:"flex gap-3 p-4 border-t border-bambu-dark-tertiary shrink-0",children:i.jsx(Oe,{variant:"secondary",onClick:e,className:"flex-1",disabled:u,children:"Cancel"})})]})})})}function wVe(t,e){return new Date(t,e+1,0).getDate()}function SVe(t,e){return new Date(t,e,1).getDay()}const _Ve=["January","February","March","April","May","June","July","August","September","October","November","December"],NVe=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function kVe({archives:t,onArchiveClick:e,highlightedArchiveId:n}){const r=new Date,[a,s]=w.useState(r.getMonth()),[o,l]=w.useState(r.getFullYear()),[c,u]=w.useState(null),[d,m]=w.useState(null),p=w.useMemo(()=>{const C=new Map;return t.forEach(A=>{const k=Jn(A.completed_at||A.created_at)||new Date,R=`${k.getFullYear()}-${String(k.getMonth()+1).padStart(2,"0")}-${String(k.getDate()).padStart(2,"0")}`,P=C.get(R)||[];P.push(A),C.set(R,P)}),C},[t]),f=wVe(o,a),y=SVe(o,a),v=()=>{a===0?(s(11),l(o-1)):s(a-1)},x=()=>{a===11?(s(0),l(o+1)):s(a+1)},g=()=>{s(r.getMonth()),l(r.getFullYear())},_=[];for(let C=0;C{C!==c&&m(null),u(C)};return i.jsxs("div",{className:"flex flex-col lg:flex-row gap-6",children:[i.jsxs("div",{className:"flex-1",children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsx("button",{onClick:v,className:"p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:i.jsx(Sc,{className:"w-5 h-5 text-bambu-gray"})}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white",children:[_Ve[a]," ",o]}),i.jsx("button",{onClick:g,className:"px-2 py-1 text-xs bg-bambu-dark-tertiary hover:bg-bambu-green/20 text-bambu-gray hover:text-white rounded transition-colors",children:"Today"})]}),i.jsx("button",{onClick:x,className:"p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:i.jsx(ha,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsx("div",{className:"grid grid-cols-7 gap-1 mb-1",children:NVe.map(C=>i.jsx("div",{className:"text-center text-xs text-bambu-gray py-2",children:C},C))}),i.jsx("div",{className:"grid grid-cols-7 gap-1",children:_.map((C,A)=>{if(C===null)return i.jsx("div",{className:"aspect-square"},`empty-${A}`);const k=`${o}-${String(a+1).padStart(2,"0")}-${String(C).padStart(2,"0")}`,R=p.get(k)||[],P=R.length>0,D=C===r.getDate()&&a===r.getMonth()&&o===r.getFullYear(),H=k===c,z=R.filter(I=>I.status==="completed").length,G=R.filter(I=>I.status==="failed").length;return i.jsxs("button",{onClick:()=>T(H?null:k),className:`aspect-square rounded-lg p-1 flex flex-col items-center justify-center transition-colors relative ${H?"bg-bambu-green text-white":D?"bg-bambu-green/20 text-white ring-2 ring-bambu-green":P?"bg-bambu-dark-tertiary hover:bg-bambu-dark-tertiary/70 text-white":"hover:bg-bambu-dark-tertiary/50 text-bambu-gray"}`,children:[i.jsx("span",{className:`text-sm font-medium ${D&&!H?"text-bambu-green":""}`,children:C}),P&&i.jsxs("div",{className:"absolute bottom-1 left-1/2 -translate-x-1/2 flex items-center gap-1",children:[i.jsx("div",{className:`w-2 h-2 rounded-full ${G>0&&z===0?"bg-red-400":G>0?"bg-yellow-400":"bg-green-400"}`}),i.jsx("span",{className:"text-xs font-medium",children:R.length})]})]},C)})}),i.jsx("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:i.jsxs("div",{className:"grid grid-cols-3 gap-4 text-center",children:[i.jsxs("div",{children:[i.jsx("div",{className:"text-2xl font-bold text-white",children:t.filter(C=>{const A=Jn(C.completed_at||C.created_at)||new Date;return A.getMonth()===a&&A.getFullYear()===o}).length}),i.jsx("div",{className:"text-xs text-bambu-gray",children:"Prints this month"})]}),i.jsxs("div",{children:[i.jsx("div",{className:"text-2xl font-bold text-green-400",children:t.filter(C=>{const A=Jn(C.completed_at||C.created_at)||new Date;return A.getMonth()===a&&A.getFullYear()===o&&C.status==="completed"}).length}),i.jsx("div",{className:"text-xs text-bambu-gray",children:"Successful"})]}),i.jsxs("div",{children:[i.jsx("div",{className:"text-2xl font-bold text-red-400",children:t.filter(C=>{const A=Jn(C.completed_at||C.created_at)||new Date;return A.getMonth()===a&&A.getFullYear()===o&&C.status==="failed"}).length}),i.jsx("div",{className:"text-xs text-bambu-gray",children:"Failed"})]})]})})]}),i.jsx("div",{className:"lg:w-80 bg-bambu-dark rounded-xl p-4",children:c?i.jsxs(i.Fragment,{children:[i.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-3",children:new Date(c+"T12:00:00").toLocaleDateString("en-US",{weekday:"long",month:"long",day:"numeric",year:"numeric"})}),N.length>0?i.jsx("div",{className:"calendar-scroll space-y-2 max-h-96 overflow-y-auto",children:N.map(C=>{const A=C.id===d||C.id===n;return i.jsxs("button",{onClick:()=>{m(C.id),e?.(C)},className:`w-full flex items-center gap-3 p-2 rounded-lg transition-colors text-left ${A?"":"hover:bg-bambu-dark-tertiary"}`,style:A?{outline:"4px solid #facc15",outlineOffset:"2px"}:void 0,children:[C.thumbnail_path?i.jsx("img",{src:be.getArchiveThumbnail(C.id),alt:"",className:"w-12 h-12 rounded object-cover"}):i.jsx("div",{className:"w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center",children:i.jsx("span",{className:"text-xs text-bambu-gray",children:"3MF"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-sm text-white truncate",children:C.print_name||C.filename}),i.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[i.jsx("span",{className:C.status==="failed"?"text-red-400":"text-green-400",children:C.status==="failed"?"Failed":"Completed"}),C.filament_color&&i.jsx("div",{className:"flex gap-0.5",children:C.filament_color.split(",").map((k,R)=>i.jsx("div",{className:"w-3 h-3 rounded-full border border-white/20",style:{backgroundColor:k}},R))})]})]})]},C.id)})}):i.jsx("p",{className:"text-sm text-bambu-gray",children:"No prints on this day"})]}):i.jsx("div",{className:"text-center py-8",children:i.jsx("p",{className:"text-sm text-bambu-gray",children:"Select a day to see prints"})})})]})}function lie({archiveId:t,archiveName:e,onClose:n}){const r=be.getArchiveQRCodeUrl(t,300);w.useEffect(()=>{const s=o=>{o.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]);const a=()=>{const s=document.createElement("a");s.href=r,s.download=`${e}_qrcode.png`,s.click()};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:n,children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-sm",onClick:s=>s.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:"QR Code"}),i.jsx("button",{onClick:n,className:"text-bambu-gray hover:text-white transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"p-6 flex flex-col items-center",children:[i.jsx("p",{className:"text-sm text-bambu-gray mb-4 text-center truncate max-w-full",children:e}),i.jsx("div",{className:"bg-white p-4 rounded-lg mb-4",children:i.jsx("img",{src:r,alt:"QR Code",className:"w-64 h-64"})}),i.jsx("p",{className:"text-xs text-bambu-gray mb-4 text-center",children:"Scan to open this archive"}),i.jsxs(Oe,{onClick:a,className:"w-full",children:[i.jsx(pi,{className:"w-4 h-4"}),"Download QR Code"]})]})]})})}function cie({archiveId:t,archiveName:e,photos:n,onClose:r,onDelete:a}){const[s,o]=w.useState(0),[l,c]=w.useState(!1);if(w.useEffect(()=>{const f=y=>{y.key==="Escape"&&r(),y.key==="ArrowLeft"&&o(v=>Math.max(0,v-1)),y.key==="ArrowRight"&&o(v=>Math.min(n.length-1,v+1))};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[r,n.length]),w.useEffect(()=>{s>=n.length&&o(Math.max(0,n.length-1))},[n.length,s]),n.length===0)return r(),null;const u=n[s],d=be.getArchivePhotoUrl(t,u),m=()=>{const f=document.createElement("a");f.href=d,f.download=`${e}_photo_${s+1}.jpg`,f.click()},p=()=>{a&&c(!0)};return i.jsxs("div",{className:"fixed inset-0 bg-black/90 flex items-center justify-center z-50",onClick:r,children:[i.jsxs("div",{className:"relative w-full h-full flex flex-col",onClick:f=>f.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 bg-black/50",children:[i.jsxs("div",{children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:e}),i.jsxs("p",{className:"text-sm text-bambu-gray",children:["Photo ",s+1," of ",n.length]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:m,children:[i.jsx(pi,{className:"w-4 h-4"}),"Download"]}),a&&i.jsx(Oe,{variant:"secondary",size:"sm",onClick:p,className:"text-red-400 hover:text-red-300",children:i.jsx(Jt,{className:"w-4 h-4"})}),i.jsx("button",{onClick:r,className:"p-2 text-bambu-gray hover:text-white transition-colors",children:i.jsx(Ht,{className:"w-6 h-6"})})]})]}),i.jsxs("div",{className:"flex-1 min-h-0 flex items-center justify-center p-4 relative overflow-hidden",children:[s>0&&i.jsx("button",{onClick:()=>o(f=>f-1),className:"absolute left-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors",children:i.jsx(Sc,{className:"w-8 h-8 text-white"})}),i.jsx("img",{src:d,alt:`Photo ${s+1}`,className:"max-w-full max-h-full object-contain rounded-lg",style:{maxHeight:"calc(100vh - 200px)"}}),so(f=>f+1),className:"absolute right-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors",children:i.jsx(ha,{className:"w-8 h-8 text-white"})})]}),n.length>1&&i.jsx("div",{className:"flex justify-center gap-2 p-4 bg-black/50",children:n.map((f,y)=>i.jsx("button",{onClick:()=>o(y),className:`w-16 h-16 rounded-lg overflow-hidden border-2 transition-colors ${y===s?"border-bambu-green":"border-transparent hover:border-bambu-gray"}`,children:i.jsx("img",{src:be.getArchivePhotoUrl(t,f),alt:`Thumbnail ${y+1}`,className:"w-full h-full object-cover"})},f))})]}),l&&i.jsx(Sn,{title:"Delete Photo",message:"Delete this photo? This cannot be undone.",confirmText:"Delete",variant:"danger",onConfirm:()=>{a?.(u),c(!1)},onCancel:()=>c(!1)})]})}const{entries:uie,setPrototypeOf:CW,isFrozen:CVe,getPrototypeOf:TVe,getOwnPropertyDescriptor:AVe}=Object;let{freeze:qs,seal:Vl,create:mN}=Object,{apply:jF,construct:DF}=typeof Reflect<"u"&&Reflect;qs||(qs=function(e){return e});Vl||(Vl=function(e){return e});jF||(jF=function(e,n){for(var r=arguments.length,a=new Array(r>2?r-2:0),s=2;s1?n-1:0),a=1;a1?n-1:0),a=1;a2&&arguments[2]!==void 0?arguments[2]:hN;CW&&CW(t,null);let r=e.length;for(;r--;){let a=e[r];if(typeof a=="string"){const s=n(a);s!==a&&(CVe(e)||(e[r]=s),a=s)}t[a]=!0}return t}function RVe(t){for(let e=0;e/gm),zVe=Vl(/\$\{[\w\W]*/gm),UVe=Vl(/^data-[\-\w.\u00B7-\uFFFF]+$/),BVe=Vl(/^aria-[\-\w]+$/),die=Vl(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),HVe=Vl(/^(?:\w+script|data):/i),$Ve=Vl(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),mie=Vl(/^html$/i),qVe=Vl(/^[a-z][.\w]*(-[.\w]+)+$/i);var jW=Object.freeze({__proto__:null,ARIA_ATTR:BVe,ATTR_WHITESPACE:$Ve,CUSTOM_ELEMENT:qVe,DATA_ATTR:UVe,DOCTYPE_NAME:mie,ERB_EXPR:IVe,IS_ALLOWED_URI:die,IS_SCRIPT_OR_DATA:HVe,MUSTACHE_EXPR:OVe,TMPLIT_EXPR:zVe});const vv={element:1,text:3,progressingInstruction:7,comment:8,document:9},VVe=function(){return typeof window>"u"?null:window},GVe=function(e,n){if(typeof e!="object"||typeof e.createPolicy!="function")return null;let r=null;const a="data-tt-policy-suffix";n&&n.hasAttribute(a)&&(r=n.getAttribute(a));const s="dompurify"+(r?"#"+r:"");try{return e.createPolicy(s,{createHTML(o){return o},createScriptURL(o){return o}})}catch{return console.warn("TrustedTypes policy "+s+" could not be created."),null}},DW=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}};function hie(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:VVe();const e=Ze=>hie(Ze);if(e.version="3.3.3",e.removed=[],!t||!t.document||t.document.nodeType!==vv.document||!t.Element)return e.isSupported=!1,e;let{document:n}=t;const r=n,a=r.currentScript,{DocumentFragment:s,HTMLTemplateElement:o,Node:l,Element:c,NodeFilter:u,NamedNodeMap:d=t.NamedNodeMap||t.MozNamedAttrMap,HTMLFormElement:m,DOMParser:p,trustedTypes:f}=t,y=c.prototype,v=yv(y,"cloneNode"),x=yv(y,"remove"),g=yv(y,"nextSibling"),_=yv(y,"childNodes"),N=yv(y,"parentNode");if(typeof o=="function"){const Ze=n.createElement("template");Ze.content&&Ze.content.ownerDocument&&(n=Ze.content.ownerDocument)}let T,C="";const{implementation:A,createNodeIterator:k,createDocumentFragment:R,getElementsByTagName:P}=n,{importNode:D}=r;let H=DW();e.isSupported=typeof uie=="function"&&typeof N=="function"&&A&&A.createHTMLDocument!==void 0;const{MUSTACHE_EXPR:z,ERB_EXPR:G,TMPLIT_EXPR:I,DATA_ATTR:ee,ARIA_ATTR:ie,IS_SCRIPT_OR_DATA:X,ATTR_WHITESPACE:me,CUSTOM_ELEMENT:he}=jW;let{IS_ALLOWED_URI:ge}=jW,Y=null;const oe=tr({},[...AW,...tD,...nD,...rD,...PW]);let le=null;const xe=tr({},[...MW,...iD,...EW,...T1]);let Pe=Object.seal(mN(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),q=null,Z=null;const j=Object.seal(mN(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let E=!0,U=!0,K=!1,$=!0,ne=!1,O=!0,V=!1,J=!1,W=!1,re=!1,ue=!1,fe=!1,ye=!0,ae=!1;const L="user-content-";let F=!0,te=!1,ve={},pe=null;const de=tr({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]);let Ne=null;const Se=tr({},["audio","video","img","source","image","track"]);let Le=null;const qe=tr({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Ee="http://www.w3.org/1998/Math/MathML",Te="http://www.w3.org/2000/svg",Ae="http://www.w3.org/1999/xhtml";let Be=Ae,je=!1,Xe=null;const ce=tr({},[Ee,Te,Ae],Jj);let Ie=tr({},["mi","mo","mn","ms","mtext"]),Ce=tr({},["annotation-xml"]);const Ge=tr({},["title","style","font","a","script"]);let $e=null;const Ue=["application/xhtml+xml","text/html"],De="text/html";let Ve=null,it=null;const xt=n.createElement("form"),Nt=function(ke){return ke instanceof RegExp||ke instanceof Function},kt=function(){let ke=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!(it&&it===ke)){if((!ke||typeof ke!="object")&&(ke={}),ke=qc(ke),$e=Ue.indexOf(ke.PARSER_MEDIA_TYPE)===-1?De:ke.PARSER_MEDIA_TYPE,Ve=$e==="application/xhtml+xml"?Jj:hN,Y=Oo(ke,"ALLOWED_TAGS")?tr({},ke.ALLOWED_TAGS,Ve):oe,le=Oo(ke,"ALLOWED_ATTR")?tr({},ke.ALLOWED_ATTR,Ve):xe,Xe=Oo(ke,"ALLOWED_NAMESPACES")?tr({},ke.ALLOWED_NAMESPACES,Jj):ce,Le=Oo(ke,"ADD_URI_SAFE_ATTR")?tr(qc(qe),ke.ADD_URI_SAFE_ATTR,Ve):qe,Ne=Oo(ke,"ADD_DATA_URI_TAGS")?tr(qc(Se),ke.ADD_DATA_URI_TAGS,Ve):Se,pe=Oo(ke,"FORBID_CONTENTS")?tr({},ke.FORBID_CONTENTS,Ve):de,q=Oo(ke,"FORBID_TAGS")?tr({},ke.FORBID_TAGS,Ve):qc({}),Z=Oo(ke,"FORBID_ATTR")?tr({},ke.FORBID_ATTR,Ve):qc({}),ve=Oo(ke,"USE_PROFILES")?ke.USE_PROFILES:!1,E=ke.ALLOW_ARIA_ATTR!==!1,U=ke.ALLOW_DATA_ATTR!==!1,K=ke.ALLOW_UNKNOWN_PROTOCOLS||!1,$=ke.ALLOW_SELF_CLOSE_IN_ATTR!==!1,ne=ke.SAFE_FOR_TEMPLATES||!1,O=ke.SAFE_FOR_XML!==!1,V=ke.WHOLE_DOCUMENT||!1,re=ke.RETURN_DOM||!1,ue=ke.RETURN_DOM_FRAGMENT||!1,fe=ke.RETURN_TRUSTED_TYPE||!1,W=ke.FORCE_BODY||!1,ye=ke.SANITIZE_DOM!==!1,ae=ke.SANITIZE_NAMED_PROPS||!1,F=ke.KEEP_CONTENT!==!1,te=ke.IN_PLACE||!1,ge=ke.ALLOWED_URI_REGEXP||die,Be=ke.NAMESPACE||Ae,Ie=ke.MATHML_TEXT_INTEGRATION_POINTS||Ie,Ce=ke.HTML_INTEGRATION_POINTS||Ce,Pe=ke.CUSTOM_ELEMENT_HANDLING||{},ke.CUSTOM_ELEMENT_HANDLING&&Nt(ke.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(Pe.tagNameCheck=ke.CUSTOM_ELEMENT_HANDLING.tagNameCheck),ke.CUSTOM_ELEMENT_HANDLING&&Nt(ke.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(Pe.attributeNameCheck=ke.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),ke.CUSTOM_ELEMENT_HANDLING&&typeof ke.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements=="boolean"&&(Pe.allowCustomizedBuiltInElements=ke.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),ne&&(U=!1),ue&&(re=!0),ve&&(Y=tr({},PW),le=mN(null),ve.html===!0&&(tr(Y,AW),tr(le,MW)),ve.svg===!0&&(tr(Y,tD),tr(le,iD),tr(le,T1)),ve.svgFilters===!0&&(tr(Y,nD),tr(le,iD),tr(le,T1)),ve.mathMl===!0&&(tr(Y,rD),tr(le,EW),tr(le,T1))),Oo(ke,"ADD_TAGS")||(j.tagCheck=null),Oo(ke,"ADD_ATTR")||(j.attributeCheck=null),ke.ADD_TAGS&&(typeof ke.ADD_TAGS=="function"?j.tagCheck=ke.ADD_TAGS:(Y===oe&&(Y=qc(Y)),tr(Y,ke.ADD_TAGS,Ve))),ke.ADD_ATTR&&(typeof ke.ADD_ATTR=="function"?j.attributeCheck=ke.ADD_ATTR:(le===xe&&(le=qc(le)),tr(le,ke.ADD_ATTR,Ve))),ke.ADD_URI_SAFE_ATTR&&tr(Le,ke.ADD_URI_SAFE_ATTR,Ve),ke.FORBID_CONTENTS&&(pe===de&&(pe=qc(pe)),tr(pe,ke.FORBID_CONTENTS,Ve)),ke.ADD_FORBID_CONTENTS&&(pe===de&&(pe=qc(pe)),tr(pe,ke.ADD_FORBID_CONTENTS,Ve)),F&&(Y["#text"]=!0),V&&tr(Y,["html","head","body"]),Y.table&&(tr(Y,["tbody"]),delete q.tbody),ke.TRUSTED_TYPES_POLICY){if(typeof ke.TRUSTED_TYPES_POLICY.createHTML!="function")throw xv('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof ke.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw xv('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');T=ke.TRUSTED_TYPES_POLICY,C=T.createHTML("")}else T===void 0&&(T=GVe(f,a)),T!==null&&typeof C=="string"&&(C=T.createHTML(""));qs&&qs(ke),it=ke}},We=tr({},[...tD,...nD,...FVe]),yt=tr({},[...rD,...LVe]),wt=function(ke){let ot=N(ke);(!ot||!ot.tagName)&&(ot={namespaceURI:Be,tagName:"template"});const se=hN(ke.tagName),He=hN(ot.tagName);return Xe[ke.namespaceURI]?ke.namespaceURI===Te?ot.namespaceURI===Ae?se==="svg":ot.namespaceURI===Ee?se==="svg"&&(He==="annotation-xml"||Ie[He]):!!We[se]:ke.namespaceURI===Ee?ot.namespaceURI===Ae?se==="math":ot.namespaceURI===Te?se==="math"&&Ce[He]:!!yt[se]:ke.namespaceURI===Ae?ot.namespaceURI===Te&&!Ce[He]||ot.namespaceURI===Ee&&!Ie[He]?!1:!yt[se]&&(Ge[se]||!We[se]):!!($e==="application/xhtml+xml"&&Xe[ke.namespaceURI]):!1},_t=function(ke){gv(e.removed,{element:ke});try{N(ke).removeChild(ke)}catch{x(ke)}},Ot=function(ke,ot){try{gv(e.removed,{attribute:ot.getAttributeNode(ke),from:ot})}catch{gv(e.removed,{attribute:null,from:ot})}if(ot.removeAttribute(ke),ke==="is")if(re||ue)try{_t(ot)}catch{}else try{ot.setAttribute(ke,"")}catch{}},Vt=function(ke){let ot=null,se=null;if(W)ke=""+ke;else{const Ye=eD(ke,/^[\r\n\t ]+/);se=Ye&&Ye[0]}$e==="application/xhtml+xml"&&Be===Ae&&(ke=''+ke+"");const He=T?T.createHTML(ke):ke;if(Be===Ae)try{ot=new p().parseFromString(He,$e)}catch{}if(!ot||!ot.documentElement){ot=A.createDocument(Be,"template",null);try{ot.documentElement.innerHTML=je?C:He}catch{}}const Ke=ot.body||ot.documentElement;return ke&&se&&Ke.insertBefore(n.createTextNode(se),Ke.childNodes[0]||null),Be===Ae?P.call(ot,V?"html":"body")[0]:V?ot.documentElement:Ke},Xt=function(ke){return k.call(ke.ownerDocument||ke,ke,u.SHOW_ELEMENT|u.SHOW_COMMENT|u.SHOW_TEXT|u.SHOW_PROCESSING_INSTRUCTION|u.SHOW_CDATA_SECTION,null)},Qe=function(ke){return ke instanceof m&&(typeof ke.nodeName!="string"||typeof ke.textContent!="string"||typeof ke.removeChild!="function"||!(ke.attributes instanceof d)||typeof ke.removeAttribute!="function"||typeof ke.setAttribute!="function"||typeof ke.namespaceURI!="string"||typeof ke.insertBefore!="function"||typeof ke.hasChildNodes!="function")},Qt=function(ke){return typeof l=="function"&&ke instanceof l};function hn(Ze,ke,ot){C1(Ze,se=>{se.call(e,ke,ot,it)})}const jn=function(ke){let ot=null;if(hn(H.beforeSanitizeElements,ke,null),Qe(ke))return _t(ke),!0;const se=Ve(ke.nodeName);if(hn(H.uponSanitizeElement,ke,{tagName:se,allowedTags:Y}),O&&ke.hasChildNodes()&&!Qt(ke.firstElementChild)&&Ms(/<[/\w!]/g,ke.innerHTML)&&Ms(/<[/\w!]/g,ke.textContent)||ke.nodeType===vv.progressingInstruction||O&&ke.nodeType===vv.comment&&Ms(/<[/\w]/g,ke.data))return _t(ke),!0;if(!(j.tagCheck instanceof Function&&j.tagCheck(se))&&(!Y[se]||q[se])){if(!q[se]&&Fe(se)&&(Pe.tagNameCheck instanceof RegExp&&Ms(Pe.tagNameCheck,se)||Pe.tagNameCheck instanceof Function&&Pe.tagNameCheck(se)))return!1;if(F&&!pe[se]){const He=N(ke)||ke.parentNode,Ke=_(ke)||ke.childNodes;if(Ke&&He){const Ye=Ke.length;for(let Me=Ye-1;Me>=0;--Me){const dt=v(Ke[Me],!0);dt.__removalCount=(ke.__removalCount||0)+1,He.insertBefore(dt,g(ke))}}}return _t(ke),!0}return ke instanceof c&&!wt(ke)||(se==="noscript"||se==="noembed"||se==="noframes")&&Ms(/<\/no(script|embed|frames)/i,ke.innerHTML)?(_t(ke),!0):(ne&&ke.nodeType===vv.text&&(ot=ke.textContent,C1([z,G,I],He=>{ot=bv(ot,He," ")}),ke.textContent!==ot&&(gv(e.removed,{element:ke.cloneNode()}),ke.textContent=ot)),hn(H.afterSanitizeElements,ke,null),!1)},kn=function(ke,ot,se){if(Z[ot]||ye&&(ot==="id"||ot==="name")&&(se in n||se in xt))return!1;if(!(U&&!Z[ot]&&Ms(ee,ot))){if(!(E&&Ms(ie,ot))){if(!(j.attributeCheck instanceof Function&&j.attributeCheck(ot,ke))){if(!le[ot]||Z[ot]){if(!(Fe(ke)&&(Pe.tagNameCheck instanceof RegExp&&Ms(Pe.tagNameCheck,ke)||Pe.tagNameCheck instanceof Function&&Pe.tagNameCheck(ke))&&(Pe.attributeNameCheck instanceof RegExp&&Ms(Pe.attributeNameCheck,ot)||Pe.attributeNameCheck instanceof Function&&Pe.attributeNameCheck(ot,ke))||ot==="is"&&Pe.allowCustomizedBuiltInElements&&(Pe.tagNameCheck instanceof RegExp&&Ms(Pe.tagNameCheck,se)||Pe.tagNameCheck instanceof Function&&Pe.tagNameCheck(se))))return!1}else if(!Le[ot]){if(!Ms(ge,bv(se,me,""))){if(!((ot==="src"||ot==="xlink:href"||ot==="href")&&ke!=="script"&&EVe(se,"data:")===0&&Ne[ke])){if(!(K&&!Ms(X,bv(se,me,"")))){if(se)return!1}}}}}}}return!0},Fe=function(ke){return ke!=="annotation-xml"&&eD(ke,he)},tt=function(ke){hn(H.beforeSanitizeAttributes,ke,null);const{attributes:ot}=ke;if(!ot||Qe(ke))return;const se={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:le,forceKeepAttr:void 0};let He=ot.length;for(;He--;){const Ke=ot[He],{name:Ye,namespaceURI:Me,value:dt}=Ke,ct=Ve(Ye),nt=dt;let bt=Ye==="value"?nt:jVe(nt);if(se.attrName=ct,se.attrValue=bt,se.keepAttr=!0,se.forceKeepAttr=void 0,hn(H.uponSanitizeAttribute,ke,se),bt=se.attrValue,ae&&(ct==="id"||ct==="name")&&(Ot(Ye,ke),bt=L+bt),O&&Ms(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,bt)){Ot(Ye,ke);continue}if(ct==="attributename"&&eD(bt,"href")){Ot(Ye,ke);continue}if(se.forceKeepAttr)continue;if(!se.keepAttr){Ot(Ye,ke);continue}if(!$&&Ms(/\/>/i,bt)){Ot(Ye,ke);continue}ne&&C1([z,G,I],Et=>{bt=bv(bt,Et," ")});const Ut=Ve(ke.nodeName);if(!kn(Ut,ct,bt)){Ot(Ye,ke);continue}if(T&&typeof f=="object"&&typeof f.getAttributeType=="function"&&!Me)switch(f.getAttributeType(Ut,ct)){case"TrustedHTML":{bt=T.createHTML(bt);break}case"TrustedScriptURL":{bt=T.createScriptURL(bt);break}}if(bt!==nt)try{Me?ke.setAttributeNS(Me,Ye,bt):ke.setAttribute(Ye,bt),Qe(ke)?_t(ke):TW(e.removed)}catch{Ot(Ye,ke)}}hn(H.afterSanitizeAttributes,ke,null)},ut=function Ze(ke){let ot=null;const se=Xt(ke);for(hn(H.beforeSanitizeShadowDOM,ke,null);ot=se.nextNode();)hn(H.uponSanitizeShadowNode,ot,null),jn(ot),tt(ot),ot.content instanceof s&&Ze(ot.content);hn(H.afterSanitizeShadowDOM,ke,null)};return e.sanitize=function(Ze){let ke=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},ot=null,se=null,He=null,Ke=null;if(je=!Ze,je&&(Ze=""),typeof Ze!="string"&&!Qt(Ze))if(typeof Ze.toString=="function"){if(Ze=Ze.toString(),typeof Ze!="string")throw xv("dirty is not a string, aborting")}else throw xv("toString is not a function");if(!e.isSupported)return Ze;if(J||kt(ke),e.removed=[],typeof Ze=="string"&&(te=!1),te){if(Ze.nodeName){const dt=Ve(Ze.nodeName);if(!Y[dt]||q[dt])throw xv("root node is forbidden and cannot be sanitized in-place")}}else if(Ze instanceof l)ot=Vt(""),se=ot.ownerDocument.importNode(Ze,!0),se.nodeType===vv.element&&se.nodeName==="BODY"||se.nodeName==="HTML"?ot=se:ot.appendChild(se);else{if(!re&&!ne&&!V&&Ze.indexOf("<")===-1)return T&&fe?T.createHTML(Ze):Ze;if(ot=Vt(Ze),!ot)return re?null:fe?C:""}ot&&W&&_t(ot.firstChild);const Ye=Xt(te?Ze:ot);for(;He=Ye.nextNode();)jn(He),tt(He),He.content instanceof s&&ut(He.content);if(te)return Ze;if(re){if(ue)for(Ke=R.call(ot.ownerDocument);ot.firstChild;)Ke.appendChild(ot.firstChild);else Ke=ot;return(le.shadowroot||le.shadowrootmode)&&(Ke=D.call(r,Ke,!0)),Ke}let Me=V?ot.outerHTML:ot.innerHTML;return V&&Y["!doctype"]&&ot.ownerDocument&&ot.ownerDocument.doctype&&ot.ownerDocument.doctype.name&&Ms(mie,ot.ownerDocument.doctype.name)&&(Me=" + `,title:C("printers:control")?g(Pt?"printers.resume":"printers.pause"):g("printers.permission.noControl"),children:[Pt?i.jsx(go,{className:"w-3 h-3"}):i.jsx(tT,{className:"w-3 h-3"}),g(Pt?"printers.resume":"printers.pause")]})]})]})]})})(),(ct?.length>0||Qe.vt_tray.length>0)&&r==="expanded"&&(()=>{const mt=ct.filter(rt=>rt.tray.length>1),Pt=ct.filter(rt=>rt.tray.length===1),rn=t.nozzle_count===2||Qe?.temperatures?.nozzle_2!==void 0;return i.jsxs("div",{className:"mt-3",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx("span",{className:"text-[10px] uppercase tracking-wider text-bambu-gray font-medium",children:g("printers.filaments")}),i.jsx("div",{className:"flex-1 h-px bg-bambu-dark-tertiary/30"})]}),i.jsxs("div",{className:"space-y-3",children:[mt.length>0&&i.jsx("div",{className:"grid grid-cols-2 gap-3",children:mt.map(rt=>{const un=Me[String(rt.id)],In=rt.id>=128?rt.id-128:rt.id,Vn=un!==void 0?un:In,Na=Vn===1,_o=Vn===0;return i.jsxs("div",{className:"p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary/30",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx(_W,{ams:rt,printerId:t.id,label:gl(rt.id,rt.tray.length),amsLabels:ut,canEdit:C("printers:update"),onSaved:Ze,children:i.jsx("span",{className:"text-[10px] text-white font-medium cursor-default select-none",children:ut?.[rt.id]||gl(rt.id,rt.tray.length)})}),rn&&(Na||_o)&&i.jsx(xW,{side:Na?"L":"R"})]}),(rt.humidity!=null||rt.temp!=null)&&i.jsxs("div",{className:"flex items-center gap-1.5 max-[550px]:flex-col max-[550px]:items-start",children:[rt.humidity!=null&&i.jsx(vW,{humidity:rt.humidity,goodThreshold:s?.humidityGood,fairThreshold:s?.humidityFair,onClick:()=>je({amsId:rt.id,amsLabel:gl(rt.id,rt.tray.length),mode:"humidity"}),compact:!0}),rt.temp!=null&&i.jsx(wW,{temp:rt.temp,goodThreshold:s?.tempGood,fairThreshold:s?.tempFair,onClick:()=>je({amsId:rt.id,amsLabel:gl(rt.id,rt.tray.length),mode:"temperature"}),compact:!0}),Qe.supports_drying&&(rt.module_type==="n3f"||rt.module_type==="n3s")&&C("printers:control")&&i.jsx("button",{disabled:!!(rt.dry_sf_reason?.length&&rt.dry_time===0),onClick:ln=>{if(rt.dry_time>0)$r.mutate(rt.id);else if(ue===rt.id)fe(null);else{const Cs=(rt.tray.find(Xs=>Xs.tray_type)?.tray_type||"PLA").split(" ")[0].toUpperCase(),Ts=x[Cs]||x.PLA,rl=rt.module_type;F(Cs),ve(Ts[rl]||Ts.n3f),de(rl==="n3s"?Ts.n3s_hours:Ts.n3f_hours),ae(rt.module_type),fe(rt.id);const ec=ln.currentTarget.getBoundingClientRect();Se({top:ec.bottom+4,left:Math.max(8,ec.right-240)})}},className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[9px] transition-colors ${rt.dry_time>0?"bg-amber-500/20 text-amber-400":rt.dry_sf_reason?.length?"bg-bambu-dark-tertiary/30 text-bambu-gray/50 cursor-not-allowed":"bg-bambu-dark-tertiary/50 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,title:rt.dry_time>0?g("printers.drying.stop"):rt.dry_sf_reason?.length?g("printers.drying.powerRequired"):g("printers.drying.start"),children:i.jsx(Fp,{className:"w-3 h-3"})})]})]}),rt.dry_time>0&&i.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 mb-1 bg-amber-500/10 border border-amber-500/20 rounded text-[9px]",children:[i.jsx(Fp,{className:"w-3 h-3 text-amber-400 shrink-0"}),i.jsx("span",{className:"text-amber-400 font-medium",children:g("printers.drying.active")}),i.jsx("span",{className:"text-amber-300/70",children:g("printers.drying.timeRemaining",{time:rt.dry_time>=60?`${Math.floor(rt.dry_time/60)}h ${rt.dry_time%60}m`:`${rt.dry_time}m`})}),i.jsx("button",{onClick:()=>$r.mutate(rt.id),disabled:$r.isPending,className:"ml-auto text-amber-400 hover:text-amber-300 transition-colors disabled:opacity-50",title:g("printers.drying.stop"),children:i.jsx(Ht,{className:"w-3 h-3"})})]}),i.jsx("div",{className:"grid grid-cols-4 gap-1.5",children:[0,1,2,3].map(ln=>{const zn=rt.tray[ln]||rt.tray.find(Nn=>Nn.id===ln),Cs=zn?.tray_type&&zn.remain>=0,Ts=!zn?.tray_type,rl=rt.id*4+ln,ec=Ut===rl,Xs=zn?.tray_info_idx?Fe?.[zn.tray_info_idx]:null,gi=tt?.[rl],Ia=(zn?.tray_uuid||zn?.tag_uid||xb(t.serial_number,rt.id,ln))?.toUpperCase(),tc=Ia?l?.[Ia]:void 0,za=Xj(tc),No=d?.(t.id,rt.id,ln),jc=(()=>{const Nn=No?.spool;return Nn&&Nn.label_weight>0&&Nn.weight_used!=null?Math.round(Math.max(0,Nn.label_weight-Nn.weight_used)/Nn.label_weight*100):null})(),ti=jc===0&&Cs&&zn.remain>0?null:jc,ko=za??ti??(Cs?zn.remain:null),iy=za!==null?"spoolman":ti!==null?"inventory":Cs?"ams":void 0,ni=zn?.tray_type?{vendor:Qj(zn)?"Bambu Lab":"Generic",profile:gi?.preset_name||Xs?.name||No?.spool?.slicer_filament_name||zn.tray_sub_brands||zn.tray_type,colorName:Gj(zn.tray_id_name)||dN(zn.tray_color),colorHex:zn.tray_color||null,kFactor:Wj(zn.k),fillLevel:ko,trayUuid:zn.tray_uuid||null,tagUid:zn.tag_uid||null,fillSource:iy}:null,Au=_s?.amsId===rt.id&&_s?.slotId===ln,Jh=i.jsxs("div",{className:`bg-bambu-dark-tertiary rounded p-1 text-center ${Ts?"opacity-50":""} ${ec?"ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark":""}`,children:[i.jsx(Vj,{trayColor:zn?.tray_color,trayType:zn?.tray_type,isEmpty:Ts,slotNumber:ln+1}),i.jsx("div",{className:"text-[9px] text-white font-bold truncate",children:zn?.tray_type||"—"}),i.jsx("div",{className:"mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden",children:ko!==null&&ko>=0&&zn&&i.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${ko}%`,backgroundColor:Yj(ko)}})})]});return i.jsxs("div",{className:"relative group",children:[Au&&i.jsx("div",{className:"absolute inset-0 bg-bambu-dark-tertiary/80 rounded flex items-center justify-center z-20",children:i.jsx(wr,{className:"w-4 h-4 text-bambu-green animate-spin"})}),Qe?.state!=="RUNNING"&&i.jsx("button",{onClick:Nn=>{Nn.stopPropagation(),Ni(on?.amsId===rt.id&&on?.slotId===ln?null:{amsId:rt.id,slotId:ln})},className:"absolute -top-1 -right-1 w-4 h-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity z-10 hover:bg-bambu-dark-tertiary",title:g("printers.slotOptions"),children:i.jsx(ph,{className:"w-2.5 h-2.5 text-bambu-gray"})}),Qe?.state!=="RUNNING"&&on?.amsId===rt.id&&on?.slotId===ln&&i.jsx("div",{className:"absolute top-full left-0 mt-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]",children:i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-xs flex items-center gap-2 ${C("printers:ams_rfid")?"text-white hover:bg-bambu-dark-tertiary":"text-bambu-gray/50 cursor-not-allowed"}`,onClick:Nn=>{Nn.stopPropagation(),C("printers:ams_rfid")&&(Jo.mutate({amsId:rt.id,slotId:ln}),Ni(null))},disabled:Au||!C("printers:ams_rfid"),title:C("printers:ams_rfid")?void 0:g("printers.permission.noAmsRfid"),children:[i.jsx(wr,{className:`w-3 h-3 ${Au?"animate-spin":""}`}),g("printers.rfid.reread")]})}),ni?i.jsx(Hj,{data:ni,spoolman:{enabled:o,linkedSpoolId:Ia?l?.[Ia]?.id:void 0,spoolmanUrl:c,syncMode:u,onLinkSpool:o?()=>{const Nn=(ni.trayUuid||ni.tagUid||xb(t.serial_number,rt.id,ln)).toUpperCase();ce({tagUid:ni.tagUid||Nn,trayUuid:ni.trayUuid||"",printerId:t.id,amsId:rt.id,trayId:ln})}:void 0,onUnlinkSpool:tc?.id?()=>_a.mutate(tc.id):void 0},inventory:o?void 0:(()=>{const Nn=d?.(t.id,rt.id,ln);return{assignedSpool:Nn?.spool?{id:Nn.spool.id,material:Nn.spool.material,brand:Nn.spool.brand,color_name:Nn.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(Nn.spool.label_weight-Nn.spool.weight_used))}:null,onAssignSpool:ni.vendor!=="Bambu Lab"?()=>Ce({printerId:t.id,amsId:rt.id,trayId:ln,trayInfo:{type:zn?.tray_type||ni.profile,material:zn?.tray_type??void 0,profile:ni.profile,color:ni.colorHex||"",location:`${gl(rt.id,rt.tray.length)} Slot ${ln+1}`}}):void 0,onUnassignSpool:Nn&&ni.vendor!=="Bambu Lab"?()=>m?.(t.id,rt.id,ln):void 0}})(),configureSlot:{enabled:C("printers:control"),onConfigure:()=>$e({amsId:rt.id,trayId:ln,trayCount:rt.tray.length,trayType:zn?.tray_type||void 0,trayColor:zn?.tray_color||void 0,traySubBrands:zn?.tray_sub_brands||void 0,trayInfoIdx:zn?.tray_info_idx||void 0,extruderId:un,caliIdx:zn?.cali_idx,savedPresetId:gi?.preset_id})},children:Jh}):i.jsx($j,{configureSlot:{enabled:C("printers:control"),onConfigure:()=>$e({amsId:rt.id,trayId:ln,trayCount:rt.tray.length,extruderId:un})},inventory:o?void 0:{onAssignSpool:()=>Ce({printerId:t.id,amsId:rt.id,trayId:ln,trayInfo:{type:"",color:"",location:`${gl(rt.id,rt.tray.length)} Slot ${ln+1}`}})},children:Jh})]},ln)})})]},rt.id)})}),(Pt.length>0||Qe.vt_tray.length>0)&&i.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[Pt.map(rt=>{const un=Me[String(rt.id)],In=rt.id>=128?rt.id-128:rt.id,Vn=un!==void 0?un:In,Na=Vn===1,_o=Vn===0,ln=rt.tray[0],zn=ln?.tray_type&&ln.remain>=0,Cs=!ln?.tray_type,Ts=G0(rt.id,ln?.id??0,!1),rl=Ut===Ts,ec=ln?.tray_info_idx?Fe?.[ln.tray_info_idx]:null,Xs=tt?.[Ts],gi=ln?.id??0,Ia=(ln?.tray_uuid||ln?.tag_uid||xb(t.serial_number,rt.id,gi))?.toUpperCase(),tc=Ia?l?.[Ia]:void 0,za=Xj(tc),No=d?.(t.id,rt.id,gi),jc=(()=>{const Nn=No?.spool;return Nn&&Nn.label_weight>0&&Nn.weight_used!=null?Math.round(Math.max(0,Nn.label_weight-Nn.weight_used)/Nn.label_weight*100):null})(),ti=jc===0&&zn&&ln.remain>0?null:jc,ko=za??ti??(zn?ln.remain:null),iy=za!==null?"spoolman":ti!==null?"inventory":zn?"ams":void 0,ni=ln?.tray_type?{vendor:Qj(ln)?"Bambu Lab":"Generic",profile:Xs?.preset_name||ec?.name||No?.spool?.slicer_filament_name||ln.tray_sub_brands||ln.tray_type,colorName:Gj(ln.tray_id_name)||dN(ln.tray_color),colorHex:ln.tray_color||null,kFactor:Wj(ln.k),fillLevel:ko,trayUuid:ln.tray_uuid||null,tagUid:ln.tag_uid||null,fillSource:iy}:null,Au=_s?.amsId===rt.id&&_s?.slotId===gi,Jh=i.jsxs("div",{className:`bg-bambu-dark-tertiary rounded p-1 text-center ${Cs?"opacity-50":""} ${rl?"ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark":""}`,children:[i.jsx(Vj,{trayColor:ln?.tray_color,trayType:ln?.tray_type,isEmpty:Cs,slotNumber:1}),i.jsx("div",{className:"text-[9px] text-white font-bold truncate",children:ln?.tray_type||"—"}),i.jsx("div",{className:"mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden",children:ko!==null&&ko>=0&&i.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${ko}%`,backgroundColor:Yj(ko)}})})]});return i.jsxs("div",{className:"p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary/30",children:[i.jsxs("div",{className:"flex items-center gap-1 mb-2",children:[i.jsx(_W,{ams:rt,printerId:t.id,label:gl(rt.id,rt.tray.length),amsLabels:ut,canEdit:C("printers:update"),onSaved:Ze,children:i.jsx("span",{className:"text-[10px] text-white font-medium cursor-default select-none",children:ut?.[rt.id]||gl(rt.id,rt.tray.length)})}),rn&&(Na||_o)&&i.jsx(xW,{side:Na?"L":"R"}),Qe.supports_drying&&(rt.module_type==="n3f"||rt.module_type==="n3s")&&C("printers:control")&&i.jsx("div",{className:"relative ml-auto",children:i.jsx("button",{onClick:Nn=>{if(rt.dry_time>0)$r.mutate(rt.id);else if(ue===rt.id)fe(null);else{const em=(rt.tray.find(Zw=>Zw.tray_type)?.tray_type||"PLA").split(" ")[0].toUpperCase(),tg=x[em]||x.PLA,ay=rt.module_type;F(em),ve(tg[ay]||tg.n3f),de(ay==="n3s"?tg.n3s_hours:tg.n3f_hours),ae(rt.module_type),fe(rt.id);const sy=Nn.currentTarget.getBoundingClientRect();Se({top:sy.bottom+4,left:Math.max(8,sy.right-240)})}},className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[9px] transition-colors ${rt.dry_time>0?"bg-amber-500/20 text-amber-400":"bg-bambu-dark-tertiary/50 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,title:rt.dry_time>0?g("printers.drying.stop"):g("printers.drying.start"),children:i.jsx(Fp,{className:"w-3 h-3"})})})]}),rt.dry_time>0&&i.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 mb-1 bg-amber-500/10 border border-amber-500/20 rounded text-[9px] whitespace-nowrap overflow-hidden",children:[i.jsx(Fp,{className:"w-3 h-3 text-amber-400 shrink-0"}),i.jsx("span",{className:"text-amber-300/70 text-[8px] truncate",children:rt.dry_time>=60?`${Math.floor(rt.dry_time/60)}h ${rt.dry_time%60}m`:`${rt.dry_time}m`}),i.jsx("button",{onClick:()=>$r.mutate(rt.id),disabled:$r.isPending,className:"ml-auto text-amber-400 hover:text-amber-300 transition-colors disabled:opacity-50 shrink-0",title:g("printers.drying.stop"),children:i.jsx(Ht,{className:"w-3 h-3"})})]}),i.jsxs("div",{className:"flex gap-1.5 max-[550px]:flex-col max-[550px]:items-start",children:[i.jsxs("div",{className:"relative group flex-1 max-[550px]:w-full",children:[Au&&i.jsx("div",{className:"absolute inset-0 bg-bambu-dark-tertiary/80 rounded flex items-center justify-center z-20",children:i.jsx(wr,{className:"w-4 h-4 text-bambu-green animate-spin"})}),Qe?.state!=="RUNNING"&&i.jsx("button",{onClick:Nn=>{Nn.stopPropagation(),Ni(on?.amsId===rt.id&&on?.slotId===gi?null:{amsId:rt.id,slotId:gi})},className:"absolute -top-1 -right-1 w-4 h-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity z-10 hover:bg-bambu-dark-tertiary",title:g("printers.slotOptions"),children:i.jsx(ph,{className:"w-2.5 h-2.5 text-bambu-gray"})}),Qe?.state!=="RUNNING"&&on?.amsId===rt.id&&on?.slotId===gi&&i.jsx("div",{className:"absolute top-full left-0 mt-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]",children:i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-xs flex items-center gap-2 ${C("printers:ams_rfid")?"text-white hover:bg-bambu-dark-tertiary":"text-bambu-gray/50 cursor-not-allowed"}`,onClick:Nn=>{Nn.stopPropagation(),C("printers:ams_rfid")&&(Jo.mutate({amsId:rt.id,slotId:gi}),Ni(null))},disabled:Au||!C("printers:ams_rfid"),title:C("printers:ams_rfid")?void 0:g("printers.permission.noAmsRfid"),children:[i.jsx(wr,{className:`w-3 h-3 ${Au?"animate-spin":""}`}),g("printers.rfid.reread")]})}),ni?i.jsx(Hj,{data:ni,spoolman:{enabled:o,linkedSpoolId:Ia?l?.[Ia]?.id:void 0,spoolmanUrl:c,syncMode:u,onLinkSpool:o?()=>{const Nn=(ni.trayUuid||ni.tagUid||xb(t.serial_number,rt.id,gi)).toUpperCase();ce({tagUid:ni.tagUid||Nn,trayUuid:ni.trayUuid||"",printerId:t.id,amsId:rt.id,trayId:gi})}:void 0,onUnlinkSpool:tc?.id?()=>_a.mutate(tc.id):void 0},inventory:o?void 0:(()=>{const Nn=d?.(t.id,rt.id,gi);return{assignedSpool:Nn?.spool?{id:Nn.spool.id,material:Nn.spool.material,brand:Nn.spool.brand,color_name:Nn.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(Nn.spool.label_weight-Nn.spool.weight_used))}:null,onAssignSpool:ni.vendor!=="Bambu Lab"?()=>Ce({printerId:t.id,amsId:rt.id,trayId:gi,trayInfo:{type:ln?.tray_type||ni.profile,material:ln?.tray_type??void 0,profile:ni.profile,color:ni.colorHex||"",location:gl(rt.id,rt.tray.length)}}):void 0,onUnassignSpool:Nn&&ni.vendor!=="Bambu Lab"?()=>m?.(t.id,rt.id,gi):void 0}})(),configureSlot:{enabled:C("printers:control"),onConfigure:()=>$e({amsId:rt.id,trayId:gi,trayCount:rt.tray.length,trayType:ln?.tray_type||void 0,trayColor:ln?.tray_color||void 0,traySubBrands:ln?.tray_sub_brands||void 0,trayInfoIdx:ln?.tray_info_idx||void 0,extruderId:un,caliIdx:ln?.cali_idx,savedPresetId:Xs?.preset_id})},children:Jh}):i.jsx($j,{configureSlot:{enabled:C("printers:control"),onConfigure:()=>$e({amsId:rt.id,trayId:gi,trayCount:rt.tray.length,extruderId:un})},inventory:o?void 0:{onAssignSpool:()=>Ce({printerId:t.id,amsId:rt.id,trayId:gi,trayInfo:{type:"",color:"",location:gl(rt.id,rt.tray.length)}})},children:Jh})]}),(rt.humidity!=null||rt.temp!=null)&&i.jsxs("div",{className:"flex flex-col justify-center gap-1 shrink-0 max-[550px]:w-full",children:[rt.temp!=null&&i.jsx(wW,{temp:rt.temp,goodThreshold:s?.tempGood,fairThreshold:s?.tempFair,onClick:()=>je({amsId:rt.id,amsLabel:gl(rt.id,rt.tray.length),mode:"temperature"}),compact:!0}),rt.humidity!=null&&i.jsx(vW,{humidity:rt.humidity,goodThreshold:s?.humidityGood,fairThreshold:s?.humidityFair,onClick:()=>je({amsId:rt.id,amsLabel:gl(rt.id,rt.tray.length),mode:"humidity"}),compact:!0})]})]})]},rt.id)}),Qe.vt_tray.length>0&&i.jsxs("div",{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary/30 ${Qe.vt_tray.length===1?"max-w-[50%]":""}`,children:[i.jsx("div",{className:"flex items-center gap-1 mb-2",children:i.jsx("span",{className:"text-[10px] text-white font-medium",children:g("printers.external")})}),i.jsx("div",{className:`grid ${Qe.vt_tray.length>1?"grid-cols-2":"grid-cols-1"} gap-1.5`,children:[...Qe.vt_tray].sort((rt,un)=>(rt.id??254)-(un.id??254)).map(rt=>{const un=rt.id??254,In=rn&&Ut===254?un===254&&Qe.active_extruder===1||un===255&&Qe.active_extruder===0:Ut===un,Vn=un-254,Na=rn?g(un===254?"printers.extL":"printers.extR"):"",_o=rt.tray_info_idx?Fe?.[rt.tray_info_idx]:null,ln=tt?.[1020+Vn],zn=(rt.tray_uuid||rt.tag_uid||xb(t.serial_number,255,Vn))?.toUpperCase(),Cs=zn?l?.[zn]:void 0,Ts=Xj(Cs),rl=d?.(t.id,255,Vn),ec=(()=>{const ti=rl?.spool;return ti&&ti.label_weight>0&&ti.weight_used!=null?Math.round(Math.max(0,ti.label_weight-ti.weight_used)/ti.label_weight*100):null})(),Xs=rt.tray_type&&rt.remain>=0,gi=ec===0&&Xs&&rt.remain>0?null:ec,Ia=Ts??gi??(Xs?rt.remain:null),tc=Ts!==null?"spoolman":gi!==null?"inventory":Xs?"ams":void 0,za={vendor:Qj(rt)?"Bambu Lab":"Generic",profile:ln?.preset_name||_o?.name||rl?.spool?.slicer_filament_name||rt.tray_sub_brands||rt.tray_type||"Unknown",colorName:Gj(rt.tray_id_name)||dN(rt.tray_color),colorHex:rt.tray_color||null,kFactor:Wj(rt.k),fillLevel:Ia,trayUuid:rt.tray_uuid||null,tagUid:rt.tag_uid||null,fillSource:tc},No=!rt.tray_type,jc=i.jsxs("div",{className:`bg-bambu-dark-tertiary rounded p-1 text-center ${No?"opacity-50":""} ${In?"ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark":""}`,children:[i.jsx(Vj,{trayColor:rt.tray_color,trayType:rt.tray_type,isEmpty:No,slotNumber:Vn+1}),i.jsx("div",{className:`text-[9px] font-bold truncate ${No?"text-white/40":"text-white"}`,children:rt.tray_type||"—"}),i.jsx("div",{className:"mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden",children:Ia!==null&&Ia>=0&&!No&&i.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${Ia}%`,backgroundColor:Yj(Ia)}})}),Na&&i.jsx("div",{className:"text-[7px] text-white/40 mt-0.5 truncate",children:Na})]});return i.jsx("div",{className:"relative group",children:No?i.jsx($j,{configureSlot:{enabled:C("printers:control"),onConfigure:()=>$e({amsId:255,trayId:Vn,trayCount:1,extruderId:rn?un===254?1:0:void 0})},inventory:o?void 0:{onAssignSpool:()=>Ce({printerId:t.id,amsId:255,trayId:Vn,trayInfo:{type:"",color:"",location:Na||g("printers.external")}})},children:jc}):i.jsx(Hj,{data:za,spoolman:{enabled:o,linkedSpoolId:zn?l?.[zn]?.id:void 0,spoolmanUrl:c,syncMode:u,onLinkSpool:o?()=>{const ti=(za.trayUuid||za.tagUid||xb(t.serial_number,255,Vn)).toUpperCase();ce({tagUid:za.tagUid||ti,trayUuid:za.trayUuid||"",printerId:t.id,amsId:255,trayId:Vn})}:void 0,onUnlinkSpool:Cs?.id?()=>_a.mutate(Cs.id):void 0},inventory:o?void 0:(()=>{const ti=d?.(t.id,255,Vn);return{assignedSpool:ti?.spool?{id:ti.spool.id,material:ti.spool.material,brand:ti.spool.brand,color_name:ti.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(ti.spool.label_weight-ti.spool.weight_used))}:null,onAssignSpool:()=>Ce({printerId:t.id,amsId:255,trayId:Vn,trayInfo:{type:rt.tray_type||za.profile,material:rt.tray_type??void 0,profile:za.profile,color:za.colorHex||"",location:Na||g("printers.external")}}),onUnassignSpool:ti?()=>m?.(t.id,255,Vn):void 0}})(),configureSlot:{enabled:C("printers:control"),onConfigure:()=>$e({amsId:255,trayId:Vn,trayCount:1,trayType:rt.tray_type||void 0,trayColor:rt.tray_color||void 0,traySubBrands:rt.tray_sub_brands||void 0,trayInfoIdx:rt.tray_info_idx||void 0,extruderId:rn?un===254?1:0:void 0,caliIdx:rt.cali_idx,savedPresetId:ln?.preset_id})},children:jc})},un)})})]})]})]})]})})()]}),Et&&r==="expanded"&&i.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[i.jsx(kc,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),i.jsx("span",{className:"text-sm text-white truncate",children:Et.name}),Zt&&i.jsxs("span",{className:`text-xs px-1.5 py-0.5 rounded flex-shrink-0 ${Zt.state==="ON"?"bg-bambu-green/20 text-bambu-green":Zt.state==="OFF"?"bg-red-500/20 text-red-400":"bg-bambu-gray/20 text-bambu-gray"}`,children:[Zt.state||"?",Zt.state==="ON"&&Zt.energy?.power!=null&&i.jsxs("span",{className:"text-yellow-400 ml-1.5",children:["· ",Zt.energy.power,"W"]})]})]}),i.jsx("div",{className:"flex-1"}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsxs("button",{onClick:()=>he(!0),disabled:cr.isPending||Zt?.state==="ON"||!C("smart_plugs:control"),className:`px-2 py-1 text-xs rounded transition-colors flex items-center gap-1 ${C("smart_plugs:control")?Zt?.state==="ON"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary":"bg-bambu-dark text-bambu-gray/50 cursor-not-allowed"}`,title:C("smart_plugs:control")?void 0:g("printers.permission.noSmartPlugControl"),children:[i.jsx(Vd,{className:"w-3 h-3"}),"On"]}),i.jsxs("button",{onClick:()=>Y(!0),disabled:cr.isPending||Zt?.state==="OFF"||!C("smart_plugs:control"),className:`px-2 py-1 text-xs rounded transition-colors flex items-center gap-1 ${C("smart_plugs:control")?Zt?.state==="OFF"?"bg-red-500/30 text-red-400":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary":"bg-bambu-dark text-bambu-gray/50 cursor-not-allowed"}`,title:C("smart_plugs:control")?void 0:g("printers.permission.noSmartPlugControl"),children:[i.jsx(nT,{className:"w-3 h-3"}),"Off"]})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[i.jsx("span",{className:`text-xs hidden sm:inline ${Et.auto_off_executed?"text-bambu-green":"text-bambu-gray"}`,children:Et.auto_off_executed?"Auto-off done":"Auto-off"}),i.jsx("button",{onClick:()=>li.mutate(!Et.auto_off),disabled:li.isPending||Et.auto_off_executed||!C("smart_plugs:control"),title:C("smart_plugs:control")?Et.auto_off_executed?g("printers.autoOffExecuted"):g("printers.autoOffAfterPrint"):g("printers.permission.noSmartPlugControl"),className:`relative w-9 h-5 rounded-full transition-colors flex-shrink-0 ${C("smart_plugs:control")?Et.auto_off_executed?"bg-bambu-green/50 cursor-not-allowed":Et.auto_off?"bg-bambu-green":"bg-bambu-dark-tertiary":"bg-bambu-dark-tertiary/50 cursor-not-allowed"}`,children:i.jsx("span",{className:`absolute top-[2px] left-[2px] w-4 h-4 bg-white rounded-full transition-transform ${Et.auto_off||Et.auto_off_executed?"translate-x-4":"translate-x-0"}`})})]})]}),It&&It.length>0&&i.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-bambu-dark-tertiary/50",children:[i.jsx(hw,{className:"w-3.5 h-3.5 text-blue-400 flex-shrink-0"}),i.jsx("span",{className:"text-xs text-bambu-gray",children:"HA:"}),i.jsx("div",{className:"flex flex-wrap gap-1",children:It.map(mt=>{const Pt=mt.ha_entity_id?.startsWith("script.");return i.jsxs("button",{onClick:()=>_i.mutate({id:mt.id,action:Pt?"on":"toggle"}),disabled:_i.isPending,title:`${Pt?"Run":"Toggle"} ${mt.ha_entity_id}`,className:"px-2 py-0.5 text-xs bg-blue-500/20 text-blue-400 hover:bg-blue-500/30 rounded transition-colors flex items-center gap-1",children:[i.jsx(go,{className:"w-2.5 h-2.5"}),mt.name]},mt.id)})})]})]}),r==="expanded"&&i.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary flex items-center justify-end gap-2 flex-wrap",children:[i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>Yh.mutate(!Qe?.chamber_light),disabled:!Qe?.connected||Yh.isPending||!C("printers:control"),title:C("printers:control")?Qe?.chamber_light?g("printers.chamberLightOff"):g("printers.chamberLightOn"):g("printers.permission.noControl"),className:Qe?.chamber_light?"!border-yellow-500 !text-yellow-400 hover:!bg-yellow-500/20":"",children:i.jsx(_O,{on:Qe?.chamber_light??!1,className:`w-4 h-4 ${Qe?.chamber_light?"text-yellow-400":""}`})}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>{if(f==="embedded"&&y)y(t.id,t.name);else{const mt=localStorage.getItem("cameraWindowState"),Pt=mt?JSON.parse(mt):{width:640,height:400},rn=[`width=${Pt.width}`,`height=${Pt.height}`,Pt.left!==void 0?`left=${Pt.left}`:"",Pt.top!==void 0?`top=${Pt.top}`:"","menubar=no,toolbar=no,location=no,status=no,noopener"].filter(Boolean).join(",");window.open(`/camera/${t.id}`,`camera-${t.id}`,rn)}},disabled:!Qe?.connected||!C("camera:view"),title:C("camera:view")?g(f==="embedded"?"printers.openCameraOverlay":"printers.openCameraWindow"):g("printers.permission.noCamera"),children:i.jsx(VL,{className:"w-4 h-4"})}),i.jsxs("div",{className:`inline-flex rounded-md ${t.plate_detection_enabled?"ring-1 ring-green-500":""}`,children:[i.jsx(Oe,{variant:"secondary",size:"sm",onClick:Nu,disabled:!Qe?.connected||Ss.isPending||!C("printers:update"),title:C("printers:update")?t.plate_detection_enabled?g("printers.plateDetection.enabledClick"):g("printers.plateDetection.disabledClick"):g("printers.plateDetection.noPermission"),className:`!rounded-r-none !border-r-0 ${t.plate_detection_enabled?"!border-green-500 !text-green-400 hover:!bg-green-500/20":""}`,children:Ss.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(RN,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:Zl,disabled:!Qe?.connected||xt||!C("printers:update"),title:C("printers:update")?g("printers.plateDetection.manageCalibration"):g("printers.plateDetection.noPermission"),className:`!rounded-l-none !px-1.5 ${t.plate_detection_enabled?"!border-green-500 !text-green-400 hover:!bg-green-500/20":""}`,children:xt?i.jsx(ht,{className:"w-3 h-3 animate-spin"}):i.jsx(Ln,{className:"w-3 h-3"})})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>ee(!0),disabled:!Ke||!C("printers:files"),title:C("printers:files")?g("printers.browseFiles"):g("printers.permission.noFiles"),children:[i.jsx(Lx,{className:"w-4 h-4"}),g("printers.files")]}),Ke&&Qe?.state!=="RUNNING"&&Qe?.state!=="PAUSE"&&i.jsxs(Oe,{size:"sm",onClick:()=>ne(!0),disabled:!C("printers:control"),title:C("printers:control")?g("common.print"):g("printers.permission.noControl"),className:"!bg-bambu-green hover:!bg-bambu-green/80 !text-white",children:[i.jsx(Sr,{className:"w-4 h-4"}),g("common.print")]})]})]}),I&&i.jsx(oMe,{printerId:t.id,printerName:t.name,onClose:()=>ee(!1)}),$&&i.jsx(Qre,{folderId:null,onClose:()=>ne(!1),onUploadComplete:()=>{},autoUpload:!0,accept:".gcode,.3mf",validateFile:mt=>{const Pt=mt.name.toLowerCase();if(!Pt.endsWith(".gcode")&&!Pt.includes(".gcode."))return g("printers.dropNotPrintable","Only .gcode and .gcode.3mf files can be printed")},onFileUploaded:mt=>{const Pt=mt.metadata?.sliced_for_model,rn=Kv(t.model);if(Pt&&rn&&Pt.toLowerCase()!==rn.toLowerCase())return be.deleteLibraryFile(mt.id).catch(()=>{}),g("printers.incompatibleFile","This file was sliced for {{slicedFor}}, but this printer is a {{printerModel}}",{slicedFor:Pt,printerModel:rn});re({id:mt.id,filename:mt.filename})}}),W&&i.jsx(uu,{mode:"reprint",libraryFileId:W.id,archiveName:W.filename,initialSelectedPrinterIds:[t.id],onClose:()=>re(null),onSuccess:()=>re(null)}),ie&&i.jsx(hMe,{printerId:t.id,printerName:t.name,onClose:()=>X(!1)}),O&&i.jsx(Xqe,{printer:t,status:Qe,totalPrintHours:n?.total_print_hours,onClose:J}),Ve&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:()=>Bi(),children:i.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-w-lg w-full",onClick:mt=>mt.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[Ve.needs_calibration?i.jsx(RN,{className:"w-5 h-5 text-blue-500"}):Ve.is_empty?i.jsx(fr,{className:"w-5 h-5 text-green-500"}):i.jsx(Vi,{className:"w-5 h-5 text-yellow-500"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:"Build Plate Check"}),Ve.reference_count!==void 0&&Ve.max_references&&i.jsxs("span",{className:"text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded",children:[Ve.reference_count,"/",Ve.max_references," refs"]})]}),i.jsx("button",{onClick:()=>Bi(),className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[Ve.needs_calibration?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"p-3 rounded-lg bg-blue-500/20 border border-blue-500/50",children:[i.jsx("p",{className:"font-medium text-blue-400",children:g("printers.plateDetection.calibrationRequired")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",dangerouslySetInnerHTML:{__html:g("printers.plateDetection.calibrationInstructions")}})]}),i.jsxs("div",{className:"text-sm text-bambu-gray space-y-2",children:[i.jsx("p",{children:g("printers.plateDetection.calibrationDescription")}),i.jsx("p",{dangerouslySetInnerHTML:{__html:g("printers.plateDetection.calibrationTip")}})]})]}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:`p-3 rounded-lg ${Ve.is_empty?"bg-green-500/20 border border-green-500/50":"bg-yellow-500/20 border border-yellow-500/50"}`,children:[i.jsx("p",{className:`font-medium ${Ve.is_empty?"text-green-400":"text-yellow-400"}`,children:Ve.is_empty?g("printers.plateDetection.plateEmpty"):g("printers.plateDetection.objectsDetected")}),i.jsxs("p",{className:"text-sm text-bambu-gray mt-1",children:[g("printers.plateDetection.confidence"),": ",Math.round(Ve.confidence*100),"% | ",g("printers.plateDetection.difference"),": ",Ve.difference_percent.toFixed(1),"%"]})]}),Ve.debug_image_url&&i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:g("printers.plateDetection.analysisPreview")}),i.jsx("img",{src:Ve.debug_image_url,alt:g("printers.plateDetection.analysisPreview"),className:"w-full rounded-lg border border-bambu-dark-tertiary"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:g("printers.plateDetection.analysisLegend")})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:Ve.message})]}),el&&el.references.length>0&&i.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-sm font-medium text-white mb-2",children:g("printers.plateDetection.savedReferences",{count:el.references.length,max:el.max_references})}),i.jsx("div",{className:"grid grid-cols-5 gap-2",children:el.references.map(mt=>i.jsxs("div",{className:"relative group",children:[i.jsx("img",{src:be.getPlateReferenceThumbnailUrl(t.id,mt.index),alt:mt.label||`Reference ${mt.index+1}`,className:"w-full aspect-video object-cover rounded border border-bambu-dark-tertiary"}),i.jsx("button",{onClick:()=>Qh(mt.index),className:"absolute top-1 right-1 p-0.5 bg-red-500/80 rounded opacity-0 group-hover:opacity-100 transition-opacity",title:g("printers.plateDetection.deleteReference"),children:i.jsx(Ht,{className:"w-3 h-3 text-white"})}),Ql?.index===mt.index?i.jsx("input",{type:"text",value:Ql.label,onChange:Pt=>Ys({...Ql,label:Pt.target.value}),onBlur:()=>nl(mt.index,Ql.label),onKeyDown:Pt=>{Pt.key==="Enter"&&nl(mt.index,Ql.label),Pt.key==="Escape"&&Ys(null)},className:"w-full mt-1 px-1 py-0.5 text-xs bg-bambu-dark-tertiary border border-bambu-green rounded text-white",autoFocus:!0,placeholder:g("printers.plateDetection.labelPlaceholder")}):i.jsx("p",{className:"text-xs text-bambu-gray mt-1 truncate cursor-pointer hover:text-white",onClick:()=>Ys({index:mt.index,label:mt.label}),title:mt.label?g("printers.plateDetection.clickToEdit",{label:mt.label}):g("printers.plateDetection.clickToAddLabel"),children:mt.label||i.jsx("span",{className:"italic opacity-50",children:g("printers.noLabel")})}),i.jsx("p",{className:"text-[10px] text-bambu-gray/60",children:mt.timestamp?Jn(mt.timestamp)?.toLocaleDateString()??"":""})]},mt.index))})]}),!Ve.needs_calibration&&i.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("p",{className:"text-sm font-medium text-white",children:g("printers.roi.title")}),yt?i.jsxs("div",{className:"flex gap-1",children:[i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>wt(null),disabled:_t,children:g("common.cancel")}),i.jsx(Oe,{size:"sm",onClick:ku,disabled:_t,children:_t?i.jsx(ht,{className:"w-3 h-3 animate-spin"}):g("common.save")})]}):i.jsxs(Oe,{variant:"ghost",size:"sm",onClick:()=>wt(Ve.roi||{x:.15,y:.35,w:.7,h:.55}),children:[i.jsx(Yi,{className:"w-3 h-3 mr-1"}),g("common.edit")]})]}),yt?i.jsxs("div",{className:"space-y-3 bg-bambu-dark-tertiary/50 p-3 rounded-lg",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"text-xs text-bambu-gray",children:g("printers.roi.xStart")}),i.jsx("input",{type:"range",min:"0",max:"0.9",step:"0.01",value:yt.x,onChange:mt=>wt({...yt,x:parseFloat(mt.target.value)}),className:"w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500"}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:[Math.round(yt.x*100),"%"]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"text-xs text-bambu-gray",children:g("printers.roi.yStart")}),i.jsx("input",{type:"range",min:"0",max:"0.9",step:"0.01",value:yt.y,onChange:mt=>wt({...yt,y:parseFloat(mt.target.value)}),className:"w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500"}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:[Math.round(yt.y*100),"%"]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"text-xs text-bambu-gray",children:g("printers.width")}),i.jsx("input",{type:"range",min:"0.1",max:"1",step:"0.01",value:yt.w,onChange:mt=>wt({...yt,w:parseFloat(mt.target.value)}),className:"w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500"}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:[Math.round(yt.w*100),"%"]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"text-xs text-bambu-gray",children:g("printers.height")}),i.jsx("input",{type:"range",min:"0.1",max:"1",step:"0.01",value:yt.h,onChange:mt=>wt({...yt,h:parseFloat(mt.target.value)}),className:"w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500"}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:[Math.round(yt.h*100),"%"]})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:g("printers.roi.instruction")})]}):i.jsxs("p",{className:"text-xs text-bambu-gray",children:["Current: X=",Math.round((Ve.roi?.x||.15)*100),"%, Y=",Math.round((Ve.roi?.y||.35)*100),"%, W=",Math.round((Ve.roi?.w||.7)*100),"%, H=",Math.round((Ve.roi?.h||.55)*100),"%"]})]})]}),i.jsx("div",{className:"flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary",children:Ve.needs_calibration?i.jsxs(i.Fragment,{children:[i.jsx(Oe,{variant:"ghost",onClick:()=>Bi(),children:g("common.cancel")}),i.jsx(Oe,{onClick:()=>tl(),disabled:kt,children:kt?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 mr-2 animate-spin"}),"Calibrating..."]}):"Calibrate Empty Plate"})]}):i.jsxs(i.Fragment,{children:[i.jsx(Oe,{variant:"ghost",onClick:()=>tl(),disabled:kt,children:kt?"Adding...":`Add Reference (${el?.references.length||0}/${el?.max_references||5})`}),i.jsx(Oe,{onClick:()=>Bi(),children:"Close"})]})})]})}),me&&Et&&i.jsx(Sn,{title:g("printers.confirm.powerOnTitle"),message:g("printers.confirm.powerOnMessage",{name:t.name}),confirmText:g("printers.confirm.powerOnButton"),variant:"default",onConfirm:()=>{cr.mutate("on"),he(!1)},onCancel:()=>he(!1)}),ge&&Et&&i.jsx(Sn,{title:g("printers.confirm.powerOffTitle"),message:Qe?.state==="RUNNING"?g("printers.confirm.powerOffWarning",{name:t.name}):g("printers.confirm.powerOffMessage",{name:t.name}),confirmText:g("printers.confirm.powerOffButton"),variant:"danger",onConfirm:()=>{cr.mutate("off"),Y(!1)},onCancel:()=>Y(!1)}),xe&&i.jsx(Sn,{title:g("printers.confirm.stopTitle"),message:g("printers.confirm.stopMessage",{name:t.name}),confirmText:g("printers.confirm.stopButton"),variant:"danger",onConfirm:()=>{Tr.mutate(),Pe(!1)},onCancel:()=>Pe(!1)}),q&&i.jsx(Sn,{title:g("printers.confirm.pauseTitle"),message:g("printers.confirm.pauseMessage",{name:t.name}),confirmText:g("printers.confirm.pauseButton"),variant:"default",onConfirm:()=>{zi.mutate(),Z(!1)},onCancel:()=>Z(!1)}),j&&i.jsx(Sn,{title:g("printers.confirm.resumeTitle"),message:g("printers.confirm.resumeMessage",{name:t.name}),confirmText:g("printers.confirm.resumeButton"),variant:"default",onConfirm:()=>{Zd.mutate(),E(!1)},onCancel:()=>E(!1)}),i.jsx(NO,{printerId:t.id,isOpen:U,onClose:()=>K(!1)}),oe&&i.jsx(bMe,{printerName:t.name,errors:Qe?.hms_errors||[],onClose:()=>le(!1),printerId:t.id,hasPermission:C}),Be&&i.jsx(Tqe,{isOpen:!!Be,onClose:()=>je(null),printerId:t.id,printerName:t.name,amsId:Be.amsId,amsLabel:Be.amsLabel,initialMode:Be.mode,thresholds:s}),Xe&&i.jsx(Aqe,{isOpen:!!Xe,onClose:()=>ce(null),tagUid:Xe.tagUid,trayUuid:Xe.trayUuid,printerId:Xe.printerId,amsId:Xe.amsId,trayId:Xe.trayId}),Ie&&i.jsx(Pqe,{isOpen:!!Ie,onClose:()=>Ce(null),printerId:Ie.printerId,amsId:Ie.amsId,trayId:Ie.trayId,trayInfo:Ie.trayInfo}),Ge&&i.jsx(Xre,{isOpen:!!Ge,onClose:()=>$e(null),printerId:t.id,slotInfo:Ge,printerModel:Kv(t.model)||void 0,onSuccess:()=>{_.invalidateQueries({queryKey:["slotPresets",t.id]}),_.invalidateQueries({queryKey:["printerStatus",t.id]})}}),z&&i.jsx(dVe,{printer:t,onClose:()=>G(!1)}),Ue&&Qt&&i.jsx(uVe,{printer:t,firmwareInfo:Qt,onClose:()=>De(!1)}),on&&i.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>Ni(null)}),ue!==null&&Ne&&(()=>{const mt=ye==="n3s"?85:65,Pt=35,rn=mt+10;return i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-[100]",onClick:()=>fe(null)}),i.jsxs("div",{className:"fixed z-[101] w-[240px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl overflow-hidden",style:{top:Ne.top,left:Ne.left},onClick:rt=>rt.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 border-b border-bambu-dark-tertiary",children:[i.jsx(Fp,{className:"w-3.5 h-3.5 text-amber-400"}),i.jsx("span",{className:"text-xs text-white font-medium",children:g("printers.drying.start")})]}),i.jsxs("div",{className:"px-3 py-2.5 space-y-2.5",children:[i.jsxs("div",{children:[i.jsx("label",{className:"text-[10px] text-bambu-gray mb-1 block",children:g("printers.filaments")}),i.jsx("select",{value:L,onChange:rt=>{const un=rt.target.value;F(un);const In=x[un];In&&(ve(In[ye==="n3s"?"n3s":"n3f"]),de(ye==="n3s"?In.n3s_hours:In.n3f_hours))},className:"w-full px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs focus:outline-none focus:border-amber-500/50",children:Object.keys(x).map(rt=>i.jsx("option",{value:rt,children:rt},rt))})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-1",children:[i.jsx("label",{className:"text-[10px] text-bambu-gray",children:g("printers.drying.temperature")}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("input",{type:"number",min:45,max:mt,value:te,onChange:rt=>ve(Math.min(mt,Math.max(45,Number(rt.target.value)||45))),className:"w-12 px-1 py-0.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-[11px] text-center focus:outline-none focus:border-amber-500/50 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"}),i.jsx("span",{className:"text-[10px] text-bambu-gray",children:"°C"})]})]}),i.jsx("input",{type:"range",min:Pt,max:rn,value:te,onChange:rt=>ve(Math.min(mt,Math.max(45,Number(rt.target.value)))),className:"w-full h-1 accent-amber-500 cursor-pointer"}),i.jsxs("div",{className:"flex justify-between text-[9px] text-bambu-gray/50 mt-0.5",children:[i.jsx("span",{children:"45°C"}),i.jsxs("span",{children:[mt,"°C"]})]})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-1",children:[i.jsx("label",{className:"text-[10px] text-bambu-gray",children:g("printers.drying.duration")}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("input",{type:"number",min:1,max:24,value:pe,onChange:rt=>de(Math.min(24,Math.max(1,Number(rt.target.value)||1))),className:"w-10 px-1 py-0.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-[11px] text-center focus:outline-none focus:border-amber-500/50 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"}),i.jsx("span",{className:"text-[10px] text-bambu-gray",children:g("printers.drying.hours")})]})]}),i.jsx("input",{type:"range",min:1,max:24,value:pe,onChange:rt=>de(Number(rt.target.value)),className:"w-full h-1 accent-amber-500 cursor-pointer"}),i.jsxs("div",{className:"flex justify-between text-[9px] text-bambu-gray/50 mt-0.5",children:[i.jsx("span",{children:"1h"}),i.jsx("span",{children:"24h"})]})]})]}),i.jsx("div",{className:"px-3 pb-3",children:i.jsx("button",{onClick:()=>{ue!==null&&On.mutate({amsId:ue,temp:te,duration:pe,filament:L})},disabled:On.isPending,className:"w-full py-1.5 bg-amber-500 hover:bg-amber-400 text-white text-xs font-medium rounded-lg transition-colors disabled:opacity-50",children:On.isPending?g("printers.drying.startingDrying"):g("printers.drying.start")})})]})]})})()]})}function cVe({onClose:t,onAdd:e,existingSerials:n}){const{t:r}=Ft(),[a,s]=w.useState({name:"",serial_number:"",ip_address:"",access_code:"",model:"",location:"",auto_archive:!0}),[o,l]=w.useState(!1),[c,u]=w.useState([]),[d,m]=w.useState(""),[p,f]=w.useState(!1),[y,v]=w.useState(!1),[x,g]=w.useState([]),[_,N]=w.useState(""),[T,C]=w.useState({scanned:0,total:0});w.useEffect(()=>{Oc.getInfo().then(P=>{v(P.is_docker),P.subnets.length>0&&(g(P.subnets),N(P.subnets[0]))}).catch(()=>{})},[]);const A=c.filter(P=>!n.includes(P.serial)),k=async()=>{m(""),u([]),l(!0),f(!1),C({scanned:0,total:0});try{if(y){await Oc.startSubnetScan(_);const P=setInterval(async()=>{try{const D=await Oc.getScanStatus();C({scanned:D.scanned,total:D.total});const H=await Oc.getDiscoveredPrinters();u(H),D.running||(clearInterval(P),l(!1),f(!0))}catch(D){console.error("Failed to get scan status:",D)}},500)}else{await Oc.startDiscovery(10);const P=setInterval(async()=>{try{const D=await Oc.getDiscoveredPrinters();u(D)}catch(D){console.error("Failed to get discovered printers:",D)}},1e3);setTimeout(async()=>{clearInterval(P);try{await Oc.stopDiscovery()}catch{}l(!1),f(!0);try{const D=await Oc.getDiscoveredPrinters();u(D)}catch(D){console.error("Failed to get final discovered printers:",D)}},1e4)}}catch(P){console.error("Failed to start discovery:",P),m(P instanceof Error?P.message:r("printers.discovery.failedToStart")),l(!1),f(!0)}},R=P=>{const D=P.serial.startsWith("unknown-")?"":P.serial;s({...a,name:P.name||"",serial_number:D,ip_address:P.ip_address,model:Kv(P.model)}),u([])};return w.useEffect(()=>()=>{Oc.stopDiscovery().catch(()=>{}),Oc.stopSubnetScan().catch(()=>{})},[]),w.useEffect(()=>{const P=D=>{D.key==="Escape"&&t()};return window.addEventListener("keydown",P),()=>window.removeEventListener("keydown",P)},[t]),i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",onClick:t,children:i.jsx(Mt,{className:"w-full max-w-md",onClick:P=>P.stopPropagation(),children:i.jsxs(Dt,{children:[i.jsx("h2",{className:"text-xl font-semibold mb-4",children:r("printers.addPrinter")}),i.jsxs("div",{className:"mb-4 pb-4 border-b border-bambu-dark-tertiary",children:[y&&i.jsxs("div",{className:"mb-3",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("printers.discovery.subnetToScan")}),x.length>0?i.jsx("select",{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 text-sm",value:_,onChange:P=>N(P.target.value),disabled:o,children:x.map(P=>i.jsx("option",{value:P,children:P},P))}):i.jsx("input",{type:"text",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 text-sm",value:_,onChange:P=>N(P.target.value),placeholder:"192.168.1.0/24",disabled:o}),i.jsx("p",{className:"mt-1 text-xs text-bambu-gray",children:r("printers.discovery.dockerNote")})]}),i.jsx(Oe,{type:"button",variant:"secondary",onClick:k,disabled:o,className:"w-full",children:o?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),y&&T.total>0?r("printers.discovery.scanProgress",{scanned:T.scanned,total:T.total}):r("printers.discovery.scanning")]}):i.jsxs(i.Fragment,{children:[i.jsx(jr,{className:"w-4 h-4"}),r(y?"printers.discovery.scanSubnet":"printers.discovery.discoverNetwork")]})}),d&&i.jsx("div",{className:"mt-2 text-sm text-red-400",children:d}),A.length>0&&i.jsx("div",{className:"mt-3 space-y-2 max-h-40 overflow-y-auto",children:A.map(P=>i.jsxs("div",{className:"flex items-center justify-between p-2 bg-bambu-dark rounded-lg hover:bg-bambu-dark-secondary cursor-pointer transition-colors",onClick:()=>R(P),children:[i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"font-medium text-white text-sm truncate",children:P.name||P.serial}),i.jsxs("p",{className:"text-xs text-bambu-gray truncate",children:[Kv(P.model)||r("printers.discovery.unknown")," • ",P.ip_address,P.serial.startsWith("unknown-")&&i.jsxs("span",{className:"text-yellow-500",children:[" • ",r("printers.discovery.serialRequired")]})]})]}),i.jsx(Ln,{className:"w-4 h-4 text-bambu-gray -rotate-90 flex-shrink-0 ml-2"})]},P.serial))}),o&&i.jsx("p",{className:"mt-2 text-sm text-bambu-gray text-center",children:r(y?"printers.discovery.scanningSubnet":"printers.discovery.scanningNetwork")}),p&&!o&&c.length===0&&i.jsx("p",{className:"mt-2 text-sm text-bambu-gray text-center",children:r(y?"printers.discovery.noPrintersFoundSubnet":"printers.discovery.noPrintersFoundNetwork")}),p&&!o&&c.length>0&&A.length===0&&i.jsx("p",{className:"mt-2 text-sm text-bambu-gray text-center",children:r("printers.discovery.allConfigured")})]}),i.jsxs("form",{onSubmit:P=>{P.preventDefault(),e(a)},className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("printers.name")}),i.jsx("input",{type:"text",required:!0,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",value:a.name,onChange:P=>s({...a,name:P.target.value}),placeholder:r("printers.modal.myPrinter")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("printers.ipAddress")}),i.jsx("input",{type:"text",required:!0,pattern:"(\\d{1,3}(\\.\\d{1,3}){3}|[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?)*)",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",value:a.ip_address,onChange:P=>s({...a,ip_address:P.target.value}),placeholder:"192.168.1.100 or printer.local"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("printers.serialNumber")}),i.jsx("input",{type:"text",required:!0,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",value:a.serial_number,onChange:P=>s({...a,serial_number:P.target.value}),placeholder:"01P00A000000000"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("printers.accessCode")}),i.jsx("input",{type:"password",required:!0,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",value:a.access_code,onChange:P=>s({...a,access_code:P.target.value}),placeholder:r("printers.modal.fromPrinterSettings")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("printers.modal.modelOptional")}),i.jsxs("select",{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",value:a.model||"",onChange:P=>s({...a,model:P.target.value}),children:[i.jsx("option",{value:"",children:r("printers.modal.selectModel")}),i.jsxs("optgroup",{label:"H2 Series",children:[i.jsx("option",{value:"H2C",children:"H2C"}),i.jsx("option",{value:"H2D",children:"H2D"}),i.jsx("option",{value:"H2D Pro",children:"H2D Pro"}),i.jsx("option",{value:"H2S",children:"H2S"})]}),i.jsxs("optgroup",{label:"X1 Series",children:[i.jsx("option",{value:"X1E",children:"X1E"}),i.jsx("option",{value:"X1C",children:"X1 Carbon"}),i.jsx("option",{value:"X1",children:"X1"})]}),i.jsxs("optgroup",{label:"P Series",children:[i.jsx("option",{value:"P2S",children:"P2S"}),i.jsx("option",{value:"P1S",children:"P1S"}),i.jsx("option",{value:"P1P",children:"P1P"})]}),i.jsxs("optgroup",{label:"A1 Series",children:[i.jsx("option",{value:"A1",children:"A1"}),i.jsx("option",{value:"A1 Mini",children:"A1 Mini"})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("printers.modal.locationGroup")}),i.jsx("input",{type:"text",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",value:a.location||"",onChange:P=>s({...a,location:P.target.value}),placeholder:r("printers.modal.locationPlaceholder")}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:r("printers.locationHelp")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"checkbox",id:"auto_archive",checked:a.auto_archive,onChange:P=>s({...a,auto_archive:P.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("label",{htmlFor:"auto_archive",className:"text-sm text-bambu-gray",children:r("printers.modal.autoArchiveLabel")})]}),i.jsxs("div",{className:"flex gap-3 pt-4",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:t,className:"flex-1",children:r("common.cancel")}),i.jsx(Oe,{type:"submit",className:"flex-1",children:r("printers.addPrinter")})]})]})]})})})}function uVe({printer:t,firmwareInfo:e,onClose:n}){const{t:r}=Ft(),a=an(),{showToast:s}=fn(),{hasPermission:o}=_r(),l=o("firmware:update"),[c,u]=w.useState(null),[d,m]=w.useState(!1),[p,f]=w.useState(null),{data:y,isLoading:v}=et({queryKey:["firmwarePrepare",t.id],queryFn:()=>Y1.prepareUpload(t.id),staleTime:3e4,enabled:e.update_available&&l}),x=pt({mutationFn:()=>Y1.startUpload(t.id),onSuccess:()=>{m(!0);const _=setInterval(async()=>{try{const N=await Y1.getUploadStatus(t.id);u(N),(N.status==="complete"||N.status==="error")&&(clearInterval(_),f(null),m(!1),N.status==="complete"&&(s(r("printers.firmwareModal.uploadedToast"),"success"),a.invalidateQueries({queryKey:["firmwareUpdate",t.id]})))}catch{}},2e3);f(_)},onError:_=>{s(r("printers.firmwareModal.uploadFailed",{error:_.message}),"error"),m(!1)}});w.useEffect(()=>()=>{p&&clearInterval(p)},[p]);const g=()=>{u(null),x.mutate()};return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:i.jsx(Mt,{className:"w-full max-w-md mx-4",children:i.jsxs(Dt,{children:[i.jsxs("div",{className:"flex items-start gap-3 mb-4",children:[i.jsx("div",{className:`p-2 rounded-full ${e.update_available?"bg-orange-500/20":"bg-status-ok/20"}`,children:e.update_available?i.jsx(pi,{className:"w-5 h-5 text-orange-400"}):i.jsx(fr,{className:"w-5 h-5 text-status-ok"})}),i.jsxs("div",{className:"flex-1",children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:e.update_available?r("printers.firmwareModal.title"):r("printers.firmwareModal.titleUpToDate")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:t.name})]})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3 mb-4",children:[i.jsxs("div",{className:"flex justify-between items-center text-sm",children:[i.jsx("span",{className:"text-bambu-gray",children:r("printers.firmwareModal.currentVersion")}),i.jsx("span",{className:`font-mono ${e.update_available?"text-white":"text-status-ok"}`,children:e.current_version||r("common.unknown")})]}),e.update_available&&i.jsxs("div",{className:"flex justify-between items-center text-sm mt-1",children:[i.jsx("span",{className:"text-bambu-gray",children:r("printers.firmwareModal.latestVersion")}),i.jsx("span",{className:"text-orange-400 font-mono",children:e.latest_version})]}),e.release_notes&&i.jsxs("details",{className:"mt-3 text-sm",open:!e.update_available,children:[i.jsx("summary",{className:`cursor-pointer hover:underline ${e.update_available?"text-orange-400":"text-status-ok"}`,children:r("printers.firmwareModal.releaseNotes")}),i.jsx("div",{className:"mt-2 text-bambu-gray text-xs max-h-40 overflow-y-auto whitespace-pre-wrap",children:e.release_notes})]})]}),e.update_available?v?i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-sm mb-4",children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),r("printers.firmwareModal.checkingPrereqs")]}):y&&!d&&!c?i.jsx("div",{className:"mb-4",children:y.can_proceed?i.jsxs("div",{className:"flex items-center gap-2 text-bambu-green text-sm",children:[i.jsx(ra,{className:"w-4 h-4"}),r("printers.firmwareModal.sdCardReady")]}):i.jsx("div",{className:"space-y-1",children:y.errors.map((_,N)=>i.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm",children:[i.jsx(Li,{className:"w-4 h-4 flex-shrink-0"}),_]},N))})}):null:null,(d||c)&&c&&i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center justify-between text-sm mb-1",children:[i.jsx("span",{className:"text-bambu-gray capitalize",children:c.status}),i.jsxs("span",{className:"text-white",children:[c.progress,"%"]})]}),i.jsx("div",{className:"w-full bg-bambu-dark-tertiary rounded-full h-2",children:i.jsx("div",{className:`h-2 rounded-full transition-all ${c.status==="error"?"bg-status-error":c.status==="complete"?"bg-status-ok":"bg-orange-500"} ${c.status==="uploading"?"animate-pulse":""}`,style:{width:`${c.progress}%`}})}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:c.message}),c.error&&i.jsx("p",{className:"text-xs text-red-400 mt-1",children:c.error})]}),c?.status==="complete"&&i.jsxs("div",{className:"bg-bambu-green/10 border border-bambu-green/30 rounded-lg p-3 mb-4",children:[i.jsx("p",{className:"text-sm text-bambu-green font-medium mb-2",children:r("printers.firmwareModal.uploadedSuccess")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:r("printers.firmwareModal.applyInstructions")}),i.jsxs("ol",{className:"text-xs text-bambu-gray mt-1 list-decimal list-inside space-y-1",children:[i.jsx("li",{dangerouslySetInnerHTML:{__html:r("printers.firmwareModal.step1")}}),i.jsx("li",{dangerouslySetInnerHTML:{__html:r("printers.firmwareModal.step2")}}),i.jsx("li",{dangerouslySetInnerHTML:{__html:r("printers.firmwareModal.step3")}}),i.jsx("li",{children:r("printers.firmwareModal.step4")})]})]}),i.jsxs("div",{className:"flex gap-2 justify-end",children:[i.jsx(Oe,{variant:"secondary",onClick:n,children:c?.status==="complete"?r("printers.firmwareModal.done"):r("common.cancel")}),y?.can_proceed&&!d&&c?.status!=="complete"&&l&&i.jsx(Oe,{onClick:g,disabled:x.isPending,children:x.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin mr-2"}),r("printers.firmwareModal.starting")]}):i.jsxs(i.Fragment,{children:[i.jsx(pi,{className:"w-4 h-4 mr-2"}),r("printers.firmwareModal.uploadFirmware")]})})]})]})})})}function dVe({printer:t,onClose:e}){const{t:n}=Ft(),r=an(),{showToast:a}=fn(),[s,o]=w.useState({name:t.name,ip_address:t.ip_address,access_code:"",model:t.model||"",location:t.location||"",auto_archive:t.auto_archive}),l=pt({mutationFn:u=>be.updatePrinter(t.id,u),onSuccess:()=>{r.invalidateQueries({queryKey:["printers"]}),r.invalidateQueries({queryKey:["printerStatus",t.id]}),e()},onError:u=>a(u.message||n("printers.toast.failedToUpdate"),"error")});w.useEffect(()=>{const u=d=>{d.key==="Escape"&&e()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[e]);const c=u=>{u.preventDefault();const d={name:s.name,ip_address:s.ip_address,model:s.model||void 0,location:s.location||void 0,auto_archive:s.auto_archive};s.access_code&&(d.access_code=s.access_code),l.mutate(d)};return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",onClick:e,children:i.jsx(Mt,{className:"w-full max-w-md",onClick:u=>u.stopPropagation(),children:i.jsxs(Dt,{children:[i.jsx("h2",{className:"text-xl font-semibold mb-4",children:n("printers.editPrinter")}),i.jsxs("form",{onSubmit:c,className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("printers.name")}),i.jsx("input",{type:"text",required:!0,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",value:s.name,onChange:u=>o({...s,name:u.target.value}),placeholder:n("printers.modal.myPrinter")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("printers.ipAddress")}),i.jsx("input",{type:"text",required:!0,pattern:"(\\d{1,3}(\\.\\d{1,3}){3}|[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?)*)",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",value:s.ip_address,onChange:u=>o({...s,ip_address:u.target.value}),placeholder:"192.168.1.100 or printer.local"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("printers.serialNumber")}),i.jsx("input",{type:"text",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",value:t.serial_number}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("printers.serialCannotBeChanged")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("printers.accessCode")}),i.jsx("input",{type:"password",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",value:s.access_code,onChange:u=>o({...s,access_code:u.target.value}),placeholder:n("printers.accessCodePlaceholder")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("printers.model")}),i.jsxs("select",{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",value:s.model,onChange:u=>o({...s,model:u.target.value}),children:[i.jsx("option",{value:"",children:n("printers.modal.selectModel")}),i.jsxs("optgroup",{label:"H2 Series",children:[i.jsx("option",{value:"H2C",children:"H2C"}),i.jsx("option",{value:"H2D",children:"H2D"}),i.jsx("option",{value:"H2D Pro",children:"H2D Pro"}),i.jsx("option",{value:"H2S",children:"H2S"})]}),i.jsxs("optgroup",{label:"X1 Series",children:[i.jsx("option",{value:"X1E",children:"X1E"}),i.jsx("option",{value:"X1C",children:"X1 Carbon"}),i.jsx("option",{value:"X1",children:"X1"})]}),i.jsxs("optgroup",{label:"P Series",children:[i.jsx("option",{value:"P2S",children:"P2S"}),i.jsx("option",{value:"P1S",children:"P1S"}),i.jsx("option",{value:"P1P",children:"P1P"})]}),i.jsxs("optgroup",{label:"A1 Series",children:[i.jsx("option",{value:"A1",children:"A1"}),i.jsx("option",{value:"A1 Mini",children:"A1 Mini"})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Location / Group"}),i.jsx("input",{type:"text",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",value:s.location,onChange:u=>o({...s,location:u.target.value}),placeholder:n("printers.modal.locationPlaceholder")}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("printers.locationHelp")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"checkbox",id:"edit_auto_archive",checked:s.auto_archive,onChange:u=>o({...s,auto_archive:u.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("label",{htmlFor:"edit_auto_archive",className:"text-sm text-bambu-gray",children:n("printers.modal.autoArchiveLabel")})]}),i.jsxs("div",{className:"flex gap-3 pt-4",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:n("common.cancel")}),i.jsx(Oe,{type:"submit",className:"flex-1",disabled:l.isPending,children:l.isPending?n("common.saving"):n("printers.modal.saveChanges")})]})]})]})})})}function mVe(t){const{data:e}=et({queryKey:["printerStatus",t],queryFn:()=>be.getPrinterStatus(t),refetchInterval:3e4});return!e?.connected}function hVe({printer:t,plug:e,onPowerOn:n,isPowering:r}){const a=mVe(t.id),{data:s}=et({queryKey:["smartPlugStatus",e.id],queryFn:()=>be.getSmartPlugStatus(e.id),refetchInterval:1e4});return a?i.jsxs("div",{className:"flex items-center justify-between px-3 py-2 hover:bg-gray-100 dark:hover:bg-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[i.jsx("span",{className:"text-sm text-gray-900 dark:text-white truncate",children:t.name}),s&&i.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${s.state==="ON"?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:s.state||"?"})]}),i.jsxs("button",{onClick:()=>n(e.id),disabled:r||s?.state==="ON",className:`px-2 py-1 text-xs rounded transition-colors flex items-center gap-1 ${s?.state==="ON"?"bg-bambu-green/20 text-bambu-green cursor-default":"bg-bambu-green/20 text-bambu-green hover:bg-bambu-green hover:text-white"}`,children:[i.jsx(Vd,{className:"w-3 h-3"}),r?"...":"On"]})]}):null}function pVe(){const{t}=Ft(),[e,n]=w.useState(!1),[r,a]=w.useState(()=>localStorage.getItem("hideDisconnectedPrinters")==="true"),[s,o]=w.useState(!1),[l,c]=w.useState(null),[u,d]=w.useState(()=>localStorage.getItem("printerSortBy")||"name"),[m,p]=w.useState(()=>localStorage.getItem("printerSortAsc")!=="false"),[f,y]=w.useState(()=>{const ne=localStorage.getItem("printerCardSize");return ne?parseInt(ne,10):2}),v=f===1?"compact":"expanded",x=an(),{showToast:g}=fn(),{hasPermission:_}=_r(),[N,T]=w.useState(()=>{const ne=localStorage.getItem("openEmbeddedCameras");if(ne)try{const O=JSON.parse(ne);return new Map(O.map(V=>[V.id,V]))}catch{return new Map}return new Map});w.useEffect(()=>{const ne=Array.from(N.values());ne.length>0?localStorage.setItem("openEmbeddedCameras",JSON.stringify(ne)):localStorage.removeItem("openEmbeddedCameras")},[N]);const{data:C,isLoading:A}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:k}=et({queryKey:["settings"],queryFn:be.getSettings}),R=w.useMemo(()=>{if(k?.drying_presets)try{const ne=JSON.parse(k.drying_presets);if(typeof ne=="object"&&ne!==null&&Object.keys(ne).length>0)return{...EF,...ne}}catch{}return EF},[k?.drying_presets]);w.useEffect(()=>{k?.camera_view_mode==="window"&&N.size>0&&T(new Map)},[k?.camera_view_mode,N.size]);const{data:P}=et({queryKey:["smart-plugs"],queryFn:be.getSmartPlugs}),{data:D}=et({queryKey:["maintenanceOverview"],queryFn:be.getMaintenanceOverview,staleTime:60*1e3}),{data:H}=et({queryKey:["spoolman-status"],queryFn:be.getSpoolmanStatus,staleTime:60*1e3}),z=H?.enabled&&H?.connected,{data:G}=et({queryKey:["spoolman-settings"],queryFn:be.getSpoolmanSettings,enabled:!!z,staleTime:60*1e3}),I=G?.spoolman_sync_mode,{data:ee}=et({queryKey:["unlinked-spools"],queryFn:be.getUnlinkedSpools,enabled:!!z,staleTime:30*1e3}),ie=ee&&ee.length>0,{data:X}=et({queryKey:["linked-spools"],queryFn:be.getLinkedSpools,enabled:!!z,staleTime:30*1e3}),me=X?.linked,{data:he}=et({queryKey:["spool-assignments"],queryFn:()=>be.getAssignments(),enabled:_("inventory:view_assignments"),staleTime:30*1e3}),ge=pt({mutationFn:({printerId:ne,amsId:O,trayId:V})=>be.unassignSpool(ne,O,V),onSuccess:()=>{x.invalidateQueries({queryKey:["spool-assignments"]})}}),Y=(ne,O,V)=>he?.find(J=>J.printer_id===ne&&J.ams_id===Number(O)&&J.tray_id===Number(V)),oe=D?.reduce((ne,O)=>(ne[O.printer_id]={due_count:O.due_count,warning_count:O.warning_count,total_print_hours:O.total_print_hours},ne),{})||{},le=P?.reduce((ne,O)=>(O.printer_id&&(ne[O.printer_id]=O),ne),{})||{},xe=pt({mutationFn:be.createPrinter,onSuccess:()=>{x.invalidateQueries({queryKey:["printers"]}),x.invalidateQueries({queryKey:["maintenanceOverview"]}),n(!1)},onError:ne=>g(ne.message||t("printers.toast.failedToAdd"),"error")}),Pe=pt({mutationFn:ne=>be.controlSmartPlug(ne,"on"),onSuccess:()=>{x.invalidateQueries({queryKey:["smart-plugs"]}),c(null)},onError:()=>{c(null)}}),q=()=>{const ne=!r;a(ne),localStorage.setItem("hideDisconnectedPrinters",String(ne))},Z=ne=>{d(ne),localStorage.setItem("printerSortBy",ne)},j=()=>{const ne=!m;p(ne),localStorage.setItem("printerSortAsc",String(ne))},E=()=>{switch(f){case 1:return"grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5";case 2:return"grid-cols-1 md:grid-cols-2 xl:grid-cols-3";case 3:return"grid-cols-1 lg:grid-cols-2";case 4:return"grid-cols-1";default:return"grid-cols-1 md:grid-cols-2 xl:grid-cols-3"}},U=["S","M","L","XL"],K=w.useMemo(()=>{if(!C)return[];const ne=[...C];switch(u){case"name":ne.sort((O,V)=>O.name.localeCompare(V.name));break;case"model":ne.sort((O,V)=>(O.model||"").localeCompare(V.model||""));break;case"location":ne.sort((O,V)=>{const J=O.location||"",W=V.location||"";return!J&&W?1:J&&!W?-1:J.localeCompare(W)||O.name.localeCompare(V.name)});break;case"status":ne.sort((O,V)=>{const J=x.getQueryData(["printerStatus",O.id]),W=x.getQueryData(["printerStatus",V.id]),re=ue=>ue?.connected?ue.state==="RUNNING"?0:1:2;return re(J)-re(W)});break}return m||ne.reverse(),ne},[C,u,m,x]),$=w.useMemo(()=>{if(u!=="location")return null;const ne={};return K.forEach(O=>{const V=O.location||"Ungrouped";ne[V]||(ne[V]=[]),ne[V].push(O)}),ne},[u,K]);return i.jsxs("div",{className:"p-4 md:p-8",children:[i.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6",children:[i.jsxs("div",{children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:t("printers.title")}),i.jsx(lVe,{printers:C})]}),i.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 flex-wrap",children:[i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsxs("select",{value:u,onChange:ne=>Z(ne.target.value),className:"text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg px-2 py-1.5 text-white focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"name",children:t("printers.sort.name")}),i.jsx("option",{value:"status",children:t("printers.sort.status")}),i.jsx("option",{value:"model",children:t("printers.sort.model")}),i.jsx("option",{value:"location",children:t("printers.sort.location")})]}),i.jsx("button",{onClick:j,className:"p-1.5 rounded-lg hover:bg-bambu-dark-tertiary transition-colors",title:t(m?"printers.sort.descending":"printers.sort.ascending"),children:m?i.jsx(yf,{className:"w-4 h-4 text-bambu-gray"}):i.jsx(tx,{className:"w-4 h-4 text-bambu-gray"})})]}),i.jsx("div",{className:"flex items-center bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:U.map((ne,O)=>{const V=O+1,J=f===V;return i.jsx("button",{onClick:()=>{y(V),localStorage.setItem("printerCardSize",String(V))},className:`px-2 py-1.5 text-xs font-medium transition-colors ${O===0?"rounded-l-lg":""} ${O===U.length-1?"rounded-r-lg":""} ${J?"bg-bambu-green text-white":"text-bambu-gray hover:bg-bambu-dark-tertiary hover:text-white"}`,title:t(ne==="S"?"printers.cardSize.small":ne==="M"?"printers.cardSize.medium":ne==="L"?"printers.cardSize.large":"printers.cardSize.extraLarge"),children:ne},ne)})}),i.jsx("div",{className:"w-px h-6 bg-bambu-dark-tertiary"}),i.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:r,onChange:q,className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),t("printers.hideOffline")]}),r&&Object.keys(le).length>0&&i.jsxs("div",{className:"relative",children:[i.jsxs("button",{onClick:()=>o(!s),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-white dark:bg-bambu-dark-secondary border border-gray-200 dark:border-bambu-dark-tertiary rounded-lg text-gray-600 dark:text-bambu-gray hover:text-gray-900 dark:hover:text-white hover:border-bambu-green transition-colors",children:[i.jsx(Vd,{className:"w-4 h-4"}),t("printers.powerOn"),i.jsx(Ln,{className:`w-3 h-3 transition-transform ${s?"rotate-180":""}`})]}),s&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>o(!1)}),i.jsxs("div",{className:"absolute right-0 mt-2 w-56 bg-white dark:bg-bambu-dark-secondary border border-gray-200 dark:border-bambu-dark-tertiary rounded-lg shadow-lg z-20 py-1",children:[i.jsx("div",{className:"px-3 py-2 text-xs text-gray-500 dark:text-bambu-gray border-b border-gray-200 dark:border-bambu-dark-tertiary",children:t("printers.offlinePrintersWithPlugs")}),C?.filter(ne=>le[ne.id]).map(ne=>i.jsx(hVe,{printer:ne,plug:le[ne.id],onPowerOn:O=>{c(O),Pe.mutate(O)},isPowering:l===le[ne.id]?.id},ne.id)),C?.filter(ne=>le[ne.id]).length===0&&i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No printers with smart plugs"})]})]})]}),i.jsxs(Oe,{onClick:()=>n(!0),disabled:!_("printers:create"),title:_("printers:create")?void 0:t("printers.permission.noAdd"),children:[i.jsx(ar,{className:"w-4 h-4"}),t("printers.addPrinter")]})]})]}),A?i.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("common.loading")}):C?.length===0?i.jsx(Mt,{children:i.jsxs(Dt,{className:"text-center py-12",children:[i.jsx("p",{className:"text-bambu-gray mb-4",children:t("printers.noPrintersConfigured")}),i.jsxs(Oe,{onClick:()=>n(!0),disabled:!_("printers:create"),title:_("printers:create")?void 0:t("printers.permission.noAdd"),children:[i.jsx(ar,{className:"w-4 h-4"}),t("printers.addPrinter")]})]})}):$?i.jsx("div",{className:"space-y-6",children:Object.entries($).map(([ne,O])=>i.jsxs("div",{children:[i.jsxs("h2",{className:"text-lg font-semibold text-white mb-3 flex items-center gap-2",children:[i.jsx("span",{className:"w-2 h-2 rounded-full bg-bambu-green"}),ne,i.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",O.length,")"]})]}),i.jsx("div",{className:`grid gap-4 ${f>=3?"gap-6":""} ${E()}`,children:O.map(V=>i.jsx(NW,{printer:V,hideIfDisconnected:r,maintenanceInfo:oe[V.id],viewMode:v,cardSize:f,amsThresholds:k?{humidityGood:Number(k.ams_humidity_good)||40,humidityFair:Number(k.ams_humidity_fair)||60,tempGood:Number(k.ams_temp_good)||28,tempFair:Number(k.ams_temp_fair)||35}:void 0,spoolmanEnabled:z,hasUnlinkedSpools:ie,linkedSpools:me,spoolmanUrl:H?.url,spoolmanSyncMode:I,onGetAssignment:Y,onUnassignSpool:(J,W,re)=>ge.mutate({printerId:J,amsId:W,trayId:re}),timeFormat:k?.time_format||"system",cameraViewMode:k?.camera_view_mode||"window",onOpenEmbeddedCamera:(J,W)=>T(re=>new Map(re).set(J,{id:J,name:W})),checkPrinterFirmware:k?.check_printer_firmware!==!1,dryingPresets:R},V.id))})]},ne))}):i.jsx("div",{className:`grid gap-4 ${f>=3?"gap-6":""} ${E()}`,children:K.map(ne=>i.jsx(NW,{printer:ne,hideIfDisconnected:r,maintenanceInfo:oe[ne.id],viewMode:v,cardSize:f,spoolmanEnabled:z,hasUnlinkedSpools:ie,linkedSpools:me,spoolmanUrl:H?.url,spoolmanSyncMode:I,onGetAssignment:Y,onUnassignSpool:(O,V,J)=>ge.mutate({printerId:O,amsId:V,trayId:J}),amsThresholds:k?{humidityGood:Number(k.ams_humidity_good)||40,humidityFair:Number(k.ams_humidity_fair)||60,tempGood:Number(k.ams_temp_good)||28,tempFair:Number(k.ams_temp_fair)||35}:void 0,timeFormat:k?.time_format||"system",cameraViewMode:k?.camera_view_mode||"window",onOpenEmbeddedCamera:(O,V)=>T(J=>new Map(J).set(O,{id:O,name:V})),checkPrinterFirmware:k?.check_printer_firmware!==!1,dryingPresets:R},ne.id))}),e&&i.jsx(cVe,{onClose:()=>n(!1),onAdd:ne=>xe.mutate(ne),existingSerials:C?.map(ne=>ne.serial_number)||[]}),Array.from(N.values()).map((ne,O)=>i.jsx(mMe,{printerId:ne.id,printerName:ne.name,viewerIndex:O,onClose:()=>T(V=>{const J=new Map(V);return J.delete(ne.id),J})},ne.id))]})}function fVe(){const t=navigator.userAgent.toLowerCase(),e=navigator.platform?.toLowerCase()||"";return t.includes("win")||e.includes("win")?"windows":t.includes("mac")||e.includes("mac")?"macos":t.includes("linux")||e.includes("linux")?"linux":"unknown"}function Qp(t,e="bambu_studio"){let n;e==="orcaslicer"?n=`orcaslicer://open?file=${t}`:fVe()==="macos"?n=`bambustudioopen://${encodeURIComponent(t)}`:n=`bambustudio://open?file=${t}`;const r=document.createElement("a");r.href=n,r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r)}const kW=768;function aie(){const[t,e]=w.useState(()=>typeof window<"u"?window.innerWidth{const n=window.matchMedia(`(max-width: ${kW-1}px)`),r=a=>{e(a.matches)};return e(n.matches),n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),t}function M4({archiveId:t,libraryFileId:e,title:n,fileType:r,onClose:a}){const{t:s}=Ft(),{data:o}=et({queryKey:["settings"],queryFn:be.getSettings}),l=o?.preferred_slicer||"bambu_studio",c=e!=null,[u,d]=w.useState(null),[m,p]=w.useState(null),[f,y]=w.useState(!0),[v,x]=w.useState(null),[g,_]=w.useState(!1),[N,T]=w.useState(null),[C,A]=w.useState(0),[k,R]=w.useState(!1),[P,D]=w.useState(null),[H,z]=w.useState(!1),[G,I]=w.useState(!1),ee=w.useRef(null),ie=w.useRef(null),X=10,me=160,he=240,ge=.35;w.useEffect(()=>{const ye=ae=>{ae.key==="Escape"&&a()};return window.addEventListener("keydown",ye),()=>window.removeEventListener("keydown",ye)},[a]),w.useEffect(()=>{if(y(!0),c){const ye=(r||"").toLowerCase(),ae=ye==="3mf"||ye==="stl",L=ye==="gcode"||ye==="3mf";p({has_model:ae,has_gcode:L,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),d(ae?"3d":L?"gcode":null),y(!1);return}if(!t){p(null),d(null),y(!1);return}be.getArchiveCapabilities(t).then(ye=>{p(ye),ye.has_model?d("3d"):ye.has_gcode&&d("gcode"),y(!1)}).catch(()=>{p({has_model:!0,has_gcode:!1,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),d("3d"),y(!1)})},[t,r,c]),w.useEffect(()=>{if(_(!0),T(null),A(0),c){const ye=(r||"").toLowerCase();if(!e||ye!=="3mf"){x(null),_(!1);return}be.getLibraryFilePlates(e).then(ae=>x(ae)).catch(()=>x(null)).finally(()=>_(!1));return}if(!t){x(null),_(!1);return}be.getArchivePlates(t).then(ye=>x(ye)).catch(()=>x(null)).finally(()=>_(!1))},[t,r,c,e]);const Y=w.useMemo(()=>v?.plates??[],[v]),oe=(v?.is_multi_plate??!1)&&Y.length>1,le=k&&oe,xe=N==null?null:Y.find(ye=>ye.index===N)??null,Pe=ye=>ye.object_count??ye.objects?.length??0,q=Y.reduce((ye,ae)=>ye+Pe(ae),0),Z=xe?Pe(xe):q,j=xe?s("modelViewer.plateNumber",{number:xe.index}):s("modelViewer.allPlates"),E=Y.length>0,U=w.useRef(null),K=w.useRef(null),[$,ne]=w.useState(10),[O,V]=w.useState(3),J=Y.length>$,W=Math.max(1,Math.ceil(Y.length/$)),re=J?Y.slice(C*$,(C+1)*$):Y;w.useEffect(()=>{if(!le){ne(10),V(3);return}const ye=U.current,ae=K.current;if(!ye||!ae)return;let L=0;const F=()=>{const pe=ae.clientWidth,Ne=Math.floor(pe/210),Se=Math.max(3,Math.min(5,Ne||3));V(ce=>ce===Se?ce:Se);const Le=window.getComputedStyle(ye),qe=Number.parseFloat(Le.rowGap||"0"),Te=ye.querySelector("button")?.getBoundingClientRect().height??44,Ae=ae.clientHeight,je=Math.max(1,Math.floor((Ae+qe)/(Te+qe)))*Se,Xe=Math.max(1,je-1);ne(ce=>ce===Xe?ce:Xe)},te=()=>{L&&cancelAnimationFrame(L),L=requestAnimationFrame(F)};te();const ve=new ResizeObserver(te);return ve.observe(ae),ve.observe(ye),()=>{L&&cancelAnimationFrame(L),ve.disconnect()}},[le,Y.length]),w.useEffect(()=>{if(!J){A(0);return}A(ye=>Math.min(ye,W-1))},[Y.length,J,W]),w.useEffect(()=>{if(!J||N==null)return;const ye=Y.findIndex(L=>L.index===N);if(ye<0)return;const ae=Math.floor(ye/$);A(L=>L===ae?L:ae)},[Y,$,N,J]),w.useEffect(()=>{if(!le){D(null),I(!1);return}if(G)return;const ye=ee.current,ae=ie.current;if(!ye||!ae)return;const L=ye.clientHeight;if(!L)return;const F=Math.max(he,L*ge),te=Math.max(me,L-X-F),ve=Math.min(ae.scrollHeight,te);D(Math.max(me,ve))},[le,G,Y.length,C,X,me,he,ge]),w.useEffect(()=>{if(!H)return;const ye=L=>{const F=ee.current;if(!F)return;const te=F.getBoundingClientRect(),ve=te.height;if(!ve)return;const pe=Math.max(he,ve*ge),de=Math.max(me,ve-X-pe),Ne=Math.min(de,Math.max(me,L.clientY-te.top));D(Ne)},ae=()=>{z(!1),I(!0)};return document.addEventListener("mousemove",ye),document.addEventListener("mouseup",ae),document.body.style.cursor="row-resize",document.body.style.userSelect="none",()=>{document.removeEventListener("mousemove",ye),document.removeEventListener("mouseup",ae),document.body.style.cursor="",document.body.style.userSelect=""}},[H,X,me,he,ge]);const ue=c?(r||"").toLowerCase()==="3mf":!0,fe=async()=>{if(!ue)return;const ye=n||"model";try{if(c){const{token:ae}=await be.createLibrarySlicerToken(e),L=be.getLibrarySlicerDownloadUrl(e,ae,ye);Qp(`${window.location.origin}${L}`,l)}else{const{token:ae}=await be.createArchiveSlicerToken(t),L=be.getArchiveSlicerDownloadUrl(t,ae,ye);Qp(`${window.location.origin}${L}`,l)}}catch{if(c){const ae=`${window.location.origin}${be.getLibraryFileDownloadUrl(e)}`;Qp(ae,l)}else{const ae=`${window.location.origin}${be.getArchiveForSlicer(t,ye)}`;Qp(ae,l)}}};return i.jsx("div",{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 ${k?"p-0":"p-8"}`,onClick:a,children:i.jsxs("div",{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary w-full flex flex-col ${k?"h-full max-w-none rounded-none":"h-[80vh] max-w-4xl rounded-xl"}`,onClick:ye=>ye.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1 mr-4",children:[i.jsx("h2",{className:"text-lg font-semibold text-white truncate",children:n}),E&&i.jsxs("span",{className:"text-xs text-bambu-gray bg-bambu-dark-tertiary/70 px-2 py-1 rounded whitespace-nowrap",children:[j,": ",s("modelViewer.objectCount",{count:Z})]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:fe,disabled:!ue,children:[i.jsx(Jr,{className:"w-4 h-4"}),s("modelViewer.openInSlicer")]}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>R(ye=>!ye),title:k?"Exit fullscreen":"Enter fullscreen",children:k?i.jsx(BL,{className:"w-4 h-4"}):i.jsx(eT,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:a,children:i.jsx(Ht,{className:"w-5 h-5"})})]})]}),m&&i.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary",children:[i.jsxs("button",{onClick:()=>m.has_model&&d("3d"),disabled:!m.has_model,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${u==="3d"?"text-bambu-green border-b-2 border-bambu-green":m.has_model?"text-bambu-gray hover:text-white":"text-bambu-gray/30 cursor-not-allowed"}`,children:[i.jsx(ra,{className:"w-4 h-4"}),s("modelViewer.tabs.model"),!m.has_model&&i.jsxs("span",{className:"text-xs",children:["(",s("modelViewer.notAvailable"),")"]})]}),i.jsxs("button",{onClick:()=>m.has_gcode&&d("gcode"),disabled:!m.has_gcode,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${u==="gcode"?"text-bambu-green border-b-2 border-bambu-green":m.has_gcode?"text-bambu-gray hover:text-white":"text-bambu-gray/30 cursor-not-allowed"}`,children:[i.jsx(cpe,{className:"w-4 h-4"}),s("modelViewer.tabs.gcode"),!m.has_gcode&&i.jsxs("span",{className:"text-xs",children:["(",s("modelViewer.notSliced"),")"]})]})]}),i.jsx("div",{className:"flex-1 overflow-hidden p-4",children:f?i.jsx("div",{className:"w-full h-full flex items-center justify-center",children:i.jsx(ht,{className:"w-8 h-8 animate-spin text-bambu-green"})}):u==="3d"&&m?i.jsxs("div",{ref:ee,className:`w-full h-full flex flex-col ${le?"gap-0 min-h-0":"gap-3"}`,children:[oe&&i.jsxs("div",{ref:ie,style:le&&P!=null?{height:P}:void 0,className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-3 ${le?"flex flex-col shrink-0":""}`,children:[i.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray mb-2",children:[i.jsx(Gi,{className:"w-4 h-4"}),s("modelViewer.plates"),g&&i.jsx(ht,{className:"w-3 h-3 animate-spin"})]}),i.jsxs("div",{className:le?"flex flex-col min-h-0 flex-1":void 0,children:[i.jsx("div",{ref:K,className:le?"min-h-0 overflow-hidden pr-1 flex-1":void 0,children:i.jsxs("div",{ref:U,className:le?"grid gap-2":"grid grid-cols-2 md:grid-cols-3 gap-2",style:le?{gridTemplateColumns:`repeat(${O}, minmax(0, 1fr))`}:void 0,children:[i.jsxs("button",{type:"button",onClick:()=>T(null),className:`flex items-center rounded-lg border text-left transition-colors ${le?"gap-1.5 p-1.5 w-full":"gap-2 p-2"} ${N==null?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray"}`,children:[i.jsx("div",{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${le?"w-8 h-8":"w-10 h-10"}`,children:i.jsx(Gi,{className:`${le?"w-4 h-4":"w-5 h-5"} text-bambu-gray`})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:`${le?"text-xs":"text-sm"} text-white font-medium truncate`,children:s("modelViewer.allPlates")}),i.jsx("p",{className:`${le?"text-[10px]":"text-xs"} text-bambu-gray truncate`,children:s("modelViewer.plateCount",{count:Y.length})})]}),N==null&&i.jsx(Yr,{className:`${le?"w-3.5 h-3.5":"w-4 h-4"} text-bambu-green flex-shrink-0`})]}),re.map(ye=>i.jsxs("button",{type:"button",onClick:()=>T(ye.index),className:`flex items-center rounded-lg border text-left transition-colors ${le?"gap-1.5 p-1.5 w-full":"gap-2 p-2"} ${N===ye.index?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray"}`,children:[ye.has_thumbnail&&ye.thumbnail_url?i.jsx("img",{src:ye.thumbnail_url,alt:`Plate ${ye.index}`,className:`${le?"w-8 h-8":"w-10 h-10"} rounded object-cover bg-bambu-dark-tertiary`}):i.jsx("div",{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${le?"w-8 h-8":"w-10 h-10"}`,children:i.jsx(Gi,{className:`${le?"w-4 h-4":"w-5 h-5"} text-bambu-gray`})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:`${le?"text-xs":"text-sm"} text-white font-medium truncate`,children:ye.name||s("modelViewer.plateNumber",{number:ye.index})}),i.jsx("p",{className:`${le?"text-[10px]":"text-xs"} text-bambu-gray truncate`,children:s("modelViewer.objectCount",{count:ye.object_count??ye.objects?.length??0})})]}),N===ye.index&&i.jsx(Yr,{className:`${le?"w-3.5 h-3.5":"w-4 h-4"} text-bambu-green flex-shrink-0`})]},ye.index))]})}),(xe||J)&&i.jsxs("div",{className:"mt-auto pt-3 flex items-center gap-4 text-xs text-bambu-gray overflow-x-auto",children:[xe&&i.jsxs("div",{className:"flex items-center gap-3 whitespace-nowrap",children:[i.jsx("span",{children:s("modelViewer.plateNumber",{number:xe.index})}),xe.print_time_seconds!=null&&i.jsx("span",{children:s("modelViewer.eta",{minutes:Math.round(xe.print_time_seconds/60)})}),xe.filament_used_grams!=null&&i.jsxs("span",{children:[xe.filament_used_grams.toFixed(1)," g"]}),xe.filaments.length>0&&i.jsx("span",{children:s("modelViewer.filamentCount",{count:xe.filaments.length})})]}),J&&i.jsxs("div",{className:`flex items-center gap-2 whitespace-nowrap ${xe?"ml-auto":""}`,children:[i.jsx("span",{children:s("modelViewer.pagination.pageOf",{current:C+1,total:W})}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("button",{type:"button",onClick:()=>A(ye=>Math.max(ye-1,0)),disabled:C===0,className:`px-2 py-1 rounded border text-xs ${C===0?"border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed":"border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray"}`,children:s("modelViewer.pagination.prev")}),(()=>{let ae=Math.max(0,C-Math.floor(2.5));const L=Math.min(W,ae+5);L-ae<5&&(ae=Math.max(0,L-5));const F=Array.from({length:L-ae},(te,ve)=>ae+ve);return i.jsxs(i.Fragment,{children:[ae>0&&i.jsx("button",{type:"button",onClick:()=>A(0),className:`px-2 py-1 rounded border text-xs ${C===0?"border-bambu-green text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray"}`,children:"1"}),ae>1&&i.jsx("span",{className:"px-1",children:"…"}),F.map(te=>i.jsx("button",{type:"button",onClick:()=>A(te),className:`px-2 py-1 rounded border text-xs ${C===te?"border-bambu-green text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray"}`,children:te+1},te)),LA(W-1),className:`px-2 py-1 rounded border text-xs ${C===W-1?"border-bambu-green text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray"}`,children:W})]})})(),i.jsx("button",{type:"button",onClick:()=>A(ye=>Math.min(ye+1,W-1)),disabled:C>=W-1,className:`px-2 py-1 rounded border text-xs ${C>=W-1?"border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed":"border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray"}`,children:s("modelViewer.pagination.next")})]})]})]})]})]}),le&&i.jsx("div",{role:"separator","aria-orientation":"horizontal",onMouseDown:ye=>{ye.preventDefault(),z(!0),I(!0)},className:`h-2 cursor-row-resize flex items-center justify-center ${H?"bg-bambu-dark-tertiary":"bg-bambu-dark-secondary/60 hover:bg-bambu-dark-tertiary"}`,children:i.jsx("div",{className:"w-12 h-1 rounded-full bg-bambu-gray/50"})}),i.jsx("div",{className:`flex-1 ${le?"min-h-0":""}`,children:i.jsx(XQ,{url:c?be.getLibraryFileDownloadUrl(e):m.has_source?be.getSource3mfDownloadUrl(t):be.getArchiveDownload(t),fileType:r,buildVolume:m.build_volume,filamentColors:m.filament_colors,selectedPlateId:N,className:"w-full h-full"})})]}):u==="gcode"&&m?i.jsx(jZ,{gcodeUrl:c?be.getLibraryFileGcodeUrl(e):be.getArchiveGcode(t),filamentColors:m.filament_colors,className:"w-full h-full"}):i.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:s("modelViewer.noPreview")})})]})})}function gVe({onClose:t,initialFiles:e}){const{t:n}=Ft(),r=an(),{showToast:a}=fn(),s=w.useRef(null),[o,l]=w.useState(()=>e?.filter(C=>C.name.endsWith(".3mf")).map(C=>({file:C,status:"pending"}))||[]),[c,u]=w.useState(!1),[d,m]=w.useState(null);w.useEffect(()=>{const C=A=>{A.key==="Escape"&&t()};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[t]);const p=pt({mutationFn:C=>be.uploadArchivesBulk(C),onSuccess:C=>{m(C),r.invalidateQueries({queryKey:["archives"]}),r.invalidateQueries({queryKey:["archiveStats"]}),l(A=>A.map(k=>{const R=C.results.find(D=>D.filename===k.file.name),P=C.errors.find(D=>D.filename===k.file.name);return R?{...k,status:"success",archiveId:R.id}:P?{...k,status:"error",error:P.error}:k})),C.failed===0?a(`${C.uploaded} file${C.uploaded!==1?"s":""} uploaded`):C.uploaded===0?a(`Failed to upload ${C.failed} file${C.failed!==1?"s":""}`,"error"):a(`${C.uploaded} uploaded, ${C.failed} failed`,"warning")},onError:()=>{l(C=>C.map(A=>({...A,status:"error",error:"Upload failed"}))),a("Upload failed","error")}}),f=w.useCallback(C=>{C.preventDefault(),u(!0)},[]),y=w.useCallback(C=>{C.preventDefault(),u(!1)},[]),v=w.useCallback(C=>{C.preventDefault(),u(!1);const A=Array.from(C.dataTransfer.files).filter(k=>k.name.endsWith(".3mf"));A.length>0&&l(k=>[...k,...A.map(R=>({file:R,status:"pending"}))])},[]),x=w.useCallback(C=>{const A=Array.from(C.target.files||[]).filter(k=>k.name.endsWith(".3mf"));A.length>0&&l(k=>[...k,...A.map(R=>({file:R,status:"pending"}))]),s.current&&(s.current.value="")},[]),g=w.useCallback(C=>{l(A=>A.filter((k,R)=>R!==C))},[]),_=()=>{if(o.length===0)return;const C=o.filter(A=>A.status==="pending");C.length!==0&&(l(A=>A.map(k=>k.status==="pending"?{...k,status:"uploading"}:k)),p.mutate(C.map(A=>A.file)))},N=o.filter(C=>C.status==="pending").length,T=p.isPending;return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:i.jsx(Mt,{className:"w-full max-w-2xl max-h-[90vh] flex flex-col",children:i.jsxs(Dt,{className:"p-0 flex flex-col h-full",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsx("h2",{className:"text-xl font-semibold text-white",children:n("uploadModal.title")}),i.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsx("div",{className:"p-4",children:i.jsxs("div",{className:`border-2 border-dashed rounded-lg p-8 text-center transition-colors ${c?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,onDragOver:f,onDragLeave:y,onDrop:v,children:[i.jsx(xi,{className:"w-12 h-12 mx-auto mb-4 text-bambu-gray"}),i.jsx("p",{className:"text-white mb-2",children:n("uploadModal.dragDrop")}),i.jsx("p",{className:"text-bambu-gray text-sm mb-4",children:n("uploadModal.or")}),i.jsx(Oe,{variant:"secondary",onClick:()=>s.current?.click(),disabled:T,children:n("uploadModal.browseFiles")}),i.jsx("input",{ref:s,type:"file",accept:".3mf",multiple:!0,className:"hidden",onChange:x})]})}),i.jsx("div",{className:"px-4 pb-4",children:i.jsx("p",{className:"text-xs text-bambu-gray",children:n("uploadModal.extractionInfo")})}),o.length>0&&i.jsx("div",{className:"px-4 pb-4 max-h-60 overflow-y-auto",children:i.jsx("div",{className:"space-y-2",children:o.map((C,A)=>i.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg",children:[i.jsx(XC,{className:"w-5 h-5 text-bambu-gray flex-shrink-0"}),i.jsx("span",{className:"flex-1 text-white text-sm truncate",children:C.file.name}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:[(C.file.size/(1024*1024)).toFixed(1)," MB"]}),C.status==="pending"&&i.jsx("button",{onClick:()=>g(A),className:"text-bambu-gray hover:text-red-400 transition-colors",disabled:T,children:i.jsx(Ht,{className:"w-4 h-4"})}),C.status==="uploading"&&i.jsx(ht,{className:"w-4 h-4 text-bambu-green animate-spin"}),C.status==="success"&&i.jsx(fr,{className:"w-4 h-4 text-bambu-green"}),C.status==="error"&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-xs text-red-400",children:C.error}),i.jsx(Li,{className:"w-4 h-4 text-red-400"})]})]},`${C.file.name}-${A}`))})}),d&&i.jsx("div",{className:"px-4 pb-4",children:i.jsx("div",{className:"p-3 bg-bambu-dark rounded-lg",children:i.jsxs("p",{className:"text-sm text-white",children:[i.jsx("span",{className:"text-bambu-green",children:d.uploaded})," ",n("uploadModal.uploaded"),d.failed>0&&i.jsxs(i.Fragment,{children:[", ",i.jsx("span",{className:"text-red-400",children:d.failed})," ",n("uploadModal.failed")]})]})})}),i.jsxs("div",{className:"flex gap-3 p-4 border-t border-bambu-dark-tertiary",children:[i.jsx(Oe,{variant:"secondary",onClick:t,className:"flex-1",children:n(d?"common.close":"common.cancel")}),!d&&i.jsx(Oe,{onClick:_,disabled:N===0||T,className:"flex-1",children:T?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),n("uploadModal.uploading")]}):i.jsxs(i.Fragment,{children:[i.jsx(xi,{className:"w-4 h-4"}),n("uploadModal.upload")," ",N>0&&`(${N})`]})})]})]})})})}const bVe=["adhesionFailure","spaghettiDetached","layerShift","cloggedNozzle","filamentRunout","warping","stringing","underExtrusion","powerFailure","userCancelled","other"],xVe=["completed","failed","aborted","printing"];function sie({archive:t,onClose:e,existingTags:n=[]}){const{t:r}=Ft();w.useEffect(()=>{const E=U=>{U.key==="Escape"&&e()};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[e]);const a=an(),[s,o]=w.useState(t.print_name||""),[l,c]=w.useState(t.printer_id),[u,d]=w.useState(t.project_id??null),[m,p]=w.useState(t.notes||""),[f,y]=w.useState(t.tags||""),[v,x]=w.useState(t.failure_reason||""),[g,_]=w.useState(t.status),[N,T]=w.useState(t.quantity??1),[C,A]=w.useState(t.photos||[]),[k,R]=w.useState(t.external_url||""),[P,D]=w.useState(!1),[H,z]=w.useState(!1),G=w.useRef(null),I=w.useRef(null),ee=w.useRef(null),{data:ie}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:X}=et({queryKey:["projects"],queryFn:()=>be.getProjects()}),{data:me}=et({queryKey:["tags"],queryFn:be.getTags,enabled:n.length===0}),he=n.length>0?n:me?.map(E=>E.name)||[],ge=f.split(",").map(E=>E.trim()).filter(Boolean),Y=f.includes(",")?f.substring(f.lastIndexOf(",")+1).trim().toLowerCase():f.trim().toLowerCase(),oe=he.filter(E=>!ge.includes(E)&&(Y===""||E.toLowerCase().includes(Y))),le=E=>{let U;if(Y&&!he.includes(Y)?U=f.includes(",")?f.substring(0,f.lastIndexOf(",")).split(",").map(K=>K.trim()).filter(Boolean):[]:U=ge,!U.includes(E)){const K=[...U,E].join(", ");y(K)}ee.current!==null&&clearTimeout(ee.current),G.current?.focus()},xe=E=>{const U=ge.filter(K=>K!==E).join(", ");y(U)},Pe=pt({mutationFn:E=>be.updateArchive(t.id,E),onSuccess:()=>{a.invalidateQueries({queryKey:["archives"]}),a.invalidateQueries({queryKey:["projects"]}),e()}}),q=async E=>{const U=E.target.files?.[0];if(U){D(!0);try{const K=await be.uploadArchivePhoto(t.id,U);A(K.photos),a.invalidateQueries({queryKey:["archives"]})}catch(K){console.error("Failed to upload photo:",K)}finally{D(!1),I.current&&(I.current.value="")}}},Z=async E=>{try{const U=await be.deleteArchivePhoto(t.id,E);A(U.photos||[]),a.invalidateQueries({queryKey:["archives"]})}catch(U){console.error("Failed to delete photo:",U)}},j=E=>{E.preventDefault();const U={print_name:s||void 0,printer_id:l,project_id:u,notes:m||void 0,tags:f||void 0,quantity:N,external_url:k||null};g!==t.status&&(U.status=g),g==="failed"||g==="aborted"?U.failure_reason=v||void 0:(t.status==="failed"||t.status==="aborted")&&(U.failure_reason=null),Pe.mutate(U)};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:i.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:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:r("editArchive.title")}),i.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:j,className:"p-6 space-y-4 overflow-y-auto flex-1",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("editArchive.name")}),i.jsx("input",{type:"text",value:s,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 focus:border-bambu-green focus:outline-none",placeholder:r("editArchive.namePlaceholder")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("editArchive.printer")}),i.jsxs("select",{value:l??"",onChange:E=>c(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:[i.jsx("option",{value:"",children:r("editArchive.noPrinter")}),ie?.map(E=>i.jsx("option",{value:E.id,children:E.name},E.id))]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i.jsx(fs,{className:"w-4 h-4 inline mr-1"}),r("editArchive.project")]}),i.jsxs("select",{value:u??"",onChange:E=>d(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:[i.jsx("option",{value:"",children:r("editArchive.noProject")}),X?.map(E=>i.jsx("option",{value:E.id,children:E.name},E.id))]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i.jsx(gfe,{className:"w-4 h-4 inline mr-1"}),r("editArchive.itemsPrinted")]}),i.jsx("input",{type:"number",min:1,value:N,onChange:E=>T(Math.max(1,parseInt(E.target.value)||1)),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:"1"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:r("editArchive.itemsPrintedHelp")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("editArchive.notes")}),i.jsx("textarea",{value:m,onChange:E=>p(E.target.value),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 resize-none",placeholder:r("editArchive.notesPlaceholder")})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i.jsx(Ox,{className:"w-4 h-4 inline mr-1"}),r("editArchive.externalLink")]}),i.jsx("input",{type:"url",value:k,onChange:E=>R(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",placeholder:"https://printables.com/model/..."}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:r("editArchive.externalLinkHelp")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("editArchive.tags")}),ge.length>0&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:ge.map(E=>i.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 bg-bambu-dark-tertiary rounded text-sm text-white",children:[i.jsx(Dd,{className:"w-3 h-3"}),E,i.jsx("button",{type:"button",onClick:()=>xe(E),className:"ml-0.5 text-bambu-gray hover:text-white",children:i.jsx(Ht,{className:"w-3 h-3"})})]},E))}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{ref:G,type:"text",value:f,onChange:E=>y(E.target.value),onFocus:()=>{ee.current!==null&&clearTimeout(ee.current),z(!0)},onBlur:()=>{ee.current=window.setTimeout(()=>z(!1),200)},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:ge.length>0?r("editArchive.addMoreTags"):r("editArchive.tagsPlaceholder")}),H&&oe.length>0&&i.jsxs("div",{className:"absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-10 max-h-40 overflow-y-auto",children:[i.jsxs("div",{className:"p-2 text-xs text-bambu-gray border-b border-bambu-dark-tertiary",children:[Y?r("editArchive.matchingTags",{query:Y}):r("editArchive.existingTags")," ",r("editArchive.clickToAdd")]}),i.jsx("div",{className:"p-2 flex flex-wrap gap-1.5",children:oe.map(E=>i.jsx("button",{type:"button",onClick:()=>le(E),className:"px-2 py-0.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded text-sm text-bambu-gray hover:text-white transition-colors",children:E},E))})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("editArchive.status")}),i.jsx("select",{value:g,onChange:E=>{_(E.target.value),E.target.value==="completed"&&x("")},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:xVe.map(E=>i.jsx("option",{value:E,children:r(`editArchive.statuses.${E}`)},E))})]}),(g==="failed"||g==="aborted")&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("editArchive.failureReason")}),i.jsxs("select",{value:v,onChange:E=>x(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:[i.jsx("option",{value:"",children:r("editArchive.selectReason")}),bVe.map(E=>i.jsx("option",{value:r(`editArchive.failureReasons.${E}`),children:r(`editArchive.failureReasons.${E}`)},E))]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i.jsx(rx,{className:"w-4 h-4 inline mr-1"}),r("editArchive.photos")]}),i.jsxs("div",{className:"flex flex-wrap gap-2 mb-2",children:[C.map(E=>i.jsxs("div",{className:"relative group",children:[i.jsx("img",{src:be.getArchivePhotoUrl(t.id,E),alt:r("editArchive.printResult"),className:"w-20 h-20 object-cover rounded-lg border border-bambu-dark-tertiary"}),i.jsx("button",{type:"button",onClick:()=>Z(E),className:"absolute -top-1 -right-1 p-1 bg-red-500 rounded-full opacity-0 group-hover:opacity-100 transition-opacity",children:i.jsx(Jt,{className:"w-3 h-3 text-white"})})]},E)),i.jsxs("label",{className:"w-20 h-20 flex items-center justify-center border-2 border-dashed border-bambu-dark-tertiary rounded-lg cursor-pointer hover:border-bambu-green transition-colors",children:[i.jsx("input",{ref:I,type:"file",accept:"image/jpeg,image/png,image/webp",onChange:q,className:"hidden",disabled:P}),P?i.jsx(ht,{className:"w-6 h-6 text-bambu-gray animate-spin"}):i.jsx(ar,{className:"w-6 h-6 text-bambu-gray"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:r("editArchive.photosHelp")})]}),i.jsxs("div",{className:"flex gap-3 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:r("common.cancel")}),i.jsxs(Oe,{type:"submit",disabled:Pe.isPending,className:"flex-1",children:[i.jsx(ts,{className:"w-4 h-4"}),Pe.isPending?r("common.saving"):r("common.save")]})]})]})]})})}function oie({x:t,y:e,items:n,onClose:r}){const a=w.useRef(null),[s,o]=w.useState(null),l=w.useRef(null),[c,u]=w.useState({x:t,y:e,visible:!1}),[d,m]=w.useState(!1),[p,f]=w.useState({});w.useEffect(()=>{const x=N=>{a.current&&!a.current.contains(N.target)&&r()},g=N=>{N.key==="Escape"&&r()},_=()=>{r()};return document.addEventListener("mousedown",x),document.addEventListener("keydown",g),document.addEventListener("scroll",_,!0),()=>{document.removeEventListener("mousedown",x),document.removeEventListener("keydown",g),document.removeEventListener("scroll",_,!0),l.current&&clearTimeout(l.current)}},[r]),w.useLayoutEffect(()=>{if(a.current){a.current.style.visibility="hidden",a.current.style.display="block";const x=a.current.getBoundingClientRect(),g=window.innerWidth,_=window.innerHeight,N=8;let T=t,C=e;t+x.width>g-N&&(T=Math.max(N,g-x.width-N)),T_-N&&(C=Math.max(N,_-x.height-N)),CA),u({x:T,y:C,visible:!0})}},[t,e]);const y=(x,g)=>{l.current&&(clearTimeout(l.current),l.current=null);const _=g.getBoundingClientRect(),N=window.innerHeight,T=300,k=N-_.top-8T;f(R=>({...R,[x]:k?"bottom":"top"})),o(x)},v=()=>{l.current=window.setTimeout(()=>{o(null)},150)};return i.jsx("div",{ref:a,className:"fixed z-50 min-w-[180px] max-w-[280px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1",style:{left:c.x,top:c.y,visibility:c.visible?"visible":"hidden"},children:n.map((x,g)=>{if(x.divider)return i.jsx("div",{className:"my-1 border-t border-bambu-dark-tertiary"},g);const _=x.submenu&&x.submenu.length>0;return i.jsxs("div",{className:"relative",onMouseEnter:N=>_&&y(g,N.currentTarget),onMouseLeave:()=>_&&v(),children:[i.jsxs("button",{onMouseEnter:N=>_&&y(g,N.currentTarget.parentElement),onClick:()=>{_?o(s===g?null:g):x.disabled||(x.onClick(),r())},disabled:x.disabled,title:x.title,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${x.disabled?"text-bambu-gray cursor-not-allowed":x.danger?"text-red-400 hover:bg-red-400/10":"text-white hover:bg-bambu-dark-tertiary"} ${_&&s===g?"bg-bambu-dark-tertiary":""}`,children:[x.icon&&i.jsx("span",{className:"w-4 h-4 flex-shrink-0 flex items-center justify-center",children:x.icon}),i.jsx("span",{className:"flex-1",children:x.label}),_&&i.jsx(ha,{className:"w-4 h-4 text-bambu-gray"})]}),_&&s===g&&i.jsx("div",{className:`absolute min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 overflow-hidden max-h-[300px] overflow-y-auto z-[60] ${d?"right-full mr-1":"left-full ml-1"} ${p[g]==="bottom"?"bottom-0":"top-0"}`,onMouseEnter:()=>{l.current&&(clearTimeout(l.current),l.current=null)},onMouseLeave:()=>v(),children:x.submenu.map((N,T)=>i.jsxs("button",{onClick:()=>{N.disabled||(N.onClick(),r())},disabled:N.disabled,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${N.disabled?"text-bambu-gray cursor-not-allowed":N.danger?"text-red-400 hover:bg-red-400/10":"text-white hover:bg-bambu-dark-tertiary"}`,children:[N.icon&&i.jsx("span",{className:"w-4 h-4 flex-shrink-0 flex items-center justify-center",children:N.icon}),N.label]},T))})]},g)})})}function yVe({selectedIds:t,existingTags:e,onClose:n}){const r=an(),{showToast:a}=fn(),[s,o]=w.useState(""),[l,c]=w.useState(new Set),[u,d]=w.useState("add");w.useEffect(()=>{const v=x=>{x.key==="Escape"&&n()};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[n]);const m=pt({mutationFn:async()=>{const v=Array.from(l);let x=0;for(const g of t)try{const _=await be.getArchive(g),N=_.tags?_.tags.split(",").map(C=>C.trim()).filter(Boolean):[];let T;u==="add"?T=[...new Set([...N,...v])]:T=N.filter(C=>!l.has(C)),await be.updateArchive(g,{tags:T.join(", ")}),x++}catch(_){throw console.error(`Failed to update archive ${g}:`,_),new Error(`Failed on archive ${g}: ${_ instanceof Error?_.message:"Unknown error"}`)}return{count:x,mode:u,tags:v}},onSuccess:({count:v,mode:x,tags:g})=>{r.invalidateQueries({queryKey:["archives"]}),a(`${x==="add"?"Added":"Removed"} ${g.length} tag${g.length!==1?"s":""} ${x==="add"?"to":"from"} ${v} archive${v!==1?"s":""}`),n()},onError:v=>{a(v.message||"Failed to update tags","error")}}),p=v=>{c(x=>{const g=new Set(x);return g.has(v)?g.delete(v):g.add(v),g})},f=()=>{s.trim()&&!l.has(s.trim())&&(c(v=>new Set([...v,s.trim()])),o(""))},y=v=>{v.key==="Enter"&&(v.preventDefault(),f())};return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:i.jsx(Mt,{className:"w-full max-w-md",children:i.jsxs(Dt,{className:"p-0",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Dd,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-xl font-semibold text-white",children:u==="add"?"Add Tags":"Remove Tags"})]}),i.jsx("button",{onClick:n,className:"text-bambu-gray hover:text-white transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsxs("p",{className:"text-sm text-bambu-gray",children:[u==="add"?"Add":"Remove"," tags for ",t.length," selected archive",t.length!==1?"s":""]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Oe,{size:"sm",variant:u==="add"?"primary":"secondary",onClick:()=>d("add"),children:"Add Tags"}),i.jsx(Oe,{size:"sm",variant:u==="remove"?"primary":"secondary",onClick:()=>d("remove"),children:"Remove Tags"})]}),u==="add"&&i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"text",placeholder:"Enter new tag...",className:"flex-1 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",value:s,onChange:v=>o(v.target.value),onKeyDown:y}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:f,disabled:!s.trim(),children:i.jsx(ar,{className:"w-4 h-4"})})]}),e.length>0&&i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:"Existing tags:"}),i.jsx("div",{className:"flex flex-wrap gap-2",children:e.map(v=>i.jsx("button",{onClick:()=>p(v),className:`px-2 py-1 rounded text-sm transition-colors ${l.has(v)?"bg-bambu-green text-white":"bg-bambu-dark-tertiary text-bambu-gray-light hover:bg-bambu-dark"}`,children:v},v))})]}),l.size>0&&i.jsxs("div",{children:[i.jsxs("p",{className:"text-xs text-bambu-gray mb-2",children:["Tags to ",u==="add"?"add":"remove",":"]}),i.jsx("div",{className:"flex flex-wrap gap-2",children:Array.from(l).map(v=>i.jsxs("span",{className:`px-2 py-1 rounded text-sm flex items-center gap-1 ${u==="add"?"bg-green-500/20 text-green-400":"bg-red-500/20 text-red-400"}`,children:[v,i.jsx("button",{onClick:()=>p(v),className:"hover:opacity-70",children:i.jsx(Ht,{className:"w-3 h-3"})})]},v))})]})]}),i.jsxs("div",{className:"flex gap-3 p-4 border-t border-bambu-dark-tertiary",children:[i.jsx(Oe,{variant:"secondary",onClick:n,className:"flex-1",children:"Cancel"}),i.jsx(Oe,{onClick:()=>m.mutate(),disabled:l.size===0||m.isPending,className:"flex-1",children:m.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),"Processing..."]}):i.jsxs(i.Fragment,{children:[i.jsx(Dd,{className:"w-4 h-4"}),u==="add"?"Add Tags":"Remove Tags"]})})]})]})})})}function vVe({selectedIds:t,onClose:e}){const n=an(),{showToast:r}=fn(),{data:a,isLoading:s}=et({queryKey:["projects"],queryFn:()=>be.getProjects()});w.useEffect(()=>{const d=m=>{m.key==="Escape"&&e()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[e]);const o=()=>{n.invalidateQueries({queryKey:["archives"]}),n.invalidateQueries({queryKey:["projects"]}),n.invalidateQueries({queryKey:["project"]}),n.invalidateQueries({queryKey:["project-archives"]})},l=pt({mutationFn:async d=>(await be.addArchivesToProject(d,t),d),onSuccess:d=>{const m=a?.find(p=>p.id===d);o(),r(`Added ${t.length} archive${t.length!==1?"s":""} to "${m?.name}"`),e()},onError:()=>{r("Failed to assign project","error")}}),c=pt({mutationFn:async()=>{for(const d of t)await be.updateArchive(d,{project_id:null});return t.length},onSuccess:d=>{o(),r(`Removed ${d} archive${d!==1?"s":""} from project`),e()},onError:()=>{r("Failed to remove from project","error")}}),u=l.isPending||c.isPending;return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:i.jsx(Mt,{className:"w-full max-w-md max-h-[80vh] flex flex-col",children:i.jsxs(Dt,{className:"p-0 flex flex-col min-h-0",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(fs,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-xl font-semibold text-white",children:"Assign to Project"})]}),i.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",disabled:u,children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"p-4 space-y-3 overflow-y-auto min-h-0",children:[i.jsxs("p",{className:"text-sm text-bambu-gray",children:["Assign ",t.length," selected archive",t.length!==1?"s":""," to a project"]}),s?i.jsx("div",{className:"flex items-center justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 animate-spin text-bambu-gray"})}):i.jsxs("div",{className:"space-y-2",children:[i.jsxs("button",{onClick:()=>c.mutate(),disabled:u,className:"w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary transition-colors text-left disabled:opacity-50",children:[i.jsx("div",{className:"w-8 h-8 rounded-full bg-red-500/20 flex items-center justify-center shrink-0",children:i.jsx(Vi,{className:"w-4 h-4 text-red-400"})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"text-white font-medium",children:"Remove from project"}),i.jsx("p",{className:"text-sm text-bambu-gray truncate",children:"Clear project assignment"})]}),c.isPending&&i.jsx(ht,{className:"w-4 h-4 animate-spin text-bambu-gray shrink-0"})]}),a&&a.length>0&&i.jsxs("div",{className:"flex items-center gap-2 py-2",children:[i.jsx("div",{className:"flex-1 h-px bg-bambu-dark-tertiary"}),i.jsx("span",{className:"text-xs text-bambu-gray",children:"or assign to"}),i.jsx("div",{className:"flex-1 h-px bg-bambu-dark-tertiary"})]}),a?.map(d=>i.jsxs("button",{onClick:()=>l.mutate(d.id),disabled:u,className:"w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary transition-colors text-left disabled:opacity-50",children:[i.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center shrink-0",style:{backgroundColor:d.color?`${d.color}20`:"rgb(var(--bambu-green) / 0.2)"},children:i.jsx(fs,{className:"w-4 h-4",style:{color:d.color||"rgb(var(--bambu-green))"}})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"text-white font-medium truncate",children:d.name}),i.jsxs("p",{className:"text-sm text-bambu-gray truncate",children:[d.archive_count," archive",d.archive_count!==1?"s":"",d.status&&` • ${d.status}`]})]}),l.isPending&&l.variables===d.id&&i.jsx(ht,{className:"w-4 h-4 animate-spin text-bambu-gray shrink-0"})]},d.id)),(!a||a.length===0)&&i.jsx("p",{className:"text-center text-bambu-gray py-4",children:"No projects yet. Create one from the Projects page."})]})]}),i.jsx("div",{className:"flex gap-3 p-4 border-t border-bambu-dark-tertiary shrink-0",children:i.jsx(Oe,{variant:"secondary",onClick:e,className:"flex-1",disabled:u,children:"Cancel"})})]})})})}function wVe(t,e){return new Date(t,e+1,0).getDate()}function SVe(t,e){return new Date(t,e,1).getDay()}const _Ve=["January","February","March","April","May","June","July","August","September","October","November","December"],NVe=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function kVe({archives:t,onArchiveClick:e,highlightedArchiveId:n}){const r=new Date,[a,s]=w.useState(r.getMonth()),[o,l]=w.useState(r.getFullYear()),[c,u]=w.useState(null),[d,m]=w.useState(null),p=w.useMemo(()=>{const C=new Map;return t.forEach(A=>{const k=Jn(A.completed_at||A.created_at)||new Date,R=`${k.getFullYear()}-${String(k.getMonth()+1).padStart(2,"0")}-${String(k.getDate()).padStart(2,"0")}`,P=C.get(R)||[];P.push(A),C.set(R,P)}),C},[t]),f=wVe(o,a),y=SVe(o,a),v=()=>{a===0?(s(11),l(o-1)):s(a-1)},x=()=>{a===11?(s(0),l(o+1)):s(a+1)},g=()=>{s(r.getMonth()),l(r.getFullYear())},_=[];for(let C=0;C{C!==c&&m(null),u(C)};return i.jsxs("div",{className:"flex flex-col lg:flex-row gap-6",children:[i.jsxs("div",{className:"flex-1",children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsx("button",{onClick:v,className:"p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:i.jsx(Sc,{className:"w-5 h-5 text-bambu-gray"})}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white",children:[_Ve[a]," ",o]}),i.jsx("button",{onClick:g,className:"px-2 py-1 text-xs bg-bambu-dark-tertiary hover:bg-bambu-green/20 text-bambu-gray hover:text-white rounded transition-colors",children:"Today"})]}),i.jsx("button",{onClick:x,className:"p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:i.jsx(ha,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsx("div",{className:"grid grid-cols-7 gap-1 mb-1",children:NVe.map(C=>i.jsx("div",{className:"text-center text-xs text-bambu-gray py-2",children:C},C))}),i.jsx("div",{className:"grid grid-cols-7 gap-1",children:_.map((C,A)=>{if(C===null)return i.jsx("div",{className:"aspect-square"},`empty-${A}`);const k=`${o}-${String(a+1).padStart(2,"0")}-${String(C).padStart(2,"0")}`,R=p.get(k)||[],P=R.length>0,D=C===r.getDate()&&a===r.getMonth()&&o===r.getFullYear(),H=k===c,z=R.filter(I=>I.status==="completed").length,G=R.filter(I=>I.status==="failed").length;return i.jsxs("button",{onClick:()=>T(H?null:k),className:`aspect-square rounded-lg p-1 flex flex-col items-center justify-center transition-colors relative ${H?"bg-bambu-green text-white":D?"bg-bambu-green/20 text-white ring-2 ring-bambu-green":P?"bg-bambu-dark-tertiary hover:bg-bambu-dark-tertiary/70 text-white":"hover:bg-bambu-dark-tertiary/50 text-bambu-gray"}`,children:[i.jsx("span",{className:`text-sm font-medium ${D&&!H?"text-bambu-green":""}`,children:C}),P&&i.jsxs("div",{className:"absolute bottom-1 left-1/2 -translate-x-1/2 flex items-center gap-1",children:[i.jsx("div",{className:`w-2 h-2 rounded-full ${G>0&&z===0?"bg-red-400":G>0?"bg-yellow-400":"bg-green-400"}`}),i.jsx("span",{className:"text-xs font-medium",children:R.length})]})]},C)})}),i.jsx("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:i.jsxs("div",{className:"grid grid-cols-3 gap-4 text-center",children:[i.jsxs("div",{children:[i.jsx("div",{className:"text-2xl font-bold text-white",children:t.filter(C=>{const A=Jn(C.completed_at||C.created_at)||new Date;return A.getMonth()===a&&A.getFullYear()===o}).length}),i.jsx("div",{className:"text-xs text-bambu-gray",children:"Prints this month"})]}),i.jsxs("div",{children:[i.jsx("div",{className:"text-2xl font-bold text-green-400",children:t.filter(C=>{const A=Jn(C.completed_at||C.created_at)||new Date;return A.getMonth()===a&&A.getFullYear()===o&&C.status==="completed"}).length}),i.jsx("div",{className:"text-xs text-bambu-gray",children:"Successful"})]}),i.jsxs("div",{children:[i.jsx("div",{className:"text-2xl font-bold text-red-400",children:t.filter(C=>{const A=Jn(C.completed_at||C.created_at)||new Date;return A.getMonth()===a&&A.getFullYear()===o&&C.status==="failed"}).length}),i.jsx("div",{className:"text-xs text-bambu-gray",children:"Failed"})]})]})})]}),i.jsx("div",{className:"lg:w-80 bg-bambu-dark rounded-xl p-4",children:c?i.jsxs(i.Fragment,{children:[i.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-3",children:new Date(c+"T12:00:00").toLocaleDateString("en-US",{weekday:"long",month:"long",day:"numeric",year:"numeric"})}),N.length>0?i.jsx("div",{className:"calendar-scroll space-y-2 max-h-96 overflow-y-auto",children:N.map(C=>{const A=C.id===d||C.id===n;return i.jsxs("button",{onClick:()=>{m(C.id),e?.(C)},className:`w-full flex items-center gap-3 p-2 rounded-lg transition-colors text-left ${A?"":"hover:bg-bambu-dark-tertiary"}`,style:A?{outline:"4px solid #facc15",outlineOffset:"2px"}:void 0,children:[C.thumbnail_path?i.jsx("img",{src:be.getArchiveThumbnail(C.id),alt:"",className:"w-12 h-12 rounded object-cover"}):i.jsx("div",{className:"w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center",children:i.jsx("span",{className:"text-xs text-bambu-gray",children:"3MF"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-sm text-white truncate",children:C.print_name||C.filename}),i.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[i.jsx("span",{className:C.status==="failed"?"text-red-400":"text-green-400",children:C.status==="failed"?"Failed":"Completed"}),C.filament_color&&i.jsx("div",{className:"flex gap-0.5",children:C.filament_color.split(",").map((k,R)=>i.jsx("div",{className:"w-3 h-3 rounded-full border border-black/20",style:{backgroundColor:k}},R))})]})]})]},C.id)})}):i.jsx("p",{className:"text-sm text-bambu-gray",children:"No prints on this day"})]}):i.jsx("div",{className:"text-center py-8",children:i.jsx("p",{className:"text-sm text-bambu-gray",children:"Select a day to see prints"})})})]})}function lie({archiveId:t,archiveName:e,onClose:n}){const r=be.getArchiveQRCodeUrl(t,300);w.useEffect(()=>{const s=o=>{o.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]);const a=()=>{const s=document.createElement("a");s.href=r,s.download=`${e}_qrcode.png`,s.click()};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:n,children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-sm",onClick:s=>s.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:"QR Code"}),i.jsx("button",{onClick:n,className:"text-bambu-gray hover:text-white transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"p-6 flex flex-col items-center",children:[i.jsx("p",{className:"text-sm text-bambu-gray mb-4 text-center truncate max-w-full",children:e}),i.jsx("div",{className:"bg-white p-4 rounded-lg mb-4",children:i.jsx("img",{src:r,alt:"QR Code",className:"w-64 h-64"})}),i.jsx("p",{className:"text-xs text-bambu-gray mb-4 text-center",children:"Scan to open this archive"}),i.jsxs(Oe,{onClick:a,className:"w-full",children:[i.jsx(pi,{className:"w-4 h-4"}),"Download QR Code"]})]})]})})}function cie({archiveId:t,archiveName:e,photos:n,onClose:r,onDelete:a}){const[s,o]=w.useState(0),[l,c]=w.useState(!1);if(w.useEffect(()=>{const f=y=>{y.key==="Escape"&&r(),y.key==="ArrowLeft"&&o(v=>Math.max(0,v-1)),y.key==="ArrowRight"&&o(v=>Math.min(n.length-1,v+1))};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[r,n.length]),w.useEffect(()=>{s>=n.length&&o(Math.max(0,n.length-1))},[n.length,s]),n.length===0)return r(),null;const u=n[s],d=be.getArchivePhotoUrl(t,u),m=()=>{const f=document.createElement("a");f.href=d,f.download=`${e}_photo_${s+1}.jpg`,f.click()},p=()=>{a&&c(!0)};return i.jsxs("div",{className:"fixed inset-0 bg-black/90 flex items-center justify-center z-50",onClick:r,children:[i.jsxs("div",{className:"relative w-full h-full flex flex-col",onClick:f=>f.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 bg-black/50",children:[i.jsxs("div",{children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:e}),i.jsxs("p",{className:"text-sm text-bambu-gray",children:["Photo ",s+1," of ",n.length]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:m,children:[i.jsx(pi,{className:"w-4 h-4"}),"Download"]}),a&&i.jsx(Oe,{variant:"secondary",size:"sm",onClick:p,className:"text-red-400 hover:text-red-300",children:i.jsx(Jt,{className:"w-4 h-4"})}),i.jsx("button",{onClick:r,className:"p-2 text-bambu-gray hover:text-white transition-colors",children:i.jsx(Ht,{className:"w-6 h-6"})})]})]}),i.jsxs("div",{className:"flex-1 min-h-0 flex items-center justify-center p-4 relative overflow-hidden",children:[s>0&&i.jsx("button",{onClick:()=>o(f=>f-1),className:"absolute left-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors",children:i.jsx(Sc,{className:"w-8 h-8 text-white"})}),i.jsx("img",{src:d,alt:`Photo ${s+1}`,className:"max-w-full max-h-full object-contain rounded-lg",style:{maxHeight:"calc(100vh - 200px)"}}),so(f=>f+1),className:"absolute right-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors",children:i.jsx(ha,{className:"w-8 h-8 text-white"})})]}),n.length>1&&i.jsx("div",{className:"flex justify-center gap-2 p-4 bg-black/50",children:n.map((f,y)=>i.jsx("button",{onClick:()=>o(y),className:`w-16 h-16 rounded-lg overflow-hidden border-2 transition-colors ${y===s?"border-bambu-green":"border-transparent hover:border-bambu-gray"}`,children:i.jsx("img",{src:be.getArchivePhotoUrl(t,f),alt:`Thumbnail ${y+1}`,className:"w-full h-full object-cover"})},f))})]}),l&&i.jsx(Sn,{title:"Delete Photo",message:"Delete this photo? This cannot be undone.",confirmText:"Delete",variant:"danger",onConfirm:()=>{a?.(u),c(!1)},onCancel:()=>c(!1)})]})}const{entries:uie,setPrototypeOf:CW,isFrozen:CVe,getPrototypeOf:TVe,getOwnPropertyDescriptor:AVe}=Object;let{freeze:qs,seal:Vl,create:mN}=Object,{apply:jF,construct:DF}=typeof Reflect<"u"&&Reflect;qs||(qs=function(e){return e});Vl||(Vl=function(e){return e});jF||(jF=function(e,n){for(var r=arguments.length,a=new Array(r>2?r-2:0),s=2;s1?n-1:0),a=1;a1?n-1:0),a=1;a2&&arguments[2]!==void 0?arguments[2]:hN;CW&&CW(t,null);let r=e.length;for(;r--;){let a=e[r];if(typeof a=="string"){const s=n(a);s!==a&&(CVe(e)||(e[r]=s),a=s)}t[a]=!0}return t}function RVe(t){for(let e=0;e/gm),zVe=Vl(/\$\{[\w\W]*/gm),UVe=Vl(/^data-[\-\w.\u00B7-\uFFFF]+$/),BVe=Vl(/^aria-[\-\w]+$/),die=Vl(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),HVe=Vl(/^(?:\w+script|data):/i),$Ve=Vl(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),mie=Vl(/^html$/i),qVe=Vl(/^[a-z][.\w]*(-[.\w]+)+$/i);var jW=Object.freeze({__proto__:null,ARIA_ATTR:BVe,ATTR_WHITESPACE:$Ve,CUSTOM_ELEMENT:qVe,DATA_ATTR:UVe,DOCTYPE_NAME:mie,ERB_EXPR:IVe,IS_ALLOWED_URI:die,IS_SCRIPT_OR_DATA:HVe,MUSTACHE_EXPR:OVe,TMPLIT_EXPR:zVe});const vv={element:1,text:3,progressingInstruction:7,comment:8,document:9},VVe=function(){return typeof window>"u"?null:window},GVe=function(e,n){if(typeof e!="object"||typeof e.createPolicy!="function")return null;let r=null;const a="data-tt-policy-suffix";n&&n.hasAttribute(a)&&(r=n.getAttribute(a));const s="dompurify"+(r?"#"+r:"");try{return e.createPolicy(s,{createHTML(o){return o},createScriptURL(o){return o}})}catch{return console.warn("TrustedTypes policy "+s+" could not be created."),null}},DW=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}};function hie(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:VVe();const e=Ze=>hie(Ze);if(e.version="3.3.3",e.removed=[],!t||!t.document||t.document.nodeType!==vv.document||!t.Element)return e.isSupported=!1,e;let{document:n}=t;const r=n,a=r.currentScript,{DocumentFragment:s,HTMLTemplateElement:o,Node:l,Element:c,NodeFilter:u,NamedNodeMap:d=t.NamedNodeMap||t.MozNamedAttrMap,HTMLFormElement:m,DOMParser:p,trustedTypes:f}=t,y=c.prototype,v=yv(y,"cloneNode"),x=yv(y,"remove"),g=yv(y,"nextSibling"),_=yv(y,"childNodes"),N=yv(y,"parentNode");if(typeof o=="function"){const Ze=n.createElement("template");Ze.content&&Ze.content.ownerDocument&&(n=Ze.content.ownerDocument)}let T,C="";const{implementation:A,createNodeIterator:k,createDocumentFragment:R,getElementsByTagName:P}=n,{importNode:D}=r;let H=DW();e.isSupported=typeof uie=="function"&&typeof N=="function"&&A&&A.createHTMLDocument!==void 0;const{MUSTACHE_EXPR:z,ERB_EXPR:G,TMPLIT_EXPR:I,DATA_ATTR:ee,ARIA_ATTR:ie,IS_SCRIPT_OR_DATA:X,ATTR_WHITESPACE:me,CUSTOM_ELEMENT:he}=jW;let{IS_ALLOWED_URI:ge}=jW,Y=null;const oe=tr({},[...AW,...tD,...nD,...rD,...PW]);let le=null;const xe=tr({},[...MW,...iD,...EW,...T1]);let Pe=Object.seal(mN(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),q=null,Z=null;const j=Object.seal(mN(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let E=!0,U=!0,K=!1,$=!0,ne=!1,O=!0,V=!1,J=!1,W=!1,re=!1,ue=!1,fe=!1,ye=!0,ae=!1;const L="user-content-";let F=!0,te=!1,ve={},pe=null;const de=tr({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]);let Ne=null;const Se=tr({},["audio","video","img","source","image","track"]);let Le=null;const qe=tr({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Ee="http://www.w3.org/1998/Math/MathML",Te="http://www.w3.org/2000/svg",Ae="http://www.w3.org/1999/xhtml";let Be=Ae,je=!1,Xe=null;const ce=tr({},[Ee,Te,Ae],Jj);let Ie=tr({},["mi","mo","mn","ms","mtext"]),Ce=tr({},["annotation-xml"]);const Ge=tr({},["title","style","font","a","script"]);let $e=null;const Ue=["application/xhtml+xml","text/html"],De="text/html";let Ve=null,it=null;const xt=n.createElement("form"),Nt=function(ke){return ke instanceof RegExp||ke instanceof Function},kt=function(){let ke=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!(it&&it===ke)){if((!ke||typeof ke!="object")&&(ke={}),ke=qc(ke),$e=Ue.indexOf(ke.PARSER_MEDIA_TYPE)===-1?De:ke.PARSER_MEDIA_TYPE,Ve=$e==="application/xhtml+xml"?Jj:hN,Y=Oo(ke,"ALLOWED_TAGS")?tr({},ke.ALLOWED_TAGS,Ve):oe,le=Oo(ke,"ALLOWED_ATTR")?tr({},ke.ALLOWED_ATTR,Ve):xe,Xe=Oo(ke,"ALLOWED_NAMESPACES")?tr({},ke.ALLOWED_NAMESPACES,Jj):ce,Le=Oo(ke,"ADD_URI_SAFE_ATTR")?tr(qc(qe),ke.ADD_URI_SAFE_ATTR,Ve):qe,Ne=Oo(ke,"ADD_DATA_URI_TAGS")?tr(qc(Se),ke.ADD_DATA_URI_TAGS,Ve):Se,pe=Oo(ke,"FORBID_CONTENTS")?tr({},ke.FORBID_CONTENTS,Ve):de,q=Oo(ke,"FORBID_TAGS")?tr({},ke.FORBID_TAGS,Ve):qc({}),Z=Oo(ke,"FORBID_ATTR")?tr({},ke.FORBID_ATTR,Ve):qc({}),ve=Oo(ke,"USE_PROFILES")?ke.USE_PROFILES:!1,E=ke.ALLOW_ARIA_ATTR!==!1,U=ke.ALLOW_DATA_ATTR!==!1,K=ke.ALLOW_UNKNOWN_PROTOCOLS||!1,$=ke.ALLOW_SELF_CLOSE_IN_ATTR!==!1,ne=ke.SAFE_FOR_TEMPLATES||!1,O=ke.SAFE_FOR_XML!==!1,V=ke.WHOLE_DOCUMENT||!1,re=ke.RETURN_DOM||!1,ue=ke.RETURN_DOM_FRAGMENT||!1,fe=ke.RETURN_TRUSTED_TYPE||!1,W=ke.FORCE_BODY||!1,ye=ke.SANITIZE_DOM!==!1,ae=ke.SANITIZE_NAMED_PROPS||!1,F=ke.KEEP_CONTENT!==!1,te=ke.IN_PLACE||!1,ge=ke.ALLOWED_URI_REGEXP||die,Be=ke.NAMESPACE||Ae,Ie=ke.MATHML_TEXT_INTEGRATION_POINTS||Ie,Ce=ke.HTML_INTEGRATION_POINTS||Ce,Pe=ke.CUSTOM_ELEMENT_HANDLING||{},ke.CUSTOM_ELEMENT_HANDLING&&Nt(ke.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(Pe.tagNameCheck=ke.CUSTOM_ELEMENT_HANDLING.tagNameCheck),ke.CUSTOM_ELEMENT_HANDLING&&Nt(ke.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(Pe.attributeNameCheck=ke.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),ke.CUSTOM_ELEMENT_HANDLING&&typeof ke.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements=="boolean"&&(Pe.allowCustomizedBuiltInElements=ke.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),ne&&(U=!1),ue&&(re=!0),ve&&(Y=tr({},PW),le=mN(null),ve.html===!0&&(tr(Y,AW),tr(le,MW)),ve.svg===!0&&(tr(Y,tD),tr(le,iD),tr(le,T1)),ve.svgFilters===!0&&(tr(Y,nD),tr(le,iD),tr(le,T1)),ve.mathMl===!0&&(tr(Y,rD),tr(le,EW),tr(le,T1))),Oo(ke,"ADD_TAGS")||(j.tagCheck=null),Oo(ke,"ADD_ATTR")||(j.attributeCheck=null),ke.ADD_TAGS&&(typeof ke.ADD_TAGS=="function"?j.tagCheck=ke.ADD_TAGS:(Y===oe&&(Y=qc(Y)),tr(Y,ke.ADD_TAGS,Ve))),ke.ADD_ATTR&&(typeof ke.ADD_ATTR=="function"?j.attributeCheck=ke.ADD_ATTR:(le===xe&&(le=qc(le)),tr(le,ke.ADD_ATTR,Ve))),ke.ADD_URI_SAFE_ATTR&&tr(Le,ke.ADD_URI_SAFE_ATTR,Ve),ke.FORBID_CONTENTS&&(pe===de&&(pe=qc(pe)),tr(pe,ke.FORBID_CONTENTS,Ve)),ke.ADD_FORBID_CONTENTS&&(pe===de&&(pe=qc(pe)),tr(pe,ke.ADD_FORBID_CONTENTS,Ve)),F&&(Y["#text"]=!0),V&&tr(Y,["html","head","body"]),Y.table&&(tr(Y,["tbody"]),delete q.tbody),ke.TRUSTED_TYPES_POLICY){if(typeof ke.TRUSTED_TYPES_POLICY.createHTML!="function")throw xv('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof ke.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw xv('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');T=ke.TRUSTED_TYPES_POLICY,C=T.createHTML("")}else T===void 0&&(T=GVe(f,a)),T!==null&&typeof C=="string"&&(C=T.createHTML(""));qs&&qs(ke),it=ke}},We=tr({},[...tD,...nD,...FVe]),yt=tr({},[...rD,...LVe]),wt=function(ke){let ot=N(ke);(!ot||!ot.tagName)&&(ot={namespaceURI:Be,tagName:"template"});const se=hN(ke.tagName),He=hN(ot.tagName);return Xe[ke.namespaceURI]?ke.namespaceURI===Te?ot.namespaceURI===Ae?se==="svg":ot.namespaceURI===Ee?se==="svg"&&(He==="annotation-xml"||Ie[He]):!!We[se]:ke.namespaceURI===Ee?ot.namespaceURI===Ae?se==="math":ot.namespaceURI===Te?se==="math"&&Ce[He]:!!yt[se]:ke.namespaceURI===Ae?ot.namespaceURI===Te&&!Ce[He]||ot.namespaceURI===Ee&&!Ie[He]?!1:!yt[se]&&(Ge[se]||!We[se]):!!($e==="application/xhtml+xml"&&Xe[ke.namespaceURI]):!1},_t=function(ke){gv(e.removed,{element:ke});try{N(ke).removeChild(ke)}catch{x(ke)}},Ot=function(ke,ot){try{gv(e.removed,{attribute:ot.getAttributeNode(ke),from:ot})}catch{gv(e.removed,{attribute:null,from:ot})}if(ot.removeAttribute(ke),ke==="is")if(re||ue)try{_t(ot)}catch{}else try{ot.setAttribute(ke,"")}catch{}},Vt=function(ke){let ot=null,se=null;if(W)ke=""+ke;else{const Ye=eD(ke,/^[\r\n\t ]+/);se=Ye&&Ye[0]}$e==="application/xhtml+xml"&&Be===Ae&&(ke=''+ke+"");const He=T?T.createHTML(ke):ke;if(Be===Ae)try{ot=new p().parseFromString(He,$e)}catch{}if(!ot||!ot.documentElement){ot=A.createDocument(Be,"template",null);try{ot.documentElement.innerHTML=je?C:He}catch{}}const Ke=ot.body||ot.documentElement;return ke&&se&&Ke.insertBefore(n.createTextNode(se),Ke.childNodes[0]||null),Be===Ae?P.call(ot,V?"html":"body")[0]:V?ot.documentElement:Ke},Xt=function(ke){return k.call(ke.ownerDocument||ke,ke,u.SHOW_ELEMENT|u.SHOW_COMMENT|u.SHOW_TEXT|u.SHOW_PROCESSING_INSTRUCTION|u.SHOW_CDATA_SECTION,null)},Qe=function(ke){return ke instanceof m&&(typeof ke.nodeName!="string"||typeof ke.textContent!="string"||typeof ke.removeChild!="function"||!(ke.attributes instanceof d)||typeof ke.removeAttribute!="function"||typeof ke.setAttribute!="function"||typeof ke.namespaceURI!="string"||typeof ke.insertBefore!="function"||typeof ke.hasChildNodes!="function")},Qt=function(ke){return typeof l=="function"&&ke instanceof l};function hn(Ze,ke,ot){C1(Ze,se=>{se.call(e,ke,ot,it)})}const jn=function(ke){let ot=null;if(hn(H.beforeSanitizeElements,ke,null),Qe(ke))return _t(ke),!0;const se=Ve(ke.nodeName);if(hn(H.uponSanitizeElement,ke,{tagName:se,allowedTags:Y}),O&&ke.hasChildNodes()&&!Qt(ke.firstElementChild)&&Ms(/<[/\w!]/g,ke.innerHTML)&&Ms(/<[/\w!]/g,ke.textContent)||ke.nodeType===vv.progressingInstruction||O&&ke.nodeType===vv.comment&&Ms(/<[/\w]/g,ke.data))return _t(ke),!0;if(!(j.tagCheck instanceof Function&&j.tagCheck(se))&&(!Y[se]||q[se])){if(!q[se]&&Fe(se)&&(Pe.tagNameCheck instanceof RegExp&&Ms(Pe.tagNameCheck,se)||Pe.tagNameCheck instanceof Function&&Pe.tagNameCheck(se)))return!1;if(F&&!pe[se]){const He=N(ke)||ke.parentNode,Ke=_(ke)||ke.childNodes;if(Ke&&He){const Ye=Ke.length;for(let Me=Ye-1;Me>=0;--Me){const dt=v(Ke[Me],!0);dt.__removalCount=(ke.__removalCount||0)+1,He.insertBefore(dt,g(ke))}}}return _t(ke),!0}return ke instanceof c&&!wt(ke)||(se==="noscript"||se==="noembed"||se==="noframes")&&Ms(/<\/no(script|embed|frames)/i,ke.innerHTML)?(_t(ke),!0):(ne&&ke.nodeType===vv.text&&(ot=ke.textContent,C1([z,G,I],He=>{ot=bv(ot,He," ")}),ke.textContent!==ot&&(gv(e.removed,{element:ke.cloneNode()}),ke.textContent=ot)),hn(H.afterSanitizeElements,ke,null),!1)},kn=function(ke,ot,se){if(Z[ot]||ye&&(ot==="id"||ot==="name")&&(se in n||se in xt))return!1;if(!(U&&!Z[ot]&&Ms(ee,ot))){if(!(E&&Ms(ie,ot))){if(!(j.attributeCheck instanceof Function&&j.attributeCheck(ot,ke))){if(!le[ot]||Z[ot]){if(!(Fe(ke)&&(Pe.tagNameCheck instanceof RegExp&&Ms(Pe.tagNameCheck,ke)||Pe.tagNameCheck instanceof Function&&Pe.tagNameCheck(ke))&&(Pe.attributeNameCheck instanceof RegExp&&Ms(Pe.attributeNameCheck,ot)||Pe.attributeNameCheck instanceof Function&&Pe.attributeNameCheck(ot,ke))||ot==="is"&&Pe.allowCustomizedBuiltInElements&&(Pe.tagNameCheck instanceof RegExp&&Ms(Pe.tagNameCheck,se)||Pe.tagNameCheck instanceof Function&&Pe.tagNameCheck(se))))return!1}else if(!Le[ot]){if(!Ms(ge,bv(se,me,""))){if(!((ot==="src"||ot==="xlink:href"||ot==="href")&&ke!=="script"&&EVe(se,"data:")===0&&Ne[ke])){if(!(K&&!Ms(X,bv(se,me,"")))){if(se)return!1}}}}}}}return!0},Fe=function(ke){return ke!=="annotation-xml"&&eD(ke,he)},tt=function(ke){hn(H.beforeSanitizeAttributes,ke,null);const{attributes:ot}=ke;if(!ot||Qe(ke))return;const se={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:le,forceKeepAttr:void 0};let He=ot.length;for(;He--;){const Ke=ot[He],{name:Ye,namespaceURI:Me,value:dt}=Ke,ct=Ve(Ye),nt=dt;let bt=Ye==="value"?nt:jVe(nt);if(se.attrName=ct,se.attrValue=bt,se.keepAttr=!0,se.forceKeepAttr=void 0,hn(H.uponSanitizeAttribute,ke,se),bt=se.attrValue,ae&&(ct==="id"||ct==="name")&&(Ot(Ye,ke),bt=L+bt),O&&Ms(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,bt)){Ot(Ye,ke);continue}if(ct==="attributename"&&eD(bt,"href")){Ot(Ye,ke);continue}if(se.forceKeepAttr)continue;if(!se.keepAttr){Ot(Ye,ke);continue}if(!$&&Ms(/\/>/i,bt)){Ot(Ye,ke);continue}ne&&C1([z,G,I],Et=>{bt=bv(bt,Et," ")});const Ut=Ve(ke.nodeName);if(!kn(Ut,ct,bt)){Ot(Ye,ke);continue}if(T&&typeof f=="object"&&typeof f.getAttributeType=="function"&&!Me)switch(f.getAttributeType(Ut,ct)){case"TrustedHTML":{bt=T.createHTML(bt);break}case"TrustedScriptURL":{bt=T.createScriptURL(bt);break}}if(bt!==nt)try{Me?ke.setAttributeNS(Me,Ye,bt):ke.setAttribute(Ye,bt),Qe(ke)?_t(ke):TW(e.removed)}catch{Ot(Ye,ke)}}hn(H.afterSanitizeAttributes,ke,null)},ut=function Ze(ke){let ot=null;const se=Xt(ke);for(hn(H.beforeSanitizeShadowDOM,ke,null);ot=se.nextNode();)hn(H.uponSanitizeShadowNode,ot,null),jn(ot),tt(ot),ot.content instanceof s&&Ze(ot.content);hn(H.afterSanitizeShadowDOM,ke,null)};return e.sanitize=function(Ze){let ke=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},ot=null,se=null,He=null,Ke=null;if(je=!Ze,je&&(Ze=""),typeof Ze!="string"&&!Qt(Ze))if(typeof Ze.toString=="function"){if(Ze=Ze.toString(),typeof Ze!="string")throw xv("dirty is not a string, aborting")}else throw xv("toString is not a function");if(!e.isSupported)return Ze;if(J||kt(ke),e.removed=[],typeof Ze=="string"&&(te=!1),te){if(Ze.nodeName){const dt=Ve(Ze.nodeName);if(!Y[dt]||q[dt])throw xv("root node is forbidden and cannot be sanitized in-place")}}else if(Ze instanceof l)ot=Vt(""),se=ot.ownerDocument.importNode(Ze,!0),se.nodeType===vv.element&&se.nodeName==="BODY"||se.nodeName==="HTML"?ot=se:ot.appendChild(se);else{if(!re&&!ne&&!V&&Ze.indexOf("<")===-1)return T&&fe?T.createHTML(Ze):Ze;if(ot=Vt(Ze),!ot)return re?null:fe?C:""}ot&&W&&_t(ot.firstChild);const Ye=Xt(te?Ze:ot);for(;He=Ye.nextNode();)jn(He),tt(He),He.content instanceof s&&ut(He.content);if(te)return Ze;if(re){if(ue)for(Ke=R.call(ot.ownerDocument);ot.firstChild;)Ke.appendChild(ot.firstChild);else Ke=ot;return(le.shadowroot||le.shadowrootmode)&&(Ke=D.call(r,Ke,!0)),Ke}let Me=V?ot.outerHTML:ot.innerHTML;return V&&Y["!doctype"]&&ot.ownerDocument&&ot.ownerDocument.doctype&&ot.ownerDocument.doctype.name&&Ms(mie,ot.ownerDocument.doctype.name)&&(Me=" `+Me),ne&&C1([z,G,I],dt=>{Me=bv(Me,dt," ")}),T&&fe?T.createHTML(Me):Me},e.setConfig=function(){let Ze=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};kt(Ze),J=!0},e.clearConfig=function(){it=null,J=!1},e.isValidAttribute=function(Ze,ke,ot){it||kt({});const se=Ve(Ze),He=Ve(ke);return kn(se,He,ot)},e.addHook=function(Ze,ke){typeof ke=="function"&&gv(H[Ze],ke)},e.removeHook=function(Ze,ke){if(ke!==void 0){const ot=PVe(H[Ze],ke);return ot===-1?void 0:MVe(H[Ze],ot,1)[0]}return TW(H[Ze])},e.removeHooks=function(Ze){H[Ze]=[]},e.removeAllHooks=function(){H=DW()},e}var pie=hie();function Ka(t){this.content=t}Ka.prototype={constructor:Ka,find:function(t){for(var e=0;e>1}};Ka.from=function(t){if(t instanceof Ka)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new Ka(e)};function fie(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let a=t.child(r),s=e.child(r);if(a==s){n+=a.nodeSize;continue}if(!a.sameMarkup(s))return n;if(a.isText&&a.text!=s.text){for(let o=0;a.text[o]==s.text[o];o++)n++;return n}if(a.content.size||s.content.size){let o=fie(a.content,s.content,n+1);if(o!=null)return o}n+=a.nodeSize}}function gie(t,e,n,r){for(let a=t.childCount,s=e.childCount;;){if(a==0||s==0)return a==s?null:{a:n,b:r};let o=t.child(--a),l=e.child(--s),c=o.nodeSize;if(o==l){n-=c,r-=c;continue}if(!o.sameMarkup(l))return{a:n,b:r};if(o.isText&&o.text!=l.text){let u=0,d=Math.min(o.text.length,l.text.length);for(;ue&&r(c,a+l,s||null,o)!==!1&&c.content.size){let d=l+1;c.nodesBetween(Math.max(0,e-d),Math.min(c.content.size,n-d),r,a+d)}l=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,a){let s="",o=!0;return this.nodesBetween(e,n,(l,c)=>{let u=l.isText?l.text.slice(Math.max(e,c)-c,n-c):l.isLeaf?a?typeof a=="function"?a(l):a:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&u||l.isTextblock)&&r&&(o?o=!1:s+=r),s+=u},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,a=this.content.slice(),s=0;for(n.isText&&n.sameMarkup(r)&&(a[a.length-1]=n.withText(n.text+r.text),s=1);se)for(let s=0,o=0;oe&&((on)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,n-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,n-o-1))),r.push(l),a+=l.nodeSize),o=c}return new Bt(r,a)}cutByIndex(e,n){return e==n?Bt.empty:e==0&&n==this.content.length?this:new Bt(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let a=this.content.slice(),s=this.size+n.nodeSize-r.nodeSize;return a[e]=n,new Bt(a,s)}addToStart(e){return new Bt([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new Bt(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;nthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,r=0;;n++){let a=this.child(n),s=r+a.nodeSize;if(s>=e)return s==e?A1(n+1,s):A1(n,r);r=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return Bt.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new Bt(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return Bt.empty;let n,r=0;for(let a=0;athis.type.rank&&(n||(n=e.slice(0,a)),n.push(this),r=!0),n&&n.push(s)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;nr.type.rank-a.type.rank),n}};Gr.none=[];class Qk extends Error{}class Kt{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=xie(this.content,e+this.openStart,n);return r&&new Kt(r,this.openStart,this.openEnd)}removeBetween(e,n){return new Kt(bie(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return Kt.empty;let r=n.openStart||0,a=n.openEnd||0;if(typeof r!="number"||typeof a!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new Kt(Bt.fromJSON(e,n.content),r,a)}static maxOpen(e,n=!0){let r=0,a=0;for(let s=e.firstChild;s&&!s.isLeaf&&(n||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(n||!s.type.spec.isolating);s=s.lastChild)a++;return new Kt(e,r,a)}}Kt.empty=new Kt(Bt.empty,0,0);function bie(t,e,n){let{index:r,offset:a}=t.findIndex(e),s=t.maybeChild(r),{index:o,offset:l}=t.findIndex(n);if(a==e||s.isText){if(l!=n&&!t.child(o).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=o)throw new RangeError("Removing non-flat range");return t.replaceChild(r,s.copy(bie(s.content,e-a-1,n-a-1)))}function xie(t,e,n,r){let{index:a,offset:s}=t.findIndex(e),o=t.maybeChild(a);if(s==e||o.isText)return r&&!r.canReplace(a,a,n)?null:t.cut(0,e).append(n).append(t.cut(e));let l=xie(o.content,e-s-1,n,o);return l&&t.replaceChild(a,o.copy(l))}function WVe(t,e,n){if(n.openStart>t.depth)throw new Qk("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new Qk("Inconsistent open depths");return yie(t,e,n,0)}function yie(t,e,n,r){let a=t.index(r),s=t.node(r);if(a==e.index(r)&&r=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function Yv(t,e,n,r){let a=(e||t).node(n),s=0,o=e?e.index(n):a.childCount;t&&(s=t.index(n),t.depth>n?s++:t.textOffset&&(df(t.nodeAfter,r),s++));for(let l=s;la&&FF(t,e,a+1),o=r.depth>a&&FF(n,r,a+1),l=[];return Yv(null,t,a,l),s&&o&&e.index(a)==n.index(a)?(vie(s,o),df(mf(s,wie(t,e,n,r,a+1)),l)):(s&&df(mf(s,Zk(t,e,a+1)),l),Yv(e,n,a,l),o&&df(mf(o,Zk(n,r,a+1)),l)),Yv(r,null,a,l),new Bt(l)}function Zk(t,e,n){let r=[];if(Yv(null,t,n,r),t.depth>n){let a=FF(t,e,n+1);df(mf(a,Zk(t,e,n+1)),r)}return Yv(e,null,n,r),new Bt(r)}function KVe(t,e){let n=e.depth-t.openStart,a=e.node(n).copy(t.content);for(let s=n-1;s>=0;s--)a=e.node(s).copy(Bt.from(a));return{start:a.resolveNoCache(t.openStart+n),end:a.resolveNoCache(a.content.size-t.openEnd-n)}}class W0{constructor(e,n,r){this.pos=e,this.path=n,this.parentOffset=r,this.depth=n.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,n=this.index(this.depth);if(n==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],a=e.child(n);return r?e.child(n).cut(r):a}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let r=this.path[n*3],a=n==0?0:this.path[n*3-1]+1;for(let s=0;s0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!n||n(this.node(r))))return new Jk(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let r=[],a=0,s=n;for(let o=e;;){let{index:l,offset:c}=o.content.findIndex(s),u=s-c;if(r.push(o,l,a+c),!u||(o=o.child(l),o.isText))break;s=u-1,a+=c+1}return new W0(n,r,s)}static resolveCached(e,n){let r=RW.get(e);if(r)for(let s=0;se&&this.nodesBetween(e,n,s=>(r.isInSet(s.marks)&&(a=!0),!a)),a}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),Sie(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,r=Bt.empty,a=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,a,s),l=o&&o.matchFragment(this.content,n);if(!l||!l.validEnd)return!1;for(let c=a;cn.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let r;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,r)}let a=Bt.fromJSON(e,n.content),s=e.nodeType(n.type).create(n.attrs,a,r);return s.type.checkAttrs(s.attrs),s}}wc.prototype.text=void 0;class eC extends wc{constructor(e,n,r,a){if(super(e,n,null,a),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Sie(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new eC(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new eC(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function Sie(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}class zf{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let r=new ZVe(e,n);if(r.next==null)return zf.empty;let a=_ie(r);r.next&&r.err("Unexpected trailing text");let s=a7e(i7e(a));return s7e(s,r),s}matchType(e){for(let n=0;nu.createAndFill()));for(let u=0;u=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function n(r){e.push(r);for(let a=0;a{let s=a+(r.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(r.next[o].next);return s}).join(` `)}}zf.empty=new zf(!0);class ZVe{constructor(e,n){this.string=e,this.nodeTypes=n,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function _ie(t){let e=[];do e.push(JVe(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function JVe(t){let e=[];do e.push(e7e(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function e7e(t){let e=r7e(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else if(t.eat("{"))e=t7e(t,e);else break;return e}function FW(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function t7e(t,e){let n=FW(t),r=n;return t.eat(",")&&(t.next!="}"?r=FW(t):r=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:e}}function n7e(t,e){let n=t.nodeTypes,r=n[e];if(r)return[r];let a=[];for(let s in n){let o=n[s];o.isInGroup(e)&&a.push(o)}return a.length==0&&t.err("No node type or group '"+e+"' found"),a}function r7e(t){if(t.eat("(")){let e=_ie(t);return t.eat(")")||t.err("Missing closing paren"),e}else if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=n7e(t,t.next).map(n=>(t.inline==null?t.inline=n.isInline:t.inline!=n.isInline&&t.err("Mixing inline and block content"),{type:"name",value:n}));return t.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function i7e(t){let e=[[]];return a(s(t,0),n()),e;function n(){return e.push([])-1}function r(o,l,c){let u={term:c,to:l};return e[o].push(u),u}function a(o,l){o.forEach(c=>c.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((c,u)=>c.concat(s(u,l)),[]);if(o.type=="seq")for(let c=0;;c++){let u=s(o.exprs[c],l);if(c==o.exprs.length-1)return u;a(u,l=n())}else if(o.type=="star"){let c=n();return r(l,c),a(s(o.expr,c),c),[r(c)]}else if(o.type=="plus"){let c=n();return a(s(o.expr,l),c),a(s(o.expr,c),c),[r(c)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let c=l;for(let u=0;u{t[o].forEach(({term:l,to:c})=>{if(!l)return;let u;for(let d=0;d{u||a.push([l,u=[]]),u.indexOf(d)==-1&&u.push(d)})})});let s=e[r.join(",")]=new zf(r.indexOf(t.length-1)>-1);for(let o=0;o-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:Cie(this.attrs,e)}create(e=null,n,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new wc(this,this.computeAttrs(e),Bt.from(n),Gr.setFrom(r))}createChecked(e=null,n,r){return n=Bt.from(n),this.checkContent(n),new wc(this,this.computeAttrs(e),n,Gr.setFrom(r))}createAndFill(e=null,n,r){if(e=this.computeAttrs(e),n=Bt.from(n),n.size){let o=this.contentMatch.fillBefore(n);if(!o)return null;n=o.append(n)}let a=this.contentMatch.matchFragment(n),s=a&&a.fillBefore(Bt.empty,!0);return s?new wc(this,e,n.append(s),Gr.setFrom(r)):null}validContent(e){let n=this.contentMatch.matchFragment(e);if(!n||!n.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let n=0;nr[s]=new Pie(s,n,o));let a=n.spec.topNode||"doc";if(!r[a])throw new RangeError("Schema is missing its top node type ('"+a+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function o7e(t,e,n){let r=n.split("|");return a=>{let s=a===null?"null":typeof a;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${t}, got ${s}`)}}class l7e{constructor(e,n,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?o7e(e,n,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class mA{constructor(e,n,r,a){this.name=e,this.rank=n,this.schema=r,this.spec=a,this.attrs=Aie(e,a.attrs),this.excluded=null;let s=kie(this.attrs);this.instance=s?new Gr(this,s):null}create(e=null){return!e&&this.instance?this.instance:new Gr(this,Cie(this.attrs,e))}static compile(e,n){let r=Object.create(null),a=0;return e.forEach((s,o)=>r[s]=new mA(s,a++,n,o)),r}removeFromSet(e){for(var n=0;n-1}}class Mie{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let n=this.spec={};for(let a in e)n[a]=e[a];n.nodes=Ka.from(e.nodes),n.marks=Ka.from(e.marks||{}),this.nodes=OW.compile(this.spec.nodes,this),this.marks=mA.compile(this.spec.marks,this);let r=Object.create(null);for(let a in this.nodes){if(a in this.marks)throw new RangeError(a+" can not be both a node and a mark");let s=this.nodes[a],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=zf.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?IW(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let a in this.marks){let s=this.marks[a],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:IW(this,o.split(" "))}this.nodeFromJSON=a=>wc.fromJSON(this,a),this.markFromJSON=a=>Gr.fromJSON(this,a),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,n=null,r,a){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof OW){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(n,r,a)}text(e,n){let r=this.nodes.text;return new eC(r,r.defaultAttrs,e,Gr.setFrom(n))}mark(e,n){return typeof e=="string"&&(e=this.marks[e]),e.create(n)}nodeType(e){let n=this.nodes[e];if(!n)throw new RangeError("Unknown node type: "+e);return n}}function IW(t,e){let n=[];for(let r=0;r-1)&&n.push(o=c)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return n}function c7e(t){return t.tag!=null}function u7e(t){return t.style!=null}let Xv=class LF{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[];let r=this.matchedStyles=[];n.forEach(a=>{if(c7e(a))this.tags.push(a);else if(u7e(a)){let s=/[^=]*/.exec(a.style)[0];r.indexOf(s)<0&&r.push(s),this.styles.push(a)}}),this.normalizeLists=!this.tags.some(a=>{if(!/^(ul|ol)\b/.test(a.tag)||!a.node)return!1;let s=e.nodes[a.node];return s.contentMatch.matchType(s)})}parse(e,n={}){let r=new UW(this,n,!1);return r.addAll(e,Gr.none,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new UW(this,n,!0);return r.addAll(e,Gr.none,n.from,n.to),Kt.maxOpen(r.finish())}matchTag(e,n,r){for(let a=r?this.tags.indexOf(r)+1:0;ae.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=n))){if(o.getAttrs){let c=o.getAttrs(n);if(c===!1)continue;o.attrs=c||void 0}return o}}}static schemaRules(e){let n=[];function r(a){let s=a.priority==null?50:a.priority,o=0;for(;o{r(o=BW(o)),o.mark||o.ignore||o.clearMark||(o.mark=a)})}for(let a in e.nodes){let s=e.nodes[a].spec.parseDOM;s&&s.forEach(o=>{r(o=BW(o)),o.node||o.ignore||o.mark||(o.node=a)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new LF(e,LF.schemaRules(e)))}};const Eie={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},d7e={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},jie={ol:!0,ul:!0},K0=1,OF=2,Qv=4;function zW(t,e,n){return e!=null?(e?K0:0)|(e==="full"?OF:0):t&&t.whitespace=="pre"?K0|OF:n&~Qv}class P1{constructor(e,n,r,a,s,o){this.type=e,this.attrs=n,this.marks=r,this.solid=a,this.options=o,this.content=[],this.activeMarks=Gr.none,this.match=s||(o&Qv?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(Bt.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,a;return(a=r.findWrapping(e.type))?(this.match=r,a):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&K0)){let r=this.content[this.content.length-1],a;if(r&&r.isText&&(a=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==a[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-a[0].length))}}let n=Bt.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(Bt.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Eie.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class UW{constructor(e,n,r){this.parser=e,this.options=n,this.isOpen=r,this.open=0,this.localPreserveWS=!1;let a=n.topNode,s,o=zW(null,n.preserveWhitespace,0)|(r?Qv:0);a?s=new P1(a.type,a.attrs,Gr.none,!0,n.topMatch||a.type.contentMatch,o):r?s=new P1(null,null,Gr.none,!0,null,o):s=new P1(e.schema.topNodeType,null,Gr.none,!0,null,o),this.nodes=[s],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,n){e.nodeType==3?this.addTextNode(e,n):e.nodeType==1&&this.addElement(e,n)}addTextNode(e,n){let r=e.nodeValue,a=this.top,s=a.options&OF?"full":this.localPreserveWS||(a.options&K0)>0,{schema:o}=this.parser;if(s==="full"||a.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(s)if(s==="full")r=r.replace(/\r\n?/g,` `);else if(o.linebreakReplacement&&/[\r\n]/.test(r)&&this.top.findWrapping(o.linebreakReplacement.create())){let l=r.split(/\r?\n|\r/);for(let c=0;ci.jsxs("button",{onClick:()=>d(A),className:`px-2 py-1 text-xs rounded transition-colors ${u===A?"bg-bambu-green text-white":"bg-bambu-dark-tertiary text-bambu-gray hover:bg-bambu-dark-tertiary/80"}`,children:[A,"x"]},A))})]})]})]})]})]}),v&&r&&i.jsx(YQe,{archiveId:r,timelapseSrc:t,onClose:()=>x(!1),onSave:s})]})}function QQe({archiveIds:t,onClose:e}){w.useEffect(()=>{const s=o=>{o.key==="Escape"&&e()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[e]);const{data:n,isLoading:r,error:a}=et({queryKey:["archive-comparison",t],queryFn:()=>be.compareArchives(t)});return i.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",onClick:e,children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg max-w-4xl w-full max-h-[90vh] flex flex-col border border-bambu-dark-tertiary",onClick:s=>s.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("h3",{className:"text-lg font-semibold text-white",children:["Compare Archives (",t.length,")"]}),i.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white p-1",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsx("div",{className:"flex-1 overflow-auto p-4 bg-bambu-dark-secondary",children:r?i.jsx("div",{className:"flex items-center justify-center py-12",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):a?i.jsxs("div",{className:"text-center py-12 text-red-400",children:[i.jsx(Mn,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),i.jsx("p",{children:"Failed to load comparison"}),i.jsx("p",{className:"text-sm text-bambu-gray mt-2",children:a instanceof Error?a.message:"Unknown error"})]}):n?i.jsx(ZQe,{comparison:n}):null}),i.jsx("div",{className:"p-4 border-t border-bambu-dark-tertiary",children:i.jsx(Oe,{variant:"secondary",onClick:e,className:"w-full",children:"Close"})})]})})}function ZQe({comparison:t}){return i.jsxs("div",{className:"space-y-6",children:[i.jsx("div",{className:"overflow-x-auto",children:i.jsxs("table",{className:"w-full",children:[i.jsx("thead",{children:i.jsxs("tr",{children:[i.jsx("th",{className:"text-left text-sm text-bambu-gray font-medium pb-2 pr-4 min-w-[150px]",children:"Setting"}),t.archives.map(e=>i.jsxs("th",{className:"text-left text-sm font-medium pb-2 px-2 min-w-[120px]",children:[i.jsx("div",{className:"text-white truncate max-w-[150px]",title:e.print_name,children:e.print_name}),i.jsx("div",{className:`text-xs ${e.status==="completed"?"text-status-ok":e.status==="failed"?"text-status-error":"text-bambu-gray"}`,children:e.status})]},e.id))]})}),i.jsx("tbody",{className:"divide-y divide-bambu-gray/20",children:t.comparison.map(e=>i.jsxs("tr",{className:e.has_difference?"bg-yellow-500/5":"",children:[i.jsx("td",{className:"py-2 pr-4 text-sm",children:i.jsxs("div",{className:"flex items-center gap-2",children:[e.has_difference&&i.jsx(Mn,{className:"w-3 h-3 text-yellow-400 flex-shrink-0"}),i.jsx("span",{className:e.has_difference?"text-yellow-400":"text-bambu-gray",children:e.label})]})}),e.values.map((n,r)=>i.jsxs("td",{className:"py-2 px-2 text-sm text-white",children:[n??i.jsx("span",{className:"text-bambu-gray/50",children:"-"}),e.unit&&n!==null&&i.jsx("span",{className:"text-bambu-gray ml-1",children:e.unit})]},r))]},e.field))})]})}),t.differences.length>0&&i.jsxs("div",{className:"p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[i.jsxs("h4",{className:"text-sm font-medium text-yellow-400 mb-2 flex items-center gap-2",children:[i.jsx(Mn,{className:"w-4 h-4"}),t.differences.length," Difference",t.differences.length>1?"s":""," Found"]}),i.jsxs("ul",{className:"text-sm text-white/80 space-y-1",children:[t.differences.slice(0,5).map(e=>i.jsxs("li",{children:[i.jsx("span",{className:"text-yellow-400",children:e.label}),": ",e.values.join(" vs ")," ",e.unit||""]},e.field)),t.differences.length>5&&i.jsxs("li",{className:"text-bambu-gray",children:["...and ",t.differences.length-5," more"]})]})]}),t.success_correlation.has_both_outcomes?i.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg",children:[i.jsxs("h4",{className:"text-sm font-medium text-white mb-3 flex items-center gap-2",children:[i.jsx(Yr,{className:"w-4 h-4 text-bambu-green"}),"Success/Failure Analysis"]}),i.jsxs("div",{className:"flex items-center gap-4 text-sm mb-3",children:[i.jsxs("span",{className:"text-bambu-green",children:[t.success_correlation.successful_count," successful"]}),i.jsxs("span",{className:"text-red-400",children:[t.success_correlation.failed_count," failed"]})]}),t.success_correlation.insights&&t.success_correlation.insights.length>0?i.jsx("div",{className:"space-y-2",children:t.success_correlation.insights.map(e=>i.jsxs("div",{className:"text-sm p-2 bg-bambu-dark-secondary rounded",children:[i.jsxs("span",{className:"text-white font-medium",children:[e.label,":"]})," ",i.jsx("span",{className:"text-white/80",children:e.insight})]},e.field))}):i.jsx("p",{className:"text-sm text-bambu-gray",children:"No clear correlations found between settings and outcomes."})]}):i.jsx("div",{className:"p-4 bg-bambu-dark rounded-lg text-sm text-bambu-gray",children:i.jsx("p",{children:t.success_correlation.message||"Need both successful and failed prints for correlation analysis."})})]})}function JQe(t){const e=new Date(t),r=new Date().getTime()-e.getTime(),a=Math.floor(r/6e4);if(a<1)return"Just now";if(a<60)return`${a}m ago`;const s=Math.floor(a/60);return s<24?`${s}h ago`:`${Math.floor(s/24)}d ago`}function eZe({upload:t,projects:e,onArchive:n,onDiscard:r,isArchiving:a,isDiscarding:s}){const[o,l]=w.useState(!1),[c,u]=w.useState(t.tags||""),[d,m]=w.useState(t.notes||""),[p,f]=w.useState(t.project_id),[y,v]=w.useState(!1);return i.jsx(Mt,{children:i.jsxs(Dt,{className:"py-3",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx(nf,{className:"w-8 h-8 text-bambu-green flex-shrink-0"}),i.jsxs("div",{children:[i.jsx("p",{className:"text-white font-medium",children:t.filename}),i.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[i.jsx("span",{children:oo(t.file_size)}),i.jsx("span",{children:"·"}),i.jsxs("span",{className:"flex items-center gap-1",children:[i.jsx(er,{className:"w-3 h-3"}),JQe(t.uploaded_at)]}),t.source_ip&&i.jsxs(i.Fragment,{children:[i.jsx("span",{children:"·"}),i.jsxs("span",{children:["from ",t.source_ip]})]})]})]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("button",{onClick:()=>l(!o),className:"p-1 text-bambu-gray hover:text-white transition-colors",children:o?i.jsx(Il,{className:"w-5 h-5"}):i.jsx(Ln,{className:"w-5 h-5"})}),i.jsx(Oe,{variant:"primary",size:"sm",onClick:()=>n(t.id,{tags:c,notes:d,project_id:p||void 0}),disabled:a,children:a?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsxs(i.Fragment,{children:[i.jsx(zs,{className:"w-4 h-4"}),"Archive"]})}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>v(!0),disabled:s,children:s?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Jt,{className:"w-4 h-4 text-red-400"})})]})]}),y&&i.jsx(Sn,{title:"Discard Upload",message:`Are you sure you want to discard "${t.filename}"? This cannot be undone.`,confirmText:"Discard",variant:"danger",onConfirm:()=>{r(t.id),v(!1)},onCancel:()=>v(!1)}),o&&i.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary space-y-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Tags"}),i.jsx("input",{type:"text",value:c,onChange:x=>u(x.target.value),placeholder:"e.g., functional, prototype, gift",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white placeholder-bambu-gray text-sm"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Notes"}),i.jsx("textarea",{value:d,onChange:x=>m(x.target.value),placeholder:"Add notes about this print...",rows:2,className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white placeholder-bambu-gray text-sm resize-none"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Project"}),i.jsxs("select",{value:p||"",onChange:x=>f(x.target.value?Number(x.target.value):null),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm",children:[i.jsx("option",{value:"",children:"No project"}),e.map(x=>i.jsx("option",{value:x.id,children:x.name},x.id))]})]})]})]})})}function tZe(){const t=an(),{showToast:e}=fn(),[n,r]=w.useState(!1),[a,s]=w.useState(!1),[o,l]=w.useState(new Set),[c,u]=w.useState(new Set),{data:d,isLoading:m}=et({queryKey:["pending-uploads"],queryFn:Nb.list,refetchInterval:1e4}),{data:p}=et({queryKey:["projects"],queryFn:()=>be.getProjects()}),f=pt({mutationFn:({id:g,data:_})=>Nb.archive(g,_),onMutate:({id:g})=>{l(_=>new Set(_).add(g))},onSettled:(g,_,{id:N})=>{l(T=>{const C=new Set(T);return C.delete(N),C})},onSuccess:g=>{t.invalidateQueries({queryKey:["pending-uploads"]}),t.invalidateQueries({queryKey:["archives"]}),e(`Archived: ${g.print_name}`)},onError:g=>{e(g.message||"Failed to archive","error")}}),y=pt({mutationFn:g=>Nb.discard(g),onMutate:g=>{u(_=>new Set(_).add(g))},onSettled:(g,_,N)=>{u(T=>{const C=new Set(T);return C.delete(N),C})},onSuccess:()=>{t.invalidateQueries({queryKey:["pending-uploads"]}),e("Upload discarded")},onError:g=>{e(g.message||"Failed to discard","error")}}),v=pt({mutationFn:Nb.archiveAll,onSuccess:g=>{t.invalidateQueries({queryKey:["pending-uploads"]}),t.invalidateQueries({queryKey:["archives"]}),e(`Archived ${g.archived} files${g.failed>0?`, ${g.failed} failed`:""}`)},onError:g=>{e(g.message||"Failed to archive all","error")}}),x=pt({mutationFn:Nb.discardAll,onSuccess:g=>{t.invalidateQueries({queryKey:["pending-uploads"]}),e(`Discarded ${g.discarded} files`)},onError:g=>{e(g.message||"Failed to discard all","error")}});return m?i.jsx(Mt,{children:i.jsx(Dt,{className:"py-8 flex justify-center",children:i.jsx(ht,{className:"w-6 h-6 animate-spin text-bambu-green"})})}):!d||d.length===0?null:i.jsxs("div",{className:"mb-6",children:[i.jsxs(Mt,{className:"border-l-4 border-l-yellow-500",children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(xi,{className:"w-5 h-5 text-yellow-500"}),i.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Pending Uploads (",d.length,")"]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Oe,{variant:"primary",size:"sm",onClick:()=>r(!0),disabled:v.isPending,children:v.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsxs(i.Fragment,{children:[i.jsx(zs,{className:"w-4 h-4"}),"Archive All"]})}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>s(!0),disabled:x.isPending,children:x.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsxs(i.Fragment,{children:[i.jsx(Jt,{className:"w-4 h-4"}),"Discard All"]})})]})]})}),i.jsxs(Dt,{children:[i.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"These files were uploaded via the virtual printer. Review and archive them to add to your collection."}),i.jsx("div",{className:"space-y-3",children:d.map(g=>i.jsx(eZe,{upload:g,projects:p||[],onArchive:(_,N)=>f.mutate({id:_,data:N}),onDiscard:_=>y.mutate(_),isArchiving:o.has(g.id),isDiscarding:c.has(g.id)},g.id))})]})]}),n&&i.jsx(Sn,{title:"Archive All Uploads",message:`Are you sure you want to archive all ${d.length} pending uploads?`,confirmText:"Archive All",onConfirm:()=>{v.mutate(),r(!1)},onCancel:()=>r(!1)}),a&&i.jsx(Sn,{title:"Discard All Uploads",message:`Are you sure you want to discard all ${d.length} pending uploads? This cannot be undone.`,confirmText:"Discard All",variant:"danger",onConfirm:()=>{x.mutate(),s(!1)},onCancel:()=>s(!1)})]})}function nZe({onClose:t}){const e=an(),{showToast:n}=fn(),[r,a]=w.useState(""),[s,o]=w.useState(null),[l,c]=w.useState(""),[u,d]=w.useState(null),[m,p]=w.useState("count");w.useEffect(()=>{const P=D=>{D.key==="Escape"&&(s?o(null):u?d(null):t())};return window.addEventListener("keydown",P),()=>window.removeEventListener("keydown",P)},[t,s,u]);const{data:f,isLoading:y}=et({queryKey:["tags"],queryFn:be.getTags}),v=pt({mutationFn:({oldName:P,newName:D})=>be.renameTag(P,D),onSuccess:(P,{oldName:D,newName:H})=>{e.invalidateQueries({queryKey:["tags"]}),e.invalidateQueries({queryKey:["archives"]}),n(`Renamed "${D}" to "${H}" in ${P.affected} archive${P.affected!==1?"s":""}`),o(null)},onError:P=>{n(P.message||"Failed to rename tag","error")}}),x=pt({mutationFn:P=>be.deleteTag(P),onSuccess:(P,D)=>{e.invalidateQueries({queryKey:["tags"]}),e.invalidateQueries({queryKey:["archives"]}),n(`Deleted "${D}" from ${P.affected} archive${P.affected!==1?"s":""}`),d(null)},onError:P=>{n(P.message||"Failed to delete tag","error")}}),g=P=>{o(P.name),c(P.name),d(null)},_=()=>{o(null),c("")},N=()=>{if(!s||!l.trim())return;const P=l.trim();if(P===s){_();return}v.mutate({oldName:s,newName:P})},T=P=>{P.key==="Enter"?(P.preventDefault(),N()):P.key==="Escape"&&(P.preventDefault(),_())},C=P=>{d(P),o(null)},A=()=>{u&&x.mutate(u)},k=f?.filter(P=>P.name.toLowerCase().includes(r.toLowerCase())).sort((P,D)=>m==="count"&&D.count-P.count||P.name.localeCompare(D.name)),R=f?.reduce((P,D)=>P+D.count,0)||0;return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:i.jsx(Mt,{className:"w-full max-w-lg max-h-[80vh] flex flex-col",children:i.jsxs(Dt,{className:"p-0 flex flex-col min-h-0",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Dd,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-xl font-semibold text-white",children:"Manage Tags"})]}),i.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex-shrink-0",children:[i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",placeholder:"Search tags...",className:"w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",value:r,onChange:P=>a(P.target.value)})]}),i.jsxs("select",{className:"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",value:m,onChange:P=>p(P.target.value),children:[i.jsx("option",{value:"count",children:"Sort by Count"}),i.jsx("option",{value:"name",children:"Sort by Name"})]})]}),f&&i.jsxs("p",{className:"text-xs text-bambu-gray mt-2",children:[f.length," tag",f.length!==1?"s":""," across ",R," usage",R!==1?"s":""]})]}),i.jsx("div",{className:"flex-1 overflow-y-auto min-h-0 p-4",children:y?i.jsx("div",{className:"flex items-center justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 animate-spin text-bambu-gray"})}):k?.length?i.jsx("div",{className:"space-y-2",children:k.map(P=>i.jsx("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors group",children:s===P.name?i.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[i.jsx("input",{type:"text",className:"flex-1 px-2 py-1 bg-bambu-dark-tertiary border border-bambu-green rounded text-white text-sm focus:outline-none",value:l,onChange:D=>c(D.target.value),onKeyDown:T,autoFocus:!0}),i.jsx(Oe,{size:"sm",variant:"primary",onClick:N,disabled:!l.trim()||v.isPending,className:"p-1.5",children:v.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Yr,{className:"w-4 h-4"})}),i.jsx(Oe,{size:"sm",variant:"ghost",onClick:_,className:"p-1.5",children:i.jsx(Ht,{className:"w-4 h-4"})})]}):u===P.name?i.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[i.jsx(Mn,{className:"w-4 h-4 text-yellow-400 flex-shrink-0"}),i.jsxs("span",{className:"text-sm text-bambu-gray-light flex-1",children:['Delete "',P.name,'" from ',P.count," archive",P.count!==1?"s":"","?"]}),i.jsx(Oe,{size:"sm",variant:"danger",onClick:A,disabled:x.isPending,className:"p-1.5",children:x.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Jt,{className:"w-4 h-4"})}),i.jsx(Oe,{size:"sm",variant:"ghost",onClick:()=>d(null),className:"p-1.5",children:i.jsx(Ht,{className:"w-4 h-4"})})]}):i.jsxs(i.Fragment,{children:[i.jsx(Dd,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),i.jsx("span",{className:"text-white flex-1 truncate",children:P.name}),i.jsx("span",{className:"px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray text-xs",children:P.count}),i.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[i.jsx("button",{onClick:()=>g(P),className:"p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors",title:"Rename tag",children:i.jsx(Yi,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>C(P.name),className:"p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors",title:"Delete tag",children:i.jsx(Jt,{className:"w-4 h-4"})})]})]})},P.name))}):i.jsx("div",{className:"text-center py-8 text-bambu-gray",children:r?"No tags match your search":"No tags found"})}),i.jsx("div",{className:"flex gap-3 p-4 border-t border-bambu-dark-tertiary flex-shrink-0",children:i.jsx(Oe,{variant:"secondary",onClick:t,className:"flex-1",children:"Close"})})]})})})}function Jm(t){const e=t.filename;if(e){const n=e.toLowerCase();if(n.endsWith(".gcode")||n.includes(".gcode."))return!0}return!!(t.total_layers||t.print_time_seconds)}function soe(t){if(!t)return;const e=t.toLowerCase();return e.endsWith(".3mf")?"3mf":e.endsWith(".stl")?"stl":e.endsWith(".gcode")||e.includes(".gcode.")?"gcode":e.split(".").pop()}async function eh(t,e,n,r){try{if(n==="source"){const{token:a}=await be.createSourceSlicerToken(t),s=be.getSourceSlicerDownloadUrl(t,a,e);Qp(`${window.location.origin}${s}`,r)}else{const{token:a}=await be.createArchiveSlicerToken(t),s=be.getArchiveSlicerDownloadUrl(t,a,e);Qp(`${window.location.origin}${s}`,r)}}catch{const a=n==="source"?be.getSource3mfForSlicer(t,e):be.getArchiveForSlicer(t,e);Qp(`${window.location.origin}${a}`,r)}}function rZe({archive:t,printerName:e,isSelected:n,onSelect:r,selectionMode:a,projects:s,isHighlighted:o,timeFormat:l="system",preferredSlicer:c="bambu_studio",currency:u,t:d,onNavigateToArchive:m}){o&&console.log("ArchiveCard isHighlighted=true for archive:",t.id);const p=an(),{showToast:f}=fn(),{hasPermission:y,canModify:v}=_r(),x=aie(),[g,_]=w.useState(!1),[N,T]=w.useState(!1),[C,A]=w.useState(!1),[k,R]=w.useState(!1),[P,D]=w.useState(!1),[H,z]=w.useState(!1),[G,I]=w.useState([]),[ee,ie]=w.useState(!1),[X,me]=w.useState(!1),[he,ge]=w.useState(!1),[Y,oe]=w.useState(!1),[le,xe]=w.useState(!1),[Pe,q]=w.useState(!1),[Z,j]=w.useState(!1),[E,U]=w.useState(null),[K,$]=w.useState(null),[ne,O]=w.useState(!1),V=w.useRef(null),J=w.useRef(null),W=w.useRef(null),{data:re}=et({queryKey:["archive-plates",t.id],queryFn:()=>be.getArchivePlates(t.id),enabled:ne,staleTime:300*1e3}),ue=t.duplicate_sequence??0,fe=t.original_archive_id??null,ye=re?.plates??[],ae=re?.is_multi_plate??!1,L=K??0,F=pt({mutationFn:()=>be.deleteArchiveTimelapse(t.id),onSuccess:()=>{p.invalidateQueries({queryKey:["archives"]}),f(d("archives.toast.timelapseRemoved"))},onError:ce=>{f(ce.message||d("archives.toast.failedRemoveTimelapse"),"error")}}),te=pt({mutationFn:ce=>be.uploadArchiveTimelapse(t.id,ce),onSuccess:ce=>{p.invalidateQueries({queryKey:["archives"]}),f(d("archives.toast.timelapseUploaded",{filename:ce.filename}))},onError:ce=>{f(ce.message||d("archives.toast.failedUploadTimelapse"),"error")}}),ve=pt({mutationFn:ce=>be.uploadSource3mf(t.id,ce),onSuccess:ce=>{p.invalidateQueries({queryKey:["archives"]}),f(d("archives.toast.source3mfAttached",{filename:ce.filename}))},onError:ce=>{f(ce.message||d("archives.toast.failedUploadSource3mf"),"error")}}),pe=pt({mutationFn:()=>be.deleteSource3mf(t.id),onSuccess:()=>{p.invalidateQueries({queryKey:["archives"]}),f(d("archives.toast.source3mfRemoved"))},onError:ce=>{f(ce.message||d("archives.toast.failedRemoveSource3mf"),"error")}}),de=pt({mutationFn:ce=>be.uploadF3d(t.id,ce),onSuccess:ce=>{p.invalidateQueries({queryKey:["archives"]}),f(d("archives.toast.f3dAttached",{filename:ce.filename}))},onError:ce=>{f(ce.message||d("archives.toast.failedUploadF3d"),"error")}}),Ne=pt({mutationFn:()=>be.deleteF3d(t.id),onSuccess:()=>{p.invalidateQueries({queryKey:["archives"]}),f(d("archives.toast.f3dRemoved"))},onError:ce=>{f(ce.message||d("archives.toast.failedRemoveF3d"),"error")}}),Se=pt({mutationFn:()=>be.scanArchiveTimelapse(t.id),onSuccess:ce=>{ce.status==="attached"?(p.invalidateQueries({queryKey:["archives"]}),f(d("archives.toast.timelapseAttached",{filename:ce.filename}))):ce.status==="exists"?f(d("archives.toast.timelapseAlreadyAttached")):ce.status==="not_found"&&ce.available_files&&ce.available_files.length>0?(I(ce.available_files),z(!0)):f(ce.message||d("archives.toast.noMatchingTimelapse"),"warning")},onError:ce=>{f(ce.message||d("archives.toast.failedScanTimelapse"),"error")}}),Le=pt({mutationFn:ce=>be.selectArchiveTimelapse(t.id,ce),onSuccess:ce=>{p.invalidateQueries({queryKey:["archives"]}),f(d("archives.toast.timelapseAttached",{filename:ce.filename})),z(!1),I([])},onError:ce=>{f(ce.message||d("archives.toast.failedAttachTimelapse"),"error")}}),qe=pt({mutationFn:()=>be.deleteArchive(t.id),onSuccess:()=>{p.invalidateQueries({queryKey:["archives"]}),f(d("archives.toast.archiveDeleted"))},onError:()=>{f(d("archives.toast.failedDeleteArchive"),"error")}}),Ee=pt({mutationFn:()=>be.toggleFavorite(t.id),onSuccess:ce=>{p.invalidateQueries({queryKey:["archives"]}),f(ce.is_favorite?d("archives.toast.addedToFavorites"):d("archives.toast.removedFromFavorites"))}}),{data:Te}=et({queryKey:["archive-folders",t.id],queryFn:()=>be.getLibraryFoldersByArchive(t.id)}),Ae=pt({mutationFn:ce=>be.updateArchive(t.id,{project_id:ce}),onSuccess:()=>{p.invalidateQueries({queryKey:["archives"]}),p.invalidateQueries({queryKey:["projects"]}),f(d("archives.toast.projectUpdated"))},onError:()=>{f(d("archives.toast.failedUpdateProject"),"error")}}),Be=ce=>{ce.preventDefault(),U({x:ce.clientX,y:ce.clientY})},Xe=[...Jm(t)?[{label:d("archives.menu.print"),icon:i.jsx(Sr,{className:"w-4 h-4"}),onClick:()=>T(!0),disabled:!t.file_path||!v("archives","reprint",t.created_by_id),title:t.file_path?v("archives","reprint",t.created_by_id)?void 0:d("archives.permission.noReprint"):d("archives.card.noFileForReprint")},{label:d("archives.menu.schedule"),icon:i.jsx(Wr,{className:"w-4 h-4"}),onClick:()=>oe(!0),disabled:!t.file_path||!y("queue:create"),title:t.file_path?y("queue:create")?void 0:d("archives.permission.noAddToQueue"):d("archives.card.noFileForReprint")},{label:d("archives.menu.openInBambuStudio"),icon:i.jsx(Jr,{className:"w-4 h-4"}),onClick:()=>{const ce=t.print_name||t.filename||"model";eh(t.id,ce,"file",c)},disabled:!t.file_path,title:t.file_path?void 0:d("archives.card.noFileForReprint")}]:[{label:d("archives.menu.slice"),icon:i.jsx(Jr,{className:"w-4 h-4"}),onClick:()=>{const ce=t.print_name||t.filename||"model";eh(t.id,ce,"file",c)}}],{label:t.external_url?d("archives.menu.externalLink"):d("archives.menu.viewOnMakerWorld"),icon:i.jsx(gh,{className:"w-4 h-4"}),onClick:()=>{const ce=t.external_url||t.makerworld_url;ce&&window.open(ce,"_blank")},disabled:!t.external_url&&!t.makerworld_url},{label:"",divider:!0,onClick:()=>{}},{label:d("archives.menu.preview3d"),icon:i.jsx(ra,{className:"w-4 h-4"}),onClick:()=>_(!0)},{label:d("archives.menu.viewTimelapse"),icon:i.jsx(fh,{className:"w-4 h-4"}),onClick:()=>D(!0),disabled:!t.timelapse_path},{label:d("archives.menu.scanForTimelapse"),icon:i.jsx(RN,{className:"w-4 h-4"}),onClick:()=>Se.mutate(),disabled:!t.printer_id||!!t.timelapse_path||Se.isPending||!v("archives","update",t.created_by_id),title:v("archives","update",t.created_by_id)?void 0:d("archives.permission.noUpdateArchives")},{label:d("archives.menu.uploadTimelapse"),icon:i.jsx(xi,{className:"w-4 h-4"}),onClick:()=>W.current?.click(),disabled:!!t.timelapse_path||!v("archives","update",t.created_by_id),title:v("archives","update",t.created_by_id)?void 0:d("archives.permission.noUpdateArchives")},...t.timelapse_path?[{label:d("archives.menu.removeTimelapse"),icon:i.jsx(Jt,{className:"w-4 h-4"}),onClick:()=>j(!0),danger:!0,disabled:!v("archives","update",t.created_by_id),title:v("archives","update",t.created_by_id)?void 0:d("archives.permission.noUpdateArchives")}]:[],{label:"",divider:!0,onClick:()=>{}},{label:t.source_3mf_path?d("archives.menu.downloadSource3mf"):d("archives.menu.uploadSource3mf"),icon:i.jsx(MN,{className:"w-4 h-4"}),onClick:()=>{t.source_3mf_path?be.downloadSource3mf(t.id).catch(ce=>{console.error("Source 3MF download failed:",ce)}):V.current?.click()},disabled:!t.source_3mf_path&&!v("archives","update",t.created_by_id),title:!t.source_3mf_path&&!v("archives","update",t.created_by_id)?d("archives.permission.noUploadFiles"):void 0},...t.source_3mf_path?[{label:d("archives.menu.replaceSource3mf"),icon:i.jsx(xi,{className:"w-4 h-4"}),onClick:()=>V.current?.click(),disabled:!v("archives","update",t.created_by_id),title:v("archives","update",t.created_by_id)?void 0:d("archives.permission.noUpdateArchives")},{label:d("archives.menu.removeSource3mf"),icon:i.jsx(Jt,{className:"w-4 h-4"}),onClick:()=>xe(!0),danger:!0,disabled:!v("archives","update",t.created_by_id),title:v("archives","update",t.created_by_id)?void 0:d("archives.permission.noUpdateArchives")}]:[],{label:t.f3d_path?d("archives.menu.replaceF3d"):d("archives.menu.uploadF3d"),icon:i.jsx(ra,{className:"w-4 h-4"}),onClick:()=>J.current?.click(),disabled:!v("archives","update",t.created_by_id),title:v("archives","update",t.created_by_id)?void 0:d("archives.permission.noUpdateArchives")},...t.f3d_path?[{label:d("archives.menu.downloadF3d"),icon:i.jsx(pi,{className:"w-4 h-4"}),onClick:()=>{be.downloadF3d(t.id).catch(ce=>{console.error("F3D download failed:",ce)})}},{label:d("archives.menu.removeF3d"),icon:i.jsx(Jt,{className:"w-4 h-4"}),onClick:()=>q(!0),danger:!0,disabled:!v("archives","update",t.created_by_id),title:v("archives","update",t.created_by_id)?void 0:d("archives.permission.noUpdateArchives")}]:[],{label:"",divider:!0,onClick:()=>{}},{label:d("archives.menu.download"),icon:i.jsx(pi,{className:"w-4 h-4"}),onClick:()=>{be.downloadArchive(t.id,`${t.print_name||t.filename}.3mf`).catch(ce=>{console.error("Archive download failed:",ce)})},disabled:!y("archives:read"),title:y("archives:read")?void 0:d("archives.permission.noDownload")},{label:d("archives.menu.copyDownloadLink"),icon:i.jsx(fo,{className:"w-4 h-4"}),onClick:()=>{const ce=`${window.location.origin}${be.getArchiveDownload(t.id)}`;navigator.clipboard.writeText(ce).then(()=>{f(d("archives.toast.linkCopied"))}).catch(()=>{f(d("archives.toast.failedCopyLink"),"error")})},disabled:!y("archives:read"),title:y("archives:read")?void 0:d("archives.permission.noCopyLink")},{label:d("archives.menu.qrCode"),icon:i.jsx(YX,{className:"w-4 h-4"}),onClick:()=>ie(!0)},{label:t.photos?.length?d("archives.menu.viewPhotosCount",{count:t.photos.length}):d("archives.menu.viewPhotos"),icon:i.jsx(rx,{className:"w-4 h-4"}),onClick:()=>me(!0),disabled:!t.photos?.length},{label:d("archives.menu.projectPage"),icon:i.jsx(Fs,{className:"w-4 h-4"}),onClick:()=>ge(!0)},{label:"",divider:!0,onClick:()=>{}},{label:t.is_favorite?d("archives.menu.removeFromFavorites"):d("archives.menu.addToFavorites"),icon:i.jsx(wf,{className:`w-4 h-4 ${t.is_favorite?"fill-yellow-400 text-yellow-400":""}`}),onClick:()=>Ee.mutate(),disabled:!v("archives","update",t.created_by_id),title:v("archives","update",t.created_by_id)?void 0:d("archives.permission.noUpdateArchives")},{label:d("archives.menu.edit"),icon:i.jsx(Yi,{className:"w-4 h-4"}),onClick:()=>R(!0),disabled:!v("archives","update",t.created_by_id),title:v("archives","update",t.created_by_id)?void 0:d("archives.permission.noUpdateArchives")},...t.project_id&&t.project_name?[{label:d("archives.menu.goToProject",{name:t.project_name}),icon:i.jsx(fs,{className:"w-4 h-4 text-bambu-green"}),onClick:()=>window.location.href="/projects"}]:[],{label:d("archives.menu.addToProject"),icon:i.jsx(fs,{className:"w-4 h-4"}),onClick:()=>{},disabled:!v("archives","update",t.created_by_id),title:v("archives","update",t.created_by_id)?void 0:d("archives.permission.noUpdateArchives"),submenu:(()=>{const ce=[];if(t.project_id&&ce.push({label:d("archives.menu.removeFromProject"),icon:i.jsx(Ht,{className:"w-4 h-4"}),onClick:()=>Ae.mutate(null),disabled:!v("archives","update",t.created_by_id)}),!s)ce.push({label:d("archives.menu.loading"),icon:i.jsx(ht,{className:"w-4 h-4 animate-spin"}),onClick:()=>{},disabled:!0});else{const Ie=s.filter(Ce=>Ce.status==="active");Ie.length===0?ce.push({label:d("archives.menu.noProjectsAvailable"),icon:i.jsx(fs,{className:"w-4 h-4 opacity-50"}),onClick:()=>{},disabled:!0}):Ie.forEach(Ce=>{ce.push({label:Ce.name,icon:i.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:Ce.color||"#888"}}),onClick:()=>Ae.mutate(Ce.id),disabled:t.project_id===Ce.id||!v("archives","update",t.created_by_id)})})}return ce})()},{label:d(n?"archives.menu.deselect":"archives.menu.select"),icon:n?i.jsx(xo,{className:"w-4 h-4"}):i.jsx(zl,{className:"w-4 h-4"}),onClick:()=>r(t.id)},{label:"",divider:!0,onClick:()=>{}},{label:d("archives.menu.delete"),icon:i.jsx(Jt,{className:"w-4 h-4"}),onClick:()=>A(!0),danger:!0,disabled:!v("archives","delete",t.created_by_id),title:v("archives","delete",t.created_by_id)?void 0:d("archives.permission.noDelete")}];return i.jsxs(Mt,{"data-archive-id":t.id,className:`relative flex flex-col group ${n?"ring-2 ring-bambu-green":""} ${a?"cursor-pointer":""}`,style:o?{outline:"4px solid #facc15",outlineOffset:"2px"}:void 0,onContextMenu:Be,onClick:a?()=>r(t.id):void 0,children:[a&&i.jsx("button",{className:"absolute top-2 left-2 z-10 p-1 rounded bg-black/50 hover:bg-black/70 transition-colors",onClick:ce=>{ce.stopPropagation(),r(t.id)},children:n?i.jsx(xo,{className:"w-5 h-5 text-bambu-green"}):i.jsx(zl,{className:"w-5 h-5 text-white"})}),i.jsxs("div",{className:"aspect-video bg-bambu-dark relative flex-shrink-0 overflow-hidden rounded-t-xl",onMouseEnter:()=>O(!0),onMouseLeave:()=>O(!1),children:[t.thumbnail_path?i.jsx("img",{src:K!==null&&ye.length>0?be.getArchivePlateThumbnail(t.id,ye[L]?.index??0):be.getArchiveThumbnail(t.id),alt:t.print_name||t.filename,className:"w-full h-full object-cover"}):i.jsx("div",{className:"w-full h-full flex items-center justify-center",children:i.jsx(Ed,{className:"w-12 h-12 text-bambu-dark-tertiary"})}),ae&&ye.length>1&&i.jsxs(i.Fragment,{children:[i.jsx("button",{className:`absolute left-1 top-1/2 -translate-y-1/2 p-1 rounded-full bg-black/60 hover:bg-black/80 transition-all ${x?"opacity-100":"opacity-0 group-hover:opacity-100"}`,onClick:ce=>{ce.stopPropagation(),$(Ie=>{const Ce=Ie??0;return Ce>0?Ce-1:ye.length-1})},title:d("archives.card.previousPlate"),children:i.jsx(Sc,{className:"w-4 h-4 text-white"})}),i.jsx("button",{className:`absolute right-1 top-1/2 -translate-y-1/2 p-1 rounded-full bg-black/60 hover:bg-black/80 transition-all ${x?"opacity-100":"opacity-0 group-hover:opacity-100"}`,onClick:ce=>{ce.stopPropagation(),$(Ie=>{const Ce=Ie??0;return Cei.jsx("button",{className:`w-2 h-2 rounded-full transition-colors ${Ie===L?"bg-bambu-green":"bg-white/50 hover:bg-white/80"}`,onClick:Ce=>{Ce.stopPropagation(),$(Ie)},title:ce.name||d("archives.card.plateNumber",{index:ce.index})},ce.index))})]}),i.jsx("button",{className:`absolute top-2 left-2 p-1.5 rounded bg-black/50 hover:bg-black/70 transition-all ${x?"opacity-100":"opacity-0 group-hover:opacity-100"} ${a?"left-10":""}`,onClick:ce=>{ce.stopPropagation();const Ie=ce.currentTarget.getBoundingClientRect();U({x:Ie.left,y:Ie.bottom+4})},title:d("archives.card.moreOptions"),children:i.jsx(ph,{className:"w-5 h-5 text-white"})}),i.jsx("button",{className:`absolute top-2 right-2 p-1 rounded transition-colors ${v("archives","update",t.created_by_id)?"bg-black/50 hover:bg-black/70":"bg-black/30 cursor-not-allowed"}`,onClick:ce=>{ce.stopPropagation(),v("archives","update",t.created_by_id)&&Ee.mutate()},disabled:!v("archives","update",t.created_by_id),title:v("archives","update",t.created_by_id)?t.is_favorite?d("archives.card.removeFromFavorites"):d("archives.card.addToFavorites"):d("archives.permission.noUpdateArchives"),children:i.jsx(wf,{className:`w-5 h-5 ${t.is_favorite?"text-yellow-400 fill-yellow-400":"text-white"} ${v("archives","update",t.created_by_id)?"":"opacity-50"}`})}),(t.status==="failed"||t.status==="aborted")&&i.jsx("div",{className:"absolute top-2 left-12 px-2 py-1 rounded text-xs bg-status-error/80 text-white",children:t.status==="aborted"?d("archives.card.cancelled"):d("archives.card.failed")}),t.duplicate_count>0&&ue>0&&fe&&i.jsxs("button",{onClick:ce=>{ce.stopPropagation(),m?.(fe)},className:"absolute top-2 right-12 px-2 py-1 rounded text-xs bg-purple-500/80 hover:bg-purple-600/90 text-white flex items-center gap-1 transition-colors cursor-pointer",title:d("archives.viewOriginalPrint",{id:fe}),children:[i.jsx(fo,{className:"w-3 h-3"}),"#",ue]}),t.duplicate_count>0&&ue===0&&i.jsxs("span",{className:"absolute top-2 right-12 px-2 py-1 rounded text-xs bg-purple-500/80 text-white flex items-center gap-1",title:`${t.duplicate_count} reprint${t.duplicate_count===1?"":"s"}`,children:[i.jsx(VX,{className:"w-3 h-3"}),"+",t.duplicate_count]}),t.source_3mf_path&&i.jsx("button",{className:"absolute bottom-2 left-2 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors",onClick:ce=>{ce.stopPropagation();const Ie=(t.print_name||t.filename||"source").replace(/\.gcode\.3mf$/i,"")+"_source";eh(t.id,Ie,"source",c)},title:d("archives.card.openSource3mf"),children:i.jsx(MN,{className:"w-4 h-4 text-orange-400"})}),t.f3d_path&&i.jsx("button",{className:`absolute bottom-2 ${t.source_3mf_path?"left-12":"left-2"} p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:ce=>{ce.stopPropagation(),be.downloadF3d(t.id).catch(Ie=>{console.error("F3D download failed:",Ie)})},title:d("archives.card.downloadF3d"),children:i.jsx(ra,{className:"w-4 h-4 text-cyan-400"})}),i.jsx("button",{className:"absolute bottom-2 right-2 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors",onClick:ce=>{ce.stopPropagation(),_(!0)},title:d("archives.card.preview3d"),children:i.jsx(Gi,{className:"w-4 h-4 text-white"})}),t.timelapse_path&&i.jsx("button",{className:"absolute bottom-2 right-12 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors",onClick:ce=>{ce.stopPropagation(),D(!0)},title:d("archives.card.viewTimelapse"),children:i.jsx(fh,{className:"w-4 h-4 text-bambu-green"})}),t.photos&&t.photos.length>0&&i.jsxs("button",{className:`absolute bottom-2 ${t.timelapse_path?"right-[5.5rem]":"right-12"} p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:ce=>{ce.stopPropagation(),me(!0)},title:t.photos.length===1?d("archives.card.viewPhoto"):d("archives.card.viewPhotos",{count:t.photos.length}),children:[i.jsx(rx,{className:"w-4 h-4 text-blue-400"}),t.photos.length>1&&i.jsx("span",{className:"absolute -top-1 -right-1 w-4 h-4 bg-blue-500 rounded-full text-[10px] text-white flex items-center justify-center",children:t.photos.length})]}),Te&&Te.length>0&&i.jsx(io,{to:`/files?folder=${Te[0].id}`,className:"absolute bottom-2 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors",onClick:ce=>ce.stopPropagation(),title:d("archives.card.openFolder",{name:Te[0].name}),style:{left:t.source_3mf_path?t.f3d_path?"5.5rem":"3rem":t.f3d_path?"3rem":"0.5rem"},children:i.jsx(Nc,{className:"w-4 h-4 text-yellow-400"})})]}),i.jsxs(Dt,{className:"p-4 flex-1 flex flex-col",children:[i.jsxs("p",{className:"text-[10px] text-bambu-gray/70 mb-1",children:["#",t.id]}),i.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1",children:[i.jsx("h3",{className:"min-w-0 font-medium text-white truncate",children:t.print_name||t.filename}),i.jsx(Oe,{variant:"ghost",size:"sm",className:"p-1 sm:p-1.5 shrink-0",onClick:()=>R(!0),disabled:!v("archives","update",t.created_by_id),title:v("archives","update",t.created_by_id)?d("archives.card.edit"):d("archives.card.noPermissionEdit"),children:i.jsx(Yi,{className:"w-3 h-3 sm:w-4 sm:h-4"})})]}),i.jsxs("div",{className:"flex items-center gap-2 mb-3 flex-wrap",children:[i.jsx("p",{className:"text-xs text-bambu-gray",children:e}),i.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${Jm(t)?"bg-bambu-green/20 text-bambu-green":"bg-orange-500/20 text-orange-400"}`,title:Jm(t)?d("archives.card.slicedFile"):d("archives.card.sourceFile"),children:Jm(t)?d("archives.card.gcode"):d("archives.card.source")}),t.content_hash&&i.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded font-mono bg-bambu-dark-tertiary/50 text-bambu-gray-light opacity-0 transition-opacity duration-150 group-hover:opacity-100",title:`SHA256: ${t.content_hash}`,children:t.content_hash.slice(0,8).toUpperCase()}),t.project_name&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full truncate max-w-[120px]",style:{backgroundColor:`${s?.find(ce=>ce.id===t.project_id)?.color||"#6b7280"}20`,color:s?.find(ce=>ce.id===t.project_id)?.color||"#6b7280"},title:d("archives.card.project",{name:t.project_name}),children:t.project_name})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs mb-4 min-h-[48px]",children:[(t.print_time_seconds||t.actual_time_seconds)&&i.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",title:t.time_accuracy?`Estimated: ${Rs(t.print_time_seconds||0)} Actual: ${Rs(t.actual_time_seconds||0)} -Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${Rs(t.actual_time_seconds)}`:`Estimated: ${Rs(t.print_time_seconds||0)}`,children:[i.jsx(er,{className:"w-3 h-3"}),Rs(t.actual_time_seconds||t.print_time_seconds||0),t.time_accuracy&&i.jsxs("span",{className:`text-[10px] px-1 rounded ${t.time_accuracy>=95&&t.time_accuracy<=105?"bg-bambu-green/20 text-bambu-green":t.time_accuracy>105?"bg-blue-500/20 text-blue-400":"bg-orange-500/20 text-orange-400"}`,children:[t.time_accuracy>100?"+":"",(t.time_accuracy-100).toFixed(0),"%"]})]}),t.filament_used_grams&&i.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",children:[i.jsx(Wi,{className:"w-3 h-3"}),t.filament_used_grams.toFixed(1),"g"]}),(t.cost!=null||t.energy_cost!=null)&&i.jsxs("div",{className:"flex items-center gap-3 text-bambu-gray",children:[t.cost!=null&&i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx(ppe,{className:"w-3 h-3"}),u,t.cost.toFixed(2)]}),t.energy_cost!=null&&i.jsxs("div",{className:"flex items-center gap-1.5",title:`${d("stats.energyUsed")}: ${t.energy_kwh?.toFixed(3)||"N/A"} kWh`,children:[i.jsx(kc,{className:"w-3 h-3"}),u,t.energy_cost.toFixed(2)]})]}),(t.layer_height||t.total_layers)&&i.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",children:[i.jsx(Gi,{className:"w-3 h-3"}),t.total_layers&&i.jsx("span",{children:t.total_layers===1?d("archives.card.layer",{count:t.total_layers}):d("archives.card.layers",{count:t.total_layers})}),t.total_layers&&t.layer_height&&i.jsx("span",{className:"text-bambu-gray/50",children:"·"}),t.layer_height&&i.jsxs("span",{children:[t.layer_height,"mm"]})]}),t.object_count!=null&&t.object_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",title:t.object_count===1?d("archives.card.object",{count:t.object_count}):d("archives.card.objects",{count:t.object_count}),children:[i.jsx(ra,{className:"w-3 h-3"}),t.object_count===1?d("archives.card.object",{count:t.object_count}):d("archives.card.objects",{count:t.object_count})]}),t.sliced_for_model&&i.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",title:d("archives.card.slicedFor",{model:t.sliced_for_model}),children:[i.jsx(Sr,{className:"w-3 h-3"}),t.sliced_for_model]}),t.filament_type&&i.jsxs("div",{className:"flex items-center gap-1.5 col-span-2",children:[i.jsx("span",{className:"text-bambu-gray text-xs",children:t.filament_type}),t.filament_color&&i.jsx("div",{className:"flex items-center gap-0.5 flex-wrap",children:t.filament_color.split(",").map((ce,Ie)=>i.jsx("div",{className:"w-3 h-3 rounded-full border border-white/20",style:{backgroundColor:ce},title:ce},Ie))})]})]}),(t.tags||t.notes)&&i.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-3",children:[t.notes&&i.jsx("div",{className:"flex items-center gap-1 px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded text-xs",title:t.notes,children:i.jsx(ZX,{className:"w-3 h-3"})}),t.tags?.split(",").map((ce,Ie)=>i.jsx("span",{className:"px-1.5 py-0.5 bg-bambu-dark-tertiary text-bambu-gray-light rounded text-xs",children:ce.trim()},Ie))]}),i.jsx("div",{className:"flex-1"}),i.jsxs("div",{className:"flex items-center justify-between text-xs text-bambu-gray border-t border-bambu-dark-tertiary pt-3",children:[i.jsx("span",{children:Nf(t.created_at,l)}),i.jsxs("div",{className:"flex items-center gap-2",children:[t.created_by_username&&i.jsxs("span",{className:"flex items-center gap-1",title:d("archives.card.uploadedBy",{name:t.created_by_username}),children:[i.jsx(Rd,{className:"w-3 h-3"}),t.created_by_username]}),i.jsx("span",{children:oo(t.file_size)})]})]}),i.jsxs("div",{className:"flex gap-1 mt-3",children:[Jm(t)?i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"primary",size:"sm",className:"flex-1 min-w-0 overflow-hidden",onClick:()=>T(!0),disabled:!t.file_path||!v("archives","reprint",t.created_by_id),title:t.file_path?v("archives","reprint",t.created_by_id)?void 0:d("archives.card.noPermissionReprint"):d("archives.card.noFileForReprint"),children:[i.jsx(Sr,{className:"w-3 h-3 flex-shrink-0"}),i.jsx("span",{className:"hidden sm:inline truncate",children:d("archives.card.reprint")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",className:"flex-1 min-w-0 overflow-hidden",onClick:()=>oe(!0),disabled:!t.file_path||!y("queue:create"),title:t.file_path?y("queue:create")?d("archives.card.schedulePrint"):d("archives.permission.noAddToQueue"):d("archives.card.noFileForReprint"),children:[i.jsx(Wr,{className:"w-3 h-3 flex-shrink-0"}),i.jsx("span",{className:"hidden sm:inline truncate",children:d("archives.card.schedule")})]}),i.jsx(Oe,{variant:"secondary",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>{const ce=t.print_name||t.filename||"model";eh(t.id,ce,"file",c)},title:d("archives.card.openInBambuStudio"),children:i.jsx(Jr,{className:"w-3 h-3 sm:w-4 sm:h-4"})})]}):i.jsxs(Oe,{variant:"primary",size:"sm",className:"flex-1 min-w-0 overflow-hidden",onClick:()=>{const ce=t.print_name||t.filename||"model";eh(t.id,ce,"file",c)},title:d("archives.card.openInBambuStudioToSlice"),children:[i.jsx(Jr,{className:"w-3 h-3 flex-shrink-0"}),i.jsx("span",{className:"hidden sm:inline truncate",children:d("archives.card.slice")})]}),i.jsx(Oe,{variant:"secondary",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>{const ce=t.external_url||t.makerworld_url;ce&&window.open(ce,"_blank")},disabled:!t.external_url&&!t.makerworld_url,title:t.external_url?d("archives.card.externalLink"):t.makerworld_url?d("archives.card.makerWorld",{designer:t.designer||d("archives.card.viewProject")}):d("archives.card.noExternalLink"),children:i.jsx(gh,{className:`w-3 h-3 sm:w-4 sm:h-4 ${!t.external_url&&!t.makerworld_url?"opacity-20":""}`})}),i.jsx(Oe,{variant:"secondary",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>{be.downloadArchive(t.id,`${t.print_name||t.filename}.3mf`).catch(ce=>{console.error("Archive download failed:",ce)})},title:d("archives.card.download"),children:i.jsx(pi,{className:"w-3 h-3 sm:w-4 sm:h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>A(!0),disabled:!v("archives","delete",t.created_by_id),title:v("archives","delete",t.created_by_id)?d("archives.card.delete"):d("archives.card.noPermissionDelete"),children:i.jsx(Jt,{className:"w-3 h-3 sm:w-4 sm:h-4 text-red-400"})})]})]}),k&&i.jsx(sie,{archive:t,onClose:()=>R(!1)}),g&&i.jsx(M4,{archiveId:t.id,title:t.print_name||t.filename,fileType:soe(t.filename),onClose:()=>_(!1)}),N&&i.jsx(uu,{mode:"reprint",archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>T(!1)}),C&&i.jsx(Sn,{title:d("archives.modal.deleteArchive"),message:d("archives.modal.deleteConfirm",{name:t.print_name||t.filename}),confirmText:d("archives.modal.deleteButton"),variant:"danger",onConfirm:()=>{qe.mutate(),A(!1)},onCancel:()=>A(!1)}),le&&i.jsx(Sn,{title:d("archives.modal.removeSource3mf"),message:d("archives.modal.removeSource3mfConfirm",{name:t.print_name||t.filename}),confirmText:d("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{pe.mutate(),xe(!1)},onCancel:()=>xe(!1)}),Pe&&i.jsx(Sn,{title:d("archives.modal.removeF3d"),message:d("archives.modal.removeF3dConfirm",{name:t.print_name||t.filename}),confirmText:d("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{Ne.mutate(),q(!1)},onCancel:()=>q(!1)}),Z&&i.jsx(Sn,{title:d("archives.modal.removeTimelapse"),message:d("archives.modal.removeTimelapseConfirm",{name:t.print_name||t.filename}),confirmText:d("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{F.mutate(),j(!1)},onCancel:()=>j(!1)}),E&&i.jsx(oie,{x:E.x,y:E.y,items:Xe,onClose:()=>U(null)}),P&&t.timelapse_path&&i.jsx(aoe,{src:be.getArchiveTimelapse(t.id),title:d("archives.modal.timelapse",{name:t.print_name||t.filename}),downloadFilename:`${t.print_name||t.filename}_timelapse.mp4`,archiveId:t.id,onClose:()=>D(!1),onEdit:()=>{p.invalidateQueries({queryKey:["archives"]}),D(!1)}}),H&&G.length>0&&i.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-card-dark rounded-lg max-w-lg w-full max-h-[80vh] flex flex-col",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-700",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:d("archives.modal.selectTimelapse")}),i.jsx("p",{className:"text-sm text-gray-400 mt-1",children:d("archives.modal.selectTimelapseDesc")})]}),i.jsx("button",{onClick:()=>{z(!1),I([])},className:"text-gray-400 hover:text-white p-1",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsx("div",{className:"overflow-y-auto flex-1 p-2",children:G.map(ce=>i.jsxs("button",{onClick:()=>Le.mutate(ce.name),disabled:Le.isPending,className:"w-full text-left p-3 rounded-lg hover:bg-gray-700 transition-colors flex items-center gap-3 disabled:opacity-50",children:[i.jsx(fh,{className:"w-8 h-8 text-bambu-green flex-shrink-0"}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-white font-medium truncate",children:ce.name}),i.jsxs("p",{className:"text-sm text-gray-400",children:[oo(ce.size),ce.mtime&&` • ${Nf(ce.mtime,l)}`]})]})]},ce.name))}),i.jsx("div",{className:"p-4 border-t border-gray-700",children:i.jsx(Oe,{variant:"secondary",onClick:()=>{z(!1),I([])},className:"w-full",children:"Cancel"})})]})}),ee&&i.jsx(lie,{archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>ie(!1)}),X&&t.photos&&t.photos.length>0&&i.jsx(cie,{archiveId:t.id,archiveName:t.print_name||t.filename,photos:t.photos,onClose:()=>me(!1),onDelete:async ce=>{try{await be.deleteArchivePhoto(t.id,ce),p.invalidateQueries({queryKey:["archives"]}),f(d("archives.toast.photoDeleted"))}catch{f(d("archives.toast.failedDeletePhoto"),"error")}}}),he&&i.jsx(ioe,{archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>ge(!1)}),Y&&i.jsx(uu,{mode:"add-to-queue",archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>oe(!1)}),i.jsx("input",{ref:V,type:"file",accept:".3mf",className:"hidden",onChange:ce=>{const Ie=ce.target.files?.[0];Ie&&ve.mutate(Ie),ce.target.value=""}}),i.jsx("input",{ref:J,type:"file",accept:".f3d",className:"hidden",onChange:ce=>{const Ie=ce.target.files?.[0];Ie&&de.mutate(Ie),ce.target.value=""}}),i.jsx("input",{ref:W,type:"file",accept:".mp4,.avi,.mkv",className:"hidden",onChange:ce=>{const Ie=ce.target.files?.[0];Ie&&te.mutate(Ie),ce.target.value=""}})]})}function iZe({archive:t,printerName:e,isSelected:n,onSelect:r,selectionMode:a,projects:s,isHighlighted:o,preferredSlicer:l="bambu_studio",t:c,onNavigateToArchive:u}){const d=an(),{showToast:m}=fn(),{hasPermission:p,canModify:f}=_r(),[y,v]=w.useState(!1),[x,g]=w.useState(!1),[_,N]=w.useState(!1),[T,C]=w.useState(!1),[A,k]=w.useState(!1),[R,P]=w.useState(!1),[D,H]=w.useState(!1),[z,G]=w.useState([]),[I,ee]=w.useState(!1),[ie,X]=w.useState(!1),[me,he]=w.useState(!1),[ge,Y]=w.useState(!1),[oe,le]=w.useState(!1),[xe,Pe]=w.useState(!1),[q,Z]=w.useState(null),j=w.useRef(null),E=w.useRef(null),U=w.useRef(null),K=t.duplicate_sequence??0,$=t.original_archive_id??null,ne=pt({mutationFn:()=>be.deleteArchiveTimelapse(t.id),onSuccess:()=>{d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.timelapseRemoved"))},onError:de=>{m(de.message||c("archives.toast.failedRemoveTimelapse"),"error")}}),O=pt({mutationFn:de=>be.uploadArchiveTimelapse(t.id,de),onSuccess:de=>{d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.timelapseUploaded",{filename:de.filename}))},onError:de=>{m(de.message||c("archives.toast.failedUploadTimelapse"),"error")}}),V=pt({mutationFn:de=>be.uploadSource3mf(t.id,de),onSuccess:de=>{d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.source3mfAttached",{filename:de.filename}))},onError:de=>{m(de.message||c("archives.toast.failedUploadSource3mf"),"error")}}),J=pt({mutationFn:()=>be.deleteSource3mf(t.id),onSuccess:()=>{d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.source3mfRemoved"))},onError:de=>{m(de.message||c("archives.toast.failedRemoveSource3mf"),"error")}}),W=pt({mutationFn:de=>be.uploadF3d(t.id,de),onSuccess:de=>{d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.f3dAttached",{filename:de.filename}))},onError:de=>{m(de.message||c("archives.toast.failedUploadF3d"),"error")}}),re=pt({mutationFn:()=>be.deleteF3d(t.id),onSuccess:()=>{d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.f3dRemoved"))},onError:de=>{m(de.message||c("archives.toast.failedRemoveF3d"),"error")}}),ue=pt({mutationFn:()=>be.scanArchiveTimelapse(t.id),onSuccess:de=>{de.status==="attached"?(d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.timelapseAttached",{filename:de.filename}))):de.status==="exists"?m(c("archives.toast.timelapseAlreadyAttached")):de.status==="not_found"&&de.available_files&&de.available_files.length>0?(G(de.available_files),H(!0)):m(de.message||c("archives.toast.noMatchingTimelapse"),"warning")},onError:de=>{m(de.message||c("archives.toast.failedScanTimelapse"),"error")}}),fe=pt({mutationFn:de=>be.selectArchiveTimelapse(t.id,de),onSuccess:de=>{d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.timelapseAttached",{filename:de.filename})),H(!1),G([])},onError:de=>{m(de.message||c("archives.toast.failedAttachTimelapse"),"error")}}),ye=pt({mutationFn:()=>be.deleteArchive(t.id),onSuccess:()=>{d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.archiveDeleted"))},onError:()=>{m(c("archives.toast.failedDeleteArchive"),"error")}}),ae=pt({mutationFn:()=>be.toggleFavorite(t.id),onSuccess:de=>{d.invalidateQueries({queryKey:["archives"]}),m(de.is_favorite?c("archives.toast.addedToFavorites"):c("archives.toast.removedFromFavorites"))}}),{data:L}=et({queryKey:["archive-folders",t.id],queryFn:()=>be.getLibraryFoldersByArchive(t.id)}),F=pt({mutationFn:de=>be.updateArchive(t.id,{project_id:de}),onSuccess:()=>{d.invalidateQueries({queryKey:["archives"]}),d.invalidateQueries({queryKey:["projects"]}),m(c("archives.toast.projectUpdated"))},onError:()=>{m(c("archives.toast.failedUpdateProject"),"error")}}),te=de=>{de.preventDefault(),Z({x:de.clientX,y:de.clientY})},pe=[...Jm(t)?[{label:c("archives.menu.print"),icon:i.jsx(Sr,{className:"w-4 h-4"}),onClick:()=>N(!0),disabled:!t.file_path||!f("archives","reprint",t.created_by_id),title:t.file_path?f("archives","reprint",t.created_by_id)?void 0:c("archives.permission.noReprint"):c("archives.card.noFileForReprint")},{label:c("archives.menu.schedule"),icon:i.jsx(Wr,{className:"w-4 h-4"}),onClick:()=>C(!0),disabled:!t.file_path||!p("queue:create"),title:t.file_path?p("queue:create")?void 0:c("archives.permission.noAddToQueue"):c("archives.card.noFileForReprint")},{label:c("archives.menu.openInBambuStudio"),icon:i.jsx(Jr,{className:"w-4 h-4"}),onClick:()=>{const de=t.print_name||t.filename||"model";eh(t.id,de,"file",l)},disabled:!t.file_path,title:t.file_path?void 0:c("archives.card.noFileForReprint")}]:[{label:c("archives.menu.slice"),icon:i.jsx(Jr,{className:"w-4 h-4"}),onClick:()=>{const de=t.print_name||t.filename||"model";eh(t.id,de,"file",l)}}],{label:t.external_url?c("archives.menu.externalLink"):c("archives.menu.viewOnMakerWorld"),icon:i.jsx(gh,{className:"w-4 h-4"}),onClick:()=>{const de=t.external_url||t.makerworld_url;de&&window.open(de,"_blank")},disabled:!t.external_url&&!t.makerworld_url},{label:"",divider:!0,onClick:()=>{}},{label:c("archives.menu.preview3d"),icon:i.jsx(ra,{className:"w-4 h-4"}),onClick:()=>k(!0)},{label:c("archives.menu.viewTimelapse"),icon:i.jsx(fh,{className:"w-4 h-4"}),onClick:()=>P(!0),disabled:!t.timelapse_path},{label:c("archives.menu.scanForTimelapse"),icon:i.jsx(RN,{className:"w-4 h-4"}),onClick:()=>ue.mutate(),disabled:!t.printer_id||!!t.timelapse_path||ue.isPending||!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")},{label:c("archives.menu.uploadTimelapse"),icon:i.jsx(xi,{className:"w-4 h-4"}),onClick:()=>U.current?.click(),disabled:!!t.timelapse_path||!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")},...t.timelapse_path?[{label:c("archives.menu.removeTimelapse"),icon:i.jsx(Jt,{className:"w-4 h-4"}),onClick:()=>Pe(!0),danger:!0,disabled:!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")}]:[],{label:"",divider:!0,onClick:()=>{}},{label:t.source_3mf_path?c("archives.menu.downloadSource3mf"):c("archives.menu.uploadSource3mf"),icon:i.jsx(MN,{className:"w-4 h-4"}),onClick:()=>{t.source_3mf_path?be.downloadSource3mf(t.id).catch(de=>{console.error("Source 3MF download failed:",de)}):j.current?.click()},disabled:!t.source_3mf_path&&!f("archives","update",t.created_by_id),title:!t.source_3mf_path&&!f("archives","update",t.created_by_id)?c("archives.permission.noUploadFiles"):void 0},...t.source_3mf_path?[{label:c("archives.menu.replaceSource3mf"),icon:i.jsx(xi,{className:"w-4 h-4"}),onClick:()=>j.current?.click(),disabled:!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")},{label:c("archives.menu.removeSource3mf"),icon:i.jsx(Jt,{className:"w-4 h-4"}),onClick:()=>Y(!0),danger:!0,disabled:!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")}]:[],{label:t.f3d_path?c("archives.menu.replaceF3d"):c("archives.menu.uploadF3d"),icon:i.jsx(ra,{className:"w-4 h-4"}),onClick:()=>E.current?.click(),disabled:!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")},...t.f3d_path?[{label:c("archives.menu.downloadF3d"),icon:i.jsx(pi,{className:"w-4 h-4"}),onClick:()=>{be.downloadF3d(t.id).catch(de=>{console.error("F3D download failed:",de)})}},{label:c("archives.menu.removeF3d"),icon:i.jsx(Jt,{className:"w-4 h-4"}),onClick:()=>le(!0),danger:!0,disabled:!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")}]:[],{label:"",divider:!0,onClick:()=>{}},{label:c("archives.menu.download"),icon:i.jsx(pi,{className:"w-4 h-4"}),onClick:()=>{be.downloadArchive(t.id,`${t.print_name||t.filename}.3mf`).catch(de=>{console.error("Archive download failed:",de)})},disabled:!p("archives:read"),title:p("archives:read")?void 0:c("archives.permission.noDownload")},{label:c("archives.menu.copyDownloadLink"),icon:i.jsx(fo,{className:"w-4 h-4"}),onClick:()=>{const de=`${window.location.origin}${be.getArchiveDownload(t.id)}`;navigator.clipboard.writeText(de).then(()=>{m(c("archives.toast.linkCopied"))}).catch(()=>{m(c("archives.toast.failedCopyLink"),"error")})},disabled:!p("archives:read"),title:p("archives:read")?void 0:c("archives.permission.noCopyLink")},{label:c("archives.menu.qrCode"),icon:i.jsx(YX,{className:"w-4 h-4"}),onClick:()=>ee(!0)},{label:t.photos?.length?c("archives.menu.viewPhotosCount",{count:t.photos.length}):c("archives.menu.viewPhotos"),icon:i.jsx(rx,{className:"w-4 h-4"}),onClick:()=>X(!0),disabled:!t.photos?.length},{label:c("archives.menu.projectPage"),icon:i.jsx(Fs,{className:"w-4 h-4"}),onClick:()=>he(!0)},{label:"",divider:!0,onClick:()=>{}},{label:t.is_favorite?c("archives.menu.removeFromFavorites"):c("archives.menu.addToFavorites"),icon:i.jsx(wf,{className:`w-4 h-4 ${t.is_favorite?"fill-yellow-400 text-yellow-400":""}`}),onClick:()=>ae.mutate(),disabled:!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")},{label:c("archives.menu.edit"),icon:i.jsx(Yi,{className:"w-4 h-4"}),onClick:()=>v(!0),disabled:!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")},...t.project_id&&t.project_name?[{label:c("archives.menu.goToProject",{name:t.project_name}),icon:i.jsx(fs,{className:"w-4 h-4 text-bambu-green"}),onClick:()=>window.location.href="/projects"}]:[],{label:c("archives.menu.addToProject"),icon:i.jsx(fs,{className:"w-4 h-4"}),onClick:()=>{},submenu:(()=>{const de=[];if(t.project_id&&de.push({label:c("archives.menu.removeFromProject"),icon:i.jsx(Ht,{className:"w-4 h-4"}),onClick:()=>F.mutate(null)}),!s)de.push({label:c("archives.menu.loading"),icon:i.jsx(ht,{className:"w-4 h-4 animate-spin"}),onClick:()=>{},disabled:!0});else{const Ne=s.filter(Se=>Se.status==="active");Ne.length===0?de.push({label:c("archives.menu.noProjectsAvailable"),icon:i.jsx(fs,{className:"w-4 h-4 opacity-50"}),onClick:()=>{},disabled:!0}):Ne.forEach(Se=>{de.push({label:Se.name,icon:i.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:Se.color||"#888"}}),onClick:()=>F.mutate(Se.id),disabled:t.project_id===Se.id})})}return de})()},{label:c(n?"archives.menu.deselect":"archives.menu.select"),icon:n?i.jsx(xo,{className:"w-4 h-4"}):i.jsx(zl,{className:"w-4 h-4"}),onClick:()=>r(t.id)},{label:"",divider:!0,onClick:()=>{}},{label:c("archives.menu.delete"),icon:i.jsx(Jt,{className:"w-4 h-4"}),onClick:()=>g(!0),danger:!0,disabled:!f("archives","delete",t.created_by_id),title:f("archives","delete",t.created_by_id)?void 0:c("archives.permission.noDelete")}];return i.jsxs(i.Fragment,{children:[i.jsxs("div",{"data-archive-id":t.id,className:`grid grid-cols-12 gap-4 px-4 py-3 items-center hover:bg-bambu-dark-tertiary/30 ${n?"bg-bambu-green/10":""}`,style:o?{outline:"4px solid #facc15",outlineOffset:"-4px"}:void 0,onContextMenu:te,children:[i.jsxs("div",{className:"col-span-1 flex items-center gap-2",children:[a&&i.jsx("button",{onClick:()=>r(t.id),children:n?i.jsx(xo,{className:"w-4 h-4 text-bambu-green"}):i.jsx(zl,{className:"w-4 h-4 text-bambu-gray"})}),t.thumbnail_path?i.jsx("img",{src:be.getArchiveThumbnail(t.id),alt:"",className:"w-10 h-10 object-cover rounded"}):i.jsx("div",{className:"w-10 h-10 bg-bambu-dark rounded flex items-center justify-center",children:i.jsx(Ed,{className:"w-5 h-5 text-bambu-dark-tertiary"})})]}),i.jsxs("div",{className:"col-span-4",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("p",{className:"text-white text-sm truncate",children:t.print_name||t.filename}),(t.status==="failed"||t.status==="aborted")&&i.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] leading-tight bg-status-error/80 text-white flex-shrink-0",children:t.status==="aborted"?c("archives.card.cancelled"):c("archives.card.failed")}),t.duplicate_count>0&&K>0&&$&&i.jsxs("button",{onClick:de=>{de.stopPropagation(),u?.($)},className:"px-1.5 py-0.5 rounded text-[10px] leading-tight bg-purple-500/80 hover:bg-purple-600/90 text-white flex-shrink-0 transition-colors flex items-center gap-1",title:c("archives.viewOriginalPrint",{id:$}),children:[i.jsx(fo,{className:"w-3 h-3"}),"#",K]}),t.duplicate_count>0&&K===0&&i.jsxs("span",{className:"px-1.5 py-0.5 rounded text-[10px] leading-tight bg-purple-500/80 text-white flex-shrink-0 flex items-center gap-1",title:`${t.duplicate_count} reprint${t.duplicate_count===1?"":"s"}`,children:[i.jsx(VX,{className:"w-3 h-3"}),"+",t.duplicate_count]}),t.timelapse_path&&i.jsx("span",{title:c("archives.list.hasTimelapse"),children:i.jsx(fh,{className:"w-3.5 h-3.5 text-bambu-green flex-shrink-0"})}),L&&L.length>0&&i.jsx(io,{to:`/files?folder=${L[0].id}`,className:"flex-shrink-0",title:c("archives.card.openFolder",{name:L[0].name}),onClick:de=>de.stopPropagation(),children:i.jsx(Nc,{className:"w-3.5 h-3.5 text-yellow-400"})})]}),(t.filament_type||t.sliced_for_model)&&i.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[t.sliced_for_model&&i.jsxs("span",{className:"text-xs text-bambu-gray flex items-center gap-1",title:c("archives.card.slicedFor",{model:t.sliced_for_model}),children:[i.jsx(Sr,{className:"w-2.5 h-2.5"}),t.sliced_for_model]}),t.sliced_for_model&&t.filament_type&&i.jsx("span",{className:"text-bambu-gray/50",children:"·"}),t.filament_type&&i.jsx("span",{className:"text-xs text-bambu-gray",children:t.filament_type}),t.filament_color&&i.jsx("div",{className:"flex items-center gap-0.5 flex-wrap",children:t.filament_color.split(",").map((de,Ne)=>i.jsx("div",{className:"w-2.5 h-2.5 rounded-full border border-white/20",style:{backgroundColor:de},title:de},Ne))})]})]}),i.jsx("div",{className:"col-span-2 text-sm text-bambu-gray truncate",children:e}),i.jsxs("div",{className:"col-span-2 text-sm text-bambu-gray",children:[i.jsx("div",{children:_f(t.created_at)}),t.created_by_username&&i.jsxs("div",{className:"flex items-center gap-1 text-xs opacity-75",title:c("archives.card.uploadedBy",{name:t.created_by_username}),children:[i.jsx(Rd,{className:"w-3 h-3"}),t.created_by_username]})]}),i.jsx("div",{className:"col-span-1 text-sm text-bambu-gray",children:oo(t.file_size)}),i.jsxs("div",{className:"col-span-2 flex justify-end gap-1",children:[Jm(t)&&i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>N(!0),disabled:!f("archives","reprint",t.created_by_id),title:f("archives","reprint",t.created_by_id)?c("archives.card.reprint"):c("archives.card.noPermissionReprint"),className:"text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10",children:i.jsx(go,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>{const de=t.print_name||t.filename||"model";eh(t.id,de,"file",l)},title:c("archives.card.openInBambuStudio"),children:i.jsx(Jr,{className:"w-4 h-4"})}),(t.external_url||t.makerworld_url)&&i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>window.open(t.external_url||t.makerworld_url,"_blank"),title:t.external_url?c("archives.card.externalLink"):"MakerWorld",children:i.jsx(gh,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>{be.downloadArchive(t.id,`${t.print_name||t.filename}.3mf`).catch(de=>{console.error("Archive download failed:",de)})},title:c("archives.card.download"),children:i.jsx(pi,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>v(!0),disabled:!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?c("archives.card.edit"):c("archives.card.noPermissionEdit"),children:i.jsx(Yi,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>g(!0),disabled:!f("archives","delete",t.created_by_id),title:f("archives","delete",t.created_by_id)?c("archives.card.delete"):c("archives.card.noPermissionDelete"),children:i.jsx(Jt,{className:"w-4 h-4 text-red-400"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:de=>{const Ne=de.currentTarget.getBoundingClientRect();Z({x:Ne.left,y:Ne.bottom+4})},title:c("archives.card.moreOptions"),children:i.jsx(ph,{className:"w-4 h-4"})})]})]}),y&&i.jsx(sie,{archive:t,onClose:()=>v(!1)}),A&&i.jsx(M4,{archiveId:t.id,title:t.print_name||t.filename,fileType:soe(t.filename),onClose:()=>k(!1)}),_&&i.jsx(uu,{mode:"reprint",archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>N(!1)}),x&&i.jsx(Sn,{title:c("archives.modal.deleteArchive"),message:c("archives.modal.deleteConfirm",{name:t.print_name||t.filename}),confirmText:c("archives.modal.deleteButton"),variant:"danger",onConfirm:()=>{ye.mutate(),g(!1)},onCancel:()=>g(!1)}),ge&&i.jsx(Sn,{title:c("archives.modal.removeSource3mf"),message:c("archives.modal.removeSource3mfConfirm",{name:t.print_name||t.filename}),confirmText:c("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{J.mutate(),Y(!1)},onCancel:()=>Y(!1)}),oe&&i.jsx(Sn,{title:c("archives.modal.removeF3d"),message:c("archives.modal.removeF3dConfirm",{name:t.print_name||t.filename}),confirmText:c("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{re.mutate(),le(!1)},onCancel:()=>le(!1)}),xe&&i.jsx(Sn,{title:c("archives.modal.removeTimelapse"),message:c("archives.modal.removeTimelapseConfirm",{name:t.print_name||t.filename}),confirmText:c("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{ne.mutate(),Pe(!1)},onCancel:()=>Pe(!1)}),q&&i.jsx(oie,{x:q.x,y:q.y,items:pe,onClose:()=>Z(null)}),R&&t.timelapse_path&&i.jsx(aoe,{src:be.getArchiveTimelapse(t.id),title:c("archives.modal.timelapse",{name:t.print_name||t.filename}),downloadFilename:`${t.print_name||t.filename}_timelapse.mp4`,archiveId:t.id,onClose:()=>P(!1),onEdit:()=>{d.invalidateQueries({queryKey:["archives"]}),P(!1)}}),D&&z.length>0&&i.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-card-dark rounded-lg max-w-lg w-full max-h-[80vh] flex flex-col",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-700",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:c("archives.modal.selectTimelapse")}),i.jsx("p",{className:"text-sm text-gray-400 mt-1",children:c("archives.modal.selectTimelapseDesc")})]}),i.jsx("button",{onClick:()=>{H(!1),G([])},className:"text-gray-400 hover:text-white p-1",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsx("div",{className:"overflow-y-auto flex-1 p-2",children:z.map(de=>i.jsxs("button",{onClick:()=>fe.mutate(de.name),disabled:fe.isPending,className:"w-full text-left p-3 rounded-lg hover:bg-gray-700 transition-colors mb-1",children:[i.jsx("div",{className:"font-medium text-white",children:de.name}),i.jsxs("div",{className:"text-sm text-gray-400 flex gap-3",children:[i.jsx("span",{children:oo(de.size)}),de.mtime&&i.jsx("span",{children:_f(de.mtime)})]})]},de.name))})]})}),I&&i.jsx(lie,{archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>ee(!1)}),ie&&t.photos&&i.jsx(cie,{archiveId:t.id,archiveName:t.print_name||t.filename,photos:t.photos,onClose:()=>X(!1),onDelete:async de=>{try{await be.deleteArchivePhoto(t.id,de),d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.photoDeleted"))}catch{m(c("archives.toast.failedDeletePhoto"),"error")}}}),me&&i.jsx(ioe,{archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>he(!1)}),T&&i.jsx(uu,{mode:"add-to-queue",archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>C(!1)}),i.jsx("input",{ref:j,type:"file",accept:".3mf",className:"hidden",onChange:de=>{const Ne=de.target.files?.[0];Ne&&V.mutate(Ne),de.target.value=""}}),i.jsx("input",{ref:E,type:"file",accept:".f3d",className:"hidden",onChange:de=>{const Ne=de.target.files?.[0];Ne&&W.mutate(Ne),de.target.value=""}}),i.jsx("input",{ref:U,type:"file",accept:".mp4,.avi,.mkv",className:"hidden",onChange:de=>{const Ne=de.target.files?.[0];Ne&&O.mutate(Ne),de.target.value=""}})]})}const aZe=[{id:"all",label:"All Archives",icon:i.jsx(Nc,{className:"w-4 h-4"})},{id:"recent",label:"Last 24 Hours",icon:i.jsx(er,{className:"w-4 h-4"})},{id:"this-week",label:"This Week",icon:i.jsx(Wr,{className:"w-4 h-4"})},{id:"this-month",label:"This Month",icon:i.jsx(Wr,{className:"w-4 h-4"})},{id:"favorites",label:"Favorites",icon:i.jsx(wf,{className:"w-4 h-4"})},{id:"failed",label:"Failed Prints",icon:i.jsx(Li,{className:"w-4 h-4"})},{id:"duplicates",label:"Duplicates",icon:i.jsx(fo,{className:"w-4 h-4"})}];function sZe(){const{t}=Ft(),e=an(),{showToast:n}=fn(),{hasPermission:r,hasAnyPermission:a}=_r(),s=w.useRef(null),[o,l]=w.useState(""),[c,u]=w.useState(()=>{const se=localStorage.getItem("archiveFilterPrinter");return se?Number(se):null}),[d,m]=w.useState(()=>localStorage.getItem("archiveFilterMaterial")),[p,f]=w.useState(()=>{const se=localStorage.getItem("archiveFilterColors");return se?new Set(JSON.parse(se)):new Set}),[y,v]=w.useState(()=>localStorage.getItem("archiveColorFilterMode")||"or"),[x,g]=w.useState(()=>localStorage.getItem("archiveFilterFavorites")==="true"),[_,N]=w.useState(()=>localStorage.getItem("archiveHideFailed")==="true"),[T,C]=w.useState(()=>localStorage.getItem("archiveHideDuplicates")==="true"),[A,k]=w.useState(()=>localStorage.getItem("archiveFilterTag")),[R,P]=w.useState(()=>localStorage.getItem("archiveFilterFileType")||"all"),[D,H]=w.useState(!1),[z,G]=w.useState([]),[I,ee]=w.useState(!1),[ie,X]=w.useState(new Set),[me,he]=w.useState(!1),[ge,Y]=w.useState(!1),[oe,le]=w.useState(!1),[xe,Pe]=w.useState(!1),[q,Z]=w.useState(()=>localStorage.getItem("archiveViewMode")||"grid"),[j,E]=w.useState(()=>localStorage.getItem("archiveSortBy")||"date-desc"),[U,K]=w.useState(()=>localStorage.getItem("archiveCollection")||"all"),[$,ne]=w.useState(!1),[O,V]=w.useState(!1),[J,W]=w.useState(!1),[re,ue]=w.useState(!1),[fe,ye]=w.useState(null),[ae,L]=w.useState(null),[F,te]=w.useState(()=>localStorage.getItem("logFilterUser")||null),[ve,pe]=w.useState(()=>localStorage.getItem("logFilterStatus")),[de,Ne]=w.useState(()=>localStorage.getItem("logFilterDateFrom")||""),[Se,Le]=w.useState(()=>localStorage.getItem("logFilterDateTo")||""),[qe,Ee]=w.useState(()=>{const se=localStorage.getItem("logOffset");return se?Number(se):0}),[Te,Ae]=w.useState(!1),[Be,je]=w.useState(()=>{const se=localStorage.getItem("logPageSize");return se?Number(se):25}),Xe=w.useCallback(se=>{L(se),ye(se)},[]);w.useEffect(()=>{if(fe){const se=setTimeout(()=>{const Ke=document.querySelector(`[data-archive-id="${fe}"]`);Ke?Ke.scrollIntoView({behavior:"smooth",block:"center"}):ae===fe&&n(t("archives.originalPrintNotVisible"),"warning"),ae===fe&&L(null)},100),He=setTimeout(()=>ye(null),5e3);return()=>{clearTimeout(se),clearTimeout(He)}}},[fe,ae,n,t]);const{data:ce,isLoading:Ie}=et({queryKey:["archives",c],queryFn:()=>be.getArchives(c||void 0)}),{data:Ce}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:Ge}=et({queryKey:["projects"],queryFn:()=>be.getProjects()}),{data:$e}=et({queryKey:["settings"],queryFn:be.getSettings}),{data:Ue}=et({queryKey:["users"],queryFn:be.getUsers,enabled:q==="log"}),{data:De,isLoading:Ve}=et({queryKey:["print-log",c,F,ve,de,Se,o,qe,Be],queryFn:()=>be.getPrintLog({search:o||void 0,printerId:c||void 0,username:F||void 0,status:ve||void 0,dateFrom:de||void 0,dateTo:Se||void 0,limit:Be,offset:qe}),enabled:q==="log"}),it=$e?.time_format||"system",xt=$e?.preferred_slicer||"bambu_studio",Nt=_l($e?.currency||"USD"),kt=pt({mutationFn:async se=>(await Promise.all(se.map(He=>be.deleteArchive(He))),se.length),onSuccess:se=>{e.invalidateQueries({queryKey:["archives"]}),X(new Set),n(`${se} archive${se!==1?"s":""} deleted`)},onError:()=>{n(t("archives.toast.failedDeleteArchives"),"error")}}),We=pt({mutationFn:()=>be.clearPrintLog(),onSuccess:se=>{e.invalidateQueries({queryKey:["print-log"]}),Ee(0),n(t("archives.log.cleared",{count:se.deleted}))},onError:()=>{n(t("archives.log.clearFailed"),"error")}});w.useEffect(()=>{c!==null?localStorage.setItem("archiveFilterPrinter",c.toString()):localStorage.removeItem("archiveFilterPrinter")},[c]),w.useEffect(()=>{d?localStorage.setItem("archiveFilterMaterial",d):localStorage.removeItem("archiveFilterMaterial")},[d]),w.useEffect(()=>{localStorage.setItem("archiveFilterColors",JSON.stringify([...p]))},[p]),w.useEffect(()=>{localStorage.setItem("archiveColorFilterMode",y)},[y]),w.useEffect(()=>{localStorage.setItem("archiveFilterFavorites",x.toString())},[x]),w.useEffect(()=>{localStorage.setItem("archiveHideFailed",_.toString())},[_]),w.useEffect(()=>{localStorage.setItem("archiveHideDuplicates",T.toString())},[T]),w.useEffect(()=>{A?localStorage.setItem("archiveFilterTag",A):localStorage.removeItem("archiveFilterTag")},[A]),w.useEffect(()=>{localStorage.setItem("archiveFilterFileType",R)},[R]),w.useEffect(()=>{localStorage.setItem("archiveViewMode",q)},[q]),w.useEffect(()=>{localStorage.setItem("archiveSortBy",j)},[j]),w.useEffect(()=>{localStorage.setItem("archiveCollection",U)},[U]),w.useEffect(()=>{F?localStorage.setItem("logFilterUser",F):localStorage.removeItem("logFilterUser")},[F]),w.useEffect(()=>{ve?localStorage.setItem("logFilterStatus",ve):localStorage.removeItem("logFilterStatus")},[ve]),w.useEffect(()=>{de?localStorage.setItem("logFilterDateFrom",de):localStorage.removeItem("logFilterDateFrom")},[de]),w.useEffect(()=>{Se?localStorage.setItem("logFilterDateTo",Se):localStorage.removeItem("logFilterDateTo")},[Se]),w.useEffect(()=>{localStorage.setItem("logOffset",qe.toString())},[qe]),w.useEffect(()=>{localStorage.setItem("logPageSize",Be.toString())},[Be]);const yt=new Map(Ce?.map(se=>[se.id,se.name])||[]),wt=[...new Set(ce?.flatMap(se=>se.filament_type?.split(", ")||[]).filter(Boolean)||[])].sort(),_t=[...new Set(ce?.flatMap(se=>se.filament_color?.split(",")||[]).filter(Boolean)||[])],Ot=[...new Set(ce?.flatMap(se=>se.tags?.split(",").map(He=>He.trim())||[]).filter(Boolean)||[])].sort(),Vt=ce?.filter(se=>{const He=new Date,Ke=Jn(se.created_at)||new Date(0);let Ye=!0;switch(U){case"recent":Ye=He.getTime()-Ke.getTime()<1440*60*1e3;break;case"this-week":Ye=He.getTime()-Ke.getTime()<10080*60*1e3;break;case"this-month":Ye=Ke.getMonth()===He.getMonth()&&Ke.getFullYear()===He.getFullYear();break;case"favorites":Ye=se.is_favorite===!0;break;case"failed":Ye=se.status==="failed"||se.status==="aborted";break;case"duplicates":Ye=se.duplicate_count>0;break}const Me=(se.print_name||se.filename).toLowerCase().includes(o.toLowerCase()),dt=!d||se.filament_type?.split(", ").includes(d),ct=se.filament_color?.split(",")||[],nt=p.size===0||(y==="or"?ct.some(_n=>p.has(_n)):[...p].every(_n=>ct.includes(_n))),bt=U==="favorites"||!x||se.is_favorite,Ut=U==="failed"||!_||se.status!=="failed"&&se.status!=="aborted",Et=U==="duplicates"||!T||se.duplicate_count===0||se.duplicate_sequence===0,It=se.tags?.split(",").map(_n=>_n.trim())||[],Zt=!A||It.includes(A),tn=Jm(se);return Ye&&Me&&dt&&nt&&bt&&Ut&&Et&&Zt&&(R==="all"||R==="gcode"&&tn||R==="source"&&!tn)}).sort((se,He)=>{switch(j){case"date-desc":return(Jn(He.created_at)?.getTime()||0)-(Jn(se.created_at)?.getTime()||0);case"date-asc":return(Jn(se.created_at)?.getTime()||0)-(Jn(He.created_at)?.getTime()||0);case"name-asc":return(se.print_name||se.filename).localeCompare(He.print_name||He.filename);case"name-desc":return(He.print_name||He.filename).localeCompare(se.print_name||se.filename);case"size-desc":return He.file_size-se.file_size;case"size-asc":return se.file_size-He.file_size;default:return 0}}),Xt=me||ie.size>0,Qe=se=>{X(He=>{const Ke=new Set(He);return Ke.has(se)?Ke.delete(se):Ke.add(se),Ke})},Qt=()=>{Vt&&X(new Set(Vt.map(se=>se.id)))},hn=()=>{X(new Set),he(!1)},jn=se=>{f(He=>{const Ke=new Set(He);return Ke.has(se)?Ke.delete(se):Ke.add(se),Ke})},kn=()=>{f(new Set)},Fe=()=>{l(""),u(null),m(null),g(!1),N(!1),C(!1),k(null),P("all")},tt=o||c||d||x||_||T||A||R!=="all",ut=w.useCallback(se=>{se.preventDefault(),se.dataTransfer.types.includes("Files")&&ee(!0)},[]),Ze=w.useCallback(se=>{se.preventDefault(),se.currentTarget===se.target&&ee(!1)},[]),ke=w.useCallback(se=>{se.preventDefault(),ee(!1);const He=Array.from(se.dataTransfer.files).filter(Ke=>Ke.name.endsWith(".3mf"));He.length>0?(G(He),H(!0)):se.dataTransfer.files.length>0&&n(t("archives.page.only3mfSupported"),"warning")},[n,t]),ot=w.useCallback(se=>{const He=se.target;if(He.tagName==="INPUT"||He.tagName==="TEXTAREA"||He.isContentEditable){se.key==="Escape"&&He.blur();return}switch(se.key){case"/":se.preventDefault(),s.current?.focus();break;case"u":case"U":!se.metaKey&&!se.ctrlKey&&(se.preventDefault(),H(!0));break;case"Escape":Xt&&hn();break}},[Xt]);return w.useEffect(()=>(document.addEventListener("keydown",ot),()=>document.removeEventListener("keydown",ot)),[ot]),i.jsxs("div",{className:"p-4 md:p-8 relative",onDragOver:ut,onDragLeave:Ze,onDrop:ke,children:[I&&i.jsx("div",{className:"fixed inset-0 z-50 bg-bambu-dark/90 flex items-center justify-center pointer-events-none",children:i.jsxs("div",{className:"border-4 border-dashed border-bambu-green rounded-xl p-12 text-center",children:[i.jsx(xi,{className:"w-16 h-16 mx-auto mb-4 text-bambu-green"}),i.jsx("p",{className:"text-2xl font-semibold text-white mb-2",children:"Drop .3mf files here"}),i.jsx("p",{className:"text-bambu-gray",children:t("archives.releaseToUpload")})]})}),Xt&&i.jsxs("div",{className:"fixed bottom-6 left-1/2 -translate-x-1/2 z-40 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl px-4 py-3 flex items-center gap-4",children:[i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:hn,children:[i.jsx(Ht,{className:"w-4 h-4"}),"Close"]}),i.jsx("div",{className:"w-px h-6 bg-bambu-dark-tertiary"}),i.jsxs("span",{className:"text-white font-medium",children:[ie.size," selected"]}),i.jsx("div",{className:"w-px h-6 bg-bambu-dark-tertiary"}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:Qt,children:"Select All"}),i.jsx("div",{className:"w-px h-6 bg-bambu-dark-tertiary"}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>le(!0),disabled:!a("archives:update_own","archives:update_all"),title:a("archives:update_own","archives:update_all")?void 0:t("archives.permission.noUpdateArchives"),children:[i.jsx(Dd,{className:"w-4 h-4"}),"Tags"]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>Pe(!0),disabled:!a("archives:update_own","archives:update_all"),title:a("archives:update_own","archives:update_all")?void 0:t("archives.permission.noUpdateArchives"),children:[i.jsx(fs,{className:"w-4 h-4"}),"Project"]}),i.jsxs(Oe,{variant:"secondary",size:"sm",disabled:!a("archives:update_own","archives:update_all"),title:a("archives:update_own","archives:update_all")?void 0:t("archives.permission.noUpdateArchives"),onClick:()=>{const se=Array.from(ie);Promise.all(se.map(He=>be.toggleFavorite(He))).then(()=>{e.invalidateQueries({queryKey:["archives"]}),n(`Toggled favorites for ${se.length} archive${se.length!==1?"s":""}`)}).catch(()=>{n(t("archives.toast.failedUpdateFavorites"),"error")})},children:[i.jsx(wf,{className:"w-4 h-4"}),"Favorite"]}),i.jsxs(Oe,{size:"sm",className:"bg-red-500 hover:bg-red-600",onClick:()=>Y(!0),disabled:!a("archives:delete_own","archives:delete_all"),title:a("archives:delete_own","archives:delete_all")?void 0:t("archives.permission.noDelete"),children:[i.jsx(Jt,{className:"w-4 h-4"}),"Delete"]})]}),i.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-8",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:"Archives"}),i.jsx("select",{className:"px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray-light text-sm focus:border-bambu-green focus:outline-none",value:U,onChange:se=>K(se.target.value),children:aZe.map(se=>i.jsx("option",{value:se.id,children:se.label},se.id))})]}),i.jsxs("p",{className:"text-bambu-gray",children:[Vt?.length||0," of ",ce?.length||0," prints"]})]}),i.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 flex-wrap",children:[i.jsxs("div",{className:"relative",children:[i.jsxs(Oe,{variant:"secondary",onClick:()=>ne(!$),disabled:O,children:[O?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(EN,{className:"w-4 h-4"}),"Export"]}),$&&i.jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20",children:[i.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg",onClick:async()=>{ne(!1),V(!0);try{const{blob:se,filename:He}=await be.exportArchives({format:"csv",printerId:c||void 0,status:U==="failed"?"failed":void 0,search:o||void 0}),Ke=URL.createObjectURL(se),Ye=document.createElement("a");Ye.href=Ke,Ye.download=He,Ye.click(),URL.revokeObjectURL(Ke),n(t("archives.toast.exportDownloaded"))}catch{n(t("archives.toast.exportFailed"),"error")}finally{V(!1)}},children:[i.jsx(Fs,{className:"w-4 h-4"}),"Export as CSV"]}),i.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg",onClick:async()=>{ne(!1),V(!0);try{const{blob:se,filename:He}=await be.exportArchives({format:"xlsx",printerId:c||void 0,status:U==="failed"?"failed":void 0,search:o||void 0}),Ke=URL.createObjectURL(se),Ye=document.createElement("a");Ye.href=Ke,Ye.download=He,Ye.click(),URL.revokeObjectURL(Ke),n(t("archives.toast.exportDownloaded"))}catch{n(t("archives.toast.exportFailed"),"error")}finally{V(!1)}},children:[i.jsx(EN,{className:"w-4 h-4"}),"Export as Excel"]})]})]}),ie.size>=2&&ie.size<=5&&i.jsxs(Oe,{variant:"secondary",onClick:()=>W(!0),children:[i.jsx(zb,{className:"w-4 h-4"}),"Compare (",ie.size,")"]}),!Xt&&i.jsxs(Oe,{variant:"secondary",onClick:()=>he(!0),children:[i.jsx(xo,{className:"w-4 h-4"}),"Select"]}),i.jsxs(Oe,{onClick:()=>H(!0),disabled:!r("archives:create"),title:r("archives:create")?void 0:t("archives.permission.noCreate"),children:[i.jsx(xi,{className:"w-4 h-4"}),"Upload 3MF"]})]})]}),i.jsxs("div",{className:"flex items-center border border-bambu-dark-tertiary rounded-lg overflow-hidden flex-shrink-0 w-fit mb-4",children:[i.jsx("button",{className:`p-2 ${q==="grid"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,onClick:()=>Z("grid"),title:t("archives.gridView"),children:i.jsx(pw,{className:"w-4 h-4"})}),i.jsx("button",{className:`p-2 ${q==="list"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,onClick:()=>Z("list"),title:t("archives.listView"),children:i.jsx(JC,{className:"w-4 h-4"})}),i.jsx("button",{className:`p-2 ${q==="calendar"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,onClick:()=>Z("calendar"),title:t("archives.calendarView"),children:i.jsx(Rhe,{className:"w-4 h-4"})}),i.jsx("button",{className:`p-2 ${q==="log"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,onClick:()=>Z("log"),title:t("archives.logView"),children:i.jsx(rpe,{className:"w-4 h-4"})})]}),q!=="log"&&i.jsx(Mt,{className:"mb-6",children:i.jsxs(Dt,{className:"py-4",children:[i.jsxs("div",{className:"flex flex-col md:flex-row gap-3 md:gap-4 md:items-center md:flex-wrap",children:[i.jsxs("div",{className:"w-full md:flex-1 relative md:min-w-[200px]",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{ref:s,type:"text",placeholder:t("archives.searchPlaceholder"),className:"w-full pl-10 pr-4 py-3 md:py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:o,onChange:se=>l(se.target.value)})]}),i.jsxs("div",{className:"flex gap-2 md:gap-4 overflow-x-auto pb-1 md:pb-0 -mx-4 px-4 md:mx-0 md:px-0 md:flex-wrap scrollbar-hide",children:[i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[i.jsx(QC,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),i.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:c||"",onChange:se=>u(se.target.value?Number(se.target.value):null),children:[i.jsx("option",{value:"",children:"All Printers"}),Ce?.map(se=>i.jsx("option",{value:se.id,children:se.name},se.id))]})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[i.jsx(Wi,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),i.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:se=>m(se.target.value||null),children:[i.jsx("option",{value:"",children:"All Materials"}),wt.map(se=>i.jsx("option",{value:se,children:se},se))]})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[i.jsx(MN,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),i.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:R,onChange:se=>P(se.target.value),children:[i.jsx("option",{value:"all",children:"All Files"}),i.jsx("option",{value:"gcode",children:"Sliced (GCODE)"}),i.jsx("option",{value:"source",children:"Source Only"})]})]}),i.jsxs("button",{onClick:()=>g(!x),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${x?"bg-yellow-500/20 border-yellow-500 text-yellow-400":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,title:t(x?"archives.showAll":"archives.showFavoritesOnly"),children:[i.jsx(wf,{className:`w-4 h-4 ${x?"fill-yellow-400":""}`}),i.jsx("span",{className:"text-sm hidden md:inline",children:"Favorites"})]}),i.jsxs("button",{onClick:()=>N(!_),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${_?"bg-red-500/20 border-red-500 text-red-400":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,title:t(_?"archives.showFailedPrints":"archives.hideFailedPrints"),children:[i.jsx(Li,{className:"w-4 h-4 "}),i.jsx("span",{className:"text-sm hidden md:inline",children:"Hide Failed"})]}),i.jsxs("button",{onClick:()=>C(!T),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${T?"bg-purple-500/20 border-purple-500 text-purple-400":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,title:t("archives.hideDuplicates"),children:[i.jsx(fo,{className:"w-4 h-4"}),i.jsx("span",{className:"text-sm hidden md:inline",children:t("archives.hideDuplicates")})]}),Ot.length>0&&i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[i.jsx(Dd,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),i.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:A||"",onChange:se=>k(se.target.value||null),children:[i.jsx("option",{value:"",children:"All Tags"}),Ot.map(se=>i.jsx("option",{value:se,children:se},se))]}),i.jsx("button",{onClick:()=>ue(!0),className:"p-2 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-green transition-colors",title:t("archives.manageTags"),children:i.jsx(iT,{className:"w-4 h-4"})})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[i.jsx(IL,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),i.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:j,onChange:se=>E(se.target.value),children:[i.jsx("option",{value:"date-desc",children:t("archives.sortNewest")}),i.jsx("option",{value:"date-asc",children:t("archives.sortOldest")}),i.jsxs("option",{value:"name-asc",children:[t("archives.sortName")," A-Z"]}),i.jsxs("option",{value:"name-desc",children:[t("archives.sortName")," Z-A"]}),i.jsx("option",{value:"size-desc",children:t("archives.sortLargest")}),i.jsx("option",{value:"size-asc",children:t("archives.sortSmallest")})]})]})]}),tt&&i.jsxs(Oe,{variant:"ghost",size:"sm",onClick:Fe,className:"text-bambu-gray hover:text-white",children:[i.jsx(Ht,{className:"w-4 h-4"}),"Reset"]})]}),_t.length>0&&i.jsxs("div",{className:"flex items-center gap-3 mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:"Colors:"}),p.size>1&&i.jsx("button",{onClick:()=>v(se=>se==="or"?"and":"or"),className:`px-2 py-0.5 text-xs rounded transition-colors ${y==="and"?"bg-bambu-green text-white":"bg-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,title:y==="or"?"Match ANY selected color":"Match ALL selected colors",children:y.toUpperCase()}),i.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:_t.map(se=>i.jsx("button",{onClick:()=>jn(se),className:`w-6 h-6 rounded-full border-2 transition-all ${p.has(se)?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:se},title:se},se))}),p.size>0&&i.jsxs("button",{onClick:kn,className:"text-xs text-bambu-gray hover:text-white flex items-center gap-1",children:[i.jsx(Ht,{className:"w-3 h-3"}),"Clear"]})]})]})}),i.jsx(tZe,{}),Ie?i.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("archives.loadingArchives")}):Vt?.length===0?i.jsx(Mt,{children:i.jsxs(Dt,{className:"text-center py-12",children:[i.jsx("p",{className:"text-bambu-gray",children:t(o?"archives.noArchivesSearch":"archives.noArchivesYet")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-2",children:"Archives are created automatically when prints complete"})]})}):q==="calendar"?i.jsx(Mt,{className:"p-6",children:i.jsx(kVe,{archives:Vt||[],onArchiveClick:se=>{l(""),Z("grid"),ye(se.id)},highlightedArchiveId:fe})}):q==="grid"?i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6",children:Vt?.map(se=>i.jsx(rZe,{archive:se,printerName:se.printer_id?yt.get(se.printer_id)||"Unknown":se.sliced_for_model?`Sliced for ${se.sliced_for_model}`:"No Printer",isSelected:ie.has(se.id),onSelect:Qe,selectionMode:Xt,projects:Ge,isHighlighted:se.id===fe,timeFormat:it,preferredSlicer:xt,currency:Nt,t,onNavigateToArchive:Xe},se.id))}):q==="list"?i.jsx(Mt,{children:i.jsxs("div",{className:"divide-y divide-bambu-dark-tertiary",children:[i.jsxs("div",{className:"grid grid-cols-12 gap-4 px-4 py-3 text-xs text-bambu-gray font-medium",children:[i.jsx("div",{className:"col-span-1"}),i.jsx("div",{className:"col-span-4",children:"Name"}),i.jsx("div",{className:"col-span-2",children:"Printer"}),i.jsx("div",{className:"col-span-2",children:"Date"}),i.jsx("div",{className:"col-span-1",children:"Size"}),i.jsx("div",{className:"col-span-2 text-right",children:"Actions"})]}),Vt?.map(se=>i.jsx(iZe,{archive:se,printerName:se.printer_id?yt.get(se.printer_id)||"Unknown":se.sliced_for_model?`Sliced for ${se.sliced_for_model}`:"No Printer",isSelected:ie.has(se.id),onSelect:Qe,selectionMode:Xt,projects:Ge,isHighlighted:se.id===fe,preferredSlicer:xt,t,onNavigateToArchive:Xe},se.id))]})}):q==="log"?i.jsxs("div",{className:"space-y-4",children:[i.jsx(Mt,{children:i.jsx(Dt,{className:"py-3",children:i.jsxs("div",{className:"flex flex-col md:flex-row gap-3 md:items-center md:flex-wrap",children:[i.jsxs("div",{className:"flex-1 relative md:min-w-[200px]",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",placeholder:t("archives.searchPlaceholder"),className:"w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",value:o,onChange:se=>{l(se.target.value),Ee(0)}})]}),i.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 text-sm",value:c||"",onChange:se=>{u(se.target.value?Number(se.target.value):null),Ee(0)},children:[i.jsx("option",{value:"",children:t("archives.log.allPrinters")}),Ce?.map(se=>i.jsx("option",{value:se.id,children:se.name},se.id))]}),i.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 text-sm",value:F||"",onChange:se=>{te(se.target.value||null),Ee(0)},children:[i.jsx("option",{value:"",children:t("archives.log.allUsers")}),Ue?.map(se=>i.jsx("option",{value:se.username,children:se.username},se.id))]}),i.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 text-sm",value:ve||"",onChange:se=>{pe(se.target.value||null),Ee(0)},children:[i.jsx("option",{value:"",children:t("archives.log.allStatuses")}),i.jsx("option",{value:"completed",children:t("archives.status.completed")}),i.jsx("option",{value:"failed",children:t("archives.status.failed")}),i.jsx("option",{value:"stopped",children:t("archives.status.stopped")}),i.jsx("option",{value:"cancelled",children:t("archives.log.cancelled")}),i.jsx("option",{value:"skipped",children:t("archives.log.skipped")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("label",{className:"text-sm text-bambu-gray",children:t("archives.log.dateFrom")}),i.jsx("input",{type:"date",className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",value:de,onChange:se=>{Ne(se.target.value),Ee(0)}})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("label",{className:"text-sm text-bambu-gray",children:t("archives.log.dateTo")}),i.jsx("input",{type:"date",className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",value:Se,onChange:se=>{Le(se.target.value),Ee(0)}})]}),i.jsx("div",{className:"ml-auto",children:i.jsxs(Oe,{variant:"danger",size:"sm",onClick:()=>Ae(!0),disabled:!r("archives:delete_all")||We.isPending,children:[i.jsx(Jt,{className:"w-4 h-4"}),t("archives.log.clearLog")]})})]})})}),i.jsx(Mt,{children:Ve?i.jsx("div",{className:"flex items-center justify-center py-12",children:i.jsx(ht,{className:"w-6 h-6 animate-spin text-bambu-green"})}):De?.items.length?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"overflow-x-auto",children:i.jsxs("table",{className:"w-full text-sm",children:[i.jsx("thead",{children:i.jsxs("tr",{className:"border-b border-bambu-dark-tertiary text-bambu-gray text-left",children:[i.jsx("th",{className:"px-4 py-3 font-medium",children:t("archives.log.date")}),i.jsx("th",{className:"px-4 py-3 font-medium",children:t("archives.log.printName")}),i.jsx("th",{className:"px-4 py-3 font-medium",children:t("archives.log.printer")}),i.jsx("th",{className:"px-4 py-3 font-medium",children:t("archives.log.user")}),i.jsx("th",{className:"px-4 py-3 font-medium",children:t("archives.log.status")}),i.jsx("th",{className:"px-4 py-3 font-medium",children:t("archives.log.duration")}),i.jsx("th",{className:"px-4 py-3 font-medium",children:t("archives.log.filament")})]})}),i.jsx("tbody",{className:"divide-y divide-bambu-dark-tertiary",children:De.items.map(se=>i.jsxs("tr",{className:"hover:bg-bambu-dark-secondary/50",children:[i.jsx("td",{className:"px-4 py-3 text-white whitespace-nowrap",children:Nf(se.started_at||se.created_at,it)}),i.jsx("td",{className:"px-4 py-3",children:i.jsxs("div",{className:"flex items-center gap-2",children:[se.thumbnail_path&&i.jsx("img",{src:be.getPrintLogThumbnail(se.id),alt:"",className:"w-8 h-8 rounded object-cover flex-shrink-0",onError:He=>{He.target.style.display="none"}}),i.jsx("span",{className:"text-white truncate max-w-[200px]",children:se.print_name||"—"})]})}),i.jsx("td",{className:"px-4 py-3 text-bambu-gray-light",children:se.printer_name||"—"}),i.jsx("td",{className:"px-4 py-3 text-bambu-gray-light",children:se.created_by_username||"—"}),i.jsx("td",{className:"px-4 py-3",children:i.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${se.status==="completed"?"bg-green-500/20 text-green-400":se.status==="failed"?"bg-red-500/20 text-red-400":se.status==="stopped"?"bg-yellow-500/20 text-yellow-400":se.status==="cancelled"?"bg-orange-500/20 text-orange-400":se.status==="skipped"?"bg-blue-500/20 text-blue-400":"bg-gray-500/20 text-gray-400"}`,children:se.status})}),i.jsx("td",{className:"px-4 py-3 text-bambu-gray-light whitespace-nowrap",children:se.duration_seconds?Rs(se.duration_seconds):"—"}),i.jsx("td",{className:"px-4 py-3",children:i.jsxs("div",{className:"flex items-center gap-1.5",children:[se.filament_color&&i.jsx("span",{className:"w-3 h-3 rounded-full border border-white/20 flex-shrink-0",style:{backgroundColor:se.filament_color.startsWith("#")?se.filament_color:void 0}}),i.jsx("span",{className:"text-bambu-gray-light text-xs",children:se.filament_type||"—"})]})})]},se.id))})]})}),i.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-t border-bambu-dark-tertiary flex-wrap gap-2",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:t("archives.log.showing",{count:Math.min(qe+Be,De.total),total:De.total})}),i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx("label",{className:"text-xs text-bambu-gray",children:t("archives.log.rowsPerPage")}),i.jsxs("select",{className:"px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-xs focus:border-bambu-green focus:outline-none",value:Be,onChange:se=>{je(Number(se.target.value)),Ee(0)},children:[i.jsx("option",{value:10,children:"10"}),i.jsx("option",{value:25,children:"25"}),i.jsx("option",{value:50,children:"50"}),i.jsx("option",{value:100,children:"100"})]})]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{className:"text-sm text-bambu-gray",children:[t("archives.log.page")," ",Math.floor(qe/Be)+1," / ",Math.max(1,Math.ceil(De.total/Be))]}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>Ee(Math.max(0,qe-Be)),disabled:qe===0,children:i.jsx(Sc,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>Ee(qe+Be),disabled:qe+Be>=De.total,children:i.jsx(ha,{className:"w-4 h-4"})})]})]})]}):i.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("archives.log.noEntries")})})]}):null,D&&i.jsx(gVe,{onClose:()=>{H(!1),G([])},initialFiles:z}),ge&&i.jsx(Sn,{title:t("archives.modal.deleteArchives"),message:t("archives.modal.deleteArchivesConfirm",{count:ie.size}),confirmText:t("archives.modal.deleteCount",{count:ie.size}),variant:"danger",onConfirm:()=>{kt.mutate(Array.from(ie)),Y(!1)},onCancel:()=>Y(!1)}),oe&&i.jsx(yVe,{selectedIds:Array.from(ie),existingTags:Ot,onClose:()=>le(!1)}),xe&&i.jsx(vVe,{selectedIds:Array.from(ie),onClose:()=>Pe(!1)}),J&&ie.size>=2&&ie.size<=5&&i.jsx(QQe,{archiveIds:Array.from(ie),onClose:()=>{W(!1),X(new Set),he(!1)}}),re&&i.jsx(nZe,{onClose:()=>ue(!1)}),Te&&i.jsx(Sn,{title:t("archives.log.clearLogTitle"),message:t("archives.log.clearLogConfirm"),confirmText:t("archives.log.clearLogButton"),variant:"danger",onConfirm:()=>{We.mutate(),Ae(!1)},onCancel:()=>Ae(!1)})]})}function oZe(){for(var t=arguments.length,e=new Array(t),n=0;nr=>{e.forEach(a=>a(r))},e)}const TA=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function ty(t){const e=Object.prototype.toString.call(t);return e==="[object Window]"||e==="[object global]"}function b5(t){return"nodeType"in t}function wo(t){var e,n;return t?ty(t)?t:b5(t)&&(e=(n=t.ownerDocument)==null?void 0:n.defaultView)!=null?e:window:window}function x5(t){const{Document:e}=wo(t);return t instanceof e}function Kw(t){return ty(t)?!1:t instanceof wo(t).HTMLElement}function ooe(t){return t instanceof wo(t).SVGElement}function ny(t){return t?ty(t)?t.document:b5(t)?x5(t)?t:Kw(t)||ooe(t)?t.ownerDocument:document:document:document}const xu=TA?w.useLayoutEffect:w.useEffect;function y5(t){const e=w.useRef(t);return xu(()=>{e.current=t}),w.useCallback(function(){for(var n=arguments.length,r=new Array(n),a=0;a{t.current=setInterval(r,a)},[]),n=w.useCallback(()=>{t.current!==null&&(clearInterval(t.current),t.current=null)},[]);return[e,n]}function iw(t,e){e===void 0&&(e=[t]);const n=w.useRef(t);return xu(()=>{n.current!==t&&(n.current=t)},e),n}function Yw(t,e){const n=w.useRef();return w.useMemo(()=>{const r=t(n.current);return n.current=r,r},[...e])}function UC(t){const e=y5(t),n=w.useRef(null),r=w.useCallback(a=>{a!==n.current&&e?.(a,n.current),n.current=a},[]);return[n,r]}function mL(t){const e=w.useRef();return w.useEffect(()=>{e.current=t},[t]),e.current}let jD={};function Xw(t,e){return w.useMemo(()=>{if(e)return e;const n=jD[t]==null?0:jD[t]+1;return jD[t]=n,t+"-"+n},[t,e])}function loe(t){return function(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),a=1;a{const l=Object.entries(o);for(const[c,u]of l){const d=s[c];d!=null&&(s[c]=d+t*u)}return s},{...e})}}const Jb=loe(1),aw=loe(-1);function cZe(t){return"clientX"in t&&"clientY"in t}function v5(t){if(!t)return!1;const{KeyboardEvent:e}=wo(t.target);return e&&t instanceof e}function uZe(t){if(!t)return!1;const{TouchEvent:e}=wo(t.target);return e&&t instanceof e}function hL(t){if(uZe(t)){if(t.touches&&t.touches.length){const{clientX:e,clientY:n}=t.touches[0];return{x:e,y:n}}else if(t.changedTouches&&t.changedTouches.length){const{clientX:e,clientY:n}=t.changedTouches[0];return{x:e,y:n}}}return cZe(t)?{x:t.clientX,y:t.clientY}:null}const Mx=Object.freeze({Translate:{toString(t){if(!t)return;const{x:e,y:n}=t;return"translate3d("+(e?Math.round(e):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(t){if(!t)return;const{scaleX:e,scaleY:n}=t;return"scaleX("+e+") scaleY("+n+")"}},Transform:{toString(t){if(t)return[Mx.Translate.toString(t),Mx.Scale.toString(t)].join(" ")}},Transition:{toString(t){let{property:e,duration:n,easing:r}=t;return e+" "+n+"ms "+r}}}),uY="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function dZe(t){return t.matches(uY)?t:t.querySelector(uY)}const mZe={display:"none"};function hZe(t){let{id:e,value:n}=t;return Vr.createElement("div",{id:e,style:mZe},n)}function pZe(t){let{id:e,announcement:n,ariaLiveType:r="assertive"}=t;const a={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return Vr.createElement("div",{id:e,style:a,role:"status","aria-live":r,"aria-atomic":!0},n)}function fZe(){const[t,e]=w.useState("");return{announce:w.useCallback(r=>{r!=null&&e(r)},[]),announcement:t}}const coe=w.createContext(null);function gZe(t){const e=w.useContext(coe);w.useEffect(()=>{if(!e)throw new Error("useDndMonitor must be used within a children of ");return e(t)},[t,e])}function bZe(){const[t]=w.useState(()=>new Set),e=w.useCallback(r=>(t.add(r),()=>t.delete(r)),[t]);return[w.useCallback(r=>{let{type:a,event:s}=r;t.forEach(o=>{var l;return(l=o[a])==null?void 0:l.call(o,s)})},[t]),e]}const xZe={draggable:` +Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${Rs(t.actual_time_seconds)}`:`Estimated: ${Rs(t.print_time_seconds||0)}`,children:[i.jsx(er,{className:"w-3 h-3"}),Rs(t.actual_time_seconds||t.print_time_seconds||0),t.time_accuracy&&i.jsxs("span",{className:`text-[10px] px-1 rounded ${t.time_accuracy>=95&&t.time_accuracy<=105?"bg-bambu-green/20 text-bambu-green":t.time_accuracy>105?"bg-blue-500/20 text-blue-400":"bg-orange-500/20 text-orange-400"}`,children:[t.time_accuracy>100?"+":"",(t.time_accuracy-100).toFixed(0),"%"]})]}),t.filament_used_grams&&i.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",children:[i.jsx(Wi,{className:"w-3 h-3"}),t.filament_used_grams.toFixed(1),"g"]}),(t.cost!=null||t.energy_cost!=null)&&i.jsxs("div",{className:"flex items-center gap-3 text-bambu-gray",children:[t.cost!=null&&i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx(ppe,{className:"w-3 h-3"}),u,t.cost.toFixed(2)]}),t.energy_cost!=null&&i.jsxs("div",{className:"flex items-center gap-1.5",title:`${d("stats.energyUsed")}: ${t.energy_kwh?.toFixed(3)||"N/A"} kWh`,children:[i.jsx(kc,{className:"w-3 h-3"}),u,t.energy_cost.toFixed(2)]})]}),(t.layer_height||t.total_layers)&&i.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",children:[i.jsx(Gi,{className:"w-3 h-3"}),t.total_layers&&i.jsx("span",{children:t.total_layers===1?d("archives.card.layer",{count:t.total_layers}):d("archives.card.layers",{count:t.total_layers})}),t.total_layers&&t.layer_height&&i.jsx("span",{className:"text-bambu-gray/50",children:"·"}),t.layer_height&&i.jsxs("span",{children:[t.layer_height,"mm"]})]}),t.object_count!=null&&t.object_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",title:t.object_count===1?d("archives.card.object",{count:t.object_count}):d("archives.card.objects",{count:t.object_count}),children:[i.jsx(ra,{className:"w-3 h-3"}),t.object_count===1?d("archives.card.object",{count:t.object_count}):d("archives.card.objects",{count:t.object_count})]}),t.sliced_for_model&&i.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",title:d("archives.card.slicedFor",{model:t.sliced_for_model}),children:[i.jsx(Sr,{className:"w-3 h-3"}),t.sliced_for_model]}),t.filament_type&&i.jsxs("div",{className:"flex items-center gap-1.5 col-span-2",children:[i.jsx("span",{className:"text-bambu-gray text-xs",children:t.filament_type}),t.filament_color&&i.jsx("div",{className:"flex items-center gap-0.5 flex-wrap",children:t.filament_color.split(",").map((ce,Ie)=>i.jsx("div",{className:"w-3 h-3 rounded-full border border-black/20",style:{backgroundColor:ce},title:ce},Ie))})]})]}),(t.tags||t.notes)&&i.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-3",children:[t.notes&&i.jsx("div",{className:"flex items-center gap-1 px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded text-xs",title:t.notes,children:i.jsx(ZX,{className:"w-3 h-3"})}),t.tags?.split(",").map((ce,Ie)=>i.jsx("span",{className:"px-1.5 py-0.5 bg-bambu-dark-tertiary text-bambu-gray-light rounded text-xs",children:ce.trim()},Ie))]}),i.jsx("div",{className:"flex-1"}),i.jsxs("div",{className:"flex items-center justify-between text-xs text-bambu-gray border-t border-bambu-dark-tertiary pt-3",children:[i.jsx("span",{children:Nf(t.created_at,l)}),i.jsxs("div",{className:"flex items-center gap-2",children:[t.created_by_username&&i.jsxs("span",{className:"flex items-center gap-1",title:d("archives.card.uploadedBy",{name:t.created_by_username}),children:[i.jsx(Rd,{className:"w-3 h-3"}),t.created_by_username]}),i.jsx("span",{children:oo(t.file_size)})]})]}),i.jsxs("div",{className:"flex gap-1 mt-3",children:[Jm(t)?i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"primary",size:"sm",className:"flex-1 min-w-0 overflow-hidden",onClick:()=>T(!0),disabled:!t.file_path||!v("archives","reprint",t.created_by_id),title:t.file_path?v("archives","reprint",t.created_by_id)?void 0:d("archives.card.noPermissionReprint"):d("archives.card.noFileForReprint"),children:[i.jsx(Sr,{className:"w-3 h-3 flex-shrink-0"}),i.jsx("span",{className:"hidden sm:inline truncate",children:d("archives.card.reprint")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",className:"flex-1 min-w-0 overflow-hidden",onClick:()=>oe(!0),disabled:!t.file_path||!y("queue:create"),title:t.file_path?y("queue:create")?d("archives.card.schedulePrint"):d("archives.permission.noAddToQueue"):d("archives.card.noFileForReprint"),children:[i.jsx(Wr,{className:"w-3 h-3 flex-shrink-0"}),i.jsx("span",{className:"hidden sm:inline truncate",children:d("archives.card.schedule")})]}),i.jsx(Oe,{variant:"secondary",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>{const ce=t.print_name||t.filename||"model";eh(t.id,ce,"file",c)},title:d("archives.card.openInBambuStudio"),children:i.jsx(Jr,{className:"w-3 h-3 sm:w-4 sm:h-4"})})]}):i.jsxs(Oe,{variant:"primary",size:"sm",className:"flex-1 min-w-0 overflow-hidden",onClick:()=>{const ce=t.print_name||t.filename||"model";eh(t.id,ce,"file",c)},title:d("archives.card.openInBambuStudioToSlice"),children:[i.jsx(Jr,{className:"w-3 h-3 flex-shrink-0"}),i.jsx("span",{className:"hidden sm:inline truncate",children:d("archives.card.slice")})]}),i.jsx(Oe,{variant:"secondary",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>{const ce=t.external_url||t.makerworld_url;ce&&window.open(ce,"_blank")},disabled:!t.external_url&&!t.makerworld_url,title:t.external_url?d("archives.card.externalLink"):t.makerworld_url?d("archives.card.makerWorld",{designer:t.designer||d("archives.card.viewProject")}):d("archives.card.noExternalLink"),children:i.jsx(gh,{className:`w-3 h-3 sm:w-4 sm:h-4 ${!t.external_url&&!t.makerworld_url?"opacity-20":""}`})}),i.jsx(Oe,{variant:"secondary",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>{be.downloadArchive(t.id,`${t.print_name||t.filename}.3mf`).catch(ce=>{console.error("Archive download failed:",ce)})},title:d("archives.card.download"),children:i.jsx(pi,{className:"w-3 h-3 sm:w-4 sm:h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>A(!0),disabled:!v("archives","delete",t.created_by_id),title:v("archives","delete",t.created_by_id)?d("archives.card.delete"):d("archives.card.noPermissionDelete"),children:i.jsx(Jt,{className:"w-3 h-3 sm:w-4 sm:h-4 text-red-400"})})]})]}),k&&i.jsx(sie,{archive:t,onClose:()=>R(!1)}),g&&i.jsx(M4,{archiveId:t.id,title:t.print_name||t.filename,fileType:soe(t.filename),onClose:()=>_(!1)}),N&&i.jsx(uu,{mode:"reprint",archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>T(!1)}),C&&i.jsx(Sn,{title:d("archives.modal.deleteArchive"),message:d("archives.modal.deleteConfirm",{name:t.print_name||t.filename}),confirmText:d("archives.modal.deleteButton"),variant:"danger",onConfirm:()=>{qe.mutate(),A(!1)},onCancel:()=>A(!1)}),le&&i.jsx(Sn,{title:d("archives.modal.removeSource3mf"),message:d("archives.modal.removeSource3mfConfirm",{name:t.print_name||t.filename}),confirmText:d("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{pe.mutate(),xe(!1)},onCancel:()=>xe(!1)}),Pe&&i.jsx(Sn,{title:d("archives.modal.removeF3d"),message:d("archives.modal.removeF3dConfirm",{name:t.print_name||t.filename}),confirmText:d("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{Ne.mutate(),q(!1)},onCancel:()=>q(!1)}),Z&&i.jsx(Sn,{title:d("archives.modal.removeTimelapse"),message:d("archives.modal.removeTimelapseConfirm",{name:t.print_name||t.filename}),confirmText:d("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{F.mutate(),j(!1)},onCancel:()=>j(!1)}),E&&i.jsx(oie,{x:E.x,y:E.y,items:Xe,onClose:()=>U(null)}),P&&t.timelapse_path&&i.jsx(aoe,{src:be.getArchiveTimelapse(t.id),title:d("archives.modal.timelapse",{name:t.print_name||t.filename}),downloadFilename:`${t.print_name||t.filename}_timelapse.mp4`,archiveId:t.id,onClose:()=>D(!1),onEdit:()=>{p.invalidateQueries({queryKey:["archives"]}),D(!1)}}),H&&G.length>0&&i.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-card-dark rounded-lg max-w-lg w-full max-h-[80vh] flex flex-col",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-700",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:d("archives.modal.selectTimelapse")}),i.jsx("p",{className:"text-sm text-gray-400 mt-1",children:d("archives.modal.selectTimelapseDesc")})]}),i.jsx("button",{onClick:()=>{z(!1),I([])},className:"text-gray-400 hover:text-white p-1",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsx("div",{className:"overflow-y-auto flex-1 p-2",children:G.map(ce=>i.jsxs("button",{onClick:()=>Le.mutate(ce.name),disabled:Le.isPending,className:"w-full text-left p-3 rounded-lg hover:bg-gray-700 transition-colors flex items-center gap-3 disabled:opacity-50",children:[i.jsx(fh,{className:"w-8 h-8 text-bambu-green flex-shrink-0"}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-white font-medium truncate",children:ce.name}),i.jsxs("p",{className:"text-sm text-gray-400",children:[oo(ce.size),ce.mtime&&` • ${Nf(ce.mtime,l)}`]})]})]},ce.name))}),i.jsx("div",{className:"p-4 border-t border-gray-700",children:i.jsx(Oe,{variant:"secondary",onClick:()=>{z(!1),I([])},className:"w-full",children:"Cancel"})})]})}),ee&&i.jsx(lie,{archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>ie(!1)}),X&&t.photos&&t.photos.length>0&&i.jsx(cie,{archiveId:t.id,archiveName:t.print_name||t.filename,photos:t.photos,onClose:()=>me(!1),onDelete:async ce=>{try{await be.deleteArchivePhoto(t.id,ce),p.invalidateQueries({queryKey:["archives"]}),f(d("archives.toast.photoDeleted"))}catch{f(d("archives.toast.failedDeletePhoto"),"error")}}}),he&&i.jsx(ioe,{archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>ge(!1)}),Y&&i.jsx(uu,{mode:"add-to-queue",archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>oe(!1)}),i.jsx("input",{ref:V,type:"file",accept:".3mf",className:"hidden",onChange:ce=>{const Ie=ce.target.files?.[0];Ie&&ve.mutate(Ie),ce.target.value=""}}),i.jsx("input",{ref:J,type:"file",accept:".f3d",className:"hidden",onChange:ce=>{const Ie=ce.target.files?.[0];Ie&&de.mutate(Ie),ce.target.value=""}}),i.jsx("input",{ref:W,type:"file",accept:".mp4,.avi,.mkv",className:"hidden",onChange:ce=>{const Ie=ce.target.files?.[0];Ie&&te.mutate(Ie),ce.target.value=""}})]})}function iZe({archive:t,printerName:e,isSelected:n,onSelect:r,selectionMode:a,projects:s,isHighlighted:o,preferredSlicer:l="bambu_studio",t:c,onNavigateToArchive:u}){const d=an(),{showToast:m}=fn(),{hasPermission:p,canModify:f}=_r(),[y,v]=w.useState(!1),[x,g]=w.useState(!1),[_,N]=w.useState(!1),[T,C]=w.useState(!1),[A,k]=w.useState(!1),[R,P]=w.useState(!1),[D,H]=w.useState(!1),[z,G]=w.useState([]),[I,ee]=w.useState(!1),[ie,X]=w.useState(!1),[me,he]=w.useState(!1),[ge,Y]=w.useState(!1),[oe,le]=w.useState(!1),[xe,Pe]=w.useState(!1),[q,Z]=w.useState(null),j=w.useRef(null),E=w.useRef(null),U=w.useRef(null),K=t.duplicate_sequence??0,$=t.original_archive_id??null,ne=pt({mutationFn:()=>be.deleteArchiveTimelapse(t.id),onSuccess:()=>{d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.timelapseRemoved"))},onError:de=>{m(de.message||c("archives.toast.failedRemoveTimelapse"),"error")}}),O=pt({mutationFn:de=>be.uploadArchiveTimelapse(t.id,de),onSuccess:de=>{d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.timelapseUploaded",{filename:de.filename}))},onError:de=>{m(de.message||c("archives.toast.failedUploadTimelapse"),"error")}}),V=pt({mutationFn:de=>be.uploadSource3mf(t.id,de),onSuccess:de=>{d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.source3mfAttached",{filename:de.filename}))},onError:de=>{m(de.message||c("archives.toast.failedUploadSource3mf"),"error")}}),J=pt({mutationFn:()=>be.deleteSource3mf(t.id),onSuccess:()=>{d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.source3mfRemoved"))},onError:de=>{m(de.message||c("archives.toast.failedRemoveSource3mf"),"error")}}),W=pt({mutationFn:de=>be.uploadF3d(t.id,de),onSuccess:de=>{d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.f3dAttached",{filename:de.filename}))},onError:de=>{m(de.message||c("archives.toast.failedUploadF3d"),"error")}}),re=pt({mutationFn:()=>be.deleteF3d(t.id),onSuccess:()=>{d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.f3dRemoved"))},onError:de=>{m(de.message||c("archives.toast.failedRemoveF3d"),"error")}}),ue=pt({mutationFn:()=>be.scanArchiveTimelapse(t.id),onSuccess:de=>{de.status==="attached"?(d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.timelapseAttached",{filename:de.filename}))):de.status==="exists"?m(c("archives.toast.timelapseAlreadyAttached")):de.status==="not_found"&&de.available_files&&de.available_files.length>0?(G(de.available_files),H(!0)):m(de.message||c("archives.toast.noMatchingTimelapse"),"warning")},onError:de=>{m(de.message||c("archives.toast.failedScanTimelapse"),"error")}}),fe=pt({mutationFn:de=>be.selectArchiveTimelapse(t.id,de),onSuccess:de=>{d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.timelapseAttached",{filename:de.filename})),H(!1),G([])},onError:de=>{m(de.message||c("archives.toast.failedAttachTimelapse"),"error")}}),ye=pt({mutationFn:()=>be.deleteArchive(t.id),onSuccess:()=>{d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.archiveDeleted"))},onError:()=>{m(c("archives.toast.failedDeleteArchive"),"error")}}),ae=pt({mutationFn:()=>be.toggleFavorite(t.id),onSuccess:de=>{d.invalidateQueries({queryKey:["archives"]}),m(de.is_favorite?c("archives.toast.addedToFavorites"):c("archives.toast.removedFromFavorites"))}}),{data:L}=et({queryKey:["archive-folders",t.id],queryFn:()=>be.getLibraryFoldersByArchive(t.id)}),F=pt({mutationFn:de=>be.updateArchive(t.id,{project_id:de}),onSuccess:()=>{d.invalidateQueries({queryKey:["archives"]}),d.invalidateQueries({queryKey:["projects"]}),m(c("archives.toast.projectUpdated"))},onError:()=>{m(c("archives.toast.failedUpdateProject"),"error")}}),te=de=>{de.preventDefault(),Z({x:de.clientX,y:de.clientY})},pe=[...Jm(t)?[{label:c("archives.menu.print"),icon:i.jsx(Sr,{className:"w-4 h-4"}),onClick:()=>N(!0),disabled:!t.file_path||!f("archives","reprint",t.created_by_id),title:t.file_path?f("archives","reprint",t.created_by_id)?void 0:c("archives.permission.noReprint"):c("archives.card.noFileForReprint")},{label:c("archives.menu.schedule"),icon:i.jsx(Wr,{className:"w-4 h-4"}),onClick:()=>C(!0),disabled:!t.file_path||!p("queue:create"),title:t.file_path?p("queue:create")?void 0:c("archives.permission.noAddToQueue"):c("archives.card.noFileForReprint")},{label:c("archives.menu.openInBambuStudio"),icon:i.jsx(Jr,{className:"w-4 h-4"}),onClick:()=>{const de=t.print_name||t.filename||"model";eh(t.id,de,"file",l)},disabled:!t.file_path,title:t.file_path?void 0:c("archives.card.noFileForReprint")}]:[{label:c("archives.menu.slice"),icon:i.jsx(Jr,{className:"w-4 h-4"}),onClick:()=>{const de=t.print_name||t.filename||"model";eh(t.id,de,"file",l)}}],{label:t.external_url?c("archives.menu.externalLink"):c("archives.menu.viewOnMakerWorld"),icon:i.jsx(gh,{className:"w-4 h-4"}),onClick:()=>{const de=t.external_url||t.makerworld_url;de&&window.open(de,"_blank")},disabled:!t.external_url&&!t.makerworld_url},{label:"",divider:!0,onClick:()=>{}},{label:c("archives.menu.preview3d"),icon:i.jsx(ra,{className:"w-4 h-4"}),onClick:()=>k(!0)},{label:c("archives.menu.viewTimelapse"),icon:i.jsx(fh,{className:"w-4 h-4"}),onClick:()=>P(!0),disabled:!t.timelapse_path},{label:c("archives.menu.scanForTimelapse"),icon:i.jsx(RN,{className:"w-4 h-4"}),onClick:()=>ue.mutate(),disabled:!t.printer_id||!!t.timelapse_path||ue.isPending||!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")},{label:c("archives.menu.uploadTimelapse"),icon:i.jsx(xi,{className:"w-4 h-4"}),onClick:()=>U.current?.click(),disabled:!!t.timelapse_path||!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")},...t.timelapse_path?[{label:c("archives.menu.removeTimelapse"),icon:i.jsx(Jt,{className:"w-4 h-4"}),onClick:()=>Pe(!0),danger:!0,disabled:!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")}]:[],{label:"",divider:!0,onClick:()=>{}},{label:t.source_3mf_path?c("archives.menu.downloadSource3mf"):c("archives.menu.uploadSource3mf"),icon:i.jsx(MN,{className:"w-4 h-4"}),onClick:()=>{t.source_3mf_path?be.downloadSource3mf(t.id).catch(de=>{console.error("Source 3MF download failed:",de)}):j.current?.click()},disabled:!t.source_3mf_path&&!f("archives","update",t.created_by_id),title:!t.source_3mf_path&&!f("archives","update",t.created_by_id)?c("archives.permission.noUploadFiles"):void 0},...t.source_3mf_path?[{label:c("archives.menu.replaceSource3mf"),icon:i.jsx(xi,{className:"w-4 h-4"}),onClick:()=>j.current?.click(),disabled:!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")},{label:c("archives.menu.removeSource3mf"),icon:i.jsx(Jt,{className:"w-4 h-4"}),onClick:()=>Y(!0),danger:!0,disabled:!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")}]:[],{label:t.f3d_path?c("archives.menu.replaceF3d"):c("archives.menu.uploadF3d"),icon:i.jsx(ra,{className:"w-4 h-4"}),onClick:()=>E.current?.click(),disabled:!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")},...t.f3d_path?[{label:c("archives.menu.downloadF3d"),icon:i.jsx(pi,{className:"w-4 h-4"}),onClick:()=>{be.downloadF3d(t.id).catch(de=>{console.error("F3D download failed:",de)})}},{label:c("archives.menu.removeF3d"),icon:i.jsx(Jt,{className:"w-4 h-4"}),onClick:()=>le(!0),danger:!0,disabled:!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")}]:[],{label:"",divider:!0,onClick:()=>{}},{label:c("archives.menu.download"),icon:i.jsx(pi,{className:"w-4 h-4"}),onClick:()=>{be.downloadArchive(t.id,`${t.print_name||t.filename}.3mf`).catch(de=>{console.error("Archive download failed:",de)})},disabled:!p("archives:read"),title:p("archives:read")?void 0:c("archives.permission.noDownload")},{label:c("archives.menu.copyDownloadLink"),icon:i.jsx(fo,{className:"w-4 h-4"}),onClick:()=>{const de=`${window.location.origin}${be.getArchiveDownload(t.id)}`;navigator.clipboard.writeText(de).then(()=>{m(c("archives.toast.linkCopied"))}).catch(()=>{m(c("archives.toast.failedCopyLink"),"error")})},disabled:!p("archives:read"),title:p("archives:read")?void 0:c("archives.permission.noCopyLink")},{label:c("archives.menu.qrCode"),icon:i.jsx(YX,{className:"w-4 h-4"}),onClick:()=>ee(!0)},{label:t.photos?.length?c("archives.menu.viewPhotosCount",{count:t.photos.length}):c("archives.menu.viewPhotos"),icon:i.jsx(rx,{className:"w-4 h-4"}),onClick:()=>X(!0),disabled:!t.photos?.length},{label:c("archives.menu.projectPage"),icon:i.jsx(Fs,{className:"w-4 h-4"}),onClick:()=>he(!0)},{label:"",divider:!0,onClick:()=>{}},{label:t.is_favorite?c("archives.menu.removeFromFavorites"):c("archives.menu.addToFavorites"),icon:i.jsx(wf,{className:`w-4 h-4 ${t.is_favorite?"fill-yellow-400 text-yellow-400":""}`}),onClick:()=>ae.mutate(),disabled:!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")},{label:c("archives.menu.edit"),icon:i.jsx(Yi,{className:"w-4 h-4"}),onClick:()=>v(!0),disabled:!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")},...t.project_id&&t.project_name?[{label:c("archives.menu.goToProject",{name:t.project_name}),icon:i.jsx(fs,{className:"w-4 h-4 text-bambu-green"}),onClick:()=>window.location.href="/projects"}]:[],{label:c("archives.menu.addToProject"),icon:i.jsx(fs,{className:"w-4 h-4"}),onClick:()=>{},submenu:(()=>{const de=[];if(t.project_id&&de.push({label:c("archives.menu.removeFromProject"),icon:i.jsx(Ht,{className:"w-4 h-4"}),onClick:()=>F.mutate(null)}),!s)de.push({label:c("archives.menu.loading"),icon:i.jsx(ht,{className:"w-4 h-4 animate-spin"}),onClick:()=>{},disabled:!0});else{const Ne=s.filter(Se=>Se.status==="active");Ne.length===0?de.push({label:c("archives.menu.noProjectsAvailable"),icon:i.jsx(fs,{className:"w-4 h-4 opacity-50"}),onClick:()=>{},disabled:!0}):Ne.forEach(Se=>{de.push({label:Se.name,icon:i.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:Se.color||"#888"}}),onClick:()=>F.mutate(Se.id),disabled:t.project_id===Se.id})})}return de})()},{label:c(n?"archives.menu.deselect":"archives.menu.select"),icon:n?i.jsx(xo,{className:"w-4 h-4"}):i.jsx(zl,{className:"w-4 h-4"}),onClick:()=>r(t.id)},{label:"",divider:!0,onClick:()=>{}},{label:c("archives.menu.delete"),icon:i.jsx(Jt,{className:"w-4 h-4"}),onClick:()=>g(!0),danger:!0,disabled:!f("archives","delete",t.created_by_id),title:f("archives","delete",t.created_by_id)?void 0:c("archives.permission.noDelete")}];return i.jsxs(i.Fragment,{children:[i.jsxs("div",{"data-archive-id":t.id,className:`grid grid-cols-12 gap-4 px-4 py-3 items-center hover:bg-bambu-dark-tertiary/30 ${n?"bg-bambu-green/10":""}`,style:o?{outline:"4px solid #facc15",outlineOffset:"-4px"}:void 0,onContextMenu:te,children:[i.jsxs("div",{className:"col-span-1 flex items-center gap-2",children:[a&&i.jsx("button",{onClick:()=>r(t.id),children:n?i.jsx(xo,{className:"w-4 h-4 text-bambu-green"}):i.jsx(zl,{className:"w-4 h-4 text-bambu-gray"})}),t.thumbnail_path?i.jsx("img",{src:be.getArchiveThumbnail(t.id),alt:"",className:"w-10 h-10 object-cover rounded"}):i.jsx("div",{className:"w-10 h-10 bg-bambu-dark rounded flex items-center justify-center",children:i.jsx(Ed,{className:"w-5 h-5 text-bambu-dark-tertiary"})})]}),i.jsxs("div",{className:"col-span-4",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("p",{className:"text-white text-sm truncate",children:t.print_name||t.filename}),(t.status==="failed"||t.status==="aborted")&&i.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] leading-tight bg-status-error/80 text-white flex-shrink-0",children:t.status==="aborted"?c("archives.card.cancelled"):c("archives.card.failed")}),t.duplicate_count>0&&K>0&&$&&i.jsxs("button",{onClick:de=>{de.stopPropagation(),u?.($)},className:"px-1.5 py-0.5 rounded text-[10px] leading-tight bg-purple-500/80 hover:bg-purple-600/90 text-white flex-shrink-0 transition-colors flex items-center gap-1",title:c("archives.viewOriginalPrint",{id:$}),children:[i.jsx(fo,{className:"w-3 h-3"}),"#",K]}),t.duplicate_count>0&&K===0&&i.jsxs("span",{className:"px-1.5 py-0.5 rounded text-[10px] leading-tight bg-purple-500/80 text-white flex-shrink-0 flex items-center gap-1",title:`${t.duplicate_count} reprint${t.duplicate_count===1?"":"s"}`,children:[i.jsx(VX,{className:"w-3 h-3"}),"+",t.duplicate_count]}),t.timelapse_path&&i.jsx("span",{title:c("archives.list.hasTimelapse"),children:i.jsx(fh,{className:"w-3.5 h-3.5 text-bambu-green flex-shrink-0"})}),L&&L.length>0&&i.jsx(io,{to:`/files?folder=${L[0].id}`,className:"flex-shrink-0",title:c("archives.card.openFolder",{name:L[0].name}),onClick:de=>de.stopPropagation(),children:i.jsx(Nc,{className:"w-3.5 h-3.5 text-yellow-400"})})]}),(t.filament_type||t.sliced_for_model)&&i.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[t.sliced_for_model&&i.jsxs("span",{className:"text-xs text-bambu-gray flex items-center gap-1",title:c("archives.card.slicedFor",{model:t.sliced_for_model}),children:[i.jsx(Sr,{className:"w-2.5 h-2.5"}),t.sliced_for_model]}),t.sliced_for_model&&t.filament_type&&i.jsx("span",{className:"text-bambu-gray/50",children:"·"}),t.filament_type&&i.jsx("span",{className:"text-xs text-bambu-gray",children:t.filament_type}),t.filament_color&&i.jsx("div",{className:"flex items-center gap-0.5 flex-wrap",children:t.filament_color.split(",").map((de,Ne)=>i.jsx("div",{className:"w-2.5 h-2.5 rounded-full border border-black/20",style:{backgroundColor:de},title:de},Ne))})]})]}),i.jsx("div",{className:"col-span-2 text-sm text-bambu-gray truncate",children:e}),i.jsxs("div",{className:"col-span-2 text-sm text-bambu-gray",children:[i.jsx("div",{children:_f(t.created_at)}),t.created_by_username&&i.jsxs("div",{className:"flex items-center gap-1 text-xs opacity-75",title:c("archives.card.uploadedBy",{name:t.created_by_username}),children:[i.jsx(Rd,{className:"w-3 h-3"}),t.created_by_username]})]}),i.jsx("div",{className:"col-span-1 text-sm text-bambu-gray",children:oo(t.file_size)}),i.jsxs("div",{className:"col-span-2 flex justify-end gap-1",children:[Jm(t)&&i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>N(!0),disabled:!f("archives","reprint",t.created_by_id),title:f("archives","reprint",t.created_by_id)?c("archives.card.reprint"):c("archives.card.noPermissionReprint"),className:"text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10",children:i.jsx(go,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>{const de=t.print_name||t.filename||"model";eh(t.id,de,"file",l)},title:c("archives.card.openInBambuStudio"),children:i.jsx(Jr,{className:"w-4 h-4"})}),(t.external_url||t.makerworld_url)&&i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>window.open(t.external_url||t.makerworld_url,"_blank"),title:t.external_url?c("archives.card.externalLink"):"MakerWorld",children:i.jsx(gh,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>{be.downloadArchive(t.id,`${t.print_name||t.filename}.3mf`).catch(de=>{console.error("Archive download failed:",de)})},title:c("archives.card.download"),children:i.jsx(pi,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>v(!0),disabled:!f("archives","update",t.created_by_id),title:f("archives","update",t.created_by_id)?c("archives.card.edit"):c("archives.card.noPermissionEdit"),children:i.jsx(Yi,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>g(!0),disabled:!f("archives","delete",t.created_by_id),title:f("archives","delete",t.created_by_id)?c("archives.card.delete"):c("archives.card.noPermissionDelete"),children:i.jsx(Jt,{className:"w-4 h-4 text-red-400"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:de=>{const Ne=de.currentTarget.getBoundingClientRect();Z({x:Ne.left,y:Ne.bottom+4})},title:c("archives.card.moreOptions"),children:i.jsx(ph,{className:"w-4 h-4"})})]})]}),y&&i.jsx(sie,{archive:t,onClose:()=>v(!1)}),A&&i.jsx(M4,{archiveId:t.id,title:t.print_name||t.filename,fileType:soe(t.filename),onClose:()=>k(!1)}),_&&i.jsx(uu,{mode:"reprint",archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>N(!1)}),x&&i.jsx(Sn,{title:c("archives.modal.deleteArchive"),message:c("archives.modal.deleteConfirm",{name:t.print_name||t.filename}),confirmText:c("archives.modal.deleteButton"),variant:"danger",onConfirm:()=>{ye.mutate(),g(!1)},onCancel:()=>g(!1)}),ge&&i.jsx(Sn,{title:c("archives.modal.removeSource3mf"),message:c("archives.modal.removeSource3mfConfirm",{name:t.print_name||t.filename}),confirmText:c("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{J.mutate(),Y(!1)},onCancel:()=>Y(!1)}),oe&&i.jsx(Sn,{title:c("archives.modal.removeF3d"),message:c("archives.modal.removeF3dConfirm",{name:t.print_name||t.filename}),confirmText:c("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{re.mutate(),le(!1)},onCancel:()=>le(!1)}),xe&&i.jsx(Sn,{title:c("archives.modal.removeTimelapse"),message:c("archives.modal.removeTimelapseConfirm",{name:t.print_name||t.filename}),confirmText:c("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{ne.mutate(),Pe(!1)},onCancel:()=>Pe(!1)}),q&&i.jsx(oie,{x:q.x,y:q.y,items:pe,onClose:()=>Z(null)}),R&&t.timelapse_path&&i.jsx(aoe,{src:be.getArchiveTimelapse(t.id),title:c("archives.modal.timelapse",{name:t.print_name||t.filename}),downloadFilename:`${t.print_name||t.filename}_timelapse.mp4`,archiveId:t.id,onClose:()=>P(!1),onEdit:()=>{d.invalidateQueries({queryKey:["archives"]}),P(!1)}}),D&&z.length>0&&i.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-card-dark rounded-lg max-w-lg w-full max-h-[80vh] flex flex-col",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-700",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:c("archives.modal.selectTimelapse")}),i.jsx("p",{className:"text-sm text-gray-400 mt-1",children:c("archives.modal.selectTimelapseDesc")})]}),i.jsx("button",{onClick:()=>{H(!1),G([])},className:"text-gray-400 hover:text-white p-1",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsx("div",{className:"overflow-y-auto flex-1 p-2",children:z.map(de=>i.jsxs("button",{onClick:()=>fe.mutate(de.name),disabled:fe.isPending,className:"w-full text-left p-3 rounded-lg hover:bg-gray-700 transition-colors mb-1",children:[i.jsx("div",{className:"font-medium text-white",children:de.name}),i.jsxs("div",{className:"text-sm text-gray-400 flex gap-3",children:[i.jsx("span",{children:oo(de.size)}),de.mtime&&i.jsx("span",{children:_f(de.mtime)})]})]},de.name))})]})}),I&&i.jsx(lie,{archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>ee(!1)}),ie&&t.photos&&i.jsx(cie,{archiveId:t.id,archiveName:t.print_name||t.filename,photos:t.photos,onClose:()=>X(!1),onDelete:async de=>{try{await be.deleteArchivePhoto(t.id,de),d.invalidateQueries({queryKey:["archives"]}),m(c("archives.toast.photoDeleted"))}catch{m(c("archives.toast.failedDeletePhoto"),"error")}}}),me&&i.jsx(ioe,{archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>he(!1)}),T&&i.jsx(uu,{mode:"add-to-queue",archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>C(!1)}),i.jsx("input",{ref:j,type:"file",accept:".3mf",className:"hidden",onChange:de=>{const Ne=de.target.files?.[0];Ne&&V.mutate(Ne),de.target.value=""}}),i.jsx("input",{ref:E,type:"file",accept:".f3d",className:"hidden",onChange:de=>{const Ne=de.target.files?.[0];Ne&&W.mutate(Ne),de.target.value=""}}),i.jsx("input",{ref:U,type:"file",accept:".mp4,.avi,.mkv",className:"hidden",onChange:de=>{const Ne=de.target.files?.[0];Ne&&O.mutate(Ne),de.target.value=""}})]})}const aZe=[{id:"all",label:"All Archives",icon:i.jsx(Nc,{className:"w-4 h-4"})},{id:"recent",label:"Last 24 Hours",icon:i.jsx(er,{className:"w-4 h-4"})},{id:"this-week",label:"This Week",icon:i.jsx(Wr,{className:"w-4 h-4"})},{id:"this-month",label:"This Month",icon:i.jsx(Wr,{className:"w-4 h-4"})},{id:"favorites",label:"Favorites",icon:i.jsx(wf,{className:"w-4 h-4"})},{id:"failed",label:"Failed Prints",icon:i.jsx(Li,{className:"w-4 h-4"})},{id:"duplicates",label:"Duplicates",icon:i.jsx(fo,{className:"w-4 h-4"})}];function sZe(){const{t}=Ft(),e=an(),{showToast:n}=fn(),{hasPermission:r,hasAnyPermission:a}=_r(),s=w.useRef(null),[o,l]=w.useState(""),[c,u]=w.useState(()=>{const se=localStorage.getItem("archiveFilterPrinter");return se?Number(se):null}),[d,m]=w.useState(()=>localStorage.getItem("archiveFilterMaterial")),[p,f]=w.useState(()=>{const se=localStorage.getItem("archiveFilterColors");return se?new Set(JSON.parse(se)):new Set}),[y,v]=w.useState(()=>localStorage.getItem("archiveColorFilterMode")||"or"),[x,g]=w.useState(()=>localStorage.getItem("archiveFilterFavorites")==="true"),[_,N]=w.useState(()=>localStorage.getItem("archiveHideFailed")==="true"),[T,C]=w.useState(()=>localStorage.getItem("archiveHideDuplicates")==="true"),[A,k]=w.useState(()=>localStorage.getItem("archiveFilterTag")),[R,P]=w.useState(()=>localStorage.getItem("archiveFilterFileType")||"all"),[D,H]=w.useState(!1),[z,G]=w.useState([]),[I,ee]=w.useState(!1),[ie,X]=w.useState(new Set),[me,he]=w.useState(!1),[ge,Y]=w.useState(!1),[oe,le]=w.useState(!1),[xe,Pe]=w.useState(!1),[q,Z]=w.useState(()=>localStorage.getItem("archiveViewMode")||"grid"),[j,E]=w.useState(()=>localStorage.getItem("archiveSortBy")||"date-desc"),[U,K]=w.useState(()=>localStorage.getItem("archiveCollection")||"all"),[$,ne]=w.useState(!1),[O,V]=w.useState(!1),[J,W]=w.useState(!1),[re,ue]=w.useState(!1),[fe,ye]=w.useState(null),[ae,L]=w.useState(null),[F,te]=w.useState(()=>localStorage.getItem("logFilterUser")||null),[ve,pe]=w.useState(()=>localStorage.getItem("logFilterStatus")),[de,Ne]=w.useState(()=>localStorage.getItem("logFilterDateFrom")||""),[Se,Le]=w.useState(()=>localStorage.getItem("logFilterDateTo")||""),[qe,Ee]=w.useState(()=>{const se=localStorage.getItem("logOffset");return se?Number(se):0}),[Te,Ae]=w.useState(!1),[Be,je]=w.useState(()=>{const se=localStorage.getItem("logPageSize");return se?Number(se):25}),Xe=w.useCallback(se=>{L(se),ye(se)},[]);w.useEffect(()=>{if(fe){const se=setTimeout(()=>{const Ke=document.querySelector(`[data-archive-id="${fe}"]`);Ke?Ke.scrollIntoView({behavior:"smooth",block:"center"}):ae===fe&&n(t("archives.originalPrintNotVisible"),"warning"),ae===fe&&L(null)},100),He=setTimeout(()=>ye(null),5e3);return()=>{clearTimeout(se),clearTimeout(He)}}},[fe,ae,n,t]);const{data:ce,isLoading:Ie}=et({queryKey:["archives",c],queryFn:()=>be.getArchives(c||void 0)}),{data:Ce}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:Ge}=et({queryKey:["projects"],queryFn:()=>be.getProjects()}),{data:$e}=et({queryKey:["settings"],queryFn:be.getSettings}),{data:Ue}=et({queryKey:["users"],queryFn:be.getUsers,enabled:q==="log"}),{data:De,isLoading:Ve}=et({queryKey:["print-log",c,F,ve,de,Se,o,qe,Be],queryFn:()=>be.getPrintLog({search:o||void 0,printerId:c||void 0,username:F||void 0,status:ve||void 0,dateFrom:de||void 0,dateTo:Se||void 0,limit:Be,offset:qe}),enabled:q==="log"}),it=$e?.time_format||"system",xt=$e?.preferred_slicer||"bambu_studio",Nt=_l($e?.currency||"USD"),kt=pt({mutationFn:async se=>(await Promise.all(se.map(He=>be.deleteArchive(He))),se.length),onSuccess:se=>{e.invalidateQueries({queryKey:["archives"]}),X(new Set),n(`${se} archive${se!==1?"s":""} deleted`)},onError:()=>{n(t("archives.toast.failedDeleteArchives"),"error")}}),We=pt({mutationFn:()=>be.clearPrintLog(),onSuccess:se=>{e.invalidateQueries({queryKey:["print-log"]}),Ee(0),n(t("archives.log.cleared",{count:se.deleted}))},onError:()=>{n(t("archives.log.clearFailed"),"error")}});w.useEffect(()=>{c!==null?localStorage.setItem("archiveFilterPrinter",c.toString()):localStorage.removeItem("archiveFilterPrinter")},[c]),w.useEffect(()=>{d?localStorage.setItem("archiveFilterMaterial",d):localStorage.removeItem("archiveFilterMaterial")},[d]),w.useEffect(()=>{localStorage.setItem("archiveFilterColors",JSON.stringify([...p]))},[p]),w.useEffect(()=>{localStorage.setItem("archiveColorFilterMode",y)},[y]),w.useEffect(()=>{localStorage.setItem("archiveFilterFavorites",x.toString())},[x]),w.useEffect(()=>{localStorage.setItem("archiveHideFailed",_.toString())},[_]),w.useEffect(()=>{localStorage.setItem("archiveHideDuplicates",T.toString())},[T]),w.useEffect(()=>{A?localStorage.setItem("archiveFilterTag",A):localStorage.removeItem("archiveFilterTag")},[A]),w.useEffect(()=>{localStorage.setItem("archiveFilterFileType",R)},[R]),w.useEffect(()=>{localStorage.setItem("archiveViewMode",q)},[q]),w.useEffect(()=>{localStorage.setItem("archiveSortBy",j)},[j]),w.useEffect(()=>{localStorage.setItem("archiveCollection",U)},[U]),w.useEffect(()=>{F?localStorage.setItem("logFilterUser",F):localStorage.removeItem("logFilterUser")},[F]),w.useEffect(()=>{ve?localStorage.setItem("logFilterStatus",ve):localStorage.removeItem("logFilterStatus")},[ve]),w.useEffect(()=>{de?localStorage.setItem("logFilterDateFrom",de):localStorage.removeItem("logFilterDateFrom")},[de]),w.useEffect(()=>{Se?localStorage.setItem("logFilterDateTo",Se):localStorage.removeItem("logFilterDateTo")},[Se]),w.useEffect(()=>{localStorage.setItem("logOffset",qe.toString())},[qe]),w.useEffect(()=>{localStorage.setItem("logPageSize",Be.toString())},[Be]);const yt=new Map(Ce?.map(se=>[se.id,se.name])||[]),wt=[...new Set(ce?.flatMap(se=>se.filament_type?.split(", ")||[]).filter(Boolean)||[])].sort(),_t=[...new Set(ce?.flatMap(se=>se.filament_color?.split(",")||[]).filter(Boolean)||[])],Ot=[...new Set(ce?.flatMap(se=>se.tags?.split(",").map(He=>He.trim())||[]).filter(Boolean)||[])].sort(),Vt=ce?.filter(se=>{const He=new Date,Ke=Jn(se.created_at)||new Date(0);let Ye=!0;switch(U){case"recent":Ye=He.getTime()-Ke.getTime()<1440*60*1e3;break;case"this-week":Ye=He.getTime()-Ke.getTime()<10080*60*1e3;break;case"this-month":Ye=Ke.getMonth()===He.getMonth()&&Ke.getFullYear()===He.getFullYear();break;case"favorites":Ye=se.is_favorite===!0;break;case"failed":Ye=se.status==="failed"||se.status==="aborted";break;case"duplicates":Ye=se.duplicate_count>0;break}const Me=(se.print_name||se.filename).toLowerCase().includes(o.toLowerCase()),dt=!d||se.filament_type?.split(", ").includes(d),ct=se.filament_color?.split(",")||[],nt=p.size===0||(y==="or"?ct.some(_n=>p.has(_n)):[...p].every(_n=>ct.includes(_n))),bt=U==="favorites"||!x||se.is_favorite,Ut=U==="failed"||!_||se.status!=="failed"&&se.status!=="aborted",Et=U==="duplicates"||!T||se.duplicate_count===0||se.duplicate_sequence===0,It=se.tags?.split(",").map(_n=>_n.trim())||[],Zt=!A||It.includes(A),tn=Jm(se);return Ye&&Me&&dt&&nt&&bt&&Ut&&Et&&Zt&&(R==="all"||R==="gcode"&&tn||R==="source"&&!tn)}).sort((se,He)=>{switch(j){case"date-desc":return(Jn(He.created_at)?.getTime()||0)-(Jn(se.created_at)?.getTime()||0);case"date-asc":return(Jn(se.created_at)?.getTime()||0)-(Jn(He.created_at)?.getTime()||0);case"name-asc":return(se.print_name||se.filename).localeCompare(He.print_name||He.filename);case"name-desc":return(He.print_name||He.filename).localeCompare(se.print_name||se.filename);case"size-desc":return He.file_size-se.file_size;case"size-asc":return se.file_size-He.file_size;default:return 0}}),Xt=me||ie.size>0,Qe=se=>{X(He=>{const Ke=new Set(He);return Ke.has(se)?Ke.delete(se):Ke.add(se),Ke})},Qt=()=>{Vt&&X(new Set(Vt.map(se=>se.id)))},hn=()=>{X(new Set),he(!1)},jn=se=>{f(He=>{const Ke=new Set(He);return Ke.has(se)?Ke.delete(se):Ke.add(se),Ke})},kn=()=>{f(new Set)},Fe=()=>{l(""),u(null),m(null),g(!1),N(!1),C(!1),k(null),P("all")},tt=o||c||d||x||_||T||A||R!=="all",ut=w.useCallback(se=>{se.preventDefault(),se.dataTransfer.types.includes("Files")&&ee(!0)},[]),Ze=w.useCallback(se=>{se.preventDefault(),se.currentTarget===se.target&&ee(!1)},[]),ke=w.useCallback(se=>{se.preventDefault(),ee(!1);const He=Array.from(se.dataTransfer.files).filter(Ke=>Ke.name.endsWith(".3mf"));He.length>0?(G(He),H(!0)):se.dataTransfer.files.length>0&&n(t("archives.page.only3mfSupported"),"warning")},[n,t]),ot=w.useCallback(se=>{const He=se.target;if(He.tagName==="INPUT"||He.tagName==="TEXTAREA"||He.isContentEditable){se.key==="Escape"&&He.blur();return}switch(se.key){case"/":se.preventDefault(),s.current?.focus();break;case"u":case"U":!se.metaKey&&!se.ctrlKey&&(se.preventDefault(),H(!0));break;case"Escape":Xt&&hn();break}},[Xt]);return w.useEffect(()=>(document.addEventListener("keydown",ot),()=>document.removeEventListener("keydown",ot)),[ot]),i.jsxs("div",{className:"p-4 md:p-8 relative",onDragOver:ut,onDragLeave:Ze,onDrop:ke,children:[I&&i.jsx("div",{className:"fixed inset-0 z-50 bg-bambu-dark/90 flex items-center justify-center pointer-events-none",children:i.jsxs("div",{className:"border-4 border-dashed border-bambu-green rounded-xl p-12 text-center",children:[i.jsx(xi,{className:"w-16 h-16 mx-auto mb-4 text-bambu-green"}),i.jsx("p",{className:"text-2xl font-semibold text-white mb-2",children:"Drop .3mf files here"}),i.jsx("p",{className:"text-bambu-gray",children:t("archives.releaseToUpload")})]})}),Xt&&i.jsxs("div",{className:"fixed bottom-6 left-1/2 -translate-x-1/2 z-40 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl px-4 py-3 flex items-center gap-4",children:[i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:hn,children:[i.jsx(Ht,{className:"w-4 h-4"}),"Close"]}),i.jsx("div",{className:"w-px h-6 bg-bambu-dark-tertiary"}),i.jsxs("span",{className:"text-white font-medium",children:[ie.size," selected"]}),i.jsx("div",{className:"w-px h-6 bg-bambu-dark-tertiary"}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:Qt,children:"Select All"}),i.jsx("div",{className:"w-px h-6 bg-bambu-dark-tertiary"}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>le(!0),disabled:!a("archives:update_own","archives:update_all"),title:a("archives:update_own","archives:update_all")?void 0:t("archives.permission.noUpdateArchives"),children:[i.jsx(Dd,{className:"w-4 h-4"}),"Tags"]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>Pe(!0),disabled:!a("archives:update_own","archives:update_all"),title:a("archives:update_own","archives:update_all")?void 0:t("archives.permission.noUpdateArchives"),children:[i.jsx(fs,{className:"w-4 h-4"}),"Project"]}),i.jsxs(Oe,{variant:"secondary",size:"sm",disabled:!a("archives:update_own","archives:update_all"),title:a("archives:update_own","archives:update_all")?void 0:t("archives.permission.noUpdateArchives"),onClick:()=>{const se=Array.from(ie);Promise.all(se.map(He=>be.toggleFavorite(He))).then(()=>{e.invalidateQueries({queryKey:["archives"]}),n(`Toggled favorites for ${se.length} archive${se.length!==1?"s":""}`)}).catch(()=>{n(t("archives.toast.failedUpdateFavorites"),"error")})},children:[i.jsx(wf,{className:"w-4 h-4"}),"Favorite"]}),i.jsxs(Oe,{size:"sm",className:"bg-red-500 hover:bg-red-600",onClick:()=>Y(!0),disabled:!a("archives:delete_own","archives:delete_all"),title:a("archives:delete_own","archives:delete_all")?void 0:t("archives.permission.noDelete"),children:[i.jsx(Jt,{className:"w-4 h-4"}),"Delete"]})]}),i.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-8",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:"Archives"}),i.jsx("select",{className:"px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray-light text-sm focus:border-bambu-green focus:outline-none",value:U,onChange:se=>K(se.target.value),children:aZe.map(se=>i.jsx("option",{value:se.id,children:se.label},se.id))})]}),i.jsxs("p",{className:"text-bambu-gray",children:[Vt?.length||0," of ",ce?.length||0," prints"]})]}),i.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 flex-wrap",children:[i.jsxs("div",{className:"relative",children:[i.jsxs(Oe,{variant:"secondary",onClick:()=>ne(!$),disabled:O,children:[O?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(EN,{className:"w-4 h-4"}),"Export"]}),$&&i.jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20",children:[i.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg",onClick:async()=>{ne(!1),V(!0);try{const{blob:se,filename:He}=await be.exportArchives({format:"csv",printerId:c||void 0,status:U==="failed"?"failed":void 0,search:o||void 0}),Ke=URL.createObjectURL(se),Ye=document.createElement("a");Ye.href=Ke,Ye.download=He,Ye.click(),URL.revokeObjectURL(Ke),n(t("archives.toast.exportDownloaded"))}catch{n(t("archives.toast.exportFailed"),"error")}finally{V(!1)}},children:[i.jsx(Fs,{className:"w-4 h-4"}),"Export as CSV"]}),i.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg",onClick:async()=>{ne(!1),V(!0);try{const{blob:se,filename:He}=await be.exportArchives({format:"xlsx",printerId:c||void 0,status:U==="failed"?"failed":void 0,search:o||void 0}),Ke=URL.createObjectURL(se),Ye=document.createElement("a");Ye.href=Ke,Ye.download=He,Ye.click(),URL.revokeObjectURL(Ke),n(t("archives.toast.exportDownloaded"))}catch{n(t("archives.toast.exportFailed"),"error")}finally{V(!1)}},children:[i.jsx(EN,{className:"w-4 h-4"}),"Export as Excel"]})]})]}),ie.size>=2&&ie.size<=5&&i.jsxs(Oe,{variant:"secondary",onClick:()=>W(!0),children:[i.jsx(zb,{className:"w-4 h-4"}),"Compare (",ie.size,")"]}),!Xt&&i.jsxs(Oe,{variant:"secondary",onClick:()=>he(!0),children:[i.jsx(xo,{className:"w-4 h-4"}),"Select"]}),i.jsxs(Oe,{onClick:()=>H(!0),disabled:!r("archives:create"),title:r("archives:create")?void 0:t("archives.permission.noCreate"),children:[i.jsx(xi,{className:"w-4 h-4"}),"Upload 3MF"]})]})]}),i.jsxs("div",{className:"flex items-center border border-bambu-dark-tertiary rounded-lg overflow-hidden flex-shrink-0 w-fit mb-4",children:[i.jsx("button",{className:`p-2 ${q==="grid"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,onClick:()=>Z("grid"),title:t("archives.gridView"),children:i.jsx(pw,{className:"w-4 h-4"})}),i.jsx("button",{className:`p-2 ${q==="list"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,onClick:()=>Z("list"),title:t("archives.listView"),children:i.jsx(JC,{className:"w-4 h-4"})}),i.jsx("button",{className:`p-2 ${q==="calendar"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,onClick:()=>Z("calendar"),title:t("archives.calendarView"),children:i.jsx(Rhe,{className:"w-4 h-4"})}),i.jsx("button",{className:`p-2 ${q==="log"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,onClick:()=>Z("log"),title:t("archives.logView"),children:i.jsx(rpe,{className:"w-4 h-4"})})]}),q!=="log"&&i.jsx(Mt,{className:"mb-6",children:i.jsxs(Dt,{className:"py-4",children:[i.jsxs("div",{className:"flex flex-col md:flex-row gap-3 md:gap-4 md:items-center md:flex-wrap",children:[i.jsxs("div",{className:"w-full md:flex-1 relative md:min-w-[200px]",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{ref:s,type:"text",placeholder:t("archives.searchPlaceholder"),className:"w-full pl-10 pr-4 py-3 md:py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:o,onChange:se=>l(se.target.value)})]}),i.jsxs("div",{className:"flex gap-2 md:gap-4 overflow-x-auto pb-1 md:pb-0 -mx-4 px-4 md:mx-0 md:px-0 md:flex-wrap scrollbar-hide",children:[i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[i.jsx(QC,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),i.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:c||"",onChange:se=>u(se.target.value?Number(se.target.value):null),children:[i.jsx("option",{value:"",children:"All Printers"}),Ce?.map(se=>i.jsx("option",{value:se.id,children:se.name},se.id))]})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[i.jsx(Wi,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),i.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:se=>m(se.target.value||null),children:[i.jsx("option",{value:"",children:"All Materials"}),wt.map(se=>i.jsx("option",{value:se,children:se},se))]})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[i.jsx(MN,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),i.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:R,onChange:se=>P(se.target.value),children:[i.jsx("option",{value:"all",children:"All Files"}),i.jsx("option",{value:"gcode",children:"Sliced (GCODE)"}),i.jsx("option",{value:"source",children:"Source Only"})]})]}),i.jsxs("button",{onClick:()=>g(!x),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${x?"bg-yellow-500/20 border-yellow-500 text-yellow-400":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,title:t(x?"archives.showAll":"archives.showFavoritesOnly"),children:[i.jsx(wf,{className:`w-4 h-4 ${x?"fill-yellow-400":""}`}),i.jsx("span",{className:"text-sm hidden md:inline",children:"Favorites"})]}),i.jsxs("button",{onClick:()=>N(!_),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${_?"bg-red-500/20 border-red-500 text-red-400":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,title:t(_?"archives.showFailedPrints":"archives.hideFailedPrints"),children:[i.jsx(Li,{className:"w-4 h-4 "}),i.jsx("span",{className:"text-sm hidden md:inline",children:"Hide Failed"})]}),i.jsxs("button",{onClick:()=>C(!T),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${T?"bg-purple-500/20 border-purple-500 text-purple-400":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,title:t("archives.hideDuplicates"),children:[i.jsx(fo,{className:"w-4 h-4"}),i.jsx("span",{className:"text-sm hidden md:inline",children:t("archives.hideDuplicates")})]}),Ot.length>0&&i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[i.jsx(Dd,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),i.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:A||"",onChange:se=>k(se.target.value||null),children:[i.jsx("option",{value:"",children:"All Tags"}),Ot.map(se=>i.jsx("option",{value:se,children:se},se))]}),i.jsx("button",{onClick:()=>ue(!0),className:"p-2 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-green transition-colors",title:t("archives.manageTags"),children:i.jsx(iT,{className:"w-4 h-4"})})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[i.jsx(IL,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),i.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:j,onChange:se=>E(se.target.value),children:[i.jsx("option",{value:"date-desc",children:t("archives.sortNewest")}),i.jsx("option",{value:"date-asc",children:t("archives.sortOldest")}),i.jsxs("option",{value:"name-asc",children:[t("archives.sortName")," A-Z"]}),i.jsxs("option",{value:"name-desc",children:[t("archives.sortName")," Z-A"]}),i.jsx("option",{value:"size-desc",children:t("archives.sortLargest")}),i.jsx("option",{value:"size-asc",children:t("archives.sortSmallest")})]})]})]}),tt&&i.jsxs(Oe,{variant:"ghost",size:"sm",onClick:Fe,className:"text-bambu-gray hover:text-white",children:[i.jsx(Ht,{className:"w-4 h-4"}),"Reset"]})]}),_t.length>0&&i.jsxs("div",{className:"flex items-center gap-3 mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:"Colors:"}),p.size>1&&i.jsx("button",{onClick:()=>v(se=>se==="or"?"and":"or"),className:`px-2 py-0.5 text-xs rounded transition-colors ${y==="and"?"bg-bambu-green text-white":"bg-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,title:y==="or"?"Match ANY selected color":"Match ALL selected colors",children:y.toUpperCase()}),i.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:_t.map(se=>i.jsx("button",{onClick:()=>jn(se),className:`w-6 h-6 rounded-full border-2 transition-all ${p.has(se)?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:se},title:se},se))}),p.size>0&&i.jsxs("button",{onClick:kn,className:"text-xs text-bambu-gray hover:text-white flex items-center gap-1",children:[i.jsx(Ht,{className:"w-3 h-3"}),"Clear"]})]})]})}),i.jsx(tZe,{}),Ie?i.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("archives.loadingArchives")}):Vt?.length===0?i.jsx(Mt,{children:i.jsxs(Dt,{className:"text-center py-12",children:[i.jsx("p",{className:"text-bambu-gray",children:t(o?"archives.noArchivesSearch":"archives.noArchivesYet")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-2",children:"Archives are created automatically when prints complete"})]})}):q==="calendar"?i.jsx(Mt,{className:"p-6",children:i.jsx(kVe,{archives:Vt||[],onArchiveClick:se=>{l(""),Z("grid"),ye(se.id)},highlightedArchiveId:fe})}):q==="grid"?i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6",children:Vt?.map(se=>i.jsx(rZe,{archive:se,printerName:se.printer_id?yt.get(se.printer_id)||"Unknown":se.sliced_for_model?`Sliced for ${se.sliced_for_model}`:"No Printer",isSelected:ie.has(se.id),onSelect:Qe,selectionMode:Xt,projects:Ge,isHighlighted:se.id===fe,timeFormat:it,preferredSlicer:xt,currency:Nt,t,onNavigateToArchive:Xe},se.id))}):q==="list"?i.jsx(Mt,{children:i.jsxs("div",{className:"divide-y divide-bambu-dark-tertiary",children:[i.jsxs("div",{className:"grid grid-cols-12 gap-4 px-4 py-3 text-xs text-bambu-gray font-medium",children:[i.jsx("div",{className:"col-span-1"}),i.jsx("div",{className:"col-span-4",children:"Name"}),i.jsx("div",{className:"col-span-2",children:"Printer"}),i.jsx("div",{className:"col-span-2",children:"Date"}),i.jsx("div",{className:"col-span-1",children:"Size"}),i.jsx("div",{className:"col-span-2 text-right",children:"Actions"})]}),Vt?.map(se=>i.jsx(iZe,{archive:se,printerName:se.printer_id?yt.get(se.printer_id)||"Unknown":se.sliced_for_model?`Sliced for ${se.sliced_for_model}`:"No Printer",isSelected:ie.has(se.id),onSelect:Qe,selectionMode:Xt,projects:Ge,isHighlighted:se.id===fe,preferredSlicer:xt,t,onNavigateToArchive:Xe},se.id))]})}):q==="log"?i.jsxs("div",{className:"space-y-4",children:[i.jsx(Mt,{children:i.jsx(Dt,{className:"py-3",children:i.jsxs("div",{className:"flex flex-col md:flex-row gap-3 md:items-center md:flex-wrap",children:[i.jsxs("div",{className:"flex-1 relative md:min-w-[200px]",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",placeholder:t("archives.searchPlaceholder"),className:"w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",value:o,onChange:se=>{l(se.target.value),Ee(0)}})]}),i.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 text-sm",value:c||"",onChange:se=>{u(se.target.value?Number(se.target.value):null),Ee(0)},children:[i.jsx("option",{value:"",children:t("archives.log.allPrinters")}),Ce?.map(se=>i.jsx("option",{value:se.id,children:se.name},se.id))]}),i.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 text-sm",value:F||"",onChange:se=>{te(se.target.value||null),Ee(0)},children:[i.jsx("option",{value:"",children:t("archives.log.allUsers")}),Ue?.map(se=>i.jsx("option",{value:se.username,children:se.username},se.id))]}),i.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 text-sm",value:ve||"",onChange:se=>{pe(se.target.value||null),Ee(0)},children:[i.jsx("option",{value:"",children:t("archives.log.allStatuses")}),i.jsx("option",{value:"completed",children:t("archives.status.completed")}),i.jsx("option",{value:"failed",children:t("archives.status.failed")}),i.jsx("option",{value:"stopped",children:t("archives.status.stopped")}),i.jsx("option",{value:"cancelled",children:t("archives.log.cancelled")}),i.jsx("option",{value:"skipped",children:t("archives.log.skipped")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("label",{className:"text-sm text-bambu-gray",children:t("archives.log.dateFrom")}),i.jsx("input",{type:"date",className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",value:de,onChange:se=>{Ne(se.target.value),Ee(0)}})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("label",{className:"text-sm text-bambu-gray",children:t("archives.log.dateTo")}),i.jsx("input",{type:"date",className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",value:Se,onChange:se=>{Le(se.target.value),Ee(0)}})]}),i.jsx("div",{className:"ml-auto",children:i.jsxs(Oe,{variant:"danger",size:"sm",onClick:()=>Ae(!0),disabled:!r("archives:delete_all")||We.isPending,children:[i.jsx(Jt,{className:"w-4 h-4"}),t("archives.log.clearLog")]})})]})})}),i.jsx(Mt,{children:Ve?i.jsx("div",{className:"flex items-center justify-center py-12",children:i.jsx(ht,{className:"w-6 h-6 animate-spin text-bambu-green"})}):De?.items.length?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"overflow-x-auto",children:i.jsxs("table",{className:"w-full text-sm",children:[i.jsx("thead",{children:i.jsxs("tr",{className:"border-b border-bambu-dark-tertiary text-bambu-gray text-left",children:[i.jsx("th",{className:"px-4 py-3 font-medium",children:t("archives.log.date")}),i.jsx("th",{className:"px-4 py-3 font-medium",children:t("archives.log.printName")}),i.jsx("th",{className:"px-4 py-3 font-medium",children:t("archives.log.printer")}),i.jsx("th",{className:"px-4 py-3 font-medium",children:t("archives.log.user")}),i.jsx("th",{className:"px-4 py-3 font-medium",children:t("archives.log.status")}),i.jsx("th",{className:"px-4 py-3 font-medium",children:t("archives.log.duration")}),i.jsx("th",{className:"px-4 py-3 font-medium",children:t("archives.log.filament")})]})}),i.jsx("tbody",{className:"divide-y divide-bambu-dark-tertiary",children:De.items.map(se=>i.jsxs("tr",{className:"hover:bg-bambu-dark-secondary/50",children:[i.jsx("td",{className:"px-4 py-3 text-white whitespace-nowrap",children:Nf(se.started_at||se.created_at,it)}),i.jsx("td",{className:"px-4 py-3",children:i.jsxs("div",{className:"flex items-center gap-2",children:[se.thumbnail_path&&i.jsx("img",{src:be.getPrintLogThumbnail(se.id),alt:"",className:"w-8 h-8 rounded object-cover flex-shrink-0",onError:He=>{He.target.style.display="none"}}),i.jsx("span",{className:"text-white truncate max-w-[200px]",children:se.print_name||"—"})]})}),i.jsx("td",{className:"px-4 py-3 text-bambu-gray-light",children:se.printer_name||"—"}),i.jsx("td",{className:"px-4 py-3 text-bambu-gray-light",children:se.created_by_username||"—"}),i.jsx("td",{className:"px-4 py-3",children:i.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${se.status==="completed"?"bg-green-500/20 text-green-400":se.status==="failed"?"bg-red-500/20 text-red-400":se.status==="stopped"?"bg-yellow-500/20 text-yellow-400":se.status==="cancelled"?"bg-orange-500/20 text-orange-400":se.status==="skipped"?"bg-blue-500/20 text-blue-400":"bg-gray-500/20 text-gray-400"}`,children:se.status})}),i.jsx("td",{className:"px-4 py-3 text-bambu-gray-light whitespace-nowrap",children:se.duration_seconds?Rs(se.duration_seconds):"—"}),i.jsx("td",{className:"px-4 py-3",children:i.jsxs("div",{className:"flex items-center gap-1.5",children:[se.filament_color&&i.jsx("span",{className:"w-3 h-3 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:se.filament_color.startsWith("#")?se.filament_color:void 0}}),i.jsx("span",{className:"text-bambu-gray-light text-xs",children:se.filament_type||"—"})]})})]},se.id))})]})}),i.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-t border-bambu-dark-tertiary flex-wrap gap-2",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:t("archives.log.showing",{count:Math.min(qe+Be,De.total),total:De.total})}),i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx("label",{className:"text-xs text-bambu-gray",children:t("archives.log.rowsPerPage")}),i.jsxs("select",{className:"px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-xs focus:border-bambu-green focus:outline-none",value:Be,onChange:se=>{je(Number(se.target.value)),Ee(0)},children:[i.jsx("option",{value:10,children:"10"}),i.jsx("option",{value:25,children:"25"}),i.jsx("option",{value:50,children:"50"}),i.jsx("option",{value:100,children:"100"})]})]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{className:"text-sm text-bambu-gray",children:[t("archives.log.page")," ",Math.floor(qe/Be)+1," / ",Math.max(1,Math.ceil(De.total/Be))]}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>Ee(Math.max(0,qe-Be)),disabled:qe===0,children:i.jsx(Sc,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>Ee(qe+Be),disabled:qe+Be>=De.total,children:i.jsx(ha,{className:"w-4 h-4"})})]})]})]}):i.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("archives.log.noEntries")})})]}):null,D&&i.jsx(gVe,{onClose:()=>{H(!1),G([])},initialFiles:z}),ge&&i.jsx(Sn,{title:t("archives.modal.deleteArchives"),message:t("archives.modal.deleteArchivesConfirm",{count:ie.size}),confirmText:t("archives.modal.deleteCount",{count:ie.size}),variant:"danger",onConfirm:()=>{kt.mutate(Array.from(ie)),Y(!1)},onCancel:()=>Y(!1)}),oe&&i.jsx(yVe,{selectedIds:Array.from(ie),existingTags:Ot,onClose:()=>le(!1)}),xe&&i.jsx(vVe,{selectedIds:Array.from(ie),onClose:()=>Pe(!1)}),J&&ie.size>=2&&ie.size<=5&&i.jsx(QQe,{archiveIds:Array.from(ie),onClose:()=>{W(!1),X(new Set),he(!1)}}),re&&i.jsx(nZe,{onClose:()=>ue(!1)}),Te&&i.jsx(Sn,{title:t("archives.log.clearLogTitle"),message:t("archives.log.clearLogConfirm"),confirmText:t("archives.log.clearLogButton"),variant:"danger",onConfirm:()=>{We.mutate(),Ae(!1)},onCancel:()=>Ae(!1)})]})}function oZe(){for(var t=arguments.length,e=new Array(t),n=0;nr=>{e.forEach(a=>a(r))},e)}const TA=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function ty(t){const e=Object.prototype.toString.call(t);return e==="[object Window]"||e==="[object global]"}function b5(t){return"nodeType"in t}function wo(t){var e,n;return t?ty(t)?t:b5(t)&&(e=(n=t.ownerDocument)==null?void 0:n.defaultView)!=null?e:window:window}function x5(t){const{Document:e}=wo(t);return t instanceof e}function Kw(t){return ty(t)?!1:t instanceof wo(t).HTMLElement}function ooe(t){return t instanceof wo(t).SVGElement}function ny(t){return t?ty(t)?t.document:b5(t)?x5(t)?t:Kw(t)||ooe(t)?t.ownerDocument:document:document:document}const xu=TA?w.useLayoutEffect:w.useEffect;function y5(t){const e=w.useRef(t);return xu(()=>{e.current=t}),w.useCallback(function(){for(var n=arguments.length,r=new Array(n),a=0;a{t.current=setInterval(r,a)},[]),n=w.useCallback(()=>{t.current!==null&&(clearInterval(t.current),t.current=null)},[]);return[e,n]}function iw(t,e){e===void 0&&(e=[t]);const n=w.useRef(t);return xu(()=>{n.current!==t&&(n.current=t)},e),n}function Yw(t,e){const n=w.useRef();return w.useMemo(()=>{const r=t(n.current);return n.current=r,r},[...e])}function UC(t){const e=y5(t),n=w.useRef(null),r=w.useCallback(a=>{a!==n.current&&e?.(a,n.current),n.current=a},[]);return[n,r]}function mL(t){const e=w.useRef();return w.useEffect(()=>{e.current=t},[t]),e.current}let jD={};function Xw(t,e){return w.useMemo(()=>{if(e)return e;const n=jD[t]==null?0:jD[t]+1;return jD[t]=n,t+"-"+n},[t,e])}function loe(t){return function(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),a=1;a{const l=Object.entries(o);for(const[c,u]of l){const d=s[c];d!=null&&(s[c]=d+t*u)}return s},{...e})}}const Jb=loe(1),aw=loe(-1);function cZe(t){return"clientX"in t&&"clientY"in t}function v5(t){if(!t)return!1;const{KeyboardEvent:e}=wo(t.target);return e&&t instanceof e}function uZe(t){if(!t)return!1;const{TouchEvent:e}=wo(t.target);return e&&t instanceof e}function hL(t){if(uZe(t)){if(t.touches&&t.touches.length){const{clientX:e,clientY:n}=t.touches[0];return{x:e,y:n}}else if(t.changedTouches&&t.changedTouches.length){const{clientX:e,clientY:n}=t.changedTouches[0];return{x:e,y:n}}}return cZe(t)?{x:t.clientX,y:t.clientY}:null}const Mx=Object.freeze({Translate:{toString(t){if(!t)return;const{x:e,y:n}=t;return"translate3d("+(e?Math.round(e):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(t){if(!t)return;const{scaleX:e,scaleY:n}=t;return"scaleX("+e+") scaleY("+n+")"}},Transform:{toString(t){if(t)return[Mx.Translate.toString(t),Mx.Scale.toString(t)].join(" ")}},Transition:{toString(t){let{property:e,duration:n,easing:r}=t;return e+" "+n+"ms "+r}}}),uY="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function dZe(t){return t.matches(uY)?t:t.querySelector(uY)}const mZe={display:"none"};function hZe(t){let{id:e,value:n}=t;return Vr.createElement("div",{id:e,style:mZe},n)}function pZe(t){let{id:e,announcement:n,ariaLiveType:r="assertive"}=t;const a={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return Vr.createElement("div",{id:e,style:a,role:"status","aria-live":r,"aria-atomic":!0},n)}function fZe(){const[t,e]=w.useState("");return{announce:w.useCallback(r=>{r!=null&&e(r)},[]),announcement:t}}const coe=w.createContext(null);function gZe(t){const e=w.useContext(coe);w.useEffect(()=>{if(!e)throw new Error("useDndMonitor must be used within a children of ");return e(t)},[t,e])}function bZe(){const[t]=w.useState(()=>new Set),e=w.useCallback(r=>(t.add(r),()=>t.delete(r)),[t]);return[w.useCallback(r=>{let{type:a,event:s}=r;t.forEach(o=>{var l;return(l=o[a])==null?void 0:l.call(o,s)})},[t]),e]}const xZe={draggable:` To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel. @@ -8699,8 +8699,8 @@ Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${Rs(t. ${u&&ie?"sm:border-bambu-dark-tertiary border-bambu-green/40":""} ${!u&&!G?"border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80":""} ${ie?"sm:cursor-default":""} - `,onClick:ie?()=>{window.innerWidth<640&&d()}:void 0,children:[ie&&u&&i.jsx("div",{className:"sm:hidden absolute left-0 top-3 bottom-3 w-1 rounded-full bg-bambu-green"}),i.jsxs("div",{className:"flex items-start sm:items-center gap-2 sm:gap-4 p-3 sm:p-4",children:[I&&d&&i.jsx("button",{onClick:X=>{X.stopPropagation(),d()},className:`hidden sm:flex items-center justify-center w-6 h-6 rounded border transition-colors shrink-0 ${u?"bg-bambu-green border-bambu-green text-white":"border-white/30 bg-black/30 hover:border-bambu-green/50"}`,children:u&&i.jsx(Yr,{className:"w-4 h-4"})}),I?i.jsx("div",{...A,...k,className:"hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-manipulation shrink-0",children:i.jsx(bh,{className:"w-4 h-4 text-bambu-gray"})}):e!==void 0?i.jsxs("div",{className:"hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark text-bambu-gray text-sm font-medium shrink-0",children:["#",e]}):i.jsx("div",{className:"hidden sm:block w-8 shrink-0"}),i.jsx("div",{className:"w-10 h-10 sm:w-14 sm:h-14 flex-shrink-0 bg-bambu-dark rounded-lg overflow-hidden",children:t.archive_thumbnail?i.jsx("img",{src:t.plate_id!=null?be.getArchivePlateThumbnail(t.archive_id,t.plate_id):be.getArchiveThumbnail(t.archive_id),alt:"",className:"w-full h-full object-cover"}):t.library_file_thumbnail?i.jsx("img",{src:t.plate_id!=null?be.getLibraryFilePlateThumbnail(t.library_file_id,t.plate_id):be.getLibraryFileThumbnailUrl(t.library_file_id),alt:"",className:"w-full h-full object-cover"}):i.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:i.jsx(Gi,{className:"w-5 h-5 sm:w-6 sm:h-6"})})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[i.jsxs("p",{className:"text-sm sm:text-base text-white font-medium truncate",children:[t.archive_name||t.library_file_name||`File #${t.archive_id||t.library_file_id}`,(N?.is_multi_plate??!1)&&t.plate_id!==void 0&&t.plate_id!==null&&` • ${T.find(X=>X.index===t.plate_id)?.name||y("queue.plateNumber",{index:t.plate_id})}`]}),t.archive_id?i.jsx(io,{to:`/archives?highlight=${t.archive_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:y("queue.viewArchive"),children:i.jsx(Jr,{className:"w-3.5 h-3.5"})}):t.library_file_id?i.jsx(io,{to:`/library?highlight=${t.library_file_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:y("queue.viewInFileManager"),children:i.jsx(Jr,{className:"w-3.5 h-3.5"})}):null]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-xs sm:text-sm text-bambu-gray",children:[i.jsxs("span",{className:`flex items-center gap-1 sm:gap-1.5 ${t.printer_id===null&&!t.target_model?"text-orange-400":""} ${t.target_model?"text-blue-400":""}`,children:[i.jsx(Sr,{className:"w-3 h-3 sm:w-3.5 sm:h-3.5"}),i.jsx("span",{className:"truncate max-w-[120px] sm:max-w-none",children:t.target_model?`${y("queue.filter.any")} ${t.target_model}${t.target_location?` @ ${t.target_location}`:""}${t.required_filament_types?.length?` (${t.required_filament_types.join(", ")})`:""}`:t.printer_id===null?y("queue.filter.unassigned"):t.printer_name||`${y("common.printer")} #${t.printer_id}`})]}),t.print_time_seconds&&i.jsxs("span",{className:"flex items-center gap-1 sm:gap-1.5",children:[i.jsx(pd,{className:"w-3 h-3 sm:w-3.5 sm:h-3.5"}),Rs(t.print_time_seconds)]}),t.filament_used_grams&&i.jsxs("span",{className:"flex items-center gap-1 sm:gap-1.5",children:[i.jsx(tQ,{className:"w-3 h-3 sm:w-3.5 sm:h-3.5"}),Foe(t.filament_used_grams)]}),t.created_by_username&&i.jsxs("span",{className:"hidden sm:flex items-center gap-1.5",title:y("queue.addedBy",{name:t.created_by_username}),children:[i.jsx(Rd,{className:"w-3.5 h-3.5"}),t.created_by_username]}),I&&!t.manual_start&&i.jsxs("span",{className:"flex items-center gap-1.5",children:[i.jsx(er,{className:"w-3.5 h-3.5"}),t.scheduled_time?(Jn(t.scheduled_time)?.getTime()??0)-Date.now()<-6e4?y?.("queue.time.overdue")??"Overdue":x0(t.scheduled_time,c,y):y?.("queue.time.asap")??"ASAP"]})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 sm:gap-2 mt-1.5 sm:mt-2",children:[t.manual_start&&i.jsxs("span",{className:"text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-purple-500/10 text-purple-400 rounded-full border border-purple-500/20 flex items-center gap-1",children:[i.jsx(GX,{className:"w-2.5 h-2.5 sm:w-3 sm:h-3"}),y("queue.badges.staged")]}),t.require_previous_success&&i.jsx("span",{className:"text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-orange-500/10 text-orange-400 rounded-full border border-orange-500/20",children:y("queue.badges.requiresPrevious")}),t.auto_off_after&&i.jsxs("span",{className:"text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-blue-500/10 text-blue-400 rounded-full border border-blue-500/20 flex items-center gap-1",children:[i.jsx(Vd,{className:"w-2.5 h-2.5 sm:w-3 sm:h-3"}),y("queue.badges.autoPowerOff")]})]}),G&&v&&i.jsxs("div",{className:"mt-2 sm:mt-3",children:[i.jsxs("div",{className:"flex items-center justify-between text-xs sm:text-sm",children:[i.jsx("div",{className:"flex-1 bg-bambu-dark-tertiary rounded-full h-1.5 sm:h-2 mr-3",children:i.jsx("div",{className:"bg-bambu-green h-1.5 sm:h-2 rounded-full transition-all",style:{width:`${v.progress||0}%`}})}),i.jsxs("span",{className:"text-white",children:[Math.round(v.progress||0),"%"]})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-3 mt-1.5 sm:mt-2 text-[10px] sm:text-xs text-bambu-gray",children:[v.remaining_time!=null&&v.remaining_time>0&&i.jsxs(i.Fragment,{children:[i.jsxs("span",{className:"flex items-center gap-1",children:[i.jsx(er,{className:"w-3 h-3"}),Rs(v.remaining_time*60)]}),i.jsxs("span",{className:"text-bambu-green font-medium",title:y("printers.estimatedCompletion"),children:["ETA ",KL(v.remaining_time,c,y)]})]}),v.layer_num!=null&&v.total_layers!=null&&v.total_layers>0&&i.jsxs("span",{className:"flex items-center gap-1",children:[i.jsx(Gi,{className:"w-3 h-3"}),v.layer_num,"/",v.total_layers]})]})]}),t.waiting_reason&&t.status==="pending"&&i.jsxs("p",{className:"text-[10px] sm:text-xs text-purple-400 mt-1.5 sm:mt-2 flex items-start gap-1",children:[i.jsx(Li,{className:"w-3 h-3 mt-0.5 flex-shrink-0"}),i.jsx("span",{children:t.waiting_reason})]}),t.error_message&&i.jsxs("p",{className:"text-[10px] sm:text-xs text-red-400 mt-1.5 sm:mt-2 flex items-center gap-1",children:[i.jsx(Li,{className:"w-3 h-3"}),t.error_message]})]}),i.jsxs("div",{className:"flex flex-col sm:flex-row items-end sm:items-center gap-2 sm:gap-1 shrink-0",onClick:X=>X.stopPropagation(),children:[i.jsx(HJe,{status:t.status,waitingReason:t.waiting_reason,printerState:f,t:y}),i.jsxs("div",{className:"flex items-center gap-0.5 sm:gap-1",children:[G&&i.jsx(Oe,{variant:"ghost",size:"sm",onClick:s,disabled:!m("printers:control"),title:m("printers:control")?y("queue.actions.stopPrint"):y("queue.permissions.noStopPrint"),className:"text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2",children:i.jsx(Jhe,{className:"w-4 h-4"})}),I&&i.jsxs(i.Fragment,{children:[t.manual_start&&i.jsx(Oe,{variant:"ghost",size:"sm",onClick:l,disabled:!m("printers:control"),title:m("printers:control")?y("queue.actions.startPrint"):y("queue.permissions.noStartPrint"),className:"text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10 p-1.5 sm:p-2",children:i.jsx(go,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:n,disabled:!p("queue","update",t.created_by_id),title:p("queue","update",t.created_by_id)?y("common.edit"):y("queue.permissions.noEdit"),className:"p-1.5 sm:p-2",children:i.jsx(Yi,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:r,disabled:!p("queue","delete",t.created_by_id),title:p("queue","delete",t.created_by_id)?y("common.cancel"):y("queue.permissions.noCancel"),className:"text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2",children:i.jsx(Ht,{className:"w-4 h-4"})})]}),ee&&i.jsxs(i.Fragment,{children:[i.jsx(Oe,{variant:"ghost",size:"sm",onClick:o,disabled:!m("queue:create"),title:m("queue:create")?y("queue.actions.requeue"):y("queue.permissions.noRequeue"),className:"text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5 sm:p-2",children:i.jsx(wr,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:a,disabled:!p("queue","delete",t.created_by_id),title:p("queue","delete",t.created_by_id)?y("common.remove"):y("queue.permissions.noRemove"),className:"p-1.5 sm:p-2",children:i.jsx(Jt,{className:"w-4 h-4"})})]})]})]})]})]})}function qJe(){const{t}=Ft(),e=an(),{showToast:n}=fn(),{hasPermission:r,hasAnyPermission:a,canModify:s}=_r(),[o,l]=w.useState(null),[c,u]=w.useState(""),[d,m]=w.useState(""),[p,f]=w.useState(!1),[y,v]=w.useState(null),[x,g]=w.useState(null),[_,N]=w.useState(null),[T,C]=w.useState([]),[A,k]=w.useState(!1),[R,P]=w.useState(()=>localStorage.getItem("queue.historySortBy")||"date"),[D,H]=w.useState(()=>{const L=localStorage.getItem("queue.historySortAsc");return L!==null?L==="true":!1}),[z,G]=w.useState(()=>localStorage.getItem("queue.pendingSortBy")||"position"),[I,ee]=w.useState(()=>{const L=localStorage.getItem("queue.pendingSortAsc");return L!==null?L==="true":!0});w.useEffect(()=>{localStorage.setItem("queue.historySortBy",R)},[R]),w.useEffect(()=>{localStorage.setItem("queue.historySortAsc",String(D))},[D]),w.useEffect(()=>{localStorage.setItem("queue.pendingSortBy",z)},[z]),w.useEffect(()=>{localStorage.setItem("queue.pendingSortAsc",String(I))},[I]);const ie=uoe(HC(MA,{activationConstraint:{distance:8}}),HC(PA,{coordinateGetter:Doe})),{data:X}=et({queryKey:["settings"],queryFn:be.getSettings}),me=X?.time_format||"system",{data:he,isLoading:ge}=et({queryKey:["queue",o,c],queryFn:()=>be.getQueue(o||void 0,c||void 0),refetchInterval:5e3}),{data:Y}=et({queryKey:["printers"],queryFn:()=>be.getPrinters()}),oe=pt({mutationFn:L=>be.cancelQueueItem(L),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.cancelled"))},onError:()=>n(t("queue.toast.cancelFailed"),"error")}),le=pt({mutationFn:L=>be.removeFromQueue(L),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.removed"))},onError:()=>n(t("queue.toast.removeFailed"),"error")}),xe=pt({mutationFn:L=>be.stopQueueItem(L),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.stopped"))},onError:()=>n(t("queue.toast.stopFailed"),"error")}),Pe=pt({mutationFn:L=>be.startQueueItem(L),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.released"))},onError:()=>n(t("queue.toast.startFailed"),"error")}),q=pt({mutationFn:L=>be.reorderQueue(L),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]})},onError:()=>n(t("queue.toast.reorderFailed"),"error")}),Z=pt({mutationFn:async()=>{const L=he?.filter(F=>["completed","failed","skipped","cancelled"].includes(F.status))||[];for(const F of L)await be.removeFromQueue(F.id);return L.length},onSuccess:L=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.historyCleared",{count:L}))},onError:()=>n(t("queue.toast.clearHistoryFailed"),"error")}),j=pt({mutationFn:L=>be.bulkUpdateQueue(L),onSuccess:L=>{e.invalidateQueries({queryKey:["queue"]}),C([]),k(!1),n(L.message)},onError:()=>n(t("queue.toast.updateFailed"),"error")}),E=pt({mutationFn:async L=>{for(const F of L)await be.cancelQueueItem(F);return L.length},onSuccess:L=>{e.invalidateQueries({queryKey:["queue"]}),C([]),n(t("queue.toast.bulkCancelled",{count:L}))},onError:()=>n(t("queue.toast.bulkCancelFailed"),"error")}),U=L=>{C(F=>F.includes(L)?F.filter(te=>te!==L):[...F,L])},K=w.useMemo(()=>{const L=new Set;return Y?.forEach(F=>{F.location&&L.add(F.location)}),he?.forEach(F=>{F.target_location&&L.add(F.target_location)}),Array.from(L).sort()},[Y,he]),$=w.useCallback(L=>d?L.target_location?L.target_location===d:L.printer_id?Y?.find(te=>te.id===L.printer_id)?.location===d:!1:!0,[d,Y]),ne=w.useMemo(()=>{let L=he?.filter(te=>te.status==="pending")||[];d&&(L=L.filter($));const F=te=>{if(!te.scheduled_time)return 0;const ve=Jn(te.scheduled_time)?.getTime()??0,pe=Date.now()+4320*60*60*1e3;return ve>pe?0:ve};return[...L].sort((te,ve)=>{let pe;if(z==="name"){const de=te.archive_name||te.library_file_name||"",Ne=ve.archive_name||ve.library_file_name||"";pe=de.localeCompare(Ne)}else z==="printer"?pe=(te.printer_name||"").localeCompare(ve.printer_name||""):z==="time"?pe=F(te)-F(ve):pe=te.position-ve.position;return I?pe:-pe})},[he,z,I,$,d]),O=()=>{const L=ne.map(F=>F.id);T.length===L.length?C([]):C(L)},V=w.useMemo(()=>{let L=he?.filter(F=>F.status==="printing")||[];return d&&(L=L.filter($)),L},[he,d,$]),J=w.useMemo(()=>{const L=new Set;return V.forEach(F=>{F.printer_id&&L.add(F.printer_id)}),Array.from(L)},[V]),W=Gf({queries:J.map(L=>({queryKey:["printerStatus",L],queryFn:()=>be.getPrinterStatus(L),refetchInterval:5e3}))}),re=w.useMemo(()=>{const L={};return J.forEach((F,te)=>{const ve=W[te];ve?.data?.state&&(L[F]=ve.data.state)}),L},[J,W]),ue=w.useMemo(()=>{let L=he?.filter(F=>["completed","failed","skipped","cancelled"].includes(F.status))||[];return d&&(L=L.filter($)),[...L].sort((F,te)=>{let ve;if(R==="name"){const pe=F.archive_name||F.library_file_name||"",de=te.archive_name||te.library_file_name||"";ve=pe.localeCompare(de)}else R==="printer"?ve=(F.printer_name||"").localeCompare(te.printer_name||""):ve=(Jn(te.completed_at||te.created_at)?.getTime()??0)-(Jn(F.completed_at||F.created_at)?.getTime()??0);return D?-ve:ve})},[he,R,D,$,d]),fe=w.useMemo(()=>ne.reduce((L,F)=>L+(F.print_time_seconds||0),0),[ne]),ye=w.useMemo(()=>ne.reduce((L,F)=>L+(F.filament_used_grams||0),0),[ne]),ae=L=>{const{active:F,over:te}=L;if(!te||F.id===te.id)return;const ve=ne.findIndex(de=>de.id===F.id),pe=ne.findIndex(de=>de.id===te.id);if(ve!==-1&&pe!==-1){const Ne=DA(ne,ve,pe).map((Se,Le)=>({id:Se.id,position:Le+1}));q.mutate(Ne)}};return i.jsxs("div",{className:"p-4 md:p-8",children:[i.jsx("div",{className:"flex items-center justify-between mb-8",children:i.jsxs("div",{children:[i.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[i.jsx(WX,{className:"w-7 h-7 text-bambu-green"}),t("queue.title")]}),i.jsx("p",{className:"text-bambu-gray mt-1",children:t("queue.subtitle")})]})}),i.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-2 sm:gap-3 lg:gap-4 mb-8",children:[i.jsx(Mt,{className:"bg-gradient-to-br from-blue-500/10 to-transparent border-blue-500/20",children:i.jsx(Dt,{className:"p-3 sm:p-4",children:i.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[i.jsx("div",{className:"w-8 h-8 sm:w-10 sm:h-10 rounded-lg bg-blue-500/20 flex items-center justify-center shrink-0",children:i.jsx(go,{className:"w-4 h-4 sm:w-5 sm:h-5 text-blue-400"})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-xl sm:text-2xl font-bold text-white truncate",children:V.length}),i.jsx("p",{className:"text-xs sm:text-sm text-bambu-gray truncate",children:t("queue.summary.printing")})]})]})})}),i.jsx(Mt,{className:"bg-gradient-to-br from-yellow-500/10 to-transparent border-yellow-500/20",children:i.jsx(Dt,{className:"p-3 sm:p-4",children:i.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[i.jsx("div",{className:"w-8 h-8 sm:w-10 sm:h-10 rounded-lg bg-yellow-500/20 flex items-center justify-center shrink-0",children:i.jsx(er,{className:"w-4 h-4 sm:w-5 sm:h-5 text-yellow-400"})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-xl sm:text-2xl font-bold text-white truncate",children:ne.length}),i.jsx("p",{className:"text-xs sm:text-sm text-bambu-gray truncate",children:t("queue.summary.queued")})]})]})})}),i.jsx(Mt,{className:"bg-gradient-to-br from-bambu-green/10 to-transparent border-bambu-green/20",children:i.jsx(Dt,{className:"p-3 sm:p-4",children:i.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[i.jsx("div",{className:"w-8 h-8 sm:w-10 sm:h-10 rounded-lg bg-bambu-green/20 flex items-center justify-center shrink-0",children:i.jsx(pd,{className:"w-4 h-4 sm:w-5 sm:h-5 text-bambu-green"})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-xl sm:text-2xl font-bold text-white truncate",children:Rs(fe)}),i.jsx("p",{className:"text-xs sm:text-sm text-bambu-gray truncate",children:t("queue.summary.totalTime")})]})]})})}),i.jsx(Mt,{className:"bg-gradient-to-br from-purple-500/10 to-transparent border-purple-500/20",children:i.jsx(Dt,{className:"p-3 sm:p-4",children:i.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[i.jsx("div",{className:"w-8 h-8 sm:w-10 sm:h-10 rounded-lg bg-purple-500/20 flex items-center justify-center shrink-0",children:i.jsx(tQ,{className:"w-4 h-4 sm:w-5 sm:h-5 text-purple-500"})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-xl sm:text-2xl font-bold text-white truncate",children:Foe(ye)}),i.jsx("p",{className:"text-xs sm:text-sm text-bambu-gray truncate",children:t("queue.summary.totalWeight")})]})]})})}),i.jsx(Mt,{className:"col-span-2 sm:col-span-1 bg-gradient-to-br from-gray-500/10 to-transparent border-gray-500/20",children:i.jsx(Dt,{className:"p-3 sm:p-4",children:i.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[i.jsx("div",{className:"w-8 h-8 sm:w-10 sm:h-10 rounded-lg bg-gray-500/20 flex items-center justify-center shrink-0",children:i.jsx(fr,{className:"w-4 h-4 sm:w-5 sm:h-5 text-gray-400"})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-xl sm:text-2xl font-bold text-white truncate",children:ue.length}),i.jsx("p",{className:"text-xs sm:text-sm text-bambu-gray truncate",children:t("queue.summary.history")})]})]})})})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-4 mb-6",children:[i.jsxs("select",{className:"px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none",value:o===-1?"unassigned":o||"",onChange:L=>{const F=L.target.value;l(F==="unassigned"?-1:F===""?null:Number(F))},children:[i.jsx("option",{value:"",children:t("queue.filter.allPrinters")}),i.jsx("option",{value:"unassigned",children:t("queue.filter.unassigned")}),Y?.map(L=>i.jsx("option",{value:L.id,children:L.name},L.id))]}),i.jsxs("select",{className:"px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none",value:c,onChange:L=>u(L.target.value),children:[i.jsx("option",{value:"",children:t("queue.filter.allStatus")}),i.jsx("option",{value:"pending",children:t("queue.status.pending")}),i.jsx("option",{value:"printing",children:t("queue.status.printing")}),i.jsx("option",{value:"completed",children:t("queue.status.completed")}),i.jsx("option",{value:"failed",children:t("queue.status.failed")}),i.jsx("option",{value:"skipped",children:t("queue.status.skipped")}),i.jsx("option",{value:"cancelled",children:t("queue.status.cancelled")})]}),K.length>0&&i.jsxs("select",{className:"px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none",value:d,onChange:L=>m(L.target.value),children:[i.jsx("option",{value:"",children:t("queue.filter.allLocations")}),K.map(L=>i.jsx("option",{value:L,children:L},L))]}),i.jsx("div",{className:"hidden sm:block flex-1"}),ue.length>0&&i.jsxs(Oe,{className:"w-full sm:w-auto",variant:"secondary",size:"sm",onClick:()=>f(!0),disabled:!r("queue:delete_all"),title:r("queue:delete_all")?void 0:t("queue.permissions.noClearHistory"),children:[i.jsx(Jt,{className:"w-4 h-4"}),t("queue.clearHistory")]})]}),ge?i.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("common.loading")}):he?.length===0?i.jsxs(Mt,{className:"p-12 text-center border-dashed",children:[i.jsx(Wr,{className:"w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50"}),i.jsx("h3",{className:"text-xl font-medium text-white mb-2",children:t("queue.empty.title")}),i.jsx("p",{className:"text-bambu-gray max-w-md mx-auto",children:t("queue.empty.description")})]}):i.jsxs("div",{className:"space-y-6 sm:space-y-8",children:[V.length>0&&i.jsxs("div",{children:[i.jsxs("h2",{className:"text-base sm:text-lg font-semibold text-white mb-3 sm:mb-4 flex items-center gap-2",children:[i.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-400 animate-pulse"}),t("queue.sections.currentlyPrinting")]}),i.jsx("div",{className:"space-y-2 sm:space-y-3",children:V.map(L=>i.jsx(LD,{item:L,onEdit:()=>{},onCancel:()=>{},onRemove:()=>{},onStop:()=>N({type:"stop",item:L}),onRequeue:()=>{},onStart:()=>{},timeFormat:me,hasPermission:r,canModify:s,printerState:L.printer_id?re[L.printer_id]:null,t},L.id))})]}),ne.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4",children:[i.jsxs("h2",{className:"text-base sm:text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(er,{className:"w-4 h-4 sm:w-5 sm:h-5 text-yellow-400"}),t("queue.sections.queued"),i.jsxs("span",{className:"text-xs sm:text-sm font-normal text-bambu-gray",children:["(",t("queue.itemCount",{count:ne.length}),")"]}),i.jsx("span",{className:"hidden sm:inline text-xs text-bambu-gray ml-2",title:t("queue.reorderHint"),children:t("queue.dragToReorder")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("select",{className:"px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:z,onChange:L=>G(L.target.value),children:[i.jsx("option",{value:"position",children:t("queue.sort.byPosition")}),i.jsx("option",{value:"name",children:t("queue.sort.byName")}),i.jsx("option",{value:"printer",children:t("queue.sort.byPrinter")}),i.jsx("option",{value:"time",children:t("queue.sort.bySchedule")})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>ee(!I),title:t(I?"common.ascending":"common.descending"),className:"px-2",children:I?i.jsx(yf,{className:"w-4 h-4"}):i.jsx(tx,{className:"w-4 h-4"})})]})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-3 mb-3 sm:mb-4 p-2 sm:p-3 bg-bambu-dark rounded-lg",children:[i.jsxs(Oe,{variant:"ghost",size:"sm",onClick:O,className:"flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm",children:[T.length===ne.length&&ne.length>0?i.jsx(xo,{className:"w-4 h-4 text-bambu-green"}):i.jsx(zl,{className:"w-4 h-4"}),T.length===ne.length&&ne.length>0?t("queue.bulkEdit.deselectAll"):t("queue.bulkEdit.selectAll")]}),T.length>0&&i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"text-xs sm:text-sm text-bambu-gray",children:t("queue.bulkEdit.selected",{count:T.length})}),i.jsx("div",{className:"hidden sm:block h-4 w-px bg-bambu-dark-tertiary"}),i.jsxs(Oe,{variant:"ghost",size:"sm",onClick:()=>k(!0),className:"flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-bambu-green hover:text-bambu-green-light",disabled:!a("queue:update_own","queue:update_all"),title:a("queue:update_own","queue:update_all")?t("queue.bulkEdit.editSelected"):t("queue.permissions.noEditItems"),children:[i.jsx(Yi,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("queue.bulkEdit.editSelected")})]}),i.jsxs(Oe,{variant:"ghost",size:"sm",onClick:()=>E.mutate(T),className:"flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-red-400 hover:text-red-300",disabled:E.isPending||!a("queue:delete_own","queue:delete_all"),title:a("queue:delete_own","queue:delete_all")?t("queue.bulkEdit.cancelSelected"):t("queue.permissions.noCancelItems"),children:[i.jsx(Ht,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("queue.bulkEdit.cancelSelected")})]})]})]}),i.jsx(Toe,{sensors:ie,collisionDetection:poe,onDragEnd:ae,children:i.jsx(Moe,{items:ne.map(L=>L.id),strategy:EJe,children:i.jsx("div",{className:"space-y-2 sm:space-y-3",children:ne.map((L,F)=>i.jsx(LD,{item:L,position:F+1,onEdit:()=>v(L),onCancel:()=>N({type:"cancel",item:L}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>Pe.mutate(L.id),timeFormat:me,isSelected:T.includes(L.id),onToggleSelect:()=>U(L.id),hasPermission:r,canModify:s,t},L.id))})})})]}),ue.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4",children:[i.jsxs("h2",{className:"text-base sm:text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(fr,{className:"w-4 h-4 sm:w-5 sm:h-5 text-bambu-gray"}),t("queue.sections.history"),i.jsxs("span",{className:"text-xs sm:text-sm font-normal text-bambu-gray",children:["(",t("queue.itemCount",{count:ue.length}),")"]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("select",{className:"px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:R,onChange:L=>P(L.target.value),children:[i.jsx("option",{value:"date",children:t("queue.sort.byDate")}),i.jsx("option",{value:"name",children:t("queue.sort.byName")}),i.jsx("option",{value:"printer",children:t("queue.sort.byPrinter")})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>H(!D),title:t(D?"queue.sort.ascendingOldest":"queue.sort.descendingNewest"),className:"px-2",children:D?i.jsx(yf,{className:"w-4 h-4"}):i.jsx(tx,{className:"w-4 h-4"})})]})]}),i.jsx("div",{className:"space-y-2 sm:space-y-3",children:ue.slice(0,20).map((L,F)=>i.jsx(LD,{item:L,position:F+1,onEdit:()=>{},onCancel:()=>{},onRemove:()=>N({type:"remove",item:L}),onStop:()=>{},onRequeue:()=>g(L),onStart:()=>{},timeFormat:me,hasPermission:r,canModify:s,t},L.id))})]})]}),y&&i.jsx(uu,{mode:"edit-queue-item",archiveId:y.archive_id??void 0,libraryFileId:y.library_file_id??void 0,archiveName:y.archive_name||y.library_file_name||`File #${y.archive_id||y.library_file_id}`,queueItem:y,onClose:()=>v(null)}),x&&i.jsx(uu,{mode:"add-to-queue",archiveId:x.archive_id??void 0,libraryFileId:x.library_file_id??void 0,archiveName:x.archive_name||x.library_file_name||`File #${x.archive_id||x.library_file_id}`,onClose:()=>g(null)}),_&&i.jsx(Sn,{title:_.type==="cancel"?t("queue.confirm.cancelTitle"):_.type==="stop"?t("queue.confirm.stopTitle"):t("queue.confirm.removeTitle"),message:_.type==="cancel"?t("queue.confirm.cancelMessage",{name:_.item.archive_name||_.item.library_file_name||t("queue.confirm.thisPrint")}):_.type==="stop"?t("queue.confirm.stopMessage",{name:_.item.archive_name||_.item.library_file_name||t("queue.confirm.thisPrint")}):t("queue.confirm.removeMessage",{name:_.item.archive_name||_.item.library_file_name||t("queue.confirm.thisItem")}),confirmText:_.type==="cancel"?t("queue.confirm.cancelButton"):_.type==="stop"?t("queue.confirm.stopButton"):t("common.remove"),variant:"danger",onConfirm:()=>{_.type==="cancel"?oe.mutate(_.item.id):_.type==="stop"?xe.mutate(_.item.id):le.mutate(_.item.id),N(null)},onCancel:()=>N(null)}),p&&i.jsx(Sn,{title:t("queue.confirm.clearHistoryTitle"),message:t("queue.confirm.clearHistoryMessage",{count:ue.length}),confirmText:t("queue.clearHistory"),variant:"danger",onConfirm:()=>{Z.mutate(),f(!1)},onCancel:()=>f(!1)}),A&&i.jsx($Je,{selectedCount:T.length,printers:Y?.map(L=>({id:L.id,name:L.name}))||[],onSave:L=>{Object.keys(L).length>0&&j.mutate({item_ids:T,...L})},onClose:()=>k(!1),isSaving:j.isPending,canControlPrinter:r("printers:control"),t})]})}function VJe({printDates:t,months:e=3}){const n=w.useRef(null),[r,a]=w.useState(0);w.useEffect(()=>{const _=n.current;if(!_)return;const N=new ResizeObserver(T=>{const C=T[0]?.contentRect.width||0;a(C)});return N.observe(_),()=>N.disconnect()},[]);const{weeks:s,monthLabels:o,printCounts:l}=w.useMemo(()=>{const _={};t.forEach(H=>{const z=H.split("T")[0];_[z]=(_[z]||0)+1});const N=new Date,T=new Date(N);T.setMonth(T.getMonth()-e),T.setDate(T.getDate()-T.getDay());const C=[],A=[];let k=[],R=-1;const P=new Date(T);let D=0;for(;P<=N;)P.getDay()===0&&k.length>0&&(C.push(k),k=[],D++),P.getMonth()!==R&&(A.push({month:P.toLocaleDateString("en-US",{month:"short"}),weekIndex:D}),R=P.getMonth()),k.push(new Date(P)),P.setDate(P.getDate()+1);return k.length>0&&C.push(k),{weeks:C,monthLabels:A,printCounts:_}},[t,e]),c=Math.max(1,...Object.values(l)),u=_=>{if(_===0)return"bg-bambu-dark";const N=_/c;return N<=.25?"bg-bambu-green/30":N<=.5?"bg-bambu-green/50":N<=.75?"bg-bambu-green/75":"bg-bambu-green"},d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],m=s.length,p=32,f=2,y=r-p-16,v=m>0?Math.floor((y-(m-1)*f)/m):12,x=Math.max(8,Math.min(20,v)),g=x<=10?10:12;return i.jsx("div",{ref:n,className:"w-full flex justify-center",children:r>0&&i.jsxs("div",{children:[i.jsx("div",{className:"flex mb-1",style:{marginLeft:p+4},children:o.map(({month:_,weekIndex:N},T)=>i.jsx("div",{className:"text-bambu-gray",style:{fontSize:g,marginLeft:T===0?0:`${(N-(o[T-1]?.weekIndex||0))*(x+f)-24}px`},children:_},T))}),i.jsxs("div",{className:"flex",style:{gap:f},children:[i.jsx("div",{className:"flex flex-col",style:{gap:f,marginRight:4,width:p},children:d.map((_,N)=>i.jsx("div",{className:"text-bambu-gray flex items-center",style:{width:p,height:x,fontSize:g,visibility:N%2===1?"visible":"hidden"},children:_},_))}),s.map((_,N)=>i.jsx("div",{className:"flex flex-col",style:{gap:f},children:[0,1,2,3,4,5,6].map(T=>{const C=_.find(P=>P.getDay()===T);if(!C)return i.jsx("div",{style:{width:x,height:x}},T);const A=C.toISOString().split("T")[0],k=l[A]||0,R=A===new Date().toISOString().split("T")[0];return i.jsx("div",{className:`rounded-sm ${u(k)} ${R?"ring-1 ring-white":""}`,style:{width:x,height:x},title:`${C.toLocaleDateString()}: ${k} print${k!==1?"s":""}`},T)})},N))]}),i.jsxs("div",{className:"flex items-center gap-2 mt-3 text-bambu-gray",style:{fontSize:g},children:[i.jsx("span",{children:"Less"}),i.jsxs("div",{className:"flex",style:{gap:f},children:[i.jsx("div",{className:"rounded-sm bg-bambu-dark",style:{width:x,height:x}}),i.jsx("div",{className:"rounded-sm bg-bambu-green/30",style:{width:x,height:x}}),i.jsx("div",{className:"rounded-sm bg-bambu-green/50",style:{width:x,height:x}}),i.jsx("div",{className:"rounded-sm bg-bambu-green/75",style:{width:x,height:x}}),i.jsx("div",{className:"rounded-sm bg-bambu-green",style:{width:x,height:x}})]}),i.jsx("span",{children:"More"})]})]})})}const _Y=["weight","prints","time"];function VC({value:t,onChange:e,exclude:n}){const{t:r}=Ft(),a={weight:r("stats.filamentByWeight"),prints:r("stats.filamentByPrints"),time:r("stats.filamentByTime")},s=n?_Y.filter(o=>!n.includes(o)):_Y;return i.jsx("div",{className:"flex gap-0.5 bg-bambu-dark rounded-lg p-0.5",children:s.map(o=>i.jsx("button",{onClick:()=>e(o),className:`px-2 py-0.5 text-xs rounded-md transition-colors ${t===o?"bg-bambu-green text-white":"text-bambu-gray hover:text-white"}`,children:a[o]},o))})}function th(t){if(t>=1e6){const e=t/1e6;return`${e%1===0?e.toFixed(0):e.toFixed(1)}t`}if(t>=1e3){const e=t/1e3;return`${e%1===0?e.toFixed(0):e.toFixed(1)}kg`}return`${Math.round(t)}g`}const $1=["#00ae42","#3b82f6","#f59e0b","#ef4444","#8b5cf6","#ec4899","#14b8a6","#f97316"],GJe=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],NY=["12am","1am","2am","3am","4am","5am","6am","7am","8am","9am","10am","11am","12pm","1pm","2pm","3pm","4pm","5pm","6pm","7pm","8pm","9pm","10pm","11pm"];function WJe({archives:t,currency:e="$",dateFrom:n,dateTo:r}){const{t:a}=Ft(),[s,o]=w.useState("weight"),[l,c]=w.useState("weight"),u=w.useMemo(()=>{const R=new Map;return t.forEach(P=>{const D=Jn(P.completed_at||P.created_at)||new Date,H=`${D.getFullYear()}-${String(D.getMonth()+1).padStart(2,"0")}-${String(D.getDate()).padStart(2,"0")}`,z=R.get(H)||{date:H,filament:0,cost:0,prints:0};z.filament+=P.filament_used_grams||0,z.cost+=P.cost||0,z.prints+=P.quantity||1,R.set(H,z)}),Array.from(R.values()).sort((P,D)=>P.date.localeCompare(D.date)).map(P=>({...P,dateLabel:new Date(P.date).toLocaleDateString("en-US",{month:"short",day:"numeric"})}))},[t]),d=w.useMemo(()=>{if(n&&r)return Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1;if(n)return Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1;if(t.length<2)return 0;const R=t.map(P=>new Date(P.completed_at||P.created_at).getTime());return(Math.max(...R)-Math.min(...R))/864e5},[t,n,r]),m=w.useMemo(()=>{if(d>7)return[];const R=new Map,P=d>1;return t.forEach(D=>{const H=Jn(D.completed_at||D.created_at)||new Date,z=H.getHours(),G=`${H.getFullYear()}-${String(H.getMonth()+1).padStart(2,"0")}-${String(H.getDate()).padStart(2,"0")}T${String(z).padStart(2,"0")}`,I=R.get(G)||{date:G,filament:0,cost:0,prints:0};I.filament+=D.filament_used_grams||0,I.cost+=D.cost||0,I.prints+=D.quantity||1,R.set(G,I)}),Array.from(R.values()).sort((D,H)=>D.date.localeCompare(H.date)).map(D=>{const[H,z]=D.date.split("T"),G=new Date(H),I=parseInt(z,10),ee=P?`${GJe[G.getDay()]} ${NY[I]}`:NY[I];return{...D,dateLabel:ee}})},[t,d]),p=w.useMemo(()=>{if(u.length<=60)return u;const R=new Map;return u.forEach(P=>{const D=new Date(P.date),H=new Date(D);H.setDate(D.getDate()-D.getDay());const z=`${H.getFullYear()}-${String(H.getMonth()+1).padStart(2,"0")}-${String(H.getDate()).padStart(2,"0")}`,G=R.get(z)||{week:z,filament:0,cost:0,prints:0};G.filament+=P.filament,G.cost+=P.cost,G.prints+=P.prints,R.set(z,G)}),Array.from(R.values()).sort((P,D)=>P.week.localeCompare(D.week)).map(P=>({date:P.week,dateLabel:`Week of ${new Date(P.week).toLocaleDateString("en-US",{month:"short",day:"numeric"})}`,...P}))},[u]),f=w.useMemo(()=>{const R=new Map;return t.forEach(P=>{const H=(P.filament_type||"Unknown").split(", ");H.forEach(z=>{const G=(P.filament_used_grams||0)/H.length;R.set(z,(R.get(z)||0)+G)})}),Array.from(R.entries()).map(([P,D])=>({name:P,value:Math.round(D)})).sort((P,D)=>D.value-P.value)},[t]),y=w.useMemo(()=>{const R=new Map;return t.forEach(P=>{(P.filament_type||"Unknown").split(", ").forEach(z=>{R.set(z,(R.get(z)||0)+1)})}),Array.from(R.entries()).map(([P,D])=>({name:P,value:D})).sort((P,D)=>D.value-P.value)},[t]),v=w.useMemo(()=>{const R=new Map;return t.forEach(P=>{const H=(P.filament_type||"Unknown").split(", "),z=(P.actual_time_seconds||P.print_time_seconds||0)/H.length;H.forEach(G=>{R.set(G,(R.get(G)||0)+z)})}),Array.from(R.entries()).map(([P,D])=>({name:P,value:Math.round(D/3600*10)/10})).sort((P,D)=>D.value-P.value)},[t]),x=w.useMemo(()=>{const R=new Map;return t.forEach(P=>{if(P.status!=="completed"&&P.status!=="failed")return;(P.filament_type||"Unknown").split(", ").forEach(H=>{const z=R.get(H)||{completed:0,failed:0};P.status==="completed"?z.completed++:z.failed++,R.set(H,z)})}),Array.from(R.entries()).filter(([,P])=>P.completed+P.failed>=2).map(([P,D])=>{const H=D.completed+D.failed,z=Math.round(D.completed/H*100);return{name:P,rate:z,total:H}}).sort((P,D)=>D.rate-P.rate)},[t]),g=w.useMemo(()=>{const R=new Map;return t.forEach(P=>{if(!P.filament_color)return;const D=P.filament_color.split(",").map(z=>z.trim()),H=(P.filament_used_grams||0)/D.length;D.forEach(z=>{const G=R.get(z)||{count:0,weight:0};G.count++,G.weight+=H,R.set(z,G)})}),Array.from(R.entries()).map(([P,D])=>({hex:P,value:l==="prints"?D.count:Math.round(D.weight)})).sort((P,D)=>D.value-P.value)},[t,l]),_=s==="weight"?f:s==="prints"?y:v,N=d<=7&&m.length>0?m:p,T=t.reduce((R,P)=>R+(P.filament_used_grams||0),0),C=t.reduce((R,P)=>R+(P.cost||0),0),A=t.reduce((R,P)=>R+(P.quantity||1),0),k=new Set(t.map(R=>R.printer_id).filter(Boolean)).size;return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"grid grid-cols-3 gap-2 max-[640px]:grid-cols-1",children:[i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx("p",{className:"text-sm text-bambu-gray leading-none",children:a("stats.periodFilament")}),i.jsx("p",{className:"text-2xl font-bold text-white leading-none",children:th(T)})]}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[k," ",a("nav.printers").toLowerCase()]})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx("p",{className:"text-sm text-bambu-gray leading-none",children:a("stats.periodCost")}),i.jsxs("p",{className:"text-2xl font-bold text-white leading-none",children:[e,C.toFixed(2)]})]}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[A," ",a("common.prints")]})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx("p",{className:"text-sm text-bambu-gray leading-none",children:a("stats.avgPerPrint")}),i.jsxs("p",{className:"text-2xl font-bold text-white leading-none",children:[A>0?(T/A).toFixed(0):0,"g"]})]}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[e,A>0?(C/A).toFixed(2):"0.00"," avg"]})]})]}),N.length>0?i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:a("stats.usageOverTime")}),i.jsx(oh,{width:"100%",height:250,children:i.jsxs(Cqe,{data:N,children:[i.jsx("defs",{children:i.jsxs("linearGradient",{id:"colorFilament",x1:"0",y1:"0",x2:"0",y2:"1",children:[i.jsx("stop",{offset:"5%",stopColor:"#00ae42",stopOpacity:.3}),i.jsx("stop",{offset:"95%",stopColor:"#00ae42",stopOpacity:0})]})}),i.jsx(Kp,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),i.jsx(Yp,{dataKey:"dateLabel",stroke:"#9ca3af",tick:{fontSize:12},interval:"preserveStartEnd"}),i.jsx(Xp,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:R=>`${R}g`}),i.jsx(lh,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},labelStyle:{color:"#fff"},formatter:R=>[`${Number(R??0).toFixed(0)}g`,"Filament"]}),i.jsx(Are,{type:"monotone",dataKey:"filament",stroke:"#00ae42",strokeWidth:2,fillOpacity:1,fill:"url(#colorFilament)"})]})})]}):i.jsx("div",{className:"bg-bambu-dark rounded-lg p-8 text-center text-bambu-gray",children:a("stats.noPrintDataInRange")}),i.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray",children:a("stats.byMaterial")}),i.jsx(VC,{value:s,onChange:o})]}),_.length>0?i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx(oh,{width:160,height:160,children:i.jsxs(aW,{children:[i.jsx(vF,{data:_,cx:"50%",cy:"50%",innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:"value",children:_.map((R,P)=>i.jsx(Sx,{fill:$1[P%$1.length]},`cell-${P}`))}),i.jsx(lh,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:R=>[s==="weight"?th(Number(R??0)):s==="time"?`${Number(R??0)}h`:`${R??0}`,s==="weight"?"Usage":s==="time"?"Time":"Prints"]})]})}),i.jsx("div",{className:"flex-1 space-y-2 overflow-hidden",children:_.map((R,P)=>{const D=_.reduce((z,G)=>z+G.value,0),H=D>0?(R.value/D*100).toFixed(0):0;return i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx("div",{className:"w-3 h-3 rounded-sm flex-shrink-0",style:{backgroundColor:$1[P%$1.length]}}),i.jsx("span",{className:"text-white truncate flex-1",children:R.name}),i.jsxs("span",{className:"text-bambu-gray flex-shrink-0",children:[s==="weight"?th(R.value):s==="time"?`${R.value}h`:R.value," · ",H,"%"]})]},R.name)})})]}):i.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:a("stats.noFilamentData")})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:a("stats.filamentSuccess")}),x.length>0?i.jsx("div",{className:"space-y-1.5",children:x.map(R=>i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx("span",{className:"text-white truncate w-20 flex-shrink-0",children:R.name}),i.jsx("div",{className:"flex-1 h-1.5 bg-bambu-dark-secondary rounded-full",children:i.jsx("div",{className:`h-full rounded-full transition-all ${R.rate>=90?"bg-status-ok":R.rate>=70?"bg-status-warning":"bg-status-error"}`,style:{width:`${R.rate}%`}})}),i.jsxs("span",{className:`font-medium flex-shrink-0 tabular-nums ${R.rate>=90?"text-status-ok":R.rate>=70?"text-status-warning":"text-status-error"}`,children:[R.rate,"%"]}),i.jsxs("span",{className:"text-bambu-gray flex-shrink-0 text-xs",children:["(",R.total,")"]})]},R.name))}):i.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:a("stats.noArchiveData")})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray",children:a("stats.colorDistribution")}),i.jsx(VC,{value:l,onChange:c,exclude:["time"]})]}),g.length>0?(()=>{const R=g.reduce((P,D)=>P+D.value,0);return i.jsxs("div",{children:[i.jsxs("div",{className:"relative mx-auto",style:{width:160,height:160},children:[i.jsx(oh,{width:"100%",height:"100%",children:i.jsxs(aW,{children:[i.jsx(vF,{data:g,cx:"50%",cy:"50%",innerRadius:45,outerRadius:70,paddingAngle:2,dataKey:"value",children:g.map((P,D)=>i.jsx(Sx,{fill:P.hex,stroke:"#1a1a1a",strokeWidth:1},`color-${D}`))}),i.jsx(lh,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:P=>[l==="weight"?th(Number(P??0)):`${P??0}`,a(l==="weight"?"stats.filamentByWeight":"stats.filamentByPrints")]})]})}),i.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[i.jsx("span",{className:"text-lg font-bold text-white",children:l==="weight"?th(R):R}),i.jsxs("span",{className:"text-[10px] text-bambu-gray",children:[g.length," ",g.length===1?"color":"colors"]})]})]}),i.jsx("div",{className:"grid grid-cols-2 gap-x-3 gap-y-1 mt-2",children:g.slice(0,8).map(P=>{const D=R>0?(P.value/R*100).toFixed(0):0;return i.jsxs("div",{className:"flex items-center gap-1.5 text-xs min-w-0",children:[i.jsx("div",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0 border border-white/20",style:{backgroundColor:P.hex}}),i.jsxs("span",{className:"text-bambu-gray truncate",children:[D,"%"]})]},P.hex)})}),g.length>8&&i.jsxs("p",{className:"text-[10px] text-bambu-gray mt-1 text-center",children:["+",g.length-8," more"]})]})})():i.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:a("stats.noColorData")})]})]})]})}function KJe({id:t,title:e,component:n,isHidden:r,size:a,columnSpan:s,onToggleVisibility:o,onToggleSize:l}){const{attributes:c,listeners:u,setNodeRef:d,transform:m,transition:p,isDragging:f}=joe({id:t}),y={transform:Mx.Transform.toString(m),transition:p,opacity:f?.5:1};return r?null:i.jsxs("div",{ref:d,style:{...y,gridColumn:`span ${s}`},className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden ${f?"ring-2 ring-bambu-green shadow-lg":""}`,children:[i.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/30",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("button",{...c,...u,className:"cursor-grab active:cursor-grabbing p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Drag to reorder",children:i.jsx(bh,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray"})}),i.jsx("h3",{className:"text-sm font-medium text-white",children:e})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("button",{onClick:l,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:`Size: ${a===1?"1/4":a===2?"1/2":"Full"} - Click to cycle`,children:a===4?i.jsx(BL,{className:"w-4 h-4 text-bambu-gray hover:text-white"}):i.jsx(eT,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),i.jsx("button",{onClick:o,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Hide widget",children:i.jsx(mw,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]})]}),i.jsx("div",{className:"p-4",children:typeof n=="function"?n(a):n})]})}function YJe({widgets:t,storageKey:e,columns:n=4,stackBelow:r,hideControls:a=!1,onResetLayout:s,renderControls:o}){const l=()=>{const R={};return t.forEach(P=>{R[P.id]=P.defaultSize||4}),R},[c,u]=w.useState(()=>{const R=localStorage.getItem(e);if(R)try{const P=JSON.parse(R);if(!P.sizes)P.sizes=l();else{const D=l();for(const H in D)H in P.sizes||(P.sizes[H]=D[H])}return P}catch{}return{order:t.map(P=>P.id),hidden:t.filter(P=>P.defaultVisible===!1).map(P=>P.id),sizes:l()}}),[d,m]=w.useState(!1),[p,f]=w.useState(!1);w.useEffect(()=>{if(!r)return;const R=window.matchMedia(`(max-width: ${r}px)`),P=H=>{f(H.matches)};P(R);const D=H=>P(H);return R.addEventListener?R.addEventListener("change",D):R.addListener(D),()=>{R.removeEventListener?R.removeEventListener("change",D):R.removeListener(D)}},[r]);const y=r&&p?1:n;w.useEffect(()=>{const R=()=>m(P=>!P);return window.addEventListener("toggle-hidden-panel",R),()=>window.removeEventListener("toggle-hidden-panel",R)},[]),w.useEffect(()=>{localStorage.setItem(e,JSON.stringify(c))},[c,e]),w.useEffect(()=>{const P=t.map(D=>D.id).filter(D=>!c.order.includes(D));P.length>0&&u(D=>({...D,order:[...D.order,...P]}))},[t,c.order]);const v=uoe(HC(MA,{activationConstraint:{distance:8}}),HC(PA,{coordinateGetter:Doe})),x=R=>{const{active:P,over:D}=R;D&&P.id!==D.id&&u(H=>{const z=H.order.indexOf(P.id),G=H.order.indexOf(D.id);return{...H,order:DA(H.order,z,G)}})},g=R=>{u(P=>({...P,hidden:P.hidden.includes(R)?P.hidden.filter(D=>D!==R):[...P.hidden,R]}))},_=R=>{u(P=>{const D=P.sizes[R]||4,H=D===1?2:D===2?4:1;return{...P,sizes:{...P.sizes,[R]:H}}})},N=()=>{const R={order:t.map(P=>P.id),hidden:t.filter(P=>P.defaultVisible===!1).map(P=>P.id),sizes:l()};u(R),s?.()},T=c.order.map(R=>t.find(P=>P.id===R)).filter(Boolean),C=T.filter(R=>!c.hidden.includes(R.id)),A=T.filter(R=>c.hidden.includes(R.id)),k=o?.({hiddenCount:A.length,showHiddenPanel:d,setShowHiddenPanel:m,resetLayout:N});return i.jsxs("div",{className:"space-y-4",children:[k,!a&&!o&&i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:N,children:[i.jsx(bo,{className:"w-4 h-4"}),"Reset Layout"]}),A.length>0&&i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>m(!d),children:[i.jsx(_c,{className:"w-4 h-4"}),A.length," Hidden"]})]}),d&&A.length>0&&i.jsxs("div",{className:"p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:"Hidden widgets (click to show):"}),i.jsx("div",{className:"flex flex-wrap gap-2",children:A.map(R=>i.jsxs("button",{onClick:()=>g(R.id),className:"px-3 py-1.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded-lg text-sm text-white transition-colors flex items-center gap-2",children:[i.jsx(_c,{className:"w-3 h-3"}),R.title]},R.id))})]}),i.jsx(Toe,{sensors:v,collisionDetection:poe,onDragEnd:x,children:i.jsx(Moe,{items:C.map(R=>R.id),strategy:_5,children:i.jsx("div",{className:"grid gap-6",style:{gridTemplateColumns:`repeat(${y}, minmax(0, 1fr))`},children:C.map(R=>{const P=c.sizes[R.id]||2,D=Math.min(P,y);return i.jsx(KJe,{id:R.id,title:R.title,component:R.component,isHidden:c.hidden.includes(R.id),size:P,columnSpan:D,onToggleVisibility:()=>g(R.id),onToggleSize:()=>_(R.id)},R.id)})})})}),C.length===0&&i.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[i.jsx("p",{children:"All widgets are hidden."}),i.jsx(Oe,{className:"mt-4",onClick:N,children:"Reset Layout"})]})]})}function XJe(t){const e=new Date,n=e.getUTCFullYear(),r=e.getUTCMonth(),a=e.getUTCDate(),s=l=>l.toISOString().split("T")[0],o=s(e);switch(t){case"today":return{dateFrom:o,dateTo:o};case"this-week":{const l=e.getUTCDay(),c=new Date(Date.UTC(n,r,a-(l===0?6:l-1)));return{dateFrom:s(c),dateTo:o}}case"this-month":return{dateFrom:s(new Date(Date.UTC(n,r,1))),dateTo:o};case"last-7":return{dateFrom:s(new Date(Date.UTC(n,r,a-6))),dateTo:o};case"last-30":return{dateFrom:s(new Date(Date.UTC(n,r,a-29))),dateTo:o};case"last-90":return{dateFrom:s(new Date(Date.UTC(n,r,a-89))),dateTo:o};case"this-year":return{dateFrom:s(new Date(Date.UTC(n,0,1))),dateTo:o};case"all-time":return{dateFrom:void 0,dateTo:void 0};case"custom":return{}}}const QJe=["today","this-week","this-month","last-7","last-30","last-90","this-year","all-time"],ZJe=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],bL=["12am","1am","2am","3am","4am","5am","6am","7am","8am","9am","10am","11am","12pm","1pm","2pm","3pm","4pm","5pm","6pm","7pm","8pm","9pm","10pm","11pm"],OD=[{key:"<30m",max:1800},{key:"30m-1h",max:3600},{key:"1-2h",max:7200},{key:"2-4h",max:14400},{key:"4-8h",max:28800},{key:"8-12h",max:43200},{key:"12-24h",max:86400},{key:"24h+",max:1/0}],q1={backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"};function JJe({stats:t,currency:e}){const{t:n}=Ft(),r=[{icon:Wi,color:"text-bambu-green",label:n("stats.totalPrints"),value:`${t?.total_prints||0}`},{icon:er,color:"text-blue-400",label:n("stats.printTime"),value:`${t?.total_print_time_hours?.toFixed(1)??"0"}h`},{icon:Wi,color:"text-orange-400",label:n("stats.filamentUsed"),value:th(t?.total_filament_grams||0)},{icon:PN,color:"text-green-400",label:n("stats.filamentCost"),value:`${e} ${t?.total_cost?.toFixed(2)??"0.00"}`},{icon:kc,color:"text-yellow-400",label:n("stats.energyUsed"),value:`${t?.total_energy_kwh?.toFixed(3)??"0.000"} kWh`},{icon:PN,color:"text-yellow-500",label:n("stats.energyCost"),value:`${e} ${t?.total_energy_cost?.toFixed(2)??"0.00"}`}];return i.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:r.map(a=>i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx("div",{className:`p-2 rounded-lg bg-bambu-dark ${a.color}`,children:i.jsx(a.icon,{className:"w-5 h-5"})}),i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray",children:a.label}),i.jsx("p",{className:"text-xl font-bold text-white",children:a.value})]})]},a.label))})}function eet({stats:t,printerMap:e,size:n=1}){const{t:r}=Ft(),a=(t?.successful_prints||0)+(t?.failed_prints||0),s=a?Math.round(t.successful_prints/a*100):0,o=n===1?112:n===2?128:144,l=o/2-8,c=l*2*Math.PI;return i.jsxs("div",{className:"flex items-center gap-6",children:[i.jsxs("div",{className:"relative flex-shrink-0",style:{width:o,height:o},children:[i.jsxs("svg",{className:"w-full h-full -rotate-90",children:[i.jsx("circle",{cx:o/2,cy:o/2,r:l,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),i.jsx("circle",{cx:o/2,cy:o/2,r:l,fill:"none",stroke:"#00ae42",strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${s/100*c} ${c}`})]}),i.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:i.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[s,"%"]})})]}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(fr,{className:"w-4 h-4 text-status-ok flex-shrink-0"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:r("stats.successful")}),i.jsx("span",{className:"text-sm text-white font-medium",children:t?.successful_prints||0})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Vi,{className:"w-4 h-4 text-status-error flex-shrink-0"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:r("stats.failed")}),i.jsx("span",{className:"text-sm text-white font-medium",children:t?.failed_prints||0})]})]}),n>=2&&t?.prints_by_printer&&Object.keys(t.prints_by_printer).length>0&&i.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:r("stats.printsByPrinter")}),i.jsx("div",{className:`grid gap-x-6 gap-y-1 ${n===4?"grid-cols-3":"grid-cols-2"}`,style:{width:"fit-content"},children:Object.entries(t.prints_by_printer).map(([u,d])=>i.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[i.jsx("span",{className:"text-bambu-gray truncate max-w-[120px]",children:e.get(u)||`${r("common.printer")} ${u}`}),i.jsx("span",{className:"text-white font-medium",children:d})]},u))})]})]})]})}function tet({stats:t,printerMap:e,size:n=1}){const{t:r}=Ft(),a=t?.average_time_accuracy;if(a==null)return i.jsx("div",{className:"flex items-center justify-center h-full",children:i.jsx("p",{className:"text-bambu-gray text-center py-4",children:r("stats.noTimeAccuracyData")})});const o=(Math.min(150,Math.max(50,a))-50)/100*100,c=(v=>v>=95&&v<=105?"#00ae42":v>105?"#3b82f6":"#f97316")(a),u=a-100,d=n===1?112:n===2?128:144,m=d/2-8,p=m*2*Math.PI,f=n===1?3:n===2?6:999,y=t?.time_accuracy_by_printer?Object.entries(t.time_accuracy_by_printer).slice(0,f):[];return i.jsxs("div",{className:"flex items-center gap-6",children:[i.jsxs("div",{className:"relative flex-shrink-0",style:{width:d,height:d},children:[i.jsxs("svg",{className:"w-full h-full -rotate-90",children:[i.jsx("circle",{cx:d/2,cy:d/2,r:m,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),i.jsx("circle",{cx:d/2,cy:d/2,r:m,fill:"none",stroke:c,strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${o/100*p} ${p}`})]}),i.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[i.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[a.toFixed(0),"%"]}),i.jsxs("span",{className:`text-xs ${u>=0?"text-blue-400":"text-orange-400"}`,children:[u>=0?"+":"",u.toFixed(0),"%"]})]})]}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[i.jsx(JX,{className:"w-3 h-3 flex-shrink-0"}),i.jsx("span",{children:r("stats.perfectEstimate")})]}),y.length>0&&i.jsx("div",{className:`mt-2 ${n===4?"grid grid-cols-3 gap-x-6 gap-y-1":n===2?"grid grid-cols-2 gap-x-6 gap-y-1":"space-y-1"}`,style:{width:"fit-content"},children:y.map(([v,x])=>i.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[i.jsx("span",{className:"text-bambu-gray truncate max-w-[100px]",children:e.get(v)||`${r("common.printer")} ${v}`}),i.jsxs("span",{className:`font-medium ${x>=95&&x<=105?"text-status-ok":x>105?"text-blue-400":"text-status-warning"}`,children:[x.toFixed(0),"%"]})]},v))})]})]})}function net({printDates:t,dateFrom:e,dateTo:n}){const{days:r,hourlyCounts:a,maxCount:s}=w.useMemo(()=>{const d=new Date(e+"T00:00:00"),m=new Date(n+"T00:00:00"),p=[],f=g=>`${g.getFullYear()}-${String(g.getMonth()+1).padStart(2,"0")}-${String(g.getDate()).padStart(2,"0")}`,y=new Date(d);for(;y<=m;)p.push({key:f(y),label:y.toLocaleDateString(void 0,{weekday:"short",month:"short",day:"numeric"})}),y.setDate(y.getDate()+1);const v={};let x=0;return t.forEach(g=>{const _=Jn(g);if(!_)return;const T=`${`${_.getFullYear()}-${String(_.getMonth()+1).padStart(2,"0")}-${String(_.getDate()).padStart(2,"0")}`}-${_.getHours()}`;v[T]=(v[T]||0)+1,v[T]>x&&(x=v[T])}),{days:p,hourlyCounts:v,maxCount:Math.max(1,x)}},[t,e,n]),o=d=>{if(d===0)return"bg-bambu-dark";const m=d/s;return m<=.25?"bg-bambu-green/30":m<=.5?"bg-bambu-green/50":m<=.75?"bg-bambu-green/75":"bg-bambu-green"},l=20,c=2,u=80;return i.jsxs("div",{className:"w-full overflow-x-auto",children:[i.jsxs("div",{className:"inline-flex flex-col",style:{gap:c},children:[i.jsx("div",{className:"flex",style:{gap:c,marginLeft:u+4},children:bL.map((d,m)=>i.jsx("div",{className:"text-bambu-gray text-[10px] text-center",style:{width:l,visibility:m%2===0?"visible":"hidden"},children:d},m))}),r.map(d=>i.jsxs("div",{className:"flex items-center",style:{gap:c},children:[i.jsx("div",{className:"text-bambu-gray text-[10px] flex-shrink-0 truncate",style:{width:u},children:d.label}),Array.from({length:24},(m,p)=>{const f=a[`${d.key}-${p}`]||0;return i.jsx("div",{className:`rounded-sm ${o(f)}`,style:{width:l,height:l},title:`${d.label} ${bL[p]}: ${f} print${f!==1?"s":""}`},p)})]},d.key))]}),i.jsxs("div",{className:"flex items-center gap-2 mt-3 text-bambu-gray text-xs",children:[i.jsx("span",{children:"Less"}),i.jsxs("div",{className:"flex",style:{gap:c},children:[i.jsx("div",{className:"rounded-sm bg-bambu-dark",style:{width:l,height:l}}),i.jsx("div",{className:"rounded-sm bg-bambu-green/30",style:{width:l,height:l}}),i.jsx("div",{className:"rounded-sm bg-bambu-green/50",style:{width:l,height:l}}),i.jsx("div",{className:"rounded-sm bg-bambu-green/75",style:{width:l,height:l}}),i.jsx("div",{className:"rounded-sm bg-bambu-green",style:{width:l,height:l}})]}),i.jsx("span",{children:"More"})]})]})}function ret({printDates:t,size:e=2,dateFrom:n,dateTo:r}){const a=w.useMemo(()=>n&&r?Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1:n?Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1:1/0,[n,r]);if(a<=7&&n&&r)return i.jsx(net,{printDates:t,dateFrom:n,dateTo:r});const o=a===1/0?e===1?3:e===2?6:12:Math.max(1,Math.ceil(a/30));return i.jsx(VJe,{printDates:t,months:o})}function iet({stats:t,archives:e,printerMap:n}){const{t:r}=Ft(),[a,s]=w.useState("weight"),[o,l]=w.useState("weight"),c=w.useMemo(()=>{const g=new Map;return t?.prints_by_printer&&Object.entries(t.prints_by_printer).forEach(([_,N])=>{const T=g.get(_)||{prints:0,weight:0,time:0};T.prints=N,g.set(_,T)}),e.forEach(_=>{if(!_.printer_id)return;const N=String(_.printer_id),T=g.get(N)||{prints:0,weight:0,time:0};T.weight+=_.filament_used_grams||0,T.time+=_.actual_time_seconds||_.print_time_seconds||0,t?.prints_by_printer||T.prints++,g.set(N,T)}),Array.from(g.entries()).map(([_,N])=>({name:n.get(_)||`${r("common.printer")} ${_}`,value:a==="prints"?N.prints:a==="weight"?Math.round(N.weight):Math.round(N.time/3600*10)/10})).sort((_,N)=>N.value-_.value)},[t,e,n,a,r]),u=w.useMemo(()=>{const g=Array.from({length:24},(_,N)=>({hour:N,label:bL[N],total:0,failures:0}));return e.forEach(_=>{if(!_.started_at)return;const N=Jn(_.started_at);if(!N)return;const T=N.getHours();g[T].total++,_.status==="failed"&&g[T].failures++}),g},[e]),d=w.useMemo(()=>{const g=OD.map(_=>({name:_.key,count:0}));return e.forEach(_=>{const N=_.actual_time_seconds||_.print_time_seconds;if(!(!N||N<=0)){for(let T=0;T{const g=[0,0,0,0,0,0,0],_=new Set;e.forEach(T=>{const C=Jn(T.created_at)||new Date(T.created_at);let A=C.getDay()-1;A<0&&(A=6),o==="prints"?g[A]++:o==="weight"?g[A]+=T.filament_used_grams||0:g[A]+=(T.actual_time_seconds||T.print_time_seconds||0)/3600;const k=new Date(C);k.setDate(C.getDate()-(C.getDay()+6)%7),_.add(`${k.getFullYear()}-${String(k.getMonth()+1).padStart(2,"0")}-${String(k.getDate()).padStart(2,"0")}`)});const N=Math.max(_.size,1);return ZJe.map((T,C)=>({name:T,avg:Math.round(g[C]/N*10)/10}))},[e,o]),p=g=>({unit:g==="weight"?"g":g==="time"?"h":"",color:g==="weight"?"#00ae42":g==="time"?"#3b82f6":"#f59e0b"}),f=p(a),y=r(a==="weight"?"stats.filamentByWeight":a==="time"?"stats.hours":"common.prints"),v=p(o),x=r(o==="weight"?"stats.avgWeight":o==="time"?"stats.avgTime":"stats.avgPrints");return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray",children:r("stats.printsByPrinter")}),i.jsx(VC,{value:a,onChange:s})]}),c.length>0?i.jsx(oh,{width:"100%",height:Math.max(140,c.length*40),children:i.jsxs(N1,{data:c,layout:"vertical",margin:{left:10},children:[i.jsx(Kp,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),i.jsx(Yp,{type:"number",stroke:"#9ca3af",tick:{fontSize:11},unit:f.unit}),i.jsx(Xp,{type:"category",dataKey:"name",stroke:"#9ca3af",tick:{fontSize:11},width:100}),i.jsx(lh,{contentStyle:q1,formatter:g=>[a==="weight"?th(Number(g??0)):`${g??0}${f.unit}`,y]}),i.jsx(Tb,{dataKey:"value",fill:f.color,radius:[0,4,4,0]})]})}):i.jsx("p",{className:"text-bambu-gray text-center py-4",children:r("stats.noPrinterData")})]}),i.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-3",children:r("stats.printDuration")}),e.length>0?i.jsx(oh,{width:"100%",height:160,children:i.jsxs(N1,{data:d,children:[i.jsx(Kp,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),i.jsx(Yp,{dataKey:"name",stroke:"#9ca3af",tick:{fontSize:11}}),i.jsx(Xp,{stroke:"#9ca3af",tick:{fontSize:11},allowDecimals:!1}),i.jsx(lh,{contentStyle:q1}),i.jsx(Tb,{dataKey:"count",name:r("common.prints"),fill:"#00ae42",radius:[4,4,0,0]})]})}):i.jsx("p",{className:"text-bambu-gray text-center py-4",children:r("stats.noArchiveData")})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray",children:r("stats.printHabits")}),i.jsx(VC,{value:o,onChange:l})]}),e.length>0?i.jsx(oh,{width:"100%",height:160,children:i.jsxs(N1,{data:m,children:[i.jsx(Kp,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),i.jsx(Yp,{dataKey:"name",stroke:"#9ca3af",tick:{fontSize:11}}),i.jsx(Xp,{stroke:"#9ca3af",tick:{fontSize:11},unit:v.unit}),i.jsx(lh,{contentStyle:q1,formatter:g=>[`${g??0}${v.unit}`,x]}),i.jsx(Tb,{dataKey:"avg",fill:v.color,radius:[4,4,0,0]})]})}):i.jsx("p",{className:"text-bambu-gray text-center py-4",children:r("stats.noArchiveData")})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-3",children:r("stats.printTimeOfDay")}),e.length>0?i.jsx(oh,{width:"100%",height:160,children:i.jsxs(N1,{data:u,children:[i.jsx(Kp,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),i.jsx(Yp,{dataKey:"label",stroke:"#9ca3af",tick:{fontSize:10},interval:5}),i.jsx(Xp,{stroke:"#9ca3af",tick:{fontSize:11},allowDecimals:!1}),i.jsx(lh,{contentStyle:q1}),i.jsx(Tb,{dataKey:"total",name:r("stats.totalPrints"),fill:"#00ae42",radius:[2,2,0,0]}),i.jsx(Tb,{dataKey:"failures",name:r("stats.failed"),fill:"#ef4444",radius:[2,2,0,0]})]})}):i.jsx("p",{className:"text-bambu-gray text-center py-4",children:r("stats.noArchiveData")})]})]})]})}function aet({archives:t,currency:e,dateFrom:n,dateTo:r}){const{t:a}=Ft();return!t||t.length===0?i.jsx("p",{className:"text-bambu-gray text-center py-4",children:a("stats.noPrintData")}):i.jsx(WJe,{archives:t,currency:e,dateFrom:n,dateTo:r})}function set({size:t=1,dateFrom:e,dateTo:n}){const{t:r}=Ft(),a=!!(e||n),{data:s,isLoading:o}=et({queryKey:["failureAnalysis",e,n],queryFn:()=>be.getFailureAnalysis({...a?{dateFrom:e,dateTo:n}:{days:30}})});if(o)return i.jsx("div",{className:"flex justify-center py-4",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(!s||s.total_prints===0)return i.jsx("p",{className:"text-bambu-gray text-center py-4",children:r(a?"stats.noPrintDataInRange":"stats.noPrintDataLast30Days")});const l=t===1?5:t===2?8:999,c=Object.entries(s.failures_by_reason).sort(([,m],[,p])=>p-m),u=c.slice(0,l),d=c.length>l;return i.jsxs("div",{className:`${t>=2?"flex gap-8":"space-y-4"}`,children:[i.jsxs("div",{className:t>=2?"flex-shrink-0":"",children:[i.jsx("div",{className:"flex items-center gap-4",children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Mn,{className:`w-5 h-5 ${s.failure_rate>20?"text-status-error":s.failure_rate>10?"text-status-warning":"text-status-ok"}`}),i.jsxs("span",{className:`font-bold text-white ${t>=2?"text-3xl":"text-2xl"}`,children:[s.failure_rate.toFixed(1),"%"]})]})}),i.jsx("div",{className:"text-sm text-bambu-gray mt-1",children:r("stats.failedPrintsCount",{failed:s.failed_prints,total:s.total_prints})}),s.trend&&s.trend.length>=2&&i.jsx("div",{className:`${t>=2?"mt-4":"mt-2 pt-2 border-t border-bambu-dark-tertiary"}`,children:i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx(qL,{className:`w-4 h-4 ${s.trend[s.trend.length-1].failure_rate0&&i.jsxs("div",{className:`flex-1 ${t>=2?"border-l border-bambu-dark-tertiary pl-8":"pt-2"}`,children:[i.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:t>=2?r("stats.failureReasons"):r("stats.topFailureReasons")}),i.jsx("div",{className:`${t===4?"grid grid-cols-2 gap-x-6 gap-y-1":"space-y-1"}`,children:u.map(([m,p])=>i.jsxs("div",{className:"flex items-center justify-between text-sm",children:[i.jsx("span",{className:`text-white truncate ${t===4?"max-w-[200px]":"max-w-[160px]"}`,children:m||r("common.unknown")}),i.jsx("span",{className:"text-bambu-gray ml-2",children:p})]},m))}),d&&i.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:r("common.more",{count:c.length-l})})]})]})}function oet({archives:t,currency:e}){const{t:n}=Ft(),r=w.useMemo(()=>{const a=[];if(t.length===0)return a;const s=y=>{let v=null,x=0;return t.forEach(g=>{const _=y(g);_&&_>x&&(x=_,v=g)}),{archive:v,value:x}},o=s(y=>y.actual_time_seconds);o.archive&&a.push({icon:er,iconColor:"text-blue-400",label:n("stats.longestPrint"),value:Rs(o.value),detail:o.archive.print_name||null});const l=s(y=>y.filament_used_grams);l.archive&&a.push({icon:Wi,iconColor:"text-orange-400",label:n("stats.heaviestPrint"),value:th(l.value),detail:l.archive.print_name||null});const c=s(y=>y.cost);c.archive&&a.push({icon:PN,iconColor:"text-green-400",label:n("stats.mostExpensivePrint"),value:`${e}${c.value.toFixed(2)}`,detail:c.archive.print_name||null});const u=new Map;t.forEach(y=>{const v=Jn(y.created_at)||new Date(y.created_at),x=`${v.getFullYear()}-${String(v.getMonth()+1).padStart(2,"0")}-${String(v.getDate()).padStart(2,"0")}`;u.set(x,(u.get(x)||0)+1)});let d="",m=0;u.forEach((y,v)=>{y>m&&(m=y,d=v)}),m>1&&a.push({icon:Wr,iconColor:"text-purple-400",label:n("stats.busiestDay"),value:`${m} ${n("common.prints")}`,detail:(()=>{const[y,v,x]=d.split("-").map(Number);return new Date(y,v-1,x).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"})})()});const p=[...t].filter(y=>y.status==="completed"||y.status==="failed").sort((y,v)=>new Date(v.completed_at||v.created_at).getTime()-new Date(y.completed_at||y.created_at).getTime());let f=0;for(const y of p)if(y.status==="completed")f++;else break;return f>0&&a.push({icon:kc,iconColor:"text-yellow-400",label:n("stats.successStreak"),value:`${f}`,detail:f===1?n("stats.streakPrint"):n("stats.streakPrints",{count:f})}),a},[t,e,n]);return r.length===0?i.jsx("p",{className:"text-bambu-gray text-center py-4",children:n("stats.noArchiveData")}):i.jsx("div",{className:"space-y-3",children:r.map((a,s)=>i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:`p-1.5 rounded-lg bg-bambu-dark ${a.iconColor}`,children:i.jsx(a.icon,{className:"w-4 h-4"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-xs text-bambu-gray",children:a.label}),i.jsxs("div",{className:"flex items-baseline gap-2",children:[i.jsx("span",{className:"text-sm font-bold text-white",children:a.value}),a.detail&&i.jsx("span",{className:"text-xs text-bambu-gray truncate",children:a.detail})]})]})]},s))})}function cet(){const{t}=Ft(),{showToast:e}=fn(),{hasPermission:n}=_r(),[r,a]=w.useState(!1),[s,o]=w.useState(!1),[l,c]=w.useState(0),[u,d]=w.useState(0),[m,p]=w.useState(!1),[f,y]=w.useState(()=>{try{const ee=localStorage.getItem("bambusy-stats-timeframe");if(ee){const ie=JSON.parse(ee);if(ie.preset)return ie}}catch{}return{preset:"all-time",dateFrom:void 0,dateTo:void 0}}),[v,x]=w.useState(!1);w.useEffect(()=>{localStorage.setItem("bambusy-stats-timeframe",JSON.stringify(f))},[f]);const g=w.useMemo(()=>f.preset==="custom"?{dateFrom:f.dateFrom,dateTo:f.dateTo}:XJe(f.preset),[f]);w.useEffect(()=>{const ee=()=>{try{const X=localStorage.getItem("bambusy-dashboard-layout-v2");if(X){const me=JSON.parse(X);d(me.hidden?.length||0)}}catch{d(0)}};ee(),window.addEventListener("storage",ee);const ie=setInterval(ee,2e3);return()=>{window.removeEventListener("storage",ee),clearInterval(ie)}},[l]);const{data:_,isLoading:N,refetch:T}=et({queryKey:["archiveStats",g.dateFrom,g.dateTo],queryFn:()=>be.getArchiveStats({dateFrom:g.dateFrom,dateTo:g.dateTo})}),{data:C}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:A,refetch:k}=et({queryKey:["archivesSlim",g.dateFrom,g.dateTo],queryFn:()=>be.getArchivesSlim(g.dateFrom,g.dateTo)}),{data:R}=et({queryKey:["settings"],queryFn:be.getSettings}),P=async ee=>{o(!1),a(!0);try{const{blob:ie,filename:X}=await be.exportStats({format:ee,days:90}),me=URL.createObjectURL(ie),he=document.createElement("a");he.href=me,he.download=X,he.click(),URL.revokeObjectURL(me),e(t("stats.exportDownloaded"))}catch{e(t("stats.exportFailed"),"error")}finally{a(!1)}},D=async()=>{p(!0);try{const ee=await be.recalculateCosts();await Promise.all([T(),k()]),e(t("stats.recalculatedCosts",{count:ee.updated}))}catch{e(t("stats.recalculateFailed"),"error")}finally{p(!1)}},H=_l(R?.currency||"USD"),z=new Map(C?.map(ee=>[String(ee.id),ee.name])||[]),G=w.useMemo(()=>A?.map(ee=>ee.created_at)||[],[A]);if(N)return i.jsx("div",{className:"p-4 md:p-8",children:i.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("stats.loadingStats")})});const I=[{id:"quick-stats",title:t("stats.quickStats"),component:i.jsx(JJe,{stats:_,currency:H}),defaultSize:2},{id:"success-rate",title:t("stats.successRate"),component:ee=>i.jsx(eet,{stats:_,printerMap:z,size:ee}),defaultSize:1},{id:"time-accuracy",title:t("stats.timeAccuracy"),component:ee=>i.jsx(tet,{stats:_,printerMap:z,size:ee}),defaultSize:1},{id:"failure-analysis",title:t("stats.failureAnalysis"),component:ee=>i.jsx(set,{size:ee,dateFrom:g.dateFrom,dateTo:g.dateTo}),defaultSize:1},{id:"print-activity",title:t("stats.printActivity"),component:ee=>i.jsx(ret,{printDates:G,size:ee,dateFrom:g.dateFrom,dateTo:g.dateTo}),defaultSize:2},{id:"records",title:t("stats.records"),component:i.jsx(oet,{archives:A||[],currency:H}),defaultSize:1},{id:"printer-stats",title:t("stats.printerStats"),component:i.jsx(iet,{stats:_,archives:A||[],printerMap:z}),defaultSize:4},{id:"filament-trends",title:t("stats.filamentTrends"),component:i.jsx(aet,{archives:A||[],currency:H,dateFrom:g.dateFrom,dateTo:g.dateTo}),defaultSize:4}];return i.jsxs("div",{className:"p-4 md:p-8",children:[i.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6",children:[i.jsxs("div",{children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:t("stats.title")}),i.jsx("p",{className:"text-bambu-gray",children:t("stats.subtitle")})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u>0&&i.jsxs(Oe,{variant:"secondary",onClick:()=>{window.dispatchEvent(new CustomEvent("toggle-hidden-panel"))},children:[i.jsx(_c,{className:"w-4 h-4"}),t("stats.hiddenCount",{count:u})]}),i.jsxs(Oe,{variant:"secondary",onClick:()=>{localStorage.removeItem("bambusy-dashboard-layout-v2"),c(ee=>ee+1),e(t("stats.layoutReset"))},disabled:!n("settings:update"),title:n("settings:update")?void 0:t("stats.noPermissionResetLayout"),children:[i.jsx(bo,{className:"w-4 h-4"}),t("stats.resetLayout")]}),i.jsxs(Oe,{variant:"secondary",onClick:D,disabled:m||!n("archives:update_all"),title:n("archives:update_all")?t("stats.recalculateCostsHint"):t("stats.noPermissionRecalculate"),children:[m?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(jhe,{className:"w-4 h-4"}),t("stats.recalculateCosts")]}),i.jsxs("div",{className:"relative",children:[i.jsxs(Oe,{variant:"secondary",onClick:()=>o(!s),disabled:r,children:[r?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(EN,{className:"w-4 h-4"}),t("stats.exportStats")]}),s&&i.jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20",children:[i.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg",onClick:()=>P("csv"),children:[i.jsx(Fs,{className:"w-4 h-4"}),t("stats.exportAsCsv")]}),i.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg",onClick:()=>P("xlsx"),children:[i.jsx(EN,{className:"w-4 h-4"}),t("stats.exportAsExcel")]})]})]}),i.jsxs("div",{className:"relative",children:[i.jsxs(Oe,{variant:"secondary",onClick:()=>x(!v),children:[i.jsx(Wr,{className:"w-4 h-4"}),t(`stats.timeframe.${f.preset}`),i.jsx(Ln,{className:"w-3 h-3"})]}),v&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>x(!1)}),i.jsxs("div",{className:"absolute right-0 top-full mt-1 w-64 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 p-2",children:[QJe.map(ee=>i.jsx("button",{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${f.preset===ee?"bg-bambu-green text-white":"text-white hover:bg-bambu-dark-tertiary"}`,onClick:()=>{y({preset:ee,dateFrom:void 0,dateTo:void 0}),x(!1)},children:t(`stats.timeframe.${ee}`)},ee)),i.jsx("div",{className:"border-t border-bambu-dark-tertiary my-2"}),i.jsx("button",{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${f.preset==="custom"?"bg-bambu-green text-white":"text-white hover:bg-bambu-dark-tertiary"}`,onClick:()=>y(ee=>({...ee,preset:"custom"})),children:t("stats.timeframe.custom")}),f.preset==="custom"&&i.jsxs("div",{className:"mt-2 px-1 pb-1 space-y-2",children:[i.jsxs("div",{children:[i.jsx("label",{className:"text-xs text-bambu-gray block mb-1",children:t("stats.timeframe.from")}),i.jsx("input",{type:"date",value:f.dateFrom||"",max:f.dateTo||new Date().toISOString().split("T")[0],onChange:ee=>y(ie=>({...ie,dateFrom:ee.target.value||void 0})),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white [color-scheme:dark]"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"text-xs text-bambu-gray block mb-1",children:t("stats.timeframe.to")}),i.jsx("input",{type:"date",value:f.dateTo||"",min:f.dateFrom,max:new Date().toISOString().split("T")[0],onChange:ee=>y(ie=>({...ie,dateTo:ee.target.value||void 0})),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white [color-scheme:dark]"})]}),i.jsx(Oe,{variant:"primary",onClick:()=>x(!1),className:"w-full",children:t("common.apply")})]})]})]})]})]})]}),i.jsx(YJe,{widgets:I,storageKey:"bambusy-dashboard-layout-v2",stackBelow:640,hideControls:!0},l)]})}function uet({plug:t,onEdit:e}){const{t:n}=Ft(),r=an(),{showToast:a}=fn(),[s,o]=w.useState(!1),[l,c]=w.useState(!1),[u,d]=w.useState(!1),[m,p]=w.useState(!1),{data:f,isLoading:y}=et({queryKey:["smart-plug-status",t.id],queryFn:()=>be.getSmartPlugStatus(t.id),refetchInterval:3e4}),{data:v}=et({queryKey:["printers"],queryFn:be.getPrinters}),x=v?.find(D=>D.id===t.printer_id),g=pt({mutationFn:D=>be.controlSmartPlug(t.id,D),onMutate:async D=>{await r.cancelQueries({queryKey:["smart-plug-status",t.id]});const H=r.getQueryData(["smart-plug-status",t.id]),z=D==="on"?"ON":D==="off"||f?.state==="ON"?"OFF":"ON";return r.setQueryData(["smart-plug-status",t.id],G=>({...G,state:z})),{previousStatus:H}},onError:(D,H,z)=>{z?.previousStatus&&r.setQueryData(["smart-plug-status",t.id],z.previousStatus),a(n("smartPlugs.failedToTurn",{action:H,name:t.name}),"error")},onSettled:()=>{setTimeout(()=>{r.invalidateQueries({queryKey:["smart-plug-status",t.id]}),r.invalidateQueries({queryKey:["smart-plugs"]})},1e3)}}),_=pt({mutationFn:D=>be.updateSmartPlug(t.id,D),onSuccess:()=>{r.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&(r.invalidateQueries({queryKey:["smartPlugByPrinter",t.printer_id]}),r.invalidateQueries({queryKey:["scriptPlugsByPrinter",t.printer_id]}))}}),N=pt({mutationFn:()=>be.deleteSmartPlug(t.id),onSuccess:()=>{r.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&r.invalidateQueries({queryKey:["scriptPlugsByPrinter",t.printer_id]})}}),T=f?.state==="ON",C=t.plug_type==="mqtt"&&f?.energy?.power!==null&&f?.energy?.power!==void 0,A=(f?.reachable??!1)||C,k=g.isPending,P=(()=>{if(t.plug_type!=="tasmota"||!t.ip_address)return null;const D=t.ip_address;return t.username&&t.password?`http://${encodeURIComponent(t.username)}:${encodeURIComponent(t.password)}@${D}/`:`http://${D}/`})();return i.jsxs(i.Fragment,{children:[i.jsx(Mt,{className:"relative",children:i.jsxs(Dt,{className:"p-4",children:[i.jsxs("div",{className:"flex items-start justify-between gap-2 mb-3",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[i.jsx("div",{className:`p-2 rounded-lg flex-shrink-0 ${t.plug_type==="mqtt"?A?"bg-teal-500/20":"bg-red-500/20":A?T?"bg-bambu-green/20":"bg-bambu-dark":"bg-red-500/20"}`,children:t.plug_type==="mqtt"?i.jsx(HL,{className:`w-5 h-5 ${A?"text-teal-400":"text-red-400"}`}):t.plug_type==="homeassistant"?i.jsx(hw,{className:`w-5 h-5 ${A?T?"text-bambu-green":"text-bambu-gray":"text-red-400"}`}):i.jsx(Dl,{className:`w-5 h-5 ${A?T?"text-bambu-green":"text-bambu-gray":"text-red-400"}`})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("h3",{className:"font-medium text-white truncate",children:t.name}),i.jsx("p",{className:"text-sm text-bambu-gray truncate",title:t.plug_type==="mqtt"?t.mqtt_topic??void 0:t.plug_type==="homeassistant"?t.ha_entity_id??void 0:t.ip_address??void 0,children:t.plug_type==="mqtt"?t.mqtt_topic:t.plug_type==="homeassistant"?t.ha_entity_id:t.ip_address})]})]}),i.jsxs("div",{className:"flex flex-col items-end gap-1 flex-shrink-0",children:[y?i.jsx(ht,{className:"w-4 h-4 text-bambu-gray animate-spin"}):t.plug_type==="mqtt"?i.jsxs("div",{className:"flex items-center gap-1.5 text-sm whitespace-nowrap",children:[i.jsx("span",{className:"px-1.5 py-0.5 bg-teal-500/20 text-teal-400 text-[10px] font-medium rounded flex-shrink-0",children:"MQTT"}),A&&i.jsx("span",{className:"text-status-ok",children:"✓"})]}):t.plug_type==="homeassistant"?i.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[i.jsx("span",{className:"px-1 py-0.5 bg-blue-500/20 text-blue-400 text-[10px] font-medium rounded",children:"HA"}),i.jsx("span",{className:A?T?"text-status-ok":"text-bambu-gray":"text-status-error",children:A?f?.state||"?":n("smartPlugs.offline")})]}):A?i.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[i.jsx(Ub,{className:"w-4 h-4 text-status-ok"}),i.jsx("span",{className:T?"text-status-ok":"text-bambu-gray",children:f?.state||n("smartPlugs.unknown")})]}):i.jsxs("div",{className:"flex items-center gap-1 text-sm text-status-error",children:[i.jsx(Ph,{className:"w-4 h-4"}),i.jsx("span",{children:n("smartPlugs.offline")})]}),P&&i.jsxs("a",{href:P,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:[i.jsx(Jr,{className:"w-3 h-3"}),n("smartPlugs.admin")]})]})]}),x&&i.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[i.jsxs("span",{className:"text-xs text-bambu-gray",children:[n("smartPlugs.linkedTo")," "]}),i.jsx("span",{className:"text-sm text-white",children:x.name})]}),(t.power_alert_enabled||t.schedule_enabled||t.plug_type==="mqtt")&&i.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-3",children:[t.plug_type==="mqtt"&&i.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-teal-500/20 text-teal-400 text-xs rounded-full",children:[i.jsx(_c,{className:"w-3 h-3"}),n("smartPlugs.monitorOnly")]}),t.power_alert_enabled&&i.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded-full",children:[i.jsx(hh,{className:"w-3 h-3"}),n("smartPlugs.alerts")]}),t.schedule_enabled&&i.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded-full",children:[i.jsx(Wr,{className:"w-3 h-3"}),t.schedule_on_time&&t.schedule_off_time?`${t.schedule_on_time} - ${t.schedule_off_time}`:t.schedule_on_time?n("smartPlugs.scheduleOn",{time:t.schedule_on_time}):n("smartPlugs.scheduleOff",{time:t.schedule_off_time})]})]}),t.plug_type!=="mqtt"&&i.jsxs("div",{className:"flex gap-2 mb-3",children:[i.jsxs(Oe,{size:"sm",variant:T?"primary":"secondary",disabled:!A||k,onClick:()=>c(!0),className:"flex-1",children:[k?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Vd,{className:"w-4 h-4"}),n("smartPlugs.on")]}),i.jsxs(Oe,{size:"sm",variant:T?"secondary":"primary",disabled:!A||k,onClick:()=>d(!0),className:"flex-1",children:[k?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(nT,{className:"w-4 h-4"}),n("smartPlugs.off")]})]}),t.plug_type==="mqtt"&&f?.energy&&i.jsxs("div",{className:"flex gap-2 mb-3 px-3 py-2 bg-bambu-dark rounded-lg",children:[f.energy.power!==null&&f.energy.power!==void 0&&i.jsxs("div",{className:"flex-1 text-center",children:[i.jsxs("p",{className:"text-lg font-semibold text-white",children:[Math.round(f.energy.power),"W"]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.power")})]}),f.energy.today!==null&&f.energy.today!==void 0&&i.jsxs("div",{className:"flex-1 text-center border-l border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-lg font-semibold text-white",children:f.energy.today.toFixed(3)}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.kwhToday")})]})]}),i.jsxs("button",{onClick:()=>p(!m),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:[i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(jd,{className:"w-4 h-4"}),t.plug_type==="mqtt"?n("smartPlugs.settings"):n("smartPlugs.automationSettings")]}),i.jsx("span",{children:m?"-":"+"})]}),m&&i.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(pw,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("smartPlugs.showInSwitchbar")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.quickAccessSidebar")})]})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:t.show_in_switchbar,onChange:D=>_.mutate({show_in_switchbar:D.target.checked}),className:"sr-only peer"}),i.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"})]})]}),t.plug_type!=="mqtt"&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("smartPlugs.enabled")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.enableAutomation")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:t.enabled,onChange:D=>_.mutate({enabled:D.target.checked}),className:"sr-only peer"}),i.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"})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("smartPlugs.autoOn")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.autoOnDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:t.auto_on,onChange:D=>_.mutate({auto_on:D.target.checked}),className:"sr-only peer"}),i.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"})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("smartPlugs.autoOff")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.autoOffDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:t.auto_off,onChange:D=>_.mutate({auto_off:D.target.checked}),className:"sr-only peer"}),i.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"})]})]}),t.auto_off&&i.jsxs("div",{className:"space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white mb-2",children:n("smartPlugs.turnOffDelayMode")}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("button",{onClick:()=>_.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 ${t.off_delay_mode==="time"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[i.jsx(er,{className:"w-4 h-4"}),n("smartPlugs.time")]}),i.jsxs("button",{onClick:()=>_.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 ${t.off_delay_mode==="temperature"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[i.jsx(aT,{className:"w-4 h-4"}),n("smartPlugs.temp")]})]})]}),t.off_delay_mode==="time"?i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("smartPlugs.delayMinutes")}),i.jsx("input",{type:"number",min:"1",max:"60",value:t.off_delay_minutes,onChange:D=>_.mutate({off_delay_minutes:parseInt(D.target.value)||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"})]}):i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("smartPlugs.tempThreshold")}),i.jsx("input",{type:"number",min:"30",max:"100",value:t.off_temp_threshold,onChange:D=>_.mutate({off_temp_threshold:parseInt(D.target.value)||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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("smartPlugs.tempThresholdDescription")})]})]})]}),i.jsxs("div",{className:"flex gap-2 pt-2",children:[i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[i.jsx(nh,{className:"w-4 h-4"}),n("smartPlugs.edit")]}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:()=>o(!0),className:"text-red-400 hover:text-red-300",children:i.jsx(Jt,{className:"w-4 h-4"})})]})]})]})}),s&&i.jsx(Sn,{title:n("smartPlugs.deleteSmartPlug"),message:n("smartPlugs.deleteConfirm",{name:t.name}),confirmText:n("smartPlugs.delete"),variant:"danger",onConfirm:()=>{N.mutate(),o(!1)},onCancel:()=>o(!1)}),l&&i.jsx(Sn,{title:n("smartPlugs.turnOnSmartPlug"),message:n("smartPlugs.turnOnConfirm",{name:t.name}),confirmText:n("smartPlugs.turnOn"),variant:"default",onConfirm:()=>{g.mutate("on"),c(!1)},onCancel:()=>c(!1)}),u&&i.jsx(Sn,{title:n("smartPlugs.turnOffSmartPlug"),message:n("smartPlugs.turnOffConfirm",{name:t.name}),confirmText:n("smartPlugs.turnOff"),variant:"danger",onConfirm:()=>{g.mutate("off"),d(!1)},onCancel:()=>d(!1)})]})}function det({plug:t,onClose:e}){const{t:n}=Ft(),r=an(),a=!!t,[s,o]=w.useState(t?.plug_type||"tasmota"),[l,c]=w.useState(t?.name||""),[u,d]=w.useState(t?.ip_address||""),[m,p]=w.useState(t?.username||""),[f,y]=w.useState(t?.password||""),[v,x]=w.useState(t?.ha_entity_id||""),[g,_]=w.useState(t?.mqtt_power_topic||t?.mqtt_topic||""),[N,T]=w.useState(t?.mqtt_power_path||""),[C,A]=w.useState((t?.mqtt_power_multiplier??t?.mqtt_multiplier??1).toString()),[k,R]=w.useState(t?.mqtt_energy_topic||""),[P,D]=w.useState(t?.mqtt_energy_path||""),[H,z]=w.useState((t?.mqtt_energy_multiplier??1).toString()),[G,I]=w.useState(t?.mqtt_state_topic||""),[ee,ie]=w.useState(t?.mqtt_state_path||""),[X,me]=w.useState(t?.mqtt_state_on_value||""),[he,ge]=w.useState(t?.ha_power_entity||""),[Y,oe]=w.useState(t?.ha_energy_today_entity||""),[le,xe]=w.useState(t?.ha_energy_total_entity||""),[Pe,q]=w.useState(""),[Z,j]=w.useState(""),[E,U]=w.useState(!1),K=w.useRef(null),[$,ne]=w.useState(""),[O,V]=w.useState(!1),J=w.useRef(null),[W,re]=w.useState(""),[ue,fe]=w.useState(!1),ye=w.useRef(null),[ae,L]=w.useState(""),[F,te]=w.useState(!1),ve=w.useRef(null),[pe,de]=w.useState(t?.printer_id||null),[Ne,Se]=w.useState(null),[Le,qe]=w.useState(null),[Ee,Te]=w.useState(t?.power_alert_enabled||!1),[Ae,Be]=w.useState(t?.power_alert_high?.toString()||""),[je,Xe]=w.useState(t?.power_alert_low?.toString()||""),[ce,Ie]=w.useState(t?.schedule_enabled||!1),[Ce,Ge]=w.useState(t?.schedule_on_time||""),[$e,Ue]=w.useState(t?.schedule_off_time||""),[De,Ve]=w.useState(t?.show_in_switchbar||!1),[it,xt]=w.useState(t?.show_on_printer_card??!0),[Nt,kt]=w.useState(!1),[We,yt]=w.useState({scanned:0,total:0}),[wt,_t]=w.useState([]),Ot=w.useRef(null),{data:Vt}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:Xt}=et({queryKey:["smart-plugs"],queryFn:be.getSmartPlugs}),{data:Qe}=et({queryKey:["settings"],queryFn:be.getSettings}),Qt=!!(Qe?.ha_enabled&&Qe?.ha_url&&Qe?.ha_token);w.useEffect(()=>{const Me=setTimeout(()=>{j(Pe)},300);return()=>clearTimeout(Me)},[Pe]),w.useEffect(()=>{const Me=dt=>{K.current&&!K.current.contains(dt.target)&&U(!1),J.current&&!J.current.contains(dt.target)&&V(!1),ye.current&&!ye.current.contains(dt.target)&&fe(!1),ve.current&&!ve.current.contains(dt.target)&&te(!1)};return document.addEventListener("mousedown",Me),()=>document.removeEventListener("mousedown",Me)},[]);const{data:hn,isLoading:jn,error:kn}=et({queryKey:["ha-entities",Z],queryFn:()=>be.getHAEntities(Z||void 0),enabled:s==="homeassistant"&&Qt,retry:!1,staleTime:0}),{data:Fe}=et({queryKey:["ha-sensor-entities"],queryFn:be.getHASensorEntities,enabled:s==="homeassistant"&&Qt,retry:!1,staleTime:0});w.useEffect(()=>{const Me=dt=>{dt.key==="Escape"&&e()};return window.addEventListener("keydown",Me),()=>{window.removeEventListener("keydown",Me),Ot.current&&clearInterval(Ot.current)}},[e]);const tt=async()=>{kt(!0),_t([]),yt({scanned:0,total:0}),qe(null);try{await be.startTasmotaScan();const Me=async()=>{try{const dt=await be.getTasmotaScanStatus();yt({scanned:dt.scanned,total:dt.total});const ct=await be.getDiscoveredTasmotaDevices();_t(ct),dt.running||(kt(!1),Ot.current&&(clearInterval(Ot.current),Ot.current=null))}catch(dt){console.error("Polling error:",dt)}};await Me(),Ot.current=setInterval(Me,500)}catch(Me){kt(!1);const dt=Me instanceof Error?Me.message:typeof Me=="string"?Me:JSON.stringify(Me);qe(dt||n("smartPlugs.failedToStartScan"))}},ut=async()=>{try{await be.stopTasmotaScan()}catch{}kt(!1),Ot.current&&(clearInterval(Ot.current),Ot.current=null)},Ze=Me=>{d(Me.ip_address),c(Me.name),Se(null)},ke=pt({mutationFn:()=>be.testSmartPlugConnection(u,m||null,f||null),onSuccess:Me=>{Se(Me),qe(null),!l&&Me.device_name&&c(Me.device_name)},onError:Me=>{Se(null),qe(Me.message)}}),ot=pt({mutationFn:Me=>be.createSmartPlug(Me),onSuccess:()=>{r.invalidateQueries({queryKey:["smart-plugs"]}),r.invalidateQueries({queryKey:["scriptPlugsByPrinter"]}),e()},onError:Me=>{qe(Me.message)}}),se=pt({mutationFn:Me=>be.updateSmartPlug(t.id,Me),onSuccess:()=>{r.invalidateQueries({queryKey:["smart-plugs"]}),r.invalidateQueries({queryKey:["scriptPlugsByPrinter"]}),e()},onError:Me=>{qe(Me.message)}}),He=Vt?.filter(Me=>s==="tasmota"?!Xt?.some(ct=>ct.printer_id===Me.id&&ct.id!==t?.id&&ct.plug_type==="tasmota"):!0),Ke=Me=>{if(Me.preventDefault(),qe(null),!l.trim()){qe(n("smartPlugs.nameRequired"));return}if(s==="tasmota"&&!u.trim()){qe("IP address is required for Tasmota plugs");return}if(s==="homeassistant"&&!v){qe(n("smartPlugs.entityRequired"));return}if(s==="mqtt"){const ct=g.trim(),nt=k.trim(),bt=G.trim();if(!ct&&!nt&&!bt){qe(n("smartPlugs.mqttTopicRequired"));return}}const dt={name:l.trim(),plug_type:s,ip_address:s==="tasmota"?u.trim():null,ha_entity_id:s==="homeassistant"?v:null,ha_power_entity:s==="homeassistant"&&he||null,ha_energy_today_entity:s==="homeassistant"&&Y||null,ha_energy_total_entity:s==="homeassistant"&&le||null,mqtt_power_topic:s==="mqtt"&&g.trim()||null,mqtt_power_path:s==="mqtt"&&N.trim()||null,mqtt_power_multiplier:s==="mqtt"&&parseFloat(C)||1,mqtt_energy_topic:s==="mqtt"&&k.trim()||null,mqtt_energy_path:s==="mqtt"&&P.trim()||null,mqtt_energy_multiplier:s==="mqtt"&&parseFloat(H)||1,mqtt_state_topic:s==="mqtt"&&G.trim()||null,mqtt_state_path:s==="mqtt"&&ee.trim()||null,mqtt_state_on_value:s==="mqtt"&&X.trim()||null,username:s==="tasmota"&&m.trim()||null,password:s==="tasmota"&&f.trim()||null,printer_id:pe,power_alert_enabled:Ee,power_alert_high:Ae?parseFloat(Ae):null,power_alert_low:je?parseFloat(je):null,schedule_enabled:ce,schedule_on_time:Ce||null,schedule_off_time:$e||null,show_in_switchbar:De,show_on_printer_card:it};a?se.mutate(dt):ot.mutate(dt)},Ye=ot.isPending||se.isPending;return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:i.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:Me=>Me.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary flex-shrink-0",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:n(a?"smartPlugs.editTitle":"smartPlugs.addTitle")}),i.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:Ke,className:"p-6 space-y-4 overflow-y-auto",children:[Le&&i.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:Le}),!a&&i.jsxs("div",{className:"flex gap-2 mb-2",children:[i.jsxs("button",{type:"button",onClick:()=>{o("tasmota"),Se(null),qe(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${s==="tasmota"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[i.jsx(Dl,{className:"w-4 h-4"}),"Tasmota"]}),i.jsxs("button",{type:"button",onClick:()=>{o("homeassistant"),Se(null),qe(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${s==="homeassistant"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[i.jsx(hw,{className:"w-4 h-4"}),"HA"]}),i.jsxs("button",{type:"button",onClick:()=>{o("mqtt"),Se(null),qe(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${s==="mqtt"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[i.jsx(HL,{className:"w-4 h-4"}),"MQTT"]})]}),!a&&s==="tasmota"&&i.jsxs("div",{className:"space-y-3",children:[Nt?i.jsxs(Oe,{type:"button",variant:"secondary",onClick:ut,className:"w-full",children:[i.jsx(Ht,{className:"w-4 h-4"}),n("smartPlugs.stopScanning")]}):i.jsxs(Oe,{type:"button",variant:"primary",onClick:tt,className:"w-full",children:[i.jsx(jr,{className:"w-4 h-4"}),n("smartPlugs.discoverTasmota")]}),Nt&&We.total>0&&i.jsxs("div",{className:"space-y-1",children:[i.jsxs("div",{className:"flex justify-between text-xs text-bambu-gray",children:[i.jsx("span",{children:n("smartPlugs.addSmartPlug.scanningNetwork")}),i.jsxs("span",{children:[We.scanned," / ",We.total]})]}),i.jsx("div",{className:"w-full bg-bambu-dark-tertiary rounded-full h-2",children:i.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${We.scanned/We.total*100}%`}})})]}),wt.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.foundDevices",{count:wt.length})}),i.jsx("div",{className:"max-h-40 overflow-y-auto space-y-1",children:wt.map(Me=>i.jsxs("button",{type:"button",onClick:()=>Ze(Me),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:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Dl,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:Me.name}),i.jsx("p",{className:"text-xs text-bambu-gray",children:Me.ip_address})]})]}),Me.state&&i.jsxs("span",{className:`flex items-center gap-1 text-xs ${Me.state==="ON"?"text-bambu-green":"text-bambu-gray"}`,children:[i.jsx(Vd,{className:"w-3 h-3"}),Me.state]})]},Me.ip_address))})]}),!Nt&&wt.length===0&&We.total>0&&i.jsx("p",{className:"text-xs text-bambu-gray text-center py-2",children:n("smartPlugs.noDevicesFound")})]}),s==="homeassistant"&&i.jsxs("div",{className:"space-y-3",children:[!Qt&&i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"p-3 bg-yellow-500/20 border border-yellow-500/50 rounded-lg text-sm text-yellow-400",children:[n("smartPlugs.haNotConfigured")," ",i.jsx("span",{className:"font-medium",children:n("smartPlugs.haSettingsPath")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1 opacity-50",children:n("smartPlugs.selectEntity")}),i.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:i.jsx("option",{children:n("smartPlugs.addSmartPlug.chooseEntity")})})]})]}),Qt&&i.jsxs(i.Fragment,{children:[jn&&i.jsxs("div",{className:"flex items-center justify-center py-4 text-bambu-gray",children:[i.jsx(ht,{className:"w-5 h-5 animate-spin mr-2"}),n("smartPlugs.loadingEntities")]}),kn&&i.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:n("smartPlugs.failedToLoadEntities",{error:kn.message})}),(()=>{const Me=Xt?.filter(nt=>nt.ha_entity_id&&nt.id!==t?.id).map(nt=>nt.ha_entity_id)||[],dt=(hn||[]).filter(nt=>!Me.includes(nt.entity_id)),ct=hn?.find(nt=>nt.entity_id===v);return i.jsxs("div",{ref:K,className:"relative",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.selectEntity")}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),i.jsx("input",{type:"text",value:E?Pe:ct?`${ct.friendly_name} (${ct.entity_id})`:"",onChange:nt=>{q(nt.target.value),E||U(!0)},onFocus:()=>{U(!0),q("")},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"}),v&&!E&&i.jsx("button",{type:"button",onClick:()=>{x(""),q("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(Ht,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),jn&&i.jsx(ht,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray animate-spin"})]}),E&&i.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:[jn&&i.jsxs("div",{className:"px-3 py-2 text-sm text-bambu-gray flex items-center gap-2",children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),n("smartPlugs.loading")]}),!jn&&dt.length===0&&i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:Z?n("smartPlugs.noEntitiesMatching",{search:Z}):n("smartPlugs.noEntitiesAvailable")}),!jn&&dt.map(nt=>i.jsxs("button",{type:"button",onClick:()=>{x(nt.entity_id),U(!1),q(""),l||c(nt.friendly_name)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary transition-colors ${nt.entity_id===v?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[i.jsx("div",{className:"font-medium",children:nt.friendly_name}),i.jsxs("div",{className:"text-xs text-bambu-gray flex items-center justify-between",children:[i.jsx("span",{children:nt.entity_id}),i.jsx("span",{className:nt.state==="on"?"text-bambu-green":"",children:nt.state})]})]},nt.entity_id))]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:Z?n("smartPlugs.searchingEntities",{count:dt.length}):n("smartPlugs.showingEntities",{count:dt.length})})]})})(),v&&Fe&&Fe.length>0&&i.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4 space-y-3",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white font-medium mb-1",children:n("smartPlugs.energyMonitoringOptional")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:n("smartPlugs.energyMonitoringHint")})]}),(()=>{const Me=Fe.filter(nt=>nt.unit_of_measurement==="W"||nt.unit_of_measurement==="kW"||nt.unit_of_measurement==="mW"),dt=$?Me.filter(nt=>nt.entity_id.toLowerCase().includes($.toLowerCase())||nt.friendly_name.toLowerCase().includes($.toLowerCase())):Me,ct=Fe.find(nt=>nt.entity_id===he);return i.jsxs("div",{ref:J,className:"relative",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.powerSensorW")}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),i.jsx("input",{type:"text",value:O?$:ct?`${ct.friendly_name} (${ct.state} ${ct.unit_of_measurement})`:"",onChange:nt=>{ne(nt.target.value),O||V(!0)},onFocus:()=>{V(!0),ne("")},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"}),he&&!O&&i.jsx("button",{type:"button",onClick:()=>{ge(""),ne("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(Ht,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),O&&i.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:[i.jsx("button",{type:"button",onClick:()=>{ge(""),V(!1),ne("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:n("smartPlugs.none")}),dt.map(nt=>i.jsxs("button",{type:"button",onClick:()=>{ge(nt.entity_id),V(!1),ne("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${nt.entity_id===he?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[i.jsx("div",{className:"font-medium",children:nt.friendly_name}),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[nt.entity_id," • ",nt.state," ",nt.unit_of_measurement]})]},nt.entity_id)),dt.length===0&&i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:n("smartPlugs.noMatchingSensors")})]})]})})(),(()=>{const Me=Fe.filter(nt=>nt.unit_of_measurement==="kWh"||nt.unit_of_measurement==="Wh"||nt.unit_of_measurement==="MWh"),dt=W?Me.filter(nt=>nt.entity_id.toLowerCase().includes(W.toLowerCase())||nt.friendly_name.toLowerCase().includes(W.toLowerCase())):Me,ct=Fe.find(nt=>nt.entity_id===Y);return i.jsxs("div",{ref:ye,className:"relative",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.energyTodayKwh")}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),i.jsx("input",{type:"text",value:ue?W:ct?`${ct.friendly_name} (${ct.state} ${ct.unit_of_measurement})`:"",onChange:nt=>{re(nt.target.value),ue||fe(!0)},onFocus:()=>{fe(!0),re("")},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"}),Y&&!ue&&i.jsx("button",{type:"button",onClick:()=>{oe(""),re("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(Ht,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),ue&&i.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:[i.jsx("button",{type:"button",onClick:()=>{oe(""),fe(!1),re("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:n("smartPlugs.none")}),dt.map(nt=>i.jsxs("button",{type:"button",onClick:()=>{oe(nt.entity_id),fe(!1),re("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${nt.entity_id===Y?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[i.jsx("div",{className:"font-medium",children:nt.friendly_name}),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[nt.entity_id," • ",nt.state," ",nt.unit_of_measurement]})]},nt.entity_id)),dt.length===0&&i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:n("smartPlugs.noMatchingSensors")})]})]})})(),(()=>{const Me=Fe.filter(nt=>nt.unit_of_measurement==="kWh"||nt.unit_of_measurement==="Wh"||nt.unit_of_measurement==="MWh"),dt=ae?Me.filter(nt=>nt.entity_id.toLowerCase().includes(ae.toLowerCase())||nt.friendly_name.toLowerCase().includes(ae.toLowerCase())):Me,ct=Fe.find(nt=>nt.entity_id===le);return i.jsxs("div",{ref:ve,className:"relative",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.totalEnergyKwh")}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),i.jsx("input",{type:"text",value:F?ae:ct?`${ct.friendly_name} (${ct.state} ${ct.unit_of_measurement})`:"",onChange:nt=>{L(nt.target.value),F||te(!0)},onFocus:()=>{te(!0),L("")},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&&!F&&i.jsx("button",{type:"button",onClick:()=>{xe(""),L("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(Ht,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),F&&i.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:[i.jsx("button",{type:"button",onClick:()=>{xe(""),te(!1),L("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:n("smartPlugs.none")}),dt.map(nt=>i.jsxs("button",{type:"button",onClick:()=>{xe(nt.entity_id),te(!1),L("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${nt.entity_id===le?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[i.jsx("div",{className:"font-medium",children:nt.friendly_name}),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[nt.entity_id," • ",nt.state," ",nt.unit_of_measurement]})]},nt.entity_id)),dt.length===0&&i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:n("smartPlugs.noMatchingSensors")})]})]})})()]})]})]}),s==="mqtt"&&i.jsxs("div",{className:"space-y-3",children:[!Qe?.mqtt_broker&&i.jsxs("div",{className:"p-3 bg-yellow-500/20 border border-yellow-500/50 rounded-lg text-sm text-yellow-400",children:[n("smartPlugs.mqttNotConfigured")," ",i.jsx("span",{className:"font-medium",children:n("smartPlugs.mqttSettingsPath")})," ",n("smartPlugs.mqttNotConfiguredSuffix")]}),Qe?.mqtt_broker&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg text-sm text-blue-300",children:[i.jsx("p",{className:"font-medium mb-1",children:n("smartPlugs.monitorOnly")}),i.jsx("p",{className:"text-xs opacity-80",children:n("smartPlugs.mqttMonitorOnlyDescription")})]}),i.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-white font-medium text-sm",children:n("smartPlugs.powerMonitoring")}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.topic")}),i.jsx("input",{type:"text",value:g,onChange:Me=>_(Me.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"})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.jsonPath")}),i.jsx("input",{type:"text",value:N,onChange:Me=>T(Me.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.multiplier")}),i.jsx("input",{type:"text",value:C,onChange:Me=>A(Me.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"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",style:{whiteSpace:"pre-line"},children:n("smartPlugs.mqttPowerHint")})]}),i.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("p",{className:"text-white font-medium text-sm",children:[n("smartPlugs.energyMonitoring")," ",i.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",n("smartPlugs.optional"),")"]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.topic")}),i.jsx("input",{type:"text",value:k,onChange:Me=>R(Me.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"})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.jsonPath")}),i.jsx("input",{type:"text",value:P,onChange:Me=>D(Me.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.multiplier")}),i.jsx("input",{type:"text",value:H,onChange:Me=>z(Me.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"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",style:{whiteSpace:"pre-line"},children:n("smartPlugs.mqttEnergyHint")})]}),i.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("p",{className:"text-white font-medium text-sm",children:[n("smartPlugs.stateMonitoring")," ",i.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",n("smartPlugs.optional"),")"]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.topic")}),i.jsx("input",{type:"text",value:G,onChange:Me=>I(Me.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"})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.jsonPath")}),i.jsx("input",{type:"text",value:ee,onChange:Me=>ie(Me.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.onValue")}),i.jsx("input",{type:"text",value:X,onChange:Me=>me(Me.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"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",style:{whiteSpace:"pre-line"},children:n("smartPlugs.mqttStateHint")})]})]})]}),s==="tasmota"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.ipAddress")}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"text",value:u,onChange:Me=>{d(Me.target.value),Se(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"}),i.jsxs(Oe,{type:"button",variant:"secondary",onClick:()=>ke.mutate(),disabled:!u.trim()||ke.isPending,children:[ke.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Ub,{className:"w-4 h-4"}),n("smartPlugs.test")]})]})]}),s==="tasmota"&&Ne&&i.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${Ne.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:Ne.success?i.jsxs(i.Fragment,{children:[i.jsx(fr,{className:"w-5 h-5"}),i.jsxs("div",{children:[i.jsx("p",{className:"font-medium",children:n("smartPlugs.connectedResult")}),i.jsxs("p",{className:"text-sm opacity-80",children:[Ne.device_name&&n("smartPlugs.deviceLabel",{name:Ne.device_name}),n("smartPlugs.stateLabel",{state:Ne.state})]})]})]}):i.jsxs(i.Fragment,{children:[i.jsx(Ph,{className:"w-5 h-5"}),i.jsx("span",{children:n("smartPlugs.addSmartPlug.connectionFailed")})]})}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.nameLabel")}),i.jsx("input",{type:"text",value:l,onChange:Me=>c(Me.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"})]}),s==="tasmota"&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.username")}),i.jsx("input",{type:"text",value:m,onChange:Me=>p(Me.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.password")}),i.jsx("input",{type:"password",value:f,onChange:Me=>y(Me.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"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray -mt-2",children:n("smartPlugs.authHint")})]}),s!=="mqtt"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.linkToPrinter")}),i.jsxs("select",{value:pe??"",onChange:Me=>de(Me.target.value?Number(Me.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:[i.jsx("option",{value:"",children:n("smartPlugs.noPrinter")}),He?.map(Me=>i.jsx("option",{value:Me.id,children:Me.name},Me.id))]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("smartPlugs.linkingDescription")})]}),i.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(hh,{className:"w-4 h-4 text-bambu-green"}),i.jsx("span",{className:"text-white font-medium",children:n("smartPlugs.powerAlerts")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:Ee,onChange:Me=>Te(Me.target.checked),className:"sr-only peer"}),i.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"})]})]}),Ee&&i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.alertAbove")}),i.jsx("input",{type:"number",value:Ae,onChange:Me=>Be(Me.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.alertBelow")}),i.jsx("input",{type:"number",value:je,onChange:Me=>Xe(Me.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"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.alertDescription")})]})]}),s!=="mqtt"&&i.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(er,{className:"w-4 h-4 text-bambu-green"}),i.jsx("span",{className:"text-white font-medium",children:n("smartPlugs.dailySchedule")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:ce,onChange:Me=>Ie(Me.target.checked),className:"sr-only peer"}),i.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"})]})]}),ce&&i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.turnOnAt")}),i.jsx("input",{type:"time",value:Ce,onChange:Me=>Ge(Me.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.turnOffAt")}),i.jsx("input",{type:"time",value:$e,onChange:Me=>Ue(Me.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"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.scheduleDescription")})]})]}),i.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(pw,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white font-medium",children:n("smartPlugs.showInSwitchbar")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.quickAccessSidebar")})]})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:De,onChange:Me=>Ve(Me.target.checked),className:"sr-only peer"}),i.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"})]})]})}),s==="homeassistant"&&i.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(_c,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white font-medium",children:n("smartPlugs.showOnPrinterCard")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.displayOnPrinterCard")})]})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:it,onChange:Me=>xt(Me.target.checked),className:"sr-only peer"}),i.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.jsxs("div",{className:"flex gap-3 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:n("smartPlugs.cancel")}),i.jsxs(Oe,{type:"submit",disabled:Ye,className:"flex-1",children:[Ye?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(ts,{className:"w-4 h-4"}),n(a?"smartPlugs.save":"smartPlugs.add")]})]})]})]})})}function Bn({checked:t,onChange:e,disabled:n}){const r=a=>{a.preventDefault(),a.stopPropagation(),n||e(!t)};return i.jsx("button",{type:"button",role:"switch","aria-checked":t,disabled:n,onClick:r,className:`relative inline-flex w-11 h-7 md:w-9 md:h-5 rounded-full transition-colors flex-shrink-0 focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${n?"bg-bambu-dark-tertiary/50 cursor-not-allowed opacity-50":t?"bg-bambu-green cursor-pointer":"bg-bambu-dark-tertiary cursor-pointer hover:bg-bambu-dark-tertiary/80"}`,children:i.jsx("span",{className:`pointer-events-none absolute top-[3px] md:top-[2px] left-[3px] md:left-[2px] w-5 h-5 md:w-4 md:h-4 bg-white rounded-full shadow transition-transform duration-200 ease-in-out ${t?"translate-x-4":"translate-x-0"}`})})}function met({provider:t,onEdit:e}){const{t:n}=Ft(),r=an(),[a,s]=w.useState(!1),[o,l]=w.useState(!1),[c,u]=w.useState(null),{data:d}=et({queryKey:["printers"],queryFn:be.getPrinters}),m=d?.find(x=>x.id===t.printer_id),p=pt({mutationFn:x=>be.updateNotificationProvider(t.id,x),onSuccess:()=>{r.invalidateQueries({queryKey:["notification-providers"]})}}),f=pt({mutationFn:()=>be.deleteNotificationProvider(t.id),onSuccess:()=>{r.invalidateQueries({queryKey:["notification-providers"]})}}),y=pt({mutationFn:()=>be.testNotificationProvider(t.id),onSuccess:x=>{u(x),r.invalidateQueries({queryKey:["notification-providers"]})},onError:x=>{u({success:!1,message:x.message})}}),v=x=>x||"";return i.jsxs(i.Fragment,{children:[i.jsx(Mt,{className:"relative",children:i.jsxs(Dt,{className:"p-4",children:[i.jsxs("div",{className:"flex items-start justify-between mb-3",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:`p-2 rounded-lg ${t.enabled?"bg-bambu-green/20":"bg-bambu-dark"}`,children:i.jsx(hh,{className:`w-5 h-5 ${t.enabled?"text-bambu-green":"text-bambu-gray"}`})}),i.jsxs("div",{children:[i.jsx("h3",{className:"font-medium text-white",children:t.name}),i.jsx("p",{className:"text-sm text-bambu-gray",children:n(`notifications.providerTypes.${t.provider_type}`,t.provider_type)})]})]}),i.jsxs("div",{className:"flex items-center gap-3",children:[t.last_success&&i.jsx("span",{className:"text-xs text-status-ok hidden sm:inline",children:n("notifications.lastSuccess",{date:_f(t.last_success)})}),t.last_error&&t.last_error_at&&(!t.last_success||(Jn(t.last_error_at)?.getTime()||0)>(Jn(t.last_success)?.getTime()||0))&&i.jsx("span",{className:"text-xs text-status-error",title:t.last_error,children:n("notifications.error")}),i.jsx(Bn,{checked:t.enabled,onChange:x=>p.mutate({enabled:x})})]})]}),m&&i.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[i.jsxs("span",{className:"text-xs text-bambu-gray",children:[n("notifications.printer")," "]}),i.jsx("span",{className:"text-sm text-white",children:m.name})]}),!m&&!t.printer_id&&i.jsx("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:i.jsx("span",{className:"text-xs text-bambu-gray",children:n("notifications.allPrinters")})}),i.jsxs("div",{className:"mb-3 flex flex-wrap gap-1",children:[t.on_print_start&&i.jsx("span",{className:"px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded",children:n("notifications.start")}),t.on_plate_not_empty&&i.jsx("span",{className:"px-2 py-0.5 bg-rose-600/20 text-rose-300 text-xs rounded",children:n("notifications.plateCheck")}),t.on_print_complete&&i.jsx("span",{className:"px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded",children:n("notifications.complete")}),t.on_print_failed&&i.jsx("span",{className:"px-2 py-0.5 bg-red-500/20 text-red-400 text-xs rounded",children:n("notifications.failed")}),t.on_print_stopped&&i.jsx("span",{className:"px-2 py-0.5 bg-orange-500/20 text-orange-400 text-xs rounded",children:n("notifications.stopped")}),t.on_print_progress&&i.jsx("span",{className:"px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded",children:n("notifications.progress")}),t.on_printer_offline&&i.jsx("span",{className:"px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded",children:n("notifications.offline")}),t.on_printer_error&&i.jsx("span",{className:"px-2 py-0.5 bg-rose-500/20 text-rose-400 text-xs rounded",children:n("notifications.error")}),t.on_filament_low&&i.jsx("span",{className:"px-2 py-0.5 bg-cyan-500/20 text-cyan-400 text-xs rounded",children:n("notifications.lowFilament")}),t.on_maintenance_due&&i.jsx("span",{className:"px-2 py-0.5 bg-purple-500/20 text-purple-400 text-xs rounded",children:n("notifications.maintenance")}),t.on_ams_humidity_high&&i.jsx("span",{className:"px-2 py-0.5 bg-blue-600/20 text-blue-300 text-xs rounded",children:n("notifications.amsHumidity")}),t.on_ams_temperature_high&&i.jsx("span",{className:"px-2 py-0.5 bg-orange-600/20 text-orange-300 text-xs rounded",children:n("notifications.amsTemp")}),t.on_ams_ht_humidity_high&&i.jsx("span",{className:"px-2 py-0.5 bg-cyan-600/20 text-cyan-300 text-xs rounded",children:n("notifications.amsHtHumidity")}),t.on_ams_ht_temperature_high&&i.jsx("span",{className:"px-2 py-0.5 bg-amber-600/20 text-amber-300 text-xs rounded",children:n("notifications.amsHtTemp")}),t.on_bed_cooled&&i.jsx("span",{className:"px-2 py-0.5 bg-teal-500/20 text-teal-400 text-xs rounded",children:n("notifications.bedCooled")}),t.on_first_layer_complete&&i.jsx("span",{className:"px-2 py-0.5 bg-emerald-600/20 text-emerald-300 text-xs rounded",children:n("notifications.firstLayer")}),t.quiet_hours_enabled&&i.jsxs("span",{className:"px-2 py-0.5 bg-indigo-500/20 text-indigo-400 text-xs rounded flex items-center gap-1",children:[i.jsx(DN,{className:"w-3 h-3"}),n("notifications.quiet")]}),t.daily_digest_enabled&&i.jsxs("span",{className:"px-2 py-0.5 bg-emerald-500/20 text-emerald-400 text-xs rounded flex items-center gap-1",children:[i.jsx(Wr,{className:"w-3 h-3"}),n("notifications.digest",{time:t.daily_digest_time})]})]}),i.jsx("div",{className:"mb-3",children:i.jsxs(Oe,{size:"sm",variant:"secondary",disabled:y.isPending,onClick:()=>{u(null),y.mutate()},className:"w-full",children:[y.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(rT,{className:"w-4 h-4"}),n("notifications.sendTestNotification")]})}),c&&i.jsxs("div",{className:`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${c.success?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:[c.success?i.jsx(fr,{className:"w-4 h-4"}):i.jsx(Vi,{className:"w-4 h-4"}),i.jsx("span",{children:c.message})]}),i.jsxs("button",{onClick:()=>l(!o),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors border-t border-bambu-dark-tertiary",children:[i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(jd,{className:"w-4 h-4"}),n("notifications.eventSettings")]}),o?i.jsx(Il,{className:"w-4 h-4"}):i.jsx(Ln,{className:"w-4 h-4"})]}),o&&i.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.enabled")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.sendFromProvider")})]}),i.jsx(Bn,{checked:t.enabled,onChange:x=>p.mutate({enabled:x})})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.printEvents")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.printStarted")}),i.jsx(Bn,{checked:t.on_print_start,onChange:x=>p.mutate({on_print_start:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.plateNotEmpty")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.plateNotEmptyDescription")})]}),i.jsx(Bn,{checked:t.on_plate_not_empty??!0,onChange:x=>p.mutate({on_plate_not_empty:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.printCompleted")}),i.jsx(Bn,{checked:t.on_print_complete,onChange:x=>p.mutate({on_print_complete:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.bedCooledLabel")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.bedCooledDescription")})]}),i.jsx(Bn,{checked:t.on_bed_cooled??!1,onChange:x=>p.mutate({on_bed_cooled:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.firstLayerCompleteLabel")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.firstLayerCompleteDescription")})]}),i.jsx(Bn,{checked:t.on_first_layer_complete??!1,onChange:x=>p.mutate({on_first_layer_complete:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.printFailed")}),i.jsx(Bn,{checked:t.on_print_failed,onChange:x=>p.mutate({on_print_failed:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.printStopped")}),i.jsx(Bn,{checked:t.on_print_stopped,onChange:x=>p.mutate({on_print_stopped:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.progressMilestones")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.progressMilestonesDescription")})]}),i.jsx(Bn,{checked:t.on_print_progress,onChange:x=>p.mutate({on_print_progress:x})})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.printerStatus")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.printerOffline")}),i.jsx(Bn,{checked:t.on_printer_offline,onChange:x=>p.mutate({on_printer_offline:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.printerError")}),i.jsx(Bn,{checked:t.on_printer_error,onChange:x=>p.mutate({on_printer_error:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.lowFilamentLabel")}),i.jsx(Bn,{checked:t.on_filament_low,onChange:x=>p.mutate({on_filament_low:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.maintenanceDue")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.maintenanceDueDescription")})]}),i.jsx(Bn,{checked:t.on_maintenance_due??!1,onChange:x=>p.mutate({on_maintenance_due:x})})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.amsAlarms")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.amsHumidityHigh")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.amsHumidityHighDescription")})]}),i.jsx(Bn,{checked:t.on_ams_humidity_high??!1,onChange:x=>p.mutate({on_ams_humidity_high:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.amsTemperatureHigh")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.amsTemperatureHighDescription")})]}),i.jsx(Bn,{checked:t.on_ams_temperature_high??!1,onChange:x=>p.mutate({on_ams_temperature_high:x})})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.amsHtAlarms")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.amsHtHumidityHigh")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.amsHtHumidityHighDescription")})]}),i.jsx(Bn,{checked:t.on_ams_ht_humidity_high??!1,onChange:x=>p.mutate({on_ams_ht_humidity_high:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.amsHtTemperatureHigh")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.amsHtTemperatureHighDescription")})]}),i.jsx(Bn,{checked:t.on_ams_ht_temperature_high??!1,onChange:x=>p.mutate({on_ams_ht_temperature_high:x})})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.printQueue")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.jobAdded")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobAddedDescription")})]}),i.jsx(Bn,{checked:t.on_queue_job_added??!1,onChange:x=>p.mutate({on_queue_job_added:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.jobAssigned")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobAssignedDescription")})]}),i.jsx(Bn,{checked:t.on_queue_job_assigned??!1,onChange:x=>p.mutate({on_queue_job_assigned:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.jobStarted")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobStartedDescription")})]}),i.jsx(Bn,{checked:t.on_queue_job_started??!1,onChange:x=>p.mutate({on_queue_job_started:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.jobWaiting")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobWaitingDescription")})]}),i.jsx(Bn,{checked:t.on_queue_job_waiting??!0,onChange:x=>p.mutate({on_queue_job_waiting:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.jobSkipped")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobSkippedDescription")})]}),i.jsx(Bn,{checked:t.on_queue_job_skipped??!0,onChange:x=>p.mutate({on_queue_job_skipped:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.jobFailed")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobFailedDescription")})]}),i.jsx(Bn,{checked:t.on_queue_job_failed??!0,onChange:x=>p.mutate({on_queue_job_failed:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.queueComplete")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.queueCompleteDescription")})]}),i.jsx(Bn,{checked:t.on_queue_completed??!1,onChange:x=>p.mutate({on_queue_completed:x})})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(DN,{className:"w-4 h-4 text-purple-400"}),i.jsx("p",{className:"text-sm text-white",children:n("notifications.quietHours")})]}),i.jsx(Bn,{checked:t.quiet_hours_enabled,onChange:x=>p.mutate({quiet_hours_enabled:x})})]}),t.quiet_hours_enabled&&i.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.noNotificationsDuring")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(er,{className:"w-4 h-4 text-bambu-gray"}),i.jsxs("span",{className:"text-sm text-white",children:[v(t.quiet_hours_start)||"22:00"," - ",v(t.quiet_hours_end)||"07:00"]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.editProviderToChangeQuietHours")})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Wr,{className:"w-4 h-4 text-emerald-400"}),i.jsx("p",{className:"text-sm text-white",children:n("notifications.dailyDigest")})]}),i.jsx(Bn,{checked:t.daily_digest_enabled,onChange:x=>p.mutate({daily_digest_enabled:x})})]}),t.daily_digest_enabled&&i.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.batchNotifications")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(er,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"text-sm text-white",children:n("notifications.sendAt",{time:v(t.daily_digest_time)||"08:00"})})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.editProviderToChangeDigestTime")})]})]}),i.jsxs("div",{className:"flex gap-2 pt-2",children:[i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[i.jsx(nh,{className:"w-4 h-4"}),n("notifications.edit")]}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:()=>s(!0),className:"text-red-400 hover:text-red-300",children:i.jsx(Jt,{className:"w-4 h-4"})})]})]})]})}),a&&i.jsx(Sn,{title:n("notifications.deleteProvider"),message:n("notifications.deleteConfirm",{name:t.name}),confirmText:n("notifications.delete"),variant:"danger",onConfirm:()=>{f.mutate(),s(!1)},onCancel:()=>s(!1)})]})}const het=["email","telegram","discord","ntfy","pushover","callmebot","webhook","homeassistant"];function pet({provider:t,onClose:e}){const{t:n}=Ft(),r=an(),a=!!t,[s,o]=w.useState(t?.name||""),[l,c]=w.useState(t?.provider_type||"email"),[u,d]=w.useState(t?.printer_id||null),[m,p]=w.useState(t?.quiet_hours_enabled||!1),[f,y]=w.useState(t?.quiet_hours_start||"22:00"),[v,x]=w.useState(t?.quiet_hours_end||"07:00"),[g,_]=w.useState(t?.daily_digest_enabled||!1),[N,T]=w.useState(t?.daily_digest_time||"08:00"),[C,A]=w.useState(t?.on_print_start??!1),[k,R]=w.useState(t?.on_print_complete??!0),[P,D]=w.useState(t?.on_print_failed??!0),[H,z]=w.useState(t?.on_print_stopped??!0),[G,I]=w.useState(t?.on_print_progress??!1),[ee,ie]=w.useState(t?.on_printer_offline??!1),[X,me]=w.useState(t?.on_printer_error??!1),[he,ge]=w.useState(t?.on_filament_low??!1),[Y,oe]=w.useState(t?.on_maintenance_due??!1),[le,xe]=w.useState(t?.on_bed_cooled??!1),[Pe,q]=w.useState(t?.on_first_layer_complete??!1),[Z,j]=w.useState(t?.config?Object.fromEntries(Object.entries(t.config).map(([ae,L])=>[ae,String(L)])):{}),[E,U]=w.useState(null),[K,$]=w.useState(null),{data:ne}=et({queryKey:["printers"],queryFn:be.getPrinters});w.useEffect(()=>{const ae=L=>{L.key==="Escape"&&e()};return window.addEventListener("keydown",ae),()=>window.removeEventListener("keydown",ae)},[e]);const O=pt({mutationFn:()=>be.testNotificationConfig({provider_type:l,config:Z}),onSuccess:ae=>{U(ae),$(null)},onError:ae=>{U({success:!1,message:ae.message})}}),V=pt({mutationFn:ae=>be.createNotificationProvider(ae),onSuccess:()=>{r.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:ae=>{$(ae.message)}}),J=pt({mutationFn:ae=>be.updateNotificationProvider(t.id,ae),onSuccess:()=>{r.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:ae=>{$(ae.message)}}),W=ae=>{if(ae.preventDefault(),$(null),!s.trim()){$(n("notifications.nameRequired"));return}const L=fe(l);for(const te of L)if(!Z[te.key]?.trim()){$(n("notifications.fieldRequired",{field:te.label}));return}const F={name:s.trim(),provider_type:l,config:Z,printer_id:u,quiet_hours_enabled:m,quiet_hours_start:m?f:null,quiet_hours_end:m?v:null,daily_digest_enabled:g,daily_digest_time:g?N:null,on_print_start:C,on_print_complete:k,on_print_failed:P,on_print_stopped:H,on_print_progress:G,on_printer_offline:ee,on_printer_error:X,on_filament_low:he,on_maintenance_due:Y,on_bed_cooled:le,on_first_layer_complete:Pe};a?J.mutate(F):V.mutate(F)},re=V.isPending||J.isPending,ue=ae=>{switch(ae){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}];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}];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:L=>L.payload_format!=="slack"},{key:"field_message",label:"Message Field Name",placeholder:"message",type:"text",required:!1,showIf:L=>L.payload_format!=="slack"}];case"homeassistant":return[];default:return[]}},fe=ae=>ue(ae).filter(L=>L.required),ye=ue(l);return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto",onClick:e,children:i.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:ae=>ae.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:n(a?"notifications.editTitle":"notifications.addTitle")}),i.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:W,className:"p-6 space-y-4",children:[K&&i.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:K}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("notifications.nameLabel")}),i.jsx("input",{type:"text",value:s,onChange:ae=>o(ae.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("notifications.providerTypeLabel")}),i.jsx("select",{value:l,onChange:ae=>{c(ae.target.value),j({}),U(null)},disabled:a,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:het.map(ae=>i.jsx("option",{value:ae,children:n(`notifications.providerTypes.${ae}`,ae)},ae))}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n(`notifications.providerDescriptions.${l}`,"")})]}),i.jsxs("div",{className:"space-y-3",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:n("notifications.configuration")}),ye.filter(ae=>!("showIf"in ae)||ae.showIf?.(Z)!==!1).map(ae=>i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[ae.label," ",ae.required&&"*"]}),ae.type==="select"&&"options"in ae&&ae.options?i.jsx("select",{value:Z[ae.key]||ae.options[0]?.value||"",onChange:L=>{j({...Z,[ae.key]:L.target.value}),U(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:ae.options.map(L=>i.jsx("option",{value:L.value,children:L.label},L.value))}):i.jsx("input",{type:ae.type,value:Z[ae.key]||"",onChange:L=>{j({...Z,[ae.key]:L.target.value}),U(null)},placeholder:ae.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"})]},ae.key))]}),i.jsx("div",{className:"flex gap-2",children:i.jsxs(Oe,{type:"button",variant:"secondary",onClick:()=>{U(null),O.mutate()},disabled:O.isPending||fe(l).length>0&&!Z[fe(l)[0]?.key],className:"flex-1",children:[O.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(rT,{className:"w-4 h-4"}),n("notifications.testConfiguration")]})}),E&&i.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${E.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:E.success?i.jsxs(i.Fragment,{children:[i.jsx(fr,{className:"w-5 h-5"}),i.jsx("span",{children:E.message})]}):i.jsxs(i.Fragment,{children:[i.jsx(Vi,{className:"w-5 h-5"}),i.jsx("span",{children:E.message})]})}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("notifications.printerFilter")}),i.jsxs("select",{value:u??"",onChange:ae=>d(ae.target.value?Number(ae.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:[i.jsx("option",{value:"",children:n("notifications.allPrinters")}),ne?.map(ae=>i.jsx("option",{value:ae.id,children:ae.name},ae.id))]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("notifications.onlyFromPrinter")})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("label",{className:"text-sm text-white",children:n("notifications.quietHoursDnd")}),i.jsx(Bn,{checked:m,onChange:p})]}),m&&i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("notifications.quietStart")}),i.jsx("input",{type:"time",value:f,onChange:ae=>y(ae.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("notifications.quietEnd")}),i.jsx("input",{type:"time",value:v,onChange:ae=>x(ae.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"})]})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("label",{className:"text-sm text-white",children:n("notifications.dailyDigestLabel")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.batchNotifications")})]}),i.jsx(Bn,{checked:g,onChange:_})]}),g&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("notifications.sendDigestAt")}),i.jsx("input",{type:"time",value:N,onChange:ae=>T(ae.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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("notifications.digestCollected")})]})]}),i.jsxs("div",{className:"space-y-3",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:n("notifications.notificationEvents")}),i.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:n("notifications.printEvents")}),i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.start")}),i.jsx(Bn,{checked:C,onChange:A})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.complete")}),i.jsx(Bn,{checked:k,onChange:R})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.failed")}),i.jsx(Bn,{checked:P,onChange:D})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.stopped")}),i.jsx(Bn,{checked:H,onChange:z})]}),i.jsxs("div",{className:"flex items-center justify-between col-span-2",children:[i.jsxs("div",{children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.progress")}),i.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:n("notifications.progressPercent")})]}),i.jsx(Bn,{checked:G,onChange:I})]}),i.jsxs("div",{className:"flex items-center justify-between col-span-2",children:[i.jsxs("div",{children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.bedCooled")}),i.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:n("notifications.bedCooledAfterPrint")})]}),i.jsx(Bn,{checked:le,onChange:xe})]}),i.jsxs("div",{className:"flex items-center justify-between col-span-2",children:[i.jsxs("div",{children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.firstLayerCompleteLabel")}),i.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:n("notifications.firstLayerCompleteDescription")})]}),i.jsx(Bn,{checked:Pe,onChange:q})]})]})]}),i.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:n("notifications.printerStatus")}),i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.offline")}),i.jsx(Bn,{checked:ee,onChange:ie})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.error")}),i.jsx(Bn,{checked:X,onChange:me})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.lowFilament")}),i.jsx(Bn,{checked:he,onChange:ge})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.maintenance")}),i.jsx(Bn,{checked:Y,onChange:oe})]})]})]})]}),i.jsxs("div",{className:"flex gap-3 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:n("notifications.cancel")}),i.jsxs(Oe,{type:"submit",disabled:re,className:"flex-1",children:[re?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(ts,{className:"w-4 h-4"}),n(a?"notifications.save":"notifications.add")]})]})]})]})})}function fet({template:t,onClose:e}){const{t:n}=Ft(),r=an(),a=w.useRef(null),[s,o]=w.useState(t.title_template),[l,c]=w.useState(t.body_template),[u,d]=w.useState(null),[m,p]=w.useState(!0),{data:f}=et({queryKey:["template-variables"],queryFn:be.getTemplateVariables}),y=f?.find(A=>A.event_type===t.event_type),{data:v,isLoading:x}=et({queryKey:["template-preview",t.event_type,s,l],queryFn:()=>be.previewTemplate({event_type:t.event_type,title_template:s,body_template:l}),enabled:m&&s.length>0&&l.length>0});w.useEffect(()=>{const A=k=>{k.key==="Escape"&&e()};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[e]);const g=pt({mutationFn:A=>be.updateNotificationTemplate(t.id,A),onSuccess:()=>{r.invalidateQueries({queryKey:["notification-templates"]}),e()},onError:A=>{d(A.message)}}),_=pt({mutationFn:()=>be.resetNotificationTemplate(t.id),onSuccess:A=>{o(A.title_template),c(A.body_template),r.invalidateQueries({queryKey:["notification-templates"]})},onError:A=>{d(A.message)}}),N=A=>{if(A.preventDefault(),d(null),!s.trim()){d(n("notifications.titleRequired"));return}if(!l.trim()){d(n("notifications.bodyRequired"));return}g.mutate({title_template:s,body_template:l})},T=A=>{const k=a.current;if(!k)return;const R=k.selectionStart,P=k.selectionEnd,D=l,H=D.substring(0,R),z=D.substring(P),G=H+`{${A}}`+z;c(G),setTimeout(()=>{k.focus();const I=R+A.length+2;k.setSelectionRange(I,I)},0)},C=s!==t.title_template||l!==t.body_template;return i.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:n("notifications.editTemplate",{name:t.name})}),i.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",children:i.jsx(Ht,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsxs("form",{onSubmit:N,className:"flex-1 overflow-y-auto p-4 space-y-4",children:[u&&i.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded text-red-400 text-sm",children:u}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:n("notifications.titleLabel")}),i.jsx("input",{type:"text",value:s,onChange:A=>o(A.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")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:n("notifications.bodyLabel")}),i.jsx("textarea",{ref:a,value:l,onChange:A=>c(A.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&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-2",children:n("notifications.availableVariables")}),i.jsx("div",{className:"flex flex-wrap gap-2",children:y.variables.map(A=>i.jsxs("button",{type:"button",onClick:()=>T(A),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:[i.jsx(ar,{className:"w-3 h-3"}),A]},A))}),i.jsx("p",{className:"text-xs text-bambu-gray/60 mt-1",children:n("notifications.clickToInsert")})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("label",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[i.jsx(_c,{className:"w-4 h-4"}),n("notifications.livePreview")]}),i.jsx("button",{type:"button",onClick:()=>p(!m),className:"text-xs text-bambu-green hover:text-bambu-green-light",children:n(m?"notifications.hide":"notifications.show")})]}),m&&i.jsx("div",{className:"bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2",children:x?i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-sm",children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),n("notifications.loadingPreview")]}):v?i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:n("notifications.titlePreview")}),i.jsx("div",{className:"text-white font-medium",children:v.title})]}),i.jsxs("div",{children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:n("notifications.bodyPreview")}),i.jsx("div",{className:"text-white whitespace-pre-wrap text-sm",children:v.body})]})]}):i.jsx("div",{className:"text-bambu-gray text-sm",children:n("notifications.enterTemplateContent")})})]})]}),i.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[i.jsxs(Oe,{type:"button",variant:"ghost",onClick:()=>_.mutate(),disabled:_.isPending,className:"text-orange-400 hover:text-orange-300",children:[_.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin mr-2"}):i.jsx(bo,{className:"w-4 h-4 mr-2"}),n("notifications.resetToDefault")]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,children:n("notifications.cancel")}),i.jsxs(Oe,{onClick:N,disabled:g.isPending||!C,children:[g.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin mr-2"}):i.jsx(ts,{className:"w-4 h-4 mr-2"}),n("notifications.save")]})]})]})]})})}const get={print_start:"text-blue-400",print_complete:"text-bambu-green",print_failed:"text-red-400",print_stopped:"text-orange-400",print_progress:"text-yellow-400",printer_offline:"text-gray-400",printer_error:"text-rose-400",filament_low:"text-cyan-400",maintenance_due:"text-purple-400",test:"text-bambu-gray"};function bet({onClose:t}){const{t:e}=Ft(),n=an(),{showToast:r}=fn(),[a,s]=w.useState(7),[o,l]=w.useState(null),[c,u]=w.useState(!1),{data:d}=et({queryKey:["settings"],queryFn:be.getSettings}),m=d?.time_format||"system",{data:p,isLoading:f,refetch:y,isRefetching:v}=et({queryKey:["notification-logs",a,c],queryFn:()=>be.getNotificationLogs({days:a,limit:100,success:c?!1:void 0})}),{data:x}=et({queryKey:["notification-log-stats",a],queryFn:()=>be.getNotificationLogStats(a)}),g=pt({mutationFn:()=>be.clearNotificationLogs(30),onSuccess:N=>{r(N.message,"success"),n.invalidateQueries({queryKey:["notification-logs"]}),n.invalidateQueries({queryKey:["notification-log-stats"]})},onError:N=>{r(`Failed to clear logs: ${N.message}`,"error")}}),_=N=>{const T=Jn(N);if(!T)return"";const A=new Date().getTime()-T.getTime();return A<6e4?e("notifications.justNow"):A<36e5?`${Math.floor(A/6e4)}m ago`:A<864e5?`${Math.floor(A/36e5)}h ago`:T.toLocaleDateString()+" "+lQ(T,m)};return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:i.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:[i.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx(f0,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:e("notifications.notificationLog")})]}),i.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white transition-colors",children:"×"})]}),x&&i.jsx("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50",children:i.jsxs("div",{className:"flex items-center gap-6 text-sm",children:[i.jsxs("span",{className:"text-bambu-gray",children:[e("notifications.statsSummary",{days:a})," ",i.jsx("span",{className:"text-white font-medium",children:x.total})," ",e("notifications.statsNotifications")]}),i.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[i.jsx(fr,{className:"w-4 h-4"}),e("notifications.statsSent",{count:x.success_count})]}),x.failure_count>0&&i.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[i.jsx(Vi,{className:"w-4 h-4"}),e("notifications.statsFailed",{count:x.failure_count})]})]})}),i.jsxs("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4",children:[i.jsxs("select",{value:a,onChange:N=>s(Number(N.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:[i.jsx("option",{value:1,children:e("notifications.last24Hours")}),i.jsx("option",{value:7,children:e("notifications.last7Days")}),i.jsx("option",{value:30,children:e("notifications.last30Days")}),i.jsx("option",{value:90,children:e("notifications.last90Days")})]}),i.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:c,onChange:N=>u(N.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),e("notifications.showFailedOnly")]}),i.jsx("div",{className:"flex-1"}),i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>y(),disabled:v,children:[v?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(wr,{className:"w-4 h-4"}),e("notifications.refresh")]}),i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>g.mutate(),disabled:g.isPending,className:"text-red-400 hover:text-red-300",children:[g.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Jt,{className:"w-4 h-4"}),e("notifications.clearOld")]})]}),i.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:f?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})}):p&&p.length>0?i.jsx("div",{className:"space-y-2",children:p.map(N=>i.jsx(xet,{log:N,isExpanded:o===N.id,onToggle:()=>l(o===N.id?null:N.id),formatDate:_,formatFullDate:T=>Nf(T,m)},N.id))}):i.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[i.jsx(f0,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),i.jsx("p",{className:"text-sm",children:e(c?"notifications.noFailedNotifications":"notifications.noNotificationsLogged")})]})})]})})}function xet({log:t,isExpanded:e,onToggle:n,formatDate:r,formatFullDate:a}){const{t:s}=Ft();return i.jsxs("div",{className:`border rounded-lg overflow-hidden transition-colors ${t.success?"border-bambu-dark-tertiary bg-bambu-dark/30":"border-red-500/30 bg-red-500/5"}`,children:[i.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:[t.success?i.jsx(fr,{className:"w-4 h-4 text-bambu-green shrink-0"}):i.jsx(Vi,{className:"w-4 h-4 text-red-400 shrink-0"}),i.jsx("span",{className:`text-xs font-medium ${get[t.event_type]||"text-bambu-gray"}`,children:s(`notifications.eventTypes.${t.event_type}`,t.event_type)}),i.jsx("span",{className:"text-sm text-white truncate flex-1",children:t.provider_name||s("notifications.unknownProvider")}),t.printer_name&&i.jsx("span",{className:"text-xs text-bambu-gray",children:t.printer_name}),i.jsx("span",{className:"text-xs text-bambu-gray shrink-0",children:r(t.created_at)}),e?i.jsx(Il,{className:"w-4 h-4 text-bambu-gray shrink-0"}):i.jsx(Ln,{className:"w-4 h-4 text-bambu-gray shrink-0"})]}),e&&i.jsxs("div",{className:"px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:s("notifications.logTitle")}),i.jsx("p",{className:"text-sm text-white",children:t.title})]}),i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:s("notifications.logMessage")}),i.jsx("p",{className:"text-sm text-white whitespace-pre-wrap",children:t.message})]}),!t.success&&t.error_message&&i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-red-400 mb-1",children:s("notifications.logError")}),i.jsx("p",{className:"text-sm text-red-300",children:t.error_message})]}),i.jsxs("div",{className:"flex gap-4 text-xs text-bambu-gray pt-1",children:[i.jsx("span",{children:s("notifications.logProvider",{type:t.provider_type})}),i.jsx("span",{children:s("notifications.logTime",{time:a(t.created_at)})})]})]})]})}function yet({formData:t,setFormData:e,groups:n,onClose:r,onCreate:a,isCreating:s,isCreateButtonDisabled:o}){const{t:l}=Ft();w.useEffect(()=>{const u=d=>{d.key==="Escape"&&r()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[r]);const c=u=>{e({...t,group_ids:t.group_ids.includes(u)?t.group_ids.filter(d=>d!==u):[...t.group_ids,u]})};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:r,children:i.jsxs(Mt,{className:"w-full max-w-md",onClick:u=>u.stopPropagation(),children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Km,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:l("users.modal.createUser")})]}),i.jsx("p",{className:"text-sm text-bambu-gray ml-7",children:l("users.modal.advancedAuthSubtitle")||"with Advanced Authentication"})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:r,children:i.jsx(Ht,{className:"w-5 h-5"})})]})}),i.jsxs(Dt,{children:[i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[l("users.form.username")," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsx("input",{type:"text",value:t.username,onChange:u=>e({...t,username:u.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:l("users.form.usernamePlaceholder"),autoComplete:"username",required:!0})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[l("users.form.email")||"Email"," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsx("input",{type:"email",value:t.email,onChange:u=>e({...t,email:u.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:l("users.form.emailPlaceholder")||"user@example.com",required:!0})]}),i.jsx("div",{className:"bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3",children:i.jsx("p",{className:"text-sm text-bambu-gray",children:l("users.form.autoGeneratedPassword")||"A secure password will be automatically generated and emailed to the user."})}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:l("users.form.groups")}),i.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(u=>i.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:t.group_ids.includes(u.id),onChange:()=>c(u.id),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark"}),i.jsx("span",{className:"text-sm text-white",children:u.name}),u.is_system&&i.jsxs("span",{className:"text-xs text-yellow-400",children:["(",l("users.system"),")"]})]},u.id)),n.length===0&&i.jsx("p",{className:"text-sm text-bambu-gray",children:l("users.noGroupsAvailable")})]})]})]}),i.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:r,children:l("users.modal.cancel")}),i.jsx(Oe,{onClick:a,disabled:o,children:s?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),l("users.modal.creating")]}):i.jsxs(i.Fragment,{children:[i.jsx(ar,{className:"w-4 h-4"}),l("users.modal.createUser")]})})]})]})]})})}function vet(){const{t}=Ft(),e=an(),{showToast:n}=fn(),[r,a]=w.useState(!1),[s,o]=w.useState(""),[l,c]=w.useState("auto"),[u,d]=w.useState(!1),[m,p]=w.useState(!0),[f,y]=w.useState("all"),[v,x]=w.useState(!1),[g,_]=w.useState(!1),[N,T]=w.useState(!1),{data:C,isLoading:A}=et({queryKey:["spoolman-settings"],queryFn:be.getSpoolmanSettings}),{data:k,isLoading:R,refetch:P}=et({queryKey:["spoolman-status"],queryFn:be.getSpoolmanStatus,refetchInterval:3e4}),{data:D}=et({queryKey:["printers"],queryFn:be.getPrinters});w.useEffect(()=>{C&&(a(C.spoolman_enabled==="true"),o(C.spoolman_url||""),c(C.spoolman_sync_mode||"auto"),d(C.spoolman_disable_weight_sync==="true"),p(C.spoolman_report_partial_usage!=="false"),x(!0))},[C]),w.useEffect(()=>{if(!v||!C)return;if(C.spoolman_enabled==="true"!==r||(C.spoolman_url||"")!==s||(C.spoolman_sync_mode||"auto")!==l||C.spoolman_disable_weight_sync==="true"!==u||C.spoolman_report_partial_usage!=="false"!==m){const oe=setTimeout(()=>{H.mutate()},500);return()=>clearTimeout(oe)}},[r,s,l,u,m,v]);const H=pt({mutationFn:()=>be.updateSpoolmanSettings({spoolman_enabled:r?"true":"false",spoolman_url:s,spoolman_sync_mode:l,spoolman_disable_weight_sync:u?"true":"false",spoolman_report_partial_usage:m?"true":"false"}),onSuccess:()=>{e.invalidateQueries({queryKey:["spoolman-settings"]}),e.invalidateQueries({queryKey:["spoolman-status"]}),e.invalidateQueries({queryKey:["spool-assignments"]}),e.invalidateQueries({queryKey:["settings"]}),n(t("settings.toast.settingsSaved"))}}),z=pt({mutationFn:be.connectSpoolman,onSuccess:()=>{P()}}),G=pt({mutationFn:be.disconnectSpoolman,onSuccess:()=>{P()}}),I=pt({mutationFn:be.syncAllPrintersAms,onSuccess:Y=>{Y.success}}),ee=pt({mutationFn:Y=>be.syncPrinterAms(Y),onSuccess:Y=>{Y.success}}),ie=()=>{f==="all"?I.mutate():ee.mutate(f)},X=pt({mutationFn:be.syncWeightsFromAms,onSuccess:Y=>{e.invalidateQueries({queryKey:["spools"]}),e.invalidateQueries({queryKey:["inventory-spools"]}),n(t("settings.amsSyncSuccess",{synced:Y.synced,skipped:Y.skipped}),"success"),T(!1)},onError:()=>{n(t("settings.amsSyncError"),"error"),T(!1)}}),me=I.isPending||ee.isPending,he=f==="all"?I.data:ee.data,ge=f==="all"?I.isSuccess:ee.isSuccess;return A?i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(au,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.filamentTracking")})]})}),i.jsx(Dt,{children:i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})})})]}):i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(au,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.filamentTracking")})]}),H.isPending&&i.jsx(ht,{className:"w-4 h-4 text-bambu-green animate-spin"})]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:t("settings.filamentTrackingDesc")}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("button",{type:"button",onClick:()=>a(!1),className:`p-3 rounded-lg border-2 text-left transition-colors ${r?"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50":"border-bambu-green bg-bambu-green/10"}`,children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[i.jsx(Wi,{className:`w-4 h-4 ${r?"text-bambu-gray":"text-bambu-green"}`}),i.jsx("span",{className:`text-sm font-medium ${r?"text-bambu-gray":"text-white"}`,children:t("settings.trackingModeBuiltIn")})]}),i.jsx("p",{className:`text-xs ${r?"text-bambu-gray/60":"text-bambu-gray"}`,children:t("settings.trackingModeBuiltInDesc")}),!r&&i.jsxs("div",{className:"flex items-center gap-1 mt-2",children:[i.jsx(Yr,{className:"w-3 h-3 text-bambu-green"}),i.jsx("span",{className:"text-xs text-bambu-green",children:t("common.enabled")})]})]}),i.jsxs("button",{type:"button",onClick:()=>a(!0),className:`p-3 rounded-lg border-2 text-left transition-colors ${r?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50"}`,children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[i.jsx(Jr,{className:`w-4 h-4 ${r?"text-bambu-green":"text-bambu-gray"}`}),i.jsx("span",{className:`text-sm font-medium ${r?"text-white":"text-bambu-gray"}`,children:"Spoolman"})]}),i.jsx("p",{className:`text-xs ${r?"text-bambu-gray":"text-bambu-gray/60"}`,children:t("settings.trackingModeSpoolmanDesc")}),r&&i.jsxs("div",{className:"flex items-center gap-1 mt-2",children:[i.jsx(Yr,{className:"w-3 h-3 text-bambu-green"}),i.jsx("span",{className:"text-xs text-bambu-green",children:t("common.enabled")})]})]})]}),!r&&i.jsxs("div",{className:"space-y-3",children:[i.jsx("div",{className:"p-3 bg-bambu-green/5 border border-bambu-green/20 rounded-lg",children:i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ls,{className:"w-4 h-4 text-bambu-green flex-shrink-0 mt-0.5"}),i.jsx("div",{className:"text-xs text-bambu-gray",children:i.jsxs("ul",{className:"list-disc list-inside space-y-0.5",children:[i.jsx("li",{children:t("settings.builtInFeatureRfid")}),i.jsx("li",{children:t("settings.builtInFeatureUsage")}),i.jsx("li",{children:t("settings.builtInFeatureCatalog")}),i.jsx("li",{children:t("settings.builtInFeatureThirdParty")})]})})]})}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>T(!0),disabled:X.isPending,children:[X.isPending?i.jsx(ht,{className:"w-4 h-4 mr-2 animate-spin"}):i.jsx(wr,{className:"w-4 h-4 mr-2"}),t("settings.amsSyncButton")]})]}),r&&i.jsxs("div",{className:"space-y-4",children:[i.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ls,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),i.jsxs("div",{className:"text-xs text-blue-300",children:[i.jsx("p",{className:"font-medium mb-1",children:t("settings.howSyncWorks")}),i.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-blue-300/80",children:[i.jsx("li",{children:t("settings.syncInfoRfidOnly")}),i.jsx("li",{children:t("settings.syncInfoAutoCreate")}),i.jsx("li",{children:t("settings.syncInfoThirdPartySkipped")})]}),i.jsx("p",{className:"font-medium mt-2 mb-1",children:t("settings.linkingExistingSpools")}),i.jsx("p",{className:"text-blue-300/80",children:t("settings.linkingExistingSpoolsDesc")})]})]})}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("settings.spoolmanUrl")}),i.jsx("input",{type:"text",placeholder:"http://192.168.1.100:7912",value:s,onChange:Y=>o(Y.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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("settings.spoolmanUrlHint")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("settings.syncMode")}),i.jsxs("select",{value:l,onChange:Y=>c(Y.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:[i.jsx("option",{value:"auto",children:t("settings.syncModeAuto")}),i.jsx("option",{value:"manual",children:t("settings.syncModeManual")})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t(l==="auto"?"settings.syncModeAutoDesc":"settings.syncModeManualDesc")})]}),l==="auto"&&i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:t("spoolman.disableWeightSync")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t("spoolman.disableWeightSyncDesc")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:u,onChange:Y=>d(Y.target.checked),className:"sr-only peer"}),i.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"})]})]}),u&&i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:t("spoolman.reportPartialUsage")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t("spoolman.reportPartialUsageDesc")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:m,onChange:Y=>p(Y.target.checked),className:"sr-only peer"}),i.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.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{className:"text-sm text-bambu-gray",children:[t("settings.status"),":"]}),R?i.jsx(ht,{className:"w-4 h-4 text-bambu-gray animate-spin"}):k?.connected?i.jsxs("span",{className:"flex items-center gap-1 text-sm text-green-500",children:[i.jsx(Yr,{className:"w-4 h-4"}),t("settings.spoolmanConnected")]}):i.jsxs("span",{className:"flex items-center gap-1 text-sm text-red-500",children:[i.jsx(Ht,{className:"w-4 h-4"}),t("settings.spoolmanDisconnected")]})]}),i.jsx("div",{className:"flex gap-2",children:k?.connected?i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>G.mutate(),disabled:G.isPending,children:[G.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(jfe,{className:"w-4 h-4"}),t("settings.disconnect")]}):i.jsxs(Oe,{size:"sm",onClick:()=>z.mutate(),disabled:z.isPending||!s,children:[z.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(xh,{className:"w-4 h-4"}),t("settings.connect")]})})]}),z.isError&&i.jsx("div",{className:"mb-3 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:z.error.message}),k?.connected&&i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:t("settings.syncAmsData")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:t("settings.syncAmsDataDesc")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsxs("select",{value:f,onChange:Y=>y(Y.target.value==="all"?"all":Number(Y.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:[i.jsx("option",{value:"all",children:t("settings.allPrinters")}),D?.map(Y=>i.jsx("option",{value:Y.id,children:Y.name},Y.id))]}),i.jsx(Ln,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:ie,disabled:me,children:[me?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(wr,{className:"w-4 h-4"}),t("spoolman.sync")]})]})]}),ge&&he&&i.jsxs("div",{className:"mt-3 space-y-2",children:[i.jsx("div",{className:`p-2 rounded text-sm ${he.success?"bg-green-500/20 border border-green-500/50 text-green-400":"bg-yellow-500/20 border border-yellow-500/50 text-yellow-400"}`,children:he.success?`Synced ${he.synced_count} spool${he.synced_count!==1?"s":""} successfully`:`Synced ${he.synced_count} spool${he.synced_count!==1?"s":""} with ${he.errors.length} error${he.errors.length!==1?"s":""}`}),he.skipped_count>0&&i.jsxs("div",{className:"p-2 bg-amber-500/10 border border-amber-500/30 rounded text-sm",children:[i.jsxs("div",{className:"flex items-center justify-between text-amber-400 mb-1",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx(Mn,{className:"w-3.5 h-3.5"}),i.jsxs("span",{className:"font-medium",children:[he.skipped_count," spool",he.skipped_count!==1?"s":""," skipped"]})]}),he.skipped_count>5&&i.jsx("button",{onClick:()=>_(!g),className:"text-xs text-amber-400 hover:text-amber-300 underline",children:g?"Show less":"Show all"})]}),i.jsxs("ul",{className:"text-xs text-amber-300/80 space-y-0.5",children:[(g?he.skipped:he.skipped.slice(0,5)).map((Y,oe)=>i.jsxs("li",{className:"flex items-center gap-2",children:[Y.color&&i.jsx("span",{className:"w-3 h-3 rounded-full border border-white/20",style:{backgroundColor:`#${Y.color}`}}),i.jsx("span",{children:Y.location}),i.jsxs("span",{className:"text-amber-300/60",children:["- ",Y.reason]})]},oe)),!g&&he.skipped_count>5&&i.jsxs("li",{className:"text-amber-300/60 italic",children:["...and ",he.skipped_count-5," more"]})]})]}),he.errors.length>0&&i.jsxs("div",{className:"p-2 bg-red-500/10 border border-red-500/30 rounded text-sm",children:[i.jsx("div",{className:"text-red-400 font-medium mb-1",children:"Errors:"}),i.jsx("ul",{className:"text-xs text-red-300/80 space-y-0.5",children:he.errors.map((Y,oe)=>i.jsx("li",{children:Y},oe))})]})]})]})]})]}),N&&i.jsx(Sn,{title:t("settings.amsSyncTitle"),message:t("settings.amsSyncMessage"),confirmText:t("settings.amsSyncButton"),variant:"warning",isLoading:X.isPending,loadingText:t("settings.amsSyncing"),onConfirm:()=>X.mutate(),onCancel:()=>T(!1)})]})}function wet(){const{t}=Ft(),{showToast:e}=fn(),[n,r]=w.useState([]),[a,s]=w.useState(!0),[o,l]=w.useState(""),c=w.useRef(null),[u,d]=w.useState(!1),[m,p]=w.useState(null),[f,y]=w.useState(""),[v,x]=w.useState(""),[g,_]=w.useState(!1),[N,T]=w.useState(new Set),[C,A]=w.useState(!1),[k,R]=w.useState(null),[P,D]=w.useState(!1),H=w.useCallback(async()=>{try{const xe=await be.getSpoolCatalog();r(xe)}catch{e(t("settings.catalog.loadFailed"),"error")}finally{s(!1)}},[e,t]);w.useEffect(()=>{H()},[H]);const z=n.filter(xe=>xe.name.toLowerCase().includes(o.toLowerCase())),G=async()=>{if(!f.trim()||!v){e(t("settings.catalog.nameWeightRequired"),"error");return}_(!0);try{const xe=await be.addCatalogEntry({name:f.trim(),weight:parseInt(v)});r(Pe=>[...Pe,xe].sort((q,Z)=>q.name.localeCompare(Z.name))),d(!1),y(""),x(""),e(t("settings.catalog.entryAdded"),"success")}catch{e(t("settings.catalog.addFailed"),"error")}finally{_(!1)}},I=xe=>{p(xe.id),y(xe.name),x(xe.weight.toString())},ee=()=>{p(null),y(""),x("")},ie=async xe=>{if(!f.trim()||!v){e(t("settings.catalog.nameWeightRequired"),"error");return}_(!0);try{const Pe=await be.updateCatalogEntry(xe,{name:f.trim(),weight:parseInt(v)});r(q=>q.map(Z=>Z.id===xe?Pe:Z).sort((Z,j)=>Z.name.localeCompare(j.name))),p(null),y(""),x(""),e(t("settings.catalog.entryUpdated"),"success")}catch{e(t("settings.catalog.updateFailed"),"error")}finally{_(!1)}},X=async()=>{if(k)try{await be.deleteCatalogEntry(k.id),r(xe=>xe.filter(Pe=>Pe.id!==k.id)),e(t("settings.catalog.entryDeleted"),"success")}catch{e(t("settings.catalog.deleteFailed"),"error")}finally{R(null)}},me=async()=>{D(!1),s(!0);try{await be.resetSpoolCatalog(),await H(),e(t("settings.catalog.resetSuccess"),"success")}catch{e(t("settings.catalog.resetFailed"),"error"),s(!1)}},he=xe=>{T(Pe=>{const q=new Set(Pe);return q.has(xe)?q.delete(xe):q.add(xe),q})},ge=()=>{N.size===z.length?T(new Set):T(new Set(z.map(xe=>xe.id)))},Y=async()=>{if(A(!1),N.size!==0)try{const xe=await be.bulkDeleteCatalogEntries([...N]);r(Pe=>Pe.filter(q=>!N.has(q.id))),T(new Set),e(t("settings.catalog.bulkDeleted",{count:xe.deleted}),"success")}catch{e(t("settings.catalog.bulkDeleteFailed"),"error")}},oe=()=>{const xe=n.map(({name:j,weight:E})=>({name:j,weight:E})),Pe=new Blob([JSON.stringify(xe,null,2)],{type:"application/json"}),q=URL.createObjectURL(Pe),Z=document.createElement("a");Z.href=q,Z.download="spool-catalog.json",document.body.appendChild(Z),Z.click(),document.body.removeChild(Z),URL.revokeObjectURL(q),e(t("settings.catalog.exported",{count:n.length}),"success")},le=async xe=>{const Pe=xe.target.files?.[0];if(Pe){try{const q=await Pe.text(),Z=JSON.parse(q);if(!Array.isArray(Z))throw new Error("Invalid format");let j=0,E=0;for(const U of Z){if(!U.name||typeof U.weight!="number"){E++;continue}if(n.some($=>$.name.toLowerCase()===U.name.toLowerCase())){E++;continue}try{const $=await be.addCatalogEntry({name:U.name,weight:U.weight});r(ne=>[...ne,$].sort((O,V)=>O.name.localeCompare(V.name))),j++}catch{E++}}e(t("settings.catalog.imported",{added:j,skipped:E}),"success")}catch{e(t("settings.catalog.importFailed"),"error")}c.current&&(c.current.value="")}};return i.jsxs(Mt,{children:[i.jsxs(Hn,{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(au,{className:"w-5 h-5 text-bambu-gray"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.catalog.spoolCatalog")}),i.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",n.length,")"]})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[i.jsxs("button",{onClick:oe,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:t("settings.catalog.exportTooltip"),children:[i.jsx(pi,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.export")})]}),i.jsxs("button",{onClick:()=>c.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:t("settings.catalog.importTooltip"),children:[i.jsx(xi,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.import")})]}),i.jsx("input",{ref:c,type:"file",accept:".json",className:"hidden",onChange:le}),i.jsxs("button",{onClick:()=>D(!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:t("settings.catalog.resetTooltip"),children:[i.jsx(bo,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.reset")})]}),i.jsxs("button",{onClick:()=>d(!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:[i.jsx(ar,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.add")})]})]}),N.size>0&&i.jsxs("div",{className:"flex items-center gap-2 mt-2 px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg",children:[i.jsx("span",{className:"text-sm text-red-400",children:t("settings.catalog.selectedCount",{count:N.size})}),i.jsxs("button",{onClick:()=>A(!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:[i.jsx(Jt,{className:"w-4 h-4"}),t("settings.catalog.deleteSelected")]}),i.jsx("button",{onClick:()=>T(new Set),className:"px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors",children:t("common.cancel")})]})]}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:t("settings.catalog.spoolCatalogDescription")}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.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:t("settings.catalog.searchCatalog"),value:o,onChange:xe=>l(xe.target.value)})]}),u&&i.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:t("settings.catalog.addNewEntry")}),i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsx("div",{className:"flex-1 min-w-0",children:i.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:t("settings.catalog.namePlaceholder"),value:f,onChange:xe=>y(xe.target.value)})}),i.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:v,onChange:xe=>x(xe.target.value)}),i.jsx("span",{className:"text-bambu-gray shrink-0",children:"g"}),i.jsxs("button",{onClick:G,disabled:g,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:[g?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Yr,{className:"w-4 h-4"}),t("common.add")]}),i.jsx("button",{onClick:()=>{d(!1),y(""),x("")},className:"p-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary",children:i.jsx(Ht,{className:"w-4 h-4"})})]})]}),a?i.jsxs("div",{className:"flex items-center justify-center py-8 text-bambu-gray",children:[i.jsx(ht,{className:"w-5 h-5 animate-spin mr-2"}),t("common.loading")]}):i.jsx("div",{className:"max-h-[600px] overflow-y-auto border border-bambu-dark-tertiary rounded-lg",children:i.jsxs("table",{className:"w-full text-sm",children:[i.jsx("thead",{className:"bg-bambu-dark sticky top-0",children:i.jsxs("tr",{children:[i.jsx("th",{className:"px-2 py-2 w-10",children:i.jsx("input",{type:"checkbox",checked:z.length>0&&N.size===z.length,onChange:ge,className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),i.jsx("th",{className:"px-4 py-2 text-left text-bambu-gray font-medium",children:t("common.name")}),i.jsx("th",{className:"px-4 py-2 text-right text-bambu-gray font-medium w-24",children:t("settings.catalog.weight")}),i.jsx("th",{className:"px-4 py-2 text-center text-bambu-gray font-medium w-20",children:t("settings.catalog.type")}),i.jsx("th",{className:"px-4 py-2 w-24"})]})}),i.jsx("tbody",{children:z.length===0?i.jsx("tr",{children:i.jsx("td",{colSpan:5,className:"px-4 py-8 text-center text-bambu-gray",children:t(o?"settings.catalog.noMatch":"settings.catalog.empty")})}):z.map(xe=>i.jsx("tr",{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${N.has(xe.id)?"bg-bambu-dark":""}`,children:m===xe.id?i.jsxs(i.Fragment,{children:[i.jsx("td",{className:"px-2 py-2",children:i.jsx("input",{type:"checkbox",checked:N.has(xe.id),onChange:()=>he(xe.id),className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),i.jsx("td",{className:"px-4 py-2",children:i.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:f,onChange:Pe=>y(Pe.target.value)})}),i.jsx("td",{className:"px-4 py-2",children:i.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:v,onChange:Pe=>x(Pe.target.value)})}),i.jsx("td",{className:"px-4 py-2 text-center",children:i.jsx("span",{className:"text-xs text-bambu-gray",children:"-"})}),i.jsx("td",{className:"px-4 py-2",children:i.jsxs("div",{className:"flex justify-end gap-1",children:[i.jsx("button",{onClick:()=>ie(xe.id),disabled:g,className:"p-1.5 rounded hover:bg-green-500/20 text-green-500",children:g?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Yr,{className:"w-4 h-4"})}),i.jsx("button",{onClick:ee,className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray",children:i.jsx(Ht,{className:"w-4 h-4"})})]})})]}):i.jsxs(i.Fragment,{children:[i.jsx("td",{className:"px-2 py-2",children:i.jsx("input",{type:"checkbox",checked:N.has(xe.id),onChange:()=>he(xe.id),className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),i.jsx("td",{className:"px-4 py-2 text-white",children:xe.name}),i.jsxs("td",{className:"px-4 py-2 text-right font-mono text-white",children:[xe.weight,"g"]}),i.jsx("td",{className:"px-4 py-2 text-center",children:xe.is_default?i.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray",children:t("settings.catalog.default")}):i.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-bambu-green/20 text-bambu-green",children:t("settings.catalog.custom")})}),i.jsx("td",{className:"px-4 py-2",children:i.jsxs("div",{className:"flex justify-end gap-1",children:[i.jsx("button",{onClick:()=>I(xe),className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:i.jsx(Yi,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>R(xe),className:"p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500",children:i.jsx(Jt,{className:"w-4 h-4"})})]})})]})},xe.id))})]})})]}),k&&i.jsx(Sn,{title:t("settings.catalog.deleteEntry"),message:t("settings.catalog.deleteConfirm",{name:k.name}),confirmText:t("common.delete"),variant:"danger",onConfirm:X,onCancel:()=>R(null)}),C&&i.jsx(Sn,{title:t("settings.catalog.deleteSelected"),message:t("settings.catalog.bulkDeleteConfirm",{count:N.size}),confirmText:t("common.delete"),variant:"danger",onConfirm:Y,onCancel:()=>A(!1)}),P&&i.jsx(Sn,{title:t("settings.catalog.resetCatalog"),message:t("settings.catalog.resetConfirm"),confirmText:t("common.reset"),variant:"danger",onConfirm:me,onCancel:()=>D(!1)})]})}function _et(){const{t}=Ft(),{showToast:e}=fn(),[n,r]=w.useState([]),[a,s]=w.useState(!0),[o,l]=w.useState(""),[c,u]=w.useState("Bambu Lab"),d=w.useRef(null),[m,p]=w.useState(!1),[f,y]=w.useState(null),[v,x]=w.useState(""),[g,_]=w.useState(""),[N,T]=w.useState("#FFFFFF"),[C,A]=w.useState(""),[k,R]=w.useState(!1),[P,D]=w.useState(new Set),[H,z]=w.useState(!1),[G,I]=w.useState(!1),[ee,ie]=w.useState(null),[X,me]=w.useState(null),[he,ge]=w.useState(!1),Y=w.useCallback(async()=>{try{const W=await be.getColorCatalog();r(W)}catch{e(t("settings.colorCatalog.loadFailed"),"error")}finally{s(!1)}},[e,t]);w.useEffect(()=>{Y()},[Y]);const oe=[...new Set(n.map(W=>W.manufacturer))].sort(),le=n.filter(W=>{const re=o===""||W.manufacturer.toLowerCase().includes(o.toLowerCase())||W.color_name.toLowerCase().includes(o.toLowerCase())||(W.material?.toLowerCase().includes(o.toLowerCase())??!1),ue=c===""||W.manufacturer===c;return re&&ue}),xe=()=>{x(""),_(""),T("#FFFFFF"),A("")},Pe=async()=>{if(!v.trim()||!g.trim()||!N){e(t("settings.colorCatalog.fieldsRequired"),"error");return}R(!0);try{const W=await be.addColorEntry({manufacturer:v.trim(),color_name:g.trim(),hex_color:N,material:C.trim()||null});r(re=>[...re,W].sort((ue,fe)=>ue.manufacturer.localeCompare(fe.manufacturer)||(ue.material||"").localeCompare(fe.material||"")||ue.color_name.localeCompare(fe.color_name))),p(!1),xe(),e(t("settings.colorCatalog.colorAdded"),"success")}catch{e(t("settings.colorCatalog.addFailed"),"error")}finally{R(!1)}},q=W=>{y(W.id),x(W.manufacturer),_(W.color_name),T(W.hex_color),A(W.material||"")},Z=()=>{y(null),xe()},j=async W=>{if(!v.trim()||!g.trim()||!N){e(t("settings.colorCatalog.fieldsRequired"),"error");return}R(!0);try{const re=await be.updateColorEntry(W,{manufacturer:v.trim(),color_name:g.trim(),hex_color:N,material:C.trim()||null});r(ue=>ue.map(fe=>fe.id===W?re:fe).sort((fe,ye)=>fe.manufacturer.localeCompare(ye.manufacturer)||(fe.material||"").localeCompare(ye.material||"")||fe.color_name.localeCompare(ye.color_name))),y(null),xe(),e(t("settings.colorCatalog.colorUpdated"),"success")}catch{e(t("settings.colorCatalog.updateFailed"),"error")}finally{R(!1)}},E=async()=>{if(X)try{await be.deleteColorEntry(X.id),r(W=>W.filter(re=>re.id!==X.id)),e(t("settings.colorCatalog.colorDeleted"),"success")}catch{e(t("settings.colorCatalog.deleteFailed"),"error")}finally{me(null)}},U=async()=>{ge(!1),s(!0);try{await be.resetColorCatalog(),await Y(),e(t("settings.colorCatalog.resetSuccess"),"success")}catch{e(t("settings.colorCatalog.resetFailed"),"error"),s(!1)}},K=async()=>{I(!0),ie(null);try{const W={},re=Fd();re&&(W.Authorization=`Bearer ${re}`);const ue=await fetch("/api/v1/inventory/colors/sync",{method:"POST",headers:W});if(!ue.ok)throw new Error("Failed to start sync");const fe=ue.body?.getReader();if(!fe)throw new Error("No response body");const ye=new TextDecoder;let ae="";for(;;){const{done:L,value:F}=await fe.read();if(L)break;ae+=ye.decode(F,{stream:!0});const te=ae.split(` -`);ae=te.pop()||"";for(const ve of te)if(ve.startsWith("data: "))try{const pe=JSON.parse(ve.slice(6));pe.type==="progress"?ie({fetched:pe.total_fetched,total:pe.total_available}):pe.type==="complete"?pe.added===0?e(t("settings.colorCatalog.syncUpToDate",{count:pe.total_fetched}),"success"):e(t("settings.colorCatalog.syncComplete",{added:pe.added,skipped:pe.skipped}),"success"):pe.type==="error"&&e(`${t("settings.colorCatalog.syncError")}: ${pe.error}`,"error")}catch{}}await Y()}catch{e(t("settings.colorCatalog.syncFailed"),"error")}finally{I(!1),ie(null)}},$=W=>{D(re=>{const ue=new Set(re);return ue.has(W)?ue.delete(W):ue.add(W),ue})},ne=()=>{P.size===le.length?D(new Set):D(new Set(le.map(W=>W.id)))},O=async()=>{if(z(!1),P.size!==0)try{const W=await be.bulkDeleteColorEntries([...P]);r(re=>re.filter(ue=>!P.has(ue.id))),D(new Set),e(t("settings.colorCatalog.bulkDeleted",{count:W.deleted}),"success")}catch{e(t("settings.colorCatalog.bulkDeleteFailed"),"error")}},V=()=>{const W=n.map(({manufacturer:ye,color_name:ae,hex_color:L,material:F})=>({manufacturer:ye,color_name:ae,hex_color:L,material:F})),re=new Blob([JSON.stringify(W,null,2)],{type:"application/json"}),ue=URL.createObjectURL(re),fe=document.createElement("a");fe.href=ue,fe.download="color-catalog.json",document.body.appendChild(fe),fe.click(),document.body.removeChild(fe),URL.revokeObjectURL(ue),e(t("settings.colorCatalog.exported",{count:n.length}),"success")},J=async W=>{const re=W.target.files?.[0];if(re){try{const ue=await re.text(),fe=JSON.parse(ue);if(!Array.isArray(fe))throw new Error("Invalid format");let ye=0,ae=0;for(const L of fe){if(!L.manufacturer||!L.color_name||!L.hex_color){ae++;continue}if(n.some(te=>te.manufacturer.toLowerCase()===L.manufacturer.toLowerCase()&&te.color_name.toLowerCase()===L.color_name.toLowerCase()&&(te.material||"").toLowerCase()===(L.material||"").toLowerCase())){ae++;continue}try{const te=await be.addColorEntry({manufacturer:L.manufacturer,color_name:L.color_name,hex_color:L.hex_color,material:L.material||null});r(ve=>[...ve,te].sort((pe,de)=>pe.manufacturer.localeCompare(de.manufacturer)||(pe.material||"").localeCompare(de.material||"")||pe.color_name.localeCompare(de.color_name))),ye++}catch{ae++}}e(t("settings.colorCatalog.imported",{added:ye,skipped:ae}),"success")}catch{e(t("settings.colorCatalog.importFailed"),"error")}d.current&&(d.current.value="")}};return i.jsxs(Mt,{children:[i.jsxs(Hn,{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(fw,{className:"w-5 h-5 text-bambu-gray"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.colorCatalog.title")}),i.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",n.length,")"]})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[i.jsxs("button",{onClick:V,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:[i.jsx(pi,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.export")})]}),i.jsxs("button",{onClick:()=>d.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:[i.jsx(xi,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.import")})]}),i.jsx("input",{ref:d,type:"file",accept:".json",className:"hidden",onChange:J}),i.jsxs("button",{onClick:K,disabled:G,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:t("settings.colorCatalog.syncTooltip"),children:[G?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Fx,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:G?ee?`${Math.min(ee.fetched,ee.total)} / ${ee.total}`:t("settings.colorCatalog.starting"):t("settings.colorCatalog.sync")})]}),i.jsxs("button",{onClick:()=>ge(!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:[i.jsx(bo,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.reset")})]}),i.jsxs("button",{onClick:()=>p(!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:[i.jsx(ar,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.add")})]})]}),P.size>0&&i.jsxs("div",{className:"flex items-center gap-2 mt-2 px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg",children:[i.jsx("span",{className:"text-sm text-red-400",children:t("settings.colorCatalog.selectedCount",{count:P.size})}),i.jsxs("button",{onClick:()=>z(!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:[i.jsx(Jt,{className:"w-4 h-4"}),t("settings.colorCatalog.deleteSelected")]}),i.jsx("button",{onClick:()=>D(new Set),className:"px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors",children:t("common.cancel")})]})]}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:t("settings.colorCatalog.description")}),i.jsxs("div",{className:"flex gap-2 flex-wrap",children:[i.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.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:t("settings.colorCatalog.searchColors"),value:o,onChange:W=>l(W.target.value)})]}),i.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:c,onChange:W=>u(W.target.value),children:[i.jsx("option",{value:"",children:t("settings.colorCatalog.allManufacturers")}),oe.map(W=>i.jsx("option",{value:W,children:W},W))]})]}),m&&i.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:t("settings.colorCatalog.addNewColor")}),i.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-2 items-end",children:[i.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:t("settings.colorCatalog.manufacturer"),value:v,onChange:W=>x(W.target.value)}),i.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:t("settings.colorCatalog.colorName"),value:g,onChange:W=>_(W.target.value)}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"color",className:"w-20 h-10 rounded cursor-pointer border border-bambu-dark-tertiary",value:N,onChange:W=>T(W.target.value)}),i.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:N,onChange:W=>T(W.target.value)})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.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:t("settings.colorCatalog.materialOptional"),value:C,onChange:W=>A(W.target.value)}),i.jsxs("button",{onClick:Pe,disabled:k,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:[k?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Yr,{className:"w-4 h-4"}),t("common.add")]}),i.jsx("button",{onClick:()=>{p(!1),xe()},className:"p-2 ml-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary",children:i.jsx(Ht,{className:"w-4 h-4"})})]})]})]}),(o||c)&&i.jsx("div",{className:"text-xs text-bambu-gray",children:t("settings.colorCatalog.showing",{filtered:le.length,total:n.length})}),a?i.jsxs("div",{className:"flex items-center justify-center py-8 text-bambu-gray",children:[i.jsx(ht,{className:"w-5 h-5 animate-spin mr-2"}),t("common.loading")]}):i.jsx("div",{className:"max-h-[600px] overflow-auto border border-bambu-dark-tertiary rounded-lg",children:i.jsxs("table",{className:"w-full text-sm",children:[i.jsx("thead",{className:"bg-bambu-dark sticky top-0",children:i.jsxs("tr",{children:[i.jsx("th",{className:"px-2 py-2 w-10",children:i.jsx("input",{type:"checkbox",checked:le.length>0&&P.size===le.length,onChange:ne,className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium w-12"}),i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium",children:t("settings.colorCatalog.manufacturer")}),i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium",children:t("inventory.material")}),i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium",children:t("settings.colorCatalog.colorName")}),i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium w-24",children:t("settings.colorCatalog.hex")}),i.jsx("th",{className:"px-3 py-2 w-16"})]})}),i.jsx("tbody",{children:le.length===0?i.jsx("tr",{children:i.jsx("td",{colSpan:7,className:"px-3 py-8 text-center text-bambu-gray",children:t(o||c?"settings.colorCatalog.noMatch":"settings.colorCatalog.empty")})}):le.map(W=>i.jsx("tr",{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${P.has(W.id)?"bg-bambu-dark":""}`,children:f===W.id?i.jsxs(i.Fragment,{children:[i.jsx("td",{className:"px-2 py-2",children:i.jsx("input",{type:"checkbox",checked:P.has(W.id),onChange:()=>$(W.id),className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),i.jsx("td",{className:"px-3 py-2",children:i.jsx("input",{type:"color",className:"w-8 h-8 rounded cursor-pointer border border-bambu-dark-tertiary",value:N,onChange:re=>T(re.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.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:re=>x(re.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.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:C,onChange:re=>A(re.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.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:g,onChange:re=>_(re.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.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:N,onChange:re=>T(re.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.jsxs("div",{className:"flex justify-end gap-1",children:[i.jsx("button",{onClick:()=>j(W.id),disabled:k,className:"p-1.5 rounded hover:bg-green-500/20 text-green-500",children:k?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Yr,{className:"w-4 h-4"})}),i.jsx("button",{onClick:Z,className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray",children:i.jsx(Ht,{className:"w-4 h-4"})})]})})]}):i.jsxs(i.Fragment,{children:[i.jsx("td",{className:"px-2 py-2",children:i.jsx("input",{type:"checkbox",checked:P.has(W.id),onChange:()=>$(W.id),className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),i.jsx("td",{className:"px-3 py-2",children:i.jsx("div",{className:"w-8 h-8 rounded border border-bambu-dark-tertiary",style:{backgroundColor:W.hex_color},title:W.hex_color})}),i.jsx("td",{className:"px-3 py-2 text-white",children:W.manufacturer}),i.jsx("td",{className:"px-3 py-2 text-bambu-gray",children:W.material||"-"}),i.jsx("td",{className:"px-3 py-2 text-white",children:W.color_name}),i.jsx("td",{className:"px-3 py-2 font-mono text-xs text-bambu-gray",children:W.hex_color}),i.jsx("td",{className:"px-3 py-2",children:i.jsxs("div",{className:"flex justify-end gap-1",children:[i.jsx("button",{onClick:()=>q(W),className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:i.jsx(Yi,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>me(W),className:"p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500",children:i.jsx(Jt,{className:"w-4 h-4"})})]})})]})},W.id))})]})})]}),X&&i.jsx(Sn,{title:t("settings.colorCatalog.deleteColor"),message:t("settings.colorCatalog.deleteConfirm",{name:`${X.manufacturer} - ${X.color_name}`}),confirmText:t("common.delete"),variant:"danger",onConfirm:E,onCancel:()=>me(null)}),H&&i.jsx(Sn,{title:t("settings.colorCatalog.deleteSelected"),message:t("settings.colorCatalog.bulkDeleteConfirm",{count:P.size}),confirmText:t("common.delete"),variant:"danger",onConfirm:O,onCancel:()=>z(!1)}),he&&i.jsx(Sn,{title:t("settings.colorCatalog.resetCatalog"),message:t("settings.colorCatalog.resetConfirm"),confirmText:t("common.reset"),variant:"danger",onConfirm:U,onCancel:()=>ge(!1)})]})}function Net({link:t,onClose:e}){const{t:n}=Ft(),r=an(),a=!!t,s=w.useRef(null),[o,l]=w.useState(t?.name||""),[c,u]=w.useState(t?.url||""),[d,m]=w.useState(t?.icon||"link"),[p,f]=w.useState(t?.open_in_new_tab||!1),[y,v]=w.useState(!!t?.custom_icon),[x,g]=w.useState(t?.custom_icon?be.getExternalLinkIconUrl(t.id):null),[_,N]=w.useState(null),[T,C]=w.useState(null);w.useEffect(()=>{const G=I=>{I.key==="Escape"&&e()};return window.addEventListener("keydown",G),()=>window.removeEventListener("keydown",G)},[e]);const A=pt({mutationFn:async G=>{const I=await be.createExternalLink(G);return _?await be.uploadExternalLinkIcon(I.id,_):I},onSuccess:()=>{r.invalidateQueries({queryKey:["external-links"]}),e()},onError:G=>{C(G.message)}}),k=pt({mutationFn:async G=>{let I=await be.updateExternalLink(t.id,G);return _?I=await be.uploadExternalLinkIcon(t.id,_):!y&&t?.custom_icon&&(I=await be.deleteExternalLinkIcon(t.id)),I},onSuccess:()=>{r.invalidateQueries({queryKey:["external-links"]}),e()},onError:G=>{C(G.message)}}),R=G=>{const I=G.target.files?.[0];if(I){if(!["image/png","image/jpeg","image/gif","image/svg+xml","image/webp","image/x-icon"].includes(I.type)){C("Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)");return}if(I.size>1024*1024){C("Image file must be less than 1MB");return}N(I),v(!0);const ie=new FileReader;ie.onload=X=>{g(X.target?.result)},ie.readAsDataURL(I)}},P=()=>{N(null),g(null),v(!1),s.current&&(s.current.value="")},D=G=>{if(G.preventDefault(),C(null),!o.trim()){C("Name is required");return}if(!c.trim()){C("URL is required");return}if(!c.startsWith("http://")&&!c.startsWith("https://")){C("URL must start with http:// or https://");return}const I={name:o.trim(),url:c.trim(),icon:d,open_in_new_tab:p};a?k.mutate(I):A.mutate(I)},H=A.isPending||k.isPending,z=sT(d);return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:G=>G.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2 rounded-full bg-bambu-green/20 text-bambu-green",children:y&&x?i.jsx("img",{src:x,alt:"",className:"w-5 h-5 rounded"}):i.jsx(z,{className:"w-5 h-5"})}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:a?"Edit Link":"Add External Link"})]}),i.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:D,className:"p-6 space-y-4",children:[T&&i.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:T}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),i.jsx("input",{type:"text",value:o,onChange:G=>l(G.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"URL *"}),i.jsx("input",{type:"text",value:c,onChange:G=>u(G.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"})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("label",{className:"text-sm text-bambu-gray",children:n("externalLinks.openInNewTab")}),i.jsx("button",{type:"button",onClick:()=>f(!p),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${p?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:i.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${p?"translate-x-6":"translate-x-1"}`})})]}),i.jsxs("div",{className:"space-y-3",children:[i.jsx("label",{className:"block text-sm text-bambu-gray",children:"Icon"}),i.jsxs("div",{className:"p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-sm text-white",children:"Custom Icon"}),i.jsx("input",{ref:s,type:"file",accept:"image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon",className:"hidden",onChange:R}),y&&x?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("img",{src:x,alt:"Custom icon",className:"w-8 h-8 rounded border border-bambu-dark-tertiary"}),i.jsx("button",{type:"button",onClick:P,className:"p-1 text-red-400 hover:text-red-300 transition-colors",title:"Remove custom icon",children:i.jsx(Jt,{className:"w-4 h-4"})})]}):i.jsxs(Oe,{type:"button",variant:"secondary",size:"sm",onClick:()=>s.current?.click(),children:[i.jsx(xi,{className:"w-4 h-4"}),"Upload"]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:"PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB."})]}),!y&&i.jsxs("div",{children:[i.jsx("span",{className:"text-sm text-bambu-gray block mb-2",children:"Or choose a preset icon"}),i.jsx(Wbe,{value:d,onChange:m})]})]}),i.jsxs("div",{className:"flex gap-3 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),i.jsxs(Oe,{type:"submit",disabled:H,className:"flex-1",children:[H?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(ts,{className:"w-4 h-4"}),a?"Save":"Add"]})]})]})]})})}function ket(){const{t}=Ft(),e=an(),[n,r]=w.useState(!1),[a,s]=w.useState(null),[o,l]=w.useState(null),[c,u]=w.useState(null),{data:d,isLoading:m}=et({queryKey:["external-links"],queryFn:be.getExternalLinks}),p=pt({mutationFn:N=>be.deleteExternalLink(N),onSuccess:()=>{e.invalidateQueries({queryKey:["external-links"]})}}),f=pt({mutationFn:N=>be.reorderExternalLinks(N),onSuccess:()=>{e.invalidateQueries({queryKey:["external-links"]})}}),y=(N,T)=>{u(T),N.dataTransfer.effectAllowed="move"},v=N=>{N.preventDefault(),N.dataTransfer.dropEffect="move"},x=(N,T)=>{if(N.preventDefault(),c===null||c===T||!d)return;const C=d.map(P=>P.id),A=C.indexOf(c),k=C.indexOf(T);if(A===-1||k===-1)return;const R=[...C];R.splice(A,1),R.splice(k,0,c),f.mutate(R),u(null)},g=N=>{l(N)},_=()=>{o&&(p.mutate(o.id),l(null))};return i.jsxs(i.Fragment,{children:[i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(xh,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:"Sidebar Links"})]}),i.jsxs(Oe,{size:"sm",onClick:()=>r(!0),children:[i.jsx(ar,{className:"w-4 h-4"}),"Add Link"]})]})}),i.jsxs(Dt,{children:[i.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Add external links to the sidebar navigation. Drag to reorder."}),m?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})}):d&&d.length>0?i.jsx("div",{className:"space-y-2",children:d.map(N=>{const T=sT(N.icon);return i.jsxs("div",{draggable:!0,onDragStart:C=>y(C,N.id),onDragOver:v,onDrop:C=>x(C,N.id),className:`flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${c===N.id?"opacity-50":""}`,children:[i.jsx(bh,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0"}),i.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray",children:i.jsx(T,{className:"w-4 h-4"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-white font-medium truncate",children:N.name}),i.jsx(Jr,{className:"w-3 h-3 text-bambu-gray flex-shrink-0"})]}),i.jsx("span",{className:"text-sm text-bambu-gray truncate block",children:N.url})]}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[i.jsx("button",{onClick:()=>s(N),className:"p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",title:t("common.edit"),children:i.jsx(Yi,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>g(N),disabled:p.isPending,className:"p-2 rounded-lg hover:bg-red-500/20 text-bambu-gray hover:text-red-400 transition-colors disabled:opacity-50",title:t("externalLinks.deleteLink"),children:i.jsx(Jt,{className:"w-4 h-4"})})]})]},N.id)})}):i.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[i.jsx(xh,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),i.jsx("p",{children:t("externalLinks.noLinksConfigured")}),i.jsx("p",{className:"text-sm",children:'Click "Add Link" to add one'})]})]})]}),(n||a)&&i.jsx(Net,{link:a,onClose:()=>{r(!1),s(null)}}),o&&i.jsx(Sn,{title:"Delete Link",message:`Are you sure you want to delete "${o.name}"? This action cannot be undone.`,confirmText:"Delete",cancelText:"Cancel",variant:"danger",onConfirm:_,onCancel:()=>l(null)})]})}const ID={immediate:"archive",review:"review",print_queue:"queue",proxy:"proxy"};function Cet({printer:t,models:e}){const{t:n}=Ft(),r=an(),{showToast:a}=fn(),[s,o]=w.useState(!0),[l,c]=w.useState(t.enabled),[u,d]=w.useState(t.name),[m,p]=w.useState(""),[f,y]=w.useState(t.mode==="queue"?"review":t.mode),[v,x]=w.useState(t.target_printer_id),[g,_]=w.useState(t.bind_ip||""),[N,T]=w.useState(t.remote_interface_ip||""),[C,A]=w.useState(t.model||""),[k,R]=w.useState(t.auto_dispatch??!0),[P,D]=w.useState(!1),[H,z]=w.useState(null),[G,I]=w.useState(!1);w.useEffect(()=>{H||(c(t.enabled),y(t.mode==="queue"?"review":t.mode),d(t.name),x(t.target_printer_id),_(t.bind_ip||""),T(t.remote_interface_ip||""),A(t.model||""),R(t.auto_dispatch??!0))},[t,H]);const{data:ee}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:ie}=et({queryKey:["network-interfaces"],queryFn:()=>be.getNetworkInterfaces().then(E=>E.interfaces)}),X=pt({mutationFn:E=>FN.update(t.id,E),onSuccess:()=>{r.invalidateQueries({queryKey:["virtual-printers"]}),a(n("virtualPrinter.toast.updated")),z(null)},onError:E=>{a(E.message||n("virtualPrinter.toast.failedToUpdate"),"error"),c(t.enabled),y(t.mode==="queue"?"review":t.mode),x(t.target_printer_id),_(t.bind_ip||""),z(null)}}),me=pt({mutationFn:()=>FN.remove(t.id),onSuccess:()=>{r.invalidateQueries({queryKey:["virtual-printers"]}),a(n("virtualPrinter.toast.deleted")),I(!1)},onError:E=>{a(E.message||n("virtualPrinter.toast.failedToDelete"),"error"),I(!1)}}),he=E=>{E.stopPropagation();const U=!l;if(U){if(!g){a(n("virtualPrinter.toast.bindIpRequired"),"error");return}if(f==="proxy"){if(!v){a(n("virtualPrinter.toast.targetPrinterRequired"),"error");return}}else if(!m&&!t.access_code_set){a(n("virtualPrinter.toast.accessCodeRequired"),"error");return}}c(U),z("toggle"),X.mutate({enabled:U})},ge=()=>{u.trim()&&(z("name"),X.mutate({name:u.trim()}))},Y=()=>{if(!m){a(n("virtualPrinter.toast.accessCodeEmpty"),"error");return}if(m.length!==8){a(n("virtualPrinter.toast.accessCodeLength"),"error");return}z("accessCode"),X.mutate({access_code:m}),p("")},oe=E=>{y(E),z("mode"),X.mutate({mode:E})},le=E=>{A(E),z("model"),X.mutate({model:E})},xe=E=>{x(E),z("targetPrinter"),X.mutate({target_printer_id:E})},Pe=E=>{T(E),z("remoteInterface"),X.mutate({remote_interface_ip:E})},q=t.status?.running||!1,Z=n(`virtualPrinter.mode.${ID[f]||"archive"}`),j=ee?.find(E=>E.id===v)?.name;return i.jsxs(i.Fragment,{children:[i.jsxs(Mt,{children:[i.jsxs("div",{className:"px-4 py-3 flex items-center gap-3 cursor-pointer select-none",onClick:()=>o(!s),children:[i.jsx("button",{className:"text-bambu-gray flex-shrink-0",children:s?i.jsx(Ln,{className:"w-4 h-4"}):i.jsx(ha,{className:"w-4 h-4"})}),i.jsx("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${q?"bg-green-400 animate-pulse":"bg-gray-500"}`}),i.jsx("span",{className:"text-white font-medium truncate",children:t.name}),i.jsx("span",{className:"text-xs text-bambu-gray flex-shrink-0",children:Z}),t.model_name&&i.jsx("span",{className:"text-xs text-bambu-gray flex-shrink-0",children:t.model_name}),j&&i.jsxs("span",{className:"text-xs text-bambu-gray flex-shrink-0 truncate",children:[f==="proxy"&&i.jsx(h3,{className:"w-3 h-3 inline mr-1"}),j]}),g&&i.jsx("span",{className:"text-[10px] text-bambu-gray flex-shrink-0 font-mono",children:g}),N&&i.jsx("span",{className:"text-[10px] text-bambu-gray flex-shrink-0 font-mono",children:N}),i.jsx("div",{className:"ml-auto flex items-center gap-2 flex-shrink-0",onClick:E=>E.stopPropagation(),children:i.jsx("button",{onClick:he,disabled:H==="toggle",className:`relative w-10 h-5 rounded-full transition-colors ${l?"bg-bambu-green":"bg-bambu-dark-tertiary"} ${H==="toggle"?"opacity-50":""}`,children:i.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${l?"translate-x-5":""}`})})})]}),s&&i.jsxs(Dt,{className:"pt-0 space-y-4",children:[i.jsx("div",{className:"border-t border-bambu-dark-tertiary"}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"text",value:u,onChange:E=>d(E.target.value),onBlur:ge,onKeyDown:E=>E.key==="Enter"&&ge(),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"}),i.jsx("span",{className:"text-xs text-bambu-gray font-mono",children:t.serial}),i.jsx("button",{onClick:()=>I(!0),className:"p-1.5 text-bambu-gray hover:text-red-400 transition-colors",title:n("common.delete"),children:i.jsx(Jt,{className:"w-4 h-4"})})]}),i.jsxs("div",{children:[i.jsx("div",{className:"text-white text-sm font-medium mb-2",children:n("virtualPrinter.mode.title")}),i.jsx("div",{className:"grid grid-cols-2 gap-2",children:["immediate","review","print_queue","proxy"].map(E=>i.jsxs("button",{onClick:()=>oe(E),disabled:H==="mode",className:`p-2 rounded-lg border text-left transition-colors ${f===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:[i.jsxs("div",{className:"flex items-center gap-1.5 text-white text-xs font-medium",children:[E==="proxy"&&i.jsx(h3,{className:"w-3 h-3"}),n(`virtualPrinter.mode.${ID[E]}`)]}),i.jsx("div",{className:"text-[10px] text-bambu-gray",children:n(`virtualPrinter.mode.${ID[E]}Desc`)})]},E))})]}),f==="print_queue"&&i.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.autoDispatch.title")}),i.jsx("div",{className:"text-[10px] text-bambu-gray",children:n("virtualPrinter.autoDispatch.description")})]}),i.jsx("button",{onClick:()=>{const E=!k;R(E),z("autoDispatch"),X.mutate({auto_dispatch:E})},disabled:H==="autoDispatch",className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${k?"bg-bambu-green":"bg-bambu-dark-tertiary"} ${H==="autoDispatch"?"opacity-50":""}`,children:i.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${k?"translate-x-5":""}`})})]})}),f!=="proxy"&&i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsx("div",{className:"text-white text-sm font-medium mb-1",children:n("virtualPrinter.model.title")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:n("virtualPrinter.model.description")}),i.jsxs("div",{className:"relative",children:[i.jsx("select",{value:C,onChange:E=>le(E.target.value),disabled:H==="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(e).map(([E,U])=>i.jsxs("option",{value:E,children:[U," (",E,")"]},E))}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),f==="proxy"&&i.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:i.jsxs("div",{className:"flex items-start gap-2 p-2 rounded bg-blue-500/10 border border-blue-500/30",children:[i.jsx(Ls,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("virtualPrinter.proxy.accessCodeHint")})]})}),f!=="proxy"&&i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.accessCode.title")}),t.access_code_set?i.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-400",children:[i.jsx(Yr,{className:"w-3 h-3"}),n("virtualPrinter.accessCode.isSet")]}):i.jsxs("span",{className:"flex items-center gap-1 text-xs text-yellow-400",children:[i.jsx(Mn,{className:"w-3 h-3"}),n("virtualPrinter.accessCode.notSet")]})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("input",{type:P?"text":"password",value:m,onChange:E=>p(E.target.value),placeholder:t.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"}),i.jsx("button",{onClick:()=>D(!P),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:P?i.jsx(mw,{className:"w-4 h-4"}):i.jsx(_c,{className:"w-4 h-4"})})]}),i.jsx(Oe,{onClick:Y,disabled:!m||H==="accessCode",variant:"primary",children:H==="accessCode"?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):n("common.save")})]}),m&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i.jsx("span",{className:m.length===8?"text-green-400":"text-yellow-400",children:n("virtualPrinter.accessCode.charCount",{count:m.length})})})]}),i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsx("div",{className:"text-white text-sm font-medium mb-2",children:n("virtualPrinter.targetPrinter.title")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:v??"",onChange:E=>{const U=parseInt(E.target.value,10);isNaN(U)||xe(U)},disabled:H==="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:[i.jsx("option",{value:"",children:n("virtualPrinter.targetPrinter.placeholder")}),ee?.map(E=>i.jsxs("option",{value:E.id,children:[E.name," (",E.ip_address,")"]},E.id))]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsx("div",{className:"text-white text-sm font-medium mb-1",children:n("virtualPrinter.bindIp.title")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:g,onChange:E=>{_(E.target.value),z("bindIp"),X.mutate({bind_ip:E.target.value})},disabled:H==="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:[i.jsx("option",{value:"",children:n("virtualPrinter.bindIp.placeholder")}),ie?.map(E=>i.jsxs("option",{value:E.ip,children:[E.name," (",E.ip,")",E.is_alias?" [alias]":""," - ",E.subnet]},E.ip))]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("virtualPrinter.bindIp.hint")})]}),i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[i.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.remoteInterface.title")}),N?i.jsx("span",{className:"flex items-center gap-1 text-xs text-green-400",children:i.jsx(Yr,{className:"w-3 h-3"})}):i.jsx("span",{className:"flex items-center gap-1 text-xs text-bambu-gray",title:n("virtualPrinter.remoteInterface.optional"),children:i.jsx(Ls,{className:"w-3 h-3"})})]}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:N,onChange:E=>Pe(E.target.value),disabled:H==="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:[i.jsx("option",{value:"",children:n("virtualPrinter.remoteInterface.placeholder")}),ie?.map(E=>i.jsxs("option",{value:E.ip,children:[E.name," (",E.ip,") - ",E.subnet]},E.ip))]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]})]})]}),G&&i.jsx(Sn,{title:n("virtualPrinter.deleteConfirm.title"),message:n("virtualPrinter.deleteConfirm.message",{name:t.name}),variant:"danger",confirmText:n("common.delete"),isLoading:me.isPending,onConfirm:()=>me.mutate(),onCancel:()=>I(!1)})]})}const kY={immediate:"archive",review:"review",print_queue:"queue",proxy:"proxy"};function Tet({onClose:t}){const{t:e}=Ft(),n=an(),{showToast:r}=fn(),[a,s]=w.useState(""),[o,l]=w.useState("immediate"),[c,u]=w.useState(null),{data:d}=et({queryKey:["printers"],queryFn:be.getPrinters}),m=pt({mutationFn:()=>FN.create({name:a.trim()||"Bambuddy",mode:o,target_printer_id:o==="proxy"?c??void 0:void 0}),onSuccess:()=>{n.invalidateQueries({queryKey:["virtual-printers"]}),r(e("virtualPrinter.toast.created")),t()},onError:p=>{r(p.message||e("virtualPrinter.toast.failedToCreate"),"error")}});return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:t,children:i.jsx(Mt,{className:"w-full max-w-md",onClick:p=>p.stopPropagation(),children:i.jsxs(Dt,{className:"p-6 space-y-4",children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:e("virtualPrinter.addDialog.title")}),i.jsxs("div",{children:[i.jsx("label",{className:"text-sm text-white font-medium block mb-1",children:e("virtualPrinter.addDialog.name")}),i.jsx("input",{type:"text",value:a,onChange:p=>s(p.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})]}),i.jsxs("div",{children:[i.jsx("label",{className:"text-sm text-white font-medium block mb-1",children:e("virtualPrinter.mode.title")}),i.jsx("div",{className:"grid grid-cols-2 gap-2",children:["immediate","review","print_queue","proxy"].map(p=>i.jsxs("button",{onClick:()=>l(p),className:`p-2 rounded-lg border text-left transition-colors ${o===p?p==="proxy"?"border-blue-500 bg-blue-500/10":"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[i.jsxs("div",{className:"flex items-center gap-1.5 text-white text-xs font-medium",children:[p==="proxy"&&i.jsx(h3,{className:"w-3 h-3"}),e(`virtualPrinter.mode.${kY[p]}`)]}),i.jsx("div",{className:"text-[10px] text-bambu-gray",children:e(`virtualPrinter.mode.${kY[p]}Desc`)})]},p))})]}),o==="proxy"&&i.jsxs("div",{children:[i.jsx("label",{className:"text-sm text-white font-medium block mb-1",children:e("virtualPrinter.targetPrinter.title")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:c??"",onChange:p=>{const f=parseInt(p.target.value,10);u(isNaN(f)?null:f)},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:[i.jsx("option",{value:"",children:e("virtualPrinter.targetPrinter.placeholder")}),d?.map(p=>i.jsxs("option",{value:p.id,children:[p.name," (",p.ip_address,")"]},p.id))]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:e("virtualPrinter.addDialog.hint")}),i.jsxs("div",{className:"flex gap-3 pt-2",children:[i.jsx(Oe,{variant:"secondary",onClick:t,className:"flex-1",disabled:m.isPending,children:e("common.cancel")}),i.jsx(Oe,{variant:"primary",onClick:()=>m.mutate(),className:"flex-1",disabled:m.isPending,children:m.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):e("virtualPrinter.addDialog.create")})]})]})})})}function Aet(){const{t}=Ft(),[e,n]=w.useState(!1),{data:r,isLoading:a}=et({queryKey:["virtual-printers"],queryFn:FN.list,refetchInterval:1e4});if(a)return i.jsx(Mt,{children:i.jsx(Dt,{className:"py-8 flex justify-center",children:i.jsx(ht,{className:"w-6 h-6 animate-spin text-bambu-green"})})});const s=r?.printers||[],o=r?.models||{};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-4 gap-4 items-stretch",children:[i.jsx(Mt,{className:"border-l-4 border-l-yellow-500",children:i.jsx(Dt,{className:"py-3 px-4",children:i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx(Mn,{className:"w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5"}),i.jsxs("div",{className:"text-xs",children:[i.jsx("p",{className:"text-white font-medium",children:t("virtualPrinter.setupRequired.title")}),i.jsx("p",{className:"text-bambu-gray mt-1",children:t("virtualPrinter.setupRequired.description")}),i.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-500/20 border border-yellow-500/50 rounded text-yellow-400 hover:bg-yellow-500/30 transition-colors text-xs",children:[i.jsx(Jr,{className:"w-3 h-3"}),t("virtualPrinter.setupRequired.readGuide")]})]})]})})}),i.jsx(Mt,{className:"lg:col-span-3",children:i.jsx(Dt,{className:"py-3 px-4",children:i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx(Ls,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[i.jsx("p",{className:"text-white font-medium mb-1",children:t("virtualPrinter.howItWorks.title")}),i.jsxs("ul",{className:"space-y-1 list-disc list-inside",children:[i.jsx("li",{children:t("virtualPrinter.howItWorks.step1")}),i.jsx("li",{children:t("virtualPrinter.howItWorks.step2")}),i.jsx("li",{children:t("virtualPrinter.howItWorks.step3")})]})]})]})})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Sr,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("virtualPrinter.list.title")}),i.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",s.length,")"]})]}),i.jsxs(Oe,{variant:"primary",onClick:()=>n(!0),children:[i.jsx(ar,{className:"w-4 h-4 mr-1"}),t("virtualPrinter.list.add")]})]}),s.length===0?i.jsx(Mt,{children:i.jsxs(Dt,{className:"py-8 text-center",children:[i.jsx(Sr,{className:"w-12 h-12 text-bambu-gray mx-auto mb-3"}),i.jsx("p",{className:"text-bambu-gray mb-4",children:t("virtualPrinter.list.empty")}),i.jsxs(Oe,{variant:"primary",onClick:()=>n(!0),children:[i.jsx(ar,{className:"w-4 h-4 mr-1"}),t("virtualPrinter.list.addFirst")]})]})}):i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 items-start",children:s.map(l=>i.jsx(Cet,{printer:l,models:o},l.id))}),e&&i.jsx(Tet,{onClose:()=>n(!1)})]})}function Pet(t){if(!t)return"-";const e=Jn(t);return e?e.toLocaleString():"-"}function CY({status:t}){if(!t)return null;const e={success:"bg-green-500/20 text-green-400",failed:"bg-red-500/20 text-red-400",skipped:"bg-yellow-500/20 text-yellow-400",running:"bg-blue-500/20 text-blue-400"},n={success:i.jsx(fr,{className:"w-3 h-3"}),failed:i.jsx(Vi,{className:"w-3 h-3"}),skipped:i.jsx($L,{className:"w-3 h-3"}),running:i.jsx(ht,{className:"w-3 h-3 animate-spin"})};return i.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium ${e[t]||"bg-gray-500/20 text-gray-400"}`,children:[n[t],t.charAt(0).toUpperCase()+t.slice(1)]})}function Met(){const t=an(),{showToast:e}=fn(),{t:n}=Ft(),[r,a]=w.useState(""),[s,o]=w.useState(""),[l,c]=w.useState("main"),[u,d]=w.useState(!1),[m,p]=w.useState("daily"),[f,y]=w.useState(!0),[v,x]=w.useState(!0),[g,_]=w.useState(!1),[N,T]=w.useState(!0),[C,A]=w.useState(!1),[k,R]=w.useState(!1),[P,D]=w.useState(""),[H,z]=w.useState(!1),[G,I]=w.useState(null),[ee,ie]=w.useState(null),X=w.useRef(null);w.useEffect(()=>{if(C||k){const L=F=>(F.preventDefault(),F.returnValue="A backup operation is in progress. Are you sure you want to leave?",F.returnValue);return window.addEventListener("beforeunload",L),()=>window.removeEventListener("beforeunload",L)}},[C,k]);const[me,he]=w.useState(!1),[ge,Y]=w.useState(null),oe=w.useRef(null),le=w.useRef(!1),{data:xe,isLoading:Pe}=et({queryKey:["github-backup-config"],queryFn:be.getGitHubBackupConfig}),{data:q}=et({queryKey:["github-backup-status"],queryFn:be.getGitHubBackupStatus,refetchInterval:ae=>ae.state.data?.is_running?500:1e4}),{data:Z}=et({queryKey:["github-backup-logs"],queryFn:()=>be.getGitHubBackupLogs(20)}),{data:j}=et({queryKey:["cloud-status"],queryFn:be.getCloudStatus}),{data:E}=et({queryKey:["printers"],queryFn:be.getPrinters}),U=Gf({queries:(E??[]).map(ae=>({queryKey:["printerStatus",ae.id],queryFn:()=>be.getPrinterStatus(ae.id),staleTime:1e4,refetchInterval:3e4}))}),K=(E??[]).map((ae,L)=>({printer:ae,connected:U[L]?.data?.connected??!1})),$=K.length,ne=K.filter(ae=>ae.connected).length,O=$>0&&ne===0,V=ne>0&&ne<$;w.useEffect(()=>{xe&&(a(xe.repository_url),c(xe.branch),d(xe.schedule_enabled),p(xe.schedule_type),y(xe.backup_kprofiles),x(xe.backup_cloud_profiles),_(xe.backup_settings),T(xe.enabled),o(""),setTimeout(()=>{le.current=!0},100))},[xe]);const J=w.useCallback(async(ae=!1)=>{if(xe?.has_token)try{ae&&s?(await be.saveGitHubBackupConfig({repository_url:r,access_token:s,branch:l,schedule_enabled:u,schedule_type:m,backup_kprofiles:f,backup_cloud_profiles:v,backup_settings:g,enabled:N}),o(""),e(n("backup.tokenUpdated"))):(await be.updateGitHubBackupConfig({repository_url:r,branch:l,schedule_enabled:u,schedule_type:m,backup_kprofiles:f,backup_cloud_profiles:v,backup_settings:g,enabled:N}),e(n("backup.settingsSaved"))),t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]})}catch(L){e(n("backup.failedToSave",{message:L.message}),"error")}},[xe?.has_token,r,s,l,u,m,f,v,g,N,t,e,n]);w.useEffect(()=>{if(!(!le.current||!xe?.has_token))return oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{J(!1)},500),()=>{oe.current&&clearTimeout(oe.current)}},[r,l,u,m,f,v,g,N,J,xe?.has_token]),w.useEffect(()=>{if(!(!le.current||!xe?.has_token||!s))return oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{J(!0)},1e3),()=>{oe.current&&clearTimeout(oe.current)}},[s,J,xe?.has_token]);const W=pt({mutationFn:ae=>be.saveGitHubBackupConfig(ae),onSuccess:()=>{t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]}),e(n("backup.githubBackupEnabled")),o(""),le.current=!0},onError:ae=>{e(n("backup.failedToSave",{message:ae.message}),"error")}}),re=pt({mutationFn:be.triggerGitHubBackup,onSuccess:ae=>{t.invalidateQueries({queryKey:["github-backup-status"]}),t.invalidateQueries({queryKey:["github-backup-logs"]}),ae.success?ae.files_changed>0?e(n("backup.backupCompleteFiles",{count:ae.files_changed})):e(n("backup.backupSkippedNoChanges")):e(n("backup.backupFailed2",{message:ae.message}),"error")},onError:ae=>{e(n("backup.backupFailed2",{message:ae.message}),"error")}}),ue=pt({mutationFn:()=>be.clearGitHubBackupLogs(0),onSuccess:ae=>{t.invalidateQueries({queryKey:["github-backup-logs"]}),e(n("backup.clearedLogs",{count:ae.deleted}))},onError:ae=>{e(n("backup.failedToClearLogs",{message:ae.message}),"error")}}),fe=async()=>{he(!0),Y(null);try{let ae;if(s){if(!r){e(n("backup.enterRepoUrl"),"error"),he(!1);return}ae=await be.testGitHubConnection(r,s)}else if(xe?.has_token)ae=await be.testGitHubStoredConnection();else{e(n("backup.enterRepoAndToken"),"error"),he(!1);return}Y({success:ae.success,message:ae.message})}catch(ae){Y({success:!1,message:ae.message})}finally{he(!1)}},ye=()=>{if(!r){e(n("backup.repoRequired"),"error");return}if(!s){e(n("backup.tokenRequired"),"error");return}W.mutate({repository_url:r,access_token:s,branch:l,schedule_enabled:u,schedule_type:m,backup_kprofiles:f,backup_cloud_profiles:v,backup_settings:g,enabled:N})};return Pe?i.jsx("div",{className:"flex items-center justify-center py-12",children:i.jsx(ht,{className:"w-8 h-8 animate-spin text-bambu-green"})}):i.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[i.jsxs("div",{className:"space-y-6",children:[i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(f3,{className:"w-5 h-5 text-gray-400"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.githubBackup")})]}),xe&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:n("backup.enabled")}),i.jsx(Bn,{checked:N,onChange:T})]})]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.githubDescription")}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.repositoryUrl")}),i.jsx("input",{type:"text",value:r,onChange:ae=>{a(ae.target.value),Y(null)},placeholder:"https://github.com/username/bambuddy-backup",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"})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[n("backup.personalAccessToken")," ",xe?.has_token&&i.jsx("span",{className:"text-green-400",children:n("backup.tokenSaved")})]}),i.jsx("input",{type:"password",value:s,onChange:ae=>{o(ae.target.value),Y(null)},placeholder:xe?.has_token?n("backup.enterNewToken"):"ghp_xxxxxxxxxxxx",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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("backup.tokenHint")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.branch")}),i.jsx("input",{type:"text",value:l,onChange:ae=>c(ae.target.value),placeholder:"main",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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.autoBackup")}),i.jsxs("select",{value:u?m:"disabled",onChange:ae=>{ae.target.value==="disabled"?d(!1):(d(!0),p(ae.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:[i.jsx("option",{value:"disabled",children:n("backup.manualOnly")}),i.jsx("option",{value:"hourly",children:n("backup.hourly")}),i.jsx("option",{value:"daily",children:n("backup.daily")}),i.jsx("option",{value:"weekly",children:n("backup.weekly")})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:n("backup.includeInBackup")}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("label",{className:`flex items-start gap-2 ${O?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:[i.jsx("input",{type:"checkbox",checked:f,onChange:ae=>y(ae.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:O}),i.jsxs("div",{className:"flex-1",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`text-sm ${O?"text-bambu-gray":"text-white"}`,children:n("backup.kProfiles")}),O&&i.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:[i.jsx(Mn,{className:"w-3 h-3"}),n("backup.noPrintersConnected")]}),V&&i.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:[i.jsx(Mn,{className:"w-3 h-3"}),n("backup.printersConnected",{connected:ne,total:$})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.kProfilesDescription")})]})]}),i.jsxs("label",{className:`flex items-start gap-2 ${j?.is_authenticated?"cursor-pointer":"cursor-not-allowed opacity-60"}`,children:[i.jsx("input",{type:"checkbox",checked:v,onChange:ae=>x(ae.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:!j?.is_authenticated}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`text-sm ${j?.is_authenticated?"text-white":"text-bambu-gray"}`,children:n("backup.cloudProfiles")}),!j?.is_authenticated&&i.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:[i.jsx(Mn,{className:"w-3 h-3"}),n("backup.cloudLoginRequiredShort")]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.cloudProfilesDescription")})]})]}),i.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:g,onChange:ae=>_(ae.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"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white text-sm",children:n("backup.appSettings")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.appSettingsDescription")})]})]})]})]}),i.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 space-y-3",children:[q?.configured&&i.jsxs("div",{className:"flex items-center justify-between text-sm",children:[i.jsx("div",{className:"flex items-center gap-2 text-bambu-gray",children:q.last_backup_at?i.jsxs(i.Fragment,{children:[i.jsxs("span",{children:[n("backup.lastBackupAt")," ",x0(q.last_backup_at,"system",n)]}),i.jsx(CY,{status:q.last_backup_status})]}):i.jsx("span",{children:n("backup.noBackupsYet")})}),q.next_scheduled_run&&i.jsxs("span",{className:"text-bambu-gray",children:[i.jsx(er,{className:"w-3 h-3 inline mr-1"}),n("backup.next")," ",x0(q.next_scheduled_run,"system",n)]})]}),ge&&i.jsxs("div",{className:`text-sm flex items-center gap-1 ${ge.success?"text-green-400":"text-red-400"}`,children:[ge.success?i.jsx(fr,{className:"w-4 h-4"}):i.jsx(Vi,{className:"w-4 h-4"}),ge.message]}),i.jsx("div",{className:"flex flex-wrap items-center gap-2",children:q?.configured?i.jsx(i.Fragment,{children:re.isPending||q.is_running?i.jsxs("div",{className:"flex items-center gap-2 text-bambu-green",children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),i.jsx("span",{className:"text-sm",children:q.progress||n("backup.startingBackup")})]}):i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"primary",size:"sm",onClick:()=>re.mutate(),disabled:!xe?.enabled,children:[i.jsx(go,{className:"w-4 h-4"}),n("backup.backupNow")]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:fe,disabled:me,children:[me?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(wr,{className:"w-4 h-4"}),n("backup.test")]})]})}):i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"primary",size:"sm",onClick:ye,disabled:W.isPending||!r||!s,children:[W.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(fr,{className:"w-4 h-4"}),n("backup.enableBackup")]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:fe,disabled:me||!r||!s,children:[me?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(wr,{className:"w-4 h-4"}),n("backup.testConnection")]})]})})]})]})]}),Z&&Z.length>0&&i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(f0,{className:"w-5 h-5 text-gray-400"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.history")})]}),i.jsxs(Oe,{variant:"ghost",size:"sm",onClick:()=>ue.mutate(),disabled:ue.isPending,children:[i.jsx(Jt,{className:"w-4 h-4"}),n("backup.clear")]})]})}),i.jsx(Dt,{children:i.jsx("div",{className:"overflow-x-auto",children:i.jsxs("table",{className:"w-full text-sm",children:[i.jsx("thead",{children:i.jsxs("tr",{className:"text-bambu-gray border-b border-bambu-dark-tertiary",children:[i.jsx("th",{className:"text-left py-2 px-2",children:n("backup.date")}),i.jsx("th",{className:"text-left py-2 px-2",children:n("backup.status")}),i.jsx("th",{className:"text-left py-2 px-2",children:n("backup.commit")})]})}),i.jsx("tbody",{children:Z.slice(0,10).map(ae=>i.jsxs("tr",{className:"border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-secondary",children:[i.jsx("td",{className:"py-2 px-2 text-white",children:Pet(ae.started_at)}),i.jsx("td",{className:"py-2 px-2",children:i.jsx(CY,{status:ae.status})}),i.jsx("td",{className:"py-2 px-2",children:ae.commit_sha?i.jsxs("a",{href:`${xe?.repository_url}/commit/${ae.commit_sha}`,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-green hover:underline inline-flex items-center gap-1",children:[ae.commit_sha.substring(0,7),i.jsx(Jr,{className:"w-3 h-3"})]}):i.jsx("span",{className:"text-bambu-gray",children:"-"})})]},ae.id))})]})})})]})]}),i.jsx("div",{className:"space-y-6",children:i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(au,{className:"w-5 h-5 text-gray-400"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.localBackup")})]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.localBackupDescription")}),i.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:n("backup.downloadBackupLabel")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.completeBackupZip")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",disabled:C||k,onClick:async()=>{A(!0),D(n("backup.preparingBackup"));try{D(n("backup.creatingArchive"));const{blob:ae,filename:L}=await be.exportBackup();D(n("backup.downloadingFile"));const F=URL.createObjectURL(ae),te=document.createElement("a");te.href=F,te.download=L,te.click(),URL.revokeObjectURL(F),e(n("backup.backupDownloaded"))}catch(ae){e(n("backup.failedToCreateBackup",{message:ae instanceof Error?ae.message:"Unknown error"}),"error")}finally{A(!1),D("")}},children:[i.jsx(pi,{className:"w-4 h-4"}),n("backup.download")]})]}),i.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:n("backup.restoreBackup")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.restoreDescription")}),i.jsx("p",{className:"text-xs text-bambu-gray-light mt-1",children:n("backup.restoreNote")})]}),i.jsx("input",{ref:X,type:"file",accept:".zip",className:"hidden",onChange:ae=>{const L=ae.target.files?.[0];L&&(I(L),z(!0)),ae.target.value=""}}),i.jsxs(Oe,{variant:"secondary",size:"sm",disabled:k||C,onClick:()=>X.current?.click(),children:[i.jsx(xi,{className:"w-4 h-4"}),n("backup.restore")]})]}),ee&&i.jsx("div",{className:`p-3 rounded-lg ${ee.success?"bg-green-500/10 border border-green-500/30":"bg-red-500/10 border border-red-500/30"}`,children:i.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[ee.success?i.jsx(fr,{className:"w-4 h-4 text-green-400 mt-0.5 flex-shrink-0"}):i.jsx(Vi,{className:"w-4 h-4 text-red-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:ee.success?"text-green-200":"text-red-200",children:[ee.message,ee.success&&i.jsx("div",{className:"mt-2",children:i.jsxs(Oe,{size:"sm",onClick:()=>window.location.reload(),children:[i.jsx(bo,{className:"w-3 h-3"}),n("backup.reloadNow")]})})]})]})}),i.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:i.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[i.jsx(Mn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"text-yellow-200",children:[i.jsx("span",{className:"font-medium",children:n("backup.restoreReplacesAll")})," ",i.jsx("span",{className:"text-yellow-200/70",children:n("backup.restoreReplacesAllDetail")})]})]})})]})]})}),H&&G&&i.jsx(Sn,{title:n("backup.restoreConfirmTitle"),message:n("backup.restoreConfirmMessage",{filename:G.name}),confirmText:n("backup.restoreConfirmButton"),variant:"danger",onConfirm:async()=>{z(!1),R(!0),ie(null);try{D(n("backup.uploadingFile"));const ae=await be.importBackup(G);ie(ae),ae.success?e(n("backup.backupRestoredRestart"),"success"):e(ae.message,"error")}catch(ae){const L=ae instanceof Error?ae.message:n("backup.failedToRestore");ie({success:!1,message:L}),e(L,"error")}finally{R(!1),D(""),I(null)}},onCancel:()=>{z(!1),I(null)}}),(C||k)&&i.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-[100]",children:i.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:[i.jsx("div",{className:"flex justify-center mb-4",children:i.jsxs("div",{className:"relative",children:[i.jsx("div",{className:"w-16 h-16 border-4 border-bambu-dark-tertiary rounded-full"}),i.jsx("div",{className:"w-16 h-16 border-4 border-bambu-green border-t-transparent rounded-full absolute inset-0 animate-spin"})]})}),i.jsx("h3",{className:"text-xl font-semibold text-white mb-2",children:n(C?"backup.creatingBackup":"backup.restoringBackup")}),i.jsx("p",{className:"text-bambu-gray mb-4",children:P||n(C?"backup.preparing":"backup.processing")}),i.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:i.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[i.jsx(Mn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),i.jsx("p",{className:"text-yellow-200 text-left",children:n("backup.doNotClosePage")})]})})]})})]})}const Eet={starttls:587,ssl:465,none:25},jet={587:"starttls",465:"ssl",25:"none"};function Det(){const{t}=Ft(),{showToast:e}=fn(),n=an(),[r,a]=w.useState({smtp_host:"",smtp_port:587,smtp_username:"",smtp_password:"",smtp_security:"starttls",smtp_auth_enabled:!0,smtp_from_email:"",smtp_from_name:"BamBuddy"}),[s,o]=w.useState(""),{data:l,isLoading:c}=et({queryKey:["smtpSettings"],queryFn:()=>be.getSMTPSettings()}),{authEnabled:u}=_r(),{data:d}=et({queryKey:["advancedAuthStatus"],queryFn:()=>be.getAdvancedAuthStatus()});w.useEffect(()=>{l&&a({...l,smtp_password:""})},[l]);const m=k=>{a({...r,smtp_security:k,smtp_port:Eet[k]})},p=k=>{const R=jet[k];a({...r,smtp_port:k,...R?{smtp_security:R}:{}})},f=k=>{a({...r,smtp_auth_enabled:k,...k?{}:{smtp_username:"",smtp_password:""}})},y=pt({mutationFn:k=>be.saveSMTPSettings(k),onSuccess:()=>{n.invalidateQueries({queryKey:["smtpSettings"]}),n.invalidateQueries({queryKey:["advancedAuthStatus"]}),e(t("settings.email.success.settingsSaved"),"success")},onError:k=>{e(k.message,"error")}}),v=pt({mutationFn:k=>be.testSMTP(k),onSuccess:k=>{e(k.message,k.success?"success":"error")},onError:k=>{e(k.message,"error")}}),x=pt({mutationFn:k=>k?be.enableAdvancedAuth():be.disableAdvancedAuth(),onSuccess:k=>{n.invalidateQueries({queryKey:["advancedAuthStatus"]}),e(k.message,"success")},onError:k=>{e(k.message,"error")}}),g=()=>{if(!r.smtp_host||!r.smtp_from_email){e(t("settings.email.errors.requiredFields"),"error");return}if(r.smtp_auth_enabled&&!r.smtp_username){e(t("settings.email.errors.usernameRequired"),"error");return}y.mutate(r)},_=()=>{if(!s){e(t("settings.email.errors.enterTestEmail"),"error");return}v.mutate({test_recipient:s})},N=()=>{if(!u){e(t("settings.email.errors.enableAuthFirst"),"error");return}if(!d?.advanced_auth_enabled&&!d?.smtp_configured){e(t("settings.email.errors.configureSmtpFirst"),"error");return}x.mutate(!d?.advanced_auth_enabled)};if(c)return i.jsx("div",{className:"flex items-center justify-center p-12",children:i.jsx(ht,{className:"w-8 h-8 animate-spin text-bambu-green"})});const T=d?.advanced_auth_enabled??!1,C="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",A="w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white/40 placeholder-bambu-gray/40 cursor-not-allowed";return i.jsxs("div",{className:"space-y-6",children:[i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(ix,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.advancedAuth")||"Advanced Authentication"})]}),i.jsx(Oe,{onClick:N,disabled:x.isPending,variant:T?"danger":"primary",children:T?i.jsxs(i.Fragment,{children:[i.jsx(K1,{className:"w-4 h-4"}),t("settings.email.disable")||"Disable"]}):i.jsxs(i.Fragment,{children:[i.jsx(Ap,{className:"w-4 h-4"}),t("settings.email.enable")||"Enable"]})})]})}),i.jsx(Dt,{children:i.jsx("div",{className:"space-y-4",children:T?i.jsx("div",{className:"bg-green-500/10 border border-green-500/30 rounded-lg p-4",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(fr,{className:"w-5 h-5 text-green-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-white font-medium",children:t("settings.email.advancedAuthEnabled")||"Advanced Authentication is enabled"}),i.jsxs("ul",{className:"text-sm text-green-300 space-y-1 list-disc list-inside",children:[i.jsx("li",{children:t("settings.email.feature1")||"Passwords are auto-generated and emailed to new users"}),i.jsx("li",{children:t("settings.email.feature2")||"Users can login with username or email"}),i.jsx("li",{children:t("settings.email.feature3")||"Forgot password feature is available"}),i.jsx("li",{children:t("settings.email.feature4")||"Admins can reset user passwords via email"})]})]})]})}):i.jsx("div",{className:"bg-yellow-500/10 border border-yellow-500/30 rounded-lg p-4",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Mn,{className:"w-5 h-5 text-yellow-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-white font-medium",children:t("settings.email.advancedAuthDisabled")||"Advanced Authentication is disabled"}),i.jsx("p",{className:"text-sm text-yellow-300",children:t("settings.email.advancedAuthDisabledDesc")||"Enable advanced authentication to activate email-based features for user management."})]})]})})})})]}),i.jsx("div",{children:i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.smtpSettings")||"SMTP Configuration"})}),i.jsx(Dt,{children:i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.authentication")||"Authentication"}),i.jsxs("select",{value:r.smtp_auth_enabled?"true":"false",onChange:k=>f(k.target.value==="true"),className:C,children:[i.jsx("option",{value:"true",children:t("settings.email.authOptions.enabled")}),i.jsx("option",{value:"false",children:t("settings.email.authOptions.disabled")})]})]}),i.jsxs("div",{className:`grid grid-cols-1 md:grid-cols-2 gap-4 transition-opacity ${r.smtp_auth_enabled?"":"opacity-40 pointer-events-none"}`,children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.username")||"Username"}),i.jsx("input",{type:"text",value:r.smtp_username||"",onChange:k=>a({...r,smtp_username:k.target.value}),placeholder:"your.email@gmail.com",disabled:!r.smtp_auth_enabled,className:r.smtp_auth_enabled?C:A})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.password")||"Password"}),i.jsx("input",{type:"password",value:r.smtp_password||"",onChange:k=>a({...r,smtp_password:k.target.value}),placeholder:l?"••••••••":"App password",disabled:!r.smtp_auth_enabled,className:r.smtp_auth_enabled?C:A})]})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[t("settings.email.smtpHost")||"SMTP Server"," *"]}),i.jsx("input",{type:"text",value:r.smtp_host,onChange:k=>a({...r,smtp_host:k.target.value}),placeholder:"smtp.gmail.com",className:C})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.smtpPort")||"SMTP Port"}),i.jsx("input",{type:"number",value:r.smtp_port,onChange:k=>p(parseInt(k.target.value)||587),placeholder:"587",className:C})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.security")||"Security"}),i.jsxs("select",{value:r.smtp_security,onChange:k=>m(k.target.value),className:C,children:[i.jsx("option",{value:"starttls",children:t("settings.email.securityOptions.starttls")}),i.jsx("option",{value:"ssl",children:t("settings.email.securityOptions.ssl")}),i.jsx("option",{value:"none",children:t("settings.email.securityOptions.none")})]})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[t("settings.email.fromEmail")||"From Email"," *"]}),i.jsx("input",{type:"email",value:r.smtp_from_email,onChange:k=>a({...r,smtp_from_email:k.target.value}),placeholder:"your@email.com",className:C})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.fromName")||"From Name"}),i.jsx("input",{type:"text",value:r.smtp_from_name,onChange:k=>a({...r,smtp_from_name:k.target.value}),placeholder:"BamBuddy",className:C})]})]}),i.jsx("div",{className:"flex gap-2",children:i.jsx(Oe,{onClick:g,disabled:y.isPending,className:"flex-1",children:y.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),t("settings.email.saving")||"Saving..."]}):t("settings.email.save")||"Save Settings"})})]})})]})}),i.jsx("div",{children:i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.testConnection")||"Test SMTP Connection"})}),i.jsx(Dt,{children:i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.testRecipient")||"Test Recipient Email"}),i.jsx("input",{type:"email",value:s,onChange:k=>o(k.target.value),placeholder:"test@example.com",className:C})]}),i.jsx(Oe,{onClick:_,disabled:v.isPending,variant:"secondary",children:v.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),t("settings.email.sending")||"Sending..."]}):i.jsxs(i.Fragment,{children:[i.jsx(rT,{className:"w-4 h-4"}),t("settings.email.sendTest")||"Send Test Email"]})})]})})]})})]})}const Ret={get:"bg-blue-500/20 text-blue-400 border-blue-500/30",post:"bg-green-500/20 text-green-400 border-green-500/30",put:"bg-yellow-500/20 text-yellow-400 border-yellow-500/30",patch:"bg-orange-500/20 text-orange-400 border-orange-500/30",delete:"bg-red-500/20 text-red-400 border-red-500/30"};function Fet(t,e){const n=e.replace("#/","").split("/");let r=t;for(const a of n)r=r[a];return r}function Ov(t,e,n=0){if(n>5)return"...";if(e.$ref)return Ov(t,Fet(t,e.$ref),n+1);if(e.allOf){const r={};for(const a of e.allOf){const s=Ov(t,a,n+1);typeof s=="object"&&s!==null&&Object.assign(r,s)}return r}if(e.example!==void 0)return e.example;if(e.default!==void 0)return e.default;switch(e.type){case"string":return e.enum?e.enum[0]:"string";case"integer":case"number":return 0;case"boolean":return!1;case"array":return e.items?[Ov(t,e.items,n+1)]:[];case"object":if(e.properties){const r={};for(const[a,s]of Object.entries(e.properties))r[a]=Ov(t,s,n+1);return r}return{};default:return null}}function Let({path:t,method:e,spec:n,schema:r,apiKey:a}){const[s,o]=w.useState(!1),[l,c]=w.useState({}),[u,d]=w.useState(""),[m,p]=w.useState(null),[f,y]=w.useState(!1),[v,x]=w.useState(!1);w.useEffect(()=>{if(s&&n.parameters){const R={};for(const P of n.parameters)P.schema?.default!==void 0&&(R[P.name]=String(P.schema.default));c(P=>({...R,...P}))}},[s,n.parameters]),w.useEffect(()=>{if(s&&n.requestBody?.content?.["application/json"]?.schema&&!u){const R=n.requestBody.content["application/json"].schema,P=Ov(r,R);d(JSON.stringify(P,null,2))}},[s,n.requestBody,r,u]);const _=(()=>{const R=[];for(const P of n.parameters||[])if(P.in==="path"||P.required){const D=l[P.name];(D===void 0||D==="")&&R.push(P.name)}return R})(),N=async()=>{if(_.length>0){p({status:0,statusText:"Validation Error",headers:{},body:`Missing required parameters: ${_.join(", ")}`,duration:0});return}y(!0),p(null);try{let R=t;const P=new URLSearchParams;for(const ge of n.parameters||[]){const Y=l[ge.name];Y!==void 0&&Y!==""&&(ge.in==="path"?R=R.replace(`{${ge.name}}`,encodeURIComponent(Y)):ge.in==="query"&&P.append(ge.name,Y))}const D=P.toString(),H=`${R}${D?`?${D}`:""}`,z={"Content-Type":"application/json"};a&&(z["X-API-Key"]=a);const G={method:e.toUpperCase(),headers:z};["post","put","patch"].includes(e)&&u&&(G.body=u);const I=performance.now(),ee=await fetch(H,G),ie=Math.round(performance.now()-I),X={};ee.headers.forEach((ge,Y)=>{X[Y]=ge});let me;ee.headers.get("content-type")?.includes("application/json")?me=await ee.json():me=await ee.text(),p({status:ee.status,statusText:ee.statusText,headers:X,body:me,duration:ie})}catch(R){p({status:0,statusText:"Network Error",headers:{},body:R instanceof Error?R.message:"Unknown error",duration:0})}finally{y(!1)}},T=async()=>{if(m){const R=typeof m.body=="string"?m.body:JSON.stringify(m.body,null,2);try{await navigator.clipboard.writeText(R),x(!0),setTimeout(()=>x(!1),2e3)}catch{const P=document.createElement("textarea");P.value=R,P.style.position="fixed",P.style.left="-999999px",document.body.appendChild(P),P.select(),document.execCommand("copy"),document.body.removeChild(P),x(!0),setTimeout(()=>x(!1),2e3)}}},C=(n.parameters||[]).filter(R=>R.in==="path"),A=(n.parameters||[]).filter(R=>R.in==="query"),k=["post","put","patch"].includes(e)&&n.requestBody;return i.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[i.jsxs("button",{onClick:()=>o(!s),className:"w-full flex items-center gap-3 p-3 hover:bg-bambu-dark-tertiary/50 transition-colors text-left",children:[s?i.jsx(Ln,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}):i.jsx(ha,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),i.jsx("span",{className:`px-2 py-0.5 text-xs font-mono font-semibold uppercase rounded border ${Ret[e]||"bg-gray-500/20 text-gray-400"}`,children:e}),i.jsx("code",{className:"text-sm text-white font-mono flex-1 truncate",children:t}),n.summary&&i.jsx("span",{className:"text-sm text-bambu-gray truncate max-w-[40%]",children:n.summary})]}),s&&i.jsxs("div",{className:"border-t border-bambu-dark-tertiary p-4 space-y-4 bg-bambu-dark/50",children:[n.description&&i.jsx("p",{className:"text-sm text-bambu-gray",children:n.description}),C.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("h4",{className:"text-sm font-medium text-white",children:"Path Parameters"}),i.jsx("div",{className:"space-y-2",children:C.map(R=>i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[R.name,R.required&&i.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),i.jsx("input",{type:"text",value:l[R.name]||"",onChange:P=>c(D=>({...D,[R.name]:P.target.value})),placeholder:R.description||R.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"})]},R.name))})]}),A.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("h4",{className:"text-sm font-medium text-white",children:"Query Parameters"}),i.jsx("div",{className:"space-y-2",children:A.map(R=>i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[R.name,R.required&&i.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),R.schema?.enum?i.jsxs("select",{value:l[R.name]||"",onChange:P=>c(D=>({...D,[R.name]:P.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:[i.jsx("option",{value:"",children:"-- Select --"}),R.schema.enum.map(P=>i.jsx("option",{value:P,children:P},P))]}):i.jsx("input",{type:"text",value:l[R.name]||"",onChange:P=>c(D=>({...D,[R.name]:P.target.value})),placeholder:R.description||R.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"})]},R.name))})]}),k&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("h4",{className:"text-sm font-medium text-white",children:"Request Body"}),i.jsx("textarea",{value:u,onChange:R=>d(R.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..."})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs(Oe,{onClick:N,disabled:f,children:[f?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(go,{className:"w-4 h-4"}),"Execute"]}),_.length>0&&i.jsxs("span",{className:"text-xs text-yellow-400 flex items-center gap-1",children:[i.jsx(Li,{className:"w-3 h-3"}),"Fill in: ",_.join(", ")]})]}),m&&i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h4",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Response",i.jsxs("span",{className:`px-2 py-0.5 text-xs rounded ${m.status>=200&&m.status<300?"bg-green-500/20 text-green-400":m.status>=400?"bg-red-500/20 text-red-400":"bg-yellow-500/20 text-yellow-400"}`,children:[m.status," ",m.statusText]}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:[m.duration,"ms"]})]}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:T,children:v?i.jsx(fr,{className:"w-3 h-3 text-green-400"}):i.jsx(fo,{className:"w-3 h-3"})})]}),i.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 m.body=="string"?m.body:JSON.stringify(m.body,null,2)})]})]})]})}function Oet({apiKey:t=""}){const[e,n]=w.useState(null),[r,a]=w.useState(!0),[s,o]=w.useState(null),[l,c]=w.useState(new Set),[u,d]=w.useState("");if(w.useEffect(()=>{async function x(){try{const g=await fetch("/openapi.json");if(!g.ok)throw new Error("Failed to fetch OpenAPI schema");const _=await g.json();n(_)}catch(g){o(g instanceof Error?g.message:"Unknown error")}finally{a(!1)}}x()},[]),r)return i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})});if(s||!e)return i.jsx(Mt,{children:i.jsx(Dt,{className:"py-8",children:i.jsxs("div",{className:"text-center text-red-400",children:[i.jsx(Li,{className:"w-12 h-12 mx-auto mb-3 opacity-50"}),i.jsx("p",{children:"Failed to load API schema"}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:s})]})})});const m={};for(const[x,g]of Object.entries(e.paths))for(const[_,N]of Object.entries(g)){if(_==="parameters")continue;const T=N.tags||["Other"];for(const C of T)m[C]||(m[C]=[]),m[C].push({path:x,method:_,spec:N})}const p=Object.entries(m).map(([x,g])=>{if(!u)return{tag:x,endpoints:g};const _=g.filter(({path:N,method:T,spec:C})=>{const A=u.toLowerCase();return N.toLowerCase().includes(A)||T.toLowerCase().includes(A)||(C.summary?.toLowerCase()||"").includes(A)||(C.description?.toLowerCase()||"").includes(A)});return{tag:x,endpoints:_}}).filter(({endpoints:x})=>x.length>0).sort((x,g)=>x.tag.localeCompare(g.tag)),f=x=>{c(g=>{const _=new Set(g);return _.has(x)?_.delete(x):_.add(x),_})},y=()=>{c(new Set(p.map(x=>x.tag)))},v=()=>{c(new Set)};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between gap-4",children:[i.jsx("div",{className:"flex-1",children:i.jsx("input",{type:"text",value:u,onChange:x=>d(x.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"})}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Oe,{variant:"secondary",size:"sm",onClick:y,children:"Expand All"}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:v,children:"Collapse All"}),i.jsxs("a",{href:"/docs",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-sm text-bambu-green hover:underline",children:[i.jsx(Jr,{className:"w-4 h-4"}),"Swagger UI"]})]})]}),i.jsxs("p",{className:"text-sm text-bambu-gray",children:[p.reduce((x,g)=>x+g.endpoints.length,0)," endpoints in ",p.length," categories"]}),i.jsx("div",{className:"space-y-3",children:p.map(({tag:x,endpoints:g})=>i.jsxs(Mt,{children:[i.jsx("button",{onClick:()=>f(x),className:"w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/30 transition-colors text-left",children:i.jsxs("div",{className:"flex items-center gap-2",children:[l.has(x)?i.jsx(Ln,{className:"w-5 h-5 text-bambu-gray"}):i.jsx(ha,{className:"w-5 h-5 text-bambu-gray"}),i.jsx("h3",{className:"text-base font-semibold text-white capitalize",children:x.replace(/-/g," ")}),i.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-2 py-0.5 rounded-full text-bambu-gray",children:g.length})]})}),l.has(x)&&i.jsx(Dt,{className:"pt-0 space-y-2",children:g.map(({path:_,method:N,spec:T})=>i.jsx(Let,{path:_,method:N,spec:T,schema:e,apiKey:t},`${N}-${_}`))})]},x))})]})}const Iet=["general","network","plugs","notifications","filament","apikeys","virtual-printer","users","backup"],zet={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"},TY=["bg-blue-500","bg-green-500","bg-yellow-500","bg-red-500","bg-orange-500","bg-teal-500","bg-cyan-500","bg-purple-500"],AY=(t,e)=>zet[t]||TY[e%TY.length];function Uet(){const t=an(),e=Qo(),[n,r]=ML(),{t:a,i18n:s}=Ft(),{showToast:o}=fn(),{authEnabled:l,user:c,refreshAuth:u}=_r(),{mode:d,darkStyle:m,darkBackground:p,darkAccent:f,lightStyle:y,lightBackground:v,lightAccent:x,setDarkStyle:g,setDarkBackground:_,setDarkAccent:N,setLightStyle:T,setLightBackground:C,setLightAccent:A}=Wf(),[k,R]=w.useState(null),[P,D]=w.useState(!1),[H,z]=w.useState(null),[G,I]=w.useState(!1),[ee,ie]=w.useState(null),[X,me]=w.useState(null),[he,ge]=w.useState(!1),[Y,oe]=w.useState(cQ()),le=n.get("tab"),xe=le==="email",Pe=xe?"users":le&&Iet.includes(le)?le:"general",[q,Z]=w.useState(Pe),[j,E]=w.useState(xe?"email":"users"),U=_e=>{Z(_e),_e==="users"&&E("users"),_e==="general"?n.delete("tab"):n.set("tab",_e),r(n,{replace:!0})},[K,$]=w.useState(!1),[ne,O]=w.useState(""),[V,J]=w.useState({can_queue:!0,can_control_printer:!1,can_read_status:!0}),[W,re]=w.useState(null),[ue,fe]=w.useState(null),[ye,ae]=w.useState(""),[L,F]=w.useState(!1),[te,ve]=w.useState(!1),[pe,de]=w.useState(null),[Ne,Se]=w.useState(!1),[Le,qe]=w.useState(!1),[Ee,Te]=w.useState(!1),[Ae,Be]=w.useState({currentPassword:"",newPassword:"",confirmPassword:""}),[je,Xe]=w.useState(!1),[ce,Ie]=w.useState(!1),[Ce,Ge]=w.useState(!1),[$e,Ue]=w.useState(!1),[De,Ve]=w.useState(null),[it,xt]=w.useState(null),[Nt,kt]=w.useState(null),[We,yt]=w.useState(!1),[wt,_t]=w.useState({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),[Ot,Vt]=w.useState(null),[Xt,Qe]=w.useState(null),[Qt,hn]=w.useState(!1),[jn,kn]=w.useState({}),[Fe,tt]=w.useState({}),ut=_e=>{oe(_e),uxe(_e),o(a("settings.toast.settingsSaved"),"success")},Ze=()=>{localStorage.removeItem("sidebarOrder"),window.location.reload()},{data:ke,isLoading:ot}=et({queryKey:["settings"],queryFn:be.getSettings}),{data:se,isLoading:He,isFetching:Ke}=et({queryKey:["storage-usage"],queryFn:()=>be.getStorageUsage(),enabled:q==="general",staleTime:1/0,refetchInterval:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1}),Ye=async()=>{Ie(!0);try{const _e=await be.getStorageUsage({refresh:!0});t.setQueryData(["storage-usage"],_e)}catch(_e){const zt=_e instanceof Error?_e.message:"Failed to refresh storage usage";o(zt,"error")}finally{Ie(!1)}},{data:Me,isLoading:dt}=et({queryKey:["smart-plugs"],queryFn:be.getSmartPlugs}),{data:ct,isLoading:nt}=et({queryKey:["smart-plugs-energy",Me?.map(_e=>_e.id)],queryFn:async()=>{if(!Me||Me.length===0)return null;const _e=await Promise.all(Me.filter(un=>un.enabled).map(async un=>{try{const In=await be.getSmartPlugStatus(un.id);return{plug:un,status:In}}catch{return{plug:un,status:null}}}));let zt=0,mt=0,Pt=0,rn=0,rt=0;for(const{plug:un,status:In}of _e){const Vn=un.plug_type==="mqtt"&&In?.energy?.power!=null;(In?.reachable||Vn)&&In?.energy&&(rt++,In.energy?.power!=null&&(zt+=In.energy.power),In.energy?.today!=null&&(mt+=In.energy.today),In.energy?.yesterday!=null&&(Pt+=In.energy.yesterday),In.energy?.total!=null&&(rn+=In.energy.total))}return{totalPower:zt,totalToday:mt,totalYesterday:Pt,totalLifetime:rn,reachableCount:rt,totalPlugs:Me.filter(un=>un.enabled).length}},enabled:q==="plugs"&&!!Me&&Me.length>0,refetchInterval:q==="plugs"?1e4:!1}),{data:bt,isLoading:Ut}=et({queryKey:["notification-providers"],queryFn:be.getNotificationProviders}),{data:Et,isLoading:It}=et({queryKey:["api-keys"],queryFn:be.getAPIKeys}),Zt=pt({mutationFn:_e=>be.createAPIKey(_e),onSuccess:_e=>{re(_e.key||null),$(!1),O(""),t.invalidateQueries({queryKey:["api-keys"]}),o(a("settings.toast.apiKeyCreated"))},onError:_e=>{o(`Failed to create API key: ${_e.message}`,"error")}}),tn=pt({mutationFn:_e=>be.deleteAPIKey(_e),onSuccess:()=>{t.invalidateQueries({queryKey:["api-keys"]}),o(a("settings.toast.apiKeyDeleted"))},onError:_e=>{o(`Failed to delete API key: ${_e.message}`,"error")}}),{data:yn}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:_n,isLoading:qn}=et({queryKey:["notification-templates"],queryFn:be.getNotificationTemplates}),{data:sn}=et({queryKey:["virtual-printer-settings"],queryFn:Bbe.getSettings,refetchInterval:1e4}),Cn=sn?.status?.running??!1,{data:gn}=et({queryKey:["ffmpeg-status"],queryFn:be.checkFfmpeg}),{data:Qr}=et({queryKey:["version"],queryFn:be.getVersion}),{data:Tn,refetch:hr,isRefetching:_a}=et({queryKey:["updateCheck"],queryFn:be.checkForUpdates,enabled:ke?.check_updates!==!1,staleTime:300*1e3}),{data:On,refetch:$r}=et({queryKey:["updateStatus"],queryFn:be.getUpdateStatus,refetchInterval:_e=>{const zt=_e.state.data;return zt?.status==="downloading"||zt?.status==="installing"?1e3:!1}}),{data:cr}=et({queryKey:["mqtt-status"],queryFn:be.getMQTTStatus,refetchInterval:q==="network"?5e3:!1}),{data:li}=et({queryKey:["github-backup-status"],queryFn:be.getGitHubBackupStatus}),{data:_i}=et({queryKey:["cloud-status"],queryFn:be.getCloudStatus}),{data:Tr={advanced_auth_enabled:!1,smtp_configured:!1}}=et({queryKey:["advancedAuthStatus"],queryFn:()=>be.getAdvancedAuthStatus()}),{hasPermission:zi}=_r(),{data:Zd=[],isLoading:Yh}=et({queryKey:["users"],queryFn:()=>be.getUsers(),enabled:l&&zi("users:read")}),{data:Ss=[],isLoading:eg}=et({queryKey:["groups"],queryFn:()=>be.getGroups(),enabled:l&&zi("groups:read")}),Yl=pt({mutationFn:_e=>be.createUser(_e),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),Ge(!1),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),o(a("settings.toast.userCreated"))},onError:_e=>{o(_e.message,"error")}}),_s=pt({mutationFn:({id:_e,data:zt})=>be.updateUser(_e,zt),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),Ue(!1),Ve(null),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),o(a("settings.toast.userUpdated"))},onError:_e=>{o(_e.message,"error")}}),ci=pt({mutationFn:({id:_e,deleteItems:zt})=>be.deleteUser(_e,zt),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),o(a("settings.toast.userDeleted")),xt(null),kt(null)},onError:_e=>{o(_e.message,"error")}}),Xl=pt({mutationFn:_e=>be.resetUserPassword({user_id:_e}),onSuccess:_e=>{o(_e.message,"success")},onError:_e=>{o(_e.message,"error")}}),Ns=async _e=>{xt(_e),yt(!0);try{const zt=await be.getUserItemsCount(_e);kt(zt)}catch{kt({archives:0,queue_items:0,library_files:0})}finally{yt(!1)}},Zo=pt({mutationFn:_e=>be.deleteGroup(_e),onSuccess:()=>{t.invalidateQueries({queryKey:["groups"]}),o(a("settings.toast.groupDeleted"))},onError:_e=>{o(_e.message,"error")}}),Jo=()=>{const _e=Tr?.advanced_auth_enabled||!1;if(!wt.username){o(a("settings.toast.fillRequiredFields"),"error");return}if(_e&&!wt.email){o("Email is required when advanced authentication is enabled","error");return}if(!_e){if(!wt.password){o(a("settings.toast.fillRequiredFields"),"error");return}if(wt.password!==wt.confirmPassword){o(a("settings.toast.passwordsDoNotMatch"),"error");return}if(wt.password.length<6){o(a("settings.toast.passwordTooShort"),"error");return}}Yl.mutate({username:wt.username,password:_e?void 0:wt.password,email:wt.email||void 0,role:wt.role,group_ids:wt.group_ids.length>0?wt.group_ids:void 0})},el=_e=>{if(wt.password){if(wt.password!==wt.confirmPassword){o(a("settings.toast.passwordsDoNotMatch"),"error");return}if(wt.password.length<6){o(a("settings.toast.passwordTooShort"),"error");return}}const zt={username:wt.username||void 0,password:wt.password||void 0,email:wt.email||void 0,role:wt.role,group_ids:wt.group_ids};zt.password||delete zt.password,_s.mutate({id:_e,data:zt})},Xh=_e=>{Ve(_e.id),_t({username:_e.username,password:"",email:_e.email||"",confirmPassword:"",role:_e.role,group_ids:_e.groups?.map(zt=>zt.id)||[]}),Ue(!0)},Ql=_e=>{_t(zt=>({...zt,group_ids:zt.group_ids.includes(_e)?zt.group_ids.filter(mt=>mt!==_e):[...zt.group_ids,_e]}))},Ys=pt({mutationFn:be.applyUpdate,onSuccess:_e=>{_e.is_docker?o(_e.message,"error"):$r()}}),[Ui,Nu]=w.useState(null),Zl=pt({mutationFn:be.testAllNotificationProviders,onSuccess:_e=>{Nu(_e),t.invalidateQueries({queryKey:["notification-providers"]}),_e.failed===0?o(`All ${_e.tested} providers tested successfully!`,"success"):o(`${_e.success}/${_e.tested} providers succeeded`,_e.failed>0?"error":"success")},onError:_e=>{o(`Failed to test providers: ${_e.message}`,"error")}}),Bi=pt({mutationFn:async _e=>{if(!Me)return{success:0,failed:0};const zt=Me.filter(Pt=>Pt.enabled),mt=await Promise.all(zt.map(async Pt=>{try{return await be.controlSmartPlug(Pt.id,_e),{success:!0}}catch{return{success:!1}}}));return{success:mt.filter(Pt=>Pt.success).length,failed:mt.filter(Pt=>!Pt.success).length}},onSuccess:(_e,zt)=>{t.invalidateQueries({queryKey:["smart-plugs"]}),t.invalidateQueries({queryKey:["smart-plugs-energy"]}),_e.failed===0?o(`All ${_e.success} plugs turned ${zt}`,"success"):o(`${_e.success} plugs turned ${zt}, ${_e.failed} failed`,"error")},onError:_e=>{o(`Failed: ${_e.message}`,"error")}}),tl=w.useRef(null),nl=w.useRef(!1),Qh=w.useRef(!0);w.useEffect(()=>{if(ke&&!k){const _e={...ke,external_url:ke.external_url||window.location.origin};R(_e),setTimeout(()=>{Qh.current=!1},100)}},[ke,k]);const ku=pt({mutationFn:be.updateSettings,onSuccess:_e=>{t.setQueryData(["settings"],_e),t.invalidateQueries({queryKey:["archiveStats"]}),o(a("settings.toast.settingsSaved"),"success")},onError:_e=>{o(`Failed to save: ${_e.message}`,"error")},onSettled:()=>{nl.current=!1}}),ks=pt({mutationFn:({id:_e,data:zt})=>be.updatePrinter(_e,zt),onSuccess:()=>{t.invalidateQueries({queryKey:["printers"]}),o(a("settings.toast.cameraSettingsSaved"),"success")},onError:_e=>{o(`Failed to update printer: ${_e.message}`,"error")}});w.useEffect(()=>{if(!(Qh.current||!k||!ke||!(ke.auto_archive!==k.auto_archive||ke.save_thumbnails!==k.save_thumbnails||ke.capture_finish_photo!==k.capture_finish_photo||ke.default_filament_cost!==k.default_filament_cost||ke.currency!==k.currency||ke.energy_cost_per_kwh!==k.energy_cost_per_kwh||ke.energy_tracking_mode!==k.energy_tracking_mode||ke.check_updates!==k.check_updates||(ke.check_printer_firmware??!0)!==(k.check_printer_firmware??!0)||(ke.include_beta_updates??!1)!==(k.include_beta_updates??!1)||ke.notification_language!==k.notification_language||(ke.bed_cooled_threshold??35)!==(k.bed_cooled_threshold??35)||ke.ams_humidity_good!==k.ams_humidity_good||ke.ams_humidity_fair!==k.ams_humidity_fair||ke.ams_temp_good!==k.ams_temp_good||ke.ams_temp_fair!==k.ams_temp_fair||ke.ams_history_retention_days!==k.ams_history_retention_days||ke.disable_filament_warnings!==k.disable_filament_warnings||(ke.queue_drying_enabled??!1)!==(k.queue_drying_enabled??!1)||(ke.queue_drying_block??!1)!==(k.queue_drying_block??!1)||(ke.ambient_drying_enabled??!1)!==(k.ambient_drying_enabled??!1)||(ke.drying_presets??"")!==(k.drying_presets??"")||ke.per_printer_mapping_expanded!==k.per_printer_mapping_expanded||ke.date_format!==k.date_format||ke.time_format!==k.time_format||ke.default_printer_id!==k.default_printer_id||ke.ftp_retry_enabled!==k.ftp_retry_enabled||ke.ftp_retry_count!==k.ftp_retry_count||ke.ftp_retry_delay!==k.ftp_retry_delay||ke.ftp_timeout!==k.ftp_timeout||ke.mqtt_enabled!==k.mqtt_enabled||ke.mqtt_broker!==k.mqtt_broker||ke.mqtt_port!==k.mqtt_port||ke.mqtt_username!==k.mqtt_username||ke.mqtt_password!==k.mqtt_password||ke.mqtt_topic_prefix!==k.mqtt_topic_prefix||ke.mqtt_use_tls!==k.mqtt_use_tls||ke.external_url!==k.external_url||ke.ha_enabled!==k.ha_enabled||ke.ha_url!==k.ha_url||ke.ha_token!==k.ha_token||(ke.library_archive_mode??"ask")!==(k.library_archive_mode??"ask")||Number(ke.library_disk_warning_gb??5)!==Number(k.library_disk_warning_gb??5)||(ke.camera_view_mode??"window")!==(k.camera_view_mode??"window")||(ke.preferred_slicer??"bambu_studio")!==(k.preferred_slicer??"bambu_studio")||ke.prometheus_enabled!==k.prometheus_enabled||ke.prometheus_token!==k.prometheus_token||(ke.user_notifications_enabled??!0)!==(k.user_notifications_enabled??!0)))&&!nl.current)return tl.current&&clearTimeout(tl.current),tl.current=setTimeout(()=>{if(nl.current)return;nl.current=!0;const zt={auto_archive:k.auto_archive,save_thumbnails:k.save_thumbnails,capture_finish_photo:k.capture_finish_photo,default_filament_cost:k.default_filament_cost,currency:k.currency,energy_cost_per_kwh:k.energy_cost_per_kwh,energy_tracking_mode:k.energy_tracking_mode,check_updates:k.check_updates,check_printer_firmware:k.check_printer_firmware,include_beta_updates:k.include_beta_updates,notification_language:k.notification_language,bed_cooled_threshold:k.bed_cooled_threshold,ams_humidity_good:k.ams_humidity_good,ams_humidity_fair:k.ams_humidity_fair,ams_temp_good:k.ams_temp_good,ams_temp_fair:k.ams_temp_fair,ams_history_retention_days:k.ams_history_retention_days,disable_filament_warnings:k.disable_filament_warnings,queue_drying_enabled:k.queue_drying_enabled,queue_drying_block:k.queue_drying_block,ambient_drying_enabled:k.ambient_drying_enabled,drying_presets:k.drying_presets,per_printer_mapping_expanded:k.per_printer_mapping_expanded,date_format:k.date_format,time_format:k.time_format,default_printer_id:k.default_printer_id,ftp_retry_enabled:k.ftp_retry_enabled,ftp_retry_count:k.ftp_retry_count,ftp_retry_delay:k.ftp_retry_delay,ftp_timeout:k.ftp_timeout,mqtt_enabled:k.mqtt_enabled,mqtt_broker:k.mqtt_broker,mqtt_port:k.mqtt_port,mqtt_username:k.mqtt_username,mqtt_password:k.mqtt_password,mqtt_topic_prefix:k.mqtt_topic_prefix,mqtt_use_tls:k.mqtt_use_tls,external_url:k.external_url,ha_enabled:k.ha_enabled,ha_url:k.ha_url,ha_token:k.ha_token,library_archive_mode:k.library_archive_mode,library_disk_warning_gb:k.library_disk_warning_gb,camera_view_mode:k.camera_view_mode,preferred_slicer:k.preferred_slicer,prometheus_enabled:k.prometheus_enabled,prometheus_token:k.prometheus_token,user_notifications_enabled:k.user_notifications_enabled};ku.mutate(zt)},500),()=>{tl.current&&clearTimeout(tl.current)}},[k,ke,ku]);const on=w.useCallback((_e,zt)=>{R(mt=>mt?{...mt,[_e]:zt}:null)},[]),Ni=async(_e,zt,mt)=>{if(!zt){o(a("settings.toast.enterCameraUrl"),"error");return}tt(Pt=>({...Pt,[_e]:!0})),kn(Pt=>({...Pt,[_e]:null}));try{const Pt=await be.testExternalCamera(_e,zt,mt);kn(rn=>({...rn,[_e]:Pt})),Pt.success?o(a("settings.toast.cameraConnected",{resolution:Pt.resolution||""}),"success"):o(Pt.error||a("settings.toast.connectionFailed"),"error")}catch(Pt){const rn=Pt instanceof Error?Pt.message:a("settings.toast.testFailed");kn(rt=>({...rt,[_e]:{success:!1,error:rn}})),o(rn,"error")}finally{tt(Pt=>({...Pt,[_e]:!1}))}},[So,Cu]=w.useState({}),Jl=w.useRef({}),Tu=w.useRef(new Set);w.useEffect(()=>{if(yn){const _e={};yn.forEach(zt=>{zt.external_camera_url&&!Tu.current.has(zt.id)&&(_e[zt.id]=zt.external_camera_url,Tu.current.add(zt.id))}),Object.keys(_e).length>0&&Cu(zt=>({...zt,..._e}))}},[yn]);const Zh=(_e,zt)=>{Cu(mt=>({...mt,[_e]:zt})),Jl.current[_e]&&clearTimeout(Jl.current[_e]),Jl.current[_e]=setTimeout(()=>{ks.mutate({id:_e,data:{external_camera_url:zt||null}})},800)},Jd=(_e,zt)=>{const mt={};zt.type!==void 0&&(mt.external_camera_type=zt.type||null),zt.enabled!==void 0&&(mt.external_camera_enabled=zt.enabled),ks.mutate({id:_e,data:mt})};return ot||!k?i.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):i.jsxs("div",{className:"p-4 md:p-8",children:[i.jsxs("div",{className:"mb-8",children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:a("settings.title")}),i.jsx("p",{className:"text-bambu-gray",children:a("settings.configureBambuddy")})]}),i.jsxs("div",{className:"flex flex-wrap gap-1 mb-6 border-b border-bambu-dark-tertiary",children:[i.jsx("button",{onClick:()=>U("general"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px ${q==="general"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:a("settings.tabs.general")}),i.jsxs("button",{onClick:()=>U("plugs"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="plugs"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Dl,{className:"w-4 h-4"}),a("settings.tabs.smartPlugs"),Me&&Me.length>0&&i.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Me.length})]}),i.jsxs("button",{onClick:()=>U("notifications"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="notifications"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(hh,{className:"w-4 h-4"}),a("settings.tabs.notifications"),bt&&bt.length>0&&i.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:bt.length})]}),i.jsxs("button",{onClick:()=>U("filament"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="filament"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Npe,{className:"w-4 h-4"}),a("settings.tabs.filament")]}),i.jsxs("button",{onClick:()=>U("network"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="network"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Ub,{className:"w-4 h-4"}),a("settings.tabs.network"),i.jsx("span",{className:`w-2 h-2 rounded-full ${cr?.enabled?"bg-green-400":"bg-gray-500"}`})]}),i.jsxs("button",{onClick:()=>U("apikeys"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="apikeys"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Sl,{className:"w-4 h-4"}),a("settings.tabs.apiKeys"),Et&&Et.length>0&&i.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Et.length})]}),i.jsxs("button",{onClick:()=>U("virtual-printer"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="virtual-printer"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Sr,{className:"w-4 h-4"}),a("settings.tabs.virtualPrinter"),i.jsx("span",{className:`w-2 h-2 rounded-full ${Cn?"bg-green-400":"bg-gray-500"}`})]}),i.jsxs("button",{onClick:()=>U("users"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="users"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Km,{className:"w-4 h-4"}),a("settings.tabs.users"),l&&i.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"})]}),i.jsxs("button",{onClick:()=>U("backup"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="backup"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(au,{className:"w-4 h-4"}),a("settings.tabs.backup"),i.jsx("span",{className:`w-2 h-2 rounded-full ${_i?.is_authenticated&&li?.configured&&li?.enabled?"bg-green-400":"bg-gray-500"}`})]})]}),q==="general"&&i.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[i.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-xl",children:[i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.general")})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i.jsx(gh,{className:"w-4 h-4 inline mr-1"}),a("settings.language")]}),i.jsxs("div",{className:"relative",children:[i.jsx("select",{value:s.language,onChange:_e=>{s.changeLanguage(_e.target.value),be.updateSettings({language:_e.target.value}),o(a("settings.toast.settingsSaved"),"success")},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:C8.map(_e=>i.jsxs("option",{value:_e.code,children:[_e.nativeName," (",_e.name,")"]},_e.code))}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.languageDescription")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.defaultView")}),i.jsxs("div",{className:"relative",children:[i.jsx("select",{value:Y,onChange:_e=>ut(_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:y0.map(_e=>i.jsx("option",{value:_e.to,children:a(_e.labelKey)},_e.id))}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.defaultViewDescription")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.dateFormat")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:k.date_format||"system",onChange:_e=>on("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:[i.jsx("option",{value:"system",children:a("settings.systemDefault")}),i.jsx("option",{value:"us",children:a("settings.dateFormatUs")}),i.jsx("option",{value:"eu",children:a("settings.dateFormatEu")}),i.jsx("option",{value:"iso",children:a("settings.dateFormatIso")})]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.timeFormat")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:k.time_format||"system",onChange:_e=>on("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:[i.jsx("option",{value:"system",children:a("settings.systemDefault")}),i.jsx("option",{value:"12h",children:a("settings.timeFormat12")}),i.jsx("option",{value:"24h",children:a("settings.timeFormat24")})]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.defaultPrinter")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:k.default_printer_id??"",onChange:_e=>on("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:[i.jsx("option",{value:"",children:a("settings.noDefaultPrinter")}),yn?.map(_e=>i.jsx("option",{value:_e.id,children:_e.name},_e.id))]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.defaultPrinterDescription")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.preferredSlicer")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:k.preferred_slicer??"bambu_studio",onChange:_e=>on("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:[i.jsx("option",{value:"bambu_studio",children:a("settings.slicerBambuStudio")}),i.jsx("option",{value:"orcaslicer",children:a("settings.slicerOrcaSlicer")})]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.preferredSlicerDescription")})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.sidebarOrder")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.sidebarOrderDescription")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:Ze,children:[i.jsx(bo,{className:"w-4 h-4"}),a("settings.reset")]})]})]})]}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(fw,{className:"w-5 h-5"}),a("settings.appearance")]})}),i.jsxs(Dt,{className:"space-y-6",children:[i.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${d==="dark"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[i.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[a("settings.darkMode"),d==="dark"&&i.jsx("span",{className:"text-xs text-bambu-green",children:a("settings.active")})]}),i.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.background")}),i.jsxs("select",{value:p,onChange:_e=>{_(_e.target.value),o(a("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:[i.jsx("option",{value:"neutral",children:a("settings.bgNeutral")}),i.jsx("option",{value:"warm",children:a("settings.bgWarm")}),i.jsx("option",{value:"cool",children:a("settings.bgCool")}),i.jsx("option",{value:"oled",children:a("settings.bgOled")}),i.jsx("option",{value:"slate",children:a("settings.bgSlate")}),i.jsx("option",{value:"forest",children:a("settings.bgForest")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.accent")}),i.jsxs("select",{value:f,onChange:_e=>{N(_e.target.value),o(a("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:[i.jsx("option",{value:"green",children:a("settings.accentGreen")}),i.jsx("option",{value:"teal",children:a("settings.accentTeal")}),i.jsx("option",{value:"blue",children:a("settings.accentBlue")}),i.jsx("option",{value:"orange",children:a("settings.accentOrange")}),i.jsx("option",{value:"purple",children:a("settings.accentPurple")}),i.jsx("option",{value:"red",children:a("settings.accentRed")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.style")}),i.jsxs("select",{value:m,onChange:_e=>{g(_e.target.value),o(a("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:[i.jsx("option",{value:"classic",children:a("settings.styleClassic")}),i.jsx("option",{value:"glow",children:a("settings.styleGlow")}),i.jsx("option",{value:"vibrant",children:a("settings.styleVibrant")})]})]})]})]}),i.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${d==="light"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[i.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[a("settings.lightMode"),d==="light"&&i.jsx("span",{className:"text-xs text-bambu-green",children:a("settings.active")})]}),i.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.background")}),i.jsxs("select",{value:v,onChange:_e=>{C(_e.target.value),o(a("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:[i.jsx("option",{value:"neutral",children:a("settings.bgNeutral")}),i.jsx("option",{value:"warm",children:a("settings.bgWarm")}),i.jsx("option",{value:"cool",children:a("settings.bgCool")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.accent")}),i.jsxs("select",{value:x,onChange:_e=>{A(_e.target.value),o(a("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:[i.jsx("option",{value:"green",children:a("settings.accentGreen")}),i.jsx("option",{value:"teal",children:a("settings.accentTeal")}),i.jsx("option",{value:"blue",children:a("settings.accentBlue")}),i.jsx("option",{value:"orange",children:a("settings.accentOrange")}),i.jsx("option",{value:"purple",children:a("settings.accentPurple")}),i.jsx("option",{value:"red",children:a("settings.accentRed")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.style")}),i.jsxs("select",{value:y,onChange:_e=>{T(_e.target.value),o(a("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:[i.jsx("option",{value:"classic",children:a("settings.styleClassic")}),i.jsx("option",{value:"glow",children:a("settings.styleGlow")}),i.jsx("option",{value:"vibrant",children:a("settings.styleVibrant")})]})]})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.themeToggleHint")})]})]}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.archiveSettings")})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.autoArchivePrints")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.autoArchiveDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.auto_archive,onChange:_e=>on("auto_archive",_e.target.checked),className:"sr-only peer"}),i.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.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.saveThumbnails")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.saveThumbnailsDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.save_thumbnails,onChange:_e=>on("save_thumbnails",_e.target.checked),className:"sr-only peer"}),i.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.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.captureFinishPhoto")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.captureFinishPhotoDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.capture_finish_photo,onChange:_e=>on("capture_finish_photo",_e.target.checked),className:"sr-only peer"}),i.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"})]})]}),k.capture_finish_photo&&gn&&!gn.installed&&i.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[i.jsx(Mn,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),i.jsxs("div",{className:"text-sm",children:[i.jsx("p",{className:"text-yellow-500 font-medium",children:a("settings.ffmpegNotInstalled")}),i.jsx("p",{className:"text-bambu-gray mt-1",children:a("settings.ffmpegRequired")})]})]})]})]})]}),i.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-md",children:[i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(VL,{className:"w-5 h-5 text-bambu-green"}),a("settings.camera")]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.cameraViewMode")}),i.jsxs("select",{value:k.camera_view_mode??"window",onChange:_e=>on("camera_view_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:[i.jsx("option",{value:"window",children:a("settings.newWindow")}),i.jsx("option",{value:"embedded",children:a("settings.embeddedOverlay")})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:k.camera_view_mode==="embedded"?a("settings.cameraOverlayDescription"):a("settings.cameraWindowDescription")})]}),i.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4",children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-2",children:a("settings.externalCameras")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:a("settings.externalCamerasDescription")}),yn&&yn.length>0?i.jsx("div",{className:"space-y-3",children:yn.map(_e=>i.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-white font-medium text-sm",children:_e.name}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:_e.external_camera_enabled,onChange:zt=>Jd(_e.id,{enabled:zt.target.checked}),className:"sr-only peer"}),i.jsx("div",{className:"w-9 h-5 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:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),_e.external_camera_enabled&&i.jsxs("div",{className:"space-y-2 mt-2",children:[i.jsx("input",{type:"text",placeholder:_e.external_camera_type==="usb"?a("settings.cameraPlaceholderUsb"):a("settings.cameraPlaceholderUrl"),value:So[_e.id]??_e.external_camera_url??"",onChange:zt=>Zh(_e.id,zt.target.value),className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("select",{value:_e.external_camera_type||"mjpeg",onChange:zt=>Jd(_e.id,{type:zt.target.value}),className:"flex-1 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"mjpeg",children:a("settings.cameraTypeMjpeg")}),i.jsx("option",{value:"rtsp",children:a("settings.cameraTypeRtsp")}),i.jsx("option",{value:"snapshot",children:a("settings.cameraTypeSnapshot")}),i.jsx("option",{value:"usb",children:a("settings.cameraTypeUsb")})]}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:()=>Ni(_e.id,So[_e.id]??_e.external_camera_url??"",_e.external_camera_type||"mjpeg"),disabled:Fe[_e.id]||!(So[_e.id]??_e.external_camera_url),children:Fe[_e.id]?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):a("settings.test")})]}),jn[_e.id]&&i.jsx("div",{className:`text-xs flex items-center gap-1 ${jn[_e.id]?.success?"text-green-500":"text-red-500"}`,children:jn[_e.id]?.success?i.jsxs(i.Fragment,{children:[i.jsx(fr,{className:"w-3 h-3"}),a("settings.connected"),jn[_e.id]?.resolution&&` (${jn[_e.id]?.resolution})`]}):i.jsxs(i.Fragment,{children:[i.jsx(Vi,{className:"w-3 h-3"}),jn[_e.id]?.error||a("settings.toast.connectionFailed")]})})]})]},_e.id))}):i.jsx("p",{className:"text-xs text-bambu-gray italic",children:a("settings.noPrintersConfigured")})]})]})]}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.costTracking")})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.currency")}),i.jsx("select",{value:k.currency,onChange:_e=>on("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:zqe.map(_e=>i.jsx("option",{value:_e.code,children:_e.label},_e.code))})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.defaultFilamentCost")}),i.jsxs("div",{className:"relative",children:[i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none",children:_l(k.currency)}),i.jsx("input",{type:"number",step:"0.01",min:"0",value:k.default_filament_cost,onChange:_e=>on("default_filament_cost",parseFloat(_e.target.value)||0),style:{paddingLeft:`${Math.max(2,_l(k.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"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.electricityCost")}),i.jsxs("div",{className:"relative",children:[i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none",children:_l(k.currency)}),i.jsx("input",{type:"number",step:"0.001",min:"0",value:k.energy_cost_per_kwh,onChange:_e=>on("energy_cost_per_kwh",parseFloat(_e.target.value)||0),style:{paddingLeft:`${Math.max(2,_l(k.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"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.energyDisplayMode")}),i.jsxs("select",{value:k.energy_tracking_mode||"total",onChange:_e=>on("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:[i.jsx("option",{value:"print",children:a("settings.printsOnly")}),i.jsx("option",{value:"total",children:a("settings.totalConsumption")})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:k.energy_tracking_mode==="print"?a("settings.energyModePrintDescription"):a("settings.energyModeTotalDescription")})]})]})]}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Fs,{className:"w-5 h-5 text-bambu-green"}),a("settings.fileManager")]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.createArchiveEntry")}),i.jsxs("select",{value:k.library_archive_mode??"ask",onChange:_e=>on("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:[i.jsx("option",{value:"always",children:a("settings.archiveMode.always")}),i.jsx("option",{value:"never",children:a("settings.archiveMode.never")}),i.jsx("option",{value:"ask",children:a("settings.archiveMode.ask")})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.createArchiveEntryDescription")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.lowDiskSpaceWarning")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",min:"0.5",max:"100",step:"0.5",value:k.library_disk_warning_gb??5,onChange:_e=>on("library_disk_warning_gb",parseFloat(_e.target.value)||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"}),i.jsx("span",{className:"text-bambu-gray",children:"GB"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.lowDiskSpaceDescription")})]})]})]})]}),i.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-sm",children:[i.jsx(ket,{}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.updates")})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wider",children:a("settings.printerFirmware")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.checkPrinterFirmware")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.checkFirmwareDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.check_printer_firmware??!0,onChange:_e=>on("check_printer_firmware",_e.target.checked),className:"sr-only peer"}),i.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.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:i.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wider mb-4",children:a("settings.bambuddySoftware")})}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.checkForUpdatesLabel")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.autoCheckDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.check_updates,onChange:_e=>on("check_updates",_e.target.checked),className:"sr-only peer"}),i.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.jsxs("div",{className:`flex items-center justify-between ${k.check_updates?"":"opacity-50"}`,children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.includeBetaUpdates")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.includeBetaUpdatesDesc")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.include_beta_updates??!1,onChange:_e=>on("include_beta_updates",_e.target.checked),disabled:!k.check_updates,className:"sr-only peer"}),i.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.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.currentVersion")}),i.jsxs("p",{className:"text-sm text-bambu-gray",children:["v",Qr?.version||"..."]})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>hr(),disabled:_a,children:[_a?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(wr,{className:"w-4 h-4"}),a("settings.checkNow")]})]}),Tn?.update_available?i.jsxs("div",{className:"mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:[i.jsxs("div",{className:"flex items-start justify-between",children:[i.jsxs("div",{children:[i.jsxs("p",{className:"text-bambu-green font-medium",children:["Update available: v",Tn.latest_version]}),Tn.release_name&&Tn.release_name!==Tn.latest_version&&i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:Tn.release_name})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[Tn.release_notes&&i.jsx("button",{onClick:()=>Se(!0),className:"text-bambu-gray hover:text-white transition-colors text-sm underline",children:a("settings.releaseNotes")}),Tn.release_url&&i.jsx("a",{href:Tn.release_url,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-white transition-colors",title:a("settings.viewReleaseOnGitHub"),children:i.jsx(Jr,{className:"w-4 h-4"})})]})]}),On?.status==="downloading"||On?.status==="installing"?i.jsxs("div",{className:"mt-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),i.jsx("span",{children:On.message})]}),i.jsx("div",{className:"mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2",children:i.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${On.progress}%`}})})]}):On?.status==="complete"?i.jsx("div",{className:"mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green",children:On.message}):On?.status==="error"?i.jsx("div",{className:"mt-3 p-2 bg-red-500/20 rounded text-sm text-red-400",children:On.error||On.message}):Tn?.is_docker?i.jsxs("div",{className:"mt-3 p-3 bg-bambu-dark-tertiary rounded-lg",children:[i.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:a("settings.updateViaDocker")}),i.jsx("code",{className:"block text-xs bg-bambu-dark p-2 rounded text-bambu-green font-mono",children:"docker compose pull && docker compose up -d"})]}):i.jsxs(Oe,{className:"mt-3",onClick:()=>Ys.mutate(),disabled:Ys.isPending,children:[Ys.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(pi,{className:"w-4 h-4"}),a("settings.installUpdate")]})]}):Tn?.error?i.jsx("div",{className:"mt-2 p-2 bg-red-500/10 border border-red-500/30 rounded text-sm text-red-400",children:a("settings.failedToCheckUpdates",{error:Tn.error})}):Tn&&!Tn.update_available?i.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:a("settings.latestVersionRunning")}):null]})]})]}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.dataManagement")})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.clearNotificationLogs")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.clearNotificationLogsDescription")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>F(!0),children:[i.jsx(Jt,{className:"w-4 h-4"}),a("common.clear")]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.resetUiPreferences")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.resetUiPreferencesDescription")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>ve(!0),children:[i.jsx(Jt,{className:"w-4 h-4"}),a("settings.reset")]})]}),i.jsxs("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.storageUsage","Storage Usage")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.storageUsageDescription","Breakdown of data usage by category")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:Ye,disabled:Ke||ce,children:[i.jsx(wr,{className:`w-4 h-4 ${Ke||ce?"animate-spin":""}`}),a("common.refresh","Refresh")]})]}),i.jsx("div",{className:"mt-3",children:He?i.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),a("common.loading","Loading")]}):se?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"w-full h-3 bg-bambu-dark rounded-full overflow-hidden flex",children:se.categories.filter(_e=>_e.bytes>0).map((_e,zt)=>i.jsx("div",{className:`${AY(_e.key,zt)} h-full`,style:{width:`${_e.percent_of_total}%`},title:`${_e.label}: ${_e.formatted}`},_e.key))}),i.jsx("div",{className:"mt-3 flex flex-wrap gap-3",children:se.categories.filter(_e=>_e.bytes>0).map((_e,zt)=>i.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[i.jsx("span",{className:`w-3 h-3 rounded-full ${AY(_e.key,zt)}`}),i.jsx("span",{className:"text-bambu-gray",children:_e.label}),i.jsx("span",{className:"text-white",children:_e.formatted}),i.jsxs("span",{className:"text-bambu-gray",children:["(",_e.percent_of_total.toFixed(1),"%)"]})]},_e.key))}),i.jsxs("div",{className:"mt-2 text-xs text-bambu-gray",children:[a("settings.storageUsageTotal","Total"),": ",i.jsx("span",{className:"text-white",children:se.total_formatted}),se.scan_errors>0&&i.jsxs("span",{className:"ml-2 text-amber-400",children:[a("settings.storageUsageErrors","Scan errors"),": ",se.scan_errors]})]}),se.other_breakdown?.length>0&&i.jsxs("div",{className:"mt-4",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:a("settings.storageUsageOtherBreakdown","Other breakdown")}),i.jsx("div",{className:"space-y-2",children:se.other_breakdown.map(_e=>i.jsxs("div",{className:"flex items-center justify-between text-xs",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-white",children:_e.label}),i.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"?a("settings.storageUsageSystem","System"):a("settings.storageUsageData","Data")})]}),i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray",children:[i.jsx("span",{className:"text-white",children:_e.formatted}),i.jsxs("span",{children:["(",_e.percent_of_total.toFixed(1),"%)"]})]})]},`${_e.bucket}-${_e.kind}`))})]})]}):i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.storageUsageUnavailable","Storage usage data is unavailable")})})]}),i.jsxs("div",{className:"flex items-center justify-between pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.backupRestore")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.backupRestoreDescription")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>U("backup"),children:[i.jsx(au,{className:"w-4 h-4"}),a("settings.goToBackup")]})]})]})]})]})]}),q==="network"&&k&&i.jsxs("div",{className:"flex flex-col lg:flex-row gap-6",children:[i.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-4",children:[i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(gh,{className:"w-5 h-5 text-blue-400"}),a("settings.externalUrl")]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.externalUrlDescription")}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.bambuddyUrl")}),i.jsx("input",{type:"text",value:k.external_url??"",onChange:_e=>on("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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.externalUrlHint")})]})]})]}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(wr,{className:"w-5 h-5 text-blue-400"}),a("settings.ftpRetry")]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.ftpRetryDescription")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.enableRetry")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.autoRetryDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.ftp_retry_enabled??!0,onChange:_e=>on("ftp_retry_enabled",_e.target.checked),className:"sr-only peer"}),i.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"})]})]}),k.ftp_retry_enabled&&i.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.retryAttempts")}),i.jsxs("div",{className:"relative w-44",children:[i.jsx("select",{value:k.ftp_retry_count??3,onChange:_e=>on("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=>i.jsx("option",{value:_e,children:a("settings.time",{count:_e})},_e))}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.retryDelay")}),i.jsxs("div",{className:"relative w-44",children:[i.jsx("select",{value:k.ftp_retry_delay??2,onChange:_e=>on("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=>i.jsx("option",{value:_e,children:a("settings.second",{count:_e})},_e))}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.connectionTimeout")}),i.jsxs("div",{className:"relative w-44",children:[i.jsx("select",{value:k.ftp_timeout??30,onChange:_e=>on("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=>i.jsx("option",{value:_e,children:a("settings.nSeconds",{count:_e})},_e))}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.increaseForWeakWifi")})]})]})]})]})]}),i.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-4",children:[i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(hw,{className:"w-5 h-5 text-bambu-green"}),a("settings.homeAssistant")]}),k.ha_enabled&&Xt&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${Xt.success?"bg-green-400":"bg-red-400"}`}),i.jsx("span",{className:`text-sm ${Xt.success?"text-green-400":"text-red-400"}`,children:Xt.success?a("settings.connected"):a("settings.disconnected")})]})]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.homeAssistantFullDescription")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-white",children:a("settings.enableHomeAssistant")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.homeAssistantDescription")}),k.ha_env_managed&&i.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[i.jsx(Ap,{className:"w-3 h-3 text-bambu-green"}),i.jsx("span",{className:"text-xs text-bambu-green",children:a("settings.autoEnabledViaEnv")})]})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.ha_enabled??!1,onChange:_e=>on("ha_enabled",_e.target.checked),disabled:k.ha_env_managed,className:"sr-only peer"}),i.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 ${k.ha_env_managed?"opacity-60 cursor-not-allowed":""}`})]})]}),k.ha_enabled&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.homeAssistantUrl"),k.ha_url_from_env&&i.jsx("span",{className:"ml-2 text-xs text-bambu-green",children:a("settings.environmentManagedLabel")})]}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"text",value:k.ha_url??"",onChange:_e=>on("ha_url",_e.target.value),placeholder:"http://192.168.1.100:8123",disabled:k.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 ${k.ha_url_from_env?"opacity-60 cursor-not-allowed":""}`}),k.ha_url_from_env&&i.jsx(Ap,{className:"absolute right-3 top-2.5 w-4 h-4 text-bambu-gray"})]}),k.ha_url_from_env&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.urlFromEnvReadOnly")})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.longLivedAccessToken"),k.ha_token_from_env&&i.jsx("span",{className:"ml-2 text-xs text-bambu-green",children:a("settings.environmentManagedLabel")})]}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"password",value:k.ha_token??"",onChange:_e=>on("ha_token",_e.target.value),placeholder:"eyJ0eXAiOiJKV1QiLC...",disabled:k.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 ${k.ha_token_from_env?"opacity-60 cursor-not-allowed":""}`}),k.ha_token_from_env&&i.jsx(Ap,{className:"absolute right-3 top-2.5 w-4 h-4 text-bambu-gray"})]}),k.ha_token_from_env?i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.tokenFromEnvReadOnly")}):i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.haTokenHint")})]}),k.ha_url&&k.ha_token&&i.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:i.jsxs(Oe,{variant:"secondary",size:"sm",disabled:Qt,onClick:async()=>{hn(!0),Qe(null);try{const _e=await be.testHAConnection(k.ha_url,k.ha_token);Qe(_e)}catch(_e){Qe({success:!1,message:null,error:_e instanceof Error?_e.message:a("common.unknownError")})}finally{hn(!1)}},children:[Qt?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Ub,{className:"w-4 h-4"}),a("settings.testConnection")]})})]})]})]}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Ub,{className:"w-5 h-5 text-blue-400"}),a("settings.mqttPublishing")]}),cr?.enabled&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${cr.connected?"bg-green-400":"bg-red-400"}`}),i.jsx("span",{className:`text-sm ${cr.connected?"text-green-400":"text-red-400"}`,children:cr.connected?a("settings.connected"):a("settings.disconnected")})]})]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.mqttDescription")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.enableMqtt")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.mqttEnableDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.mqtt_enabled??!1,onChange:_e=>on("mqtt_enabled",_e.target.checked),className:"sr-only peer"}),i.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"})]})]}),k.mqtt_enabled&&i.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.brokerHostname")}),i.jsx("input",{type:"text",value:k.mqtt_broker??"",onChange:_e=>on("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"})]}),i.jsxs("div",{className:"flex items-end gap-4",children:[i.jsxs("div",{className:"flex-1",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.port")}),i.jsx("input",{type:"number",min:"1",max:"65535",value:k.mqtt_port??1883,onChange:_e=>on("mqtt_port",Math.min(65535,Math.max(1,parseInt(_e.target.value)||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"})]}),i.jsxs("div",{className:"flex items-center gap-3 pb-2",children:[i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.mqtt_use_tls??!1,onChange:_e=>{const zt=_e.target.checked;on("mqtt_use_tls",zt);const mt=k.mqtt_port??1883;zt&&mt===1883?on("mqtt_port",8883):!zt&&mt===8883&&on("mqtt_port",1883)},className:"sr-only peer"}),i.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.jsx("span",{className:"text-white text-sm",children:a("settings.useTls")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.usernameOptional")}),i.jsx("input",{type:"text",value:k.mqtt_username??"",onChange:_e=>on("mqtt_username",_e.target.value),placeholder:a("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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.passwordOptional")}),i.jsx("input",{type:"password",value:k.mqtt_password??"",onChange:_e=>on("mqtt_password",_e.target.value),placeholder:a("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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.topicPrefix")}),i.jsx("input",{type:"text",value:k.mqtt_topic_prefix??"bambuddy",onChange:_e=>on("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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.topicPrefixHint",{prefix:k.mqtt_topic_prefix||"bambuddy"})})]}),cr&&i.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary",children:i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx("span",{className:`w-2 h-2 rounded-full ${cr.connected?"bg-green-400":"bg-red-400"}`}),i.jsx("span",{className:"text-bambu-gray",children:cr.connected?i.jsxs(i.Fragment,{children:[a("settings.mqttConnectedTo")," ",i.jsxs("span",{className:"text-white",children:[cr.broker,":",cr.port]})]}):a("settings.spoolmanDisconnected")})]})})]})]})]})]}),i.jsx("div",{className:"flex-1 lg:max-w-md space-y-4",children:i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(w3,{className:"w-5 h-5 text-orange-400"}),a("settings.prometheusMetrics")]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.prometheusEndpointDescription")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.enableMetricsEndpoint")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.prometheusDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.prometheus_enabled??!1,onChange:_e=>on("prometheus_enabled",_e.target.checked),className:"sr-only peer"}),i.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"})]})]}),k.prometheus_enabled&&i.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.bearerTokenOptional")}),i.jsx("input",{type:"password",value:k.prometheus_token??"",onChange:_e=>on("prometheus_token",_e.target.value),placeholder:a("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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.bearerTokenHint")})]}),i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-sm text-white mb-2",children:a("settings.availableMetrics")}),i.jsxs("div",{className:"text-xs text-bambu-gray space-y-1",children:[i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_connected"})," - ",a("settings.metricsConnectionStatus")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_state"})," - ",a("settings.metricsPrinterState")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_print_progress"})," - ",a("settings.metricsPrintProgress")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_bed_temp_celsius"})," - ",a("settings.metricsBedTemp")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_nozzle_temp_celsius"})," - ",a("settings.metricsNozzleTemp")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_prints_total"})," - ",a("settings.metricsPrintsTotal")]}),i.jsx("p",{className:"text-bambu-gray/70 italic",children:a("settings.metricsMore")})]})]})]})]})]})})]}),Xt&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full mx-4",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[Xt.success?i.jsx(fr,{className:"w-8 h-8 text-green-400"}):i.jsx(Vi,{className:"w-8 h-8 text-red-400"}),i.jsx("h3",{className:"text-lg font-medium text-white",children:Xt.success?a("settings.connectionSuccessful"):a("settings.connectionFailed")})]}),i.jsx("p",{className:"text-bambu-gray mb-6",children:Xt.success?Xt.message||a("settings.haConnectionSuccess"):Xt.error||a("settings.haConnectionFailed")}),i.jsx("div",{className:"flex justify-end",children:i.jsx(Oe,{variant:"primary",onClick:()=>Qe(null),children:a("settings.ok")})})]})}),q==="plugs"&&i.jsxs("div",{className:"max-w-4xl",children:[i.jsxs("div",{className:"flex items-start justify-between mb-6",children:[i.jsxs("div",{children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Dl,{className:"w-5 h-5 text-bambu-green"}),a("settings.smartPlugs")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a("settings.smartPlugsDescription")})]}),i.jsxs("div",{className:"flex items-center gap-2 pt-1 shrink-0",children:[Me&&Me.filter(_e=>_e.enabled).length>1&&i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>de("on"),disabled:Bi.isPending,title:a("settings.turnAllPlugsOn"),children:[Bi.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Vd,{className:"w-4 h-4 text-bambu-green"}),a("settings.allOn")]}),i.jsxs(Oe,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>de("off"),disabled:Bi.isPending,title:a("settings.turnAllPlugsOff"),children:[Bi.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(nT,{className:"w-4 h-4 text-red-400"}),a("settings.allOff")]})]}),i.jsxs(Oe,{className:"whitespace-nowrap",onClick:()=>{z(null),D(!0)},children:[i.jsx(ar,{className:"w-4 h-4"}),a("settings.addSmartPlug")]})]})]}),Me&&Me.length>0&&i.jsxs(Mt,{className:"mb-6",children:[i.jsx(Hn,{children:i.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[i.jsx(kc,{className:"w-4 h-4 text-yellow-400"}),a("settings.energySummary"),nt&&i.jsx(ht,{className:"w-4 h-4 animate-spin text-bambu-gray ml-2"})]})}),i.jsx(Dt,{children:ct?i.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[i.jsx(kc,{className:"w-3 h-3"}),a("settings.currentPower")]}),i.jsxs("div",{className:"text-xl font-bold text-white",children:[ct.totalPower.toFixed(1),i.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"W"})]}),i.jsx("div",{className:"text-xs text-bambu-gray mt-1",children:a("settings.plugsOnline",{reachable:ct.reachableCount,total:ct.totalPlugs})})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[i.jsx(Wr,{className:"w-3 h-3"}),a("settings.today")]}),i.jsxs("div",{className:"text-xl font-bold text-white",children:[ct.totalToday.toFixed(3),i.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(k?.energy_cost_per_kwh??0)>0&&i.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(ct.totalToday*(k?.energy_cost_per_kwh??0)).toFixed(2)," ",_l(k?.currency||"USD")]})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[i.jsx(w3,{className:"w-3 h-3"}),a("settings.yesterday")]}),i.jsxs("div",{className:"text-xl font-bold text-white",children:[ct.totalYesterday.toFixed(3),i.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(k?.energy_cost_per_kwh??0)>0&&i.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(ct.totalYesterday*(k?.energy_cost_per_kwh??0)).toFixed(2)," ",_l(k?.currency||"USD")]})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[i.jsx(PN,{className:"w-3 h-3"}),a("settings.total")]}),i.jsxs("div",{className:"text-xl font-bold text-white",children:[ct.totalLifetime.toFixed(1),i.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(k?.energy_cost_per_kwh??0)>0&&i.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(ct.totalLifetime*(k?.energy_cost_per_kwh??0)).toFixed(2)," ",_l(k?.currency||"USD")]})]})]}):nt?null:i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.enablePlugsForSummary")})})]}),dt?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):Me&&Me.length>0?i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Me.map(_e=>i.jsx(uet,{plug:_e,onEdit:zt=>{z(zt),D(!0)}},_e.id))}):i.jsx(Mt,{children:i.jsx(Dt,{className:"py-12",children:i.jsxs("div",{className:"text-center text-bambu-gray",children:[i.jsx(Dl,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),i.jsx("p",{className:"text-lg font-medium text-white mb-2",children:a("settings.noSmartPlugsTitle")}),i.jsx("p",{className:"text-sm mb-4",children:a("settings.noSmartPlugsDescription")}),i.jsxs(Oe,{onClick:()=>{z(null),D(!0)},children:[i.jsx(ar,{className:"w-4 h-4"}),a("settings.addFirstSmartPlug")]})]})})})]}),q==="notifications"&&i.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(hh,{className:"w-5 h-5 text-bambu-green"}),a("settings.providers")]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>ge(!0),children:[i.jsx(f0,{className:"w-4 h-4"}),a("settings.log")]}),bt&&bt.length>0&&i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>{Nu(null),Zl.mutate()},disabled:Zl.isPending,children:[Zl.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(rT,{className:"w-4 h-4"}),a("settings.testAll")]}),i.jsxs(Oe,{size:"sm",onClick:()=>{ie(null),I(!0)},children:[i.jsx(ar,{className:"w-4 h-4"}),a("settings.addNotificationProvider")]})]})]}),i.jsx(Mt,{className:"mb-4",children:i.jsx(Dt,{className:"py-3",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white text-sm font-medium",children:a("settings.notificationLanguage")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.notificationLanguageDescription")})]}),i.jsx("select",{value:k.notification_language||"en",onChange:_e=>on("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:C8.map(_e=>i.jsx("option",{value:_e.code,children:_e.nativeName},_e.code))})]})})}),i.jsx(Mt,{className:"mb-4",children:i.jsx(Dt,{className:"py-3",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white text-sm font-medium",children:a("settings.bedCooledThreshold")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.bedCooledThresholdDescription")})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("input",{type:"number",min:20,max:80,step:1,value:k.bed_cooled_threshold??35,onChange:_e=>on("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"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:"°C"})]})]})})}),i.jsx(Mt,{className:"mb-4",children:i.jsx(Dt,{className:"py-3",children:i.jsxs("div",{className:`flex items-center justify-between ${Tr?.advanced_auth_enabled?"":"opacity-50"}`,children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white text-sm font-medium",children:a("settings.userNotificationsEnabled")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:Tr?.advanced_auth_enabled?a("settings.userNotificationsEnabledDescription"):a("settings.userNotificationsDisabledHint")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",className:"sr-only peer",checked:k.user_notifications_enabled??!0,disabled:!Tr?.advanced_auth_enabled,onChange:_e=>on("user_notifications_enabled",_e.target.checked)}),i.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"})]})]})})}),Ui&&i.jsx(Mt,{className:"mb-4",children:i.jsxs(Dt,{className:"py-3",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-sm font-medium text-white",children:a("settings.testResults")}),i.jsx("button",{onClick:()=>Nu(null),className:"text-bambu-gray hover:text-white text-xs",children:a("common.dismiss")})]}),i.jsxs("div",{className:"flex items-center gap-4 text-sm mb-2",children:[i.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[i.jsx(fr,{className:"w-4 h-4"}),a("settings.testPassedCount",{count:Ui.success})]}),Ui.failed>0&&i.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[i.jsx(Vi,{className:"w-4 h-4"}),a("settings.testFailedCount",{count:Ui.failed})]})]}),Ui.results.filter(_e=>!_e.success).length>0&&i.jsx("div",{className:"space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary",children:Ui.results.filter(_e=>!_e.success).map(_e=>i.jsxs("div",{className:"text-xs text-red-400",children:[i.jsxs("span",{className:"font-medium",children:[_e.provider_name,":"]})," ",_e.message]},_e.provider_id))})]})}),Ut?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})}):bt&&bt.length>0?i.jsx("div",{className:"space-y-3",children:bt.map(_e=>i.jsx(met,{provider:_e,onEdit:zt=>{ie(zt),I(!0)}},_e.id))}):i.jsx(Mt,{children:i.jsx(Dt,{className:"py-8",children:i.jsxs("div",{className:"text-center text-bambu-gray",children:[i.jsx(hh,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),i.jsx("p",{className:"text-sm font-medium text-white mb-2",children:a("settings.noProvidersTitle")}),i.jsx("p",{className:"text-xs mb-3",children:a("settings.noProvidersDescription")}),i.jsxs(Oe,{size:"sm",onClick:()=>{ie(null),I(!0)},children:[i.jsx(ar,{className:"w-4 h-4"}),a("settings.addProvider")]})]})})})]}),i.jsxs("div",{children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-4",children:[i.jsx(Fs,{className:"w-5 h-5 text-bambu-green"}),a("settings.messageTemplates")]}),i.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:a("settings.messageTemplatesDescription")}),qn?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})}):_n&&_n.length>0?i.jsx("div",{className:"space-y-2",children:[..._n].sort((_e,zt)=>_e.name.localeCompare(zt.name)).map(_e=>i.jsx(Mt,{className:"cursor-pointer hover:border-bambu-green/50 transition-colors",onClick:()=>me(_e),children:i.jsx(Dt,{className:"py-2.5 px-3",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"text-white font-medium text-sm truncate",children:_e.name}),i.jsx("p",{className:"text-bambu-gray text-xs truncate mt-0.5",children:_e.title_template})]}),i.jsx("button",{className:"p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2",onClick:zt=>{zt.stopPropagation(),me(_e)},children:i.jsx(nh,{className:"w-4 h-4 text-bambu-gray"})})]})})},_e.id))}):i.jsx(Mt,{children:i.jsx(Dt,{className:"py-8",children:i.jsxs("div",{className:"text-center text-bambu-gray",children:[i.jsx(Fs,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),i.jsx("p",{className:"text-sm",children:a("settings.noTemplatesAvailable")})]})})})]})]}),q==="apikeys"&&i.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-8",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-start justify-between gap-4 mb-6",children:[i.jsxs("div",{className:"flex-1",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Sl,{className:"w-5 h-5 text-bambu-green"}),a("settings.apiKeys")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a("settings.apiKeysDescription")})]}),i.jsxs(Oe,{size:"sm",onClick:()=>$(!0),className:"flex-shrink-0",children:[i.jsx(ar,{className:"w-4 h-4"}),a("settings.createKey")]})]}),W&&i.jsx(Mt,{className:"mb-6 border-bambu-green",children:i.jsx(Dt,{className:"py-4",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(fr,{className:"w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-white font-medium mb-1",children:a("settings.apiKeyCreated")}),i.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:a("settings.apiKeyCopyWarning")}),i.jsxs("div",{className:"flex items-center gap-2 bg-bambu-dark rounded-lg p-2",children:[i.jsx("code",{className:"flex-1 text-sm text-bambu-green font-mono break-all",children:W}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(W);else{const _e=document.createElement("textarea");_e.value=W,_e.style.position="fixed",_e.style.left="-999999px",document.body.appendChild(_e),_e.select(),document.execCommand("copy"),document.body.removeChild(_e)}o(a("settings.toast.keyCopied"))}catch{o(a("settings.toast.copyFailed"),"error")}},children:i.jsx(fo,{className:"w-4 h-4"})})]}),i.jsxs("div",{className:"flex gap-2 mt-3",children:[i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>{ae(W),o(a("settings.toast.keyAddedToBrowser"))},children:a("settings.useInApiBrowser")}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>re(null),children:a("common.dismiss")})]})]})]})})}),K&&i.jsxs(Mt,{className:"mb-6",children:[i.jsx(Hn,{children:i.jsx("h3",{className:"text-base font-semibold text-white",children:a("settings.createNewApiKey")})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.keyName")}),i.jsx("input",{type:"text",value:ne,onChange:_e=>O(_e.target.value),placeholder:a("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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:a("common.permissions")}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:V.can_read_status,onChange:_e=>J(zt=>({...zt,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"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white",children:a("settings.readStatus")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.readStatusDescription")})]})]}),i.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:V.can_queue,onChange:_e=>J(zt=>({...zt,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"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white",children:a("settings.manageQueue")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.manageQueueDescription")})]})]}),i.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:V.can_control_printer,onChange:_e=>J(zt=>({...zt,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"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white",children:a("settings.controlPrinter")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.controlPrinterDescription")})]})]})]})]}),i.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[i.jsxs(Oe,{onClick:()=>Zt.mutate({name:ne||a("settings.unnamedKey"),...V}),disabled:Zt.isPending,children:[Zt.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(ar,{className:"w-4 h-4"}),a("settings.createKey")]}),i.jsx(Oe,{variant:"secondary",onClick:()=>$(!1),children:a("common.cancel")})]})]})]}),It?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):Et&&Et.length>0?i.jsx("div",{className:"space-y-3",children:Et.map(_e=>i.jsx(Mt,{children:i.jsx(Dt,{className:"py-3",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx(Sl,{className:`w-5 h-5 ${_e.enabled?"text-bambu-green":"text-bambu-gray"}`}),i.jsxs("div",{children:[i.jsx("p",{className:"text-white font-medium",children:_e.name}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[_e.key_prefix,"••••••••",_e.last_used&&` · ${a("settings.lastUsed")}: ${_f(_e.last_used)}`]})]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex gap-1 text-xs",children:[_e.can_read_status&&i.jsx("span",{className:"px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded",children:a("settings.read")}),_e.can_queue&&i.jsx("span",{className:"px-1.5 py-0.5 bg-green-500/20 text-green-400 rounded",children:a("queue.title")}),_e.can_control_printer&&i.jsx("span",{className:"px-1.5 py-0.5 bg-orange-500/20 text-orange-400 rounded",children:a("settings.control")})]}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>fe(_e.id),children:i.jsx(Jt,{className:"w-4 h-4 text-red-400"})})]})]})})},_e.id))}):i.jsx(Mt,{children:i.jsx(Dt,{className:"py-12",children:i.jsxs("div",{className:"text-center text-bambu-gray",children:[i.jsx(Sl,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),i.jsx("p",{className:"text-lg font-medium text-white mb-2",children:a("settings.apiKeysEmptyTitle")}),i.jsx("p",{className:"text-sm mb-4",children:a("settings.apiKeysEmptyDescription")}),i.jsxs(Oe,{onClick:()=>$(!0),children:[i.jsx(ar,{className:"w-4 h-4"}),a("settings.createFirstKey")]})]})})}),i.jsxs(Mt,{className:"mt-6",children:[i.jsx(Hn,{children:i.jsx("h3",{className:"text-base font-semibold text-white",children:a("settings.webhookEndpoints")})}),i.jsxs(Dt,{className:"space-y-3 text-sm",children:[i.jsx("p",{className:"text-bambu-gray",children:a("settings.webhookApiKeyHint")}),i.jsxs("div",{className:"space-y-2 font-mono text-xs",children:[i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-blue-400",children:"GET"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/status"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.getAllStatus")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-blue-400",children:"GET"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/status/:id"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.getSpecificStatus")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-green-400",children:"POST"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/queue"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.addToQueue")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-orange-400",children:"POST"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/pause"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.pausePrint")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-orange-400",children:"POST"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/resume"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.resumePrint")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-red-400",children:"POST"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/stop"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.stopPrint")]})]})]})]})]})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"mb-6",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(gh,{className:"w-5 h-5 text-bambu-green"}),a("settings.apiBrowser")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a("settings.apiBrowserDescription")})]}),i.jsx(Mt,{className:"mb-4",children:i.jsxs(Dt,{className:"py-3",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:a("settings.apiKeyForTesting")}),i.jsx("input",{type:"text",value:ye,onChange:_e=>ae(_e.target.value),placeholder:a("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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:a("settings.apiKeyHint")})]})}),i.jsx(Oet,{apiKey:ye})]})]}),q==="virtual-printer"&&i.jsx(Aet,{}),q==="filament"&&k&&i.jsx(i.Fragment,{children:i.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[i.jsxs("div",{className:"lg:w-1/3 space-y-6",children:[i.jsx(vet,{}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.filamentChecks")})}),i.jsx(Dt,{className:"space-y-4",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.disableFilamentWarnings")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.disableFilamentWarningsDesc")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.disable_filament_warnings,onChange:_e=>on("disable_filament_warnings",_e.target.checked),className:"sr-only peer"}),i.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.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.amsDisplayThresholds")})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.amsThresholdsDescription")}),i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-white",children:[i.jsx(UL,{className:"w-4 h-4 text-blue-400"}),i.jsx("span",{className:"font-medium",children:a("settings.humidity")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.goodGreen")," ≤"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",min:"0",max:"100",value:k.ams_humidity_good??40,onChange:_e=>on("ams_humidity_good",parseInt(_e.target.value)||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"}),i.jsx("span",{className:"text-bambu-gray",children:"%"})]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.fairOrange")," ≤"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",min:"0",max:"100",value:k.ams_humidity_fair??60,onChange:_e=>on("ams_humidity_fair",parseInt(_e.target.value)||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"}),i.jsx("span",{className:"text-bambu-gray",children:"%"})]})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.aboveFairBad")}),i.jsx("p",{className:"text-xs text-amber-400/70",children:a("settings.fairAlsoDryingThreshold")})]}),i.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 text-white",children:[i.jsx(aT,{className:"w-4 h-4 text-orange-400"}),i.jsx("span",{className:"font-medium",children:a("settings.temperature")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.goodBlue")," ≤"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:k.ams_temp_good??28,onChange:_e=>on("ams_temp_good",parseFloat(_e.target.value)||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"}),i.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.fairOrange")," ≤"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:k.ams_temp_fair??35,onChange:_e=>on("ams_temp_fair",parseFloat(_e.target.value)||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"}),i.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.aboveFairHot")})]}),i.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 text-white",children:[i.jsx(au,{className:"w-4 h-4 text-purple-400"}),i.jsx("span",{className:"font-medium",children:a("settings.historyRetention")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.keepSensorHistory")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",min:"1",max:"365",value:k.ams_history_retention_days??30,onChange:_e=>on("ams_history_retention_days",parseInt(_e.target.value)||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"}),i.jsx("span",{className:"text-bambu-gray",children:a("common.days")})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.historyRetentionDescription")})]}),i.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 text-white",children:[i.jsx(Fp,{className:"w-4 h-4 text-amber-400"}),i.jsx("span",{className:"font-medium",children:a("settings.queueDrying")})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.queueDryingDescription")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-white",children:a("settings.queueDryingEnabled")}),i.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:a("settings.queueDryingEnabledDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.queue_drying_enabled??!1,onChange:_e=>on("queue_drying_enabled",_e.target.checked),className:"sr-only peer"}),i.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"})]})]}),k.queue_drying_enabled&&i.jsx(i.Fragment,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-white",children:a("settings.queueDryingBlock")}),i.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:a("settings.queueDryingBlockDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.queue_drying_block??!1,onChange:_e=>on("queue_drying_block",_e.target.checked),className:"sr-only peer"}),i.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"})]})]})}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-white",children:a("settings.ambientDryingEnabled")}),i.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:a("settings.ambientDryingEnabledDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.ambient_drying_enabled??!1,onChange:_e=>on("ambient_drying_enabled",_e.target.checked),className:"sr-only peer"}),i.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.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-sm text-white font-medium",children:a("settings.dryingPresets")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.dryingPresetsDescription")}),i.jsx("div",{className:"overflow-x-auto",children:i.jsxs("table",{className:"w-full text-xs",children:[i.jsx("thead",{children:i.jsxs("tr",{className:"text-bambu-gray border-b border-bambu-dark-tertiary",children:[i.jsx("th",{className:"text-left py-1.5 pr-2",children:a("settings.dryingFilament")}),i.jsx("th",{className:"text-center py-1.5 px-1",children:"AMS 2 Pro °C"}),i.jsx("th",{className:"text-center py-1.5 px-1",children:"AMS-HT °C"}),i.jsx("th",{className:"text-center py-1.5 px-1",children:"AMS 2 Pro h"}),i.jsx("th",{className:"text-center py-1.5 px-1",children:"AMS-HT h"})]})}),i.jsx("tbody",{children:(()=>{const _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}};let zt={..._e};try{if(k.drying_presets){const Pt=JSON.parse(k.drying_presets);typeof Pt=="object"&&Pt!==null&&(zt={..._e,...Pt})}}catch{}const mt=(Pt,rn,rt)=>{const un={...zt,[Pt]:{...zt[Pt],[rn]:rt}};on("drying_presets",JSON.stringify(un))};return Object.entries(zt).map(([Pt,rn])=>i.jsxs("tr",{className:"border-b border-bambu-dark-tertiary/50",children:[i.jsx("td",{className:"py-1.5 pr-2 text-white font-medium",children:Pt}),["n3f","n3s","n3f_hours","n3s_hours"].map(rt=>i.jsx("td",{className:"py-1 px-1",children:i.jsx("input",{type:"number",min:rt.includes("hours")?1:30,max:rt.includes("hours")?24:rt==="n3s"?85:65,value:rn[rt],onChange:un=>mt(Pt,rt,Math.max(1,parseInt(un.target.value)||0)),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"})},rt))]},Pt))})()})]})})]})]}),i.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 text-white",children:[i.jsx(Sr,{className:"w-4 h-4 text-bambu-green"}),i.jsx("span",{className:"font-medium",children:a("settings.printModal")})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-white",children:a("settings.expandCustomMapping")}),i.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:a("settings.expandCustomMappingDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.per_printer_mapping_expanded??!1,onChange:_e=>on("per_printer_mapping_expanded",_e.target.checked),className:"sr-only peer"}),i.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.jsxs("div",{className:"lg:w-2/3 space-y-6",children:[i.jsx(wet,{}),i.jsx(_et,{})]})]})}),ue!==null&&i.jsx(Sn,{title:a("settings.deleteApiKeyTitle"),message:a("settings.deleteApiKeyMessage"),confirmText:a("settings.deleteKey"),variant:"danger",onConfirm:()=>{tn.mutate(ue),fe(null)},onCancel:()=>fe(null)}),P&&i.jsx(det,{plug:H,onClose:()=>{D(!1),z(null)}}),G&&i.jsx(pet,{provider:ee,onClose:()=>{I(!1),ie(null)}}),X&&i.jsx(fet,{template:X,onClose:()=>me(null)}),he&&i.jsx(bet,{onClose:()=>ge(!1)}),L&&i.jsx(Sn,{title:a("settings.clearNotificationLogs"),message:a("settings.clearLogsMessage"),confirmText:a("settings.clearLogs"),variant:"warning",onConfirm:async()=>{F(!1);try{const _e=await be.clearNotificationLogs(30);o(_e.message,"success")}catch{o(a("settings.toast.clearLogsFailed"),"error")}},onCancel:()=>F(!1)}),te&&i.jsx(Sn,{title:a("settings.resetUiPreferences"),message:a("settings.resetUiPreferencesMessage"),confirmText:a("settings.resetPreferences"),variant:"default",onConfirm:()=>{ve(!1),localStorage.clear(),o(a("settings.toast.uiPreferencesReset"),"success"),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>ve(!1)}),pe&&i.jsx(Sn,{title:`Turn All Plugs ${pe==="on"?"On":"Off"}`,message:`This will turn ${pe==="on"?"ON":"OFF"} all ${Me?.filter(_e=>_e.enabled).length||0} enabled smart plugs. ${pe==="off"?"Any running printers may be affected!":""}`,confirmText:`Turn All ${pe==="on"?"On":"Off"}`,variant:pe==="off"?"danger":"warning",onConfirm:()=>{const _e=pe;de(null),Bi.mutate(_e)},onCancel:()=>de(null)}),Ne&&Tn?.release_notes&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:()=>Se(!1),children:i.jsxs(Mt,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",onClick:_e=>_e.stopPropagation(),children:[i.jsxs(Hn,{className:"flex flex-row items-center justify-between shrink-0",children:[i.jsxs("div",{children:[i.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Release Notes - v",Tn.latest_version]}),Tn.release_name&&Tn.release_name!==Tn.latest_version&&i.jsx("p",{className:"text-sm text-bambu-gray",children:Tn.release_name})]}),i.jsx("button",{onClick:()=>Se(!1),className:"p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsx(Dt,{className:"overflow-y-auto flex-1",children:i.jsx("pre",{className:"text-sm text-bambu-gray whitespace-pre-wrap font-sans",children:Tn.release_notes})}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary shrink-0 flex gap-2",children:[Tn.release_url&&i.jsx("a",{href:Tn.release_url,target:"_blank",rel:"noopener noreferrer",className:"flex-1",children:i.jsxs(Oe,{variant:"secondary",className:"w-full",children:[i.jsx(Jr,{className:"w-4 h-4"}),"View on GitHub"]})}),i.jsx(Oe,{onClick:()=>Se(!1),className:"flex-1",children:"Close"})]})]})}),q==="users"&&i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"flex gap-1 border-b border-bambu-dark-tertiary",children:[i.jsxs("button",{onClick:()=>E("users"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${j==="users"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Km,{className:"w-4 h-4"}),a("settings.tabs.users")]}),i.jsxs("button",{onClick:()=>E("email"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${j==="email"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(ix,{className:"w-4 h-4"}),a("settings.tabs.emailAuth")||"Email Authentication",Tr?.advanced_auth_enabled&&i.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"})]})]}),j==="users"&&i.jsxs(i.Fragment,{children:[i.jsx(Mt,{children:i.jsx(Dt,{className:"py-4",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center ${l?"bg-green-500/20":"bg-gray-500/20"}`,children:l?i.jsx(Ap,{className:"w-5 h-5 text-green-400"}):i.jsx(K1,{className:"w-5 h-5 text-gray-400"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-white font-medium",children:a("settings.authentication")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a(l?"settings.authEnabledDescription":"settings.authDisabledDescription")})]})]}),l?c?.is_admin&&i.jsxs(Oe,{variant:"secondary",onClick:()=>qe(!0),children:[i.jsx(K1,{className:"w-4 h-4"}),a("common.disable")]}):i.jsxs(Oe,{onClick:()=>e("/setup"),children:[i.jsx(Ap,{className:"w-4 h-4"}),a("common.enable")]})]})})}),Tr?.advanced_auth_enabled&&i.jsx(Mt,{className:"border-blue-500/30 bg-blue-500/5",children:i.jsx(Dt,{className:"py-4",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center bg-blue-500/20 flex-shrink-0",children:i.jsx(ix,{className:"w-5 h-5 text-blue-400"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-white font-medium",children:a("settings.email.advancedAuthEnabled")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a("settings.email.advancedAuthEnabledDesc")})]})]})})}),l&&i.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-6",children:[i.jsxs("div",{className:"space-y-6",children:[c&&i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Km,{className:"w-5 h-5 text-bambu-green"}),a("settings.currentUser")]}),i.jsxs(Oe,{size:"sm",variant:"ghost",onClick:()=>Te(!0),children:[i.jsx(Sl,{className:"w-4 h-4"}),a("settings.changePassword")]})]})}),i.jsx(Dt,{children:i.jsx("div",{className:"flex items-center justify-between",children:i.jsxs("div",{children:[i.jsx("p",{className:"text-white font-medium text-lg",children:c.username}),i.jsxs("div",{className:"flex flex-wrap gap-1 mt-2",children:[c.is_admin&&i.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:a("settings.admin")}),c.groups?.map(_e=>i.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${_e.name==="Administrators"?"bg-purple-500/20 text-purple-300":_e.name==="Operators"?"bg-blue-500/20 text-blue-300":_e.name==="Viewers"?"bg-green-500/20 text-green-300":"bg-gray-500/20 text-gray-300"}`,children:_e.name},_e.id))]})]})})})]}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Km,{className:"w-5 h-5 text-bambu-green"}),a("settings.users")]}),zi("users:create")&&i.jsxs(Oe,{size:"sm",onClick:()=>{Ge(!0),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:[i.jsx(ar,{className:"w-4 h-4"}),a("settings.addUser")]})]})}),i.jsx(Dt,{children:Yh?i.jsx("div",{className:"flex items-center justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Zd.length===0?i.jsx("p",{className:"text-center text-bambu-gray py-8",children:a("settings.noUsersFound")}):i.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:Zd.map(_e=>i.jsxs("div",{className:"py-3 flex items-center justify-between",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-white font-medium truncate",children:_e.username}),i.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[_e.is_admin&&i.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:a("settings.admin")}),_e.groups?.map(zt=>i.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${zt.name==="Administrators"?"bg-purple-500/20 text-purple-300":zt.name==="Operators"?"bg-blue-500/20 text-blue-300":zt.name==="Viewers"?"bg-green-500/20 text-green-300":"bg-gray-500/20 text-gray-300"}`,children:zt.name},zt.id))]})]}),i.jsxs("div",{className:"flex items-center gap-1 ml-4",children:[zi("users:update")&&i.jsx(Oe,{size:"sm",variant:"ghost",onClick:()=>Xh(_e),children:i.jsx(nh,{className:"w-4 h-4"})}),zi("users:delete")&&_e.id!==c?.id&&i.jsx(Oe,{size:"sm",variant:"ghost",onClick:()=>Ns(_e.id),children:i.jsx(Jt,{className:"w-4 h-4"})})]})]},_e.id))})})]})]}),i.jsx("div",{children:i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(v3,{className:"w-5 h-5 text-bambu-green"}),a("settings.groups")]}),zi("groups:create")&&i.jsxs(Oe,{size:"sm",onClick:()=>e("/groups/new"),children:[i.jsx(ar,{className:"w-4 h-4"}),a("settings.addGroup")]})]})}),i.jsx(Dt,{children:eg?i.jsx("div",{className:"flex items-center justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Ss.length===0?i.jsx("p",{className:"text-center text-bambu-gray py-8",children:a("settings.noGroupsFound")}):i.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:Ss.map(_e=>i.jsxs("div",{className:"py-3",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(v3,{className:`w-4 h-4 ${_e.name==="Administrators"?"text-purple-400":_e.name==="Operators"?"text-blue-400":_e.name==="Viewers"?"text-green-400":"text-bambu-gray"}`}),i.jsx("span",{className:"text-white font-medium",children:_e.name}),_e.is_system&&i.jsx("span",{className:"px-2 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:a("settings.system")})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[zi("groups:update")&&i.jsx(Oe,{size:"sm",variant:"ghost",onClick:()=>e(`/groups/${_e.id}/edit`),children:i.jsx(nh,{className:"w-4 h-4"})}),zi("groups:delete")&&!_e.is_system&&i.jsx(Oe,{size:"sm",variant:"ghost",onClick:()=>Vt(_e.id),children:i.jsx(Jt,{className:"w-4 h-4"})})]})]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1 ml-6",children:_e.description||a("settings.noDescription")}),i.jsxs("div",{className:"flex items-center gap-4 mt-2 ml-6 text-xs text-bambu-gray",children:[i.jsx("span",{children:a("settings.userCount",{count:_e.user_count})}),i.jsx("span",{children:a("settings.permissionCount",{count:_e.permissions.length})})]})]},_e.id))})})]})})]}),!l&&i.jsx(Mt,{children:i.jsx(Dt,{className:"py-6",children:i.jsxs("div",{className:"text-center",children:[i.jsx(K1,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:a("settings.authDisabledTitle")}),i.jsx("p",{className:"text-sm text-bambu-gray mb-4 max-w-md mx-auto",children:a("settings.authDisabledMessage")}),i.jsxs("ul",{className:"space-y-2 text-sm text-bambu-gray mb-6 text-left max-w-xs mx-auto",children:[i.jsxs("li",{className:"flex items-start gap-2",children:[i.jsx(fr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),i.jsx("span",{children:a("settings.authDisabledFeature1")})]}),i.jsxs("li",{className:"flex items-start gap-2",children:[i.jsx(fr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),i.jsx("span",{children:a("settings.authDisabledFeature2")})]}),i.jsxs("li",{className:"flex items-start gap-2",children:[i.jsx(fr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),i.jsx("span",{children:a("settings.authDisabledFeature3")})]})]}),i.jsxs(Oe,{onClick:()=>e("/setup"),children:[i.jsx(Ap,{className:"w-4 h-4"}),a("settings.enableAuthentication")]})]})})})]}),j==="email"&&i.jsx("div",{className:"max-w-2xl",children:i.jsx(Det,{})})]}),Ce&&!Tr?.advanced_auth_enabled&&i.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Ge(!1),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i.jsxs(Mt,{className:"w-full max-w-md",onClick:_e=>_e.stopPropagation(),children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Km,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.createUser")})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>{Ge(!1),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i.jsx(Ht,{className:"w-5 h-5"})})]})}),i.jsxs(Dt,{children:[i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.username")}),i.jsx("input",{type:"text",value:wt.username,onChange:_e=>_t({...wt,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:a("settings.enterUsername"),autoComplete:"username"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.password")}),i.jsx("input",{type:"password",value:wt.password,onChange:_e=>_t({...wt,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:a("settings.enterPassword"),autoComplete:"new-password",minLength:6})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.confirmPassword")}),i.jsx("input",{type:"password",value:wt.confirmPassword,onChange:_e=>_t({...wt,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 ${wt.confirmPassword&&wt.password!==wt.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:a("settings.confirmPasswordPlaceholder"),autoComplete:"new-password",minLength:6}),wt.confirmPassword&&wt.password!==wt.confirmPassword&&i.jsx("p",{className:"text-red-400 text-xs mt-1",children:a("settings.passwordsDoNotMatch")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.groups")}),i.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:[Ss.map(_e=>i.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:wt.group_ids.includes(_e.id),onChange:()=>Ql(_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"}),i.jsx("span",{className:"text-sm text-white",children:_e.name}),_e.is_system&&i.jsx("span",{className:"text-xs text-yellow-400",children:a("settings.systemBadge")})]},_e.id)),Ss.length===0&&i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.noGroupsAvailable")})]})]})]}),i.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>{Ge(!1),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:a("common.cancel")}),i.jsx(Oe,{onClick:Jo,disabled:Yl.isPending||!wt.username||!wt.password||wt.password!==wt.confirmPassword||wt.password.length<6,children:Yl.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),a("settings.creating")]}):i.jsxs(i.Fragment,{children:[i.jsx(ar,{className:"w-4 h-4"}),a("settings.createUser")]})})]})]})]})}),Ce&&Tr?.advanced_auth_enabled&&i.jsx(yet,{formData:wt,setFormData:_t,groups:Ss,onClose:()=>{Ge(!1),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},onCreate:Jo,isCreating:Yl.isPending,isCreateButtonDisabled:Yl.isPending||!wt.username||!wt.email}),$e&&De!==null&&i.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Ue(!1),Ve(null),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i.jsxs(Mt,{className:"w-full max-w-md",onClick:_e=>_e.stopPropagation(),children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(nh,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.editUser")})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>{Ue(!1),Ve(null),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i.jsx(Ht,{className:"w-5 h-5"})})]})}),i.jsxs(Dt,{children:[i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[a("settings.username")," ",Tr?.advanced_auth_enabled&&i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsx("input",{type:"text",value:wt.username,onChange:_e=>_t({...wt,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:a("settings.enterUsername"),autoComplete:"username"})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[a("users.form.email")||"Email"," ",Tr?.advanced_auth_enabled?i.jsx("span",{className:"text-red-400",children:"*"}):i.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",a("users.form.optional")||"optional",")"]})]}),i.jsx("input",{type:"email",value:wt.email,onChange:_e=>_t({...wt,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:a("users.form.emailPlaceholder")||"user@example.com",required:Tr?.advanced_auth_enabled})]}),!Tr?.advanced_auth_enabled&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[a("users.form.password")||"Password"," ",i.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",a("users.form.leaveBlankToKeep")||"leave blank to keep current",")"]})]}),i.jsx("input",{type:"password",value:wt.password,onChange:_e=>_t({...wt,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:a("settings.enterNewPassword"),autoComplete:"new-password",minLength:6})]}),wt.password&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.confirmPassword")}),i.jsx("input",{type:"password",value:wt.confirmPassword,onChange:_e=>_t({...wt,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 ${wt.confirmPassword&&wt.password!==wt.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:a("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),wt.confirmPassword&&wt.password!==wt.confirmPassword&&i.jsx("p",{className:"text-red-400 text-xs mt-1",children:a("settings.passwordsDoNotMatch")})]})]}),Tr?.advanced_auth_enabled&&i.jsxs("div",{className:"bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-3",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("users.form.passwordManagedByAdvancedAuth")||'Password is managed by Advanced Authentication. Use "Reset Password" to send a new password to the user via email.'}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>De&&Xl.mutate(De),disabled:Xl.isPending||!wt.email,className:"w-full",children:Xl.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),a("users.form.resettingPassword")||"Resetting Password..."]}):i.jsxs(i.Fragment,{children:[i.jsx(bo,{className:"w-4 h-4"}),a("users.form.resetPassword")||"Reset Password"]})})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("users.form.groups")||"Groups"}),i.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:Ss.map(_e=>i.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:wt.group_ids.includes(_e.id),onChange:()=>Ql(_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"}),i.jsx("span",{className:"text-sm text-white",children:_e.name}),_e.is_system&&i.jsxs("span",{className:"text-xs text-yellow-400",children:["(",a("users.system")||"System",")"]})]},_e.id))})]})]}),i.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>{Ue(!1),Ve(null),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:a("users.modal.cancel")||"Cancel"}),i.jsx(Oe,{onClick:()=>el(De),disabled:_s.isPending||!wt.username||Tr?.advanced_auth_enabled&&!wt.email||!!(!Tr?.advanced_auth_enabled&&wt.password&&(wt.password!==wt.confirmPassword||wt.password.length<6)),children:_s.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),a("users.modal.saving")||"Saving..."]}):i.jsxs(i.Fragment,{children:[i.jsx(ts,{className:"w-4 h-4"}),a("users.modal.saveChanges")||"Save Changes"]})})]})]})]})}),it!==null&&i.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",onClick:()=>{xt(null),kt(null)},children:i.jsxs(Mt,{className:"w-full max-w-md",onClick:_e=>_e.stopPropagation(),children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center gap-2 text-red-400",children:[i.jsx(Jt,{className:"w-5 h-5"}),i.jsx("h3",{className:"text-lg font-semibold",children:a("settings.deleteUserTitle")})]})}),i.jsx(Dt,{className:"space-y-4",children:We?i.jsx("div",{className:"flex items-center justify-center py-4",children:i.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-2 border-bambu-green border-t-transparent"})}):Nt&&Nt.archives+Nt.queue_items+Nt.library_files>0?i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"text-white",children:a("settings.userHasCreated")}),i.jsxs("ul",{className:"list-disc list-inside text-bambu-gray space-y-1",children:[Nt.archives>0&&i.jsxs("li",{children:[Nt.archives," archive",Nt.archives!==1?"s":""]}),Nt.queue_items>0&&i.jsxs("li",{children:[Nt.queue_items," queue item",Nt.queue_items!==1?"s":""]}),Nt.library_files>0&&i.jsxs("li",{children:[Nt.library_files," library file",Nt.library_files!==1?"s":""]})]}),i.jsx("p",{className:"text-bambu-gray text-sm",children:a("settings.userItemsQuestion")}),i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx(Oe,{variant:"danger",onClick:()=>ci.mutate({id:it,deleteItems:!0}),disabled:ci.isPending,className:"justify-center",children:a("settings.deleteUserAndItems")}),i.jsx(Oe,{variant:"secondary",onClick:()=>ci.mutate({id:it,deleteItems:!1}),disabled:ci.isPending,className:"justify-center",children:a("settings.deleteUserKeepItems")}),i.jsx(Oe,{variant:"ghost",onClick:()=>{xt(null),kt(null)},disabled:ci.isPending,className:"justify-center",children:a("common.cancel")})]})]}):i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"text-white",children:a("settings.deleteUserConfirm")}),i.jsx("p",{className:"text-bambu-gray text-sm",children:a("settings.actionCannotBeUndone")}),i.jsxs("div",{className:"flex gap-2 justify-end",children:[i.jsx(Oe,{variant:"ghost",onClick:()=>{xt(null),kt(null)},disabled:ci.isPending,children:a("common.cancel")}),i.jsx(Oe,{variant:"danger",onClick:()=>ci.mutate({id:it,deleteItems:!1}),disabled:ci.isPending,children:a("settings.deleteUserTitle")})]})]})})]})}),Ot!==null&&i.jsx(Sn,{title:a("settings.deleteGroupTitle"),message:a("settings.deleteGroupMessage"),confirmText:a("settings.deleteGroup"),variant:"danger",onConfirm:()=>{Zo.mutate(Ot),Vt(null)},onCancel:()=>Vt(null)}),q==="backup"&&i.jsx(Met,{}),Le&&i.jsx(Sn,{title:a("settings.disableAuthenticationTitle"),message:a("settings.disableAuthenticationMessage"),confirmText:a("settings.disableAuthentication"),variant:"danger",onConfirm:async()=>{try{await be.disableAuth(),o(a("settings.toast.authDisabled"),"success"),await u(),qe(!1),window.location.href="/"}catch(_e){const zt=_e instanceof Error?_e.message:a("settings.toast.authDisableFailed");o(zt,"error")}},onCancel:()=>qe(!1)}),Ee&&i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:()=>{Te(!1),Be({currentPassword:"",newPassword:"",confirmPassword:""})},children:i.jsxs(Mt,{className:"w-full max-w-md",onClick:_e=>_e.stopPropagation(),children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Sl,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.changePassword")})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>{Te(!1),Be({currentPassword:"",newPassword:"",confirmPassword:""})},children:i.jsx(Ht,{className:"w-5 h-5"})})]})}),i.jsxs(Dt,{children:[i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Current Password"}),i.jsx("input",{type:"password",value:Ae.currentPassword,onChange:_e=>Be({...Ae,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:a("settings.enterCurrentPassword"),autoComplete:"current-password"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"New Password"}),i.jsx("input",{type:"password",value:Ae.newPassword,onChange:_e=>Be({...Ae,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:a("settings.enterNewPasswordMin6"),autoComplete:"new-password",minLength:6})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Confirm New Password"}),i.jsx("input",{type:"password",value:Ae.confirmPassword,onChange:_e=>Be({...Ae,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 ${Ae.confirmPassword&&Ae.newPassword!==Ae.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:a("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),Ae.confirmPassword&&Ae.newPassword!==Ae.confirmPassword&&i.jsx("p",{className:"text-red-400 text-xs mt-1",children:a("settings.passwordsDoNotMatch")})]})]}),i.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>{Te(!1),Be({currentPassword:"",newPassword:"",confirmPassword:""})},children:a("common.cancel")}),i.jsx(Oe,{onClick:async()=>{if(Ae.newPassword!==Ae.confirmPassword){o(a("settings.toast.passwordsDoNotMatch"),"error");return}if(Ae.newPassword.length<6){o(a("settings.toast.passwordTooShort"),"error");return}Xe(!0);try{await be.changePassword(Ae.currentPassword,Ae.newPassword),o(a("settings.toast.passwordChanged"),"success"),Te(!1),Be({currentPassword:"",newPassword:"",confirmPassword:""})}catch(_e){const zt=_e instanceof Error?_e.message:"Failed to change password";o(zt,"error")}finally{Xe(!1)}},disabled:je||!Ae.currentPassword||!Ae.newPassword||Ae.newPassword!==Ae.confirmPassword||Ae.newPassword.length<6,children:je?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),a("settings.changing")]}):i.jsxs(i.Fragment,{children:[i.jsx(Sl,{className:"w-4 h-4"}),a("settings.changePassword")]})})]})]})]})})]})}const Loe=t=>{const e=parseFloat(t);return(Math.trunc(e*1e3)/1e3).toFixed(3)},Bet=t=>t.startsWith("HH")?"HF":"S",Het=t=>{const e=t.match(/^([A-Z]{2}\d{2})/);return e?e[1]:"HH00"},Ooe=t=>{const e=["High Flow_","High Flow ","Standard_","Standard ","HF_","HF ","S_","S "];for(const r of e)if(t.startsWith(r))return t.slice(r.length);const n=t.indexOf("_");return n>0?t.slice(n+1):t};function zD({profile:t,onEdit:e,onCopy:n,selectionMode:r,isSelected:a,onToggleSelect:s,note:o}){const l=Bet(t.nozzle_id),c=t.nozzle_diameter,u=()=>{r&&s?s():e()};return i.jsxs("div",{className:"flex items-center gap-2",children:[r&&i.jsx("button",{onClick:s,className:"text-bambu-gray hover:text-white transition-colors p-1",children:a?i.jsx(xo,{className:"w-4 h-4 text-bambu-green"}):i.jsx(zl,{className:"w-4 h-4"})}),i.jsxs("button",{onClick:u,className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${a?"ring-1 ring-bambu-green":""}`,children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-bambu-green font-mono text-sm font-bold whitespace-nowrap",children:Loe(t.k_value)}),i.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name||"Unnamed"}),o&&i.jsx("span",{title:"Has note",children:i.jsx(ZX,{className:"w-3 h-3 text-yellow-500"})}),i.jsxs("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:[l," ",c]})]}),o&&i.jsxs("div",{className:"text-xs mt-0.5 truncate text-yellow-500/70",title:o,children:["Note: ",o.length>50?o.substring(0,50)+"...":o]})]}),!r&&n&&i.jsx("button",{onClick:d=>{d.stopPropagation(),n()},className:"text-bambu-gray hover:text-white transition-colors p-1",title:"Copy profile",children:i.jsx(fo,{className:"w-4 h-4"})})]})}function UD({profile:t,printerId:e,nozzleDiameter:n,existingProfiles:r=[],builtinFilaments:a=[],isDualNozzle:s=!1,initialNote:o="",initialNoteKey:l=null,onClose:c,onSave:u,onSaveNote:d,hasPermission:m}){const{t:p}=Ft(),{showToast:f}=fn(),[y,v]=w.useState(t?.name||""),[x,g]=w.useState(t?.k_value?Loe(t.k_value):"0.020"),[_,N]=w.useState(t?.filament_id||""),[T,C]=w.useState(t?.nozzle_id?Het(t.nozzle_id):"HH00"),[A,k]=w.useState(t?.nozzle_diameter||n),[R,P]=w.useState(t?[t.extruder_id]:s?[0,1]:[0]),[D,H]=w.useState(!1),[z,G]=w.useState({current:0,total:0}),[I,ee]=w.useState(o),ie=Vr.useMemo(()=>{const le=new Map;for(const Pe of a)le.set(Pe.filament_id,Pe.name);const xe=new Map;for(const Pe of r)if(Pe.filament_id&&!xe.has(Pe.filament_id)){const Z=le.get(Pe.filament_id)||Ooe(Pe.name||"");xe.set(Pe.filament_id,{id:Pe.filament_id,name:Z||Pe.filament_id})}return Array.from(xe.values()).sort((Pe,q)=>Pe.name.localeCompare(q.name))},[r,a]),X=pt({mutationFn:le=>(console.log("[KProfile] Calling API..."),be.setKProfile(e,le)),onSuccess:le=>{if(console.log("[KProfile] Save success:",le),f(p("kProfiles.toast.profileSaved")),d&&I!==o){let xe;I===""&&l?xe=l:t&&t.slot_id>0?xe=t.setting_id||`slot_${t.slot_id}_${t.filament_id}_${t.extruder_id}`:xe=`name_${y}_${_}`,d(xe,I)}H(!0),setTimeout(()=>{H(!1),u()},2500)},onError:le=>{console.error("[KProfile] Save error:",le),f(le.message,"error"),H(!1)}}),me=pt({mutationFn:le=>(console.log("[KProfile] Deleting profile..."),be.deleteKProfile(e,le)),onSuccess:le=>{console.log("[KProfile] Delete success:",le),f(p("kProfiles.toast.profileDeleted")),H(!0),setTimeout(()=>{H(!1),c()},4e3)},onError:le=>{console.error("[KProfile] Delete error:",le),f(le.message,"error"),H(!1)}}),[he,ge]=w.useState(!1),Y=()=>{t&&me.mutate({slot_id:t.slot_id,extruder_id:t.extruder_id,nozzle_id:t.nozzle_id,nozzle_diameter:t.nozzle_diameter,filament_id:t.filament_id,setting_id:t.setting_id})},oe=async le=>{if(le.preventDefault(),s&&!t&&R.length===0){f(p("kProfiles.toast.selectAtLeastOneExtruder"),"error");return}const xe=parseFloat(x).toFixed(6),Pe=`${T}-${A}`;if(t||R.length===1){const Z={name:y,k_value:xe,filament_id:_,nozzle_id:Pe,nozzle_diameter:A,extruder_id:t?t.extruder_id:R[0],setting_id:t?.setting_id,slot_id:t?.slot_id??0};console.log("[KProfile] Saving profile:",Z),X.mutate(Z);return}H(!0),G({current:1,total:R.length});const q=R.map(Z=>({name:y,k_value:xe,filament_id:_,nozzle_id:Pe,nozzle_diameter:A,extruder_id:Z,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${q.length} profiles in batch:`,q);try{if(await be.setKProfilesBatch(e,q),f(p("kProfiles.toast.profilesSaved",{count:R.length})),d&&I){const Z=`name_${y}_${_}`;d(Z,I)}}catch(Z){console.error("[KProfile] Failed to save batch:",Z),f(p("kProfiles.toast.failedToSaveBatch"),"error"),H(!1),G({current:0,total:0});return}G({current:R.length,total:R.length}),setTimeout(()=>{H(!1),G({current:0,total:0}),u()},3e3)};return i.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:[i.jsxs(Mt,{className:"w-full max-w-md relative",children:[D&&i.jsxs("div",{className:"absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg",children:[i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin mb-3"}),i.jsx("p",{className:"text-white font-medium",children:z.total>1?p("kProfiles.modal.savingExtruder",{current:z.current,total:z.total}):p("kProfiles.modal.syncing")}),i.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:p("kProfiles.modal.pleaseWait")})]}),i.jsxs(Dt,{className:"p-0",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsx("h2",{className:"text-xl font-semibold text-white",children:p(t?"kProfiles.modal.editTitle":"kProfiles.modal.addTitle")}),i.jsx("button",{onClick:c,className:"text-bambu-gray hover:text-white transition-colors",disabled:D,children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:oe,className:"p-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.profileName")}),i.jsx("input",{type:"text",value:y,onChange:le=>v(le.target.value),disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,placeholder:p("kProfiles.modal.profileNamePlaceholder"),required:!t})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.kValue")}),i.jsx("input",{type:"text",inputMode:"decimal",value:x,onChange:le=>{const xe=le.target.value;(xe===""||/^\d*\.?\d*$/.test(xe))&&g(xe)},onBlur:le=>{const xe=parseFloat(le.target.value);isNaN(xe)||g((Math.trunc(xe*1e3)/1e3).toFixed(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",placeholder:p("kProfiles.modal.kValuePlaceholder"),required:!0}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:p("kProfiles.modal.kValueHelp")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.filament")}),i.jsxs("select",{value:_,onChange:le=>{const xe=le.target.value;if(N(xe),!t&&xe&&!y){const Pe=ie.find(q=>q.id===xe);Pe&&v(`${T==="HH00"?"HF":"S"} ${Pe.name}`)}},disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,required:!t,children:[i.jsx("option",{value:"",children:p("kProfiles.modal.selectFilament")}),t?.filament_id&&i.jsx("option",{value:t.filament_id,children:ie.find(le=>le.id===t.filament_id)?.name||t.filament_id},t.filament_id),!t&&ie.map(le=>i.jsx("option",{value:le.id,children:le.name},le.id))]}),!t&&ie.length===0&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:p("kProfiles.modal.noFilamentsHelp")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.flowType")}),i.jsxs("select",{value:T,onChange:le=>{const xe=le.target.value;if(C(xe),!t&&_&&!y){const Pe=ie.find(q=>q.id===_);Pe&&v(`${xe==="HS00"?"HF":"S"} ${Pe.name}`)}},disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,children:[i.jsx("option",{value:"HH00",children:p("kProfiles.modal.highFlow")}),i.jsx("option",{value:"HS00",children:p("kProfiles.modal.standard")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.nozzleSize")}),i.jsxs("select",{value:A,onChange:le=>k(le.target.value),disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,children:[i.jsx("option",{value:"0.2",children:"0.2mm"}),i.jsx("option",{value:"0.4",children:"0.4mm"}),i.jsx("option",{value:"0.6",children:"0.6mm"}),i.jsx("option",{value:"0.8",children:"0.8mm"})]})]})]}),s&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p(t?"kProfiles.modal.extruder":"kProfiles.modal.extruders")}),t?i.jsx("div",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60",children:t.extruder_id===1?p("kProfiles.modal.left"):p("kProfiles.modal.right")}):i.jsxs("div",{className:"flex gap-4",children:[i.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:R.includes(1),onChange:le=>{le.target.checked?P([...R,1]):P(R.filter(xe=>xe!==1))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),i.jsx("span",{className:"text-white",children:p("kProfiles.modal.left")})]}),i.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:R.includes(0),onChange:le=>{le.target.checked?P([...R,0]):P(R.filter(xe=>xe!==0))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),i.jsx("span",{className:"text-white",children:p("kProfiles.modal.right")})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.notes")}),i.jsx("textarea",{value:I,onChange:le=>ee(le.target.value),placeholder:p("kProfiles.modal.notesPlaceholder"),rows:2,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 resize-none"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:p("kProfiles.modal.notesHelp")})]}),i.jsxs("div",{className:"flex gap-2 pt-4",children:[t&&i.jsx(Oe,{type:"button",variant:"secondary",onClick:()=>ge(!0),disabled:me.isPending||D||!m("kprofiles:delete"),title:m("kprofiles:delete")?void 0:p("kProfiles.permission.noDelete"),className:"text-red-500 hover:bg-red-500/10",children:me.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Jt,{className:"w-4 h-4"})}),i.jsx(Oe,{type:"button",variant:"secondary",onClick:c,disabled:D,className:"flex-1",children:p("common.cancel")}),i.jsxs(Oe,{type:"submit",disabled:X.isPending||D||!m(t?"kprofiles:update":"kprofiles:create"),title:m(t?"kprofiles:update":"kprofiles:create")?void 0:p(t?"kProfiles.permission.noUpdate":"kProfiles.permission.noCreate"),className:"flex-1",children:[X.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(ZC,{className:"w-4 h-4"}),p("common.save")]})]})]})]})]}),he&&i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",children:i.jsx(Mt,{className:"w-full max-w-sm",children:i.jsxs(Dt,{className:"p-6",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[i.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:i.jsx(Jt,{className:"w-5 h-5 text-red-500"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:p("kProfiles.deleteConfirm.title")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:p("kProfiles.deleteConfirm.cannotUndo")})]})]}),i.jsx("p",{className:"text-bambu-gray mb-6",children:p("kProfiles.deleteConfirm.message",{name:t?.name})}),i.jsxs("div",{className:"flex gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>ge(!1),className:"flex-1",children:p("common.cancel")}),i.jsxs(Oe,{onClick:()=>{ge(!1),Y()},disabled:me.isPending,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[me.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Jt,{className:"w-4 h-4"}),p("common.delete")]})]})]})})})]})}const V1={NOZZLE_DIAMETER:"bambusy_kprofiles_nozzle",SORT_OPTION:"bambusy_kprofiles_sort"};function $et(){const{t}=Ft(),{showToast:e}=fn(),{hasPermission:n}=_r(),[r,a]=w.useState(null),[s,o]=w.useState(()=>localStorage.getItem(V1.NOZZLE_DIAMETER)||"0.4"),[l,c]=w.useState(null),[u,d]=w.useState(!1),[m,p]=w.useState(null),[f,y]=w.useState(""),[v,x]=w.useState("all"),[g,_]=w.useState("all"),[N,T]=w.useState(()=>localStorage.getItem(V1.SORT_OPTION)||"name"),[C,A]=w.useState(!1),[k,R]=w.useState(new Set),[P,D]=w.useState(!1),[H,z]=w.useState(!1),G=w.useCallback(F=>`${F.slot_id}_${F.extruder_id}`,[]);w.useEffect(()=>{localStorage.setItem(V1.NOZZLE_DIAMETER,s)},[s]),w.useEffect(()=>{localStorage.setItem(V1.SORT_OPTION,N)},[N]);const{data:I,isLoading:ee}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:ie,isLoading:X,isFetching:me,error:he,refetch:ge}=et({queryKey:["kprofiles",r,s],queryFn:async()=>{console.log("[KProfiles] Fetching profiles for printer",r,"nozzle",s);const F=await be.getKProfiles(r,s);return console.log("[KProfiles] Received profiles:",F?.profiles?.length||0,"profiles"),F},enabled:!!r,retry:!1,staleTime:0,gcTime:0,refetchOnMount:"always"}),{data:Y}=et({queryKey:["kprofiles",r,"0.4"],queryFn:()=>be.getKProfiles(r,"0.4"),enabled:!!r,staleTime:6e4}),{data:oe}=et({queryKey:["builtinFilaments"],queryFn:()=>be.getBuiltinFilaments(),staleTime:3e5}),{data:le}=et({queryKey:["filamentIdMap"],queryFn:()=>be.getFilamentIdMap(),staleTime:3e5}),{data:xe,refetch:Pe}=et({queryKey:["kprofile-notes",r],queryFn:()=>be.getKProfileNotes(r),enabled:!!r,staleTime:3e4}),q=he?.message?.includes("not connected");w.useEffect(()=>{if(!r&&I&&I.length>0){const F=I.find(te=>te.is_active);F&&a(F.id)}},[r,I]),w.useEffect(()=>{if(r){const F=setTimeout(()=>{ge()},150);return()=>clearTimeout(F)}},[r,s]);const Z=I?.filter(F=>F.is_active)||[],j=Vr.useMemo(()=>{const F=new Map;if(oe)for(const te of oe)F.set(te.filament_id,te.name);if(le)for(const[te,ve]of Object.entries(le))F.has(te)||F.set(te,ve);return F},[oe,le]),E=Vr.useMemo(()=>Array.from(j.entries()).map(([F,te])=>({filament_id:F,name:te})),[j]),U=Vr.useCallback(F=>j.get(F.filament_id)||Ooe(F.name),[j]),K=Vr.useMemo(()=>ie?.profiles?ie.profiles.filter(te=>{const ve=f.toLowerCase(),pe=!ve||te.name.toLowerCase().includes(ve)||te.filament_id.toLowerCase().includes(ve),de=v==="all"||v==="left"&&te.extruder_id===1||v==="right"&&te.extruder_id===0,Ne=g==="all"||g==="hf"&&te.nozzle_id.startsWith("HH")||g==="s"&&te.nozzle_id.startsWith("HS");return pe&&de&&Ne}).sort((te,ve)=>{switch(N){case"k_value":return parseFloat(te.k_value)-parseFloat(ve.k_value);case"filament":return U(te).localeCompare(U(ve));default:return te.name.localeCompare(ve.name)}}):[],[ie?.profiles,f,v,g,N,U]),$=I?.find(F=>F.id===r),ne=$?.nozzle_count===2;w.useEffect(()=>{const F=te=>{te.target instanceof HTMLInputElement||te.target instanceof HTMLTextAreaElement||te.target instanceof HTMLSelectElement||l||u||m||(te.key==="r"||te.key==="R"?(te.preventDefault(),ge()):te.key==="n"||te.key==="N"?(te.preventDefault(),d(!0)):te.key==="Escape"&&C&&(te.preventDefault(),A(!1),R(new Set)))};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[l,u,m,C,ge]);const O=w.useCallback(()=>{if(!ie?.profiles||ie.profiles.length===0){e(t("kProfiles.toast.noProfilesToExport"),"error");return}const F={version:1,exported_at:new Date().toISOString(),printer:$?.name||"Unknown",nozzle_diameter:s,profiles:ie.profiles.map(de=>({name:de.name,k_value:de.k_value,filament_id:de.filament_id,nozzle_id:de.nozzle_id,nozzle_diameter:de.nozzle_diameter,extruder_id:de.extruder_id}))},te=new Blob([JSON.stringify(F,null,2)],{type:"application/json"}),ve=URL.createObjectURL(te),pe=document.createElement("a");pe.href=ve,pe.download=`kprofiles_${$?.name||"printer"}_${s}mm_${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(pe),pe.click(),document.body.removeChild(pe),URL.revokeObjectURL(ve),e(t("kProfiles.toast.exportedProfiles",{count:ie.profiles.length}))},[ie?.profiles,$,s,e,t]),V=w.useCallback(()=>{const F=document.createElement("input");F.type="file",F.accept=".json",F.onchange=async te=>{const ve=te.target.files?.[0];if(ve)try{const pe=await ve.text(),de=JSON.parse(pe);if(!de.profiles||!Array.isArray(de.profiles)){e(t("kProfiles.toast.invalidFileFormat"),"error");return}let Ne=0;for(const Se of de.profiles)if(!(!Se.name||!Se.k_value||!Se.filament_id))try{await be.setKProfile(r,{name:Se.name,k_value:parseFloat(Se.k_value).toFixed(6),filament_id:Se.filament_id,nozzle_id:Se.nozzle_id||`HH00-${s}`,nozzle_diameter:Se.nozzle_diameter||s,extruder_id:Se.extruder_id??0,slot_id:0}),Ne++,await new Promise(Le=>setTimeout(Le,500))}catch(Le){console.error("Failed to import profile:",Se.name,Le)}e(t("kProfiles.toast.importedProfiles",{count:Ne,total:de.profiles.length})),ge()}catch(pe){console.error("Import error:",pe),e(t("kProfiles.toast.failedToParseImport"),"error")}},F.click()},[r,s,e,ge,t]),J=w.useCallback(F=>{R(te=>{const ve=new Set(te);return ve.has(F)?ve.delete(F):ve.add(F),ve})},[]),W=w.useCallback(()=>{R(new Set(K.map(F=>G(F))))},[K,G]),re=w.useCallback(()=>{k.size!==0&&D(!0)},[k.size]),ue=w.useCallback(async()=>{const F=K.filter(ve=>k.has(G(ve)));z(!0);let te=0;for(const ve of F)try{await be.deleteKProfile(r,{slot_id:ve.slot_id,extruder_id:ve.extruder_id,nozzle_id:ve.nozzle_id,nozzle_diameter:ve.nozzle_diameter,filament_id:ve.filament_id,setting_id:ve.setting_id}),te++,await new Promise(pe=>setTimeout(pe,300))}catch(pe){console.error("Failed to delete profile:",ve.name,pe)}e(t("kProfiles.toast.profilesDeleted",{count:te})),z(!1),D(!1),A(!1),R(new Set),ge()},[r,k,K,e,ge,G,t]),fe=w.useCallback(F=>{const te=[];return F.setting_id&&te.push(F.setting_id),te.push(`slot_${F.slot_id}_${F.filament_id}_${F.extruder_id}`),te.push(`name_${F.name}_${F.filament_id}`),te},[]),ye=w.useCallback(async(F,te)=>{if(r)try{await be.setKProfileNote(r,F,te),Pe()}catch(ve){console.error("Failed to save note:",ve),e(t("kProfiles.toast.failedToSaveNote"),"error")}},[r,Pe,e,t]),ae=w.useCallback(F=>{if(!xe?.notes)return{note:"",key:null};const te=fe(F);for(const ve of te)if(xe.notes[ve])return{note:xe.notes[ve],key:ve};return{note:"",key:null}},[xe,fe]),L=w.useCallback(F=>ae(F).note,[ae]);return ee?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):!I||I.length===0?i.jsx(Mt,{children:i.jsxs(Dt,{className:"py-12 text-center",children:[i.jsx(Li,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noPrintersConfigured")}),i.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.addPrinterInSettings")})]})}):Z.length===0?i.jsx(Mt,{children:i.jsxs(Dt,{className:"py-12 text-center",children:[i.jsx(Sr,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noActivePrinters")}),i.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.enablePrinterConnection")})]})}):i.jsxs(i.Fragment,{children:[me&&!X&&i.jsxs("div",{className:"fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40",children:[i.jsx(ht,{className:"w-10 h-10 text-bambu-green animate-spin mb-3"}),i.jsx("p",{className:"text-white font-medium",children:t("kProfiles.loadingProfiles")})]}),i.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[i.jsxs("div",{className:"flex-1 min-w-48",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.printer")}),i.jsx("select",{value:r||"",onChange:F=>a(parseInt(F.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:Z.map(F=>i.jsx("option",{value:F.id,children:F.name},F.id))})]}),i.jsxs("div",{className:"w-32",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.nozzle")}),i.jsxs("select",{value:s,onChange:F=>o(F.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:[i.jsx("option",{value:"0.2",children:"0.2mm"}),i.jsx("option",{value:"0.4",children:"0.4mm"}),i.jsx("option",{value:"0.6",children:"0.6mm"}),i.jsx("option",{value:"0.8",children:"0.8mm"})]})]}),i.jsxs("div",{className:"flex items-end gap-2",children:[i.jsxs(Oe,{variant:"secondary",onClick:()=>ge(),disabled:me||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noRead"),children:[i.jsx(wr,{className:`w-4 h-4 ${me?"animate-spin":""}`}),t("kProfiles.refresh")]}),i.jsxs(Oe,{onClick:()=>d(!0),disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noCreate"),children:[i.jsx(ar,{className:"w-4 h-4"}),t("kProfiles.addProfile")]})]})]}),i.jsxs("div",{className:"flex flex-wrap gap-4 mb-4",children:[i.jsxs("div",{className:"flex-1 min-w-48 relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:f,onChange:F=>y(F.target.value),placeholder:t("kProfiles.searchPlaceholder"),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"})]}),ne&&i.jsx("div",{className:"w-36",children:i.jsxs("select",{value:v,onChange:F=>x(F.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:[i.jsx("option",{value:"all",children:t("kProfiles.allExtruders")}),i.jsx("option",{value:"left",children:t("kProfiles.leftOnly")}),i.jsx("option",{value:"right",children:t("kProfiles.rightOnly")})]})}),i.jsx("div",{className:"w-32",children:i.jsxs("select",{value:g,onChange:F=>_(F.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:[i.jsx("option",{value:"all",children:t("kProfiles.allFlow")}),i.jsx("option",{value:"hf",children:t("kProfiles.hfOnly")}),i.jsx("option",{value:"s",children:t("kProfiles.sOnly")})]})}),i.jsx("div",{className:"w-32",children:i.jsxs("select",{value:N,onChange:F=>T(F.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:[i.jsx("option",{value:"name",children:t("kProfiles.sortName")}),i.jsx("option",{value:"k_value",children:t("kProfiles.sortKValue")}),i.jsx("option",{value:"filament",children:t("kProfiles.sortFilament")})]})})]}),i.jsxs("div",{className:"flex flex-wrap gap-2 mb-6",children:[i.jsxs(Oe,{variant:"secondary",onClick:O,disabled:!ie?.profiles?.length||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noExport"),children:[i.jsx(pi,{className:"w-4 h-4"}),t("kProfiles.export")]}),i.jsxs(Oe,{variant:"secondary",onClick:V,disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noImport"),children:[i.jsx(xi,{className:"w-4 h-4"}),t("kProfiles.import")]}),i.jsx("div",{className:"flex-1"}),C?i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"secondary",onClick:W,children:[i.jsx(xo,{className:"w-4 h-4"}),t("kProfiles.selectAll")]}),i.jsxs(Oe,{variant:"secondary",onClick:re,disabled:k.size===0||!n("kprofiles:delete"),className:"text-red-500 hover:bg-red-500/10",title:n("kprofiles:delete")?void 0:t("kProfiles.permission.noDelete"),children:[i.jsx(Jt,{className:"w-4 h-4"}),t("kProfiles.delete")," (",k.size,")"]}),i.jsxs(Oe,{variant:"secondary",onClick:()=>{A(!1),R(new Set)},children:[i.jsx(Ht,{className:"w-4 h-4"}),t("common.cancel")]})]}):i.jsxs(Oe,{variant:"secondary",onClick:()=>A(!0),disabled:!K.length||!n("kprofiles:delete"),title:n("kprofiles:delete")?void 0:t("kProfiles.permission.noDelete"),children:[i.jsx(xo,{className:"w-4 h-4"}),t("kProfiles.select")]})]}),X?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):q?i.jsx(Mt,{children:i.jsxs(Dt,{className:"py-12 text-center",children:[i.jsx(Ph,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.printerOffline")}),i.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.printerOfflineDesc")}),i.jsxs(Oe,{variant:"secondary",onClick:()=>ge(),children:[i.jsx(wr,{className:"w-4 h-4"}),t("common.refresh")]})]})}):K.length>0?ne?i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.leftExtruder")}),i.jsx("div",{className:"space-y-1",children:K.filter(F=>F.extruder_id===1).map(F=>i.jsx(zD,{profile:F,onEdit:()=>c(F),onCopy:()=>p(F),selectionMode:C,isSelected:k.has(G(F)),onToggleSelect:()=>J(G(F)),note:L(F)},G(F)))})]}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.rightExtruder")}),i.jsx("div",{className:"space-y-1",children:K.filter(F=>F.extruder_id===0).map(F=>i.jsx(zD,{profile:F,onEdit:()=>c(F),onCopy:()=>p(F),selectionMode:C,isSelected:k.has(G(F)),onToggleSelect:()=>J(G(F)),note:L(F)},G(F)))})]})]}):i.jsx("div",{className:"space-y-1",children:K.map(F=>i.jsx(zD,{profile:F,onEdit:()=>c(F),onCopy:()=>p(F),selectionMode:C,isSelected:k.has(G(F)),onToggleSelect:()=>J(G(F)),note:L(F)},G(F)))}):f||v!=="all"||g!=="all"?i.jsx(Mt,{children:i.jsxs(Dt,{className:"py-12 text-center",children:[i.jsx(jr,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noMatchingProfiles")}),i.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.noMatchingProfilesDesc")})]})}):i.jsx(Mt,{children:i.jsxs(Dt,{className:"py-12 text-center",children:[i.jsx(ZC,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noKProfiles")}),i.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.noKProfilesDesc",{diameter:s})}),i.jsxs(Oe,{onClick:()=>d(!0),children:[i.jsx(ar,{className:"w-4 h-4"}),t("kProfiles.createFirstProfile")]})]})}),l&&r&&(()=>{const{note:F,key:te}=ae(l);return i.jsx(UD,{profile:l,printerId:r,nozzleDiameter:s,existingProfiles:Y?.profiles||ie?.profiles,builtinFilaments:E,isDualNozzle:ne,initialNote:F,initialNoteKey:te,onSaveNote:ye,hasPermission:n,onClose:()=>{console.log("[KProfiles] Edit modal onClose - refetching profiles..."),c(null),ge()},onSave:()=>{c(null),ge()}})})(),u&&r&&i.jsx(UD,{printerId:r,nozzleDiameter:s,existingProfiles:Y?.profiles||ie?.profiles,builtinFilaments:E,isDualNozzle:ne,onSaveNote:ye,hasPermission:n,onClose:()=>{d(!1),ge()},onSave:()=>{d(!1),ge()}}),m&&r&&i.jsx(UD,{printerId:r,nozzleDiameter:s,existingProfiles:Y?.profiles||ie?.profiles,builtinFilaments:E,isDualNozzle:ne,onSaveNote:ye,hasPermission:n,profile:{...m,slot_id:0,name:`${m.name} (Copy)`},onClose:()=>{p(null),ge()},onSave:()=>{p(null),ge()}}),P&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:i.jsx(Mt,{className:"w-full max-w-sm",children:i.jsxs(Dt,{className:"p-6",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[i.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:i.jsx(Jt,{className:"w-5 h-5 text-red-500"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:t("kProfiles.bulkDelete.title")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t("kProfiles.bulkDelete.cannotUndo")})]})]}),i.jsx("p",{className:"text-bambu-gray mb-6",children:t("kProfiles.bulkDelete.message",{count:k.size})}),i.jsxs("div",{className:"flex gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>D(!1),disabled:H,className:"flex-1",children:t("common.cancel")}),i.jsxs(Oe,{onClick:ue,disabled:H,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[H?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Jt,{className:"w-4 h-4"}),t("common.delete")]})]})]})})})]})}const Ioe=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","PVA","HIPS","PP","PET","NYLON"],qet={PLA:"E8E8E8",PETG:"4A90D9",ABS:"E67E22",ASA:"D35400",TPU:"9B59B6",PC:"BDC3C7",PA:"2ECC71",NYLON:"2ECC71",PVA:"F1C40F",HIPS:"95A5A6",PP:"ECF0F1",PET:"3498DB"};function Vet(t){const e=t.toUpperCase();for(const n of Ioe)if(new RegExp(`\\b${n}\\b`).test(e))return n;return null}function Get(t){const e=t.replace(/@.+$/,"").trim(),n=e.toUpperCase();for(const r of Ioe){const a=n.indexOf(r);if(a>0){const s=e.slice(0,a).trim();if(s&&s.length>1)return s}}return null}function BD({preset:t,onDelete:e,onExpand:n,isExpanded:r}){const{t:a}=Ft(),{hasPermission:s}=_r(),o=t.filament_type||Vet(t.name),l=t.filament_vendor||Get(t.name);let c=null,u=!1;if(t.default_filament_colour)try{const d=JSON.parse(t.default_filament_colour),m=Array.isArray(d)?d[0]:d;typeof m=="string"&&/^#?[0-9a-fA-F]{6,8}$/.test(m.replace("#",""))&&(c=m.replace("#","").slice(0,6),u=!0)}catch{const d=t.default_filament_colour;/^#?[0-9a-fA-F]{6,8}$/.test(d.replace("#",""))&&(c=d.replace("#","").slice(0,6),u=!0)}return!c&&o&&(c=qet[o.toUpperCase()]||null),i.jsx(Mt,{className:"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80 transition-colors",children:i.jsxs(Dt,{className:"p-3",children:[i.jsxs("div",{className:"flex items-start justify-between gap-2",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.preset_type==="filament"&&i.jsx("div",{className:`w-4 h-4 rounded-full border border-white/20 flex-shrink-0 ${!u&&!c?"opacity-25":u?"":"opacity-50"}`,style:{backgroundColor:c?`#${c}`:"#666"}}),i.jsx("span",{className:"text-sm font-medium text-white truncate",children:t.name})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[o&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green",children:o}),l&&i.jsx("span",{className:"text-xs text-bambu-gray",children:l}),i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-400",children:a("profiles.localProfiles.badge")})]})]}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[s("settings:update")&&i.jsx("button",{onClick:()=>e(t.id),className:"p-1 text-bambu-gray hover:text-red-400 transition-colors",title:a("profiles.localProfiles.delete"),children:i.jsx(Jt,{className:"w-3.5 h-3.5"})}),i.jsx("button",{onClick:()=>n(r?null:t.id),className:"p-1 text-bambu-gray hover:text-white transition-colors",children:r?i.jsx(Il,{className:"w-3.5 h-3.5"}):i.jsx(Ln,{className:"w-3.5 h-3.5"})})]})]}),r&&i.jsxs("div",{className:"mt-3 pt-3 border-t border-bambu-dark-tertiary text-xs space-y-1.5",children:[o&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.filamentType")}),i.jsx("span",{className:"text-white",children:o})]}),l&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.vendor")}),i.jsx("span",{className:"text-white",children:l})]}),t.nozzle_temp_min!=null&&t.nozzle_temp_max!=null&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.nozzleTemp")}),i.jsxs("span",{className:"text-white",children:[t.nozzle_temp_min,"–",t.nozzle_temp_max,"°C"]})]}),t.filament_cost&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.cost")}),i.jsx("span",{className:"text-white",children:t.filament_cost})]}),t.filament_density&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.density")}),i.jsxs("span",{className:"text-white",children:[t.filament_density," g/cm³"]})]}),t.pressure_advance&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.pressureAdvance")}),i.jsx("span",{className:"text-white",children:t.pressure_advance})]}),t.compatible_printers&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.compatiblePrinters")}),i.jsx("span",{className:"text-white truncate ml-2",children:(()=>{try{return JSON.parse(t.compatible_printers).join(", ")}catch{return t.compatible_printers}})()})]}),t.inherits&&t.inherits!==t.name&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.inheritsFrom")}),i.jsx("span",{className:"text-white truncate ml-2",children:t.inherits})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.source")}),i.jsx("span",{className:"text-white capitalize",children:t.source})]})]})]})})}function Wet(){const{t}=Ft(),{hasPermission:e}=_r(),n=an(),{showToast:r}=fn(),[a,s]=w.useState(""),[o,l]=w.useState(null),[c,u]=w.useState(!1),[d,m]=w.useState(null),{data:p,isLoading:f}=et({queryKey:["localPresets"],queryFn:()=>be.getLocalPresets()}),y=pt({mutationFn:async k=>{const R=[];for(const P of Array.from(k)){const D=new FormData;D.append("file",P),R.push(await be.importLocalPresets(D))}return R},onSuccess:k=>{n.invalidateQueries({queryKey:["localPresets"]});let R=0,P=0,D=0;for(const H of k)R+=H.imported,P+=H.skipped,D+=H.errors.length;R>0&&r(t("profiles.localProfiles.toast.importSuccess",{count:R})),P>0&&r(t("profiles.localProfiles.toast.importSkipped",{count:P}),"warning"),D>0&&r(t("profiles.localProfiles.toast.importError",{count:D}),"error")},onError:k=>{r(k.message,"error")}}),v=pt({mutationFn:k=>be.deleteLocalPreset(k),onSuccess:()=>{n.invalidateQueries({queryKey:["localPresets"]}),m(null),r(t("profiles.localProfiles.toast.deleted"))}}),x=w.useCallback(k=>{!k||k.length===0||y.mutate(k)},[y]),g=w.useCallback(k=>{k.preventDefault(),u(!1),x(k.dataTransfer.files)},[x]),_=w.useCallback(k=>{if(!a)return k;const R=a.toLowerCase();return k.filter(P=>P.name.toLowerCase().includes(R)||P.filament_type?.toLowerCase().includes(R)||P.filament_vendor?.toLowerCase().includes(R))},[a]),N=w.useMemo(()=>_(p?.filament||[]),[p?.filament,_]),T=w.useMemo(()=>_(p?.printer||[]),[p?.printer,_]),C=w.useMemo(()=>_(p?.process||[]),[p?.process,_]),A=N.length+T.length+C.length;return f?i.jsx("div",{className:"flex items-center justify-center py-16",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):i.jsxs("div",{className:"space-y-6",children:[e("settings:update")&&i.jsxs("div",{onDragOver:k=>{k.preventDefault(),u(!0)},onDragLeave:()=>u(!1),onDrop:g,className:`relative border-2 border-dashed rounded-lg p-6 text-center transition-colors ${c?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[i.jsx("input",{type:"file",accept:".json,.zip,.orca_filament,.bbscfg,.bbsflmt",multiple:!0,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer",onChange:k=>x(k.target.files)}),y.isPending?i.jsxs("div",{className:"flex items-center justify-center gap-2",children:[i.jsx(ht,{className:"w-5 h-5 text-bambu-green animate-spin"}),i.jsx("span",{className:"text-bambu-gray",children:t("profiles.localProfiles.importing")})]}):i.jsxs(i.Fragment,{children:[i.jsx(xi,{className:"w-8 h-8 text-bambu-gray mx-auto mb-2"}),i.jsx("p",{className:"text-sm text-white font-medium",children:t("profiles.localProfiles.import")}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("profiles.localProfiles.importDesc")})]})]}),A>0&&i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:a,onChange:k=>s(k.target.value),placeholder:t("profiles.localProfiles.search"),className:"w-full pl-9 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green"})]}),A===0&&!f&&i.jsxs("div",{className:"text-center py-12",children:[i.jsx(Lx,{className:"w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50"}),i.jsx("p",{className:"text-bambu-gray",children:t("profiles.localProfiles.noPresets")}),i.jsx("p",{className:"text-xs text-bambu-gray/60 mt-1",children:t("profiles.localProfiles.importDesc")})]}),A>0&&i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[N.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(YC,{className:"w-4 h-4 text-bambu-green"}),i.jsx("h3",{className:"text-sm font-medium text-white",children:t("profiles.localProfiles.filament")}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",N.length,")"]})]}),i.jsx("div",{className:"space-y-2",children:N.map(k=>i.jsx(BD,{preset:k,onDelete:R=>m(R),onExpand:l,isExpanded:o===k.id},k.id))})]}),C.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(Gi,{className:"w-4 h-4 text-blue-400"}),i.jsx("h3",{className:"text-sm font-medium text-white",children:t("profiles.localProfiles.process")}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",C.length,")"]})]}),i.jsx("div",{className:"space-y-2",children:C.map(k=>i.jsx(BD,{preset:k,onDelete:R=>m(R),onExpand:l,isExpanded:o===k.id},k.id))})]}),T.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(jd,{className:"w-4 h-4 text-orange-400"}),i.jsx("h3",{className:"text-sm font-medium text-white",children:t("profiles.localProfiles.printer")}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",T.length,")"]})]}),i.jsx("div",{className:"space-y-2",children:T.map(k=>i.jsx(BD,{preset:k,onDelete:R=>m(R),onExpand:l,isExpanded:o===k.id},k.id))})]})]}),d!==null&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:i.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-6 max-w-sm mx-4",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(Li,{className:"w-5 h-5 text-red-400"}),i.jsx("h3",{className:"text-white font-medium",children:t("profiles.localProfiles.deleteConfirmTitle")})]}),i.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:t("profiles.localProfiles.deleteConfirm")}),i.jsxs("div",{className:"flex justify-end gap-2",children:[i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>m(null),children:t("profiles.localProfiles.cancel")}),i.jsxs(Oe,{variant:"danger",size:"sm",onClick:()=>v.mutate(d),disabled:v.isPending,children:[v.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Jt,{className:"w-4 h-4"}),t("profiles.localProfiles.delete")]})]})]})})]})}function N5(t,e){const n=`${t} ${e||""}`,r=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),a=r?r[1].trim():null,s=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=s?(s[1]||s[2])+"mm":null,l=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),c=l?l[1]+"mm":null,u=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i),d=u?u[1].toUpperCase():null;return{printer:a,nozzle:o,layerHeight:c,filamentType:d}}function ow(t){return/^(P[FPM]US|PF\d|PP\d)/.test(t)}function Ket({onSuccess:t,t:e}){const{showToast:n}=fn(),[r,a]=w.useState("email"),[s,o]=w.useState(""),[l,c]=w.useState(""),[u,d]=w.useState(""),[m,p]=w.useState(""),[f,y]=w.useState("global"),[v,x]=w.useState(null),[g,_]=w.useState(null),N=pt({mutationFn:()=>be.cloudLogin(s,l,f),onSuccess:R=>{R.success?(n(e("profiles.login.toast.loggedIn")),t()):R.needs_verification?(x(R.verification_type||"email"),_(R.tfa_key||null),R.verification_type==="totp"?n(e("profiles.login.toast.enterTotp")):n(e("profiles.login.toast.codeSent")),a("code")):n(R.message,"error")},onError:R=>n(R.message,"error")}),T=pt({mutationFn:()=>be.cloudVerify(s,u,g||void 0),onSuccess:R=>{R.success?(n(e("profiles.login.toast.loggedIn")),t()):n(R.message,"error")},onError:R=>n(R.message,"error")}),C=pt({mutationFn:()=>be.cloudSetToken(m),onSuccess:()=>{n(e("profiles.login.toast.tokenSet")),t()},onError:R=>n(R.message,"error")}),A=R=>{R.preventDefault(),r==="email"?N.mutate():r==="code"?T.mutate():r==="token"&&C.mutate()},k=N.isPending||T.isPending||C.isPending;return i.jsx(Mt,{className:"max-w-md mx-auto",children:i.jsxs(Dt,{children:[i.jsxs("div",{className:"text-center mb-6",children:[i.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3",children:i.jsx(Fx,{className:"w-6 h-6 text-bambu-green"})}),i.jsx("h2",{className:"text-xl font-semibold text-white",children:e("profiles.login.title")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:e("profiles.login.subtitle")})]}),i.jsxs("form",{onSubmit:A,className:"space-y-4",children:[r==="email"&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.email")}),i.jsx("input",{type:"email",value:s,onChange:R=>o(R.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",placeholder:"your@email.com",required:!0})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.password")}),i.jsx("input",{type:"password",value:l,onChange:R=>c(R.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",placeholder:"••••••••",required:!0})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.region")}),i.jsxs("select",{value:f,onChange:R=>y(R.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:[i.jsx("option",{value:"global",children:e("profiles.login.regionGlobal")}),i.jsx("option",{value:"china",children:e("profiles.login.regionChina")})]})]})]}),r==="code"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e(v==="totp"?"profiles.login.totpCode":"profiles.login.verificationCode")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:v==="totp"?e("profiles.login.enterTotpHint"):e("profiles.login.checkEmail",{email:s})}),i.jsx("input",{type:"text",value:u,onChange:R=>d(R.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none",placeholder:"000000",maxLength:6,required:!0})]}),r==="token"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.accessToken")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:e("profiles.login.accessTokenHint")}),i.jsx("textarea",{value:m,onChange:R=>p(R.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none resize-none",placeholder:"eyJ...",rows:4,required:!0})]}),i.jsxs("div",{className:"flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center",children:[r==="code"&&i.jsx(Oe,{type:"button",variant:"secondary",onClick:()=>a("email"),className:"flex-1",children:e("profiles.login.back")}),i.jsxs(Oe,{type:"submit",disabled:k,className:"flex-1",children:[k?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(V8,{className:"w-4 h-4"}),e(r==="email"?"profiles.login.loginButton":r==="code"?"profiles.login.verifyButton":"profiles.login.setTokenButton")]})]}),r==="email"&&i.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:i.jsxs("button",{type:"button",onClick:()=>a("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[i.jsx(Sl,{className:"w-4 h-4"}),e("profiles.login.useToken")]})}),r==="token"&&i.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:i.jsxs("button",{type:"button",onClick:()=>a("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[i.jsx(V8,{className:"w-4 h-4"}),e("profiles.login.useEmail")]})})]})]})})}function wb({label:t,value:e,options:n,onChange:r}){const[a,s]=w.useState(!1),o=n.find(l=>l.value===e);return i.jsxs("div",{className:"relative",children:[i.jsxs("button",{onClick:()=>s(!a),className:"flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors",children:[i.jsxs("span",{className:"text-bambu-gray",children:[t,":"]}),i.jsx("span",{children:o?.label||"All"}),i.jsx(Ln,{className:`w-4 h-4 text-bambu-gray transition-transform ${a?"rotate-180":""}`})]}),a&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>s(!1)}),i.jsx("div",{className:"absolute top-full left-0 mt-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 py-1 max-h-60 overflow-y-auto",children:n.map(l=>i.jsxs("button",{onClick:()=>{r(l.value),s(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${e===l.value?"text-bambu-green":"text-white"}`,children:[i.jsx("span",{children:l.label}),l.count!==void 0&&i.jsx("span",{className:"text-bambu-gray text-xs",children:l.count})]},l.value))})]})]})}function Yet(){const[t,e]=w.useState(!1);w.useEffect(()=>{const r=()=>{e(window.scrollY>300)};return window.addEventListener("scroll",r),()=>window.removeEventListener("scroll",r)},[]);const n=()=>{window.scrollTo({top:0,behavior:"smooth"})};return t?i.jsx("button",{onClick:n,className:"fixed bottom-6 right-6 p-3 bg-bambu-green hover:bg-bambu-green-light text-white rounded-full shadow-lg shadow-bambu-green/25 transition-all z-40","aria-label":"Scroll to top",children:i.jsx(yf,{className:"w-5 h-5"})}):null}function HD({setting:t,onClick:e,onDuplicate:n,compareMode:r,isCompareSelected:a,compareIndex:s,compareDisabled:o,t:l}){const c=N5(t.name),u=ow(t.setting_id);return i.jsxs("div",{className:"flex items-center gap-2 group",children:[i.jsx("button",{onClick:e,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${a?"bg-blue-500/20 border border-blue-500/50":o?"bg-bambu-dark/50 opacity-40 cursor-not-allowed":"bg-bambu-dark hover:bg-bambu-dark-tertiary"} ${r&&!o?"cursor-pointer":""}`,children:i.jsxs("div",{className:"flex items-center gap-2",children:[a&&s!==void 0&&i.jsx("span",{className:"flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium",children:s+1}),!a&&u&&i.jsx("span",{className:"flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green",title:l("profiles.presets.myPreset")}),i.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name}),c.filamentType&&t.type==="filament"&&i.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.filamentType}),c.layerHeight&&t.type==="process"&&i.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.layerHeight}),c.printer&&i.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.printer})]})}),i.jsx("button",{onClick:d=>{d.stopPropagation(),n()},className:"opacity-0 group-hover:opacity-100 text-bambu-gray hover:text-white transition-all p-1",title:l("profiles.presets.duplicate"),children:i.jsx(fo,{className:"w-4 h-4"})})]})}function xL(t,e=0){const n=" ".repeat(e);if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string"){if(t.includes("\\n")||t.includes(` + `,onClick:ie?()=>{window.innerWidth<640&&d()}:void 0,children:[ie&&u&&i.jsx("div",{className:"sm:hidden absolute left-0 top-3 bottom-3 w-1 rounded-full bg-bambu-green"}),i.jsxs("div",{className:"flex items-start sm:items-center gap-2 sm:gap-4 p-3 sm:p-4",children:[I&&d&&i.jsx("button",{onClick:X=>{X.stopPropagation(),d()},className:`hidden sm:flex items-center justify-center w-6 h-6 rounded border transition-colors shrink-0 ${u?"bg-bambu-green border-bambu-green text-white":"border-white/30 bg-black/30 hover:border-bambu-green/50"}`,children:u&&i.jsx(Yr,{className:"w-4 h-4"})}),I?i.jsx("div",{...A,...k,className:"hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-manipulation shrink-0",children:i.jsx(bh,{className:"w-4 h-4 text-bambu-gray"})}):e!==void 0?i.jsxs("div",{className:"hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark text-bambu-gray text-sm font-medium shrink-0",children:["#",e]}):i.jsx("div",{className:"hidden sm:block w-8 shrink-0"}),i.jsx("div",{className:"w-10 h-10 sm:w-14 sm:h-14 flex-shrink-0 bg-bambu-dark rounded-lg overflow-hidden",children:t.archive_thumbnail?i.jsx("img",{src:t.plate_id!=null?be.getArchivePlateThumbnail(t.archive_id,t.plate_id):be.getArchiveThumbnail(t.archive_id),alt:"",className:"w-full h-full object-cover"}):t.library_file_thumbnail?i.jsx("img",{src:t.plate_id!=null?be.getLibraryFilePlateThumbnail(t.library_file_id,t.plate_id):be.getLibraryFileThumbnailUrl(t.library_file_id),alt:"",className:"w-full h-full object-cover"}):i.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:i.jsx(Gi,{className:"w-5 h-5 sm:w-6 sm:h-6"})})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[i.jsxs("p",{className:"text-sm sm:text-base text-white font-medium truncate",children:[t.archive_name||t.library_file_name||`File #${t.archive_id||t.library_file_id}`,(N?.is_multi_plate??!1)&&t.plate_id!==void 0&&t.plate_id!==null&&` • ${T.find(X=>X.index===t.plate_id)?.name||y("queue.plateNumber",{index:t.plate_id})}`]}),t.archive_id?i.jsx(io,{to:`/archives?highlight=${t.archive_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:y("queue.viewArchive"),children:i.jsx(Jr,{className:"w-3.5 h-3.5"})}):t.library_file_id?i.jsx(io,{to:`/library?highlight=${t.library_file_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:y("queue.viewInFileManager"),children:i.jsx(Jr,{className:"w-3.5 h-3.5"})}):null]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-xs sm:text-sm text-bambu-gray",children:[i.jsxs("span",{className:`flex items-center gap-1 sm:gap-1.5 ${t.printer_id===null&&!t.target_model?"text-orange-400":""} ${t.target_model?"text-blue-400":""}`,children:[i.jsx(Sr,{className:"w-3 h-3 sm:w-3.5 sm:h-3.5"}),i.jsx("span",{className:"truncate max-w-[120px] sm:max-w-none",children:t.target_model?`${y("queue.filter.any")} ${t.target_model}${t.target_location?` @ ${t.target_location}`:""}${t.required_filament_types?.length?` (${t.required_filament_types.join(", ")})`:""}`:t.printer_id===null?y("queue.filter.unassigned"):t.printer_name||`${y("common.printer")} #${t.printer_id}`})]}),t.print_time_seconds&&i.jsxs("span",{className:"flex items-center gap-1 sm:gap-1.5",children:[i.jsx(pd,{className:"w-3 h-3 sm:w-3.5 sm:h-3.5"}),Rs(t.print_time_seconds)]}),t.filament_used_grams&&i.jsxs("span",{className:"flex items-center gap-1 sm:gap-1.5",children:[i.jsx(tQ,{className:"w-3 h-3 sm:w-3.5 sm:h-3.5"}),Foe(t.filament_used_grams)]}),t.created_by_username&&i.jsxs("span",{className:"hidden sm:flex items-center gap-1.5",title:y("queue.addedBy",{name:t.created_by_username}),children:[i.jsx(Rd,{className:"w-3.5 h-3.5"}),t.created_by_username]}),I&&!t.manual_start&&i.jsxs("span",{className:"flex items-center gap-1.5",children:[i.jsx(er,{className:"w-3.5 h-3.5"}),t.scheduled_time?(Jn(t.scheduled_time)?.getTime()??0)-Date.now()<-6e4?y?.("queue.time.overdue")??"Overdue":x0(t.scheduled_time,c,y):y?.("queue.time.asap")??"ASAP"]})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 sm:gap-2 mt-1.5 sm:mt-2",children:[t.manual_start&&i.jsxs("span",{className:"text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-purple-500/10 text-purple-400 rounded-full border border-purple-500/20 flex items-center gap-1",children:[i.jsx(GX,{className:"w-2.5 h-2.5 sm:w-3 sm:h-3"}),y("queue.badges.staged")]}),t.require_previous_success&&i.jsx("span",{className:"text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-orange-500/10 text-orange-400 rounded-full border border-orange-500/20",children:y("queue.badges.requiresPrevious")}),t.auto_off_after&&i.jsxs("span",{className:"text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-blue-500/10 text-blue-400 rounded-full border border-blue-500/20 flex items-center gap-1",children:[i.jsx(Vd,{className:"w-2.5 h-2.5 sm:w-3 sm:h-3"}),y("queue.badges.autoPowerOff")]})]}),G&&v&&i.jsxs("div",{className:"mt-2 sm:mt-3",children:[i.jsxs("div",{className:"flex items-center justify-between text-xs sm:text-sm",children:[i.jsx("div",{className:"flex-1 bg-bambu-dark-tertiary rounded-full h-1.5 sm:h-2 mr-3",children:i.jsx("div",{className:"bg-bambu-green h-1.5 sm:h-2 rounded-full transition-all",style:{width:`${v.progress||0}%`}})}),i.jsxs("span",{className:"text-white",children:[Math.round(v.progress||0),"%"]})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-3 mt-1.5 sm:mt-2 text-[10px] sm:text-xs text-bambu-gray",children:[v.remaining_time!=null&&v.remaining_time>0&&i.jsxs(i.Fragment,{children:[i.jsxs("span",{className:"flex items-center gap-1",children:[i.jsx(er,{className:"w-3 h-3"}),Rs(v.remaining_time*60)]}),i.jsxs("span",{className:"text-bambu-green font-medium",title:y("printers.estimatedCompletion"),children:["ETA ",KL(v.remaining_time,c,y)]})]}),v.layer_num!=null&&v.total_layers!=null&&v.total_layers>0&&i.jsxs("span",{className:"flex items-center gap-1",children:[i.jsx(Gi,{className:"w-3 h-3"}),v.layer_num,"/",v.total_layers]})]})]}),t.waiting_reason&&t.status==="pending"&&i.jsxs("p",{className:"text-[10px] sm:text-xs text-purple-400 mt-1.5 sm:mt-2 flex items-start gap-1",children:[i.jsx(Li,{className:"w-3 h-3 mt-0.5 flex-shrink-0"}),i.jsx("span",{children:t.waiting_reason})]}),t.error_message&&i.jsxs("p",{className:"text-[10px] sm:text-xs text-red-400 mt-1.5 sm:mt-2 flex items-center gap-1",children:[i.jsx(Li,{className:"w-3 h-3"}),t.error_message]})]}),i.jsxs("div",{className:"flex flex-col sm:flex-row items-end sm:items-center gap-2 sm:gap-1 shrink-0",onClick:X=>X.stopPropagation(),children:[i.jsx(HJe,{status:t.status,waitingReason:t.waiting_reason,printerState:f,t:y}),i.jsxs("div",{className:"flex items-center gap-0.5 sm:gap-1",children:[G&&i.jsx(Oe,{variant:"ghost",size:"sm",onClick:s,disabled:!m("printers:control"),title:m("printers:control")?y("queue.actions.stopPrint"):y("queue.permissions.noStopPrint"),className:"text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2",children:i.jsx(Jhe,{className:"w-4 h-4"})}),I&&i.jsxs(i.Fragment,{children:[t.manual_start&&i.jsx(Oe,{variant:"ghost",size:"sm",onClick:l,disabled:!m("printers:control"),title:m("printers:control")?y("queue.actions.startPrint"):y("queue.permissions.noStartPrint"),className:"text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10 p-1.5 sm:p-2",children:i.jsx(go,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:n,disabled:!p("queue","update",t.created_by_id),title:p("queue","update",t.created_by_id)?y("common.edit"):y("queue.permissions.noEdit"),className:"p-1.5 sm:p-2",children:i.jsx(Yi,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:r,disabled:!p("queue","delete",t.created_by_id),title:p("queue","delete",t.created_by_id)?y("common.cancel"):y("queue.permissions.noCancel"),className:"text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2",children:i.jsx(Ht,{className:"w-4 h-4"})})]}),ee&&i.jsxs(i.Fragment,{children:[i.jsx(Oe,{variant:"ghost",size:"sm",onClick:o,disabled:!m("queue:create"),title:m("queue:create")?y("queue.actions.requeue"):y("queue.permissions.noRequeue"),className:"text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5 sm:p-2",children:i.jsx(wr,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:a,disabled:!p("queue","delete",t.created_by_id),title:p("queue","delete",t.created_by_id)?y("common.remove"):y("queue.permissions.noRemove"),className:"p-1.5 sm:p-2",children:i.jsx(Jt,{className:"w-4 h-4"})})]})]})]})]})]})}function qJe(){const{t}=Ft(),e=an(),{showToast:n}=fn(),{hasPermission:r,hasAnyPermission:a,canModify:s}=_r(),[o,l]=w.useState(null),[c,u]=w.useState(""),[d,m]=w.useState(""),[p,f]=w.useState(!1),[y,v]=w.useState(null),[x,g]=w.useState(null),[_,N]=w.useState(null),[T,C]=w.useState([]),[A,k]=w.useState(!1),[R,P]=w.useState(()=>localStorage.getItem("queue.historySortBy")||"date"),[D,H]=w.useState(()=>{const L=localStorage.getItem("queue.historySortAsc");return L!==null?L==="true":!1}),[z,G]=w.useState(()=>localStorage.getItem("queue.pendingSortBy")||"position"),[I,ee]=w.useState(()=>{const L=localStorage.getItem("queue.pendingSortAsc");return L!==null?L==="true":!0});w.useEffect(()=>{localStorage.setItem("queue.historySortBy",R)},[R]),w.useEffect(()=>{localStorage.setItem("queue.historySortAsc",String(D))},[D]),w.useEffect(()=>{localStorage.setItem("queue.pendingSortBy",z)},[z]),w.useEffect(()=>{localStorage.setItem("queue.pendingSortAsc",String(I))},[I]);const ie=uoe(HC(MA,{activationConstraint:{distance:8}}),HC(PA,{coordinateGetter:Doe})),{data:X}=et({queryKey:["settings"],queryFn:be.getSettings}),me=X?.time_format||"system",{data:he,isLoading:ge}=et({queryKey:["queue",o,c],queryFn:()=>be.getQueue(o||void 0,c||void 0),refetchInterval:5e3}),{data:Y}=et({queryKey:["printers"],queryFn:()=>be.getPrinters()}),oe=pt({mutationFn:L=>be.cancelQueueItem(L),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.cancelled"))},onError:()=>n(t("queue.toast.cancelFailed"),"error")}),le=pt({mutationFn:L=>be.removeFromQueue(L),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.removed"))},onError:()=>n(t("queue.toast.removeFailed"),"error")}),xe=pt({mutationFn:L=>be.stopQueueItem(L),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.stopped"))},onError:()=>n(t("queue.toast.stopFailed"),"error")}),Pe=pt({mutationFn:L=>be.startQueueItem(L),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.released"))},onError:()=>n(t("queue.toast.startFailed"),"error")}),q=pt({mutationFn:L=>be.reorderQueue(L),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]})},onError:()=>n(t("queue.toast.reorderFailed"),"error")}),Z=pt({mutationFn:async()=>{const L=he?.filter(F=>["completed","failed","skipped","cancelled"].includes(F.status))||[];for(const F of L)await be.removeFromQueue(F.id);return L.length},onSuccess:L=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.historyCleared",{count:L}))},onError:()=>n(t("queue.toast.clearHistoryFailed"),"error")}),j=pt({mutationFn:L=>be.bulkUpdateQueue(L),onSuccess:L=>{e.invalidateQueries({queryKey:["queue"]}),C([]),k(!1),n(L.message)},onError:()=>n(t("queue.toast.updateFailed"),"error")}),E=pt({mutationFn:async L=>{for(const F of L)await be.cancelQueueItem(F);return L.length},onSuccess:L=>{e.invalidateQueries({queryKey:["queue"]}),C([]),n(t("queue.toast.bulkCancelled",{count:L}))},onError:()=>n(t("queue.toast.bulkCancelFailed"),"error")}),U=L=>{C(F=>F.includes(L)?F.filter(te=>te!==L):[...F,L])},K=w.useMemo(()=>{const L=new Set;return Y?.forEach(F=>{F.location&&L.add(F.location)}),he?.forEach(F=>{F.target_location&&L.add(F.target_location)}),Array.from(L).sort()},[Y,he]),$=w.useCallback(L=>d?L.target_location?L.target_location===d:L.printer_id?Y?.find(te=>te.id===L.printer_id)?.location===d:!1:!0,[d,Y]),ne=w.useMemo(()=>{let L=he?.filter(te=>te.status==="pending")||[];d&&(L=L.filter($));const F=te=>{if(!te.scheduled_time)return 0;const ve=Jn(te.scheduled_time)?.getTime()??0,pe=Date.now()+4320*60*60*1e3;return ve>pe?0:ve};return[...L].sort((te,ve)=>{let pe;if(z==="name"){const de=te.archive_name||te.library_file_name||"",Ne=ve.archive_name||ve.library_file_name||"";pe=de.localeCompare(Ne)}else z==="printer"?pe=(te.printer_name||"").localeCompare(ve.printer_name||""):z==="time"?pe=F(te)-F(ve):pe=te.position-ve.position;return I?pe:-pe})},[he,z,I,$,d]),O=()=>{const L=ne.map(F=>F.id);T.length===L.length?C([]):C(L)},V=w.useMemo(()=>{let L=he?.filter(F=>F.status==="printing")||[];return d&&(L=L.filter($)),L},[he,d,$]),J=w.useMemo(()=>{const L=new Set;return V.forEach(F=>{F.printer_id&&L.add(F.printer_id)}),Array.from(L)},[V]),W=Gf({queries:J.map(L=>({queryKey:["printerStatus",L],queryFn:()=>be.getPrinterStatus(L),refetchInterval:5e3}))}),re=w.useMemo(()=>{const L={};return J.forEach((F,te)=>{const ve=W[te];ve?.data?.state&&(L[F]=ve.data.state)}),L},[J,W]),ue=w.useMemo(()=>{let L=he?.filter(F=>["completed","failed","skipped","cancelled"].includes(F.status))||[];return d&&(L=L.filter($)),[...L].sort((F,te)=>{let ve;if(R==="name"){const pe=F.archive_name||F.library_file_name||"",de=te.archive_name||te.library_file_name||"";ve=pe.localeCompare(de)}else R==="printer"?ve=(F.printer_name||"").localeCompare(te.printer_name||""):ve=(Jn(te.completed_at||te.created_at)?.getTime()??0)-(Jn(F.completed_at||F.created_at)?.getTime()??0);return D?-ve:ve})},[he,R,D,$,d]),fe=w.useMemo(()=>ne.reduce((L,F)=>L+(F.print_time_seconds||0),0),[ne]),ye=w.useMemo(()=>ne.reduce((L,F)=>L+(F.filament_used_grams||0),0),[ne]),ae=L=>{const{active:F,over:te}=L;if(!te||F.id===te.id)return;const ve=ne.findIndex(de=>de.id===F.id),pe=ne.findIndex(de=>de.id===te.id);if(ve!==-1&&pe!==-1){const Ne=DA(ne,ve,pe).map((Se,Le)=>({id:Se.id,position:Le+1}));q.mutate(Ne)}};return i.jsxs("div",{className:"p-4 md:p-8",children:[i.jsx("div",{className:"flex items-center justify-between mb-8",children:i.jsxs("div",{children:[i.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[i.jsx(WX,{className:"w-7 h-7 text-bambu-green"}),t("queue.title")]}),i.jsx("p",{className:"text-bambu-gray mt-1",children:t("queue.subtitle")})]})}),i.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-2 sm:gap-3 lg:gap-4 mb-8",children:[i.jsx(Mt,{className:"bg-gradient-to-br from-blue-500/10 to-transparent border-blue-500/20",children:i.jsx(Dt,{className:"p-3 sm:p-4",children:i.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[i.jsx("div",{className:"w-8 h-8 sm:w-10 sm:h-10 rounded-lg bg-blue-500/20 flex items-center justify-center shrink-0",children:i.jsx(go,{className:"w-4 h-4 sm:w-5 sm:h-5 text-blue-400"})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-xl sm:text-2xl font-bold text-white truncate",children:V.length}),i.jsx("p",{className:"text-xs sm:text-sm text-bambu-gray truncate",children:t("queue.summary.printing")})]})]})})}),i.jsx(Mt,{className:"bg-gradient-to-br from-yellow-500/10 to-transparent border-yellow-500/20",children:i.jsx(Dt,{className:"p-3 sm:p-4",children:i.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[i.jsx("div",{className:"w-8 h-8 sm:w-10 sm:h-10 rounded-lg bg-yellow-500/20 flex items-center justify-center shrink-0",children:i.jsx(er,{className:"w-4 h-4 sm:w-5 sm:h-5 text-yellow-400"})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-xl sm:text-2xl font-bold text-white truncate",children:ne.length}),i.jsx("p",{className:"text-xs sm:text-sm text-bambu-gray truncate",children:t("queue.summary.queued")})]})]})})}),i.jsx(Mt,{className:"bg-gradient-to-br from-bambu-green/10 to-transparent border-bambu-green/20",children:i.jsx(Dt,{className:"p-3 sm:p-4",children:i.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[i.jsx("div",{className:"w-8 h-8 sm:w-10 sm:h-10 rounded-lg bg-bambu-green/20 flex items-center justify-center shrink-0",children:i.jsx(pd,{className:"w-4 h-4 sm:w-5 sm:h-5 text-bambu-green"})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-xl sm:text-2xl font-bold text-white truncate",children:Rs(fe)}),i.jsx("p",{className:"text-xs sm:text-sm text-bambu-gray truncate",children:t("queue.summary.totalTime")})]})]})})}),i.jsx(Mt,{className:"bg-gradient-to-br from-purple-500/10 to-transparent border-purple-500/20",children:i.jsx(Dt,{className:"p-3 sm:p-4",children:i.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[i.jsx("div",{className:"w-8 h-8 sm:w-10 sm:h-10 rounded-lg bg-purple-500/20 flex items-center justify-center shrink-0",children:i.jsx(tQ,{className:"w-4 h-4 sm:w-5 sm:h-5 text-purple-500"})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-xl sm:text-2xl font-bold text-white truncate",children:Foe(ye)}),i.jsx("p",{className:"text-xs sm:text-sm text-bambu-gray truncate",children:t("queue.summary.totalWeight")})]})]})})}),i.jsx(Mt,{className:"col-span-2 sm:col-span-1 bg-gradient-to-br from-gray-500/10 to-transparent border-gray-500/20",children:i.jsx(Dt,{className:"p-3 sm:p-4",children:i.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[i.jsx("div",{className:"w-8 h-8 sm:w-10 sm:h-10 rounded-lg bg-gray-500/20 flex items-center justify-center shrink-0",children:i.jsx(fr,{className:"w-4 h-4 sm:w-5 sm:h-5 text-gray-400"})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-xl sm:text-2xl font-bold text-white truncate",children:ue.length}),i.jsx("p",{className:"text-xs sm:text-sm text-bambu-gray truncate",children:t("queue.summary.history")})]})]})})})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-4 mb-6",children:[i.jsxs("select",{className:"px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none",value:o===-1?"unassigned":o||"",onChange:L=>{const F=L.target.value;l(F==="unassigned"?-1:F===""?null:Number(F))},children:[i.jsx("option",{value:"",children:t("queue.filter.allPrinters")}),i.jsx("option",{value:"unassigned",children:t("queue.filter.unassigned")}),Y?.map(L=>i.jsx("option",{value:L.id,children:L.name},L.id))]}),i.jsxs("select",{className:"px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none",value:c,onChange:L=>u(L.target.value),children:[i.jsx("option",{value:"",children:t("queue.filter.allStatus")}),i.jsx("option",{value:"pending",children:t("queue.status.pending")}),i.jsx("option",{value:"printing",children:t("queue.status.printing")}),i.jsx("option",{value:"completed",children:t("queue.status.completed")}),i.jsx("option",{value:"failed",children:t("queue.status.failed")}),i.jsx("option",{value:"skipped",children:t("queue.status.skipped")}),i.jsx("option",{value:"cancelled",children:t("queue.status.cancelled")})]}),K.length>0&&i.jsxs("select",{className:"px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none",value:d,onChange:L=>m(L.target.value),children:[i.jsx("option",{value:"",children:t("queue.filter.allLocations")}),K.map(L=>i.jsx("option",{value:L,children:L},L))]}),i.jsx("div",{className:"hidden sm:block flex-1"}),ue.length>0&&i.jsxs(Oe,{className:"w-full sm:w-auto",variant:"secondary",size:"sm",onClick:()=>f(!0),disabled:!r("queue:delete_all"),title:r("queue:delete_all")?void 0:t("queue.permissions.noClearHistory"),children:[i.jsx(Jt,{className:"w-4 h-4"}),t("queue.clearHistory")]})]}),ge?i.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("common.loading")}):he?.length===0?i.jsxs(Mt,{className:"p-12 text-center border-dashed",children:[i.jsx(Wr,{className:"w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50"}),i.jsx("h3",{className:"text-xl font-medium text-white mb-2",children:t("queue.empty.title")}),i.jsx("p",{className:"text-bambu-gray max-w-md mx-auto",children:t("queue.empty.description")})]}):i.jsxs("div",{className:"space-y-6 sm:space-y-8",children:[V.length>0&&i.jsxs("div",{children:[i.jsxs("h2",{className:"text-base sm:text-lg font-semibold text-white mb-3 sm:mb-4 flex items-center gap-2",children:[i.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-400 animate-pulse"}),t("queue.sections.currentlyPrinting")]}),i.jsx("div",{className:"space-y-2 sm:space-y-3",children:V.map(L=>i.jsx(LD,{item:L,onEdit:()=>{},onCancel:()=>{},onRemove:()=>{},onStop:()=>N({type:"stop",item:L}),onRequeue:()=>{},onStart:()=>{},timeFormat:me,hasPermission:r,canModify:s,printerState:L.printer_id?re[L.printer_id]:null,t},L.id))})]}),ne.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4",children:[i.jsxs("h2",{className:"text-base sm:text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(er,{className:"w-4 h-4 sm:w-5 sm:h-5 text-yellow-400"}),t("queue.sections.queued"),i.jsxs("span",{className:"text-xs sm:text-sm font-normal text-bambu-gray",children:["(",t("queue.itemCount",{count:ne.length}),")"]}),i.jsx("span",{className:"hidden sm:inline text-xs text-bambu-gray ml-2",title:t("queue.reorderHint"),children:t("queue.dragToReorder")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("select",{className:"px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:z,onChange:L=>G(L.target.value),children:[i.jsx("option",{value:"position",children:t("queue.sort.byPosition")}),i.jsx("option",{value:"name",children:t("queue.sort.byName")}),i.jsx("option",{value:"printer",children:t("queue.sort.byPrinter")}),i.jsx("option",{value:"time",children:t("queue.sort.bySchedule")})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>ee(!I),title:t(I?"common.ascending":"common.descending"),className:"px-2",children:I?i.jsx(yf,{className:"w-4 h-4"}):i.jsx(tx,{className:"w-4 h-4"})})]})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-3 mb-3 sm:mb-4 p-2 sm:p-3 bg-bambu-dark rounded-lg",children:[i.jsxs(Oe,{variant:"ghost",size:"sm",onClick:O,className:"flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm",children:[T.length===ne.length&&ne.length>0?i.jsx(xo,{className:"w-4 h-4 text-bambu-green"}):i.jsx(zl,{className:"w-4 h-4"}),T.length===ne.length&&ne.length>0?t("queue.bulkEdit.deselectAll"):t("queue.bulkEdit.selectAll")]}),T.length>0&&i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"text-xs sm:text-sm text-bambu-gray",children:t("queue.bulkEdit.selected",{count:T.length})}),i.jsx("div",{className:"hidden sm:block h-4 w-px bg-bambu-dark-tertiary"}),i.jsxs(Oe,{variant:"ghost",size:"sm",onClick:()=>k(!0),className:"flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-bambu-green hover:text-bambu-green-light",disabled:!a("queue:update_own","queue:update_all"),title:a("queue:update_own","queue:update_all")?t("queue.bulkEdit.editSelected"):t("queue.permissions.noEditItems"),children:[i.jsx(Yi,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("queue.bulkEdit.editSelected")})]}),i.jsxs(Oe,{variant:"ghost",size:"sm",onClick:()=>E.mutate(T),className:"flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-red-400 hover:text-red-300",disabled:E.isPending||!a("queue:delete_own","queue:delete_all"),title:a("queue:delete_own","queue:delete_all")?t("queue.bulkEdit.cancelSelected"):t("queue.permissions.noCancelItems"),children:[i.jsx(Ht,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("queue.bulkEdit.cancelSelected")})]})]})]}),i.jsx(Toe,{sensors:ie,collisionDetection:poe,onDragEnd:ae,children:i.jsx(Moe,{items:ne.map(L=>L.id),strategy:EJe,children:i.jsx("div",{className:"space-y-2 sm:space-y-3",children:ne.map((L,F)=>i.jsx(LD,{item:L,position:F+1,onEdit:()=>v(L),onCancel:()=>N({type:"cancel",item:L}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>Pe.mutate(L.id),timeFormat:me,isSelected:T.includes(L.id),onToggleSelect:()=>U(L.id),hasPermission:r,canModify:s,t},L.id))})})})]}),ue.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4",children:[i.jsxs("h2",{className:"text-base sm:text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(fr,{className:"w-4 h-4 sm:w-5 sm:h-5 text-bambu-gray"}),t("queue.sections.history"),i.jsxs("span",{className:"text-xs sm:text-sm font-normal text-bambu-gray",children:["(",t("queue.itemCount",{count:ue.length}),")"]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("select",{className:"px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:R,onChange:L=>P(L.target.value),children:[i.jsx("option",{value:"date",children:t("queue.sort.byDate")}),i.jsx("option",{value:"name",children:t("queue.sort.byName")}),i.jsx("option",{value:"printer",children:t("queue.sort.byPrinter")})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>H(!D),title:t(D?"queue.sort.ascendingOldest":"queue.sort.descendingNewest"),className:"px-2",children:D?i.jsx(yf,{className:"w-4 h-4"}):i.jsx(tx,{className:"w-4 h-4"})})]})]}),i.jsx("div",{className:"space-y-2 sm:space-y-3",children:ue.slice(0,20).map((L,F)=>i.jsx(LD,{item:L,position:F+1,onEdit:()=>{},onCancel:()=>{},onRemove:()=>N({type:"remove",item:L}),onStop:()=>{},onRequeue:()=>g(L),onStart:()=>{},timeFormat:me,hasPermission:r,canModify:s,t},L.id))})]})]}),y&&i.jsx(uu,{mode:"edit-queue-item",archiveId:y.archive_id??void 0,libraryFileId:y.library_file_id??void 0,archiveName:y.archive_name||y.library_file_name||`File #${y.archive_id||y.library_file_id}`,queueItem:y,onClose:()=>v(null)}),x&&i.jsx(uu,{mode:"add-to-queue",archiveId:x.archive_id??void 0,libraryFileId:x.library_file_id??void 0,archiveName:x.archive_name||x.library_file_name||`File #${x.archive_id||x.library_file_id}`,onClose:()=>g(null)}),_&&i.jsx(Sn,{title:_.type==="cancel"?t("queue.confirm.cancelTitle"):_.type==="stop"?t("queue.confirm.stopTitle"):t("queue.confirm.removeTitle"),message:_.type==="cancel"?t("queue.confirm.cancelMessage",{name:_.item.archive_name||_.item.library_file_name||t("queue.confirm.thisPrint")}):_.type==="stop"?t("queue.confirm.stopMessage",{name:_.item.archive_name||_.item.library_file_name||t("queue.confirm.thisPrint")}):t("queue.confirm.removeMessage",{name:_.item.archive_name||_.item.library_file_name||t("queue.confirm.thisItem")}),confirmText:_.type==="cancel"?t("queue.confirm.cancelButton"):_.type==="stop"?t("queue.confirm.stopButton"):t("common.remove"),variant:"danger",onConfirm:()=>{_.type==="cancel"?oe.mutate(_.item.id):_.type==="stop"?xe.mutate(_.item.id):le.mutate(_.item.id),N(null)},onCancel:()=>N(null)}),p&&i.jsx(Sn,{title:t("queue.confirm.clearHistoryTitle"),message:t("queue.confirm.clearHistoryMessage",{count:ue.length}),confirmText:t("queue.clearHistory"),variant:"danger",onConfirm:()=>{Z.mutate(),f(!1)},onCancel:()=>f(!1)}),A&&i.jsx($Je,{selectedCount:T.length,printers:Y?.map(L=>({id:L.id,name:L.name}))||[],onSave:L=>{Object.keys(L).length>0&&j.mutate({item_ids:T,...L})},onClose:()=>k(!1),isSaving:j.isPending,canControlPrinter:r("printers:control"),t})]})}function VJe({printDates:t,months:e=3}){const n=w.useRef(null),[r,a]=w.useState(0);w.useEffect(()=>{const _=n.current;if(!_)return;const N=new ResizeObserver(T=>{const C=T[0]?.contentRect.width||0;a(C)});return N.observe(_),()=>N.disconnect()},[]);const{weeks:s,monthLabels:o,printCounts:l}=w.useMemo(()=>{const _={};t.forEach(H=>{const z=H.split("T")[0];_[z]=(_[z]||0)+1});const N=new Date,T=new Date(N);T.setMonth(T.getMonth()-e),T.setDate(T.getDate()-T.getDay());const C=[],A=[];let k=[],R=-1;const P=new Date(T);let D=0;for(;P<=N;)P.getDay()===0&&k.length>0&&(C.push(k),k=[],D++),P.getMonth()!==R&&(A.push({month:P.toLocaleDateString("en-US",{month:"short"}),weekIndex:D}),R=P.getMonth()),k.push(new Date(P)),P.setDate(P.getDate()+1);return k.length>0&&C.push(k),{weeks:C,monthLabels:A,printCounts:_}},[t,e]),c=Math.max(1,...Object.values(l)),u=_=>{if(_===0)return"bg-bambu-dark";const N=_/c;return N<=.25?"bg-bambu-green/30":N<=.5?"bg-bambu-green/50":N<=.75?"bg-bambu-green/75":"bg-bambu-green"},d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],m=s.length,p=32,f=2,y=r-p-16,v=m>0?Math.floor((y-(m-1)*f)/m):12,x=Math.max(8,Math.min(20,v)),g=x<=10?10:12;return i.jsx("div",{ref:n,className:"w-full flex justify-center",children:r>0&&i.jsxs("div",{children:[i.jsx("div",{className:"flex mb-1",style:{marginLeft:p+4},children:o.map(({month:_,weekIndex:N},T)=>i.jsx("div",{className:"text-bambu-gray",style:{fontSize:g,marginLeft:T===0?0:`${(N-(o[T-1]?.weekIndex||0))*(x+f)-24}px`},children:_},T))}),i.jsxs("div",{className:"flex",style:{gap:f},children:[i.jsx("div",{className:"flex flex-col",style:{gap:f,marginRight:4,width:p},children:d.map((_,N)=>i.jsx("div",{className:"text-bambu-gray flex items-center",style:{width:p,height:x,fontSize:g,visibility:N%2===1?"visible":"hidden"},children:_},_))}),s.map((_,N)=>i.jsx("div",{className:"flex flex-col",style:{gap:f},children:[0,1,2,3,4,5,6].map(T=>{const C=_.find(P=>P.getDay()===T);if(!C)return i.jsx("div",{style:{width:x,height:x}},T);const A=C.toISOString().split("T")[0],k=l[A]||0,R=A===new Date().toISOString().split("T")[0];return i.jsx("div",{className:`rounded-sm ${u(k)} ${R?"ring-1 ring-white":""}`,style:{width:x,height:x},title:`${C.toLocaleDateString()}: ${k} print${k!==1?"s":""}`},T)})},N))]}),i.jsxs("div",{className:"flex items-center gap-2 mt-3 text-bambu-gray",style:{fontSize:g},children:[i.jsx("span",{children:"Less"}),i.jsxs("div",{className:"flex",style:{gap:f},children:[i.jsx("div",{className:"rounded-sm bg-bambu-dark",style:{width:x,height:x}}),i.jsx("div",{className:"rounded-sm bg-bambu-green/30",style:{width:x,height:x}}),i.jsx("div",{className:"rounded-sm bg-bambu-green/50",style:{width:x,height:x}}),i.jsx("div",{className:"rounded-sm bg-bambu-green/75",style:{width:x,height:x}}),i.jsx("div",{className:"rounded-sm bg-bambu-green",style:{width:x,height:x}})]}),i.jsx("span",{children:"More"})]})]})})}const _Y=["weight","prints","time"];function VC({value:t,onChange:e,exclude:n}){const{t:r}=Ft(),a={weight:r("stats.filamentByWeight"),prints:r("stats.filamentByPrints"),time:r("stats.filamentByTime")},s=n?_Y.filter(o=>!n.includes(o)):_Y;return i.jsx("div",{className:"flex gap-0.5 bg-bambu-dark rounded-lg p-0.5",children:s.map(o=>i.jsx("button",{onClick:()=>e(o),className:`px-2 py-0.5 text-xs rounded-md transition-colors ${t===o?"bg-bambu-green text-white":"text-bambu-gray hover:text-white"}`,children:a[o]},o))})}function th(t){if(t>=1e6){const e=t/1e6;return`${e%1===0?e.toFixed(0):e.toFixed(1)}t`}if(t>=1e3){const e=t/1e3;return`${e%1===0?e.toFixed(0):e.toFixed(1)}kg`}return`${Math.round(t)}g`}const $1=["#00ae42","#3b82f6","#f59e0b","#ef4444","#8b5cf6","#ec4899","#14b8a6","#f97316"],GJe=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],NY=["12am","1am","2am","3am","4am","5am","6am","7am","8am","9am","10am","11am","12pm","1pm","2pm","3pm","4pm","5pm","6pm","7pm","8pm","9pm","10pm","11pm"];function WJe({archives:t,currency:e="$",dateFrom:n,dateTo:r}){const{t:a}=Ft(),[s,o]=w.useState("weight"),[l,c]=w.useState("weight"),u=w.useMemo(()=>{const R=new Map;return t.forEach(P=>{const D=Jn(P.completed_at||P.created_at)||new Date,H=`${D.getFullYear()}-${String(D.getMonth()+1).padStart(2,"0")}-${String(D.getDate()).padStart(2,"0")}`,z=R.get(H)||{date:H,filament:0,cost:0,prints:0};z.filament+=P.filament_used_grams||0,z.cost+=P.cost||0,z.prints+=P.quantity||1,R.set(H,z)}),Array.from(R.values()).sort((P,D)=>P.date.localeCompare(D.date)).map(P=>({...P,dateLabel:new Date(P.date).toLocaleDateString("en-US",{month:"short",day:"numeric"})}))},[t]),d=w.useMemo(()=>{if(n&&r)return Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1;if(n)return Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1;if(t.length<2)return 0;const R=t.map(P=>new Date(P.completed_at||P.created_at).getTime());return(Math.max(...R)-Math.min(...R))/864e5},[t,n,r]),m=w.useMemo(()=>{if(d>7)return[];const R=new Map,P=d>1;return t.forEach(D=>{const H=Jn(D.completed_at||D.created_at)||new Date,z=H.getHours(),G=`${H.getFullYear()}-${String(H.getMonth()+1).padStart(2,"0")}-${String(H.getDate()).padStart(2,"0")}T${String(z).padStart(2,"0")}`,I=R.get(G)||{date:G,filament:0,cost:0,prints:0};I.filament+=D.filament_used_grams||0,I.cost+=D.cost||0,I.prints+=D.quantity||1,R.set(G,I)}),Array.from(R.values()).sort((D,H)=>D.date.localeCompare(H.date)).map(D=>{const[H,z]=D.date.split("T"),G=new Date(H),I=parseInt(z,10),ee=P?`${GJe[G.getDay()]} ${NY[I]}`:NY[I];return{...D,dateLabel:ee}})},[t,d]),p=w.useMemo(()=>{if(u.length<=60)return u;const R=new Map;return u.forEach(P=>{const D=new Date(P.date),H=new Date(D);H.setDate(D.getDate()-D.getDay());const z=`${H.getFullYear()}-${String(H.getMonth()+1).padStart(2,"0")}-${String(H.getDate()).padStart(2,"0")}`,G=R.get(z)||{week:z,filament:0,cost:0,prints:0};G.filament+=P.filament,G.cost+=P.cost,G.prints+=P.prints,R.set(z,G)}),Array.from(R.values()).sort((P,D)=>P.week.localeCompare(D.week)).map(P=>({date:P.week,dateLabel:`Week of ${new Date(P.week).toLocaleDateString("en-US",{month:"short",day:"numeric"})}`,...P}))},[u]),f=w.useMemo(()=>{const R=new Map;return t.forEach(P=>{const H=(P.filament_type||"Unknown").split(", ");H.forEach(z=>{const G=(P.filament_used_grams||0)/H.length;R.set(z,(R.get(z)||0)+G)})}),Array.from(R.entries()).map(([P,D])=>({name:P,value:Math.round(D)})).sort((P,D)=>D.value-P.value)},[t]),y=w.useMemo(()=>{const R=new Map;return t.forEach(P=>{(P.filament_type||"Unknown").split(", ").forEach(z=>{R.set(z,(R.get(z)||0)+1)})}),Array.from(R.entries()).map(([P,D])=>({name:P,value:D})).sort((P,D)=>D.value-P.value)},[t]),v=w.useMemo(()=>{const R=new Map;return t.forEach(P=>{const H=(P.filament_type||"Unknown").split(", "),z=(P.actual_time_seconds||P.print_time_seconds||0)/H.length;H.forEach(G=>{R.set(G,(R.get(G)||0)+z)})}),Array.from(R.entries()).map(([P,D])=>({name:P,value:Math.round(D/3600*10)/10})).sort((P,D)=>D.value-P.value)},[t]),x=w.useMemo(()=>{const R=new Map;return t.forEach(P=>{if(P.status!=="completed"&&P.status!=="failed")return;(P.filament_type||"Unknown").split(", ").forEach(H=>{const z=R.get(H)||{completed:0,failed:0};P.status==="completed"?z.completed++:z.failed++,R.set(H,z)})}),Array.from(R.entries()).filter(([,P])=>P.completed+P.failed>=2).map(([P,D])=>{const H=D.completed+D.failed,z=Math.round(D.completed/H*100);return{name:P,rate:z,total:H}}).sort((P,D)=>D.rate-P.rate)},[t]),g=w.useMemo(()=>{const R=new Map;return t.forEach(P=>{if(!P.filament_color)return;const D=P.filament_color.split(",").map(z=>z.trim()),H=(P.filament_used_grams||0)/D.length;D.forEach(z=>{const G=R.get(z)||{count:0,weight:0};G.count++,G.weight+=H,R.set(z,G)})}),Array.from(R.entries()).map(([P,D])=>({hex:P,value:l==="prints"?D.count:Math.round(D.weight)})).sort((P,D)=>D.value-P.value)},[t,l]),_=s==="weight"?f:s==="prints"?y:v,N=d<=7&&m.length>0?m:p,T=t.reduce((R,P)=>R+(P.filament_used_grams||0),0),C=t.reduce((R,P)=>R+(P.cost||0),0),A=t.reduce((R,P)=>R+(P.quantity||1),0),k=new Set(t.map(R=>R.printer_id).filter(Boolean)).size;return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"grid grid-cols-3 gap-2 max-[640px]:grid-cols-1",children:[i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx("p",{className:"text-sm text-bambu-gray leading-none",children:a("stats.periodFilament")}),i.jsx("p",{className:"text-2xl font-bold text-white leading-none",children:th(T)})]}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[k," ",a("nav.printers").toLowerCase()]})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx("p",{className:"text-sm text-bambu-gray leading-none",children:a("stats.periodCost")}),i.jsxs("p",{className:"text-2xl font-bold text-white leading-none",children:[e,C.toFixed(2)]})]}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[A," ",a("common.prints")]})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx("p",{className:"text-sm text-bambu-gray leading-none",children:a("stats.avgPerPrint")}),i.jsxs("p",{className:"text-2xl font-bold text-white leading-none",children:[A>0?(T/A).toFixed(0):0,"g"]})]}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[e,A>0?(C/A).toFixed(2):"0.00"," avg"]})]})]}),N.length>0?i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:a("stats.usageOverTime")}),i.jsx(oh,{width:"100%",height:250,children:i.jsxs(Cqe,{data:N,children:[i.jsx("defs",{children:i.jsxs("linearGradient",{id:"colorFilament",x1:"0",y1:"0",x2:"0",y2:"1",children:[i.jsx("stop",{offset:"5%",stopColor:"#00ae42",stopOpacity:.3}),i.jsx("stop",{offset:"95%",stopColor:"#00ae42",stopOpacity:0})]})}),i.jsx(Kp,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),i.jsx(Yp,{dataKey:"dateLabel",stroke:"#9ca3af",tick:{fontSize:12},interval:"preserveStartEnd"}),i.jsx(Xp,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:R=>`${R}g`}),i.jsx(lh,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},labelStyle:{color:"#fff"},formatter:R=>[`${Number(R??0).toFixed(0)}g`,"Filament"]}),i.jsx(Are,{type:"monotone",dataKey:"filament",stroke:"#00ae42",strokeWidth:2,fillOpacity:1,fill:"url(#colorFilament)"})]})})]}):i.jsx("div",{className:"bg-bambu-dark rounded-lg p-8 text-center text-bambu-gray",children:a("stats.noPrintDataInRange")}),i.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray",children:a("stats.byMaterial")}),i.jsx(VC,{value:s,onChange:o})]}),_.length>0?i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx(oh,{width:160,height:160,children:i.jsxs(aW,{children:[i.jsx(vF,{data:_,cx:"50%",cy:"50%",innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:"value",children:_.map((R,P)=>i.jsx(Sx,{fill:$1[P%$1.length]},`cell-${P}`))}),i.jsx(lh,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:R=>[s==="weight"?th(Number(R??0)):s==="time"?`${Number(R??0)}h`:`${R??0}`,s==="weight"?"Usage":s==="time"?"Time":"Prints"]})]})}),i.jsx("div",{className:"flex-1 space-y-2 overflow-hidden",children:_.map((R,P)=>{const D=_.reduce((z,G)=>z+G.value,0),H=D>0?(R.value/D*100).toFixed(0):0;return i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx("div",{className:"w-3 h-3 rounded-sm flex-shrink-0",style:{backgroundColor:$1[P%$1.length]}}),i.jsx("span",{className:"text-white truncate flex-1",children:R.name}),i.jsxs("span",{className:"text-bambu-gray flex-shrink-0",children:[s==="weight"?th(R.value):s==="time"?`${R.value}h`:R.value," · ",H,"%"]})]},R.name)})})]}):i.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:a("stats.noFilamentData")})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:a("stats.filamentSuccess")}),x.length>0?i.jsx("div",{className:"space-y-1.5",children:x.map(R=>i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx("span",{className:"text-white truncate w-20 flex-shrink-0",children:R.name}),i.jsx("div",{className:"flex-1 h-1.5 bg-bambu-dark-secondary rounded-full",children:i.jsx("div",{className:`h-full rounded-full transition-all ${R.rate>=90?"bg-status-ok":R.rate>=70?"bg-status-warning":"bg-status-error"}`,style:{width:`${R.rate}%`}})}),i.jsxs("span",{className:`font-medium flex-shrink-0 tabular-nums ${R.rate>=90?"text-status-ok":R.rate>=70?"text-status-warning":"text-status-error"}`,children:[R.rate,"%"]}),i.jsxs("span",{className:"text-bambu-gray flex-shrink-0 text-xs",children:["(",R.total,")"]})]},R.name))}):i.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:a("stats.noArchiveData")})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray",children:a("stats.colorDistribution")}),i.jsx(VC,{value:l,onChange:c,exclude:["time"]})]}),g.length>0?(()=>{const R=g.reduce((P,D)=>P+D.value,0);return i.jsxs("div",{children:[i.jsxs("div",{className:"relative mx-auto",style:{width:160,height:160},children:[i.jsx(oh,{width:"100%",height:"100%",children:i.jsxs(aW,{children:[i.jsx(vF,{data:g,cx:"50%",cy:"50%",innerRadius:45,outerRadius:70,paddingAngle:2,dataKey:"value",children:g.map((P,D)=>i.jsx(Sx,{fill:P.hex,stroke:"#1a1a1a",strokeWidth:1},`color-${D}`))}),i.jsx(lh,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:P=>[l==="weight"?th(Number(P??0)):`${P??0}`,a(l==="weight"?"stats.filamentByWeight":"stats.filamentByPrints")]})]})}),i.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[i.jsx("span",{className:"text-lg font-bold text-white",children:l==="weight"?th(R):R}),i.jsxs("span",{className:"text-[10px] text-bambu-gray",children:[g.length," ",g.length===1?"color":"colors"]})]})]}),i.jsx("div",{className:"grid grid-cols-2 gap-x-3 gap-y-1 mt-2",children:g.slice(0,8).map(P=>{const D=R>0?(P.value/R*100).toFixed(0):0;return i.jsxs("div",{className:"flex items-center gap-1.5 text-xs min-w-0",children:[i.jsx("div",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0 border border-black/20",style:{backgroundColor:P.hex}}),i.jsxs("span",{className:"text-bambu-gray truncate",children:[D,"%"]})]},P.hex)})}),g.length>8&&i.jsxs("p",{className:"text-[10px] text-bambu-gray mt-1 text-center",children:["+",g.length-8," more"]})]})})():i.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:a("stats.noColorData")})]})]})]})}function KJe({id:t,title:e,component:n,isHidden:r,size:a,columnSpan:s,onToggleVisibility:o,onToggleSize:l}){const{attributes:c,listeners:u,setNodeRef:d,transform:m,transition:p,isDragging:f}=joe({id:t}),y={transform:Mx.Transform.toString(m),transition:p,opacity:f?.5:1};return r?null:i.jsxs("div",{ref:d,style:{...y,gridColumn:`span ${s}`},className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden ${f?"ring-2 ring-bambu-green shadow-lg":""}`,children:[i.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/30",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("button",{...c,...u,className:"cursor-grab active:cursor-grabbing p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Drag to reorder",children:i.jsx(bh,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray"})}),i.jsx("h3",{className:"text-sm font-medium text-white",children:e})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("button",{onClick:l,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:`Size: ${a===1?"1/4":a===2?"1/2":"Full"} - Click to cycle`,children:a===4?i.jsx(BL,{className:"w-4 h-4 text-bambu-gray hover:text-white"}):i.jsx(eT,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),i.jsx("button",{onClick:o,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Hide widget",children:i.jsx(mw,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]})]}),i.jsx("div",{className:"p-4",children:typeof n=="function"?n(a):n})]})}function YJe({widgets:t,storageKey:e,columns:n=4,stackBelow:r,hideControls:a=!1,onResetLayout:s,renderControls:o}){const l=()=>{const R={};return t.forEach(P=>{R[P.id]=P.defaultSize||4}),R},[c,u]=w.useState(()=>{const R=localStorage.getItem(e);if(R)try{const P=JSON.parse(R);if(!P.sizes)P.sizes=l();else{const D=l();for(const H in D)H in P.sizes||(P.sizes[H]=D[H])}return P}catch{}return{order:t.map(P=>P.id),hidden:t.filter(P=>P.defaultVisible===!1).map(P=>P.id),sizes:l()}}),[d,m]=w.useState(!1),[p,f]=w.useState(!1);w.useEffect(()=>{if(!r)return;const R=window.matchMedia(`(max-width: ${r}px)`),P=H=>{f(H.matches)};P(R);const D=H=>P(H);return R.addEventListener?R.addEventListener("change",D):R.addListener(D),()=>{R.removeEventListener?R.removeEventListener("change",D):R.removeListener(D)}},[r]);const y=r&&p?1:n;w.useEffect(()=>{const R=()=>m(P=>!P);return window.addEventListener("toggle-hidden-panel",R),()=>window.removeEventListener("toggle-hidden-panel",R)},[]),w.useEffect(()=>{localStorage.setItem(e,JSON.stringify(c))},[c,e]),w.useEffect(()=>{const P=t.map(D=>D.id).filter(D=>!c.order.includes(D));P.length>0&&u(D=>({...D,order:[...D.order,...P]}))},[t,c.order]);const v=uoe(HC(MA,{activationConstraint:{distance:8}}),HC(PA,{coordinateGetter:Doe})),x=R=>{const{active:P,over:D}=R;D&&P.id!==D.id&&u(H=>{const z=H.order.indexOf(P.id),G=H.order.indexOf(D.id);return{...H,order:DA(H.order,z,G)}})},g=R=>{u(P=>({...P,hidden:P.hidden.includes(R)?P.hidden.filter(D=>D!==R):[...P.hidden,R]}))},_=R=>{u(P=>{const D=P.sizes[R]||4,H=D===1?2:D===2?4:1;return{...P,sizes:{...P.sizes,[R]:H}}})},N=()=>{const R={order:t.map(P=>P.id),hidden:t.filter(P=>P.defaultVisible===!1).map(P=>P.id),sizes:l()};u(R),s?.()},T=c.order.map(R=>t.find(P=>P.id===R)).filter(Boolean),C=T.filter(R=>!c.hidden.includes(R.id)),A=T.filter(R=>c.hidden.includes(R.id)),k=o?.({hiddenCount:A.length,showHiddenPanel:d,setShowHiddenPanel:m,resetLayout:N});return i.jsxs("div",{className:"space-y-4",children:[k,!a&&!o&&i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:N,children:[i.jsx(bo,{className:"w-4 h-4"}),"Reset Layout"]}),A.length>0&&i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>m(!d),children:[i.jsx(_c,{className:"w-4 h-4"}),A.length," Hidden"]})]}),d&&A.length>0&&i.jsxs("div",{className:"p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:"Hidden widgets (click to show):"}),i.jsx("div",{className:"flex flex-wrap gap-2",children:A.map(R=>i.jsxs("button",{onClick:()=>g(R.id),className:"px-3 py-1.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded-lg text-sm text-white transition-colors flex items-center gap-2",children:[i.jsx(_c,{className:"w-3 h-3"}),R.title]},R.id))})]}),i.jsx(Toe,{sensors:v,collisionDetection:poe,onDragEnd:x,children:i.jsx(Moe,{items:C.map(R=>R.id),strategy:_5,children:i.jsx("div",{className:"grid gap-6",style:{gridTemplateColumns:`repeat(${y}, minmax(0, 1fr))`},children:C.map(R=>{const P=c.sizes[R.id]||2,D=Math.min(P,y);return i.jsx(KJe,{id:R.id,title:R.title,component:R.component,isHidden:c.hidden.includes(R.id),size:P,columnSpan:D,onToggleVisibility:()=>g(R.id),onToggleSize:()=>_(R.id)},R.id)})})})}),C.length===0&&i.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[i.jsx("p",{children:"All widgets are hidden."}),i.jsx(Oe,{className:"mt-4",onClick:N,children:"Reset Layout"})]})]})}function XJe(t){const e=new Date,n=e.getUTCFullYear(),r=e.getUTCMonth(),a=e.getUTCDate(),s=l=>l.toISOString().split("T")[0],o=s(e);switch(t){case"today":return{dateFrom:o,dateTo:o};case"this-week":{const l=e.getUTCDay(),c=new Date(Date.UTC(n,r,a-(l===0?6:l-1)));return{dateFrom:s(c),dateTo:o}}case"this-month":return{dateFrom:s(new Date(Date.UTC(n,r,1))),dateTo:o};case"last-7":return{dateFrom:s(new Date(Date.UTC(n,r,a-6))),dateTo:o};case"last-30":return{dateFrom:s(new Date(Date.UTC(n,r,a-29))),dateTo:o};case"last-90":return{dateFrom:s(new Date(Date.UTC(n,r,a-89))),dateTo:o};case"this-year":return{dateFrom:s(new Date(Date.UTC(n,0,1))),dateTo:o};case"all-time":return{dateFrom:void 0,dateTo:void 0};case"custom":return{}}}const QJe=["today","this-week","this-month","last-7","last-30","last-90","this-year","all-time"],ZJe=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],bL=["12am","1am","2am","3am","4am","5am","6am","7am","8am","9am","10am","11am","12pm","1pm","2pm","3pm","4pm","5pm","6pm","7pm","8pm","9pm","10pm","11pm"],OD=[{key:"<30m",max:1800},{key:"30m-1h",max:3600},{key:"1-2h",max:7200},{key:"2-4h",max:14400},{key:"4-8h",max:28800},{key:"8-12h",max:43200},{key:"12-24h",max:86400},{key:"24h+",max:1/0}],q1={backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"};function JJe({stats:t,currency:e}){const{t:n}=Ft(),r=[{icon:Wi,color:"text-bambu-green",label:n("stats.totalPrints"),value:`${t?.total_prints||0}`},{icon:er,color:"text-blue-400",label:n("stats.printTime"),value:`${t?.total_print_time_hours?.toFixed(1)??"0"}h`},{icon:Wi,color:"text-orange-400",label:n("stats.filamentUsed"),value:th(t?.total_filament_grams||0)},{icon:PN,color:"text-green-400",label:n("stats.filamentCost"),value:`${e} ${t?.total_cost?.toFixed(2)??"0.00"}`},{icon:kc,color:"text-yellow-400",label:n("stats.energyUsed"),value:`${t?.total_energy_kwh?.toFixed(3)??"0.000"} kWh`},{icon:PN,color:"text-yellow-500",label:n("stats.energyCost"),value:`${e} ${t?.total_energy_cost?.toFixed(2)??"0.00"}`}];return i.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:r.map(a=>i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx("div",{className:`p-2 rounded-lg bg-bambu-dark ${a.color}`,children:i.jsx(a.icon,{className:"w-5 h-5"})}),i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray",children:a.label}),i.jsx("p",{className:"text-xl font-bold text-white",children:a.value})]})]},a.label))})}function eet({stats:t,printerMap:e,size:n=1}){const{t:r}=Ft(),a=(t?.successful_prints||0)+(t?.failed_prints||0),s=a?Math.round(t.successful_prints/a*100):0,o=n===1?112:n===2?128:144,l=o/2-8,c=l*2*Math.PI;return i.jsxs("div",{className:"flex items-center gap-6",children:[i.jsxs("div",{className:"relative flex-shrink-0",style:{width:o,height:o},children:[i.jsxs("svg",{className:"w-full h-full -rotate-90",children:[i.jsx("circle",{cx:o/2,cy:o/2,r:l,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),i.jsx("circle",{cx:o/2,cy:o/2,r:l,fill:"none",stroke:"#00ae42",strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${s/100*c} ${c}`})]}),i.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:i.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[s,"%"]})})]}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(fr,{className:"w-4 h-4 text-status-ok flex-shrink-0"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:r("stats.successful")}),i.jsx("span",{className:"text-sm text-white font-medium",children:t?.successful_prints||0})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Vi,{className:"w-4 h-4 text-status-error flex-shrink-0"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:r("stats.failed")}),i.jsx("span",{className:"text-sm text-white font-medium",children:t?.failed_prints||0})]})]}),n>=2&&t?.prints_by_printer&&Object.keys(t.prints_by_printer).length>0&&i.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:r("stats.printsByPrinter")}),i.jsx("div",{className:`grid gap-x-6 gap-y-1 ${n===4?"grid-cols-3":"grid-cols-2"}`,style:{width:"fit-content"},children:Object.entries(t.prints_by_printer).map(([u,d])=>i.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[i.jsx("span",{className:"text-bambu-gray truncate max-w-[120px]",children:e.get(u)||`${r("common.printer")} ${u}`}),i.jsx("span",{className:"text-white font-medium",children:d})]},u))})]})]})]})}function tet({stats:t,printerMap:e,size:n=1}){const{t:r}=Ft(),a=t?.average_time_accuracy;if(a==null)return i.jsx("div",{className:"flex items-center justify-center h-full",children:i.jsx("p",{className:"text-bambu-gray text-center py-4",children:r("stats.noTimeAccuracyData")})});const o=(Math.min(150,Math.max(50,a))-50)/100*100,c=(v=>v>=95&&v<=105?"#00ae42":v>105?"#3b82f6":"#f97316")(a),u=a-100,d=n===1?112:n===2?128:144,m=d/2-8,p=m*2*Math.PI,f=n===1?3:n===2?6:999,y=t?.time_accuracy_by_printer?Object.entries(t.time_accuracy_by_printer).slice(0,f):[];return i.jsxs("div",{className:"flex items-center gap-6",children:[i.jsxs("div",{className:"relative flex-shrink-0",style:{width:d,height:d},children:[i.jsxs("svg",{className:"w-full h-full -rotate-90",children:[i.jsx("circle",{cx:d/2,cy:d/2,r:m,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),i.jsx("circle",{cx:d/2,cy:d/2,r:m,fill:"none",stroke:c,strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${o/100*p} ${p}`})]}),i.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[i.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[a.toFixed(0),"%"]}),i.jsxs("span",{className:`text-xs ${u>=0?"text-blue-400":"text-orange-400"}`,children:[u>=0?"+":"",u.toFixed(0),"%"]})]})]}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[i.jsx(JX,{className:"w-3 h-3 flex-shrink-0"}),i.jsx("span",{children:r("stats.perfectEstimate")})]}),y.length>0&&i.jsx("div",{className:`mt-2 ${n===4?"grid grid-cols-3 gap-x-6 gap-y-1":n===2?"grid grid-cols-2 gap-x-6 gap-y-1":"space-y-1"}`,style:{width:"fit-content"},children:y.map(([v,x])=>i.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[i.jsx("span",{className:"text-bambu-gray truncate max-w-[100px]",children:e.get(v)||`${r("common.printer")} ${v}`}),i.jsxs("span",{className:`font-medium ${x>=95&&x<=105?"text-status-ok":x>105?"text-blue-400":"text-status-warning"}`,children:[x.toFixed(0),"%"]})]},v))})]})]})}function net({printDates:t,dateFrom:e,dateTo:n}){const{days:r,hourlyCounts:a,maxCount:s}=w.useMemo(()=>{const d=new Date(e+"T00:00:00"),m=new Date(n+"T00:00:00"),p=[],f=g=>`${g.getFullYear()}-${String(g.getMonth()+1).padStart(2,"0")}-${String(g.getDate()).padStart(2,"0")}`,y=new Date(d);for(;y<=m;)p.push({key:f(y),label:y.toLocaleDateString(void 0,{weekday:"short",month:"short",day:"numeric"})}),y.setDate(y.getDate()+1);const v={};let x=0;return t.forEach(g=>{const _=Jn(g);if(!_)return;const T=`${`${_.getFullYear()}-${String(_.getMonth()+1).padStart(2,"0")}-${String(_.getDate()).padStart(2,"0")}`}-${_.getHours()}`;v[T]=(v[T]||0)+1,v[T]>x&&(x=v[T])}),{days:p,hourlyCounts:v,maxCount:Math.max(1,x)}},[t,e,n]),o=d=>{if(d===0)return"bg-bambu-dark";const m=d/s;return m<=.25?"bg-bambu-green/30":m<=.5?"bg-bambu-green/50":m<=.75?"bg-bambu-green/75":"bg-bambu-green"},l=20,c=2,u=80;return i.jsxs("div",{className:"w-full overflow-x-auto",children:[i.jsxs("div",{className:"inline-flex flex-col",style:{gap:c},children:[i.jsx("div",{className:"flex",style:{gap:c,marginLeft:u+4},children:bL.map((d,m)=>i.jsx("div",{className:"text-bambu-gray text-[10px] text-center",style:{width:l,visibility:m%2===0?"visible":"hidden"},children:d},m))}),r.map(d=>i.jsxs("div",{className:"flex items-center",style:{gap:c},children:[i.jsx("div",{className:"text-bambu-gray text-[10px] flex-shrink-0 truncate",style:{width:u},children:d.label}),Array.from({length:24},(m,p)=>{const f=a[`${d.key}-${p}`]||0;return i.jsx("div",{className:`rounded-sm ${o(f)}`,style:{width:l,height:l},title:`${d.label} ${bL[p]}: ${f} print${f!==1?"s":""}`},p)})]},d.key))]}),i.jsxs("div",{className:"flex items-center gap-2 mt-3 text-bambu-gray text-xs",children:[i.jsx("span",{children:"Less"}),i.jsxs("div",{className:"flex",style:{gap:c},children:[i.jsx("div",{className:"rounded-sm bg-bambu-dark",style:{width:l,height:l}}),i.jsx("div",{className:"rounded-sm bg-bambu-green/30",style:{width:l,height:l}}),i.jsx("div",{className:"rounded-sm bg-bambu-green/50",style:{width:l,height:l}}),i.jsx("div",{className:"rounded-sm bg-bambu-green/75",style:{width:l,height:l}}),i.jsx("div",{className:"rounded-sm bg-bambu-green",style:{width:l,height:l}})]}),i.jsx("span",{children:"More"})]})]})}function ret({printDates:t,size:e=2,dateFrom:n,dateTo:r}){const a=w.useMemo(()=>n&&r?Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1:n?Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1:1/0,[n,r]);if(a<=7&&n&&r)return i.jsx(net,{printDates:t,dateFrom:n,dateTo:r});const o=a===1/0?e===1?3:e===2?6:12:Math.max(1,Math.ceil(a/30));return i.jsx(VJe,{printDates:t,months:o})}function iet({stats:t,archives:e,printerMap:n}){const{t:r}=Ft(),[a,s]=w.useState("weight"),[o,l]=w.useState("weight"),c=w.useMemo(()=>{const g=new Map;return t?.prints_by_printer&&Object.entries(t.prints_by_printer).forEach(([_,N])=>{const T=g.get(_)||{prints:0,weight:0,time:0};T.prints=N,g.set(_,T)}),e.forEach(_=>{if(!_.printer_id)return;const N=String(_.printer_id),T=g.get(N)||{prints:0,weight:0,time:0};T.weight+=_.filament_used_grams||0,T.time+=_.actual_time_seconds||_.print_time_seconds||0,t?.prints_by_printer||T.prints++,g.set(N,T)}),Array.from(g.entries()).map(([_,N])=>({name:n.get(_)||`${r("common.printer")} ${_}`,value:a==="prints"?N.prints:a==="weight"?Math.round(N.weight):Math.round(N.time/3600*10)/10})).sort((_,N)=>N.value-_.value)},[t,e,n,a,r]),u=w.useMemo(()=>{const g=Array.from({length:24},(_,N)=>({hour:N,label:bL[N],total:0,failures:0}));return e.forEach(_=>{if(!_.started_at)return;const N=Jn(_.started_at);if(!N)return;const T=N.getHours();g[T].total++,_.status==="failed"&&g[T].failures++}),g},[e]),d=w.useMemo(()=>{const g=OD.map(_=>({name:_.key,count:0}));return e.forEach(_=>{const N=_.actual_time_seconds||_.print_time_seconds;if(!(!N||N<=0)){for(let T=0;T{const g=[0,0,0,0,0,0,0],_=new Set;e.forEach(T=>{const C=Jn(T.created_at)||new Date(T.created_at);let A=C.getDay()-1;A<0&&(A=6),o==="prints"?g[A]++:o==="weight"?g[A]+=T.filament_used_grams||0:g[A]+=(T.actual_time_seconds||T.print_time_seconds||0)/3600;const k=new Date(C);k.setDate(C.getDate()-(C.getDay()+6)%7),_.add(`${k.getFullYear()}-${String(k.getMonth()+1).padStart(2,"0")}-${String(k.getDate()).padStart(2,"0")}`)});const N=Math.max(_.size,1);return ZJe.map((T,C)=>({name:T,avg:Math.round(g[C]/N*10)/10}))},[e,o]),p=g=>({unit:g==="weight"?"g":g==="time"?"h":"",color:g==="weight"?"#00ae42":g==="time"?"#3b82f6":"#f59e0b"}),f=p(a),y=r(a==="weight"?"stats.filamentByWeight":a==="time"?"stats.hours":"common.prints"),v=p(o),x=r(o==="weight"?"stats.avgWeight":o==="time"?"stats.avgTime":"stats.avgPrints");return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray",children:r("stats.printsByPrinter")}),i.jsx(VC,{value:a,onChange:s})]}),c.length>0?i.jsx(oh,{width:"100%",height:Math.max(140,c.length*40),children:i.jsxs(N1,{data:c,layout:"vertical",margin:{left:10},children:[i.jsx(Kp,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),i.jsx(Yp,{type:"number",stroke:"#9ca3af",tick:{fontSize:11},unit:f.unit}),i.jsx(Xp,{type:"category",dataKey:"name",stroke:"#9ca3af",tick:{fontSize:11},width:100}),i.jsx(lh,{contentStyle:q1,formatter:g=>[a==="weight"?th(Number(g??0)):`${g??0}${f.unit}`,y]}),i.jsx(Tb,{dataKey:"value",fill:f.color,radius:[0,4,4,0]})]})}):i.jsx("p",{className:"text-bambu-gray text-center py-4",children:r("stats.noPrinterData")})]}),i.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-3",children:r("stats.printDuration")}),e.length>0?i.jsx(oh,{width:"100%",height:160,children:i.jsxs(N1,{data:d,children:[i.jsx(Kp,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),i.jsx(Yp,{dataKey:"name",stroke:"#9ca3af",tick:{fontSize:11}}),i.jsx(Xp,{stroke:"#9ca3af",tick:{fontSize:11},allowDecimals:!1}),i.jsx(lh,{contentStyle:q1}),i.jsx(Tb,{dataKey:"count",name:r("common.prints"),fill:"#00ae42",radius:[4,4,0,0]})]})}):i.jsx("p",{className:"text-bambu-gray text-center py-4",children:r("stats.noArchiveData")})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray",children:r("stats.printHabits")}),i.jsx(VC,{value:o,onChange:l})]}),e.length>0?i.jsx(oh,{width:"100%",height:160,children:i.jsxs(N1,{data:m,children:[i.jsx(Kp,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),i.jsx(Yp,{dataKey:"name",stroke:"#9ca3af",tick:{fontSize:11}}),i.jsx(Xp,{stroke:"#9ca3af",tick:{fontSize:11},unit:v.unit}),i.jsx(lh,{contentStyle:q1,formatter:g=>[`${g??0}${v.unit}`,x]}),i.jsx(Tb,{dataKey:"avg",fill:v.color,radius:[4,4,0,0]})]})}):i.jsx("p",{className:"text-bambu-gray text-center py-4",children:r("stats.noArchiveData")})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-3",children:r("stats.printTimeOfDay")}),e.length>0?i.jsx(oh,{width:"100%",height:160,children:i.jsxs(N1,{data:u,children:[i.jsx(Kp,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),i.jsx(Yp,{dataKey:"label",stroke:"#9ca3af",tick:{fontSize:10},interval:5}),i.jsx(Xp,{stroke:"#9ca3af",tick:{fontSize:11},allowDecimals:!1}),i.jsx(lh,{contentStyle:q1}),i.jsx(Tb,{dataKey:"total",name:r("stats.totalPrints"),fill:"#00ae42",radius:[2,2,0,0]}),i.jsx(Tb,{dataKey:"failures",name:r("stats.failed"),fill:"#ef4444",radius:[2,2,0,0]})]})}):i.jsx("p",{className:"text-bambu-gray text-center py-4",children:r("stats.noArchiveData")})]})]})]})}function aet({archives:t,currency:e,dateFrom:n,dateTo:r}){const{t:a}=Ft();return!t||t.length===0?i.jsx("p",{className:"text-bambu-gray text-center py-4",children:a("stats.noPrintData")}):i.jsx(WJe,{archives:t,currency:e,dateFrom:n,dateTo:r})}function set({size:t=1,dateFrom:e,dateTo:n}){const{t:r}=Ft(),a=!!(e||n),{data:s,isLoading:o}=et({queryKey:["failureAnalysis",e,n],queryFn:()=>be.getFailureAnalysis({...a?{dateFrom:e,dateTo:n}:{days:30}})});if(o)return i.jsx("div",{className:"flex justify-center py-4",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(!s||s.total_prints===0)return i.jsx("p",{className:"text-bambu-gray text-center py-4",children:r(a?"stats.noPrintDataInRange":"stats.noPrintDataLast30Days")});const l=t===1?5:t===2?8:999,c=Object.entries(s.failures_by_reason).sort(([,m],[,p])=>p-m),u=c.slice(0,l),d=c.length>l;return i.jsxs("div",{className:`${t>=2?"flex gap-8":"space-y-4"}`,children:[i.jsxs("div",{className:t>=2?"flex-shrink-0":"",children:[i.jsx("div",{className:"flex items-center gap-4",children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Mn,{className:`w-5 h-5 ${s.failure_rate>20?"text-status-error":s.failure_rate>10?"text-status-warning":"text-status-ok"}`}),i.jsxs("span",{className:`font-bold text-white ${t>=2?"text-3xl":"text-2xl"}`,children:[s.failure_rate.toFixed(1),"%"]})]})}),i.jsx("div",{className:"text-sm text-bambu-gray mt-1",children:r("stats.failedPrintsCount",{failed:s.failed_prints,total:s.total_prints})}),s.trend&&s.trend.length>=2&&i.jsx("div",{className:`${t>=2?"mt-4":"mt-2 pt-2 border-t border-bambu-dark-tertiary"}`,children:i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx(qL,{className:`w-4 h-4 ${s.trend[s.trend.length-1].failure_rate0&&i.jsxs("div",{className:`flex-1 ${t>=2?"border-l border-bambu-dark-tertiary pl-8":"pt-2"}`,children:[i.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:t>=2?r("stats.failureReasons"):r("stats.topFailureReasons")}),i.jsx("div",{className:`${t===4?"grid grid-cols-2 gap-x-6 gap-y-1":"space-y-1"}`,children:u.map(([m,p])=>i.jsxs("div",{className:"flex items-center justify-between text-sm",children:[i.jsx("span",{className:`text-white truncate ${t===4?"max-w-[200px]":"max-w-[160px]"}`,children:m||r("common.unknown")}),i.jsx("span",{className:"text-bambu-gray ml-2",children:p})]},m))}),d&&i.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:r("common.more",{count:c.length-l})})]})]})}function oet({archives:t,currency:e}){const{t:n}=Ft(),r=w.useMemo(()=>{const a=[];if(t.length===0)return a;const s=y=>{let v=null,x=0;return t.forEach(g=>{const _=y(g);_&&_>x&&(x=_,v=g)}),{archive:v,value:x}},o=s(y=>y.actual_time_seconds);o.archive&&a.push({icon:er,iconColor:"text-blue-400",label:n("stats.longestPrint"),value:Rs(o.value),detail:o.archive.print_name||null});const l=s(y=>y.filament_used_grams);l.archive&&a.push({icon:Wi,iconColor:"text-orange-400",label:n("stats.heaviestPrint"),value:th(l.value),detail:l.archive.print_name||null});const c=s(y=>y.cost);c.archive&&a.push({icon:PN,iconColor:"text-green-400",label:n("stats.mostExpensivePrint"),value:`${e}${c.value.toFixed(2)}`,detail:c.archive.print_name||null});const u=new Map;t.forEach(y=>{const v=Jn(y.created_at)||new Date(y.created_at),x=`${v.getFullYear()}-${String(v.getMonth()+1).padStart(2,"0")}-${String(v.getDate()).padStart(2,"0")}`;u.set(x,(u.get(x)||0)+1)});let d="",m=0;u.forEach((y,v)=>{y>m&&(m=y,d=v)}),m>1&&a.push({icon:Wr,iconColor:"text-purple-400",label:n("stats.busiestDay"),value:`${m} ${n("common.prints")}`,detail:(()=>{const[y,v,x]=d.split("-").map(Number);return new Date(y,v-1,x).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"})})()});const p=[...t].filter(y=>y.status==="completed"||y.status==="failed").sort((y,v)=>new Date(v.completed_at||v.created_at).getTime()-new Date(y.completed_at||y.created_at).getTime());let f=0;for(const y of p)if(y.status==="completed")f++;else break;return f>0&&a.push({icon:kc,iconColor:"text-yellow-400",label:n("stats.successStreak"),value:`${f}`,detail:f===1?n("stats.streakPrint"):n("stats.streakPrints",{count:f})}),a},[t,e,n]);return r.length===0?i.jsx("p",{className:"text-bambu-gray text-center py-4",children:n("stats.noArchiveData")}):i.jsx("div",{className:"space-y-3",children:r.map((a,s)=>i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:`p-1.5 rounded-lg bg-bambu-dark ${a.iconColor}`,children:i.jsx(a.icon,{className:"w-4 h-4"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-xs text-bambu-gray",children:a.label}),i.jsxs("div",{className:"flex items-baseline gap-2",children:[i.jsx("span",{className:"text-sm font-bold text-white",children:a.value}),a.detail&&i.jsx("span",{className:"text-xs text-bambu-gray truncate",children:a.detail})]})]})]},s))})}function cet(){const{t}=Ft(),{showToast:e}=fn(),{hasPermission:n}=_r(),[r,a]=w.useState(!1),[s,o]=w.useState(!1),[l,c]=w.useState(0),[u,d]=w.useState(0),[m,p]=w.useState(!1),[f,y]=w.useState(()=>{try{const ee=localStorage.getItem("bambusy-stats-timeframe");if(ee){const ie=JSON.parse(ee);if(ie.preset)return ie}}catch{}return{preset:"all-time",dateFrom:void 0,dateTo:void 0}}),[v,x]=w.useState(!1);w.useEffect(()=>{localStorage.setItem("bambusy-stats-timeframe",JSON.stringify(f))},[f]);const g=w.useMemo(()=>f.preset==="custom"?{dateFrom:f.dateFrom,dateTo:f.dateTo}:XJe(f.preset),[f]);w.useEffect(()=>{const ee=()=>{try{const X=localStorage.getItem("bambusy-dashboard-layout-v2");if(X){const me=JSON.parse(X);d(me.hidden?.length||0)}}catch{d(0)}};ee(),window.addEventListener("storage",ee);const ie=setInterval(ee,2e3);return()=>{window.removeEventListener("storage",ee),clearInterval(ie)}},[l]);const{data:_,isLoading:N,refetch:T}=et({queryKey:["archiveStats",g.dateFrom,g.dateTo],queryFn:()=>be.getArchiveStats({dateFrom:g.dateFrom,dateTo:g.dateTo})}),{data:C}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:A,refetch:k}=et({queryKey:["archivesSlim",g.dateFrom,g.dateTo],queryFn:()=>be.getArchivesSlim(g.dateFrom,g.dateTo)}),{data:R}=et({queryKey:["settings"],queryFn:be.getSettings}),P=async ee=>{o(!1),a(!0);try{const{blob:ie,filename:X}=await be.exportStats({format:ee,days:90}),me=URL.createObjectURL(ie),he=document.createElement("a");he.href=me,he.download=X,he.click(),URL.revokeObjectURL(me),e(t("stats.exportDownloaded"))}catch{e(t("stats.exportFailed"),"error")}finally{a(!1)}},D=async()=>{p(!0);try{const ee=await be.recalculateCosts();await Promise.all([T(),k()]),e(t("stats.recalculatedCosts",{count:ee.updated}))}catch{e(t("stats.recalculateFailed"),"error")}finally{p(!1)}},H=_l(R?.currency||"USD"),z=new Map(C?.map(ee=>[String(ee.id),ee.name])||[]),G=w.useMemo(()=>A?.map(ee=>ee.created_at)||[],[A]);if(N)return i.jsx("div",{className:"p-4 md:p-8",children:i.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("stats.loadingStats")})});const I=[{id:"quick-stats",title:t("stats.quickStats"),component:i.jsx(JJe,{stats:_,currency:H}),defaultSize:2},{id:"success-rate",title:t("stats.successRate"),component:ee=>i.jsx(eet,{stats:_,printerMap:z,size:ee}),defaultSize:1},{id:"time-accuracy",title:t("stats.timeAccuracy"),component:ee=>i.jsx(tet,{stats:_,printerMap:z,size:ee}),defaultSize:1},{id:"failure-analysis",title:t("stats.failureAnalysis"),component:ee=>i.jsx(set,{size:ee,dateFrom:g.dateFrom,dateTo:g.dateTo}),defaultSize:1},{id:"print-activity",title:t("stats.printActivity"),component:ee=>i.jsx(ret,{printDates:G,size:ee,dateFrom:g.dateFrom,dateTo:g.dateTo}),defaultSize:2},{id:"records",title:t("stats.records"),component:i.jsx(oet,{archives:A||[],currency:H}),defaultSize:1},{id:"printer-stats",title:t("stats.printerStats"),component:i.jsx(iet,{stats:_,archives:A||[],printerMap:z}),defaultSize:4},{id:"filament-trends",title:t("stats.filamentTrends"),component:i.jsx(aet,{archives:A||[],currency:H,dateFrom:g.dateFrom,dateTo:g.dateTo}),defaultSize:4}];return i.jsxs("div",{className:"p-4 md:p-8",children:[i.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6",children:[i.jsxs("div",{children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:t("stats.title")}),i.jsx("p",{className:"text-bambu-gray",children:t("stats.subtitle")})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u>0&&i.jsxs(Oe,{variant:"secondary",onClick:()=>{window.dispatchEvent(new CustomEvent("toggle-hidden-panel"))},children:[i.jsx(_c,{className:"w-4 h-4"}),t("stats.hiddenCount",{count:u})]}),i.jsxs(Oe,{variant:"secondary",onClick:()=>{localStorage.removeItem("bambusy-dashboard-layout-v2"),c(ee=>ee+1),e(t("stats.layoutReset"))},disabled:!n("settings:update"),title:n("settings:update")?void 0:t("stats.noPermissionResetLayout"),children:[i.jsx(bo,{className:"w-4 h-4"}),t("stats.resetLayout")]}),i.jsxs(Oe,{variant:"secondary",onClick:D,disabled:m||!n("archives:update_all"),title:n("archives:update_all")?t("stats.recalculateCostsHint"):t("stats.noPermissionRecalculate"),children:[m?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(jhe,{className:"w-4 h-4"}),t("stats.recalculateCosts")]}),i.jsxs("div",{className:"relative",children:[i.jsxs(Oe,{variant:"secondary",onClick:()=>o(!s),disabled:r,children:[r?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(EN,{className:"w-4 h-4"}),t("stats.exportStats")]}),s&&i.jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20",children:[i.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg",onClick:()=>P("csv"),children:[i.jsx(Fs,{className:"w-4 h-4"}),t("stats.exportAsCsv")]}),i.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg",onClick:()=>P("xlsx"),children:[i.jsx(EN,{className:"w-4 h-4"}),t("stats.exportAsExcel")]})]})]}),i.jsxs("div",{className:"relative",children:[i.jsxs(Oe,{variant:"secondary",onClick:()=>x(!v),children:[i.jsx(Wr,{className:"w-4 h-4"}),t(`stats.timeframe.${f.preset}`),i.jsx(Ln,{className:"w-3 h-3"})]}),v&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>x(!1)}),i.jsxs("div",{className:"absolute right-0 top-full mt-1 w-64 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 p-2",children:[QJe.map(ee=>i.jsx("button",{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${f.preset===ee?"bg-bambu-green text-white":"text-white hover:bg-bambu-dark-tertiary"}`,onClick:()=>{y({preset:ee,dateFrom:void 0,dateTo:void 0}),x(!1)},children:t(`stats.timeframe.${ee}`)},ee)),i.jsx("div",{className:"border-t border-bambu-dark-tertiary my-2"}),i.jsx("button",{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${f.preset==="custom"?"bg-bambu-green text-white":"text-white hover:bg-bambu-dark-tertiary"}`,onClick:()=>y(ee=>({...ee,preset:"custom"})),children:t("stats.timeframe.custom")}),f.preset==="custom"&&i.jsxs("div",{className:"mt-2 px-1 pb-1 space-y-2",children:[i.jsxs("div",{children:[i.jsx("label",{className:"text-xs text-bambu-gray block mb-1",children:t("stats.timeframe.from")}),i.jsx("input",{type:"date",value:f.dateFrom||"",max:f.dateTo||new Date().toISOString().split("T")[0],onChange:ee=>y(ie=>({...ie,dateFrom:ee.target.value||void 0})),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white [color-scheme:dark]"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"text-xs text-bambu-gray block mb-1",children:t("stats.timeframe.to")}),i.jsx("input",{type:"date",value:f.dateTo||"",min:f.dateFrom,max:new Date().toISOString().split("T")[0],onChange:ee=>y(ie=>({...ie,dateTo:ee.target.value||void 0})),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white [color-scheme:dark]"})]}),i.jsx(Oe,{variant:"primary",onClick:()=>x(!1),className:"w-full",children:t("common.apply")})]})]})]})]})]})]}),i.jsx(YJe,{widgets:I,storageKey:"bambusy-dashboard-layout-v2",stackBelow:640,hideControls:!0},l)]})}function uet({plug:t,onEdit:e}){const{t:n}=Ft(),r=an(),{showToast:a}=fn(),[s,o]=w.useState(!1),[l,c]=w.useState(!1),[u,d]=w.useState(!1),[m,p]=w.useState(!1),{data:f,isLoading:y}=et({queryKey:["smart-plug-status",t.id],queryFn:()=>be.getSmartPlugStatus(t.id),refetchInterval:3e4}),{data:v}=et({queryKey:["printers"],queryFn:be.getPrinters}),x=v?.find(D=>D.id===t.printer_id),g=pt({mutationFn:D=>be.controlSmartPlug(t.id,D),onMutate:async D=>{await r.cancelQueries({queryKey:["smart-plug-status",t.id]});const H=r.getQueryData(["smart-plug-status",t.id]),z=D==="on"?"ON":D==="off"||f?.state==="ON"?"OFF":"ON";return r.setQueryData(["smart-plug-status",t.id],G=>({...G,state:z})),{previousStatus:H}},onError:(D,H,z)=>{z?.previousStatus&&r.setQueryData(["smart-plug-status",t.id],z.previousStatus),a(n("smartPlugs.failedToTurn",{action:H,name:t.name}),"error")},onSettled:()=>{setTimeout(()=>{r.invalidateQueries({queryKey:["smart-plug-status",t.id]}),r.invalidateQueries({queryKey:["smart-plugs"]})},1e3)}}),_=pt({mutationFn:D=>be.updateSmartPlug(t.id,D),onSuccess:()=>{r.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&(r.invalidateQueries({queryKey:["smartPlugByPrinter",t.printer_id]}),r.invalidateQueries({queryKey:["scriptPlugsByPrinter",t.printer_id]}))}}),N=pt({mutationFn:()=>be.deleteSmartPlug(t.id),onSuccess:()=>{r.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&r.invalidateQueries({queryKey:["scriptPlugsByPrinter",t.printer_id]})}}),T=f?.state==="ON",C=t.plug_type==="mqtt"&&f?.energy?.power!==null&&f?.energy?.power!==void 0,A=(f?.reachable??!1)||C,k=g.isPending,P=(()=>{if(t.plug_type!=="tasmota"||!t.ip_address)return null;const D=t.ip_address;return t.username&&t.password?`http://${encodeURIComponent(t.username)}:${encodeURIComponent(t.password)}@${D}/`:`http://${D}/`})();return i.jsxs(i.Fragment,{children:[i.jsx(Mt,{className:"relative",children:i.jsxs(Dt,{className:"p-4",children:[i.jsxs("div",{className:"flex items-start justify-between gap-2 mb-3",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[i.jsx("div",{className:`p-2 rounded-lg flex-shrink-0 ${t.plug_type==="mqtt"?A?"bg-teal-500/20":"bg-red-500/20":A?T?"bg-bambu-green/20":"bg-bambu-dark":"bg-red-500/20"}`,children:t.plug_type==="mqtt"?i.jsx(HL,{className:`w-5 h-5 ${A?"text-teal-400":"text-red-400"}`}):t.plug_type==="homeassistant"?i.jsx(hw,{className:`w-5 h-5 ${A?T?"text-bambu-green":"text-bambu-gray":"text-red-400"}`}):i.jsx(Dl,{className:`w-5 h-5 ${A?T?"text-bambu-green":"text-bambu-gray":"text-red-400"}`})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("h3",{className:"font-medium text-white truncate",children:t.name}),i.jsx("p",{className:"text-sm text-bambu-gray truncate",title:t.plug_type==="mqtt"?t.mqtt_topic??void 0:t.plug_type==="homeassistant"?t.ha_entity_id??void 0:t.ip_address??void 0,children:t.plug_type==="mqtt"?t.mqtt_topic:t.plug_type==="homeassistant"?t.ha_entity_id:t.ip_address})]})]}),i.jsxs("div",{className:"flex flex-col items-end gap-1 flex-shrink-0",children:[y?i.jsx(ht,{className:"w-4 h-4 text-bambu-gray animate-spin"}):t.plug_type==="mqtt"?i.jsxs("div",{className:"flex items-center gap-1.5 text-sm whitespace-nowrap",children:[i.jsx("span",{className:"px-1.5 py-0.5 bg-teal-500/20 text-teal-400 text-[10px] font-medium rounded flex-shrink-0",children:"MQTT"}),A&&i.jsx("span",{className:"text-status-ok",children:"✓"})]}):t.plug_type==="homeassistant"?i.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[i.jsx("span",{className:"px-1 py-0.5 bg-blue-500/20 text-blue-400 text-[10px] font-medium rounded",children:"HA"}),i.jsx("span",{className:A?T?"text-status-ok":"text-bambu-gray":"text-status-error",children:A?f?.state||"?":n("smartPlugs.offline")})]}):A?i.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[i.jsx(Ub,{className:"w-4 h-4 text-status-ok"}),i.jsx("span",{className:T?"text-status-ok":"text-bambu-gray",children:f?.state||n("smartPlugs.unknown")})]}):i.jsxs("div",{className:"flex items-center gap-1 text-sm text-status-error",children:[i.jsx(Ph,{className:"w-4 h-4"}),i.jsx("span",{children:n("smartPlugs.offline")})]}),P&&i.jsxs("a",{href:P,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:[i.jsx(Jr,{className:"w-3 h-3"}),n("smartPlugs.admin")]})]})]}),x&&i.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[i.jsxs("span",{className:"text-xs text-bambu-gray",children:[n("smartPlugs.linkedTo")," "]}),i.jsx("span",{className:"text-sm text-white",children:x.name})]}),(t.power_alert_enabled||t.schedule_enabled||t.plug_type==="mqtt")&&i.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-3",children:[t.plug_type==="mqtt"&&i.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-teal-500/20 text-teal-400 text-xs rounded-full",children:[i.jsx(_c,{className:"w-3 h-3"}),n("smartPlugs.monitorOnly")]}),t.power_alert_enabled&&i.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded-full",children:[i.jsx(hh,{className:"w-3 h-3"}),n("smartPlugs.alerts")]}),t.schedule_enabled&&i.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded-full",children:[i.jsx(Wr,{className:"w-3 h-3"}),t.schedule_on_time&&t.schedule_off_time?`${t.schedule_on_time} - ${t.schedule_off_time}`:t.schedule_on_time?n("smartPlugs.scheduleOn",{time:t.schedule_on_time}):n("smartPlugs.scheduleOff",{time:t.schedule_off_time})]})]}),t.plug_type!=="mqtt"&&i.jsxs("div",{className:"flex gap-2 mb-3",children:[i.jsxs(Oe,{size:"sm",variant:T?"primary":"secondary",disabled:!A||k,onClick:()=>c(!0),className:"flex-1",children:[k?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Vd,{className:"w-4 h-4"}),n("smartPlugs.on")]}),i.jsxs(Oe,{size:"sm",variant:T?"secondary":"primary",disabled:!A||k,onClick:()=>d(!0),className:"flex-1",children:[k?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(nT,{className:"w-4 h-4"}),n("smartPlugs.off")]})]}),t.plug_type==="mqtt"&&f?.energy&&i.jsxs("div",{className:"flex gap-2 mb-3 px-3 py-2 bg-bambu-dark rounded-lg",children:[f.energy.power!==null&&f.energy.power!==void 0&&i.jsxs("div",{className:"flex-1 text-center",children:[i.jsxs("p",{className:"text-lg font-semibold text-white",children:[Math.round(f.energy.power),"W"]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.power")})]}),f.energy.today!==null&&f.energy.today!==void 0&&i.jsxs("div",{className:"flex-1 text-center border-l border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-lg font-semibold text-white",children:f.energy.today.toFixed(3)}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.kwhToday")})]})]}),i.jsxs("button",{onClick:()=>p(!m),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:[i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(jd,{className:"w-4 h-4"}),t.plug_type==="mqtt"?n("smartPlugs.settings"):n("smartPlugs.automationSettings")]}),i.jsx("span",{children:m?"-":"+"})]}),m&&i.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(pw,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("smartPlugs.showInSwitchbar")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.quickAccessSidebar")})]})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:t.show_in_switchbar,onChange:D=>_.mutate({show_in_switchbar:D.target.checked}),className:"sr-only peer"}),i.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"})]})]}),t.plug_type!=="mqtt"&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("smartPlugs.enabled")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.enableAutomation")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:t.enabled,onChange:D=>_.mutate({enabled:D.target.checked}),className:"sr-only peer"}),i.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"})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("smartPlugs.autoOn")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.autoOnDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:t.auto_on,onChange:D=>_.mutate({auto_on:D.target.checked}),className:"sr-only peer"}),i.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"})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("smartPlugs.autoOff")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.autoOffDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:t.auto_off,onChange:D=>_.mutate({auto_off:D.target.checked}),className:"sr-only peer"}),i.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"})]})]}),t.auto_off&&i.jsxs("div",{className:"space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white mb-2",children:n("smartPlugs.turnOffDelayMode")}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("button",{onClick:()=>_.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 ${t.off_delay_mode==="time"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[i.jsx(er,{className:"w-4 h-4"}),n("smartPlugs.time")]}),i.jsxs("button",{onClick:()=>_.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 ${t.off_delay_mode==="temperature"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[i.jsx(aT,{className:"w-4 h-4"}),n("smartPlugs.temp")]})]})]}),t.off_delay_mode==="time"?i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("smartPlugs.delayMinutes")}),i.jsx("input",{type:"number",min:"1",max:"60",value:t.off_delay_minutes,onChange:D=>_.mutate({off_delay_minutes:parseInt(D.target.value)||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"})]}):i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("smartPlugs.tempThreshold")}),i.jsx("input",{type:"number",min:"30",max:"100",value:t.off_temp_threshold,onChange:D=>_.mutate({off_temp_threshold:parseInt(D.target.value)||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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("smartPlugs.tempThresholdDescription")})]})]})]}),i.jsxs("div",{className:"flex gap-2 pt-2",children:[i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[i.jsx(nh,{className:"w-4 h-4"}),n("smartPlugs.edit")]}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:()=>o(!0),className:"text-red-400 hover:text-red-300",children:i.jsx(Jt,{className:"w-4 h-4"})})]})]})]})}),s&&i.jsx(Sn,{title:n("smartPlugs.deleteSmartPlug"),message:n("smartPlugs.deleteConfirm",{name:t.name}),confirmText:n("smartPlugs.delete"),variant:"danger",onConfirm:()=>{N.mutate(),o(!1)},onCancel:()=>o(!1)}),l&&i.jsx(Sn,{title:n("smartPlugs.turnOnSmartPlug"),message:n("smartPlugs.turnOnConfirm",{name:t.name}),confirmText:n("smartPlugs.turnOn"),variant:"default",onConfirm:()=>{g.mutate("on"),c(!1)},onCancel:()=>c(!1)}),u&&i.jsx(Sn,{title:n("smartPlugs.turnOffSmartPlug"),message:n("smartPlugs.turnOffConfirm",{name:t.name}),confirmText:n("smartPlugs.turnOff"),variant:"danger",onConfirm:()=>{g.mutate("off"),d(!1)},onCancel:()=>d(!1)})]})}function det({plug:t,onClose:e}){const{t:n}=Ft(),r=an(),a=!!t,[s,o]=w.useState(t?.plug_type||"tasmota"),[l,c]=w.useState(t?.name||""),[u,d]=w.useState(t?.ip_address||""),[m,p]=w.useState(t?.username||""),[f,y]=w.useState(t?.password||""),[v,x]=w.useState(t?.ha_entity_id||""),[g,_]=w.useState(t?.mqtt_power_topic||t?.mqtt_topic||""),[N,T]=w.useState(t?.mqtt_power_path||""),[C,A]=w.useState((t?.mqtt_power_multiplier??t?.mqtt_multiplier??1).toString()),[k,R]=w.useState(t?.mqtt_energy_topic||""),[P,D]=w.useState(t?.mqtt_energy_path||""),[H,z]=w.useState((t?.mqtt_energy_multiplier??1).toString()),[G,I]=w.useState(t?.mqtt_state_topic||""),[ee,ie]=w.useState(t?.mqtt_state_path||""),[X,me]=w.useState(t?.mqtt_state_on_value||""),[he,ge]=w.useState(t?.ha_power_entity||""),[Y,oe]=w.useState(t?.ha_energy_today_entity||""),[le,xe]=w.useState(t?.ha_energy_total_entity||""),[Pe,q]=w.useState(""),[Z,j]=w.useState(""),[E,U]=w.useState(!1),K=w.useRef(null),[$,ne]=w.useState(""),[O,V]=w.useState(!1),J=w.useRef(null),[W,re]=w.useState(""),[ue,fe]=w.useState(!1),ye=w.useRef(null),[ae,L]=w.useState(""),[F,te]=w.useState(!1),ve=w.useRef(null),[pe,de]=w.useState(t?.printer_id||null),[Ne,Se]=w.useState(null),[Le,qe]=w.useState(null),[Ee,Te]=w.useState(t?.power_alert_enabled||!1),[Ae,Be]=w.useState(t?.power_alert_high?.toString()||""),[je,Xe]=w.useState(t?.power_alert_low?.toString()||""),[ce,Ie]=w.useState(t?.schedule_enabled||!1),[Ce,Ge]=w.useState(t?.schedule_on_time||""),[$e,Ue]=w.useState(t?.schedule_off_time||""),[De,Ve]=w.useState(t?.show_in_switchbar||!1),[it,xt]=w.useState(t?.show_on_printer_card??!0),[Nt,kt]=w.useState(!1),[We,yt]=w.useState({scanned:0,total:0}),[wt,_t]=w.useState([]),Ot=w.useRef(null),{data:Vt}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:Xt}=et({queryKey:["smart-plugs"],queryFn:be.getSmartPlugs}),{data:Qe}=et({queryKey:["settings"],queryFn:be.getSettings}),Qt=!!(Qe?.ha_enabled&&Qe?.ha_url&&Qe?.ha_token);w.useEffect(()=>{const Me=setTimeout(()=>{j(Pe)},300);return()=>clearTimeout(Me)},[Pe]),w.useEffect(()=>{const Me=dt=>{K.current&&!K.current.contains(dt.target)&&U(!1),J.current&&!J.current.contains(dt.target)&&V(!1),ye.current&&!ye.current.contains(dt.target)&&fe(!1),ve.current&&!ve.current.contains(dt.target)&&te(!1)};return document.addEventListener("mousedown",Me),()=>document.removeEventListener("mousedown",Me)},[]);const{data:hn,isLoading:jn,error:kn}=et({queryKey:["ha-entities",Z],queryFn:()=>be.getHAEntities(Z||void 0),enabled:s==="homeassistant"&&Qt,retry:!1,staleTime:0}),{data:Fe}=et({queryKey:["ha-sensor-entities"],queryFn:be.getHASensorEntities,enabled:s==="homeassistant"&&Qt,retry:!1,staleTime:0});w.useEffect(()=>{const Me=dt=>{dt.key==="Escape"&&e()};return window.addEventListener("keydown",Me),()=>{window.removeEventListener("keydown",Me),Ot.current&&clearInterval(Ot.current)}},[e]);const tt=async()=>{kt(!0),_t([]),yt({scanned:0,total:0}),qe(null);try{await be.startTasmotaScan();const Me=async()=>{try{const dt=await be.getTasmotaScanStatus();yt({scanned:dt.scanned,total:dt.total});const ct=await be.getDiscoveredTasmotaDevices();_t(ct),dt.running||(kt(!1),Ot.current&&(clearInterval(Ot.current),Ot.current=null))}catch(dt){console.error("Polling error:",dt)}};await Me(),Ot.current=setInterval(Me,500)}catch(Me){kt(!1);const dt=Me instanceof Error?Me.message:typeof Me=="string"?Me:JSON.stringify(Me);qe(dt||n("smartPlugs.failedToStartScan"))}},ut=async()=>{try{await be.stopTasmotaScan()}catch{}kt(!1),Ot.current&&(clearInterval(Ot.current),Ot.current=null)},Ze=Me=>{d(Me.ip_address),c(Me.name),Se(null)},ke=pt({mutationFn:()=>be.testSmartPlugConnection(u,m||null,f||null),onSuccess:Me=>{Se(Me),qe(null),!l&&Me.device_name&&c(Me.device_name)},onError:Me=>{Se(null),qe(Me.message)}}),ot=pt({mutationFn:Me=>be.createSmartPlug(Me),onSuccess:()=>{r.invalidateQueries({queryKey:["smart-plugs"]}),r.invalidateQueries({queryKey:["scriptPlugsByPrinter"]}),e()},onError:Me=>{qe(Me.message)}}),se=pt({mutationFn:Me=>be.updateSmartPlug(t.id,Me),onSuccess:()=>{r.invalidateQueries({queryKey:["smart-plugs"]}),r.invalidateQueries({queryKey:["scriptPlugsByPrinter"]}),e()},onError:Me=>{qe(Me.message)}}),He=Vt?.filter(Me=>s==="tasmota"?!Xt?.some(ct=>ct.printer_id===Me.id&&ct.id!==t?.id&&ct.plug_type==="tasmota"):!0),Ke=Me=>{if(Me.preventDefault(),qe(null),!l.trim()){qe(n("smartPlugs.nameRequired"));return}if(s==="tasmota"&&!u.trim()){qe("IP address is required for Tasmota plugs");return}if(s==="homeassistant"&&!v){qe(n("smartPlugs.entityRequired"));return}if(s==="mqtt"){const ct=g.trim(),nt=k.trim(),bt=G.trim();if(!ct&&!nt&&!bt){qe(n("smartPlugs.mqttTopicRequired"));return}}const dt={name:l.trim(),plug_type:s,ip_address:s==="tasmota"?u.trim():null,ha_entity_id:s==="homeassistant"?v:null,ha_power_entity:s==="homeassistant"&&he||null,ha_energy_today_entity:s==="homeassistant"&&Y||null,ha_energy_total_entity:s==="homeassistant"&&le||null,mqtt_power_topic:s==="mqtt"&&g.trim()||null,mqtt_power_path:s==="mqtt"&&N.trim()||null,mqtt_power_multiplier:s==="mqtt"&&parseFloat(C)||1,mqtt_energy_topic:s==="mqtt"&&k.trim()||null,mqtt_energy_path:s==="mqtt"&&P.trim()||null,mqtt_energy_multiplier:s==="mqtt"&&parseFloat(H)||1,mqtt_state_topic:s==="mqtt"&&G.trim()||null,mqtt_state_path:s==="mqtt"&&ee.trim()||null,mqtt_state_on_value:s==="mqtt"&&X.trim()||null,username:s==="tasmota"&&m.trim()||null,password:s==="tasmota"&&f.trim()||null,printer_id:pe,power_alert_enabled:Ee,power_alert_high:Ae?parseFloat(Ae):null,power_alert_low:je?parseFloat(je):null,schedule_enabled:ce,schedule_on_time:Ce||null,schedule_off_time:$e||null,show_in_switchbar:De,show_on_printer_card:it};a?se.mutate(dt):ot.mutate(dt)},Ye=ot.isPending||se.isPending;return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:i.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:Me=>Me.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary flex-shrink-0",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:n(a?"smartPlugs.editTitle":"smartPlugs.addTitle")}),i.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:Ke,className:"p-6 space-y-4 overflow-y-auto",children:[Le&&i.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:Le}),!a&&i.jsxs("div",{className:"flex gap-2 mb-2",children:[i.jsxs("button",{type:"button",onClick:()=>{o("tasmota"),Se(null),qe(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${s==="tasmota"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[i.jsx(Dl,{className:"w-4 h-4"}),"Tasmota"]}),i.jsxs("button",{type:"button",onClick:()=>{o("homeassistant"),Se(null),qe(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${s==="homeassistant"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[i.jsx(hw,{className:"w-4 h-4"}),"HA"]}),i.jsxs("button",{type:"button",onClick:()=>{o("mqtt"),Se(null),qe(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${s==="mqtt"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[i.jsx(HL,{className:"w-4 h-4"}),"MQTT"]})]}),!a&&s==="tasmota"&&i.jsxs("div",{className:"space-y-3",children:[Nt?i.jsxs(Oe,{type:"button",variant:"secondary",onClick:ut,className:"w-full",children:[i.jsx(Ht,{className:"w-4 h-4"}),n("smartPlugs.stopScanning")]}):i.jsxs(Oe,{type:"button",variant:"primary",onClick:tt,className:"w-full",children:[i.jsx(jr,{className:"w-4 h-4"}),n("smartPlugs.discoverTasmota")]}),Nt&&We.total>0&&i.jsxs("div",{className:"space-y-1",children:[i.jsxs("div",{className:"flex justify-between text-xs text-bambu-gray",children:[i.jsx("span",{children:n("smartPlugs.addSmartPlug.scanningNetwork")}),i.jsxs("span",{children:[We.scanned," / ",We.total]})]}),i.jsx("div",{className:"w-full bg-bambu-dark-tertiary rounded-full h-2",children:i.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${We.scanned/We.total*100}%`}})})]}),wt.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.foundDevices",{count:wt.length})}),i.jsx("div",{className:"max-h-40 overflow-y-auto space-y-1",children:wt.map(Me=>i.jsxs("button",{type:"button",onClick:()=>Ze(Me),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:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Dl,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:Me.name}),i.jsx("p",{className:"text-xs text-bambu-gray",children:Me.ip_address})]})]}),Me.state&&i.jsxs("span",{className:`flex items-center gap-1 text-xs ${Me.state==="ON"?"text-bambu-green":"text-bambu-gray"}`,children:[i.jsx(Vd,{className:"w-3 h-3"}),Me.state]})]},Me.ip_address))})]}),!Nt&&wt.length===0&&We.total>0&&i.jsx("p",{className:"text-xs text-bambu-gray text-center py-2",children:n("smartPlugs.noDevicesFound")})]}),s==="homeassistant"&&i.jsxs("div",{className:"space-y-3",children:[!Qt&&i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"p-3 bg-yellow-500/20 border border-yellow-500/50 rounded-lg text-sm text-yellow-400",children:[n("smartPlugs.haNotConfigured")," ",i.jsx("span",{className:"font-medium",children:n("smartPlugs.haSettingsPath")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1 opacity-50",children:n("smartPlugs.selectEntity")}),i.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:i.jsx("option",{children:n("smartPlugs.addSmartPlug.chooseEntity")})})]})]}),Qt&&i.jsxs(i.Fragment,{children:[jn&&i.jsxs("div",{className:"flex items-center justify-center py-4 text-bambu-gray",children:[i.jsx(ht,{className:"w-5 h-5 animate-spin mr-2"}),n("smartPlugs.loadingEntities")]}),kn&&i.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:n("smartPlugs.failedToLoadEntities",{error:kn.message})}),(()=>{const Me=Xt?.filter(nt=>nt.ha_entity_id&&nt.id!==t?.id).map(nt=>nt.ha_entity_id)||[],dt=(hn||[]).filter(nt=>!Me.includes(nt.entity_id)),ct=hn?.find(nt=>nt.entity_id===v);return i.jsxs("div",{ref:K,className:"relative",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.selectEntity")}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),i.jsx("input",{type:"text",value:E?Pe:ct?`${ct.friendly_name} (${ct.entity_id})`:"",onChange:nt=>{q(nt.target.value),E||U(!0)},onFocus:()=>{U(!0),q("")},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"}),v&&!E&&i.jsx("button",{type:"button",onClick:()=>{x(""),q("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(Ht,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),jn&&i.jsx(ht,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray animate-spin"})]}),E&&i.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:[jn&&i.jsxs("div",{className:"px-3 py-2 text-sm text-bambu-gray flex items-center gap-2",children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),n("smartPlugs.loading")]}),!jn&&dt.length===0&&i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:Z?n("smartPlugs.noEntitiesMatching",{search:Z}):n("smartPlugs.noEntitiesAvailable")}),!jn&&dt.map(nt=>i.jsxs("button",{type:"button",onClick:()=>{x(nt.entity_id),U(!1),q(""),l||c(nt.friendly_name)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary transition-colors ${nt.entity_id===v?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[i.jsx("div",{className:"font-medium",children:nt.friendly_name}),i.jsxs("div",{className:"text-xs text-bambu-gray flex items-center justify-between",children:[i.jsx("span",{children:nt.entity_id}),i.jsx("span",{className:nt.state==="on"?"text-bambu-green":"",children:nt.state})]})]},nt.entity_id))]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:Z?n("smartPlugs.searchingEntities",{count:dt.length}):n("smartPlugs.showingEntities",{count:dt.length})})]})})(),v&&Fe&&Fe.length>0&&i.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4 space-y-3",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white font-medium mb-1",children:n("smartPlugs.energyMonitoringOptional")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:n("smartPlugs.energyMonitoringHint")})]}),(()=>{const Me=Fe.filter(nt=>nt.unit_of_measurement==="W"||nt.unit_of_measurement==="kW"||nt.unit_of_measurement==="mW"),dt=$?Me.filter(nt=>nt.entity_id.toLowerCase().includes($.toLowerCase())||nt.friendly_name.toLowerCase().includes($.toLowerCase())):Me,ct=Fe.find(nt=>nt.entity_id===he);return i.jsxs("div",{ref:J,className:"relative",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.powerSensorW")}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),i.jsx("input",{type:"text",value:O?$:ct?`${ct.friendly_name} (${ct.state} ${ct.unit_of_measurement})`:"",onChange:nt=>{ne(nt.target.value),O||V(!0)},onFocus:()=>{V(!0),ne("")},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"}),he&&!O&&i.jsx("button",{type:"button",onClick:()=>{ge(""),ne("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(Ht,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),O&&i.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:[i.jsx("button",{type:"button",onClick:()=>{ge(""),V(!1),ne("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:n("smartPlugs.none")}),dt.map(nt=>i.jsxs("button",{type:"button",onClick:()=>{ge(nt.entity_id),V(!1),ne("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${nt.entity_id===he?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[i.jsx("div",{className:"font-medium",children:nt.friendly_name}),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[nt.entity_id," • ",nt.state," ",nt.unit_of_measurement]})]},nt.entity_id)),dt.length===0&&i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:n("smartPlugs.noMatchingSensors")})]})]})})(),(()=>{const Me=Fe.filter(nt=>nt.unit_of_measurement==="kWh"||nt.unit_of_measurement==="Wh"||nt.unit_of_measurement==="MWh"),dt=W?Me.filter(nt=>nt.entity_id.toLowerCase().includes(W.toLowerCase())||nt.friendly_name.toLowerCase().includes(W.toLowerCase())):Me,ct=Fe.find(nt=>nt.entity_id===Y);return i.jsxs("div",{ref:ye,className:"relative",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.energyTodayKwh")}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),i.jsx("input",{type:"text",value:ue?W:ct?`${ct.friendly_name} (${ct.state} ${ct.unit_of_measurement})`:"",onChange:nt=>{re(nt.target.value),ue||fe(!0)},onFocus:()=>{fe(!0),re("")},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"}),Y&&!ue&&i.jsx("button",{type:"button",onClick:()=>{oe(""),re("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(Ht,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),ue&&i.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:[i.jsx("button",{type:"button",onClick:()=>{oe(""),fe(!1),re("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:n("smartPlugs.none")}),dt.map(nt=>i.jsxs("button",{type:"button",onClick:()=>{oe(nt.entity_id),fe(!1),re("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${nt.entity_id===Y?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[i.jsx("div",{className:"font-medium",children:nt.friendly_name}),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[nt.entity_id," • ",nt.state," ",nt.unit_of_measurement]})]},nt.entity_id)),dt.length===0&&i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:n("smartPlugs.noMatchingSensors")})]})]})})(),(()=>{const Me=Fe.filter(nt=>nt.unit_of_measurement==="kWh"||nt.unit_of_measurement==="Wh"||nt.unit_of_measurement==="MWh"),dt=ae?Me.filter(nt=>nt.entity_id.toLowerCase().includes(ae.toLowerCase())||nt.friendly_name.toLowerCase().includes(ae.toLowerCase())):Me,ct=Fe.find(nt=>nt.entity_id===le);return i.jsxs("div",{ref:ve,className:"relative",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.totalEnergyKwh")}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),i.jsx("input",{type:"text",value:F?ae:ct?`${ct.friendly_name} (${ct.state} ${ct.unit_of_measurement})`:"",onChange:nt=>{L(nt.target.value),F||te(!0)},onFocus:()=>{te(!0),L("")},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&&!F&&i.jsx("button",{type:"button",onClick:()=>{xe(""),L("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(Ht,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),F&&i.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:[i.jsx("button",{type:"button",onClick:()=>{xe(""),te(!1),L("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:n("smartPlugs.none")}),dt.map(nt=>i.jsxs("button",{type:"button",onClick:()=>{xe(nt.entity_id),te(!1),L("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${nt.entity_id===le?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[i.jsx("div",{className:"font-medium",children:nt.friendly_name}),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[nt.entity_id," • ",nt.state," ",nt.unit_of_measurement]})]},nt.entity_id)),dt.length===0&&i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:n("smartPlugs.noMatchingSensors")})]})]})})()]})]})]}),s==="mqtt"&&i.jsxs("div",{className:"space-y-3",children:[!Qe?.mqtt_broker&&i.jsxs("div",{className:"p-3 bg-yellow-500/20 border border-yellow-500/50 rounded-lg text-sm text-yellow-400",children:[n("smartPlugs.mqttNotConfigured")," ",i.jsx("span",{className:"font-medium",children:n("smartPlugs.mqttSettingsPath")})," ",n("smartPlugs.mqttNotConfiguredSuffix")]}),Qe?.mqtt_broker&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg text-sm text-blue-300",children:[i.jsx("p",{className:"font-medium mb-1",children:n("smartPlugs.monitorOnly")}),i.jsx("p",{className:"text-xs opacity-80",children:n("smartPlugs.mqttMonitorOnlyDescription")})]}),i.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-white font-medium text-sm",children:n("smartPlugs.powerMonitoring")}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.topic")}),i.jsx("input",{type:"text",value:g,onChange:Me=>_(Me.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"})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.jsonPath")}),i.jsx("input",{type:"text",value:N,onChange:Me=>T(Me.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.multiplier")}),i.jsx("input",{type:"text",value:C,onChange:Me=>A(Me.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"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",style:{whiteSpace:"pre-line"},children:n("smartPlugs.mqttPowerHint")})]}),i.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("p",{className:"text-white font-medium text-sm",children:[n("smartPlugs.energyMonitoring")," ",i.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",n("smartPlugs.optional"),")"]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.topic")}),i.jsx("input",{type:"text",value:k,onChange:Me=>R(Me.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"})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.jsonPath")}),i.jsx("input",{type:"text",value:P,onChange:Me=>D(Me.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.multiplier")}),i.jsx("input",{type:"text",value:H,onChange:Me=>z(Me.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"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",style:{whiteSpace:"pre-line"},children:n("smartPlugs.mqttEnergyHint")})]}),i.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("p",{className:"text-white font-medium text-sm",children:[n("smartPlugs.stateMonitoring")," ",i.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",n("smartPlugs.optional"),")"]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.topic")}),i.jsx("input",{type:"text",value:G,onChange:Me=>I(Me.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"})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.jsonPath")}),i.jsx("input",{type:"text",value:ee,onChange:Me=>ie(Me.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.onValue")}),i.jsx("input",{type:"text",value:X,onChange:Me=>me(Me.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"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",style:{whiteSpace:"pre-line"},children:n("smartPlugs.mqttStateHint")})]})]})]}),s==="tasmota"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.ipAddress")}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"text",value:u,onChange:Me=>{d(Me.target.value),Se(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"}),i.jsxs(Oe,{type:"button",variant:"secondary",onClick:()=>ke.mutate(),disabled:!u.trim()||ke.isPending,children:[ke.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Ub,{className:"w-4 h-4"}),n("smartPlugs.test")]})]})]}),s==="tasmota"&&Ne&&i.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${Ne.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:Ne.success?i.jsxs(i.Fragment,{children:[i.jsx(fr,{className:"w-5 h-5"}),i.jsxs("div",{children:[i.jsx("p",{className:"font-medium",children:n("smartPlugs.connectedResult")}),i.jsxs("p",{className:"text-sm opacity-80",children:[Ne.device_name&&n("smartPlugs.deviceLabel",{name:Ne.device_name}),n("smartPlugs.stateLabel",{state:Ne.state})]})]})]}):i.jsxs(i.Fragment,{children:[i.jsx(Ph,{className:"w-5 h-5"}),i.jsx("span",{children:n("smartPlugs.addSmartPlug.connectionFailed")})]})}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.nameLabel")}),i.jsx("input",{type:"text",value:l,onChange:Me=>c(Me.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"})]}),s==="tasmota"&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.username")}),i.jsx("input",{type:"text",value:m,onChange:Me=>p(Me.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.password")}),i.jsx("input",{type:"password",value:f,onChange:Me=>y(Me.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"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray -mt-2",children:n("smartPlugs.authHint")})]}),s!=="mqtt"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.linkToPrinter")}),i.jsxs("select",{value:pe??"",onChange:Me=>de(Me.target.value?Number(Me.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:[i.jsx("option",{value:"",children:n("smartPlugs.noPrinter")}),He?.map(Me=>i.jsx("option",{value:Me.id,children:Me.name},Me.id))]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("smartPlugs.linkingDescription")})]}),i.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(hh,{className:"w-4 h-4 text-bambu-green"}),i.jsx("span",{className:"text-white font-medium",children:n("smartPlugs.powerAlerts")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:Ee,onChange:Me=>Te(Me.target.checked),className:"sr-only peer"}),i.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"})]})]}),Ee&&i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.alertAbove")}),i.jsx("input",{type:"number",value:Ae,onChange:Me=>Be(Me.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.alertBelow")}),i.jsx("input",{type:"number",value:je,onChange:Me=>Xe(Me.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"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.alertDescription")})]})]}),s!=="mqtt"&&i.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(er,{className:"w-4 h-4 text-bambu-green"}),i.jsx("span",{className:"text-white font-medium",children:n("smartPlugs.dailySchedule")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:ce,onChange:Me=>Ie(Me.target.checked),className:"sr-only peer"}),i.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"})]})]}),ce&&i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.turnOnAt")}),i.jsx("input",{type:"time",value:Ce,onChange:Me=>Ge(Me.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.turnOffAt")}),i.jsx("input",{type:"time",value:$e,onChange:Me=>Ue(Me.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"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.scheduleDescription")})]})]}),i.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(pw,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white font-medium",children:n("smartPlugs.showInSwitchbar")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.quickAccessSidebar")})]})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:De,onChange:Me=>Ve(Me.target.checked),className:"sr-only peer"}),i.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"})]})]})}),s==="homeassistant"&&i.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(_c,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white font-medium",children:n("smartPlugs.showOnPrinterCard")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.displayOnPrinterCard")})]})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:it,onChange:Me=>xt(Me.target.checked),className:"sr-only peer"}),i.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.jsxs("div",{className:"flex gap-3 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:n("smartPlugs.cancel")}),i.jsxs(Oe,{type:"submit",disabled:Ye,className:"flex-1",children:[Ye?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(ts,{className:"w-4 h-4"}),n(a?"smartPlugs.save":"smartPlugs.add")]})]})]})]})})}function Bn({checked:t,onChange:e,disabled:n}){const r=a=>{a.preventDefault(),a.stopPropagation(),n||e(!t)};return i.jsx("button",{type:"button",role:"switch","aria-checked":t,disabled:n,onClick:r,className:`relative inline-flex w-11 h-7 md:w-9 md:h-5 rounded-full transition-colors flex-shrink-0 focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${n?"bg-bambu-dark-tertiary/50 cursor-not-allowed opacity-50":t?"bg-bambu-green cursor-pointer":"bg-bambu-dark-tertiary cursor-pointer hover:bg-bambu-dark-tertiary/80"}`,children:i.jsx("span",{className:`pointer-events-none absolute top-[3px] md:top-[2px] left-[3px] md:left-[2px] w-5 h-5 md:w-4 md:h-4 bg-white rounded-full shadow transition-transform duration-200 ease-in-out ${t?"translate-x-4":"translate-x-0"}`})})}function met({provider:t,onEdit:e}){const{t:n}=Ft(),r=an(),[a,s]=w.useState(!1),[o,l]=w.useState(!1),[c,u]=w.useState(null),{data:d}=et({queryKey:["printers"],queryFn:be.getPrinters}),m=d?.find(x=>x.id===t.printer_id),p=pt({mutationFn:x=>be.updateNotificationProvider(t.id,x),onSuccess:()=>{r.invalidateQueries({queryKey:["notification-providers"]})}}),f=pt({mutationFn:()=>be.deleteNotificationProvider(t.id),onSuccess:()=>{r.invalidateQueries({queryKey:["notification-providers"]})}}),y=pt({mutationFn:()=>be.testNotificationProvider(t.id),onSuccess:x=>{u(x),r.invalidateQueries({queryKey:["notification-providers"]})},onError:x=>{u({success:!1,message:x.message})}}),v=x=>x||"";return i.jsxs(i.Fragment,{children:[i.jsx(Mt,{className:"relative",children:i.jsxs(Dt,{className:"p-4",children:[i.jsxs("div",{className:"flex items-start justify-between mb-3",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:`p-2 rounded-lg ${t.enabled?"bg-bambu-green/20":"bg-bambu-dark"}`,children:i.jsx(hh,{className:`w-5 h-5 ${t.enabled?"text-bambu-green":"text-bambu-gray"}`})}),i.jsxs("div",{children:[i.jsx("h3",{className:"font-medium text-white",children:t.name}),i.jsx("p",{className:"text-sm text-bambu-gray",children:n(`notifications.providerTypes.${t.provider_type}`,t.provider_type)})]})]}),i.jsxs("div",{className:"flex items-center gap-3",children:[t.last_success&&i.jsx("span",{className:"text-xs text-status-ok hidden sm:inline",children:n("notifications.lastSuccess",{date:_f(t.last_success)})}),t.last_error&&t.last_error_at&&(!t.last_success||(Jn(t.last_error_at)?.getTime()||0)>(Jn(t.last_success)?.getTime()||0))&&i.jsx("span",{className:"text-xs text-status-error",title:t.last_error,children:n("notifications.error")}),i.jsx(Bn,{checked:t.enabled,onChange:x=>p.mutate({enabled:x})})]})]}),m&&i.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[i.jsxs("span",{className:"text-xs text-bambu-gray",children:[n("notifications.printer")," "]}),i.jsx("span",{className:"text-sm text-white",children:m.name})]}),!m&&!t.printer_id&&i.jsx("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:i.jsx("span",{className:"text-xs text-bambu-gray",children:n("notifications.allPrinters")})}),i.jsxs("div",{className:"mb-3 flex flex-wrap gap-1",children:[t.on_print_start&&i.jsx("span",{className:"px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded",children:n("notifications.start")}),t.on_plate_not_empty&&i.jsx("span",{className:"px-2 py-0.5 bg-rose-600/20 text-rose-300 text-xs rounded",children:n("notifications.plateCheck")}),t.on_print_complete&&i.jsx("span",{className:"px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded",children:n("notifications.complete")}),t.on_print_failed&&i.jsx("span",{className:"px-2 py-0.5 bg-red-500/20 text-red-400 text-xs rounded",children:n("notifications.failed")}),t.on_print_stopped&&i.jsx("span",{className:"px-2 py-0.5 bg-orange-500/20 text-orange-400 text-xs rounded",children:n("notifications.stopped")}),t.on_print_progress&&i.jsx("span",{className:"px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded",children:n("notifications.progress")}),t.on_printer_offline&&i.jsx("span",{className:"px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded",children:n("notifications.offline")}),t.on_printer_error&&i.jsx("span",{className:"px-2 py-0.5 bg-rose-500/20 text-rose-400 text-xs rounded",children:n("notifications.error")}),t.on_filament_low&&i.jsx("span",{className:"px-2 py-0.5 bg-cyan-500/20 text-cyan-400 text-xs rounded",children:n("notifications.lowFilament")}),t.on_maintenance_due&&i.jsx("span",{className:"px-2 py-0.5 bg-purple-500/20 text-purple-400 text-xs rounded",children:n("notifications.maintenance")}),t.on_ams_humidity_high&&i.jsx("span",{className:"px-2 py-0.5 bg-blue-600/20 text-blue-300 text-xs rounded",children:n("notifications.amsHumidity")}),t.on_ams_temperature_high&&i.jsx("span",{className:"px-2 py-0.5 bg-orange-600/20 text-orange-300 text-xs rounded",children:n("notifications.amsTemp")}),t.on_ams_ht_humidity_high&&i.jsx("span",{className:"px-2 py-0.5 bg-cyan-600/20 text-cyan-300 text-xs rounded",children:n("notifications.amsHtHumidity")}),t.on_ams_ht_temperature_high&&i.jsx("span",{className:"px-2 py-0.5 bg-amber-600/20 text-amber-300 text-xs rounded",children:n("notifications.amsHtTemp")}),t.on_bed_cooled&&i.jsx("span",{className:"px-2 py-0.5 bg-teal-500/20 text-teal-400 text-xs rounded",children:n("notifications.bedCooled")}),t.on_first_layer_complete&&i.jsx("span",{className:"px-2 py-0.5 bg-emerald-600/20 text-emerald-300 text-xs rounded",children:n("notifications.firstLayer")}),t.quiet_hours_enabled&&i.jsxs("span",{className:"px-2 py-0.5 bg-indigo-500/20 text-indigo-400 text-xs rounded flex items-center gap-1",children:[i.jsx(DN,{className:"w-3 h-3"}),n("notifications.quiet")]}),t.daily_digest_enabled&&i.jsxs("span",{className:"px-2 py-0.5 bg-emerald-500/20 text-emerald-400 text-xs rounded flex items-center gap-1",children:[i.jsx(Wr,{className:"w-3 h-3"}),n("notifications.digest",{time:t.daily_digest_time})]})]}),i.jsx("div",{className:"mb-3",children:i.jsxs(Oe,{size:"sm",variant:"secondary",disabled:y.isPending,onClick:()=>{u(null),y.mutate()},className:"w-full",children:[y.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(rT,{className:"w-4 h-4"}),n("notifications.sendTestNotification")]})}),c&&i.jsxs("div",{className:`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${c.success?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:[c.success?i.jsx(fr,{className:"w-4 h-4"}):i.jsx(Vi,{className:"w-4 h-4"}),i.jsx("span",{children:c.message})]}),i.jsxs("button",{onClick:()=>l(!o),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors border-t border-bambu-dark-tertiary",children:[i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(jd,{className:"w-4 h-4"}),n("notifications.eventSettings")]}),o?i.jsx(Il,{className:"w-4 h-4"}):i.jsx(Ln,{className:"w-4 h-4"})]}),o&&i.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.enabled")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.sendFromProvider")})]}),i.jsx(Bn,{checked:t.enabled,onChange:x=>p.mutate({enabled:x})})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.printEvents")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.printStarted")}),i.jsx(Bn,{checked:t.on_print_start,onChange:x=>p.mutate({on_print_start:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.plateNotEmpty")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.plateNotEmptyDescription")})]}),i.jsx(Bn,{checked:t.on_plate_not_empty??!0,onChange:x=>p.mutate({on_plate_not_empty:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.printCompleted")}),i.jsx(Bn,{checked:t.on_print_complete,onChange:x=>p.mutate({on_print_complete:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.bedCooledLabel")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.bedCooledDescription")})]}),i.jsx(Bn,{checked:t.on_bed_cooled??!1,onChange:x=>p.mutate({on_bed_cooled:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.firstLayerCompleteLabel")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.firstLayerCompleteDescription")})]}),i.jsx(Bn,{checked:t.on_first_layer_complete??!1,onChange:x=>p.mutate({on_first_layer_complete:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.printFailed")}),i.jsx(Bn,{checked:t.on_print_failed,onChange:x=>p.mutate({on_print_failed:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.printStopped")}),i.jsx(Bn,{checked:t.on_print_stopped,onChange:x=>p.mutate({on_print_stopped:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.progressMilestones")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.progressMilestonesDescription")})]}),i.jsx(Bn,{checked:t.on_print_progress,onChange:x=>p.mutate({on_print_progress:x})})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.printerStatus")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.printerOffline")}),i.jsx(Bn,{checked:t.on_printer_offline,onChange:x=>p.mutate({on_printer_offline:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.printerError")}),i.jsx(Bn,{checked:t.on_printer_error,onChange:x=>p.mutate({on_printer_error:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.lowFilamentLabel")}),i.jsx(Bn,{checked:t.on_filament_low,onChange:x=>p.mutate({on_filament_low:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.maintenanceDue")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.maintenanceDueDescription")})]}),i.jsx(Bn,{checked:t.on_maintenance_due??!1,onChange:x=>p.mutate({on_maintenance_due:x})})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.amsAlarms")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.amsHumidityHigh")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.amsHumidityHighDescription")})]}),i.jsx(Bn,{checked:t.on_ams_humidity_high??!1,onChange:x=>p.mutate({on_ams_humidity_high:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.amsTemperatureHigh")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.amsTemperatureHighDescription")})]}),i.jsx(Bn,{checked:t.on_ams_temperature_high??!1,onChange:x=>p.mutate({on_ams_temperature_high:x})})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.amsHtAlarms")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.amsHtHumidityHigh")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.amsHtHumidityHighDescription")})]}),i.jsx(Bn,{checked:t.on_ams_ht_humidity_high??!1,onChange:x=>p.mutate({on_ams_ht_humidity_high:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.amsHtTemperatureHigh")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.amsHtTemperatureHighDescription")})]}),i.jsx(Bn,{checked:t.on_ams_ht_temperature_high??!1,onChange:x=>p.mutate({on_ams_ht_temperature_high:x})})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.printQueue")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.jobAdded")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobAddedDescription")})]}),i.jsx(Bn,{checked:t.on_queue_job_added??!1,onChange:x=>p.mutate({on_queue_job_added:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.jobAssigned")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobAssignedDescription")})]}),i.jsx(Bn,{checked:t.on_queue_job_assigned??!1,onChange:x=>p.mutate({on_queue_job_assigned:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.jobStarted")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobStartedDescription")})]}),i.jsx(Bn,{checked:t.on_queue_job_started??!1,onChange:x=>p.mutate({on_queue_job_started:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.jobWaiting")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobWaitingDescription")})]}),i.jsx(Bn,{checked:t.on_queue_job_waiting??!0,onChange:x=>p.mutate({on_queue_job_waiting:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.jobSkipped")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobSkippedDescription")})]}),i.jsx(Bn,{checked:t.on_queue_job_skipped??!0,onChange:x=>p.mutate({on_queue_job_skipped:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.jobFailed")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobFailedDescription")})]}),i.jsx(Bn,{checked:t.on_queue_job_failed??!0,onChange:x=>p.mutate({on_queue_job_failed:x})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.queueComplete")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.queueCompleteDescription")})]}),i.jsx(Bn,{checked:t.on_queue_completed??!1,onChange:x=>p.mutate({on_queue_completed:x})})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(DN,{className:"w-4 h-4 text-purple-400"}),i.jsx("p",{className:"text-sm text-white",children:n("notifications.quietHours")})]}),i.jsx(Bn,{checked:t.quiet_hours_enabled,onChange:x=>p.mutate({quiet_hours_enabled:x})})]}),t.quiet_hours_enabled&&i.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.noNotificationsDuring")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(er,{className:"w-4 h-4 text-bambu-gray"}),i.jsxs("span",{className:"text-sm text-white",children:[v(t.quiet_hours_start)||"22:00"," - ",v(t.quiet_hours_end)||"07:00"]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.editProviderToChangeQuietHours")})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Wr,{className:"w-4 h-4 text-emerald-400"}),i.jsx("p",{className:"text-sm text-white",children:n("notifications.dailyDigest")})]}),i.jsx(Bn,{checked:t.daily_digest_enabled,onChange:x=>p.mutate({daily_digest_enabled:x})})]}),t.daily_digest_enabled&&i.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.batchNotifications")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(er,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"text-sm text-white",children:n("notifications.sendAt",{time:v(t.daily_digest_time)||"08:00"})})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.editProviderToChangeDigestTime")})]})]}),i.jsxs("div",{className:"flex gap-2 pt-2",children:[i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[i.jsx(nh,{className:"w-4 h-4"}),n("notifications.edit")]}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:()=>s(!0),className:"text-red-400 hover:text-red-300",children:i.jsx(Jt,{className:"w-4 h-4"})})]})]})]})}),a&&i.jsx(Sn,{title:n("notifications.deleteProvider"),message:n("notifications.deleteConfirm",{name:t.name}),confirmText:n("notifications.delete"),variant:"danger",onConfirm:()=>{f.mutate(),s(!1)},onCancel:()=>s(!1)})]})}const het=["email","telegram","discord","ntfy","pushover","callmebot","webhook","homeassistant"];function pet({provider:t,onClose:e}){const{t:n}=Ft(),r=an(),a=!!t,[s,o]=w.useState(t?.name||""),[l,c]=w.useState(t?.provider_type||"email"),[u,d]=w.useState(t?.printer_id||null),[m,p]=w.useState(t?.quiet_hours_enabled||!1),[f,y]=w.useState(t?.quiet_hours_start||"22:00"),[v,x]=w.useState(t?.quiet_hours_end||"07:00"),[g,_]=w.useState(t?.daily_digest_enabled||!1),[N,T]=w.useState(t?.daily_digest_time||"08:00"),[C,A]=w.useState(t?.on_print_start??!1),[k,R]=w.useState(t?.on_print_complete??!0),[P,D]=w.useState(t?.on_print_failed??!0),[H,z]=w.useState(t?.on_print_stopped??!0),[G,I]=w.useState(t?.on_print_progress??!1),[ee,ie]=w.useState(t?.on_printer_offline??!1),[X,me]=w.useState(t?.on_printer_error??!1),[he,ge]=w.useState(t?.on_filament_low??!1),[Y,oe]=w.useState(t?.on_maintenance_due??!1),[le,xe]=w.useState(t?.on_bed_cooled??!1),[Pe,q]=w.useState(t?.on_first_layer_complete??!1),[Z,j]=w.useState(t?.config?Object.fromEntries(Object.entries(t.config).map(([ae,L])=>[ae,String(L)])):{}),[E,U]=w.useState(null),[K,$]=w.useState(null),{data:ne}=et({queryKey:["printers"],queryFn:be.getPrinters});w.useEffect(()=>{const ae=L=>{L.key==="Escape"&&e()};return window.addEventListener("keydown",ae),()=>window.removeEventListener("keydown",ae)},[e]);const O=pt({mutationFn:()=>be.testNotificationConfig({provider_type:l,config:Z}),onSuccess:ae=>{U(ae),$(null)},onError:ae=>{U({success:!1,message:ae.message})}}),V=pt({mutationFn:ae=>be.createNotificationProvider(ae),onSuccess:()=>{r.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:ae=>{$(ae.message)}}),J=pt({mutationFn:ae=>be.updateNotificationProvider(t.id,ae),onSuccess:()=>{r.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:ae=>{$(ae.message)}}),W=ae=>{if(ae.preventDefault(),$(null),!s.trim()){$(n("notifications.nameRequired"));return}const L=fe(l);for(const te of L)if(!Z[te.key]?.trim()){$(n("notifications.fieldRequired",{field:te.label}));return}const F={name:s.trim(),provider_type:l,config:Z,printer_id:u,quiet_hours_enabled:m,quiet_hours_start:m?f:null,quiet_hours_end:m?v:null,daily_digest_enabled:g,daily_digest_time:g?N:null,on_print_start:C,on_print_complete:k,on_print_failed:P,on_print_stopped:H,on_print_progress:G,on_printer_offline:ee,on_printer_error:X,on_filament_low:he,on_maintenance_due:Y,on_bed_cooled:le,on_first_layer_complete:Pe};a?J.mutate(F):V.mutate(F)},re=V.isPending||J.isPending,ue=ae=>{switch(ae){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}];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}];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:L=>L.payload_format!=="slack"},{key:"field_message",label:"Message Field Name",placeholder:"message",type:"text",required:!1,showIf:L=>L.payload_format!=="slack"}];case"homeassistant":return[];default:return[]}},fe=ae=>ue(ae).filter(L=>L.required),ye=ue(l);return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto",onClick:e,children:i.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:ae=>ae.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:n(a?"notifications.editTitle":"notifications.addTitle")}),i.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:W,className:"p-6 space-y-4",children:[K&&i.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:K}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("notifications.nameLabel")}),i.jsx("input",{type:"text",value:s,onChange:ae=>o(ae.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("notifications.providerTypeLabel")}),i.jsx("select",{value:l,onChange:ae=>{c(ae.target.value),j({}),U(null)},disabled:a,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:het.map(ae=>i.jsx("option",{value:ae,children:n(`notifications.providerTypes.${ae}`,ae)},ae))}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n(`notifications.providerDescriptions.${l}`,"")})]}),i.jsxs("div",{className:"space-y-3",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:n("notifications.configuration")}),ye.filter(ae=>!("showIf"in ae)||ae.showIf?.(Z)!==!1).map(ae=>i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[ae.label," ",ae.required&&"*"]}),ae.type==="select"&&"options"in ae&&ae.options?i.jsx("select",{value:Z[ae.key]||ae.options[0]?.value||"",onChange:L=>{j({...Z,[ae.key]:L.target.value}),U(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:ae.options.map(L=>i.jsx("option",{value:L.value,children:L.label},L.value))}):i.jsx("input",{type:ae.type,value:Z[ae.key]||"",onChange:L=>{j({...Z,[ae.key]:L.target.value}),U(null)},placeholder:ae.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"})]},ae.key))]}),i.jsx("div",{className:"flex gap-2",children:i.jsxs(Oe,{type:"button",variant:"secondary",onClick:()=>{U(null),O.mutate()},disabled:O.isPending||fe(l).length>0&&!Z[fe(l)[0]?.key],className:"flex-1",children:[O.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(rT,{className:"w-4 h-4"}),n("notifications.testConfiguration")]})}),E&&i.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${E.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:E.success?i.jsxs(i.Fragment,{children:[i.jsx(fr,{className:"w-5 h-5"}),i.jsx("span",{children:E.message})]}):i.jsxs(i.Fragment,{children:[i.jsx(Vi,{className:"w-5 h-5"}),i.jsx("span",{children:E.message})]})}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("notifications.printerFilter")}),i.jsxs("select",{value:u??"",onChange:ae=>d(ae.target.value?Number(ae.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:[i.jsx("option",{value:"",children:n("notifications.allPrinters")}),ne?.map(ae=>i.jsx("option",{value:ae.id,children:ae.name},ae.id))]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("notifications.onlyFromPrinter")})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("label",{className:"text-sm text-white",children:n("notifications.quietHoursDnd")}),i.jsx(Bn,{checked:m,onChange:p})]}),m&&i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("notifications.quietStart")}),i.jsx("input",{type:"time",value:f,onChange:ae=>y(ae.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("notifications.quietEnd")}),i.jsx("input",{type:"time",value:v,onChange:ae=>x(ae.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"})]})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("label",{className:"text-sm text-white",children:n("notifications.dailyDigestLabel")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.batchNotifications")})]}),i.jsx(Bn,{checked:g,onChange:_})]}),g&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("notifications.sendDigestAt")}),i.jsx("input",{type:"time",value:N,onChange:ae=>T(ae.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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("notifications.digestCollected")})]})]}),i.jsxs("div",{className:"space-y-3",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:n("notifications.notificationEvents")}),i.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:n("notifications.printEvents")}),i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.start")}),i.jsx(Bn,{checked:C,onChange:A})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.complete")}),i.jsx(Bn,{checked:k,onChange:R})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.failed")}),i.jsx(Bn,{checked:P,onChange:D})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.stopped")}),i.jsx(Bn,{checked:H,onChange:z})]}),i.jsxs("div",{className:"flex items-center justify-between col-span-2",children:[i.jsxs("div",{children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.progress")}),i.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:n("notifications.progressPercent")})]}),i.jsx(Bn,{checked:G,onChange:I})]}),i.jsxs("div",{className:"flex items-center justify-between col-span-2",children:[i.jsxs("div",{children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.bedCooled")}),i.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:n("notifications.bedCooledAfterPrint")})]}),i.jsx(Bn,{checked:le,onChange:xe})]}),i.jsxs("div",{className:"flex items-center justify-between col-span-2",children:[i.jsxs("div",{children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.firstLayerCompleteLabel")}),i.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:n("notifications.firstLayerCompleteDescription")})]}),i.jsx(Bn,{checked:Pe,onChange:q})]})]})]}),i.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:n("notifications.printerStatus")}),i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.offline")}),i.jsx(Bn,{checked:ee,onChange:ie})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.error")}),i.jsx(Bn,{checked:X,onChange:me})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.lowFilament")}),i.jsx(Bn,{checked:he,onChange:ge})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.maintenance")}),i.jsx(Bn,{checked:Y,onChange:oe})]})]})]})]}),i.jsxs("div",{className:"flex gap-3 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:n("notifications.cancel")}),i.jsxs(Oe,{type:"submit",disabled:re,className:"flex-1",children:[re?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(ts,{className:"w-4 h-4"}),n(a?"notifications.save":"notifications.add")]})]})]})]})})}function fet({template:t,onClose:e}){const{t:n}=Ft(),r=an(),a=w.useRef(null),[s,o]=w.useState(t.title_template),[l,c]=w.useState(t.body_template),[u,d]=w.useState(null),[m,p]=w.useState(!0),{data:f}=et({queryKey:["template-variables"],queryFn:be.getTemplateVariables}),y=f?.find(A=>A.event_type===t.event_type),{data:v,isLoading:x}=et({queryKey:["template-preview",t.event_type,s,l],queryFn:()=>be.previewTemplate({event_type:t.event_type,title_template:s,body_template:l}),enabled:m&&s.length>0&&l.length>0});w.useEffect(()=>{const A=k=>{k.key==="Escape"&&e()};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[e]);const g=pt({mutationFn:A=>be.updateNotificationTemplate(t.id,A),onSuccess:()=>{r.invalidateQueries({queryKey:["notification-templates"]}),e()},onError:A=>{d(A.message)}}),_=pt({mutationFn:()=>be.resetNotificationTemplate(t.id),onSuccess:A=>{o(A.title_template),c(A.body_template),r.invalidateQueries({queryKey:["notification-templates"]})},onError:A=>{d(A.message)}}),N=A=>{if(A.preventDefault(),d(null),!s.trim()){d(n("notifications.titleRequired"));return}if(!l.trim()){d(n("notifications.bodyRequired"));return}g.mutate({title_template:s,body_template:l})},T=A=>{const k=a.current;if(!k)return;const R=k.selectionStart,P=k.selectionEnd,D=l,H=D.substring(0,R),z=D.substring(P),G=H+`{${A}}`+z;c(G),setTimeout(()=>{k.focus();const I=R+A.length+2;k.setSelectionRange(I,I)},0)},C=s!==t.title_template||l!==t.body_template;return i.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:n("notifications.editTemplate",{name:t.name})}),i.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",children:i.jsx(Ht,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsxs("form",{onSubmit:N,className:"flex-1 overflow-y-auto p-4 space-y-4",children:[u&&i.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded text-red-400 text-sm",children:u}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:n("notifications.titleLabel")}),i.jsx("input",{type:"text",value:s,onChange:A=>o(A.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")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:n("notifications.bodyLabel")}),i.jsx("textarea",{ref:a,value:l,onChange:A=>c(A.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&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-2",children:n("notifications.availableVariables")}),i.jsx("div",{className:"flex flex-wrap gap-2",children:y.variables.map(A=>i.jsxs("button",{type:"button",onClick:()=>T(A),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:[i.jsx(ar,{className:"w-3 h-3"}),A]},A))}),i.jsx("p",{className:"text-xs text-bambu-gray/60 mt-1",children:n("notifications.clickToInsert")})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("label",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[i.jsx(_c,{className:"w-4 h-4"}),n("notifications.livePreview")]}),i.jsx("button",{type:"button",onClick:()=>p(!m),className:"text-xs text-bambu-green hover:text-bambu-green-light",children:n(m?"notifications.hide":"notifications.show")})]}),m&&i.jsx("div",{className:"bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2",children:x?i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-sm",children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),n("notifications.loadingPreview")]}):v?i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:n("notifications.titlePreview")}),i.jsx("div",{className:"text-white font-medium",children:v.title})]}),i.jsxs("div",{children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:n("notifications.bodyPreview")}),i.jsx("div",{className:"text-white whitespace-pre-wrap text-sm",children:v.body})]})]}):i.jsx("div",{className:"text-bambu-gray text-sm",children:n("notifications.enterTemplateContent")})})]})]}),i.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[i.jsxs(Oe,{type:"button",variant:"ghost",onClick:()=>_.mutate(),disabled:_.isPending,className:"text-orange-400 hover:text-orange-300",children:[_.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin mr-2"}):i.jsx(bo,{className:"w-4 h-4 mr-2"}),n("notifications.resetToDefault")]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,children:n("notifications.cancel")}),i.jsxs(Oe,{onClick:N,disabled:g.isPending||!C,children:[g.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin mr-2"}):i.jsx(ts,{className:"w-4 h-4 mr-2"}),n("notifications.save")]})]})]})]})})}const get={print_start:"text-blue-400",print_complete:"text-bambu-green",print_failed:"text-red-400",print_stopped:"text-orange-400",print_progress:"text-yellow-400",printer_offline:"text-gray-400",printer_error:"text-rose-400",filament_low:"text-cyan-400",maintenance_due:"text-purple-400",test:"text-bambu-gray"};function bet({onClose:t}){const{t:e}=Ft(),n=an(),{showToast:r}=fn(),[a,s]=w.useState(7),[o,l]=w.useState(null),[c,u]=w.useState(!1),{data:d}=et({queryKey:["settings"],queryFn:be.getSettings}),m=d?.time_format||"system",{data:p,isLoading:f,refetch:y,isRefetching:v}=et({queryKey:["notification-logs",a,c],queryFn:()=>be.getNotificationLogs({days:a,limit:100,success:c?!1:void 0})}),{data:x}=et({queryKey:["notification-log-stats",a],queryFn:()=>be.getNotificationLogStats(a)}),g=pt({mutationFn:()=>be.clearNotificationLogs(30),onSuccess:N=>{r(N.message,"success"),n.invalidateQueries({queryKey:["notification-logs"]}),n.invalidateQueries({queryKey:["notification-log-stats"]})},onError:N=>{r(`Failed to clear logs: ${N.message}`,"error")}}),_=N=>{const T=Jn(N);if(!T)return"";const A=new Date().getTime()-T.getTime();return A<6e4?e("notifications.justNow"):A<36e5?`${Math.floor(A/6e4)}m ago`:A<864e5?`${Math.floor(A/36e5)}h ago`:T.toLocaleDateString()+" "+lQ(T,m)};return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:i.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:[i.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx(f0,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:e("notifications.notificationLog")})]}),i.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white transition-colors",children:"×"})]}),x&&i.jsx("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50",children:i.jsxs("div",{className:"flex items-center gap-6 text-sm",children:[i.jsxs("span",{className:"text-bambu-gray",children:[e("notifications.statsSummary",{days:a})," ",i.jsx("span",{className:"text-white font-medium",children:x.total})," ",e("notifications.statsNotifications")]}),i.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[i.jsx(fr,{className:"w-4 h-4"}),e("notifications.statsSent",{count:x.success_count})]}),x.failure_count>0&&i.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[i.jsx(Vi,{className:"w-4 h-4"}),e("notifications.statsFailed",{count:x.failure_count})]})]})}),i.jsxs("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4",children:[i.jsxs("select",{value:a,onChange:N=>s(Number(N.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:[i.jsx("option",{value:1,children:e("notifications.last24Hours")}),i.jsx("option",{value:7,children:e("notifications.last7Days")}),i.jsx("option",{value:30,children:e("notifications.last30Days")}),i.jsx("option",{value:90,children:e("notifications.last90Days")})]}),i.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:c,onChange:N=>u(N.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),e("notifications.showFailedOnly")]}),i.jsx("div",{className:"flex-1"}),i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>y(),disabled:v,children:[v?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(wr,{className:"w-4 h-4"}),e("notifications.refresh")]}),i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>g.mutate(),disabled:g.isPending,className:"text-red-400 hover:text-red-300",children:[g.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Jt,{className:"w-4 h-4"}),e("notifications.clearOld")]})]}),i.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:f?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})}):p&&p.length>0?i.jsx("div",{className:"space-y-2",children:p.map(N=>i.jsx(xet,{log:N,isExpanded:o===N.id,onToggle:()=>l(o===N.id?null:N.id),formatDate:_,formatFullDate:T=>Nf(T,m)},N.id))}):i.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[i.jsx(f0,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),i.jsx("p",{className:"text-sm",children:e(c?"notifications.noFailedNotifications":"notifications.noNotificationsLogged")})]})})]})})}function xet({log:t,isExpanded:e,onToggle:n,formatDate:r,formatFullDate:a}){const{t:s}=Ft();return i.jsxs("div",{className:`border rounded-lg overflow-hidden transition-colors ${t.success?"border-bambu-dark-tertiary bg-bambu-dark/30":"border-red-500/30 bg-red-500/5"}`,children:[i.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:[t.success?i.jsx(fr,{className:"w-4 h-4 text-bambu-green shrink-0"}):i.jsx(Vi,{className:"w-4 h-4 text-red-400 shrink-0"}),i.jsx("span",{className:`text-xs font-medium ${get[t.event_type]||"text-bambu-gray"}`,children:s(`notifications.eventTypes.${t.event_type}`,t.event_type)}),i.jsx("span",{className:"text-sm text-white truncate flex-1",children:t.provider_name||s("notifications.unknownProvider")}),t.printer_name&&i.jsx("span",{className:"text-xs text-bambu-gray",children:t.printer_name}),i.jsx("span",{className:"text-xs text-bambu-gray shrink-0",children:r(t.created_at)}),e?i.jsx(Il,{className:"w-4 h-4 text-bambu-gray shrink-0"}):i.jsx(Ln,{className:"w-4 h-4 text-bambu-gray shrink-0"})]}),e&&i.jsxs("div",{className:"px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:s("notifications.logTitle")}),i.jsx("p",{className:"text-sm text-white",children:t.title})]}),i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:s("notifications.logMessage")}),i.jsx("p",{className:"text-sm text-white whitespace-pre-wrap",children:t.message})]}),!t.success&&t.error_message&&i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-red-400 mb-1",children:s("notifications.logError")}),i.jsx("p",{className:"text-sm text-red-300",children:t.error_message})]}),i.jsxs("div",{className:"flex gap-4 text-xs text-bambu-gray pt-1",children:[i.jsx("span",{children:s("notifications.logProvider",{type:t.provider_type})}),i.jsx("span",{children:s("notifications.logTime",{time:a(t.created_at)})})]})]})]})}function yet({formData:t,setFormData:e,groups:n,onClose:r,onCreate:a,isCreating:s,isCreateButtonDisabled:o}){const{t:l}=Ft();w.useEffect(()=>{const u=d=>{d.key==="Escape"&&r()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[r]);const c=u=>{e({...t,group_ids:t.group_ids.includes(u)?t.group_ids.filter(d=>d!==u):[...t.group_ids,u]})};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:r,children:i.jsxs(Mt,{className:"w-full max-w-md",onClick:u=>u.stopPropagation(),children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Km,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:l("users.modal.createUser")})]}),i.jsx("p",{className:"text-sm text-bambu-gray ml-7",children:l("users.modal.advancedAuthSubtitle")||"with Advanced Authentication"})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:r,children:i.jsx(Ht,{className:"w-5 h-5"})})]})}),i.jsxs(Dt,{children:[i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[l("users.form.username")," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsx("input",{type:"text",value:t.username,onChange:u=>e({...t,username:u.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:l("users.form.usernamePlaceholder"),autoComplete:"username",required:!0})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[l("users.form.email")||"Email"," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsx("input",{type:"email",value:t.email,onChange:u=>e({...t,email:u.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:l("users.form.emailPlaceholder")||"user@example.com",required:!0})]}),i.jsx("div",{className:"bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3",children:i.jsx("p",{className:"text-sm text-bambu-gray",children:l("users.form.autoGeneratedPassword")||"A secure password will be automatically generated and emailed to the user."})}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:l("users.form.groups")}),i.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(u=>i.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:t.group_ids.includes(u.id),onChange:()=>c(u.id),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark"}),i.jsx("span",{className:"text-sm text-white",children:u.name}),u.is_system&&i.jsxs("span",{className:"text-xs text-yellow-400",children:["(",l("users.system"),")"]})]},u.id)),n.length===0&&i.jsx("p",{className:"text-sm text-bambu-gray",children:l("users.noGroupsAvailable")})]})]})]}),i.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:r,children:l("users.modal.cancel")}),i.jsx(Oe,{onClick:a,disabled:o,children:s?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),l("users.modal.creating")]}):i.jsxs(i.Fragment,{children:[i.jsx(ar,{className:"w-4 h-4"}),l("users.modal.createUser")]})})]})]})]})})}function vet(){const{t}=Ft(),e=an(),{showToast:n}=fn(),[r,a]=w.useState(!1),[s,o]=w.useState(""),[l,c]=w.useState("auto"),[u,d]=w.useState(!1),[m,p]=w.useState(!0),[f,y]=w.useState("all"),[v,x]=w.useState(!1),[g,_]=w.useState(!1),[N,T]=w.useState(!1),{data:C,isLoading:A}=et({queryKey:["spoolman-settings"],queryFn:be.getSpoolmanSettings}),{data:k,isLoading:R,refetch:P}=et({queryKey:["spoolman-status"],queryFn:be.getSpoolmanStatus,refetchInterval:3e4}),{data:D}=et({queryKey:["printers"],queryFn:be.getPrinters});w.useEffect(()=>{C&&(a(C.spoolman_enabled==="true"),o(C.spoolman_url||""),c(C.spoolman_sync_mode||"auto"),d(C.spoolman_disable_weight_sync==="true"),p(C.spoolman_report_partial_usage!=="false"),x(!0))},[C]),w.useEffect(()=>{if(!v||!C)return;if(C.spoolman_enabled==="true"!==r||(C.spoolman_url||"")!==s||(C.spoolman_sync_mode||"auto")!==l||C.spoolman_disable_weight_sync==="true"!==u||C.spoolman_report_partial_usage!=="false"!==m){const oe=setTimeout(()=>{H.mutate()},500);return()=>clearTimeout(oe)}},[r,s,l,u,m,v]);const H=pt({mutationFn:()=>be.updateSpoolmanSettings({spoolman_enabled:r?"true":"false",spoolman_url:s,spoolman_sync_mode:l,spoolman_disable_weight_sync:u?"true":"false",spoolman_report_partial_usage:m?"true":"false"}),onSuccess:()=>{e.invalidateQueries({queryKey:["spoolman-settings"]}),e.invalidateQueries({queryKey:["spoolman-status"]}),e.invalidateQueries({queryKey:["spool-assignments"]}),e.invalidateQueries({queryKey:["settings"]}),n(t("settings.toast.settingsSaved"))}}),z=pt({mutationFn:be.connectSpoolman,onSuccess:()=>{P()}}),G=pt({mutationFn:be.disconnectSpoolman,onSuccess:()=>{P()}}),I=pt({mutationFn:be.syncAllPrintersAms,onSuccess:Y=>{Y.success}}),ee=pt({mutationFn:Y=>be.syncPrinterAms(Y),onSuccess:Y=>{Y.success}}),ie=()=>{f==="all"?I.mutate():ee.mutate(f)},X=pt({mutationFn:be.syncWeightsFromAms,onSuccess:Y=>{e.invalidateQueries({queryKey:["spools"]}),e.invalidateQueries({queryKey:["inventory-spools"]}),n(t("settings.amsSyncSuccess",{synced:Y.synced,skipped:Y.skipped}),"success"),T(!1)},onError:()=>{n(t("settings.amsSyncError"),"error"),T(!1)}}),me=I.isPending||ee.isPending,he=f==="all"?I.data:ee.data,ge=f==="all"?I.isSuccess:ee.isSuccess;return A?i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(au,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.filamentTracking")})]})}),i.jsx(Dt,{children:i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})})})]}):i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(au,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.filamentTracking")})]}),H.isPending&&i.jsx(ht,{className:"w-4 h-4 text-bambu-green animate-spin"})]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:t("settings.filamentTrackingDesc")}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("button",{type:"button",onClick:()=>a(!1),className:`p-3 rounded-lg border-2 text-left transition-colors ${r?"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50":"border-bambu-green bg-bambu-green/10"}`,children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[i.jsx(Wi,{className:`w-4 h-4 ${r?"text-bambu-gray":"text-bambu-green"}`}),i.jsx("span",{className:`text-sm font-medium ${r?"text-bambu-gray":"text-white"}`,children:t("settings.trackingModeBuiltIn")})]}),i.jsx("p",{className:`text-xs ${r?"text-bambu-gray/60":"text-bambu-gray"}`,children:t("settings.trackingModeBuiltInDesc")}),!r&&i.jsxs("div",{className:"flex items-center gap-1 mt-2",children:[i.jsx(Yr,{className:"w-3 h-3 text-bambu-green"}),i.jsx("span",{className:"text-xs text-bambu-green",children:t("common.enabled")})]})]}),i.jsxs("button",{type:"button",onClick:()=>a(!0),className:`p-3 rounded-lg border-2 text-left transition-colors ${r?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50"}`,children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[i.jsx(Jr,{className:`w-4 h-4 ${r?"text-bambu-green":"text-bambu-gray"}`}),i.jsx("span",{className:`text-sm font-medium ${r?"text-white":"text-bambu-gray"}`,children:"Spoolman"})]}),i.jsx("p",{className:`text-xs ${r?"text-bambu-gray":"text-bambu-gray/60"}`,children:t("settings.trackingModeSpoolmanDesc")}),r&&i.jsxs("div",{className:"flex items-center gap-1 mt-2",children:[i.jsx(Yr,{className:"w-3 h-3 text-bambu-green"}),i.jsx("span",{className:"text-xs text-bambu-green",children:t("common.enabled")})]})]})]}),!r&&i.jsxs("div",{className:"space-y-3",children:[i.jsx("div",{className:"p-3 bg-bambu-green/5 border border-bambu-green/20 rounded-lg",children:i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ls,{className:"w-4 h-4 text-bambu-green flex-shrink-0 mt-0.5"}),i.jsx("div",{className:"text-xs text-bambu-gray",children:i.jsxs("ul",{className:"list-disc list-inside space-y-0.5",children:[i.jsx("li",{children:t("settings.builtInFeatureRfid")}),i.jsx("li",{children:t("settings.builtInFeatureUsage")}),i.jsx("li",{children:t("settings.builtInFeatureCatalog")}),i.jsx("li",{children:t("settings.builtInFeatureThirdParty")})]})})]})}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>T(!0),disabled:X.isPending,children:[X.isPending?i.jsx(ht,{className:"w-4 h-4 mr-2 animate-spin"}):i.jsx(wr,{className:"w-4 h-4 mr-2"}),t("settings.amsSyncButton")]})]}),r&&i.jsxs("div",{className:"space-y-4",children:[i.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ls,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),i.jsxs("div",{className:"text-xs text-blue-300",children:[i.jsx("p",{className:"font-medium mb-1",children:t("settings.howSyncWorks")}),i.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-blue-300/80",children:[i.jsx("li",{children:t("settings.syncInfoRfidOnly")}),i.jsx("li",{children:t("settings.syncInfoAutoCreate")}),i.jsx("li",{children:t("settings.syncInfoThirdPartySkipped")})]}),i.jsx("p",{className:"font-medium mt-2 mb-1",children:t("settings.linkingExistingSpools")}),i.jsx("p",{className:"text-blue-300/80",children:t("settings.linkingExistingSpoolsDesc")})]})]})}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("settings.spoolmanUrl")}),i.jsx("input",{type:"text",placeholder:"http://192.168.1.100:7912",value:s,onChange:Y=>o(Y.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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("settings.spoolmanUrlHint")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("settings.syncMode")}),i.jsxs("select",{value:l,onChange:Y=>c(Y.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:[i.jsx("option",{value:"auto",children:t("settings.syncModeAuto")}),i.jsx("option",{value:"manual",children:t("settings.syncModeManual")})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t(l==="auto"?"settings.syncModeAutoDesc":"settings.syncModeManualDesc")})]}),l==="auto"&&i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:t("spoolman.disableWeightSync")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t("spoolman.disableWeightSyncDesc")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:u,onChange:Y=>d(Y.target.checked),className:"sr-only peer"}),i.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"})]})]}),u&&i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:t("spoolman.reportPartialUsage")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t("spoolman.reportPartialUsageDesc")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:m,onChange:Y=>p(Y.target.checked),className:"sr-only peer"}),i.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.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{className:"text-sm text-bambu-gray",children:[t("settings.status"),":"]}),R?i.jsx(ht,{className:"w-4 h-4 text-bambu-gray animate-spin"}):k?.connected?i.jsxs("span",{className:"flex items-center gap-1 text-sm text-green-500",children:[i.jsx(Yr,{className:"w-4 h-4"}),t("settings.spoolmanConnected")]}):i.jsxs("span",{className:"flex items-center gap-1 text-sm text-red-500",children:[i.jsx(Ht,{className:"w-4 h-4"}),t("settings.spoolmanDisconnected")]})]}),i.jsx("div",{className:"flex gap-2",children:k?.connected?i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>G.mutate(),disabled:G.isPending,children:[G.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(jfe,{className:"w-4 h-4"}),t("settings.disconnect")]}):i.jsxs(Oe,{size:"sm",onClick:()=>z.mutate(),disabled:z.isPending||!s,children:[z.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(xh,{className:"w-4 h-4"}),t("settings.connect")]})})]}),z.isError&&i.jsx("div",{className:"mb-3 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:z.error.message}),k?.connected&&i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:t("settings.syncAmsData")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:t("settings.syncAmsDataDesc")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsxs("select",{value:f,onChange:Y=>y(Y.target.value==="all"?"all":Number(Y.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:[i.jsx("option",{value:"all",children:t("settings.allPrinters")}),D?.map(Y=>i.jsx("option",{value:Y.id,children:Y.name},Y.id))]}),i.jsx(Ln,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:ie,disabled:me,children:[me?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(wr,{className:"w-4 h-4"}),t("spoolman.sync")]})]})]}),ge&&he&&i.jsxs("div",{className:"mt-3 space-y-2",children:[i.jsx("div",{className:`p-2 rounded text-sm ${he.success?"bg-green-500/20 border border-green-500/50 text-green-400":"bg-yellow-500/20 border border-yellow-500/50 text-yellow-400"}`,children:he.success?`Synced ${he.synced_count} spool${he.synced_count!==1?"s":""} successfully`:`Synced ${he.synced_count} spool${he.synced_count!==1?"s":""} with ${he.errors.length} error${he.errors.length!==1?"s":""}`}),he.skipped_count>0&&i.jsxs("div",{className:"p-2 bg-amber-500/10 border border-amber-500/30 rounded text-sm",children:[i.jsxs("div",{className:"flex items-center justify-between text-amber-400 mb-1",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx(Mn,{className:"w-3.5 h-3.5"}),i.jsxs("span",{className:"font-medium",children:[he.skipped_count," spool",he.skipped_count!==1?"s":""," skipped"]})]}),he.skipped_count>5&&i.jsx("button",{onClick:()=>_(!g),className:"text-xs text-amber-400 hover:text-amber-300 underline",children:g?"Show less":"Show all"})]}),i.jsxs("ul",{className:"text-xs text-amber-300/80 space-y-0.5",children:[(g?he.skipped:he.skipped.slice(0,5)).map((Y,oe)=>i.jsxs("li",{className:"flex items-center gap-2",children:[Y.color&&i.jsx("span",{className:"w-3 h-3 rounded-full border border-black/20",style:{backgroundColor:`#${Y.color}`}}),i.jsx("span",{children:Y.location}),i.jsxs("span",{className:"text-amber-300/60",children:["- ",Y.reason]})]},oe)),!g&&he.skipped_count>5&&i.jsxs("li",{className:"text-amber-300/60 italic",children:["...and ",he.skipped_count-5," more"]})]})]}),he.errors.length>0&&i.jsxs("div",{className:"p-2 bg-red-500/10 border border-red-500/30 rounded text-sm",children:[i.jsx("div",{className:"text-red-400 font-medium mb-1",children:"Errors:"}),i.jsx("ul",{className:"text-xs text-red-300/80 space-y-0.5",children:he.errors.map((Y,oe)=>i.jsx("li",{children:Y},oe))})]})]})]})]})]}),N&&i.jsx(Sn,{title:t("settings.amsSyncTitle"),message:t("settings.amsSyncMessage"),confirmText:t("settings.amsSyncButton"),variant:"warning",isLoading:X.isPending,loadingText:t("settings.amsSyncing"),onConfirm:()=>X.mutate(),onCancel:()=>T(!1)})]})}function wet(){const{t}=Ft(),{showToast:e}=fn(),[n,r]=w.useState([]),[a,s]=w.useState(!0),[o,l]=w.useState(""),c=w.useRef(null),[u,d]=w.useState(!1),[m,p]=w.useState(null),[f,y]=w.useState(""),[v,x]=w.useState(""),[g,_]=w.useState(!1),[N,T]=w.useState(new Set),[C,A]=w.useState(!1),[k,R]=w.useState(null),[P,D]=w.useState(!1),H=w.useCallback(async()=>{try{const xe=await be.getSpoolCatalog();r(xe)}catch{e(t("settings.catalog.loadFailed"),"error")}finally{s(!1)}},[e,t]);w.useEffect(()=>{H()},[H]);const z=n.filter(xe=>xe.name.toLowerCase().includes(o.toLowerCase())),G=async()=>{if(!f.trim()||!v){e(t("settings.catalog.nameWeightRequired"),"error");return}_(!0);try{const xe=await be.addCatalogEntry({name:f.trim(),weight:parseInt(v)});r(Pe=>[...Pe,xe].sort((q,Z)=>q.name.localeCompare(Z.name))),d(!1),y(""),x(""),e(t("settings.catalog.entryAdded"),"success")}catch{e(t("settings.catalog.addFailed"),"error")}finally{_(!1)}},I=xe=>{p(xe.id),y(xe.name),x(xe.weight.toString())},ee=()=>{p(null),y(""),x("")},ie=async xe=>{if(!f.trim()||!v){e(t("settings.catalog.nameWeightRequired"),"error");return}_(!0);try{const Pe=await be.updateCatalogEntry(xe,{name:f.trim(),weight:parseInt(v)});r(q=>q.map(Z=>Z.id===xe?Pe:Z).sort((Z,j)=>Z.name.localeCompare(j.name))),p(null),y(""),x(""),e(t("settings.catalog.entryUpdated"),"success")}catch{e(t("settings.catalog.updateFailed"),"error")}finally{_(!1)}},X=async()=>{if(k)try{await be.deleteCatalogEntry(k.id),r(xe=>xe.filter(Pe=>Pe.id!==k.id)),e(t("settings.catalog.entryDeleted"),"success")}catch{e(t("settings.catalog.deleteFailed"),"error")}finally{R(null)}},me=async()=>{D(!1),s(!0);try{await be.resetSpoolCatalog(),await H(),e(t("settings.catalog.resetSuccess"),"success")}catch{e(t("settings.catalog.resetFailed"),"error"),s(!1)}},he=xe=>{T(Pe=>{const q=new Set(Pe);return q.has(xe)?q.delete(xe):q.add(xe),q})},ge=()=>{N.size===z.length?T(new Set):T(new Set(z.map(xe=>xe.id)))},Y=async()=>{if(A(!1),N.size!==0)try{const xe=await be.bulkDeleteCatalogEntries([...N]);r(Pe=>Pe.filter(q=>!N.has(q.id))),T(new Set),e(t("settings.catalog.bulkDeleted",{count:xe.deleted}),"success")}catch{e(t("settings.catalog.bulkDeleteFailed"),"error")}},oe=()=>{const xe=n.map(({name:j,weight:E})=>({name:j,weight:E})),Pe=new Blob([JSON.stringify(xe,null,2)],{type:"application/json"}),q=URL.createObjectURL(Pe),Z=document.createElement("a");Z.href=q,Z.download="spool-catalog.json",document.body.appendChild(Z),Z.click(),document.body.removeChild(Z),URL.revokeObjectURL(q),e(t("settings.catalog.exported",{count:n.length}),"success")},le=async xe=>{const Pe=xe.target.files?.[0];if(Pe){try{const q=await Pe.text(),Z=JSON.parse(q);if(!Array.isArray(Z))throw new Error("Invalid format");let j=0,E=0;for(const U of Z){if(!U.name||typeof U.weight!="number"){E++;continue}if(n.some($=>$.name.toLowerCase()===U.name.toLowerCase())){E++;continue}try{const $=await be.addCatalogEntry({name:U.name,weight:U.weight});r(ne=>[...ne,$].sort((O,V)=>O.name.localeCompare(V.name))),j++}catch{E++}}e(t("settings.catalog.imported",{added:j,skipped:E}),"success")}catch{e(t("settings.catalog.importFailed"),"error")}c.current&&(c.current.value="")}};return i.jsxs(Mt,{children:[i.jsxs(Hn,{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(au,{className:"w-5 h-5 text-bambu-gray"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.catalog.spoolCatalog")}),i.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",n.length,")"]})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[i.jsxs("button",{onClick:oe,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:t("settings.catalog.exportTooltip"),children:[i.jsx(pi,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.export")})]}),i.jsxs("button",{onClick:()=>c.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:t("settings.catalog.importTooltip"),children:[i.jsx(xi,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.import")})]}),i.jsx("input",{ref:c,type:"file",accept:".json",className:"hidden",onChange:le}),i.jsxs("button",{onClick:()=>D(!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:t("settings.catalog.resetTooltip"),children:[i.jsx(bo,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.reset")})]}),i.jsxs("button",{onClick:()=>d(!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:[i.jsx(ar,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.add")})]})]}),N.size>0&&i.jsxs("div",{className:"flex items-center gap-2 mt-2 px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg",children:[i.jsx("span",{className:"text-sm text-red-400",children:t("settings.catalog.selectedCount",{count:N.size})}),i.jsxs("button",{onClick:()=>A(!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:[i.jsx(Jt,{className:"w-4 h-4"}),t("settings.catalog.deleteSelected")]}),i.jsx("button",{onClick:()=>T(new Set),className:"px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors",children:t("common.cancel")})]})]}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:t("settings.catalog.spoolCatalogDescription")}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.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:t("settings.catalog.searchCatalog"),value:o,onChange:xe=>l(xe.target.value)})]}),u&&i.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:t("settings.catalog.addNewEntry")}),i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsx("div",{className:"flex-1 min-w-0",children:i.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:t("settings.catalog.namePlaceholder"),value:f,onChange:xe=>y(xe.target.value)})}),i.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:v,onChange:xe=>x(xe.target.value)}),i.jsx("span",{className:"text-bambu-gray shrink-0",children:"g"}),i.jsxs("button",{onClick:G,disabled:g,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:[g?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Yr,{className:"w-4 h-4"}),t("common.add")]}),i.jsx("button",{onClick:()=>{d(!1),y(""),x("")},className:"p-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary",children:i.jsx(Ht,{className:"w-4 h-4"})})]})]}),a?i.jsxs("div",{className:"flex items-center justify-center py-8 text-bambu-gray",children:[i.jsx(ht,{className:"w-5 h-5 animate-spin mr-2"}),t("common.loading")]}):i.jsx("div",{className:"max-h-[600px] overflow-y-auto border border-bambu-dark-tertiary rounded-lg",children:i.jsxs("table",{className:"w-full text-sm",children:[i.jsx("thead",{className:"bg-bambu-dark sticky top-0",children:i.jsxs("tr",{children:[i.jsx("th",{className:"px-2 py-2 w-10",children:i.jsx("input",{type:"checkbox",checked:z.length>0&&N.size===z.length,onChange:ge,className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),i.jsx("th",{className:"px-4 py-2 text-left text-bambu-gray font-medium",children:t("common.name")}),i.jsx("th",{className:"px-4 py-2 text-right text-bambu-gray font-medium w-24",children:t("settings.catalog.weight")}),i.jsx("th",{className:"px-4 py-2 text-center text-bambu-gray font-medium w-20",children:t("settings.catalog.type")}),i.jsx("th",{className:"px-4 py-2 w-24"})]})}),i.jsx("tbody",{children:z.length===0?i.jsx("tr",{children:i.jsx("td",{colSpan:5,className:"px-4 py-8 text-center text-bambu-gray",children:t(o?"settings.catalog.noMatch":"settings.catalog.empty")})}):z.map(xe=>i.jsx("tr",{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${N.has(xe.id)?"bg-bambu-dark":""}`,children:m===xe.id?i.jsxs(i.Fragment,{children:[i.jsx("td",{className:"px-2 py-2",children:i.jsx("input",{type:"checkbox",checked:N.has(xe.id),onChange:()=>he(xe.id),className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),i.jsx("td",{className:"px-4 py-2",children:i.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:f,onChange:Pe=>y(Pe.target.value)})}),i.jsx("td",{className:"px-4 py-2",children:i.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:v,onChange:Pe=>x(Pe.target.value)})}),i.jsx("td",{className:"px-4 py-2 text-center",children:i.jsx("span",{className:"text-xs text-bambu-gray",children:"-"})}),i.jsx("td",{className:"px-4 py-2",children:i.jsxs("div",{className:"flex justify-end gap-1",children:[i.jsx("button",{onClick:()=>ie(xe.id),disabled:g,className:"p-1.5 rounded hover:bg-green-500/20 text-green-500",children:g?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Yr,{className:"w-4 h-4"})}),i.jsx("button",{onClick:ee,className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray",children:i.jsx(Ht,{className:"w-4 h-4"})})]})})]}):i.jsxs(i.Fragment,{children:[i.jsx("td",{className:"px-2 py-2",children:i.jsx("input",{type:"checkbox",checked:N.has(xe.id),onChange:()=>he(xe.id),className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),i.jsx("td",{className:"px-4 py-2 text-white",children:xe.name}),i.jsxs("td",{className:"px-4 py-2 text-right font-mono text-white",children:[xe.weight,"g"]}),i.jsx("td",{className:"px-4 py-2 text-center",children:xe.is_default?i.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray",children:t("settings.catalog.default")}):i.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-bambu-green/20 text-bambu-green",children:t("settings.catalog.custom")})}),i.jsx("td",{className:"px-4 py-2",children:i.jsxs("div",{className:"flex justify-end gap-1",children:[i.jsx("button",{onClick:()=>I(xe),className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:i.jsx(Yi,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>R(xe),className:"p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500",children:i.jsx(Jt,{className:"w-4 h-4"})})]})})]})},xe.id))})]})})]}),k&&i.jsx(Sn,{title:t("settings.catalog.deleteEntry"),message:t("settings.catalog.deleteConfirm",{name:k.name}),confirmText:t("common.delete"),variant:"danger",onConfirm:X,onCancel:()=>R(null)}),C&&i.jsx(Sn,{title:t("settings.catalog.deleteSelected"),message:t("settings.catalog.bulkDeleteConfirm",{count:N.size}),confirmText:t("common.delete"),variant:"danger",onConfirm:Y,onCancel:()=>A(!1)}),P&&i.jsx(Sn,{title:t("settings.catalog.resetCatalog"),message:t("settings.catalog.resetConfirm"),confirmText:t("common.reset"),variant:"danger",onConfirm:me,onCancel:()=>D(!1)})]})}function _et(){const{t}=Ft(),{showToast:e}=fn(),[n,r]=w.useState([]),[a,s]=w.useState(!0),[o,l]=w.useState(""),[c,u]=w.useState("Bambu Lab"),d=w.useRef(null),[m,p]=w.useState(!1),[f,y]=w.useState(null),[v,x]=w.useState(""),[g,_]=w.useState(""),[N,T]=w.useState("#FFFFFF"),[C,A]=w.useState(""),[k,R]=w.useState(!1),[P,D]=w.useState(new Set),[H,z]=w.useState(!1),[G,I]=w.useState(!1),[ee,ie]=w.useState(null),[X,me]=w.useState(null),[he,ge]=w.useState(!1),Y=w.useCallback(async()=>{try{const W=await be.getColorCatalog();r(W)}catch{e(t("settings.colorCatalog.loadFailed"),"error")}finally{s(!1)}},[e,t]);w.useEffect(()=>{Y()},[Y]);const oe=[...new Set(n.map(W=>W.manufacturer))].sort(),le=n.filter(W=>{const re=o===""||W.manufacturer.toLowerCase().includes(o.toLowerCase())||W.color_name.toLowerCase().includes(o.toLowerCase())||(W.material?.toLowerCase().includes(o.toLowerCase())??!1),ue=c===""||W.manufacturer===c;return re&&ue}),xe=()=>{x(""),_(""),T("#FFFFFF"),A("")},Pe=async()=>{if(!v.trim()||!g.trim()||!N){e(t("settings.colorCatalog.fieldsRequired"),"error");return}R(!0);try{const W=await be.addColorEntry({manufacturer:v.trim(),color_name:g.trim(),hex_color:N,material:C.trim()||null});r(re=>[...re,W].sort((ue,fe)=>ue.manufacturer.localeCompare(fe.manufacturer)||(ue.material||"").localeCompare(fe.material||"")||ue.color_name.localeCompare(fe.color_name))),p(!1),xe(),e(t("settings.colorCatalog.colorAdded"),"success")}catch{e(t("settings.colorCatalog.addFailed"),"error")}finally{R(!1)}},q=W=>{y(W.id),x(W.manufacturer),_(W.color_name),T(W.hex_color),A(W.material||"")},Z=()=>{y(null),xe()},j=async W=>{if(!v.trim()||!g.trim()||!N){e(t("settings.colorCatalog.fieldsRequired"),"error");return}R(!0);try{const re=await be.updateColorEntry(W,{manufacturer:v.trim(),color_name:g.trim(),hex_color:N,material:C.trim()||null});r(ue=>ue.map(fe=>fe.id===W?re:fe).sort((fe,ye)=>fe.manufacturer.localeCompare(ye.manufacturer)||(fe.material||"").localeCompare(ye.material||"")||fe.color_name.localeCompare(ye.color_name))),y(null),xe(),e(t("settings.colorCatalog.colorUpdated"),"success")}catch{e(t("settings.colorCatalog.updateFailed"),"error")}finally{R(!1)}},E=async()=>{if(X)try{await be.deleteColorEntry(X.id),r(W=>W.filter(re=>re.id!==X.id)),e(t("settings.colorCatalog.colorDeleted"),"success")}catch{e(t("settings.colorCatalog.deleteFailed"),"error")}finally{me(null)}},U=async()=>{ge(!1),s(!0);try{await be.resetColorCatalog(),await Y(),e(t("settings.colorCatalog.resetSuccess"),"success")}catch{e(t("settings.colorCatalog.resetFailed"),"error"),s(!1)}},K=async()=>{I(!0),ie(null);try{const W={},re=Fd();re&&(W.Authorization=`Bearer ${re}`);const ue=await fetch("/api/v1/inventory/colors/sync",{method:"POST",headers:W});if(!ue.ok)throw new Error("Failed to start sync");const fe=ue.body?.getReader();if(!fe)throw new Error("No response body");const ye=new TextDecoder;let ae="";for(;;){const{done:L,value:F}=await fe.read();if(L)break;ae+=ye.decode(F,{stream:!0});const te=ae.split(` +`);ae=te.pop()||"";for(const ve of te)if(ve.startsWith("data: "))try{const pe=JSON.parse(ve.slice(6));pe.type==="progress"?ie({fetched:pe.total_fetched,total:pe.total_available}):pe.type==="complete"?pe.added===0?e(t("settings.colorCatalog.syncUpToDate",{count:pe.total_fetched}),"success"):e(t("settings.colorCatalog.syncComplete",{added:pe.added,skipped:pe.skipped}),"success"):pe.type==="error"&&e(`${t("settings.colorCatalog.syncError")}: ${pe.error}`,"error")}catch{}}await Y()}catch{e(t("settings.colorCatalog.syncFailed"),"error")}finally{I(!1),ie(null)}},$=W=>{D(re=>{const ue=new Set(re);return ue.has(W)?ue.delete(W):ue.add(W),ue})},ne=()=>{P.size===le.length?D(new Set):D(new Set(le.map(W=>W.id)))},O=async()=>{if(z(!1),P.size!==0)try{const W=await be.bulkDeleteColorEntries([...P]);r(re=>re.filter(ue=>!P.has(ue.id))),D(new Set),e(t("settings.colorCatalog.bulkDeleted",{count:W.deleted}),"success")}catch{e(t("settings.colorCatalog.bulkDeleteFailed"),"error")}},V=()=>{const W=n.map(({manufacturer:ye,color_name:ae,hex_color:L,material:F})=>({manufacturer:ye,color_name:ae,hex_color:L,material:F})),re=new Blob([JSON.stringify(W,null,2)],{type:"application/json"}),ue=URL.createObjectURL(re),fe=document.createElement("a");fe.href=ue,fe.download="color-catalog.json",document.body.appendChild(fe),fe.click(),document.body.removeChild(fe),URL.revokeObjectURL(ue),e(t("settings.colorCatalog.exported",{count:n.length}),"success")},J=async W=>{const re=W.target.files?.[0];if(re){try{const ue=await re.text(),fe=JSON.parse(ue);if(!Array.isArray(fe))throw new Error("Invalid format");let ye=0,ae=0;for(const L of fe){if(!L.manufacturer||!L.color_name||!L.hex_color){ae++;continue}if(n.some(te=>te.manufacturer.toLowerCase()===L.manufacturer.toLowerCase()&&te.color_name.toLowerCase()===L.color_name.toLowerCase()&&(te.material||"").toLowerCase()===(L.material||"").toLowerCase())){ae++;continue}try{const te=await be.addColorEntry({manufacturer:L.manufacturer,color_name:L.color_name,hex_color:L.hex_color,material:L.material||null});r(ve=>[...ve,te].sort((pe,de)=>pe.manufacturer.localeCompare(de.manufacturer)||(pe.material||"").localeCompare(de.material||"")||pe.color_name.localeCompare(de.color_name))),ye++}catch{ae++}}e(t("settings.colorCatalog.imported",{added:ye,skipped:ae}),"success")}catch{e(t("settings.colorCatalog.importFailed"),"error")}d.current&&(d.current.value="")}};return i.jsxs(Mt,{children:[i.jsxs(Hn,{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(fw,{className:"w-5 h-5 text-bambu-gray"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.colorCatalog.title")}),i.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",n.length,")"]})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[i.jsxs("button",{onClick:V,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:[i.jsx(pi,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.export")})]}),i.jsxs("button",{onClick:()=>d.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:[i.jsx(xi,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.import")})]}),i.jsx("input",{ref:d,type:"file",accept:".json",className:"hidden",onChange:J}),i.jsxs("button",{onClick:K,disabled:G,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:t("settings.colorCatalog.syncTooltip"),children:[G?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Fx,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:G?ee?`${Math.min(ee.fetched,ee.total)} / ${ee.total}`:t("settings.colorCatalog.starting"):t("settings.colorCatalog.sync")})]}),i.jsxs("button",{onClick:()=>ge(!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:[i.jsx(bo,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.reset")})]}),i.jsxs("button",{onClick:()=>p(!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:[i.jsx(ar,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.add")})]})]}),P.size>0&&i.jsxs("div",{className:"flex items-center gap-2 mt-2 px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg",children:[i.jsx("span",{className:"text-sm text-red-400",children:t("settings.colorCatalog.selectedCount",{count:P.size})}),i.jsxs("button",{onClick:()=>z(!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:[i.jsx(Jt,{className:"w-4 h-4"}),t("settings.colorCatalog.deleteSelected")]}),i.jsx("button",{onClick:()=>D(new Set),className:"px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors",children:t("common.cancel")})]})]}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:t("settings.colorCatalog.description")}),i.jsxs("div",{className:"flex gap-2 flex-wrap",children:[i.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.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:t("settings.colorCatalog.searchColors"),value:o,onChange:W=>l(W.target.value)})]}),i.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:c,onChange:W=>u(W.target.value),children:[i.jsx("option",{value:"",children:t("settings.colorCatalog.allManufacturers")}),oe.map(W=>i.jsx("option",{value:W,children:W},W))]})]}),m&&i.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:t("settings.colorCatalog.addNewColor")}),i.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-2 items-end",children:[i.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:t("settings.colorCatalog.manufacturer"),value:v,onChange:W=>x(W.target.value)}),i.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:t("settings.colorCatalog.colorName"),value:g,onChange:W=>_(W.target.value)}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"color",className:"w-20 h-10 rounded cursor-pointer border border-bambu-dark-tertiary",value:N,onChange:W=>T(W.target.value)}),i.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:N,onChange:W=>T(W.target.value)})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.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:t("settings.colorCatalog.materialOptional"),value:C,onChange:W=>A(W.target.value)}),i.jsxs("button",{onClick:Pe,disabled:k,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:[k?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Yr,{className:"w-4 h-4"}),t("common.add")]}),i.jsx("button",{onClick:()=>{p(!1),xe()},className:"p-2 ml-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary",children:i.jsx(Ht,{className:"w-4 h-4"})})]})]})]}),(o||c)&&i.jsx("div",{className:"text-xs text-bambu-gray",children:t("settings.colorCatalog.showing",{filtered:le.length,total:n.length})}),a?i.jsxs("div",{className:"flex items-center justify-center py-8 text-bambu-gray",children:[i.jsx(ht,{className:"w-5 h-5 animate-spin mr-2"}),t("common.loading")]}):i.jsx("div",{className:"max-h-[600px] overflow-auto border border-bambu-dark-tertiary rounded-lg",children:i.jsxs("table",{className:"w-full text-sm",children:[i.jsx("thead",{className:"bg-bambu-dark sticky top-0",children:i.jsxs("tr",{children:[i.jsx("th",{className:"px-2 py-2 w-10",children:i.jsx("input",{type:"checkbox",checked:le.length>0&&P.size===le.length,onChange:ne,className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium w-12"}),i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium",children:t("settings.colorCatalog.manufacturer")}),i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium",children:t("inventory.material")}),i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium",children:t("settings.colorCatalog.colorName")}),i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium w-24",children:t("settings.colorCatalog.hex")}),i.jsx("th",{className:"px-3 py-2 w-16"})]})}),i.jsx("tbody",{children:le.length===0?i.jsx("tr",{children:i.jsx("td",{colSpan:7,className:"px-3 py-8 text-center text-bambu-gray",children:t(o||c?"settings.colorCatalog.noMatch":"settings.colorCatalog.empty")})}):le.map(W=>i.jsx("tr",{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${P.has(W.id)?"bg-bambu-dark":""}`,children:f===W.id?i.jsxs(i.Fragment,{children:[i.jsx("td",{className:"px-2 py-2",children:i.jsx("input",{type:"checkbox",checked:P.has(W.id),onChange:()=>$(W.id),className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),i.jsx("td",{className:"px-3 py-2",children:i.jsx("input",{type:"color",className:"w-8 h-8 rounded cursor-pointer border border-bambu-dark-tertiary",value:N,onChange:re=>T(re.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.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:re=>x(re.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.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:C,onChange:re=>A(re.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.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:g,onChange:re=>_(re.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.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:N,onChange:re=>T(re.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.jsxs("div",{className:"flex justify-end gap-1",children:[i.jsx("button",{onClick:()=>j(W.id),disabled:k,className:"p-1.5 rounded hover:bg-green-500/20 text-green-500",children:k?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Yr,{className:"w-4 h-4"})}),i.jsx("button",{onClick:Z,className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray",children:i.jsx(Ht,{className:"w-4 h-4"})})]})})]}):i.jsxs(i.Fragment,{children:[i.jsx("td",{className:"px-2 py-2",children:i.jsx("input",{type:"checkbox",checked:P.has(W.id),onChange:()=>$(W.id),className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),i.jsx("td",{className:"px-3 py-2",children:i.jsx("div",{className:"w-8 h-8 rounded border border-bambu-dark-tertiary",style:{backgroundColor:W.hex_color},title:W.hex_color})}),i.jsx("td",{className:"px-3 py-2 text-white",children:W.manufacturer}),i.jsx("td",{className:"px-3 py-2 text-bambu-gray",children:W.material||"-"}),i.jsx("td",{className:"px-3 py-2 text-white",children:W.color_name}),i.jsx("td",{className:"px-3 py-2 font-mono text-xs text-bambu-gray",children:W.hex_color}),i.jsx("td",{className:"px-3 py-2",children:i.jsxs("div",{className:"flex justify-end gap-1",children:[i.jsx("button",{onClick:()=>q(W),className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:i.jsx(Yi,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>me(W),className:"p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500",children:i.jsx(Jt,{className:"w-4 h-4"})})]})})]})},W.id))})]})})]}),X&&i.jsx(Sn,{title:t("settings.colorCatalog.deleteColor"),message:t("settings.colorCatalog.deleteConfirm",{name:`${X.manufacturer} - ${X.color_name}`}),confirmText:t("common.delete"),variant:"danger",onConfirm:E,onCancel:()=>me(null)}),H&&i.jsx(Sn,{title:t("settings.colorCatalog.deleteSelected"),message:t("settings.colorCatalog.bulkDeleteConfirm",{count:P.size}),confirmText:t("common.delete"),variant:"danger",onConfirm:O,onCancel:()=>z(!1)}),he&&i.jsx(Sn,{title:t("settings.colorCatalog.resetCatalog"),message:t("settings.colorCatalog.resetConfirm"),confirmText:t("common.reset"),variant:"danger",onConfirm:U,onCancel:()=>ge(!1)})]})}function Net({link:t,onClose:e}){const{t:n}=Ft(),r=an(),a=!!t,s=w.useRef(null),[o,l]=w.useState(t?.name||""),[c,u]=w.useState(t?.url||""),[d,m]=w.useState(t?.icon||"link"),[p,f]=w.useState(t?.open_in_new_tab||!1),[y,v]=w.useState(!!t?.custom_icon),[x,g]=w.useState(t?.custom_icon?be.getExternalLinkIconUrl(t.id):null),[_,N]=w.useState(null),[T,C]=w.useState(null);w.useEffect(()=>{const G=I=>{I.key==="Escape"&&e()};return window.addEventListener("keydown",G),()=>window.removeEventListener("keydown",G)},[e]);const A=pt({mutationFn:async G=>{const I=await be.createExternalLink(G);return _?await be.uploadExternalLinkIcon(I.id,_):I},onSuccess:()=>{r.invalidateQueries({queryKey:["external-links"]}),e()},onError:G=>{C(G.message)}}),k=pt({mutationFn:async G=>{let I=await be.updateExternalLink(t.id,G);return _?I=await be.uploadExternalLinkIcon(t.id,_):!y&&t?.custom_icon&&(I=await be.deleteExternalLinkIcon(t.id)),I},onSuccess:()=>{r.invalidateQueries({queryKey:["external-links"]}),e()},onError:G=>{C(G.message)}}),R=G=>{const I=G.target.files?.[0];if(I){if(!["image/png","image/jpeg","image/gif","image/svg+xml","image/webp","image/x-icon"].includes(I.type)){C("Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)");return}if(I.size>1024*1024){C("Image file must be less than 1MB");return}N(I),v(!0);const ie=new FileReader;ie.onload=X=>{g(X.target?.result)},ie.readAsDataURL(I)}},P=()=>{N(null),g(null),v(!1),s.current&&(s.current.value="")},D=G=>{if(G.preventDefault(),C(null),!o.trim()){C("Name is required");return}if(!c.trim()){C("URL is required");return}if(!c.startsWith("http://")&&!c.startsWith("https://")){C("URL must start with http:// or https://");return}const I={name:o.trim(),url:c.trim(),icon:d,open_in_new_tab:p};a?k.mutate(I):A.mutate(I)},H=A.isPending||k.isPending,z=sT(d);return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:G=>G.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2 rounded-full bg-bambu-green/20 text-bambu-green",children:y&&x?i.jsx("img",{src:x,alt:"",className:"w-5 h-5 rounded"}):i.jsx(z,{className:"w-5 h-5"})}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:a?"Edit Link":"Add External Link"})]}),i.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:D,className:"p-6 space-y-4",children:[T&&i.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:T}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),i.jsx("input",{type:"text",value:o,onChange:G=>l(G.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"URL *"}),i.jsx("input",{type:"text",value:c,onChange:G=>u(G.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"})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("label",{className:"text-sm text-bambu-gray",children:n("externalLinks.openInNewTab")}),i.jsx("button",{type:"button",onClick:()=>f(!p),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${p?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:i.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${p?"translate-x-6":"translate-x-1"}`})})]}),i.jsxs("div",{className:"space-y-3",children:[i.jsx("label",{className:"block text-sm text-bambu-gray",children:"Icon"}),i.jsxs("div",{className:"p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-sm text-white",children:"Custom Icon"}),i.jsx("input",{ref:s,type:"file",accept:"image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon",className:"hidden",onChange:R}),y&&x?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("img",{src:x,alt:"Custom icon",className:"w-8 h-8 rounded border border-bambu-dark-tertiary"}),i.jsx("button",{type:"button",onClick:P,className:"p-1 text-red-400 hover:text-red-300 transition-colors",title:"Remove custom icon",children:i.jsx(Jt,{className:"w-4 h-4"})})]}):i.jsxs(Oe,{type:"button",variant:"secondary",size:"sm",onClick:()=>s.current?.click(),children:[i.jsx(xi,{className:"w-4 h-4"}),"Upload"]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:"PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB."})]}),!y&&i.jsxs("div",{children:[i.jsx("span",{className:"text-sm text-bambu-gray block mb-2",children:"Or choose a preset icon"}),i.jsx(Wbe,{value:d,onChange:m})]})]}),i.jsxs("div",{className:"flex gap-3 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),i.jsxs(Oe,{type:"submit",disabled:H,className:"flex-1",children:[H?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(ts,{className:"w-4 h-4"}),a?"Save":"Add"]})]})]})]})})}function ket(){const{t}=Ft(),e=an(),[n,r]=w.useState(!1),[a,s]=w.useState(null),[o,l]=w.useState(null),[c,u]=w.useState(null),{data:d,isLoading:m}=et({queryKey:["external-links"],queryFn:be.getExternalLinks}),p=pt({mutationFn:N=>be.deleteExternalLink(N),onSuccess:()=>{e.invalidateQueries({queryKey:["external-links"]})}}),f=pt({mutationFn:N=>be.reorderExternalLinks(N),onSuccess:()=>{e.invalidateQueries({queryKey:["external-links"]})}}),y=(N,T)=>{u(T),N.dataTransfer.effectAllowed="move"},v=N=>{N.preventDefault(),N.dataTransfer.dropEffect="move"},x=(N,T)=>{if(N.preventDefault(),c===null||c===T||!d)return;const C=d.map(P=>P.id),A=C.indexOf(c),k=C.indexOf(T);if(A===-1||k===-1)return;const R=[...C];R.splice(A,1),R.splice(k,0,c),f.mutate(R),u(null)},g=N=>{l(N)},_=()=>{o&&(p.mutate(o.id),l(null))};return i.jsxs(i.Fragment,{children:[i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(xh,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:"Sidebar Links"})]}),i.jsxs(Oe,{size:"sm",onClick:()=>r(!0),children:[i.jsx(ar,{className:"w-4 h-4"}),"Add Link"]})]})}),i.jsxs(Dt,{children:[i.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Add external links to the sidebar navigation. Drag to reorder."}),m?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})}):d&&d.length>0?i.jsx("div",{className:"space-y-2",children:d.map(N=>{const T=sT(N.icon);return i.jsxs("div",{draggable:!0,onDragStart:C=>y(C,N.id),onDragOver:v,onDrop:C=>x(C,N.id),className:`flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${c===N.id?"opacity-50":""}`,children:[i.jsx(bh,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0"}),i.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray",children:i.jsx(T,{className:"w-4 h-4"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-white font-medium truncate",children:N.name}),i.jsx(Jr,{className:"w-3 h-3 text-bambu-gray flex-shrink-0"})]}),i.jsx("span",{className:"text-sm text-bambu-gray truncate block",children:N.url})]}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[i.jsx("button",{onClick:()=>s(N),className:"p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",title:t("common.edit"),children:i.jsx(Yi,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>g(N),disabled:p.isPending,className:"p-2 rounded-lg hover:bg-red-500/20 text-bambu-gray hover:text-red-400 transition-colors disabled:opacity-50",title:t("externalLinks.deleteLink"),children:i.jsx(Jt,{className:"w-4 h-4"})})]})]},N.id)})}):i.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[i.jsx(xh,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),i.jsx("p",{children:t("externalLinks.noLinksConfigured")}),i.jsx("p",{className:"text-sm",children:'Click "Add Link" to add one'})]})]})]}),(n||a)&&i.jsx(Net,{link:a,onClose:()=>{r(!1),s(null)}}),o&&i.jsx(Sn,{title:"Delete Link",message:`Are you sure you want to delete "${o.name}"? This action cannot be undone.`,confirmText:"Delete",cancelText:"Cancel",variant:"danger",onConfirm:_,onCancel:()=>l(null)})]})}const ID={immediate:"archive",review:"review",print_queue:"queue",proxy:"proxy"};function Cet({printer:t,models:e}){const{t:n}=Ft(),r=an(),{showToast:a}=fn(),[s,o]=w.useState(!0),[l,c]=w.useState(t.enabled),[u,d]=w.useState(t.name),[m,p]=w.useState(""),[f,y]=w.useState(t.mode==="queue"?"review":t.mode),[v,x]=w.useState(t.target_printer_id),[g,_]=w.useState(t.bind_ip||""),[N,T]=w.useState(t.remote_interface_ip||""),[C,A]=w.useState(t.model||""),[k,R]=w.useState(t.auto_dispatch??!0),[P,D]=w.useState(!1),[H,z]=w.useState(null),[G,I]=w.useState(!1);w.useEffect(()=>{H||(c(t.enabled),y(t.mode==="queue"?"review":t.mode),d(t.name),x(t.target_printer_id),_(t.bind_ip||""),T(t.remote_interface_ip||""),A(t.model||""),R(t.auto_dispatch??!0))},[t,H]);const{data:ee}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:ie}=et({queryKey:["network-interfaces"],queryFn:()=>be.getNetworkInterfaces().then(E=>E.interfaces)}),X=pt({mutationFn:E=>FN.update(t.id,E),onSuccess:()=>{r.invalidateQueries({queryKey:["virtual-printers"]}),a(n("virtualPrinter.toast.updated")),z(null)},onError:E=>{a(E.message||n("virtualPrinter.toast.failedToUpdate"),"error"),c(t.enabled),y(t.mode==="queue"?"review":t.mode),x(t.target_printer_id),_(t.bind_ip||""),z(null)}}),me=pt({mutationFn:()=>FN.remove(t.id),onSuccess:()=>{r.invalidateQueries({queryKey:["virtual-printers"]}),a(n("virtualPrinter.toast.deleted")),I(!1)},onError:E=>{a(E.message||n("virtualPrinter.toast.failedToDelete"),"error"),I(!1)}}),he=E=>{E.stopPropagation();const U=!l;if(U){if(!g){a(n("virtualPrinter.toast.bindIpRequired"),"error");return}if(f==="proxy"){if(!v){a(n("virtualPrinter.toast.targetPrinterRequired"),"error");return}}else if(!m&&!t.access_code_set){a(n("virtualPrinter.toast.accessCodeRequired"),"error");return}}c(U),z("toggle"),X.mutate({enabled:U})},ge=()=>{u.trim()&&(z("name"),X.mutate({name:u.trim()}))},Y=()=>{if(!m){a(n("virtualPrinter.toast.accessCodeEmpty"),"error");return}if(m.length!==8){a(n("virtualPrinter.toast.accessCodeLength"),"error");return}z("accessCode"),X.mutate({access_code:m}),p("")},oe=E=>{y(E),z("mode"),X.mutate({mode:E})},le=E=>{A(E),z("model"),X.mutate({model:E})},xe=E=>{x(E),z("targetPrinter"),X.mutate({target_printer_id:E})},Pe=E=>{T(E),z("remoteInterface"),X.mutate({remote_interface_ip:E})},q=t.status?.running||!1,Z=n(`virtualPrinter.mode.${ID[f]||"archive"}`),j=ee?.find(E=>E.id===v)?.name;return i.jsxs(i.Fragment,{children:[i.jsxs(Mt,{children:[i.jsxs("div",{className:"px-4 py-3 flex items-center gap-3 cursor-pointer select-none",onClick:()=>o(!s),children:[i.jsx("button",{className:"text-bambu-gray flex-shrink-0",children:s?i.jsx(Ln,{className:"w-4 h-4"}):i.jsx(ha,{className:"w-4 h-4"})}),i.jsx("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${q?"bg-green-400 animate-pulse":"bg-gray-500"}`}),i.jsx("span",{className:"text-white font-medium truncate",children:t.name}),i.jsx("span",{className:"text-xs text-bambu-gray flex-shrink-0",children:Z}),t.model_name&&i.jsx("span",{className:"text-xs text-bambu-gray flex-shrink-0",children:t.model_name}),j&&i.jsxs("span",{className:"text-xs text-bambu-gray flex-shrink-0 truncate",children:[f==="proxy"&&i.jsx(h3,{className:"w-3 h-3 inline mr-1"}),j]}),g&&i.jsx("span",{className:"text-[10px] text-bambu-gray flex-shrink-0 font-mono",children:g}),N&&i.jsx("span",{className:"text-[10px] text-bambu-gray flex-shrink-0 font-mono",children:N}),i.jsx("div",{className:"ml-auto flex items-center gap-2 flex-shrink-0",onClick:E=>E.stopPropagation(),children:i.jsx("button",{onClick:he,disabled:H==="toggle",className:`relative w-10 h-5 rounded-full transition-colors ${l?"bg-bambu-green":"bg-bambu-dark-tertiary"} ${H==="toggle"?"opacity-50":""}`,children:i.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${l?"translate-x-5":""}`})})})]}),s&&i.jsxs(Dt,{className:"pt-0 space-y-4",children:[i.jsx("div",{className:"border-t border-bambu-dark-tertiary"}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"text",value:u,onChange:E=>d(E.target.value),onBlur:ge,onKeyDown:E=>E.key==="Enter"&&ge(),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"}),i.jsx("span",{className:"text-xs text-bambu-gray font-mono",children:t.serial}),i.jsx("button",{onClick:()=>I(!0),className:"p-1.5 text-bambu-gray hover:text-red-400 transition-colors",title:n("common.delete"),children:i.jsx(Jt,{className:"w-4 h-4"})})]}),i.jsxs("div",{children:[i.jsx("div",{className:"text-white text-sm font-medium mb-2",children:n("virtualPrinter.mode.title")}),i.jsx("div",{className:"grid grid-cols-2 gap-2",children:["immediate","review","print_queue","proxy"].map(E=>i.jsxs("button",{onClick:()=>oe(E),disabled:H==="mode",className:`p-2 rounded-lg border text-left transition-colors ${f===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:[i.jsxs("div",{className:"flex items-center gap-1.5 text-white text-xs font-medium",children:[E==="proxy"&&i.jsx(h3,{className:"w-3 h-3"}),n(`virtualPrinter.mode.${ID[E]}`)]}),i.jsx("div",{className:"text-[10px] text-bambu-gray",children:n(`virtualPrinter.mode.${ID[E]}Desc`)})]},E))})]}),f==="print_queue"&&i.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.autoDispatch.title")}),i.jsx("div",{className:"text-[10px] text-bambu-gray",children:n("virtualPrinter.autoDispatch.description")})]}),i.jsx("button",{onClick:()=>{const E=!k;R(E),z("autoDispatch"),X.mutate({auto_dispatch:E})},disabled:H==="autoDispatch",className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${k?"bg-bambu-green":"bg-bambu-dark-tertiary"} ${H==="autoDispatch"?"opacity-50":""}`,children:i.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${k?"translate-x-5":""}`})})]})}),f!=="proxy"&&i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsx("div",{className:"text-white text-sm font-medium mb-1",children:n("virtualPrinter.model.title")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:n("virtualPrinter.model.description")}),i.jsxs("div",{className:"relative",children:[i.jsx("select",{value:C,onChange:E=>le(E.target.value),disabled:H==="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(e).map(([E,U])=>i.jsxs("option",{value:E,children:[U," (",E,")"]},E))}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),f==="proxy"&&i.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:i.jsxs("div",{className:"flex items-start gap-2 p-2 rounded bg-blue-500/10 border border-blue-500/30",children:[i.jsx(Ls,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("virtualPrinter.proxy.accessCodeHint")})]})}),f!=="proxy"&&i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.accessCode.title")}),t.access_code_set?i.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-400",children:[i.jsx(Yr,{className:"w-3 h-3"}),n("virtualPrinter.accessCode.isSet")]}):i.jsxs("span",{className:"flex items-center gap-1 text-xs text-yellow-400",children:[i.jsx(Mn,{className:"w-3 h-3"}),n("virtualPrinter.accessCode.notSet")]})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("input",{type:P?"text":"password",value:m,onChange:E=>p(E.target.value),placeholder:t.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"}),i.jsx("button",{onClick:()=>D(!P),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:P?i.jsx(mw,{className:"w-4 h-4"}):i.jsx(_c,{className:"w-4 h-4"})})]}),i.jsx(Oe,{onClick:Y,disabled:!m||H==="accessCode",variant:"primary",children:H==="accessCode"?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):n("common.save")})]}),m&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i.jsx("span",{className:m.length===8?"text-green-400":"text-yellow-400",children:n("virtualPrinter.accessCode.charCount",{count:m.length})})})]}),i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsx("div",{className:"text-white text-sm font-medium mb-2",children:n("virtualPrinter.targetPrinter.title")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:v??"",onChange:E=>{const U=parseInt(E.target.value,10);isNaN(U)||xe(U)},disabled:H==="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:[i.jsx("option",{value:"",children:n("virtualPrinter.targetPrinter.placeholder")}),ee?.map(E=>i.jsxs("option",{value:E.id,children:[E.name," (",E.ip_address,")"]},E.id))]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsx("div",{className:"text-white text-sm font-medium mb-1",children:n("virtualPrinter.bindIp.title")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:g,onChange:E=>{_(E.target.value),z("bindIp"),X.mutate({bind_ip:E.target.value})},disabled:H==="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:[i.jsx("option",{value:"",children:n("virtualPrinter.bindIp.placeholder")}),ie?.map(E=>i.jsxs("option",{value:E.ip,children:[E.name," (",E.ip,")",E.is_alias?" [alias]":""," - ",E.subnet]},E.ip))]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("virtualPrinter.bindIp.hint")})]}),i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[i.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.remoteInterface.title")}),N?i.jsx("span",{className:"flex items-center gap-1 text-xs text-green-400",children:i.jsx(Yr,{className:"w-3 h-3"})}):i.jsx("span",{className:"flex items-center gap-1 text-xs text-bambu-gray",title:n("virtualPrinter.remoteInterface.optional"),children:i.jsx(Ls,{className:"w-3 h-3"})})]}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:N,onChange:E=>Pe(E.target.value),disabled:H==="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:[i.jsx("option",{value:"",children:n("virtualPrinter.remoteInterface.placeholder")}),ie?.map(E=>i.jsxs("option",{value:E.ip,children:[E.name," (",E.ip,") - ",E.subnet]},E.ip))]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]})]})]}),G&&i.jsx(Sn,{title:n("virtualPrinter.deleteConfirm.title"),message:n("virtualPrinter.deleteConfirm.message",{name:t.name}),variant:"danger",confirmText:n("common.delete"),isLoading:me.isPending,onConfirm:()=>me.mutate(),onCancel:()=>I(!1)})]})}const kY={immediate:"archive",review:"review",print_queue:"queue",proxy:"proxy"};function Tet({onClose:t}){const{t:e}=Ft(),n=an(),{showToast:r}=fn(),[a,s]=w.useState(""),[o,l]=w.useState("immediate"),[c,u]=w.useState(null),{data:d}=et({queryKey:["printers"],queryFn:be.getPrinters}),m=pt({mutationFn:()=>FN.create({name:a.trim()||"Bambuddy",mode:o,target_printer_id:o==="proxy"?c??void 0:void 0}),onSuccess:()=>{n.invalidateQueries({queryKey:["virtual-printers"]}),r(e("virtualPrinter.toast.created")),t()},onError:p=>{r(p.message||e("virtualPrinter.toast.failedToCreate"),"error")}});return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:t,children:i.jsx(Mt,{className:"w-full max-w-md",onClick:p=>p.stopPropagation(),children:i.jsxs(Dt,{className:"p-6 space-y-4",children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:e("virtualPrinter.addDialog.title")}),i.jsxs("div",{children:[i.jsx("label",{className:"text-sm text-white font-medium block mb-1",children:e("virtualPrinter.addDialog.name")}),i.jsx("input",{type:"text",value:a,onChange:p=>s(p.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})]}),i.jsxs("div",{children:[i.jsx("label",{className:"text-sm text-white font-medium block mb-1",children:e("virtualPrinter.mode.title")}),i.jsx("div",{className:"grid grid-cols-2 gap-2",children:["immediate","review","print_queue","proxy"].map(p=>i.jsxs("button",{onClick:()=>l(p),className:`p-2 rounded-lg border text-left transition-colors ${o===p?p==="proxy"?"border-blue-500 bg-blue-500/10":"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[i.jsxs("div",{className:"flex items-center gap-1.5 text-white text-xs font-medium",children:[p==="proxy"&&i.jsx(h3,{className:"w-3 h-3"}),e(`virtualPrinter.mode.${kY[p]}`)]}),i.jsx("div",{className:"text-[10px] text-bambu-gray",children:e(`virtualPrinter.mode.${kY[p]}Desc`)})]},p))})]}),o==="proxy"&&i.jsxs("div",{children:[i.jsx("label",{className:"text-sm text-white font-medium block mb-1",children:e("virtualPrinter.targetPrinter.title")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:c??"",onChange:p=>{const f=parseInt(p.target.value,10);u(isNaN(f)?null:f)},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:[i.jsx("option",{value:"",children:e("virtualPrinter.targetPrinter.placeholder")}),d?.map(p=>i.jsxs("option",{value:p.id,children:[p.name," (",p.ip_address,")"]},p.id))]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:e("virtualPrinter.addDialog.hint")}),i.jsxs("div",{className:"flex gap-3 pt-2",children:[i.jsx(Oe,{variant:"secondary",onClick:t,className:"flex-1",disabled:m.isPending,children:e("common.cancel")}),i.jsx(Oe,{variant:"primary",onClick:()=>m.mutate(),className:"flex-1",disabled:m.isPending,children:m.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):e("virtualPrinter.addDialog.create")})]})]})})})}function Aet(){const{t}=Ft(),[e,n]=w.useState(!1),{data:r,isLoading:a}=et({queryKey:["virtual-printers"],queryFn:FN.list,refetchInterval:1e4});if(a)return i.jsx(Mt,{children:i.jsx(Dt,{className:"py-8 flex justify-center",children:i.jsx(ht,{className:"w-6 h-6 animate-spin text-bambu-green"})})});const s=r?.printers||[],o=r?.models||{};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-4 gap-4 items-stretch",children:[i.jsx(Mt,{className:"border-l-4 border-l-yellow-500",children:i.jsx(Dt,{className:"py-3 px-4",children:i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx(Mn,{className:"w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5"}),i.jsxs("div",{className:"text-xs",children:[i.jsx("p",{className:"text-white font-medium",children:t("virtualPrinter.setupRequired.title")}),i.jsx("p",{className:"text-bambu-gray mt-1",children:t("virtualPrinter.setupRequired.description")}),i.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-500/20 border border-yellow-500/50 rounded text-yellow-400 hover:bg-yellow-500/30 transition-colors text-xs",children:[i.jsx(Jr,{className:"w-3 h-3"}),t("virtualPrinter.setupRequired.readGuide")]})]})]})})}),i.jsx(Mt,{className:"lg:col-span-3",children:i.jsx(Dt,{className:"py-3 px-4",children:i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx(Ls,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[i.jsx("p",{className:"text-white font-medium mb-1",children:t("virtualPrinter.howItWorks.title")}),i.jsxs("ul",{className:"space-y-1 list-disc list-inside",children:[i.jsx("li",{children:t("virtualPrinter.howItWorks.step1")}),i.jsx("li",{children:t("virtualPrinter.howItWorks.step2")}),i.jsx("li",{children:t("virtualPrinter.howItWorks.step3")})]})]})]})})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Sr,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("virtualPrinter.list.title")}),i.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",s.length,")"]})]}),i.jsxs(Oe,{variant:"primary",onClick:()=>n(!0),children:[i.jsx(ar,{className:"w-4 h-4 mr-1"}),t("virtualPrinter.list.add")]})]}),s.length===0?i.jsx(Mt,{children:i.jsxs(Dt,{className:"py-8 text-center",children:[i.jsx(Sr,{className:"w-12 h-12 text-bambu-gray mx-auto mb-3"}),i.jsx("p",{className:"text-bambu-gray mb-4",children:t("virtualPrinter.list.empty")}),i.jsxs(Oe,{variant:"primary",onClick:()=>n(!0),children:[i.jsx(ar,{className:"w-4 h-4 mr-1"}),t("virtualPrinter.list.addFirst")]})]})}):i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 items-start",children:s.map(l=>i.jsx(Cet,{printer:l,models:o},l.id))}),e&&i.jsx(Tet,{onClose:()=>n(!1)})]})}function Pet(t){if(!t)return"-";const e=Jn(t);return e?e.toLocaleString():"-"}function CY({status:t}){if(!t)return null;const e={success:"bg-green-500/20 text-green-400",failed:"bg-red-500/20 text-red-400",skipped:"bg-yellow-500/20 text-yellow-400",running:"bg-blue-500/20 text-blue-400"},n={success:i.jsx(fr,{className:"w-3 h-3"}),failed:i.jsx(Vi,{className:"w-3 h-3"}),skipped:i.jsx($L,{className:"w-3 h-3"}),running:i.jsx(ht,{className:"w-3 h-3 animate-spin"})};return i.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium ${e[t]||"bg-gray-500/20 text-gray-400"}`,children:[n[t],t.charAt(0).toUpperCase()+t.slice(1)]})}function Met(){const t=an(),{showToast:e}=fn(),{t:n}=Ft(),[r,a]=w.useState(""),[s,o]=w.useState(""),[l,c]=w.useState("main"),[u,d]=w.useState(!1),[m,p]=w.useState("daily"),[f,y]=w.useState(!0),[v,x]=w.useState(!0),[g,_]=w.useState(!1),[N,T]=w.useState(!0),[C,A]=w.useState(!1),[k,R]=w.useState(!1),[P,D]=w.useState(""),[H,z]=w.useState(!1),[G,I]=w.useState(null),[ee,ie]=w.useState(null),X=w.useRef(null);w.useEffect(()=>{if(C||k){const L=F=>(F.preventDefault(),F.returnValue="A backup operation is in progress. Are you sure you want to leave?",F.returnValue);return window.addEventListener("beforeunload",L),()=>window.removeEventListener("beforeunload",L)}},[C,k]);const[me,he]=w.useState(!1),[ge,Y]=w.useState(null),oe=w.useRef(null),le=w.useRef(!1),{data:xe,isLoading:Pe}=et({queryKey:["github-backup-config"],queryFn:be.getGitHubBackupConfig}),{data:q}=et({queryKey:["github-backup-status"],queryFn:be.getGitHubBackupStatus,refetchInterval:ae=>ae.state.data?.is_running?500:1e4}),{data:Z}=et({queryKey:["github-backup-logs"],queryFn:()=>be.getGitHubBackupLogs(20)}),{data:j}=et({queryKey:["cloud-status"],queryFn:be.getCloudStatus}),{data:E}=et({queryKey:["printers"],queryFn:be.getPrinters}),U=Gf({queries:(E??[]).map(ae=>({queryKey:["printerStatus",ae.id],queryFn:()=>be.getPrinterStatus(ae.id),staleTime:1e4,refetchInterval:3e4}))}),K=(E??[]).map((ae,L)=>({printer:ae,connected:U[L]?.data?.connected??!1})),$=K.length,ne=K.filter(ae=>ae.connected).length,O=$>0&&ne===0,V=ne>0&&ne<$;w.useEffect(()=>{xe&&(a(xe.repository_url),c(xe.branch),d(xe.schedule_enabled),p(xe.schedule_type),y(xe.backup_kprofiles),x(xe.backup_cloud_profiles),_(xe.backup_settings),T(xe.enabled),o(""),setTimeout(()=>{le.current=!0},100))},[xe]);const J=w.useCallback(async(ae=!1)=>{if(xe?.has_token)try{ae&&s?(await be.saveGitHubBackupConfig({repository_url:r,access_token:s,branch:l,schedule_enabled:u,schedule_type:m,backup_kprofiles:f,backup_cloud_profiles:v,backup_settings:g,enabled:N}),o(""),e(n("backup.tokenUpdated"))):(await be.updateGitHubBackupConfig({repository_url:r,branch:l,schedule_enabled:u,schedule_type:m,backup_kprofiles:f,backup_cloud_profiles:v,backup_settings:g,enabled:N}),e(n("backup.settingsSaved"))),t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]})}catch(L){e(n("backup.failedToSave",{message:L.message}),"error")}},[xe?.has_token,r,s,l,u,m,f,v,g,N,t,e,n]);w.useEffect(()=>{if(!(!le.current||!xe?.has_token))return oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{J(!1)},500),()=>{oe.current&&clearTimeout(oe.current)}},[r,l,u,m,f,v,g,N,J,xe?.has_token]),w.useEffect(()=>{if(!(!le.current||!xe?.has_token||!s))return oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{J(!0)},1e3),()=>{oe.current&&clearTimeout(oe.current)}},[s,J,xe?.has_token]);const W=pt({mutationFn:ae=>be.saveGitHubBackupConfig(ae),onSuccess:()=>{t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]}),e(n("backup.githubBackupEnabled")),o(""),le.current=!0},onError:ae=>{e(n("backup.failedToSave",{message:ae.message}),"error")}}),re=pt({mutationFn:be.triggerGitHubBackup,onSuccess:ae=>{t.invalidateQueries({queryKey:["github-backup-status"]}),t.invalidateQueries({queryKey:["github-backup-logs"]}),ae.success?ae.files_changed>0?e(n("backup.backupCompleteFiles",{count:ae.files_changed})):e(n("backup.backupSkippedNoChanges")):e(n("backup.backupFailed2",{message:ae.message}),"error")},onError:ae=>{e(n("backup.backupFailed2",{message:ae.message}),"error")}}),ue=pt({mutationFn:()=>be.clearGitHubBackupLogs(0),onSuccess:ae=>{t.invalidateQueries({queryKey:["github-backup-logs"]}),e(n("backup.clearedLogs",{count:ae.deleted}))},onError:ae=>{e(n("backup.failedToClearLogs",{message:ae.message}),"error")}}),fe=async()=>{he(!0),Y(null);try{let ae;if(s){if(!r){e(n("backup.enterRepoUrl"),"error"),he(!1);return}ae=await be.testGitHubConnection(r,s)}else if(xe?.has_token)ae=await be.testGitHubStoredConnection();else{e(n("backup.enterRepoAndToken"),"error"),he(!1);return}Y({success:ae.success,message:ae.message})}catch(ae){Y({success:!1,message:ae.message})}finally{he(!1)}},ye=()=>{if(!r){e(n("backup.repoRequired"),"error");return}if(!s){e(n("backup.tokenRequired"),"error");return}W.mutate({repository_url:r,access_token:s,branch:l,schedule_enabled:u,schedule_type:m,backup_kprofiles:f,backup_cloud_profiles:v,backup_settings:g,enabled:N})};return Pe?i.jsx("div",{className:"flex items-center justify-center py-12",children:i.jsx(ht,{className:"w-8 h-8 animate-spin text-bambu-green"})}):i.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[i.jsxs("div",{className:"space-y-6",children:[i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(f3,{className:"w-5 h-5 text-gray-400"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.githubBackup")})]}),xe&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:n("backup.enabled")}),i.jsx(Bn,{checked:N,onChange:T})]})]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.githubDescription")}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.repositoryUrl")}),i.jsx("input",{type:"text",value:r,onChange:ae=>{a(ae.target.value),Y(null)},placeholder:"https://github.com/username/bambuddy-backup",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"})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[n("backup.personalAccessToken")," ",xe?.has_token&&i.jsx("span",{className:"text-green-400",children:n("backup.tokenSaved")})]}),i.jsx("input",{type:"password",value:s,onChange:ae=>{o(ae.target.value),Y(null)},placeholder:xe?.has_token?n("backup.enterNewToken"):"ghp_xxxxxxxxxxxx",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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("backup.tokenHint")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.branch")}),i.jsx("input",{type:"text",value:l,onChange:ae=>c(ae.target.value),placeholder:"main",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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.autoBackup")}),i.jsxs("select",{value:u?m:"disabled",onChange:ae=>{ae.target.value==="disabled"?d(!1):(d(!0),p(ae.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:[i.jsx("option",{value:"disabled",children:n("backup.manualOnly")}),i.jsx("option",{value:"hourly",children:n("backup.hourly")}),i.jsx("option",{value:"daily",children:n("backup.daily")}),i.jsx("option",{value:"weekly",children:n("backup.weekly")})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:n("backup.includeInBackup")}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("label",{className:`flex items-start gap-2 ${O?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:[i.jsx("input",{type:"checkbox",checked:f,onChange:ae=>y(ae.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:O}),i.jsxs("div",{className:"flex-1",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`text-sm ${O?"text-bambu-gray":"text-white"}`,children:n("backup.kProfiles")}),O&&i.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:[i.jsx(Mn,{className:"w-3 h-3"}),n("backup.noPrintersConnected")]}),V&&i.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:[i.jsx(Mn,{className:"w-3 h-3"}),n("backup.printersConnected",{connected:ne,total:$})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.kProfilesDescription")})]})]}),i.jsxs("label",{className:`flex items-start gap-2 ${j?.is_authenticated?"cursor-pointer":"cursor-not-allowed opacity-60"}`,children:[i.jsx("input",{type:"checkbox",checked:v,onChange:ae=>x(ae.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:!j?.is_authenticated}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`text-sm ${j?.is_authenticated?"text-white":"text-bambu-gray"}`,children:n("backup.cloudProfiles")}),!j?.is_authenticated&&i.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:[i.jsx(Mn,{className:"w-3 h-3"}),n("backup.cloudLoginRequiredShort")]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.cloudProfilesDescription")})]})]}),i.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:g,onChange:ae=>_(ae.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"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white text-sm",children:n("backup.appSettings")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.appSettingsDescription")})]})]})]})]}),i.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 space-y-3",children:[q?.configured&&i.jsxs("div",{className:"flex items-center justify-between text-sm",children:[i.jsx("div",{className:"flex items-center gap-2 text-bambu-gray",children:q.last_backup_at?i.jsxs(i.Fragment,{children:[i.jsxs("span",{children:[n("backup.lastBackupAt")," ",x0(q.last_backup_at,"system",n)]}),i.jsx(CY,{status:q.last_backup_status})]}):i.jsx("span",{children:n("backup.noBackupsYet")})}),q.next_scheduled_run&&i.jsxs("span",{className:"text-bambu-gray",children:[i.jsx(er,{className:"w-3 h-3 inline mr-1"}),n("backup.next")," ",x0(q.next_scheduled_run,"system",n)]})]}),ge&&i.jsxs("div",{className:`text-sm flex items-center gap-1 ${ge.success?"text-green-400":"text-red-400"}`,children:[ge.success?i.jsx(fr,{className:"w-4 h-4"}):i.jsx(Vi,{className:"w-4 h-4"}),ge.message]}),i.jsx("div",{className:"flex flex-wrap items-center gap-2",children:q?.configured?i.jsx(i.Fragment,{children:re.isPending||q.is_running?i.jsxs("div",{className:"flex items-center gap-2 text-bambu-green",children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),i.jsx("span",{className:"text-sm",children:q.progress||n("backup.startingBackup")})]}):i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"primary",size:"sm",onClick:()=>re.mutate(),disabled:!xe?.enabled,children:[i.jsx(go,{className:"w-4 h-4"}),n("backup.backupNow")]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:fe,disabled:me,children:[me?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(wr,{className:"w-4 h-4"}),n("backup.test")]})]})}):i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"primary",size:"sm",onClick:ye,disabled:W.isPending||!r||!s,children:[W.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(fr,{className:"w-4 h-4"}),n("backup.enableBackup")]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:fe,disabled:me||!r||!s,children:[me?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(wr,{className:"w-4 h-4"}),n("backup.testConnection")]})]})})]})]})]}),Z&&Z.length>0&&i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(f0,{className:"w-5 h-5 text-gray-400"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.history")})]}),i.jsxs(Oe,{variant:"ghost",size:"sm",onClick:()=>ue.mutate(),disabled:ue.isPending,children:[i.jsx(Jt,{className:"w-4 h-4"}),n("backup.clear")]})]})}),i.jsx(Dt,{children:i.jsx("div",{className:"overflow-x-auto",children:i.jsxs("table",{className:"w-full text-sm",children:[i.jsx("thead",{children:i.jsxs("tr",{className:"text-bambu-gray border-b border-bambu-dark-tertiary",children:[i.jsx("th",{className:"text-left py-2 px-2",children:n("backup.date")}),i.jsx("th",{className:"text-left py-2 px-2",children:n("backup.status")}),i.jsx("th",{className:"text-left py-2 px-2",children:n("backup.commit")})]})}),i.jsx("tbody",{children:Z.slice(0,10).map(ae=>i.jsxs("tr",{className:"border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-secondary",children:[i.jsx("td",{className:"py-2 px-2 text-white",children:Pet(ae.started_at)}),i.jsx("td",{className:"py-2 px-2",children:i.jsx(CY,{status:ae.status})}),i.jsx("td",{className:"py-2 px-2",children:ae.commit_sha?i.jsxs("a",{href:`${xe?.repository_url}/commit/${ae.commit_sha}`,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-green hover:underline inline-flex items-center gap-1",children:[ae.commit_sha.substring(0,7),i.jsx(Jr,{className:"w-3 h-3"})]}):i.jsx("span",{className:"text-bambu-gray",children:"-"})})]},ae.id))})]})})})]})]}),i.jsx("div",{className:"space-y-6",children:i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(au,{className:"w-5 h-5 text-gray-400"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.localBackup")})]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.localBackupDescription")}),i.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:n("backup.downloadBackupLabel")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.completeBackupZip")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",disabled:C||k,onClick:async()=>{A(!0),D(n("backup.preparingBackup"));try{D(n("backup.creatingArchive"));const{blob:ae,filename:L}=await be.exportBackup();D(n("backup.downloadingFile"));const F=URL.createObjectURL(ae),te=document.createElement("a");te.href=F,te.download=L,te.click(),URL.revokeObjectURL(F),e(n("backup.backupDownloaded"))}catch(ae){e(n("backup.failedToCreateBackup",{message:ae instanceof Error?ae.message:"Unknown error"}),"error")}finally{A(!1),D("")}},children:[i.jsx(pi,{className:"w-4 h-4"}),n("backup.download")]})]}),i.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:n("backup.restoreBackup")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.restoreDescription")}),i.jsx("p",{className:"text-xs text-bambu-gray-light mt-1",children:n("backup.restoreNote")})]}),i.jsx("input",{ref:X,type:"file",accept:".zip",className:"hidden",onChange:ae=>{const L=ae.target.files?.[0];L&&(I(L),z(!0)),ae.target.value=""}}),i.jsxs(Oe,{variant:"secondary",size:"sm",disabled:k||C,onClick:()=>X.current?.click(),children:[i.jsx(xi,{className:"w-4 h-4"}),n("backup.restore")]})]}),ee&&i.jsx("div",{className:`p-3 rounded-lg ${ee.success?"bg-green-500/10 border border-green-500/30":"bg-red-500/10 border border-red-500/30"}`,children:i.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[ee.success?i.jsx(fr,{className:"w-4 h-4 text-green-400 mt-0.5 flex-shrink-0"}):i.jsx(Vi,{className:"w-4 h-4 text-red-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:ee.success?"text-green-200":"text-red-200",children:[ee.message,ee.success&&i.jsx("div",{className:"mt-2",children:i.jsxs(Oe,{size:"sm",onClick:()=>window.location.reload(),children:[i.jsx(bo,{className:"w-3 h-3"}),n("backup.reloadNow")]})})]})]})}),i.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:i.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[i.jsx(Mn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"text-yellow-200",children:[i.jsx("span",{className:"font-medium",children:n("backup.restoreReplacesAll")})," ",i.jsx("span",{className:"text-yellow-200/70",children:n("backup.restoreReplacesAllDetail")})]})]})})]})]})}),H&&G&&i.jsx(Sn,{title:n("backup.restoreConfirmTitle"),message:n("backup.restoreConfirmMessage",{filename:G.name}),confirmText:n("backup.restoreConfirmButton"),variant:"danger",onConfirm:async()=>{z(!1),R(!0),ie(null);try{D(n("backup.uploadingFile"));const ae=await be.importBackup(G);ie(ae),ae.success?e(n("backup.backupRestoredRestart"),"success"):e(ae.message,"error")}catch(ae){const L=ae instanceof Error?ae.message:n("backup.failedToRestore");ie({success:!1,message:L}),e(L,"error")}finally{R(!1),D(""),I(null)}},onCancel:()=>{z(!1),I(null)}}),(C||k)&&i.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-[100]",children:i.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:[i.jsx("div",{className:"flex justify-center mb-4",children:i.jsxs("div",{className:"relative",children:[i.jsx("div",{className:"w-16 h-16 border-4 border-bambu-dark-tertiary rounded-full"}),i.jsx("div",{className:"w-16 h-16 border-4 border-bambu-green border-t-transparent rounded-full absolute inset-0 animate-spin"})]})}),i.jsx("h3",{className:"text-xl font-semibold text-white mb-2",children:n(C?"backup.creatingBackup":"backup.restoringBackup")}),i.jsx("p",{className:"text-bambu-gray mb-4",children:P||n(C?"backup.preparing":"backup.processing")}),i.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:i.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[i.jsx(Mn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),i.jsx("p",{className:"text-yellow-200 text-left",children:n("backup.doNotClosePage")})]})})]})})]})}const Eet={starttls:587,ssl:465,none:25},jet={587:"starttls",465:"ssl",25:"none"};function Det(){const{t}=Ft(),{showToast:e}=fn(),n=an(),[r,a]=w.useState({smtp_host:"",smtp_port:587,smtp_username:"",smtp_password:"",smtp_security:"starttls",smtp_auth_enabled:!0,smtp_from_email:"",smtp_from_name:"BamBuddy"}),[s,o]=w.useState(""),{data:l,isLoading:c}=et({queryKey:["smtpSettings"],queryFn:()=>be.getSMTPSettings()}),{authEnabled:u}=_r(),{data:d}=et({queryKey:["advancedAuthStatus"],queryFn:()=>be.getAdvancedAuthStatus()});w.useEffect(()=>{l&&a({...l,smtp_password:""})},[l]);const m=k=>{a({...r,smtp_security:k,smtp_port:Eet[k]})},p=k=>{const R=jet[k];a({...r,smtp_port:k,...R?{smtp_security:R}:{}})},f=k=>{a({...r,smtp_auth_enabled:k,...k?{}:{smtp_username:"",smtp_password:""}})},y=pt({mutationFn:k=>be.saveSMTPSettings(k),onSuccess:()=>{n.invalidateQueries({queryKey:["smtpSettings"]}),n.invalidateQueries({queryKey:["advancedAuthStatus"]}),e(t("settings.email.success.settingsSaved"),"success")},onError:k=>{e(k.message,"error")}}),v=pt({mutationFn:k=>be.testSMTP(k),onSuccess:k=>{e(k.message,k.success?"success":"error")},onError:k=>{e(k.message,"error")}}),x=pt({mutationFn:k=>k?be.enableAdvancedAuth():be.disableAdvancedAuth(),onSuccess:k=>{n.invalidateQueries({queryKey:["advancedAuthStatus"]}),e(k.message,"success")},onError:k=>{e(k.message,"error")}}),g=()=>{if(!r.smtp_host||!r.smtp_from_email){e(t("settings.email.errors.requiredFields"),"error");return}if(r.smtp_auth_enabled&&!r.smtp_username){e(t("settings.email.errors.usernameRequired"),"error");return}y.mutate(r)},_=()=>{if(!s){e(t("settings.email.errors.enterTestEmail"),"error");return}v.mutate({test_recipient:s})},N=()=>{if(!u){e(t("settings.email.errors.enableAuthFirst"),"error");return}if(!d?.advanced_auth_enabled&&!d?.smtp_configured){e(t("settings.email.errors.configureSmtpFirst"),"error");return}x.mutate(!d?.advanced_auth_enabled)};if(c)return i.jsx("div",{className:"flex items-center justify-center p-12",children:i.jsx(ht,{className:"w-8 h-8 animate-spin text-bambu-green"})});const T=d?.advanced_auth_enabled??!1,C="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",A="w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white/40 placeholder-bambu-gray/40 cursor-not-allowed";return i.jsxs("div",{className:"space-y-6",children:[i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(ix,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.advancedAuth")||"Advanced Authentication"})]}),i.jsx(Oe,{onClick:N,disabled:x.isPending,variant:T?"danger":"primary",children:T?i.jsxs(i.Fragment,{children:[i.jsx(K1,{className:"w-4 h-4"}),t("settings.email.disable")||"Disable"]}):i.jsxs(i.Fragment,{children:[i.jsx(Ap,{className:"w-4 h-4"}),t("settings.email.enable")||"Enable"]})})]})}),i.jsx(Dt,{children:i.jsx("div",{className:"space-y-4",children:T?i.jsx("div",{className:"bg-green-500/10 border border-green-500/30 rounded-lg p-4",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(fr,{className:"w-5 h-5 text-green-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-white font-medium",children:t("settings.email.advancedAuthEnabled")||"Advanced Authentication is enabled"}),i.jsxs("ul",{className:"text-sm text-green-300 space-y-1 list-disc list-inside",children:[i.jsx("li",{children:t("settings.email.feature1")||"Passwords are auto-generated and emailed to new users"}),i.jsx("li",{children:t("settings.email.feature2")||"Users can login with username or email"}),i.jsx("li",{children:t("settings.email.feature3")||"Forgot password feature is available"}),i.jsx("li",{children:t("settings.email.feature4")||"Admins can reset user passwords via email"})]})]})]})}):i.jsx("div",{className:"bg-yellow-500/10 border border-yellow-500/30 rounded-lg p-4",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Mn,{className:"w-5 h-5 text-yellow-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-white font-medium",children:t("settings.email.advancedAuthDisabled")||"Advanced Authentication is disabled"}),i.jsx("p",{className:"text-sm text-yellow-300",children:t("settings.email.advancedAuthDisabledDesc")||"Enable advanced authentication to activate email-based features for user management."})]})]})})})})]}),i.jsx("div",{children:i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.smtpSettings")||"SMTP Configuration"})}),i.jsx(Dt,{children:i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.authentication")||"Authentication"}),i.jsxs("select",{value:r.smtp_auth_enabled?"true":"false",onChange:k=>f(k.target.value==="true"),className:C,children:[i.jsx("option",{value:"true",children:t("settings.email.authOptions.enabled")}),i.jsx("option",{value:"false",children:t("settings.email.authOptions.disabled")})]})]}),i.jsxs("div",{className:`grid grid-cols-1 md:grid-cols-2 gap-4 transition-opacity ${r.smtp_auth_enabled?"":"opacity-40 pointer-events-none"}`,children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.username")||"Username"}),i.jsx("input",{type:"text",value:r.smtp_username||"",onChange:k=>a({...r,smtp_username:k.target.value}),placeholder:"your.email@gmail.com",disabled:!r.smtp_auth_enabled,className:r.smtp_auth_enabled?C:A})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.password")||"Password"}),i.jsx("input",{type:"password",value:r.smtp_password||"",onChange:k=>a({...r,smtp_password:k.target.value}),placeholder:l?"••••••••":"App password",disabled:!r.smtp_auth_enabled,className:r.smtp_auth_enabled?C:A})]})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[t("settings.email.smtpHost")||"SMTP Server"," *"]}),i.jsx("input",{type:"text",value:r.smtp_host,onChange:k=>a({...r,smtp_host:k.target.value}),placeholder:"smtp.gmail.com",className:C})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.smtpPort")||"SMTP Port"}),i.jsx("input",{type:"number",value:r.smtp_port,onChange:k=>p(parseInt(k.target.value)||587),placeholder:"587",className:C})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.security")||"Security"}),i.jsxs("select",{value:r.smtp_security,onChange:k=>m(k.target.value),className:C,children:[i.jsx("option",{value:"starttls",children:t("settings.email.securityOptions.starttls")}),i.jsx("option",{value:"ssl",children:t("settings.email.securityOptions.ssl")}),i.jsx("option",{value:"none",children:t("settings.email.securityOptions.none")})]})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[t("settings.email.fromEmail")||"From Email"," *"]}),i.jsx("input",{type:"email",value:r.smtp_from_email,onChange:k=>a({...r,smtp_from_email:k.target.value}),placeholder:"your@email.com",className:C})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.fromName")||"From Name"}),i.jsx("input",{type:"text",value:r.smtp_from_name,onChange:k=>a({...r,smtp_from_name:k.target.value}),placeholder:"BamBuddy",className:C})]})]}),i.jsx("div",{className:"flex gap-2",children:i.jsx(Oe,{onClick:g,disabled:y.isPending,className:"flex-1",children:y.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),t("settings.email.saving")||"Saving..."]}):t("settings.email.save")||"Save Settings"})})]})})]})}),i.jsx("div",{children:i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.testConnection")||"Test SMTP Connection"})}),i.jsx(Dt,{children:i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.testRecipient")||"Test Recipient Email"}),i.jsx("input",{type:"email",value:s,onChange:k=>o(k.target.value),placeholder:"test@example.com",className:C})]}),i.jsx(Oe,{onClick:_,disabled:v.isPending,variant:"secondary",children:v.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),t("settings.email.sending")||"Sending..."]}):i.jsxs(i.Fragment,{children:[i.jsx(rT,{className:"w-4 h-4"}),t("settings.email.sendTest")||"Send Test Email"]})})]})})]})})]})}const Ret={get:"bg-blue-500/20 text-blue-400 border-blue-500/30",post:"bg-green-500/20 text-green-400 border-green-500/30",put:"bg-yellow-500/20 text-yellow-400 border-yellow-500/30",patch:"bg-orange-500/20 text-orange-400 border-orange-500/30",delete:"bg-red-500/20 text-red-400 border-red-500/30"};function Fet(t,e){const n=e.replace("#/","").split("/");let r=t;for(const a of n)r=r[a];return r}function Ov(t,e,n=0){if(n>5)return"...";if(e.$ref)return Ov(t,Fet(t,e.$ref),n+1);if(e.allOf){const r={};for(const a of e.allOf){const s=Ov(t,a,n+1);typeof s=="object"&&s!==null&&Object.assign(r,s)}return r}if(e.example!==void 0)return e.example;if(e.default!==void 0)return e.default;switch(e.type){case"string":return e.enum?e.enum[0]:"string";case"integer":case"number":return 0;case"boolean":return!1;case"array":return e.items?[Ov(t,e.items,n+1)]:[];case"object":if(e.properties){const r={};for(const[a,s]of Object.entries(e.properties))r[a]=Ov(t,s,n+1);return r}return{};default:return null}}function Let({path:t,method:e,spec:n,schema:r,apiKey:a}){const[s,o]=w.useState(!1),[l,c]=w.useState({}),[u,d]=w.useState(""),[m,p]=w.useState(null),[f,y]=w.useState(!1),[v,x]=w.useState(!1);w.useEffect(()=>{if(s&&n.parameters){const R={};for(const P of n.parameters)P.schema?.default!==void 0&&(R[P.name]=String(P.schema.default));c(P=>({...R,...P}))}},[s,n.parameters]),w.useEffect(()=>{if(s&&n.requestBody?.content?.["application/json"]?.schema&&!u){const R=n.requestBody.content["application/json"].schema,P=Ov(r,R);d(JSON.stringify(P,null,2))}},[s,n.requestBody,r,u]);const _=(()=>{const R=[];for(const P of n.parameters||[])if(P.in==="path"||P.required){const D=l[P.name];(D===void 0||D==="")&&R.push(P.name)}return R})(),N=async()=>{if(_.length>0){p({status:0,statusText:"Validation Error",headers:{},body:`Missing required parameters: ${_.join(", ")}`,duration:0});return}y(!0),p(null);try{let R=t;const P=new URLSearchParams;for(const ge of n.parameters||[]){const Y=l[ge.name];Y!==void 0&&Y!==""&&(ge.in==="path"?R=R.replace(`{${ge.name}}`,encodeURIComponent(Y)):ge.in==="query"&&P.append(ge.name,Y))}const D=P.toString(),H=`${R}${D?`?${D}`:""}`,z={"Content-Type":"application/json"};a&&(z["X-API-Key"]=a);const G={method:e.toUpperCase(),headers:z};["post","put","patch"].includes(e)&&u&&(G.body=u);const I=performance.now(),ee=await fetch(H,G),ie=Math.round(performance.now()-I),X={};ee.headers.forEach((ge,Y)=>{X[Y]=ge});let me;ee.headers.get("content-type")?.includes("application/json")?me=await ee.json():me=await ee.text(),p({status:ee.status,statusText:ee.statusText,headers:X,body:me,duration:ie})}catch(R){p({status:0,statusText:"Network Error",headers:{},body:R instanceof Error?R.message:"Unknown error",duration:0})}finally{y(!1)}},T=async()=>{if(m){const R=typeof m.body=="string"?m.body:JSON.stringify(m.body,null,2);try{await navigator.clipboard.writeText(R),x(!0),setTimeout(()=>x(!1),2e3)}catch{const P=document.createElement("textarea");P.value=R,P.style.position="fixed",P.style.left="-999999px",document.body.appendChild(P),P.select(),document.execCommand("copy"),document.body.removeChild(P),x(!0),setTimeout(()=>x(!1),2e3)}}},C=(n.parameters||[]).filter(R=>R.in==="path"),A=(n.parameters||[]).filter(R=>R.in==="query"),k=["post","put","patch"].includes(e)&&n.requestBody;return i.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[i.jsxs("button",{onClick:()=>o(!s),className:"w-full flex items-center gap-3 p-3 hover:bg-bambu-dark-tertiary/50 transition-colors text-left",children:[s?i.jsx(Ln,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}):i.jsx(ha,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),i.jsx("span",{className:`px-2 py-0.5 text-xs font-mono font-semibold uppercase rounded border ${Ret[e]||"bg-gray-500/20 text-gray-400"}`,children:e}),i.jsx("code",{className:"text-sm text-white font-mono flex-1 truncate",children:t}),n.summary&&i.jsx("span",{className:"text-sm text-bambu-gray truncate max-w-[40%]",children:n.summary})]}),s&&i.jsxs("div",{className:"border-t border-bambu-dark-tertiary p-4 space-y-4 bg-bambu-dark/50",children:[n.description&&i.jsx("p",{className:"text-sm text-bambu-gray",children:n.description}),C.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("h4",{className:"text-sm font-medium text-white",children:"Path Parameters"}),i.jsx("div",{className:"space-y-2",children:C.map(R=>i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[R.name,R.required&&i.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),i.jsx("input",{type:"text",value:l[R.name]||"",onChange:P=>c(D=>({...D,[R.name]:P.target.value})),placeholder:R.description||R.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"})]},R.name))})]}),A.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("h4",{className:"text-sm font-medium text-white",children:"Query Parameters"}),i.jsx("div",{className:"space-y-2",children:A.map(R=>i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[R.name,R.required&&i.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),R.schema?.enum?i.jsxs("select",{value:l[R.name]||"",onChange:P=>c(D=>({...D,[R.name]:P.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:[i.jsx("option",{value:"",children:"-- Select --"}),R.schema.enum.map(P=>i.jsx("option",{value:P,children:P},P))]}):i.jsx("input",{type:"text",value:l[R.name]||"",onChange:P=>c(D=>({...D,[R.name]:P.target.value})),placeholder:R.description||R.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"})]},R.name))})]}),k&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("h4",{className:"text-sm font-medium text-white",children:"Request Body"}),i.jsx("textarea",{value:u,onChange:R=>d(R.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..."})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs(Oe,{onClick:N,disabled:f,children:[f?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(go,{className:"w-4 h-4"}),"Execute"]}),_.length>0&&i.jsxs("span",{className:"text-xs text-yellow-400 flex items-center gap-1",children:[i.jsx(Li,{className:"w-3 h-3"}),"Fill in: ",_.join(", ")]})]}),m&&i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h4",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Response",i.jsxs("span",{className:`px-2 py-0.5 text-xs rounded ${m.status>=200&&m.status<300?"bg-green-500/20 text-green-400":m.status>=400?"bg-red-500/20 text-red-400":"bg-yellow-500/20 text-yellow-400"}`,children:[m.status," ",m.statusText]}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:[m.duration,"ms"]})]}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:T,children:v?i.jsx(fr,{className:"w-3 h-3 text-green-400"}):i.jsx(fo,{className:"w-3 h-3"})})]}),i.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 m.body=="string"?m.body:JSON.stringify(m.body,null,2)})]})]})]})}function Oet({apiKey:t=""}){const[e,n]=w.useState(null),[r,a]=w.useState(!0),[s,o]=w.useState(null),[l,c]=w.useState(new Set),[u,d]=w.useState("");if(w.useEffect(()=>{async function x(){try{const g=await fetch("/openapi.json");if(!g.ok)throw new Error("Failed to fetch OpenAPI schema");const _=await g.json();n(_)}catch(g){o(g instanceof Error?g.message:"Unknown error")}finally{a(!1)}}x()},[]),r)return i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})});if(s||!e)return i.jsx(Mt,{children:i.jsx(Dt,{className:"py-8",children:i.jsxs("div",{className:"text-center text-red-400",children:[i.jsx(Li,{className:"w-12 h-12 mx-auto mb-3 opacity-50"}),i.jsx("p",{children:"Failed to load API schema"}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:s})]})})});const m={};for(const[x,g]of Object.entries(e.paths))for(const[_,N]of Object.entries(g)){if(_==="parameters")continue;const T=N.tags||["Other"];for(const C of T)m[C]||(m[C]=[]),m[C].push({path:x,method:_,spec:N})}const p=Object.entries(m).map(([x,g])=>{if(!u)return{tag:x,endpoints:g};const _=g.filter(({path:N,method:T,spec:C})=>{const A=u.toLowerCase();return N.toLowerCase().includes(A)||T.toLowerCase().includes(A)||(C.summary?.toLowerCase()||"").includes(A)||(C.description?.toLowerCase()||"").includes(A)});return{tag:x,endpoints:_}}).filter(({endpoints:x})=>x.length>0).sort((x,g)=>x.tag.localeCompare(g.tag)),f=x=>{c(g=>{const _=new Set(g);return _.has(x)?_.delete(x):_.add(x),_})},y=()=>{c(new Set(p.map(x=>x.tag)))},v=()=>{c(new Set)};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between gap-4",children:[i.jsx("div",{className:"flex-1",children:i.jsx("input",{type:"text",value:u,onChange:x=>d(x.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"})}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Oe,{variant:"secondary",size:"sm",onClick:y,children:"Expand All"}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:v,children:"Collapse All"}),i.jsxs("a",{href:"/docs",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-sm text-bambu-green hover:underline",children:[i.jsx(Jr,{className:"w-4 h-4"}),"Swagger UI"]})]})]}),i.jsxs("p",{className:"text-sm text-bambu-gray",children:[p.reduce((x,g)=>x+g.endpoints.length,0)," endpoints in ",p.length," categories"]}),i.jsx("div",{className:"space-y-3",children:p.map(({tag:x,endpoints:g})=>i.jsxs(Mt,{children:[i.jsx("button",{onClick:()=>f(x),className:"w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/30 transition-colors text-left",children:i.jsxs("div",{className:"flex items-center gap-2",children:[l.has(x)?i.jsx(Ln,{className:"w-5 h-5 text-bambu-gray"}):i.jsx(ha,{className:"w-5 h-5 text-bambu-gray"}),i.jsx("h3",{className:"text-base font-semibold text-white capitalize",children:x.replace(/-/g," ")}),i.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-2 py-0.5 rounded-full text-bambu-gray",children:g.length})]})}),l.has(x)&&i.jsx(Dt,{className:"pt-0 space-y-2",children:g.map(({path:_,method:N,spec:T})=>i.jsx(Let,{path:_,method:N,spec:T,schema:e,apiKey:t},`${N}-${_}`))})]},x))})]})}const Iet=["general","network","plugs","notifications","filament","apikeys","virtual-printer","users","backup"],zet={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"},TY=["bg-blue-500","bg-green-500","bg-yellow-500","bg-red-500","bg-orange-500","bg-teal-500","bg-cyan-500","bg-purple-500"],AY=(t,e)=>zet[t]||TY[e%TY.length];function Uet(){const t=an(),e=Qo(),[n,r]=ML(),{t:a,i18n:s}=Ft(),{showToast:o}=fn(),{authEnabled:l,user:c,refreshAuth:u}=_r(),{mode:d,darkStyle:m,darkBackground:p,darkAccent:f,lightStyle:y,lightBackground:v,lightAccent:x,setDarkStyle:g,setDarkBackground:_,setDarkAccent:N,setLightStyle:T,setLightBackground:C,setLightAccent:A}=Wf(),[k,R]=w.useState(null),[P,D]=w.useState(!1),[H,z]=w.useState(null),[G,I]=w.useState(!1),[ee,ie]=w.useState(null),[X,me]=w.useState(null),[he,ge]=w.useState(!1),[Y,oe]=w.useState(cQ()),le=n.get("tab"),xe=le==="email",Pe=xe?"users":le&&Iet.includes(le)?le:"general",[q,Z]=w.useState(Pe),[j,E]=w.useState(xe?"email":"users"),U=_e=>{Z(_e),_e==="users"&&E("users"),_e==="general"?n.delete("tab"):n.set("tab",_e),r(n,{replace:!0})},[K,$]=w.useState(!1),[ne,O]=w.useState(""),[V,J]=w.useState({can_queue:!0,can_control_printer:!1,can_read_status:!0}),[W,re]=w.useState(null),[ue,fe]=w.useState(null),[ye,ae]=w.useState(""),[L,F]=w.useState(!1),[te,ve]=w.useState(!1),[pe,de]=w.useState(null),[Ne,Se]=w.useState(!1),[Le,qe]=w.useState(!1),[Ee,Te]=w.useState(!1),[Ae,Be]=w.useState({currentPassword:"",newPassword:"",confirmPassword:""}),[je,Xe]=w.useState(!1),[ce,Ie]=w.useState(!1),[Ce,Ge]=w.useState(!1),[$e,Ue]=w.useState(!1),[De,Ve]=w.useState(null),[it,xt]=w.useState(null),[Nt,kt]=w.useState(null),[We,yt]=w.useState(!1),[wt,_t]=w.useState({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),[Ot,Vt]=w.useState(null),[Xt,Qe]=w.useState(null),[Qt,hn]=w.useState(!1),[jn,kn]=w.useState({}),[Fe,tt]=w.useState({}),ut=_e=>{oe(_e),uxe(_e),o(a("settings.toast.settingsSaved"),"success")},Ze=()=>{localStorage.removeItem("sidebarOrder"),window.location.reload()},{data:ke,isLoading:ot}=et({queryKey:["settings"],queryFn:be.getSettings}),{data:se,isLoading:He,isFetching:Ke}=et({queryKey:["storage-usage"],queryFn:()=>be.getStorageUsage(),enabled:q==="general",staleTime:1/0,refetchInterval:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1}),Ye=async()=>{Ie(!0);try{const _e=await be.getStorageUsage({refresh:!0});t.setQueryData(["storage-usage"],_e)}catch(_e){const zt=_e instanceof Error?_e.message:"Failed to refresh storage usage";o(zt,"error")}finally{Ie(!1)}},{data:Me,isLoading:dt}=et({queryKey:["smart-plugs"],queryFn:be.getSmartPlugs}),{data:ct,isLoading:nt}=et({queryKey:["smart-plugs-energy",Me?.map(_e=>_e.id)],queryFn:async()=>{if(!Me||Me.length===0)return null;const _e=await Promise.all(Me.filter(un=>un.enabled).map(async un=>{try{const In=await be.getSmartPlugStatus(un.id);return{plug:un,status:In}}catch{return{plug:un,status:null}}}));let zt=0,mt=0,Pt=0,rn=0,rt=0;for(const{plug:un,status:In}of _e){const Vn=un.plug_type==="mqtt"&&In?.energy?.power!=null;(In?.reachable||Vn)&&In?.energy&&(rt++,In.energy?.power!=null&&(zt+=In.energy.power),In.energy?.today!=null&&(mt+=In.energy.today),In.energy?.yesterday!=null&&(Pt+=In.energy.yesterday),In.energy?.total!=null&&(rn+=In.energy.total))}return{totalPower:zt,totalToday:mt,totalYesterday:Pt,totalLifetime:rn,reachableCount:rt,totalPlugs:Me.filter(un=>un.enabled).length}},enabled:q==="plugs"&&!!Me&&Me.length>0,refetchInterval:q==="plugs"?1e4:!1}),{data:bt,isLoading:Ut}=et({queryKey:["notification-providers"],queryFn:be.getNotificationProviders}),{data:Et,isLoading:It}=et({queryKey:["api-keys"],queryFn:be.getAPIKeys}),Zt=pt({mutationFn:_e=>be.createAPIKey(_e),onSuccess:_e=>{re(_e.key||null),$(!1),O(""),t.invalidateQueries({queryKey:["api-keys"]}),o(a("settings.toast.apiKeyCreated"))},onError:_e=>{o(`Failed to create API key: ${_e.message}`,"error")}}),tn=pt({mutationFn:_e=>be.deleteAPIKey(_e),onSuccess:()=>{t.invalidateQueries({queryKey:["api-keys"]}),o(a("settings.toast.apiKeyDeleted"))},onError:_e=>{o(`Failed to delete API key: ${_e.message}`,"error")}}),{data:yn}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:_n,isLoading:qn}=et({queryKey:["notification-templates"],queryFn:be.getNotificationTemplates}),{data:sn}=et({queryKey:["virtual-printer-settings"],queryFn:Bbe.getSettings,refetchInterval:1e4}),Cn=sn?.status?.running??!1,{data:gn}=et({queryKey:["ffmpeg-status"],queryFn:be.checkFfmpeg}),{data:Qr}=et({queryKey:["version"],queryFn:be.getVersion}),{data:Tn,refetch:hr,isRefetching:_a}=et({queryKey:["updateCheck"],queryFn:be.checkForUpdates,enabled:ke?.check_updates!==!1,staleTime:300*1e3}),{data:On,refetch:$r}=et({queryKey:["updateStatus"],queryFn:be.getUpdateStatus,refetchInterval:_e=>{const zt=_e.state.data;return zt?.status==="downloading"||zt?.status==="installing"?1e3:!1}}),{data:cr}=et({queryKey:["mqtt-status"],queryFn:be.getMQTTStatus,refetchInterval:q==="network"?5e3:!1}),{data:li}=et({queryKey:["github-backup-status"],queryFn:be.getGitHubBackupStatus}),{data:_i}=et({queryKey:["cloud-status"],queryFn:be.getCloudStatus}),{data:Tr={advanced_auth_enabled:!1,smtp_configured:!1}}=et({queryKey:["advancedAuthStatus"],queryFn:()=>be.getAdvancedAuthStatus()}),{hasPermission:zi}=_r(),{data:Zd=[],isLoading:Yh}=et({queryKey:["users"],queryFn:()=>be.getUsers(),enabled:l&&zi("users:read")}),{data:Ss=[],isLoading:eg}=et({queryKey:["groups"],queryFn:()=>be.getGroups(),enabled:l&&zi("groups:read")}),Yl=pt({mutationFn:_e=>be.createUser(_e),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),Ge(!1),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),o(a("settings.toast.userCreated"))},onError:_e=>{o(_e.message,"error")}}),_s=pt({mutationFn:({id:_e,data:zt})=>be.updateUser(_e,zt),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),Ue(!1),Ve(null),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),o(a("settings.toast.userUpdated"))},onError:_e=>{o(_e.message,"error")}}),ci=pt({mutationFn:({id:_e,deleteItems:zt})=>be.deleteUser(_e,zt),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),o(a("settings.toast.userDeleted")),xt(null),kt(null)},onError:_e=>{o(_e.message,"error")}}),Xl=pt({mutationFn:_e=>be.resetUserPassword({user_id:_e}),onSuccess:_e=>{o(_e.message,"success")},onError:_e=>{o(_e.message,"error")}}),Ns=async _e=>{xt(_e),yt(!0);try{const zt=await be.getUserItemsCount(_e);kt(zt)}catch{kt({archives:0,queue_items:0,library_files:0})}finally{yt(!1)}},Zo=pt({mutationFn:_e=>be.deleteGroup(_e),onSuccess:()=>{t.invalidateQueries({queryKey:["groups"]}),o(a("settings.toast.groupDeleted"))},onError:_e=>{o(_e.message,"error")}}),Jo=()=>{const _e=Tr?.advanced_auth_enabled||!1;if(!wt.username){o(a("settings.toast.fillRequiredFields"),"error");return}if(_e&&!wt.email){o("Email is required when advanced authentication is enabled","error");return}if(!_e){if(!wt.password){o(a("settings.toast.fillRequiredFields"),"error");return}if(wt.password!==wt.confirmPassword){o(a("settings.toast.passwordsDoNotMatch"),"error");return}if(wt.password.length<6){o(a("settings.toast.passwordTooShort"),"error");return}}Yl.mutate({username:wt.username,password:_e?void 0:wt.password,email:wt.email||void 0,role:wt.role,group_ids:wt.group_ids.length>0?wt.group_ids:void 0})},el=_e=>{if(wt.password){if(wt.password!==wt.confirmPassword){o(a("settings.toast.passwordsDoNotMatch"),"error");return}if(wt.password.length<6){o(a("settings.toast.passwordTooShort"),"error");return}}const zt={username:wt.username||void 0,password:wt.password||void 0,email:wt.email||void 0,role:wt.role,group_ids:wt.group_ids};zt.password||delete zt.password,_s.mutate({id:_e,data:zt})},Xh=_e=>{Ve(_e.id),_t({username:_e.username,password:"",email:_e.email||"",confirmPassword:"",role:_e.role,group_ids:_e.groups?.map(zt=>zt.id)||[]}),Ue(!0)},Ql=_e=>{_t(zt=>({...zt,group_ids:zt.group_ids.includes(_e)?zt.group_ids.filter(mt=>mt!==_e):[...zt.group_ids,_e]}))},Ys=pt({mutationFn:be.applyUpdate,onSuccess:_e=>{_e.is_docker?o(_e.message,"error"):$r()}}),[Ui,Nu]=w.useState(null),Zl=pt({mutationFn:be.testAllNotificationProviders,onSuccess:_e=>{Nu(_e),t.invalidateQueries({queryKey:["notification-providers"]}),_e.failed===0?o(`All ${_e.tested} providers tested successfully!`,"success"):o(`${_e.success}/${_e.tested} providers succeeded`,_e.failed>0?"error":"success")},onError:_e=>{o(`Failed to test providers: ${_e.message}`,"error")}}),Bi=pt({mutationFn:async _e=>{if(!Me)return{success:0,failed:0};const zt=Me.filter(Pt=>Pt.enabled),mt=await Promise.all(zt.map(async Pt=>{try{return await be.controlSmartPlug(Pt.id,_e),{success:!0}}catch{return{success:!1}}}));return{success:mt.filter(Pt=>Pt.success).length,failed:mt.filter(Pt=>!Pt.success).length}},onSuccess:(_e,zt)=>{t.invalidateQueries({queryKey:["smart-plugs"]}),t.invalidateQueries({queryKey:["smart-plugs-energy"]}),_e.failed===0?o(`All ${_e.success} plugs turned ${zt}`,"success"):o(`${_e.success} plugs turned ${zt}, ${_e.failed} failed`,"error")},onError:_e=>{o(`Failed: ${_e.message}`,"error")}}),tl=w.useRef(null),nl=w.useRef(!1),Qh=w.useRef(!0);w.useEffect(()=>{if(ke&&!k){const _e={...ke,external_url:ke.external_url||window.location.origin};R(_e),setTimeout(()=>{Qh.current=!1},100)}},[ke,k]);const ku=pt({mutationFn:be.updateSettings,onSuccess:_e=>{t.setQueryData(["settings"],_e),t.invalidateQueries({queryKey:["archiveStats"]}),o(a("settings.toast.settingsSaved"),"success")},onError:_e=>{o(`Failed to save: ${_e.message}`,"error")},onSettled:()=>{nl.current=!1}}),ks=pt({mutationFn:({id:_e,data:zt})=>be.updatePrinter(_e,zt),onSuccess:()=>{t.invalidateQueries({queryKey:["printers"]}),o(a("settings.toast.cameraSettingsSaved"),"success")},onError:_e=>{o(`Failed to update printer: ${_e.message}`,"error")}});w.useEffect(()=>{if(!(Qh.current||!k||!ke||!(ke.auto_archive!==k.auto_archive||ke.save_thumbnails!==k.save_thumbnails||ke.capture_finish_photo!==k.capture_finish_photo||ke.default_filament_cost!==k.default_filament_cost||ke.currency!==k.currency||ke.energy_cost_per_kwh!==k.energy_cost_per_kwh||ke.energy_tracking_mode!==k.energy_tracking_mode||ke.check_updates!==k.check_updates||(ke.check_printer_firmware??!0)!==(k.check_printer_firmware??!0)||(ke.include_beta_updates??!1)!==(k.include_beta_updates??!1)||ke.notification_language!==k.notification_language||(ke.bed_cooled_threshold??35)!==(k.bed_cooled_threshold??35)||ke.ams_humidity_good!==k.ams_humidity_good||ke.ams_humidity_fair!==k.ams_humidity_fair||ke.ams_temp_good!==k.ams_temp_good||ke.ams_temp_fair!==k.ams_temp_fair||ke.ams_history_retention_days!==k.ams_history_retention_days||ke.disable_filament_warnings!==k.disable_filament_warnings||(ke.queue_drying_enabled??!1)!==(k.queue_drying_enabled??!1)||(ke.queue_drying_block??!1)!==(k.queue_drying_block??!1)||(ke.ambient_drying_enabled??!1)!==(k.ambient_drying_enabled??!1)||(ke.drying_presets??"")!==(k.drying_presets??"")||ke.per_printer_mapping_expanded!==k.per_printer_mapping_expanded||ke.date_format!==k.date_format||ke.time_format!==k.time_format||ke.default_printer_id!==k.default_printer_id||ke.ftp_retry_enabled!==k.ftp_retry_enabled||ke.ftp_retry_count!==k.ftp_retry_count||ke.ftp_retry_delay!==k.ftp_retry_delay||ke.ftp_timeout!==k.ftp_timeout||ke.mqtt_enabled!==k.mqtt_enabled||ke.mqtt_broker!==k.mqtt_broker||ke.mqtt_port!==k.mqtt_port||ke.mqtt_username!==k.mqtt_username||ke.mqtt_password!==k.mqtt_password||ke.mqtt_topic_prefix!==k.mqtt_topic_prefix||ke.mqtt_use_tls!==k.mqtt_use_tls||ke.external_url!==k.external_url||ke.ha_enabled!==k.ha_enabled||ke.ha_url!==k.ha_url||ke.ha_token!==k.ha_token||(ke.library_archive_mode??"ask")!==(k.library_archive_mode??"ask")||Number(ke.library_disk_warning_gb??5)!==Number(k.library_disk_warning_gb??5)||(ke.camera_view_mode??"window")!==(k.camera_view_mode??"window")||(ke.preferred_slicer??"bambu_studio")!==(k.preferred_slicer??"bambu_studio")||ke.prometheus_enabled!==k.prometheus_enabled||ke.prometheus_token!==k.prometheus_token||(ke.user_notifications_enabled??!0)!==(k.user_notifications_enabled??!0)))&&!nl.current)return tl.current&&clearTimeout(tl.current),tl.current=setTimeout(()=>{if(nl.current)return;nl.current=!0;const zt={auto_archive:k.auto_archive,save_thumbnails:k.save_thumbnails,capture_finish_photo:k.capture_finish_photo,default_filament_cost:k.default_filament_cost,currency:k.currency,energy_cost_per_kwh:k.energy_cost_per_kwh,energy_tracking_mode:k.energy_tracking_mode,check_updates:k.check_updates,check_printer_firmware:k.check_printer_firmware,include_beta_updates:k.include_beta_updates,notification_language:k.notification_language,bed_cooled_threshold:k.bed_cooled_threshold,ams_humidity_good:k.ams_humidity_good,ams_humidity_fair:k.ams_humidity_fair,ams_temp_good:k.ams_temp_good,ams_temp_fair:k.ams_temp_fair,ams_history_retention_days:k.ams_history_retention_days,disable_filament_warnings:k.disable_filament_warnings,queue_drying_enabled:k.queue_drying_enabled,queue_drying_block:k.queue_drying_block,ambient_drying_enabled:k.ambient_drying_enabled,drying_presets:k.drying_presets,per_printer_mapping_expanded:k.per_printer_mapping_expanded,date_format:k.date_format,time_format:k.time_format,default_printer_id:k.default_printer_id,ftp_retry_enabled:k.ftp_retry_enabled,ftp_retry_count:k.ftp_retry_count,ftp_retry_delay:k.ftp_retry_delay,ftp_timeout:k.ftp_timeout,mqtt_enabled:k.mqtt_enabled,mqtt_broker:k.mqtt_broker,mqtt_port:k.mqtt_port,mqtt_username:k.mqtt_username,mqtt_password:k.mqtt_password,mqtt_topic_prefix:k.mqtt_topic_prefix,mqtt_use_tls:k.mqtt_use_tls,external_url:k.external_url,ha_enabled:k.ha_enabled,ha_url:k.ha_url,ha_token:k.ha_token,library_archive_mode:k.library_archive_mode,library_disk_warning_gb:k.library_disk_warning_gb,camera_view_mode:k.camera_view_mode,preferred_slicer:k.preferred_slicer,prometheus_enabled:k.prometheus_enabled,prometheus_token:k.prometheus_token,user_notifications_enabled:k.user_notifications_enabled};ku.mutate(zt)},500),()=>{tl.current&&clearTimeout(tl.current)}},[k,ke,ku]);const on=w.useCallback((_e,zt)=>{R(mt=>mt?{...mt,[_e]:zt}:null)},[]),Ni=async(_e,zt,mt)=>{if(!zt){o(a("settings.toast.enterCameraUrl"),"error");return}tt(Pt=>({...Pt,[_e]:!0})),kn(Pt=>({...Pt,[_e]:null}));try{const Pt=await be.testExternalCamera(_e,zt,mt);kn(rn=>({...rn,[_e]:Pt})),Pt.success?o(a("settings.toast.cameraConnected",{resolution:Pt.resolution||""}),"success"):o(Pt.error||a("settings.toast.connectionFailed"),"error")}catch(Pt){const rn=Pt instanceof Error?Pt.message:a("settings.toast.testFailed");kn(rt=>({...rt,[_e]:{success:!1,error:rn}})),o(rn,"error")}finally{tt(Pt=>({...Pt,[_e]:!1}))}},[So,Cu]=w.useState({}),Jl=w.useRef({}),Tu=w.useRef(new Set);w.useEffect(()=>{if(yn){const _e={};yn.forEach(zt=>{zt.external_camera_url&&!Tu.current.has(zt.id)&&(_e[zt.id]=zt.external_camera_url,Tu.current.add(zt.id))}),Object.keys(_e).length>0&&Cu(zt=>({...zt,..._e}))}},[yn]);const Zh=(_e,zt)=>{Cu(mt=>({...mt,[_e]:zt})),Jl.current[_e]&&clearTimeout(Jl.current[_e]),Jl.current[_e]=setTimeout(()=>{ks.mutate({id:_e,data:{external_camera_url:zt||null}})},800)},Jd=(_e,zt)=>{const mt={};zt.type!==void 0&&(mt.external_camera_type=zt.type||null),zt.enabled!==void 0&&(mt.external_camera_enabled=zt.enabled),ks.mutate({id:_e,data:mt})};return ot||!k?i.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):i.jsxs("div",{className:"p-4 md:p-8",children:[i.jsxs("div",{className:"mb-8",children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:a("settings.title")}),i.jsx("p",{className:"text-bambu-gray",children:a("settings.configureBambuddy")})]}),i.jsxs("div",{className:"flex flex-wrap gap-1 mb-6 border-b border-bambu-dark-tertiary",children:[i.jsx("button",{onClick:()=>U("general"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px ${q==="general"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:a("settings.tabs.general")}),i.jsxs("button",{onClick:()=>U("plugs"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="plugs"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Dl,{className:"w-4 h-4"}),a("settings.tabs.smartPlugs"),Me&&Me.length>0&&i.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Me.length})]}),i.jsxs("button",{onClick:()=>U("notifications"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="notifications"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(hh,{className:"w-4 h-4"}),a("settings.tabs.notifications"),bt&&bt.length>0&&i.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:bt.length})]}),i.jsxs("button",{onClick:()=>U("filament"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="filament"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Npe,{className:"w-4 h-4"}),a("settings.tabs.filament")]}),i.jsxs("button",{onClick:()=>U("network"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="network"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Ub,{className:"w-4 h-4"}),a("settings.tabs.network"),i.jsx("span",{className:`w-2 h-2 rounded-full ${cr?.enabled?"bg-green-400":"bg-gray-500"}`})]}),i.jsxs("button",{onClick:()=>U("apikeys"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="apikeys"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Sl,{className:"w-4 h-4"}),a("settings.tabs.apiKeys"),Et&&Et.length>0&&i.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Et.length})]}),i.jsxs("button",{onClick:()=>U("virtual-printer"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="virtual-printer"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Sr,{className:"w-4 h-4"}),a("settings.tabs.virtualPrinter"),i.jsx("span",{className:`w-2 h-2 rounded-full ${Cn?"bg-green-400":"bg-gray-500"}`})]}),i.jsxs("button",{onClick:()=>U("users"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="users"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Km,{className:"w-4 h-4"}),a("settings.tabs.users"),l&&i.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"})]}),i.jsxs("button",{onClick:()=>U("backup"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="backup"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(au,{className:"w-4 h-4"}),a("settings.tabs.backup"),i.jsx("span",{className:`w-2 h-2 rounded-full ${_i?.is_authenticated&&li?.configured&&li?.enabled?"bg-green-400":"bg-gray-500"}`})]})]}),q==="general"&&i.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[i.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-xl",children:[i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.general")})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i.jsx(gh,{className:"w-4 h-4 inline mr-1"}),a("settings.language")]}),i.jsxs("div",{className:"relative",children:[i.jsx("select",{value:s.language,onChange:_e=>{s.changeLanguage(_e.target.value),be.updateSettings({language:_e.target.value}),o(a("settings.toast.settingsSaved"),"success")},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:C8.map(_e=>i.jsxs("option",{value:_e.code,children:[_e.nativeName," (",_e.name,")"]},_e.code))}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.languageDescription")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.defaultView")}),i.jsxs("div",{className:"relative",children:[i.jsx("select",{value:Y,onChange:_e=>ut(_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:y0.map(_e=>i.jsx("option",{value:_e.to,children:a(_e.labelKey)},_e.id))}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.defaultViewDescription")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.dateFormat")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:k.date_format||"system",onChange:_e=>on("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:[i.jsx("option",{value:"system",children:a("settings.systemDefault")}),i.jsx("option",{value:"us",children:a("settings.dateFormatUs")}),i.jsx("option",{value:"eu",children:a("settings.dateFormatEu")}),i.jsx("option",{value:"iso",children:a("settings.dateFormatIso")})]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.timeFormat")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:k.time_format||"system",onChange:_e=>on("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:[i.jsx("option",{value:"system",children:a("settings.systemDefault")}),i.jsx("option",{value:"12h",children:a("settings.timeFormat12")}),i.jsx("option",{value:"24h",children:a("settings.timeFormat24")})]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.defaultPrinter")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:k.default_printer_id??"",onChange:_e=>on("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:[i.jsx("option",{value:"",children:a("settings.noDefaultPrinter")}),yn?.map(_e=>i.jsx("option",{value:_e.id,children:_e.name},_e.id))]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.defaultPrinterDescription")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.preferredSlicer")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:k.preferred_slicer??"bambu_studio",onChange:_e=>on("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:[i.jsx("option",{value:"bambu_studio",children:a("settings.slicerBambuStudio")}),i.jsx("option",{value:"orcaslicer",children:a("settings.slicerOrcaSlicer")})]}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.preferredSlicerDescription")})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.sidebarOrder")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.sidebarOrderDescription")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:Ze,children:[i.jsx(bo,{className:"w-4 h-4"}),a("settings.reset")]})]})]})]}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(fw,{className:"w-5 h-5"}),a("settings.appearance")]})}),i.jsxs(Dt,{className:"space-y-6",children:[i.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${d==="dark"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[i.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[a("settings.darkMode"),d==="dark"&&i.jsx("span",{className:"text-xs text-bambu-green",children:a("settings.active")})]}),i.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.background")}),i.jsxs("select",{value:p,onChange:_e=>{_(_e.target.value),o(a("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:[i.jsx("option",{value:"neutral",children:a("settings.bgNeutral")}),i.jsx("option",{value:"warm",children:a("settings.bgWarm")}),i.jsx("option",{value:"cool",children:a("settings.bgCool")}),i.jsx("option",{value:"oled",children:a("settings.bgOled")}),i.jsx("option",{value:"slate",children:a("settings.bgSlate")}),i.jsx("option",{value:"forest",children:a("settings.bgForest")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.accent")}),i.jsxs("select",{value:f,onChange:_e=>{N(_e.target.value),o(a("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:[i.jsx("option",{value:"green",children:a("settings.accentGreen")}),i.jsx("option",{value:"teal",children:a("settings.accentTeal")}),i.jsx("option",{value:"blue",children:a("settings.accentBlue")}),i.jsx("option",{value:"orange",children:a("settings.accentOrange")}),i.jsx("option",{value:"purple",children:a("settings.accentPurple")}),i.jsx("option",{value:"red",children:a("settings.accentRed")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.style")}),i.jsxs("select",{value:m,onChange:_e=>{g(_e.target.value),o(a("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:[i.jsx("option",{value:"classic",children:a("settings.styleClassic")}),i.jsx("option",{value:"glow",children:a("settings.styleGlow")}),i.jsx("option",{value:"vibrant",children:a("settings.styleVibrant")})]})]})]})]}),i.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${d==="light"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[i.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[a("settings.lightMode"),d==="light"&&i.jsx("span",{className:"text-xs text-bambu-green",children:a("settings.active")})]}),i.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.background")}),i.jsxs("select",{value:v,onChange:_e=>{C(_e.target.value),o(a("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:[i.jsx("option",{value:"neutral",children:a("settings.bgNeutral")}),i.jsx("option",{value:"warm",children:a("settings.bgWarm")}),i.jsx("option",{value:"cool",children:a("settings.bgCool")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.accent")}),i.jsxs("select",{value:x,onChange:_e=>{A(_e.target.value),o(a("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:[i.jsx("option",{value:"green",children:a("settings.accentGreen")}),i.jsx("option",{value:"teal",children:a("settings.accentTeal")}),i.jsx("option",{value:"blue",children:a("settings.accentBlue")}),i.jsx("option",{value:"orange",children:a("settings.accentOrange")}),i.jsx("option",{value:"purple",children:a("settings.accentPurple")}),i.jsx("option",{value:"red",children:a("settings.accentRed")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.style")}),i.jsxs("select",{value:y,onChange:_e=>{T(_e.target.value),o(a("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:[i.jsx("option",{value:"classic",children:a("settings.styleClassic")}),i.jsx("option",{value:"glow",children:a("settings.styleGlow")}),i.jsx("option",{value:"vibrant",children:a("settings.styleVibrant")})]})]})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.themeToggleHint")})]})]}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.archiveSettings")})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.autoArchivePrints")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.autoArchiveDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.auto_archive,onChange:_e=>on("auto_archive",_e.target.checked),className:"sr-only peer"}),i.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.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.saveThumbnails")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.saveThumbnailsDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.save_thumbnails,onChange:_e=>on("save_thumbnails",_e.target.checked),className:"sr-only peer"}),i.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.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.captureFinishPhoto")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.captureFinishPhotoDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.capture_finish_photo,onChange:_e=>on("capture_finish_photo",_e.target.checked),className:"sr-only peer"}),i.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"})]})]}),k.capture_finish_photo&&gn&&!gn.installed&&i.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[i.jsx(Mn,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),i.jsxs("div",{className:"text-sm",children:[i.jsx("p",{className:"text-yellow-500 font-medium",children:a("settings.ffmpegNotInstalled")}),i.jsx("p",{className:"text-bambu-gray mt-1",children:a("settings.ffmpegRequired")})]})]})]})]})]}),i.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-md",children:[i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(VL,{className:"w-5 h-5 text-bambu-green"}),a("settings.camera")]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.cameraViewMode")}),i.jsxs("select",{value:k.camera_view_mode??"window",onChange:_e=>on("camera_view_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:[i.jsx("option",{value:"window",children:a("settings.newWindow")}),i.jsx("option",{value:"embedded",children:a("settings.embeddedOverlay")})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:k.camera_view_mode==="embedded"?a("settings.cameraOverlayDescription"):a("settings.cameraWindowDescription")})]}),i.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4",children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-2",children:a("settings.externalCameras")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:a("settings.externalCamerasDescription")}),yn&&yn.length>0?i.jsx("div",{className:"space-y-3",children:yn.map(_e=>i.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-white font-medium text-sm",children:_e.name}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:_e.external_camera_enabled,onChange:zt=>Jd(_e.id,{enabled:zt.target.checked}),className:"sr-only peer"}),i.jsx("div",{className:"w-9 h-5 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:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),_e.external_camera_enabled&&i.jsxs("div",{className:"space-y-2 mt-2",children:[i.jsx("input",{type:"text",placeholder:_e.external_camera_type==="usb"?a("settings.cameraPlaceholderUsb"):a("settings.cameraPlaceholderUrl"),value:So[_e.id]??_e.external_camera_url??"",onChange:zt=>Zh(_e.id,zt.target.value),className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("select",{value:_e.external_camera_type||"mjpeg",onChange:zt=>Jd(_e.id,{type:zt.target.value}),className:"flex-1 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"mjpeg",children:a("settings.cameraTypeMjpeg")}),i.jsx("option",{value:"rtsp",children:a("settings.cameraTypeRtsp")}),i.jsx("option",{value:"snapshot",children:a("settings.cameraTypeSnapshot")}),i.jsx("option",{value:"usb",children:a("settings.cameraTypeUsb")})]}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:()=>Ni(_e.id,So[_e.id]??_e.external_camera_url??"",_e.external_camera_type||"mjpeg"),disabled:Fe[_e.id]||!(So[_e.id]??_e.external_camera_url),children:Fe[_e.id]?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):a("settings.test")})]}),jn[_e.id]&&i.jsx("div",{className:`text-xs flex items-center gap-1 ${jn[_e.id]?.success?"text-green-500":"text-red-500"}`,children:jn[_e.id]?.success?i.jsxs(i.Fragment,{children:[i.jsx(fr,{className:"w-3 h-3"}),a("settings.connected"),jn[_e.id]?.resolution&&` (${jn[_e.id]?.resolution})`]}):i.jsxs(i.Fragment,{children:[i.jsx(Vi,{className:"w-3 h-3"}),jn[_e.id]?.error||a("settings.toast.connectionFailed")]})})]})]},_e.id))}):i.jsx("p",{className:"text-xs text-bambu-gray italic",children:a("settings.noPrintersConfigured")})]})]})]}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.costTracking")})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.currency")}),i.jsx("select",{value:k.currency,onChange:_e=>on("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:zqe.map(_e=>i.jsx("option",{value:_e.code,children:_e.label},_e.code))})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.defaultFilamentCost")}),i.jsxs("div",{className:"relative",children:[i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none",children:_l(k.currency)}),i.jsx("input",{type:"number",step:"0.01",min:"0",value:k.default_filament_cost,onChange:_e=>on("default_filament_cost",parseFloat(_e.target.value)||0),style:{paddingLeft:`${Math.max(2,_l(k.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"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.electricityCost")}),i.jsxs("div",{className:"relative",children:[i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none",children:_l(k.currency)}),i.jsx("input",{type:"number",step:"0.001",min:"0",value:k.energy_cost_per_kwh,onChange:_e=>on("energy_cost_per_kwh",parseFloat(_e.target.value)||0),style:{paddingLeft:`${Math.max(2,_l(k.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"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.energyDisplayMode")}),i.jsxs("select",{value:k.energy_tracking_mode||"total",onChange:_e=>on("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:[i.jsx("option",{value:"print",children:a("settings.printsOnly")}),i.jsx("option",{value:"total",children:a("settings.totalConsumption")})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:k.energy_tracking_mode==="print"?a("settings.energyModePrintDescription"):a("settings.energyModeTotalDescription")})]})]})]}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Fs,{className:"w-5 h-5 text-bambu-green"}),a("settings.fileManager")]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.createArchiveEntry")}),i.jsxs("select",{value:k.library_archive_mode??"ask",onChange:_e=>on("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:[i.jsx("option",{value:"always",children:a("settings.archiveMode.always")}),i.jsx("option",{value:"never",children:a("settings.archiveMode.never")}),i.jsx("option",{value:"ask",children:a("settings.archiveMode.ask")})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.createArchiveEntryDescription")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.lowDiskSpaceWarning")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",min:"0.5",max:"100",step:"0.5",value:k.library_disk_warning_gb??5,onChange:_e=>on("library_disk_warning_gb",parseFloat(_e.target.value)||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"}),i.jsx("span",{className:"text-bambu-gray",children:"GB"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.lowDiskSpaceDescription")})]})]})]})]}),i.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-sm",children:[i.jsx(ket,{}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.updates")})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wider",children:a("settings.printerFirmware")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.checkPrinterFirmware")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.checkFirmwareDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.check_printer_firmware??!0,onChange:_e=>on("check_printer_firmware",_e.target.checked),className:"sr-only peer"}),i.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.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:i.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wider mb-4",children:a("settings.bambuddySoftware")})}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.checkForUpdatesLabel")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.autoCheckDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.check_updates,onChange:_e=>on("check_updates",_e.target.checked),className:"sr-only peer"}),i.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.jsxs("div",{className:`flex items-center justify-between ${k.check_updates?"":"opacity-50"}`,children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.includeBetaUpdates")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.includeBetaUpdatesDesc")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.include_beta_updates??!1,onChange:_e=>on("include_beta_updates",_e.target.checked),disabled:!k.check_updates,className:"sr-only peer"}),i.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.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.currentVersion")}),i.jsxs("p",{className:"text-sm text-bambu-gray",children:["v",Qr?.version||"..."]})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>hr(),disabled:_a,children:[_a?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(wr,{className:"w-4 h-4"}),a("settings.checkNow")]})]}),Tn?.update_available?i.jsxs("div",{className:"mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:[i.jsxs("div",{className:"flex items-start justify-between",children:[i.jsxs("div",{children:[i.jsxs("p",{className:"text-bambu-green font-medium",children:["Update available: v",Tn.latest_version]}),Tn.release_name&&Tn.release_name!==Tn.latest_version&&i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:Tn.release_name})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[Tn.release_notes&&i.jsx("button",{onClick:()=>Se(!0),className:"text-bambu-gray hover:text-white transition-colors text-sm underline",children:a("settings.releaseNotes")}),Tn.release_url&&i.jsx("a",{href:Tn.release_url,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-white transition-colors",title:a("settings.viewReleaseOnGitHub"),children:i.jsx(Jr,{className:"w-4 h-4"})})]})]}),On?.status==="downloading"||On?.status==="installing"?i.jsxs("div",{className:"mt-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),i.jsx("span",{children:On.message})]}),i.jsx("div",{className:"mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2",children:i.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${On.progress}%`}})})]}):On?.status==="complete"?i.jsx("div",{className:"mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green",children:On.message}):On?.status==="error"?i.jsx("div",{className:"mt-3 p-2 bg-red-500/20 rounded text-sm text-red-400",children:On.error||On.message}):Tn?.is_docker?i.jsxs("div",{className:"mt-3 p-3 bg-bambu-dark-tertiary rounded-lg",children:[i.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:a("settings.updateViaDocker")}),i.jsx("code",{className:"block text-xs bg-bambu-dark p-2 rounded text-bambu-green font-mono",children:"docker compose pull && docker compose up -d"})]}):i.jsxs(Oe,{className:"mt-3",onClick:()=>Ys.mutate(),disabled:Ys.isPending,children:[Ys.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(pi,{className:"w-4 h-4"}),a("settings.installUpdate")]})]}):Tn?.error?i.jsx("div",{className:"mt-2 p-2 bg-red-500/10 border border-red-500/30 rounded text-sm text-red-400",children:a("settings.failedToCheckUpdates",{error:Tn.error})}):Tn&&!Tn.update_available?i.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:a("settings.latestVersionRunning")}):null]})]})]}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.dataManagement")})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.clearNotificationLogs")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.clearNotificationLogsDescription")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>F(!0),children:[i.jsx(Jt,{className:"w-4 h-4"}),a("common.clear")]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.resetUiPreferences")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.resetUiPreferencesDescription")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>ve(!0),children:[i.jsx(Jt,{className:"w-4 h-4"}),a("settings.reset")]})]}),i.jsxs("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.storageUsage","Storage Usage")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.storageUsageDescription","Breakdown of data usage by category")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:Ye,disabled:Ke||ce,children:[i.jsx(wr,{className:`w-4 h-4 ${Ke||ce?"animate-spin":""}`}),a("common.refresh","Refresh")]})]}),i.jsx("div",{className:"mt-3",children:He?i.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),a("common.loading","Loading")]}):se?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"w-full h-3 bg-bambu-dark rounded-full overflow-hidden flex",children:se.categories.filter(_e=>_e.bytes>0).map((_e,zt)=>i.jsx("div",{className:`${AY(_e.key,zt)} h-full`,style:{width:`${_e.percent_of_total}%`},title:`${_e.label}: ${_e.formatted}`},_e.key))}),i.jsx("div",{className:"mt-3 flex flex-wrap gap-3",children:se.categories.filter(_e=>_e.bytes>0).map((_e,zt)=>i.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[i.jsx("span",{className:`w-3 h-3 rounded-full ${AY(_e.key,zt)}`}),i.jsx("span",{className:"text-bambu-gray",children:_e.label}),i.jsx("span",{className:"text-white",children:_e.formatted}),i.jsxs("span",{className:"text-bambu-gray",children:["(",_e.percent_of_total.toFixed(1),"%)"]})]},_e.key))}),i.jsxs("div",{className:"mt-2 text-xs text-bambu-gray",children:[a("settings.storageUsageTotal","Total"),": ",i.jsx("span",{className:"text-white",children:se.total_formatted}),se.scan_errors>0&&i.jsxs("span",{className:"ml-2 text-amber-400",children:[a("settings.storageUsageErrors","Scan errors"),": ",se.scan_errors]})]}),se.other_breakdown?.length>0&&i.jsxs("div",{className:"mt-4",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:a("settings.storageUsageOtherBreakdown","Other breakdown")}),i.jsx("div",{className:"space-y-2",children:se.other_breakdown.map(_e=>i.jsxs("div",{className:"flex items-center justify-between text-xs",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-white",children:_e.label}),i.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"?a("settings.storageUsageSystem","System"):a("settings.storageUsageData","Data")})]}),i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray",children:[i.jsx("span",{className:"text-white",children:_e.formatted}),i.jsxs("span",{children:["(",_e.percent_of_total.toFixed(1),"%)"]})]})]},`${_e.bucket}-${_e.kind}`))})]})]}):i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.storageUsageUnavailable","Storage usage data is unavailable")})})]}),i.jsxs("div",{className:"flex items-center justify-between pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.backupRestore")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.backupRestoreDescription")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>U("backup"),children:[i.jsx(au,{className:"w-4 h-4"}),a("settings.goToBackup")]})]})]})]})]})]}),q==="network"&&k&&i.jsxs("div",{className:"flex flex-col lg:flex-row gap-6",children:[i.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-4",children:[i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(gh,{className:"w-5 h-5 text-blue-400"}),a("settings.externalUrl")]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.externalUrlDescription")}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.bambuddyUrl")}),i.jsx("input",{type:"text",value:k.external_url??"",onChange:_e=>on("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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.externalUrlHint")})]})]})]}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(wr,{className:"w-5 h-5 text-blue-400"}),a("settings.ftpRetry")]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.ftpRetryDescription")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.enableRetry")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.autoRetryDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.ftp_retry_enabled??!0,onChange:_e=>on("ftp_retry_enabled",_e.target.checked),className:"sr-only peer"}),i.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"})]})]}),k.ftp_retry_enabled&&i.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.retryAttempts")}),i.jsxs("div",{className:"relative w-44",children:[i.jsx("select",{value:k.ftp_retry_count??3,onChange:_e=>on("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=>i.jsx("option",{value:_e,children:a("settings.time",{count:_e})},_e))}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.retryDelay")}),i.jsxs("div",{className:"relative w-44",children:[i.jsx("select",{value:k.ftp_retry_delay??2,onChange:_e=>on("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=>i.jsx("option",{value:_e,children:a("settings.second",{count:_e})},_e))}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.connectionTimeout")}),i.jsxs("div",{className:"relative w-44",children:[i.jsx("select",{value:k.ftp_timeout??30,onChange:_e=>on("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=>i.jsx("option",{value:_e,children:a("settings.nSeconds",{count:_e})},_e))}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.increaseForWeakWifi")})]})]})]})]})]}),i.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-4",children:[i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(hw,{className:"w-5 h-5 text-bambu-green"}),a("settings.homeAssistant")]}),k.ha_enabled&&Xt&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${Xt.success?"bg-green-400":"bg-red-400"}`}),i.jsx("span",{className:`text-sm ${Xt.success?"text-green-400":"text-red-400"}`,children:Xt.success?a("settings.connected"):a("settings.disconnected")})]})]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.homeAssistantFullDescription")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-white",children:a("settings.enableHomeAssistant")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.homeAssistantDescription")}),k.ha_env_managed&&i.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[i.jsx(Ap,{className:"w-3 h-3 text-bambu-green"}),i.jsx("span",{className:"text-xs text-bambu-green",children:a("settings.autoEnabledViaEnv")})]})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.ha_enabled??!1,onChange:_e=>on("ha_enabled",_e.target.checked),disabled:k.ha_env_managed,className:"sr-only peer"}),i.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 ${k.ha_env_managed?"opacity-60 cursor-not-allowed":""}`})]})]}),k.ha_enabled&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.homeAssistantUrl"),k.ha_url_from_env&&i.jsx("span",{className:"ml-2 text-xs text-bambu-green",children:a("settings.environmentManagedLabel")})]}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"text",value:k.ha_url??"",onChange:_e=>on("ha_url",_e.target.value),placeholder:"http://192.168.1.100:8123",disabled:k.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 ${k.ha_url_from_env?"opacity-60 cursor-not-allowed":""}`}),k.ha_url_from_env&&i.jsx(Ap,{className:"absolute right-3 top-2.5 w-4 h-4 text-bambu-gray"})]}),k.ha_url_from_env&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.urlFromEnvReadOnly")})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.longLivedAccessToken"),k.ha_token_from_env&&i.jsx("span",{className:"ml-2 text-xs text-bambu-green",children:a("settings.environmentManagedLabel")})]}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"password",value:k.ha_token??"",onChange:_e=>on("ha_token",_e.target.value),placeholder:"eyJ0eXAiOiJKV1QiLC...",disabled:k.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 ${k.ha_token_from_env?"opacity-60 cursor-not-allowed":""}`}),k.ha_token_from_env&&i.jsx(Ap,{className:"absolute right-3 top-2.5 w-4 h-4 text-bambu-gray"})]}),k.ha_token_from_env?i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.tokenFromEnvReadOnly")}):i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.haTokenHint")})]}),k.ha_url&&k.ha_token&&i.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:i.jsxs(Oe,{variant:"secondary",size:"sm",disabled:Qt,onClick:async()=>{hn(!0),Qe(null);try{const _e=await be.testHAConnection(k.ha_url,k.ha_token);Qe(_e)}catch(_e){Qe({success:!1,message:null,error:_e instanceof Error?_e.message:a("common.unknownError")})}finally{hn(!1)}},children:[Qt?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Ub,{className:"w-4 h-4"}),a("settings.testConnection")]})})]})]})]}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Ub,{className:"w-5 h-5 text-blue-400"}),a("settings.mqttPublishing")]}),cr?.enabled&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${cr.connected?"bg-green-400":"bg-red-400"}`}),i.jsx("span",{className:`text-sm ${cr.connected?"text-green-400":"text-red-400"}`,children:cr.connected?a("settings.connected"):a("settings.disconnected")})]})]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.mqttDescription")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.enableMqtt")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.mqttEnableDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.mqtt_enabled??!1,onChange:_e=>on("mqtt_enabled",_e.target.checked),className:"sr-only peer"}),i.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"})]})]}),k.mqtt_enabled&&i.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.brokerHostname")}),i.jsx("input",{type:"text",value:k.mqtt_broker??"",onChange:_e=>on("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"})]}),i.jsxs("div",{className:"flex items-end gap-4",children:[i.jsxs("div",{className:"flex-1",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.port")}),i.jsx("input",{type:"number",min:"1",max:"65535",value:k.mqtt_port??1883,onChange:_e=>on("mqtt_port",Math.min(65535,Math.max(1,parseInt(_e.target.value)||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"})]}),i.jsxs("div",{className:"flex items-center gap-3 pb-2",children:[i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.mqtt_use_tls??!1,onChange:_e=>{const zt=_e.target.checked;on("mqtt_use_tls",zt);const mt=k.mqtt_port??1883;zt&&mt===1883?on("mqtt_port",8883):!zt&&mt===8883&&on("mqtt_port",1883)},className:"sr-only peer"}),i.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.jsx("span",{className:"text-white text-sm",children:a("settings.useTls")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.usernameOptional")}),i.jsx("input",{type:"text",value:k.mqtt_username??"",onChange:_e=>on("mqtt_username",_e.target.value),placeholder:a("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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.passwordOptional")}),i.jsx("input",{type:"password",value:k.mqtt_password??"",onChange:_e=>on("mqtt_password",_e.target.value),placeholder:a("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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.topicPrefix")}),i.jsx("input",{type:"text",value:k.mqtt_topic_prefix??"bambuddy",onChange:_e=>on("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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.topicPrefixHint",{prefix:k.mqtt_topic_prefix||"bambuddy"})})]}),cr&&i.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary",children:i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx("span",{className:`w-2 h-2 rounded-full ${cr.connected?"bg-green-400":"bg-red-400"}`}),i.jsx("span",{className:"text-bambu-gray",children:cr.connected?i.jsxs(i.Fragment,{children:[a("settings.mqttConnectedTo")," ",i.jsxs("span",{className:"text-white",children:[cr.broker,":",cr.port]})]}):a("settings.spoolmanDisconnected")})]})})]})]})]})]}),i.jsx("div",{className:"flex-1 lg:max-w-md space-y-4",children:i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(w3,{className:"w-5 h-5 text-orange-400"}),a("settings.prometheusMetrics")]})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.prometheusEndpointDescription")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.enableMetricsEndpoint")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.prometheusDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.prometheus_enabled??!1,onChange:_e=>on("prometheus_enabled",_e.target.checked),className:"sr-only peer"}),i.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"})]})]}),k.prometheus_enabled&&i.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.bearerTokenOptional")}),i.jsx("input",{type:"password",value:k.prometheus_token??"",onChange:_e=>on("prometheus_token",_e.target.value),placeholder:a("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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.bearerTokenHint")})]}),i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-sm text-white mb-2",children:a("settings.availableMetrics")}),i.jsxs("div",{className:"text-xs text-bambu-gray space-y-1",children:[i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_connected"})," - ",a("settings.metricsConnectionStatus")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_state"})," - ",a("settings.metricsPrinterState")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_print_progress"})," - ",a("settings.metricsPrintProgress")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_bed_temp_celsius"})," - ",a("settings.metricsBedTemp")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_nozzle_temp_celsius"})," - ",a("settings.metricsNozzleTemp")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_prints_total"})," - ",a("settings.metricsPrintsTotal")]}),i.jsx("p",{className:"text-bambu-gray/70 italic",children:a("settings.metricsMore")})]})]})]})]})]})})]}),Xt&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full mx-4",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[Xt.success?i.jsx(fr,{className:"w-8 h-8 text-green-400"}):i.jsx(Vi,{className:"w-8 h-8 text-red-400"}),i.jsx("h3",{className:"text-lg font-medium text-white",children:Xt.success?a("settings.connectionSuccessful"):a("settings.connectionFailed")})]}),i.jsx("p",{className:"text-bambu-gray mb-6",children:Xt.success?Xt.message||a("settings.haConnectionSuccess"):Xt.error||a("settings.haConnectionFailed")}),i.jsx("div",{className:"flex justify-end",children:i.jsx(Oe,{variant:"primary",onClick:()=>Qe(null),children:a("settings.ok")})})]})}),q==="plugs"&&i.jsxs("div",{className:"max-w-4xl",children:[i.jsxs("div",{className:"flex items-start justify-between mb-6",children:[i.jsxs("div",{children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Dl,{className:"w-5 h-5 text-bambu-green"}),a("settings.smartPlugs")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a("settings.smartPlugsDescription")})]}),i.jsxs("div",{className:"flex items-center gap-2 pt-1 shrink-0",children:[Me&&Me.filter(_e=>_e.enabled).length>1&&i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>de("on"),disabled:Bi.isPending,title:a("settings.turnAllPlugsOn"),children:[Bi.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Vd,{className:"w-4 h-4 text-bambu-green"}),a("settings.allOn")]}),i.jsxs(Oe,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>de("off"),disabled:Bi.isPending,title:a("settings.turnAllPlugsOff"),children:[Bi.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(nT,{className:"w-4 h-4 text-red-400"}),a("settings.allOff")]})]}),i.jsxs(Oe,{className:"whitespace-nowrap",onClick:()=>{z(null),D(!0)},children:[i.jsx(ar,{className:"w-4 h-4"}),a("settings.addSmartPlug")]})]})]}),Me&&Me.length>0&&i.jsxs(Mt,{className:"mb-6",children:[i.jsx(Hn,{children:i.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[i.jsx(kc,{className:"w-4 h-4 text-yellow-400"}),a("settings.energySummary"),nt&&i.jsx(ht,{className:"w-4 h-4 animate-spin text-bambu-gray ml-2"})]})}),i.jsx(Dt,{children:ct?i.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[i.jsx(kc,{className:"w-3 h-3"}),a("settings.currentPower")]}),i.jsxs("div",{className:"text-xl font-bold text-white",children:[ct.totalPower.toFixed(1),i.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"W"})]}),i.jsx("div",{className:"text-xs text-bambu-gray mt-1",children:a("settings.plugsOnline",{reachable:ct.reachableCount,total:ct.totalPlugs})})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[i.jsx(Wr,{className:"w-3 h-3"}),a("settings.today")]}),i.jsxs("div",{className:"text-xl font-bold text-white",children:[ct.totalToday.toFixed(3),i.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(k?.energy_cost_per_kwh??0)>0&&i.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(ct.totalToday*(k?.energy_cost_per_kwh??0)).toFixed(2)," ",_l(k?.currency||"USD")]})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[i.jsx(w3,{className:"w-3 h-3"}),a("settings.yesterday")]}),i.jsxs("div",{className:"text-xl font-bold text-white",children:[ct.totalYesterday.toFixed(3),i.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(k?.energy_cost_per_kwh??0)>0&&i.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(ct.totalYesterday*(k?.energy_cost_per_kwh??0)).toFixed(2)," ",_l(k?.currency||"USD")]})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[i.jsx(PN,{className:"w-3 h-3"}),a("settings.total")]}),i.jsxs("div",{className:"text-xl font-bold text-white",children:[ct.totalLifetime.toFixed(1),i.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(k?.energy_cost_per_kwh??0)>0&&i.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(ct.totalLifetime*(k?.energy_cost_per_kwh??0)).toFixed(2)," ",_l(k?.currency||"USD")]})]})]}):nt?null:i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.enablePlugsForSummary")})})]}),dt?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):Me&&Me.length>0?i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Me.map(_e=>i.jsx(uet,{plug:_e,onEdit:zt=>{z(zt),D(!0)}},_e.id))}):i.jsx(Mt,{children:i.jsx(Dt,{className:"py-12",children:i.jsxs("div",{className:"text-center text-bambu-gray",children:[i.jsx(Dl,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),i.jsx("p",{className:"text-lg font-medium text-white mb-2",children:a("settings.noSmartPlugsTitle")}),i.jsx("p",{className:"text-sm mb-4",children:a("settings.noSmartPlugsDescription")}),i.jsxs(Oe,{onClick:()=>{z(null),D(!0)},children:[i.jsx(ar,{className:"w-4 h-4"}),a("settings.addFirstSmartPlug")]})]})})})]}),q==="notifications"&&i.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(hh,{className:"w-5 h-5 text-bambu-green"}),a("settings.providers")]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>ge(!0),children:[i.jsx(f0,{className:"w-4 h-4"}),a("settings.log")]}),bt&&bt.length>0&&i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>{Nu(null),Zl.mutate()},disabled:Zl.isPending,children:[Zl.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(rT,{className:"w-4 h-4"}),a("settings.testAll")]}),i.jsxs(Oe,{size:"sm",onClick:()=>{ie(null),I(!0)},children:[i.jsx(ar,{className:"w-4 h-4"}),a("settings.addNotificationProvider")]})]})]}),i.jsx(Mt,{className:"mb-4",children:i.jsx(Dt,{className:"py-3",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white text-sm font-medium",children:a("settings.notificationLanguage")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.notificationLanguageDescription")})]}),i.jsx("select",{value:k.notification_language||"en",onChange:_e=>on("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:C8.map(_e=>i.jsx("option",{value:_e.code,children:_e.nativeName},_e.code))})]})})}),i.jsx(Mt,{className:"mb-4",children:i.jsx(Dt,{className:"py-3",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white text-sm font-medium",children:a("settings.bedCooledThreshold")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.bedCooledThresholdDescription")})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("input",{type:"number",min:20,max:80,step:1,value:k.bed_cooled_threshold??35,onChange:_e=>on("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"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:"°C"})]})]})})}),i.jsx(Mt,{className:"mb-4",children:i.jsx(Dt,{className:"py-3",children:i.jsxs("div",{className:`flex items-center justify-between ${Tr?.advanced_auth_enabled?"":"opacity-50"}`,children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white text-sm font-medium",children:a("settings.userNotificationsEnabled")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:Tr?.advanced_auth_enabled?a("settings.userNotificationsEnabledDescription"):a("settings.userNotificationsDisabledHint")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",className:"sr-only peer",checked:k.user_notifications_enabled??!0,disabled:!Tr?.advanced_auth_enabled,onChange:_e=>on("user_notifications_enabled",_e.target.checked)}),i.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"})]})]})})}),Ui&&i.jsx(Mt,{className:"mb-4",children:i.jsxs(Dt,{className:"py-3",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-sm font-medium text-white",children:a("settings.testResults")}),i.jsx("button",{onClick:()=>Nu(null),className:"text-bambu-gray hover:text-white text-xs",children:a("common.dismiss")})]}),i.jsxs("div",{className:"flex items-center gap-4 text-sm mb-2",children:[i.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[i.jsx(fr,{className:"w-4 h-4"}),a("settings.testPassedCount",{count:Ui.success})]}),Ui.failed>0&&i.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[i.jsx(Vi,{className:"w-4 h-4"}),a("settings.testFailedCount",{count:Ui.failed})]})]}),Ui.results.filter(_e=>!_e.success).length>0&&i.jsx("div",{className:"space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary",children:Ui.results.filter(_e=>!_e.success).map(_e=>i.jsxs("div",{className:"text-xs text-red-400",children:[i.jsxs("span",{className:"font-medium",children:[_e.provider_name,":"]})," ",_e.message]},_e.provider_id))})]})}),Ut?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})}):bt&&bt.length>0?i.jsx("div",{className:"space-y-3",children:bt.map(_e=>i.jsx(met,{provider:_e,onEdit:zt=>{ie(zt),I(!0)}},_e.id))}):i.jsx(Mt,{children:i.jsx(Dt,{className:"py-8",children:i.jsxs("div",{className:"text-center text-bambu-gray",children:[i.jsx(hh,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),i.jsx("p",{className:"text-sm font-medium text-white mb-2",children:a("settings.noProvidersTitle")}),i.jsx("p",{className:"text-xs mb-3",children:a("settings.noProvidersDescription")}),i.jsxs(Oe,{size:"sm",onClick:()=>{ie(null),I(!0)},children:[i.jsx(ar,{className:"w-4 h-4"}),a("settings.addProvider")]})]})})})]}),i.jsxs("div",{children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-4",children:[i.jsx(Fs,{className:"w-5 h-5 text-bambu-green"}),a("settings.messageTemplates")]}),i.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:a("settings.messageTemplatesDescription")}),qn?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})}):_n&&_n.length>0?i.jsx("div",{className:"space-y-2",children:[..._n].sort((_e,zt)=>_e.name.localeCompare(zt.name)).map(_e=>i.jsx(Mt,{className:"cursor-pointer hover:border-bambu-green/50 transition-colors",onClick:()=>me(_e),children:i.jsx(Dt,{className:"py-2.5 px-3",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"text-white font-medium text-sm truncate",children:_e.name}),i.jsx("p",{className:"text-bambu-gray text-xs truncate mt-0.5",children:_e.title_template})]}),i.jsx("button",{className:"p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2",onClick:zt=>{zt.stopPropagation(),me(_e)},children:i.jsx(nh,{className:"w-4 h-4 text-bambu-gray"})})]})})},_e.id))}):i.jsx(Mt,{children:i.jsx(Dt,{className:"py-8",children:i.jsxs("div",{className:"text-center text-bambu-gray",children:[i.jsx(Fs,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),i.jsx("p",{className:"text-sm",children:a("settings.noTemplatesAvailable")})]})})})]})]}),q==="apikeys"&&i.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-8",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-start justify-between gap-4 mb-6",children:[i.jsxs("div",{className:"flex-1",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Sl,{className:"w-5 h-5 text-bambu-green"}),a("settings.apiKeys")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a("settings.apiKeysDescription")})]}),i.jsxs(Oe,{size:"sm",onClick:()=>$(!0),className:"flex-shrink-0",children:[i.jsx(ar,{className:"w-4 h-4"}),a("settings.createKey")]})]}),W&&i.jsx(Mt,{className:"mb-6 border-bambu-green",children:i.jsx(Dt,{className:"py-4",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(fr,{className:"w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-white font-medium mb-1",children:a("settings.apiKeyCreated")}),i.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:a("settings.apiKeyCopyWarning")}),i.jsxs("div",{className:"flex items-center gap-2 bg-bambu-dark rounded-lg p-2",children:[i.jsx("code",{className:"flex-1 text-sm text-bambu-green font-mono break-all",children:W}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(W);else{const _e=document.createElement("textarea");_e.value=W,_e.style.position="fixed",_e.style.left="-999999px",document.body.appendChild(_e),_e.select(),document.execCommand("copy"),document.body.removeChild(_e)}o(a("settings.toast.keyCopied"))}catch{o(a("settings.toast.copyFailed"),"error")}},children:i.jsx(fo,{className:"w-4 h-4"})})]}),i.jsxs("div",{className:"flex gap-2 mt-3",children:[i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>{ae(W),o(a("settings.toast.keyAddedToBrowser"))},children:a("settings.useInApiBrowser")}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>re(null),children:a("common.dismiss")})]})]})]})})}),K&&i.jsxs(Mt,{className:"mb-6",children:[i.jsx(Hn,{children:i.jsx("h3",{className:"text-base font-semibold text-white",children:a("settings.createNewApiKey")})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.keyName")}),i.jsx("input",{type:"text",value:ne,onChange:_e=>O(_e.target.value),placeholder:a("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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:a("common.permissions")}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:V.can_read_status,onChange:_e=>J(zt=>({...zt,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"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white",children:a("settings.readStatus")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.readStatusDescription")})]})]}),i.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:V.can_queue,onChange:_e=>J(zt=>({...zt,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"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white",children:a("settings.manageQueue")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.manageQueueDescription")})]})]}),i.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:V.can_control_printer,onChange:_e=>J(zt=>({...zt,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"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white",children:a("settings.controlPrinter")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.controlPrinterDescription")})]})]})]})]}),i.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[i.jsxs(Oe,{onClick:()=>Zt.mutate({name:ne||a("settings.unnamedKey"),...V}),disabled:Zt.isPending,children:[Zt.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(ar,{className:"w-4 h-4"}),a("settings.createKey")]}),i.jsx(Oe,{variant:"secondary",onClick:()=>$(!1),children:a("common.cancel")})]})]})]}),It?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):Et&&Et.length>0?i.jsx("div",{className:"space-y-3",children:Et.map(_e=>i.jsx(Mt,{children:i.jsx(Dt,{className:"py-3",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx(Sl,{className:`w-5 h-5 ${_e.enabled?"text-bambu-green":"text-bambu-gray"}`}),i.jsxs("div",{children:[i.jsx("p",{className:"text-white font-medium",children:_e.name}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[_e.key_prefix,"••••••••",_e.last_used&&` · ${a("settings.lastUsed")}: ${_f(_e.last_used)}`]})]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex gap-1 text-xs",children:[_e.can_read_status&&i.jsx("span",{className:"px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded",children:a("settings.read")}),_e.can_queue&&i.jsx("span",{className:"px-1.5 py-0.5 bg-green-500/20 text-green-400 rounded",children:a("queue.title")}),_e.can_control_printer&&i.jsx("span",{className:"px-1.5 py-0.5 bg-orange-500/20 text-orange-400 rounded",children:a("settings.control")})]}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>fe(_e.id),children:i.jsx(Jt,{className:"w-4 h-4 text-red-400"})})]})]})})},_e.id))}):i.jsx(Mt,{children:i.jsx(Dt,{className:"py-12",children:i.jsxs("div",{className:"text-center text-bambu-gray",children:[i.jsx(Sl,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),i.jsx("p",{className:"text-lg font-medium text-white mb-2",children:a("settings.apiKeysEmptyTitle")}),i.jsx("p",{className:"text-sm mb-4",children:a("settings.apiKeysEmptyDescription")}),i.jsxs(Oe,{onClick:()=>$(!0),children:[i.jsx(ar,{className:"w-4 h-4"}),a("settings.createFirstKey")]})]})})}),i.jsxs(Mt,{className:"mt-6",children:[i.jsx(Hn,{children:i.jsx("h3",{className:"text-base font-semibold text-white",children:a("settings.webhookEndpoints")})}),i.jsxs(Dt,{className:"space-y-3 text-sm",children:[i.jsx("p",{className:"text-bambu-gray",children:a("settings.webhookApiKeyHint")}),i.jsxs("div",{className:"space-y-2 font-mono text-xs",children:[i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-blue-400",children:"GET"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/status"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.getAllStatus")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-blue-400",children:"GET"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/status/:id"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.getSpecificStatus")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-green-400",children:"POST"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/queue"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.addToQueue")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-orange-400",children:"POST"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/pause"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.pausePrint")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-orange-400",children:"POST"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/resume"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.resumePrint")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-red-400",children:"POST"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/stop"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.stopPrint")]})]})]})]})]})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"mb-6",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(gh,{className:"w-5 h-5 text-bambu-green"}),a("settings.apiBrowser")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a("settings.apiBrowserDescription")})]}),i.jsx(Mt,{className:"mb-4",children:i.jsxs(Dt,{className:"py-3",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:a("settings.apiKeyForTesting")}),i.jsx("input",{type:"text",value:ye,onChange:_e=>ae(_e.target.value),placeholder:a("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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:a("settings.apiKeyHint")})]})}),i.jsx(Oet,{apiKey:ye})]})]}),q==="virtual-printer"&&i.jsx(Aet,{}),q==="filament"&&k&&i.jsx(i.Fragment,{children:i.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[i.jsxs("div",{className:"lg:w-1/3 space-y-6",children:[i.jsx(vet,{}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.filamentChecks")})}),i.jsx(Dt,{className:"space-y-4",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.disableFilamentWarnings")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.disableFilamentWarningsDesc")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.disable_filament_warnings,onChange:_e=>on("disable_filament_warnings",_e.target.checked),className:"sr-only peer"}),i.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.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.amsDisplayThresholds")})}),i.jsxs(Dt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.amsThresholdsDescription")}),i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-white",children:[i.jsx(UL,{className:"w-4 h-4 text-blue-400"}),i.jsx("span",{className:"font-medium",children:a("settings.humidity")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.goodGreen")," ≤"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",min:"0",max:"100",value:k.ams_humidity_good??40,onChange:_e=>on("ams_humidity_good",parseInt(_e.target.value)||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"}),i.jsx("span",{className:"text-bambu-gray",children:"%"})]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.fairOrange")," ≤"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",min:"0",max:"100",value:k.ams_humidity_fair??60,onChange:_e=>on("ams_humidity_fair",parseInt(_e.target.value)||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"}),i.jsx("span",{className:"text-bambu-gray",children:"%"})]})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.aboveFairBad")}),i.jsx("p",{className:"text-xs text-amber-400/70",children:a("settings.fairAlsoDryingThreshold")})]}),i.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 text-white",children:[i.jsx(aT,{className:"w-4 h-4 text-orange-400"}),i.jsx("span",{className:"font-medium",children:a("settings.temperature")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.goodBlue")," ≤"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:k.ams_temp_good??28,onChange:_e=>on("ams_temp_good",parseFloat(_e.target.value)||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"}),i.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.fairOrange")," ≤"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:k.ams_temp_fair??35,onChange:_e=>on("ams_temp_fair",parseFloat(_e.target.value)||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"}),i.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.aboveFairHot")})]}),i.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 text-white",children:[i.jsx(au,{className:"w-4 h-4 text-purple-400"}),i.jsx("span",{className:"font-medium",children:a("settings.historyRetention")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.keepSensorHistory")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",min:"1",max:"365",value:k.ams_history_retention_days??30,onChange:_e=>on("ams_history_retention_days",parseInt(_e.target.value)||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"}),i.jsx("span",{className:"text-bambu-gray",children:a("common.days")})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.historyRetentionDescription")})]}),i.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 text-white",children:[i.jsx(Fp,{className:"w-4 h-4 text-amber-400"}),i.jsx("span",{className:"font-medium",children:a("settings.queueDrying")})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.queueDryingDescription")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-white",children:a("settings.queueDryingEnabled")}),i.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:a("settings.queueDryingEnabledDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.queue_drying_enabled??!1,onChange:_e=>on("queue_drying_enabled",_e.target.checked),className:"sr-only peer"}),i.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"})]})]}),k.queue_drying_enabled&&i.jsx(i.Fragment,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-white",children:a("settings.queueDryingBlock")}),i.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:a("settings.queueDryingBlockDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.queue_drying_block??!1,onChange:_e=>on("queue_drying_block",_e.target.checked),className:"sr-only peer"}),i.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"})]})]})}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-white",children:a("settings.ambientDryingEnabled")}),i.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:a("settings.ambientDryingEnabledDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.ambient_drying_enabled??!1,onChange:_e=>on("ambient_drying_enabled",_e.target.checked),className:"sr-only peer"}),i.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.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-sm text-white font-medium",children:a("settings.dryingPresets")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.dryingPresetsDescription")}),i.jsx("div",{className:"overflow-x-auto",children:i.jsxs("table",{className:"w-full text-xs",children:[i.jsx("thead",{children:i.jsxs("tr",{className:"text-bambu-gray border-b border-bambu-dark-tertiary",children:[i.jsx("th",{className:"text-left py-1.5 pr-2",children:a("settings.dryingFilament")}),i.jsx("th",{className:"text-center py-1.5 px-1",children:"AMS 2 Pro °C"}),i.jsx("th",{className:"text-center py-1.5 px-1",children:"AMS-HT °C"}),i.jsx("th",{className:"text-center py-1.5 px-1",children:"AMS 2 Pro h"}),i.jsx("th",{className:"text-center py-1.5 px-1",children:"AMS-HT h"})]})}),i.jsx("tbody",{children:(()=>{const _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}};let zt={..._e};try{if(k.drying_presets){const Pt=JSON.parse(k.drying_presets);typeof Pt=="object"&&Pt!==null&&(zt={..._e,...Pt})}}catch{}const mt=(Pt,rn,rt)=>{const un={...zt,[Pt]:{...zt[Pt],[rn]:rt}};on("drying_presets",JSON.stringify(un))};return Object.entries(zt).map(([Pt,rn])=>i.jsxs("tr",{className:"border-b border-bambu-dark-tertiary/50",children:[i.jsx("td",{className:"py-1.5 pr-2 text-white font-medium",children:Pt}),["n3f","n3s","n3f_hours","n3s_hours"].map(rt=>i.jsx("td",{className:"py-1 px-1",children:i.jsx("input",{type:"number",min:rt.includes("hours")?1:30,max:rt.includes("hours")?24:rt==="n3s"?85:65,value:rn[rt],onChange:un=>mt(Pt,rt,Math.max(1,parseInt(un.target.value)||0)),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"})},rt))]},Pt))})()})]})})]})]}),i.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 text-white",children:[i.jsx(Sr,{className:"w-4 h-4 text-bambu-green"}),i.jsx("span",{className:"font-medium",children:a("settings.printModal")})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-white",children:a("settings.expandCustomMapping")}),i.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:a("settings.expandCustomMappingDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.per_printer_mapping_expanded??!1,onChange:_e=>on("per_printer_mapping_expanded",_e.target.checked),className:"sr-only peer"}),i.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.jsxs("div",{className:"lg:w-2/3 space-y-6",children:[i.jsx(wet,{}),i.jsx(_et,{})]})]})}),ue!==null&&i.jsx(Sn,{title:a("settings.deleteApiKeyTitle"),message:a("settings.deleteApiKeyMessage"),confirmText:a("settings.deleteKey"),variant:"danger",onConfirm:()=>{tn.mutate(ue),fe(null)},onCancel:()=>fe(null)}),P&&i.jsx(det,{plug:H,onClose:()=>{D(!1),z(null)}}),G&&i.jsx(pet,{provider:ee,onClose:()=>{I(!1),ie(null)}}),X&&i.jsx(fet,{template:X,onClose:()=>me(null)}),he&&i.jsx(bet,{onClose:()=>ge(!1)}),L&&i.jsx(Sn,{title:a("settings.clearNotificationLogs"),message:a("settings.clearLogsMessage"),confirmText:a("settings.clearLogs"),variant:"warning",onConfirm:async()=>{F(!1);try{const _e=await be.clearNotificationLogs(30);o(_e.message,"success")}catch{o(a("settings.toast.clearLogsFailed"),"error")}},onCancel:()=>F(!1)}),te&&i.jsx(Sn,{title:a("settings.resetUiPreferences"),message:a("settings.resetUiPreferencesMessage"),confirmText:a("settings.resetPreferences"),variant:"default",onConfirm:()=>{ve(!1),localStorage.clear(),o(a("settings.toast.uiPreferencesReset"),"success"),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>ve(!1)}),pe&&i.jsx(Sn,{title:`Turn All Plugs ${pe==="on"?"On":"Off"}`,message:`This will turn ${pe==="on"?"ON":"OFF"} all ${Me?.filter(_e=>_e.enabled).length||0} enabled smart plugs. ${pe==="off"?"Any running printers may be affected!":""}`,confirmText:`Turn All ${pe==="on"?"On":"Off"}`,variant:pe==="off"?"danger":"warning",onConfirm:()=>{const _e=pe;de(null),Bi.mutate(_e)},onCancel:()=>de(null)}),Ne&&Tn?.release_notes&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:()=>Se(!1),children:i.jsxs(Mt,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",onClick:_e=>_e.stopPropagation(),children:[i.jsxs(Hn,{className:"flex flex-row items-center justify-between shrink-0",children:[i.jsxs("div",{children:[i.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Release Notes - v",Tn.latest_version]}),Tn.release_name&&Tn.release_name!==Tn.latest_version&&i.jsx("p",{className:"text-sm text-bambu-gray",children:Tn.release_name})]}),i.jsx("button",{onClick:()=>Se(!1),className:"p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsx(Dt,{className:"overflow-y-auto flex-1",children:i.jsx("pre",{className:"text-sm text-bambu-gray whitespace-pre-wrap font-sans",children:Tn.release_notes})}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary shrink-0 flex gap-2",children:[Tn.release_url&&i.jsx("a",{href:Tn.release_url,target:"_blank",rel:"noopener noreferrer",className:"flex-1",children:i.jsxs(Oe,{variant:"secondary",className:"w-full",children:[i.jsx(Jr,{className:"w-4 h-4"}),"View on GitHub"]})}),i.jsx(Oe,{onClick:()=>Se(!1),className:"flex-1",children:"Close"})]})]})}),q==="users"&&i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"flex gap-1 border-b border-bambu-dark-tertiary",children:[i.jsxs("button",{onClick:()=>E("users"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${j==="users"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Km,{className:"w-4 h-4"}),a("settings.tabs.users")]}),i.jsxs("button",{onClick:()=>E("email"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${j==="email"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(ix,{className:"w-4 h-4"}),a("settings.tabs.emailAuth")||"Email Authentication",Tr?.advanced_auth_enabled&&i.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"})]})]}),j==="users"&&i.jsxs(i.Fragment,{children:[i.jsx(Mt,{children:i.jsx(Dt,{className:"py-4",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center ${l?"bg-green-500/20":"bg-gray-500/20"}`,children:l?i.jsx(Ap,{className:"w-5 h-5 text-green-400"}):i.jsx(K1,{className:"w-5 h-5 text-gray-400"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-white font-medium",children:a("settings.authentication")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a(l?"settings.authEnabledDescription":"settings.authDisabledDescription")})]})]}),l?c?.is_admin&&i.jsxs(Oe,{variant:"secondary",onClick:()=>qe(!0),children:[i.jsx(K1,{className:"w-4 h-4"}),a("common.disable")]}):i.jsxs(Oe,{onClick:()=>e("/setup"),children:[i.jsx(Ap,{className:"w-4 h-4"}),a("common.enable")]})]})})}),Tr?.advanced_auth_enabled&&i.jsx(Mt,{className:"border-blue-500/30 bg-blue-500/5",children:i.jsx(Dt,{className:"py-4",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center bg-blue-500/20 flex-shrink-0",children:i.jsx(ix,{className:"w-5 h-5 text-blue-400"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-white font-medium",children:a("settings.email.advancedAuthEnabled")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a("settings.email.advancedAuthEnabledDesc")})]})]})})}),l&&i.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-6",children:[i.jsxs("div",{className:"space-y-6",children:[c&&i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Km,{className:"w-5 h-5 text-bambu-green"}),a("settings.currentUser")]}),i.jsxs(Oe,{size:"sm",variant:"ghost",onClick:()=>Te(!0),children:[i.jsx(Sl,{className:"w-4 h-4"}),a("settings.changePassword")]})]})}),i.jsx(Dt,{children:i.jsx("div",{className:"flex items-center justify-between",children:i.jsxs("div",{children:[i.jsx("p",{className:"text-white font-medium text-lg",children:c.username}),i.jsxs("div",{className:"flex flex-wrap gap-1 mt-2",children:[c.is_admin&&i.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:a("settings.admin")}),c.groups?.map(_e=>i.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${_e.name==="Administrators"?"bg-purple-500/20 text-purple-300":_e.name==="Operators"?"bg-blue-500/20 text-blue-300":_e.name==="Viewers"?"bg-green-500/20 text-green-300":"bg-gray-500/20 text-gray-300"}`,children:_e.name},_e.id))]})]})})})]}),i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Km,{className:"w-5 h-5 text-bambu-green"}),a("settings.users")]}),zi("users:create")&&i.jsxs(Oe,{size:"sm",onClick:()=>{Ge(!0),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:[i.jsx(ar,{className:"w-4 h-4"}),a("settings.addUser")]})]})}),i.jsx(Dt,{children:Yh?i.jsx("div",{className:"flex items-center justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Zd.length===0?i.jsx("p",{className:"text-center text-bambu-gray py-8",children:a("settings.noUsersFound")}):i.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:Zd.map(_e=>i.jsxs("div",{className:"py-3 flex items-center justify-between",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-white font-medium truncate",children:_e.username}),i.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[_e.is_admin&&i.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:a("settings.admin")}),_e.groups?.map(zt=>i.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${zt.name==="Administrators"?"bg-purple-500/20 text-purple-300":zt.name==="Operators"?"bg-blue-500/20 text-blue-300":zt.name==="Viewers"?"bg-green-500/20 text-green-300":"bg-gray-500/20 text-gray-300"}`,children:zt.name},zt.id))]})]}),i.jsxs("div",{className:"flex items-center gap-1 ml-4",children:[zi("users:update")&&i.jsx(Oe,{size:"sm",variant:"ghost",onClick:()=>Xh(_e),children:i.jsx(nh,{className:"w-4 h-4"})}),zi("users:delete")&&_e.id!==c?.id&&i.jsx(Oe,{size:"sm",variant:"ghost",onClick:()=>Ns(_e.id),children:i.jsx(Jt,{className:"w-4 h-4"})})]})]},_e.id))})})]})]}),i.jsx("div",{children:i.jsxs(Mt,{children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(v3,{className:"w-5 h-5 text-bambu-green"}),a("settings.groups")]}),zi("groups:create")&&i.jsxs(Oe,{size:"sm",onClick:()=>e("/groups/new"),children:[i.jsx(ar,{className:"w-4 h-4"}),a("settings.addGroup")]})]})}),i.jsx(Dt,{children:eg?i.jsx("div",{className:"flex items-center justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Ss.length===0?i.jsx("p",{className:"text-center text-bambu-gray py-8",children:a("settings.noGroupsFound")}):i.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:Ss.map(_e=>i.jsxs("div",{className:"py-3",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(v3,{className:`w-4 h-4 ${_e.name==="Administrators"?"text-purple-400":_e.name==="Operators"?"text-blue-400":_e.name==="Viewers"?"text-green-400":"text-bambu-gray"}`}),i.jsx("span",{className:"text-white font-medium",children:_e.name}),_e.is_system&&i.jsx("span",{className:"px-2 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:a("settings.system")})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[zi("groups:update")&&i.jsx(Oe,{size:"sm",variant:"ghost",onClick:()=>e(`/groups/${_e.id}/edit`),children:i.jsx(nh,{className:"w-4 h-4"})}),zi("groups:delete")&&!_e.is_system&&i.jsx(Oe,{size:"sm",variant:"ghost",onClick:()=>Vt(_e.id),children:i.jsx(Jt,{className:"w-4 h-4"})})]})]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1 ml-6",children:_e.description||a("settings.noDescription")}),i.jsxs("div",{className:"flex items-center gap-4 mt-2 ml-6 text-xs text-bambu-gray",children:[i.jsx("span",{children:a("settings.userCount",{count:_e.user_count})}),i.jsx("span",{children:a("settings.permissionCount",{count:_e.permissions.length})})]})]},_e.id))})})]})})]}),!l&&i.jsx(Mt,{children:i.jsx(Dt,{className:"py-6",children:i.jsxs("div",{className:"text-center",children:[i.jsx(K1,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:a("settings.authDisabledTitle")}),i.jsx("p",{className:"text-sm text-bambu-gray mb-4 max-w-md mx-auto",children:a("settings.authDisabledMessage")}),i.jsxs("ul",{className:"space-y-2 text-sm text-bambu-gray mb-6 text-left max-w-xs mx-auto",children:[i.jsxs("li",{className:"flex items-start gap-2",children:[i.jsx(fr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),i.jsx("span",{children:a("settings.authDisabledFeature1")})]}),i.jsxs("li",{className:"flex items-start gap-2",children:[i.jsx(fr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),i.jsx("span",{children:a("settings.authDisabledFeature2")})]}),i.jsxs("li",{className:"flex items-start gap-2",children:[i.jsx(fr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),i.jsx("span",{children:a("settings.authDisabledFeature3")})]})]}),i.jsxs(Oe,{onClick:()=>e("/setup"),children:[i.jsx(Ap,{className:"w-4 h-4"}),a("settings.enableAuthentication")]})]})})})]}),j==="email"&&i.jsx("div",{className:"max-w-2xl",children:i.jsx(Det,{})})]}),Ce&&!Tr?.advanced_auth_enabled&&i.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Ge(!1),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i.jsxs(Mt,{className:"w-full max-w-md",onClick:_e=>_e.stopPropagation(),children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Km,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.createUser")})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>{Ge(!1),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i.jsx(Ht,{className:"w-5 h-5"})})]})}),i.jsxs(Dt,{children:[i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.username")}),i.jsx("input",{type:"text",value:wt.username,onChange:_e=>_t({...wt,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:a("settings.enterUsername"),autoComplete:"username"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.password")}),i.jsx("input",{type:"password",value:wt.password,onChange:_e=>_t({...wt,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:a("settings.enterPassword"),autoComplete:"new-password",minLength:6})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.confirmPassword")}),i.jsx("input",{type:"password",value:wt.confirmPassword,onChange:_e=>_t({...wt,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 ${wt.confirmPassword&&wt.password!==wt.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:a("settings.confirmPasswordPlaceholder"),autoComplete:"new-password",minLength:6}),wt.confirmPassword&&wt.password!==wt.confirmPassword&&i.jsx("p",{className:"text-red-400 text-xs mt-1",children:a("settings.passwordsDoNotMatch")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.groups")}),i.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:[Ss.map(_e=>i.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:wt.group_ids.includes(_e.id),onChange:()=>Ql(_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"}),i.jsx("span",{className:"text-sm text-white",children:_e.name}),_e.is_system&&i.jsx("span",{className:"text-xs text-yellow-400",children:a("settings.systemBadge")})]},_e.id)),Ss.length===0&&i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.noGroupsAvailable")})]})]})]}),i.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>{Ge(!1),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:a("common.cancel")}),i.jsx(Oe,{onClick:Jo,disabled:Yl.isPending||!wt.username||!wt.password||wt.password!==wt.confirmPassword||wt.password.length<6,children:Yl.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),a("settings.creating")]}):i.jsxs(i.Fragment,{children:[i.jsx(ar,{className:"w-4 h-4"}),a("settings.createUser")]})})]})]})]})}),Ce&&Tr?.advanced_auth_enabled&&i.jsx(yet,{formData:wt,setFormData:_t,groups:Ss,onClose:()=>{Ge(!1),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},onCreate:Jo,isCreating:Yl.isPending,isCreateButtonDisabled:Yl.isPending||!wt.username||!wt.email}),$e&&De!==null&&i.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Ue(!1),Ve(null),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i.jsxs(Mt,{className:"w-full max-w-md",onClick:_e=>_e.stopPropagation(),children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(nh,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.editUser")})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>{Ue(!1),Ve(null),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i.jsx(Ht,{className:"w-5 h-5"})})]})}),i.jsxs(Dt,{children:[i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[a("settings.username")," ",Tr?.advanced_auth_enabled&&i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsx("input",{type:"text",value:wt.username,onChange:_e=>_t({...wt,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:a("settings.enterUsername"),autoComplete:"username"})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[a("users.form.email")||"Email"," ",Tr?.advanced_auth_enabled?i.jsx("span",{className:"text-red-400",children:"*"}):i.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",a("users.form.optional")||"optional",")"]})]}),i.jsx("input",{type:"email",value:wt.email,onChange:_e=>_t({...wt,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:a("users.form.emailPlaceholder")||"user@example.com",required:Tr?.advanced_auth_enabled})]}),!Tr?.advanced_auth_enabled&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[a("users.form.password")||"Password"," ",i.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",a("users.form.leaveBlankToKeep")||"leave blank to keep current",")"]})]}),i.jsx("input",{type:"password",value:wt.password,onChange:_e=>_t({...wt,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:a("settings.enterNewPassword"),autoComplete:"new-password",minLength:6})]}),wt.password&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.confirmPassword")}),i.jsx("input",{type:"password",value:wt.confirmPassword,onChange:_e=>_t({...wt,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 ${wt.confirmPassword&&wt.password!==wt.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:a("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),wt.confirmPassword&&wt.password!==wt.confirmPassword&&i.jsx("p",{className:"text-red-400 text-xs mt-1",children:a("settings.passwordsDoNotMatch")})]})]}),Tr?.advanced_auth_enabled&&i.jsxs("div",{className:"bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-3",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("users.form.passwordManagedByAdvancedAuth")||'Password is managed by Advanced Authentication. Use "Reset Password" to send a new password to the user via email.'}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>De&&Xl.mutate(De),disabled:Xl.isPending||!wt.email,className:"w-full",children:Xl.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),a("users.form.resettingPassword")||"Resetting Password..."]}):i.jsxs(i.Fragment,{children:[i.jsx(bo,{className:"w-4 h-4"}),a("users.form.resetPassword")||"Reset Password"]})})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("users.form.groups")||"Groups"}),i.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:Ss.map(_e=>i.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:wt.group_ids.includes(_e.id),onChange:()=>Ql(_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"}),i.jsx("span",{className:"text-sm text-white",children:_e.name}),_e.is_system&&i.jsxs("span",{className:"text-xs text-yellow-400",children:["(",a("users.system")||"System",")"]})]},_e.id))})]})]}),i.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>{Ue(!1),Ve(null),_t({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:a("users.modal.cancel")||"Cancel"}),i.jsx(Oe,{onClick:()=>el(De),disabled:_s.isPending||!wt.username||Tr?.advanced_auth_enabled&&!wt.email||!!(!Tr?.advanced_auth_enabled&&wt.password&&(wt.password!==wt.confirmPassword||wt.password.length<6)),children:_s.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),a("users.modal.saving")||"Saving..."]}):i.jsxs(i.Fragment,{children:[i.jsx(ts,{className:"w-4 h-4"}),a("users.modal.saveChanges")||"Save Changes"]})})]})]})]})}),it!==null&&i.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",onClick:()=>{xt(null),kt(null)},children:i.jsxs(Mt,{className:"w-full max-w-md",onClick:_e=>_e.stopPropagation(),children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center gap-2 text-red-400",children:[i.jsx(Jt,{className:"w-5 h-5"}),i.jsx("h3",{className:"text-lg font-semibold",children:a("settings.deleteUserTitle")})]})}),i.jsx(Dt,{className:"space-y-4",children:We?i.jsx("div",{className:"flex items-center justify-center py-4",children:i.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-2 border-bambu-green border-t-transparent"})}):Nt&&Nt.archives+Nt.queue_items+Nt.library_files>0?i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"text-white",children:a("settings.userHasCreated")}),i.jsxs("ul",{className:"list-disc list-inside text-bambu-gray space-y-1",children:[Nt.archives>0&&i.jsxs("li",{children:[Nt.archives," archive",Nt.archives!==1?"s":""]}),Nt.queue_items>0&&i.jsxs("li",{children:[Nt.queue_items," queue item",Nt.queue_items!==1?"s":""]}),Nt.library_files>0&&i.jsxs("li",{children:[Nt.library_files," library file",Nt.library_files!==1?"s":""]})]}),i.jsx("p",{className:"text-bambu-gray text-sm",children:a("settings.userItemsQuestion")}),i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx(Oe,{variant:"danger",onClick:()=>ci.mutate({id:it,deleteItems:!0}),disabled:ci.isPending,className:"justify-center",children:a("settings.deleteUserAndItems")}),i.jsx(Oe,{variant:"secondary",onClick:()=>ci.mutate({id:it,deleteItems:!1}),disabled:ci.isPending,className:"justify-center",children:a("settings.deleteUserKeepItems")}),i.jsx(Oe,{variant:"ghost",onClick:()=>{xt(null),kt(null)},disabled:ci.isPending,className:"justify-center",children:a("common.cancel")})]})]}):i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"text-white",children:a("settings.deleteUserConfirm")}),i.jsx("p",{className:"text-bambu-gray text-sm",children:a("settings.actionCannotBeUndone")}),i.jsxs("div",{className:"flex gap-2 justify-end",children:[i.jsx(Oe,{variant:"ghost",onClick:()=>{xt(null),kt(null)},disabled:ci.isPending,children:a("common.cancel")}),i.jsx(Oe,{variant:"danger",onClick:()=>ci.mutate({id:it,deleteItems:!1}),disabled:ci.isPending,children:a("settings.deleteUserTitle")})]})]})})]})}),Ot!==null&&i.jsx(Sn,{title:a("settings.deleteGroupTitle"),message:a("settings.deleteGroupMessage"),confirmText:a("settings.deleteGroup"),variant:"danger",onConfirm:()=>{Zo.mutate(Ot),Vt(null)},onCancel:()=>Vt(null)}),q==="backup"&&i.jsx(Met,{}),Le&&i.jsx(Sn,{title:a("settings.disableAuthenticationTitle"),message:a("settings.disableAuthenticationMessage"),confirmText:a("settings.disableAuthentication"),variant:"danger",onConfirm:async()=>{try{await be.disableAuth(),o(a("settings.toast.authDisabled"),"success"),await u(),qe(!1),window.location.href="/"}catch(_e){const zt=_e instanceof Error?_e.message:a("settings.toast.authDisableFailed");o(zt,"error")}},onCancel:()=>qe(!1)}),Ee&&i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:()=>{Te(!1),Be({currentPassword:"",newPassword:"",confirmPassword:""})},children:i.jsxs(Mt,{className:"w-full max-w-md",onClick:_e=>_e.stopPropagation(),children:[i.jsx(Hn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Sl,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.changePassword")})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>{Te(!1),Be({currentPassword:"",newPassword:"",confirmPassword:""})},children:i.jsx(Ht,{className:"w-5 h-5"})})]})}),i.jsxs(Dt,{children:[i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Current Password"}),i.jsx("input",{type:"password",value:Ae.currentPassword,onChange:_e=>Be({...Ae,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:a("settings.enterCurrentPassword"),autoComplete:"current-password"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"New Password"}),i.jsx("input",{type:"password",value:Ae.newPassword,onChange:_e=>Be({...Ae,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:a("settings.enterNewPasswordMin6"),autoComplete:"new-password",minLength:6})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Confirm New Password"}),i.jsx("input",{type:"password",value:Ae.confirmPassword,onChange:_e=>Be({...Ae,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 ${Ae.confirmPassword&&Ae.newPassword!==Ae.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:a("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),Ae.confirmPassword&&Ae.newPassword!==Ae.confirmPassword&&i.jsx("p",{className:"text-red-400 text-xs mt-1",children:a("settings.passwordsDoNotMatch")})]})]}),i.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>{Te(!1),Be({currentPassword:"",newPassword:"",confirmPassword:""})},children:a("common.cancel")}),i.jsx(Oe,{onClick:async()=>{if(Ae.newPassword!==Ae.confirmPassword){o(a("settings.toast.passwordsDoNotMatch"),"error");return}if(Ae.newPassword.length<6){o(a("settings.toast.passwordTooShort"),"error");return}Xe(!0);try{await be.changePassword(Ae.currentPassword,Ae.newPassword),o(a("settings.toast.passwordChanged"),"success"),Te(!1),Be({currentPassword:"",newPassword:"",confirmPassword:""})}catch(_e){const zt=_e instanceof Error?_e.message:"Failed to change password";o(zt,"error")}finally{Xe(!1)}},disabled:je||!Ae.currentPassword||!Ae.newPassword||Ae.newPassword!==Ae.confirmPassword||Ae.newPassword.length<6,children:je?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),a("settings.changing")]}):i.jsxs(i.Fragment,{children:[i.jsx(Sl,{className:"w-4 h-4"}),a("settings.changePassword")]})})]})]})]})})]})}const Loe=t=>{const e=parseFloat(t);return(Math.trunc(e*1e3)/1e3).toFixed(3)},Bet=t=>t.startsWith("HH")?"HF":"S",Het=t=>{const e=t.match(/^([A-Z]{2}\d{2})/);return e?e[1]:"HH00"},Ooe=t=>{const e=["High Flow_","High Flow ","Standard_","Standard ","HF_","HF ","S_","S "];for(const r of e)if(t.startsWith(r))return t.slice(r.length);const n=t.indexOf("_");return n>0?t.slice(n+1):t};function zD({profile:t,onEdit:e,onCopy:n,selectionMode:r,isSelected:a,onToggleSelect:s,note:o}){const l=Bet(t.nozzle_id),c=t.nozzle_diameter,u=()=>{r&&s?s():e()};return i.jsxs("div",{className:"flex items-center gap-2",children:[r&&i.jsx("button",{onClick:s,className:"text-bambu-gray hover:text-white transition-colors p-1",children:a?i.jsx(xo,{className:"w-4 h-4 text-bambu-green"}):i.jsx(zl,{className:"w-4 h-4"})}),i.jsxs("button",{onClick:u,className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${a?"ring-1 ring-bambu-green":""}`,children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-bambu-green font-mono text-sm font-bold whitespace-nowrap",children:Loe(t.k_value)}),i.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name||"Unnamed"}),o&&i.jsx("span",{title:"Has note",children:i.jsx(ZX,{className:"w-3 h-3 text-yellow-500"})}),i.jsxs("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:[l," ",c]})]}),o&&i.jsxs("div",{className:"text-xs mt-0.5 truncate text-yellow-500/70",title:o,children:["Note: ",o.length>50?o.substring(0,50)+"...":o]})]}),!r&&n&&i.jsx("button",{onClick:d=>{d.stopPropagation(),n()},className:"text-bambu-gray hover:text-white transition-colors p-1",title:"Copy profile",children:i.jsx(fo,{className:"w-4 h-4"})})]})}function UD({profile:t,printerId:e,nozzleDiameter:n,existingProfiles:r=[],builtinFilaments:a=[],isDualNozzle:s=!1,initialNote:o="",initialNoteKey:l=null,onClose:c,onSave:u,onSaveNote:d,hasPermission:m}){const{t:p}=Ft(),{showToast:f}=fn(),[y,v]=w.useState(t?.name||""),[x,g]=w.useState(t?.k_value?Loe(t.k_value):"0.020"),[_,N]=w.useState(t?.filament_id||""),[T,C]=w.useState(t?.nozzle_id?Het(t.nozzle_id):"HH00"),[A,k]=w.useState(t?.nozzle_diameter||n),[R,P]=w.useState(t?[t.extruder_id]:s?[0,1]:[0]),[D,H]=w.useState(!1),[z,G]=w.useState({current:0,total:0}),[I,ee]=w.useState(o),ie=Vr.useMemo(()=>{const le=new Map;for(const Pe of a)le.set(Pe.filament_id,Pe.name);const xe=new Map;for(const Pe of r)if(Pe.filament_id&&!xe.has(Pe.filament_id)){const Z=le.get(Pe.filament_id)||Ooe(Pe.name||"");xe.set(Pe.filament_id,{id:Pe.filament_id,name:Z||Pe.filament_id})}return Array.from(xe.values()).sort((Pe,q)=>Pe.name.localeCompare(q.name))},[r,a]),X=pt({mutationFn:le=>(console.log("[KProfile] Calling API..."),be.setKProfile(e,le)),onSuccess:le=>{if(console.log("[KProfile] Save success:",le),f(p("kProfiles.toast.profileSaved")),d&&I!==o){let xe;I===""&&l?xe=l:t&&t.slot_id>0?xe=t.setting_id||`slot_${t.slot_id}_${t.filament_id}_${t.extruder_id}`:xe=`name_${y}_${_}`,d(xe,I)}H(!0),setTimeout(()=>{H(!1),u()},2500)},onError:le=>{console.error("[KProfile] Save error:",le),f(le.message,"error"),H(!1)}}),me=pt({mutationFn:le=>(console.log("[KProfile] Deleting profile..."),be.deleteKProfile(e,le)),onSuccess:le=>{console.log("[KProfile] Delete success:",le),f(p("kProfiles.toast.profileDeleted")),H(!0),setTimeout(()=>{H(!1),c()},4e3)},onError:le=>{console.error("[KProfile] Delete error:",le),f(le.message,"error"),H(!1)}}),[he,ge]=w.useState(!1),Y=()=>{t&&me.mutate({slot_id:t.slot_id,extruder_id:t.extruder_id,nozzle_id:t.nozzle_id,nozzle_diameter:t.nozzle_diameter,filament_id:t.filament_id,setting_id:t.setting_id})},oe=async le=>{if(le.preventDefault(),s&&!t&&R.length===0){f(p("kProfiles.toast.selectAtLeastOneExtruder"),"error");return}const xe=parseFloat(x).toFixed(6),Pe=`${T}-${A}`;if(t||R.length===1){const Z={name:y,k_value:xe,filament_id:_,nozzle_id:Pe,nozzle_diameter:A,extruder_id:t?t.extruder_id:R[0],setting_id:t?.setting_id,slot_id:t?.slot_id??0};console.log("[KProfile] Saving profile:",Z),X.mutate(Z);return}H(!0),G({current:1,total:R.length});const q=R.map(Z=>({name:y,k_value:xe,filament_id:_,nozzle_id:Pe,nozzle_diameter:A,extruder_id:Z,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${q.length} profiles in batch:`,q);try{if(await be.setKProfilesBatch(e,q),f(p("kProfiles.toast.profilesSaved",{count:R.length})),d&&I){const Z=`name_${y}_${_}`;d(Z,I)}}catch(Z){console.error("[KProfile] Failed to save batch:",Z),f(p("kProfiles.toast.failedToSaveBatch"),"error"),H(!1),G({current:0,total:0});return}G({current:R.length,total:R.length}),setTimeout(()=>{H(!1),G({current:0,total:0}),u()},3e3)};return i.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:[i.jsxs(Mt,{className:"w-full max-w-md relative",children:[D&&i.jsxs("div",{className:"absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg",children:[i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin mb-3"}),i.jsx("p",{className:"text-white font-medium",children:z.total>1?p("kProfiles.modal.savingExtruder",{current:z.current,total:z.total}):p("kProfiles.modal.syncing")}),i.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:p("kProfiles.modal.pleaseWait")})]}),i.jsxs(Dt,{className:"p-0",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsx("h2",{className:"text-xl font-semibold text-white",children:p(t?"kProfiles.modal.editTitle":"kProfiles.modal.addTitle")}),i.jsx("button",{onClick:c,className:"text-bambu-gray hover:text-white transition-colors",disabled:D,children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:oe,className:"p-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.profileName")}),i.jsx("input",{type:"text",value:y,onChange:le=>v(le.target.value),disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,placeholder:p("kProfiles.modal.profileNamePlaceholder"),required:!t})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.kValue")}),i.jsx("input",{type:"text",inputMode:"decimal",value:x,onChange:le=>{const xe=le.target.value;(xe===""||/^\d*\.?\d*$/.test(xe))&&g(xe)},onBlur:le=>{const xe=parseFloat(le.target.value);isNaN(xe)||g((Math.trunc(xe*1e3)/1e3).toFixed(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",placeholder:p("kProfiles.modal.kValuePlaceholder"),required:!0}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:p("kProfiles.modal.kValueHelp")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.filament")}),i.jsxs("select",{value:_,onChange:le=>{const xe=le.target.value;if(N(xe),!t&&xe&&!y){const Pe=ie.find(q=>q.id===xe);Pe&&v(`${T==="HH00"?"HF":"S"} ${Pe.name}`)}},disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,required:!t,children:[i.jsx("option",{value:"",children:p("kProfiles.modal.selectFilament")}),t?.filament_id&&i.jsx("option",{value:t.filament_id,children:ie.find(le=>le.id===t.filament_id)?.name||t.filament_id},t.filament_id),!t&&ie.map(le=>i.jsx("option",{value:le.id,children:le.name},le.id))]}),!t&&ie.length===0&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:p("kProfiles.modal.noFilamentsHelp")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.flowType")}),i.jsxs("select",{value:T,onChange:le=>{const xe=le.target.value;if(C(xe),!t&&_&&!y){const Pe=ie.find(q=>q.id===_);Pe&&v(`${xe==="HS00"?"HF":"S"} ${Pe.name}`)}},disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,children:[i.jsx("option",{value:"HH00",children:p("kProfiles.modal.highFlow")}),i.jsx("option",{value:"HS00",children:p("kProfiles.modal.standard")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.nozzleSize")}),i.jsxs("select",{value:A,onChange:le=>k(le.target.value),disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,children:[i.jsx("option",{value:"0.2",children:"0.2mm"}),i.jsx("option",{value:"0.4",children:"0.4mm"}),i.jsx("option",{value:"0.6",children:"0.6mm"}),i.jsx("option",{value:"0.8",children:"0.8mm"})]})]})]}),s&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p(t?"kProfiles.modal.extruder":"kProfiles.modal.extruders")}),t?i.jsx("div",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60",children:t.extruder_id===1?p("kProfiles.modal.left"):p("kProfiles.modal.right")}):i.jsxs("div",{className:"flex gap-4",children:[i.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:R.includes(1),onChange:le=>{le.target.checked?P([...R,1]):P(R.filter(xe=>xe!==1))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),i.jsx("span",{className:"text-white",children:p("kProfiles.modal.left")})]}),i.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:R.includes(0),onChange:le=>{le.target.checked?P([...R,0]):P(R.filter(xe=>xe!==0))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),i.jsx("span",{className:"text-white",children:p("kProfiles.modal.right")})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.notes")}),i.jsx("textarea",{value:I,onChange:le=>ee(le.target.value),placeholder:p("kProfiles.modal.notesPlaceholder"),rows:2,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 resize-none"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:p("kProfiles.modal.notesHelp")})]}),i.jsxs("div",{className:"flex gap-2 pt-4",children:[t&&i.jsx(Oe,{type:"button",variant:"secondary",onClick:()=>ge(!0),disabled:me.isPending||D||!m("kprofiles:delete"),title:m("kprofiles:delete")?void 0:p("kProfiles.permission.noDelete"),className:"text-red-500 hover:bg-red-500/10",children:me.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Jt,{className:"w-4 h-4"})}),i.jsx(Oe,{type:"button",variant:"secondary",onClick:c,disabled:D,className:"flex-1",children:p("common.cancel")}),i.jsxs(Oe,{type:"submit",disabled:X.isPending||D||!m(t?"kprofiles:update":"kprofiles:create"),title:m(t?"kprofiles:update":"kprofiles:create")?void 0:p(t?"kProfiles.permission.noUpdate":"kProfiles.permission.noCreate"),className:"flex-1",children:[X.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(ZC,{className:"w-4 h-4"}),p("common.save")]})]})]})]})]}),he&&i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",children:i.jsx(Mt,{className:"w-full max-w-sm",children:i.jsxs(Dt,{className:"p-6",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[i.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:i.jsx(Jt,{className:"w-5 h-5 text-red-500"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:p("kProfiles.deleteConfirm.title")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:p("kProfiles.deleteConfirm.cannotUndo")})]})]}),i.jsx("p",{className:"text-bambu-gray mb-6",children:p("kProfiles.deleteConfirm.message",{name:t?.name})}),i.jsxs("div",{className:"flex gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>ge(!1),className:"flex-1",children:p("common.cancel")}),i.jsxs(Oe,{onClick:()=>{ge(!1),Y()},disabled:me.isPending,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[me.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Jt,{className:"w-4 h-4"}),p("common.delete")]})]})]})})})]})}const V1={NOZZLE_DIAMETER:"bambusy_kprofiles_nozzle",SORT_OPTION:"bambusy_kprofiles_sort"};function $et(){const{t}=Ft(),{showToast:e}=fn(),{hasPermission:n}=_r(),[r,a]=w.useState(null),[s,o]=w.useState(()=>localStorage.getItem(V1.NOZZLE_DIAMETER)||"0.4"),[l,c]=w.useState(null),[u,d]=w.useState(!1),[m,p]=w.useState(null),[f,y]=w.useState(""),[v,x]=w.useState("all"),[g,_]=w.useState("all"),[N,T]=w.useState(()=>localStorage.getItem(V1.SORT_OPTION)||"name"),[C,A]=w.useState(!1),[k,R]=w.useState(new Set),[P,D]=w.useState(!1),[H,z]=w.useState(!1),G=w.useCallback(F=>`${F.slot_id}_${F.extruder_id}`,[]);w.useEffect(()=>{localStorage.setItem(V1.NOZZLE_DIAMETER,s)},[s]),w.useEffect(()=>{localStorage.setItem(V1.SORT_OPTION,N)},[N]);const{data:I,isLoading:ee}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:ie,isLoading:X,isFetching:me,error:he,refetch:ge}=et({queryKey:["kprofiles",r,s],queryFn:async()=>{console.log("[KProfiles] Fetching profiles for printer",r,"nozzle",s);const F=await be.getKProfiles(r,s);return console.log("[KProfiles] Received profiles:",F?.profiles?.length||0,"profiles"),F},enabled:!!r,retry:!1,staleTime:0,gcTime:0,refetchOnMount:"always"}),{data:Y}=et({queryKey:["kprofiles",r,"0.4"],queryFn:()=>be.getKProfiles(r,"0.4"),enabled:!!r,staleTime:6e4}),{data:oe}=et({queryKey:["builtinFilaments"],queryFn:()=>be.getBuiltinFilaments(),staleTime:3e5}),{data:le}=et({queryKey:["filamentIdMap"],queryFn:()=>be.getFilamentIdMap(),staleTime:3e5}),{data:xe,refetch:Pe}=et({queryKey:["kprofile-notes",r],queryFn:()=>be.getKProfileNotes(r),enabled:!!r,staleTime:3e4}),q=he?.message?.includes("not connected");w.useEffect(()=>{if(!r&&I&&I.length>0){const F=I.find(te=>te.is_active);F&&a(F.id)}},[r,I]),w.useEffect(()=>{if(r){const F=setTimeout(()=>{ge()},150);return()=>clearTimeout(F)}},[r,s]);const Z=I?.filter(F=>F.is_active)||[],j=Vr.useMemo(()=>{const F=new Map;if(oe)for(const te of oe)F.set(te.filament_id,te.name);if(le)for(const[te,ve]of Object.entries(le))F.has(te)||F.set(te,ve);return F},[oe,le]),E=Vr.useMemo(()=>Array.from(j.entries()).map(([F,te])=>({filament_id:F,name:te})),[j]),U=Vr.useCallback(F=>j.get(F.filament_id)||Ooe(F.name),[j]),K=Vr.useMemo(()=>ie?.profiles?ie.profiles.filter(te=>{const ve=f.toLowerCase(),pe=!ve||te.name.toLowerCase().includes(ve)||te.filament_id.toLowerCase().includes(ve),de=v==="all"||v==="left"&&te.extruder_id===1||v==="right"&&te.extruder_id===0,Ne=g==="all"||g==="hf"&&te.nozzle_id.startsWith("HH")||g==="s"&&te.nozzle_id.startsWith("HS");return pe&&de&&Ne}).sort((te,ve)=>{switch(N){case"k_value":return parseFloat(te.k_value)-parseFloat(ve.k_value);case"filament":return U(te).localeCompare(U(ve));default:return te.name.localeCompare(ve.name)}}):[],[ie?.profiles,f,v,g,N,U]),$=I?.find(F=>F.id===r),ne=$?.nozzle_count===2;w.useEffect(()=>{const F=te=>{te.target instanceof HTMLInputElement||te.target instanceof HTMLTextAreaElement||te.target instanceof HTMLSelectElement||l||u||m||(te.key==="r"||te.key==="R"?(te.preventDefault(),ge()):te.key==="n"||te.key==="N"?(te.preventDefault(),d(!0)):te.key==="Escape"&&C&&(te.preventDefault(),A(!1),R(new Set)))};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[l,u,m,C,ge]);const O=w.useCallback(()=>{if(!ie?.profiles||ie.profiles.length===0){e(t("kProfiles.toast.noProfilesToExport"),"error");return}const F={version:1,exported_at:new Date().toISOString(),printer:$?.name||"Unknown",nozzle_diameter:s,profiles:ie.profiles.map(de=>({name:de.name,k_value:de.k_value,filament_id:de.filament_id,nozzle_id:de.nozzle_id,nozzle_diameter:de.nozzle_diameter,extruder_id:de.extruder_id}))},te=new Blob([JSON.stringify(F,null,2)],{type:"application/json"}),ve=URL.createObjectURL(te),pe=document.createElement("a");pe.href=ve,pe.download=`kprofiles_${$?.name||"printer"}_${s}mm_${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(pe),pe.click(),document.body.removeChild(pe),URL.revokeObjectURL(ve),e(t("kProfiles.toast.exportedProfiles",{count:ie.profiles.length}))},[ie?.profiles,$,s,e,t]),V=w.useCallback(()=>{const F=document.createElement("input");F.type="file",F.accept=".json",F.onchange=async te=>{const ve=te.target.files?.[0];if(ve)try{const pe=await ve.text(),de=JSON.parse(pe);if(!de.profiles||!Array.isArray(de.profiles)){e(t("kProfiles.toast.invalidFileFormat"),"error");return}let Ne=0;for(const Se of de.profiles)if(!(!Se.name||!Se.k_value||!Se.filament_id))try{await be.setKProfile(r,{name:Se.name,k_value:parseFloat(Se.k_value).toFixed(6),filament_id:Se.filament_id,nozzle_id:Se.nozzle_id||`HH00-${s}`,nozzle_diameter:Se.nozzle_diameter||s,extruder_id:Se.extruder_id??0,slot_id:0}),Ne++,await new Promise(Le=>setTimeout(Le,500))}catch(Le){console.error("Failed to import profile:",Se.name,Le)}e(t("kProfiles.toast.importedProfiles",{count:Ne,total:de.profiles.length})),ge()}catch(pe){console.error("Import error:",pe),e(t("kProfiles.toast.failedToParseImport"),"error")}},F.click()},[r,s,e,ge,t]),J=w.useCallback(F=>{R(te=>{const ve=new Set(te);return ve.has(F)?ve.delete(F):ve.add(F),ve})},[]),W=w.useCallback(()=>{R(new Set(K.map(F=>G(F))))},[K,G]),re=w.useCallback(()=>{k.size!==0&&D(!0)},[k.size]),ue=w.useCallback(async()=>{const F=K.filter(ve=>k.has(G(ve)));z(!0);let te=0;for(const ve of F)try{await be.deleteKProfile(r,{slot_id:ve.slot_id,extruder_id:ve.extruder_id,nozzle_id:ve.nozzle_id,nozzle_diameter:ve.nozzle_diameter,filament_id:ve.filament_id,setting_id:ve.setting_id}),te++,await new Promise(pe=>setTimeout(pe,300))}catch(pe){console.error("Failed to delete profile:",ve.name,pe)}e(t("kProfiles.toast.profilesDeleted",{count:te})),z(!1),D(!1),A(!1),R(new Set),ge()},[r,k,K,e,ge,G,t]),fe=w.useCallback(F=>{const te=[];return F.setting_id&&te.push(F.setting_id),te.push(`slot_${F.slot_id}_${F.filament_id}_${F.extruder_id}`),te.push(`name_${F.name}_${F.filament_id}`),te},[]),ye=w.useCallback(async(F,te)=>{if(r)try{await be.setKProfileNote(r,F,te),Pe()}catch(ve){console.error("Failed to save note:",ve),e(t("kProfiles.toast.failedToSaveNote"),"error")}},[r,Pe,e,t]),ae=w.useCallback(F=>{if(!xe?.notes)return{note:"",key:null};const te=fe(F);for(const ve of te)if(xe.notes[ve])return{note:xe.notes[ve],key:ve};return{note:"",key:null}},[xe,fe]),L=w.useCallback(F=>ae(F).note,[ae]);return ee?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):!I||I.length===0?i.jsx(Mt,{children:i.jsxs(Dt,{className:"py-12 text-center",children:[i.jsx(Li,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noPrintersConfigured")}),i.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.addPrinterInSettings")})]})}):Z.length===0?i.jsx(Mt,{children:i.jsxs(Dt,{className:"py-12 text-center",children:[i.jsx(Sr,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noActivePrinters")}),i.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.enablePrinterConnection")})]})}):i.jsxs(i.Fragment,{children:[me&&!X&&i.jsxs("div",{className:"fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40",children:[i.jsx(ht,{className:"w-10 h-10 text-bambu-green animate-spin mb-3"}),i.jsx("p",{className:"text-white font-medium",children:t("kProfiles.loadingProfiles")})]}),i.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[i.jsxs("div",{className:"flex-1 min-w-48",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.printer")}),i.jsx("select",{value:r||"",onChange:F=>a(parseInt(F.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:Z.map(F=>i.jsx("option",{value:F.id,children:F.name},F.id))})]}),i.jsxs("div",{className:"w-32",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.nozzle")}),i.jsxs("select",{value:s,onChange:F=>o(F.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:[i.jsx("option",{value:"0.2",children:"0.2mm"}),i.jsx("option",{value:"0.4",children:"0.4mm"}),i.jsx("option",{value:"0.6",children:"0.6mm"}),i.jsx("option",{value:"0.8",children:"0.8mm"})]})]}),i.jsxs("div",{className:"flex items-end gap-2",children:[i.jsxs(Oe,{variant:"secondary",onClick:()=>ge(),disabled:me||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noRead"),children:[i.jsx(wr,{className:`w-4 h-4 ${me?"animate-spin":""}`}),t("kProfiles.refresh")]}),i.jsxs(Oe,{onClick:()=>d(!0),disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noCreate"),children:[i.jsx(ar,{className:"w-4 h-4"}),t("kProfiles.addProfile")]})]})]}),i.jsxs("div",{className:"flex flex-wrap gap-4 mb-4",children:[i.jsxs("div",{className:"flex-1 min-w-48 relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:f,onChange:F=>y(F.target.value),placeholder:t("kProfiles.searchPlaceholder"),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"})]}),ne&&i.jsx("div",{className:"w-36",children:i.jsxs("select",{value:v,onChange:F=>x(F.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:[i.jsx("option",{value:"all",children:t("kProfiles.allExtruders")}),i.jsx("option",{value:"left",children:t("kProfiles.leftOnly")}),i.jsx("option",{value:"right",children:t("kProfiles.rightOnly")})]})}),i.jsx("div",{className:"w-32",children:i.jsxs("select",{value:g,onChange:F=>_(F.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:[i.jsx("option",{value:"all",children:t("kProfiles.allFlow")}),i.jsx("option",{value:"hf",children:t("kProfiles.hfOnly")}),i.jsx("option",{value:"s",children:t("kProfiles.sOnly")})]})}),i.jsx("div",{className:"w-32",children:i.jsxs("select",{value:N,onChange:F=>T(F.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:[i.jsx("option",{value:"name",children:t("kProfiles.sortName")}),i.jsx("option",{value:"k_value",children:t("kProfiles.sortKValue")}),i.jsx("option",{value:"filament",children:t("kProfiles.sortFilament")})]})})]}),i.jsxs("div",{className:"flex flex-wrap gap-2 mb-6",children:[i.jsxs(Oe,{variant:"secondary",onClick:O,disabled:!ie?.profiles?.length||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noExport"),children:[i.jsx(pi,{className:"w-4 h-4"}),t("kProfiles.export")]}),i.jsxs(Oe,{variant:"secondary",onClick:V,disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noImport"),children:[i.jsx(xi,{className:"w-4 h-4"}),t("kProfiles.import")]}),i.jsx("div",{className:"flex-1"}),C?i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"secondary",onClick:W,children:[i.jsx(xo,{className:"w-4 h-4"}),t("kProfiles.selectAll")]}),i.jsxs(Oe,{variant:"secondary",onClick:re,disabled:k.size===0||!n("kprofiles:delete"),className:"text-red-500 hover:bg-red-500/10",title:n("kprofiles:delete")?void 0:t("kProfiles.permission.noDelete"),children:[i.jsx(Jt,{className:"w-4 h-4"}),t("kProfiles.delete")," (",k.size,")"]}),i.jsxs(Oe,{variant:"secondary",onClick:()=>{A(!1),R(new Set)},children:[i.jsx(Ht,{className:"w-4 h-4"}),t("common.cancel")]})]}):i.jsxs(Oe,{variant:"secondary",onClick:()=>A(!0),disabled:!K.length||!n("kprofiles:delete"),title:n("kprofiles:delete")?void 0:t("kProfiles.permission.noDelete"),children:[i.jsx(xo,{className:"w-4 h-4"}),t("kProfiles.select")]})]}),X?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):q?i.jsx(Mt,{children:i.jsxs(Dt,{className:"py-12 text-center",children:[i.jsx(Ph,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.printerOffline")}),i.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.printerOfflineDesc")}),i.jsxs(Oe,{variant:"secondary",onClick:()=>ge(),children:[i.jsx(wr,{className:"w-4 h-4"}),t("common.refresh")]})]})}):K.length>0?ne?i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.leftExtruder")}),i.jsx("div",{className:"space-y-1",children:K.filter(F=>F.extruder_id===1).map(F=>i.jsx(zD,{profile:F,onEdit:()=>c(F),onCopy:()=>p(F),selectionMode:C,isSelected:k.has(G(F)),onToggleSelect:()=>J(G(F)),note:L(F)},G(F)))})]}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.rightExtruder")}),i.jsx("div",{className:"space-y-1",children:K.filter(F=>F.extruder_id===0).map(F=>i.jsx(zD,{profile:F,onEdit:()=>c(F),onCopy:()=>p(F),selectionMode:C,isSelected:k.has(G(F)),onToggleSelect:()=>J(G(F)),note:L(F)},G(F)))})]})]}):i.jsx("div",{className:"space-y-1",children:K.map(F=>i.jsx(zD,{profile:F,onEdit:()=>c(F),onCopy:()=>p(F),selectionMode:C,isSelected:k.has(G(F)),onToggleSelect:()=>J(G(F)),note:L(F)},G(F)))}):f||v!=="all"||g!=="all"?i.jsx(Mt,{children:i.jsxs(Dt,{className:"py-12 text-center",children:[i.jsx(jr,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noMatchingProfiles")}),i.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.noMatchingProfilesDesc")})]})}):i.jsx(Mt,{children:i.jsxs(Dt,{className:"py-12 text-center",children:[i.jsx(ZC,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noKProfiles")}),i.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.noKProfilesDesc",{diameter:s})}),i.jsxs(Oe,{onClick:()=>d(!0),children:[i.jsx(ar,{className:"w-4 h-4"}),t("kProfiles.createFirstProfile")]})]})}),l&&r&&(()=>{const{note:F,key:te}=ae(l);return i.jsx(UD,{profile:l,printerId:r,nozzleDiameter:s,existingProfiles:Y?.profiles||ie?.profiles,builtinFilaments:E,isDualNozzle:ne,initialNote:F,initialNoteKey:te,onSaveNote:ye,hasPermission:n,onClose:()=>{console.log("[KProfiles] Edit modal onClose - refetching profiles..."),c(null),ge()},onSave:()=>{c(null),ge()}})})(),u&&r&&i.jsx(UD,{printerId:r,nozzleDiameter:s,existingProfiles:Y?.profiles||ie?.profiles,builtinFilaments:E,isDualNozzle:ne,onSaveNote:ye,hasPermission:n,onClose:()=>{d(!1),ge()},onSave:()=>{d(!1),ge()}}),m&&r&&i.jsx(UD,{printerId:r,nozzleDiameter:s,existingProfiles:Y?.profiles||ie?.profiles,builtinFilaments:E,isDualNozzle:ne,onSaveNote:ye,hasPermission:n,profile:{...m,slot_id:0,name:`${m.name} (Copy)`},onClose:()=>{p(null),ge()},onSave:()=>{p(null),ge()}}),P&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:i.jsx(Mt,{className:"w-full max-w-sm",children:i.jsxs(Dt,{className:"p-6",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[i.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:i.jsx(Jt,{className:"w-5 h-5 text-red-500"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:t("kProfiles.bulkDelete.title")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t("kProfiles.bulkDelete.cannotUndo")})]})]}),i.jsx("p",{className:"text-bambu-gray mb-6",children:t("kProfiles.bulkDelete.message",{count:k.size})}),i.jsxs("div",{className:"flex gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>D(!1),disabled:H,className:"flex-1",children:t("common.cancel")}),i.jsxs(Oe,{onClick:ue,disabled:H,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[H?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Jt,{className:"w-4 h-4"}),t("common.delete")]})]})]})})})]})}const Ioe=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","PVA","HIPS","PP","PET","NYLON"],qet={PLA:"E8E8E8",PETG:"4A90D9",ABS:"E67E22",ASA:"D35400",TPU:"9B59B6",PC:"BDC3C7",PA:"2ECC71",NYLON:"2ECC71",PVA:"F1C40F",HIPS:"95A5A6",PP:"ECF0F1",PET:"3498DB"};function Vet(t){const e=t.toUpperCase();for(const n of Ioe)if(new RegExp(`\\b${n}\\b`).test(e))return n;return null}function Get(t){const e=t.replace(/@.+$/,"").trim(),n=e.toUpperCase();for(const r of Ioe){const a=n.indexOf(r);if(a>0){const s=e.slice(0,a).trim();if(s&&s.length>1)return s}}return null}function BD({preset:t,onDelete:e,onExpand:n,isExpanded:r}){const{t:a}=Ft(),{hasPermission:s}=_r(),o=t.filament_type||Vet(t.name),l=t.filament_vendor||Get(t.name);let c=null,u=!1;if(t.default_filament_colour)try{const d=JSON.parse(t.default_filament_colour),m=Array.isArray(d)?d[0]:d;typeof m=="string"&&/^#?[0-9a-fA-F]{6,8}$/.test(m.replace("#",""))&&(c=m.replace("#","").slice(0,6),u=!0)}catch{const d=t.default_filament_colour;/^#?[0-9a-fA-F]{6,8}$/.test(d.replace("#",""))&&(c=d.replace("#","").slice(0,6),u=!0)}return!c&&o&&(c=qet[o.toUpperCase()]||null),i.jsx(Mt,{className:"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80 transition-colors",children:i.jsxs(Dt,{className:"p-3",children:[i.jsxs("div",{className:"flex items-start justify-between gap-2",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.preset_type==="filament"&&i.jsx("div",{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0 ${!u&&!c?"opacity-25":u?"":"opacity-50"}`,style:{backgroundColor:c?`#${c}`:"#666"}}),i.jsx("span",{className:"text-sm font-medium text-white truncate",children:t.name})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[o&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green",children:o}),l&&i.jsx("span",{className:"text-xs text-bambu-gray",children:l}),i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-400",children:a("profiles.localProfiles.badge")})]})]}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[s("settings:update")&&i.jsx("button",{onClick:()=>e(t.id),className:"p-1 text-bambu-gray hover:text-red-400 transition-colors",title:a("profiles.localProfiles.delete"),children:i.jsx(Jt,{className:"w-3.5 h-3.5"})}),i.jsx("button",{onClick:()=>n(r?null:t.id),className:"p-1 text-bambu-gray hover:text-white transition-colors",children:r?i.jsx(Il,{className:"w-3.5 h-3.5"}):i.jsx(Ln,{className:"w-3.5 h-3.5"})})]})]}),r&&i.jsxs("div",{className:"mt-3 pt-3 border-t border-bambu-dark-tertiary text-xs space-y-1.5",children:[o&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.filamentType")}),i.jsx("span",{className:"text-white",children:o})]}),l&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.vendor")}),i.jsx("span",{className:"text-white",children:l})]}),t.nozzle_temp_min!=null&&t.nozzle_temp_max!=null&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.nozzleTemp")}),i.jsxs("span",{className:"text-white",children:[t.nozzle_temp_min,"–",t.nozzle_temp_max,"°C"]})]}),t.filament_cost&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.cost")}),i.jsx("span",{className:"text-white",children:t.filament_cost})]}),t.filament_density&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.density")}),i.jsxs("span",{className:"text-white",children:[t.filament_density," g/cm³"]})]}),t.pressure_advance&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.pressureAdvance")}),i.jsx("span",{className:"text-white",children:t.pressure_advance})]}),t.compatible_printers&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.compatiblePrinters")}),i.jsx("span",{className:"text-white truncate ml-2",children:(()=>{try{return JSON.parse(t.compatible_printers).join(", ")}catch{return t.compatible_printers}})()})]}),t.inherits&&t.inherits!==t.name&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.inheritsFrom")}),i.jsx("span",{className:"text-white truncate ml-2",children:t.inherits})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.source")}),i.jsx("span",{className:"text-white capitalize",children:t.source})]})]})]})})}function Wet(){const{t}=Ft(),{hasPermission:e}=_r(),n=an(),{showToast:r}=fn(),[a,s]=w.useState(""),[o,l]=w.useState(null),[c,u]=w.useState(!1),[d,m]=w.useState(null),{data:p,isLoading:f}=et({queryKey:["localPresets"],queryFn:()=>be.getLocalPresets()}),y=pt({mutationFn:async k=>{const R=[];for(const P of Array.from(k)){const D=new FormData;D.append("file",P),R.push(await be.importLocalPresets(D))}return R},onSuccess:k=>{n.invalidateQueries({queryKey:["localPresets"]});let R=0,P=0,D=0;for(const H of k)R+=H.imported,P+=H.skipped,D+=H.errors.length;R>0&&r(t("profiles.localProfiles.toast.importSuccess",{count:R})),P>0&&r(t("profiles.localProfiles.toast.importSkipped",{count:P}),"warning"),D>0&&r(t("profiles.localProfiles.toast.importError",{count:D}),"error")},onError:k=>{r(k.message,"error")}}),v=pt({mutationFn:k=>be.deleteLocalPreset(k),onSuccess:()=>{n.invalidateQueries({queryKey:["localPresets"]}),m(null),r(t("profiles.localProfiles.toast.deleted"))}}),x=w.useCallback(k=>{!k||k.length===0||y.mutate(k)},[y]),g=w.useCallback(k=>{k.preventDefault(),u(!1),x(k.dataTransfer.files)},[x]),_=w.useCallback(k=>{if(!a)return k;const R=a.toLowerCase();return k.filter(P=>P.name.toLowerCase().includes(R)||P.filament_type?.toLowerCase().includes(R)||P.filament_vendor?.toLowerCase().includes(R))},[a]),N=w.useMemo(()=>_(p?.filament||[]),[p?.filament,_]),T=w.useMemo(()=>_(p?.printer||[]),[p?.printer,_]),C=w.useMemo(()=>_(p?.process||[]),[p?.process,_]),A=N.length+T.length+C.length;return f?i.jsx("div",{className:"flex items-center justify-center py-16",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):i.jsxs("div",{className:"space-y-6",children:[e("settings:update")&&i.jsxs("div",{onDragOver:k=>{k.preventDefault(),u(!0)},onDragLeave:()=>u(!1),onDrop:g,className:`relative border-2 border-dashed rounded-lg p-6 text-center transition-colors ${c?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[i.jsx("input",{type:"file",accept:".json,.zip,.orca_filament,.bbscfg,.bbsflmt",multiple:!0,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer",onChange:k=>x(k.target.files)}),y.isPending?i.jsxs("div",{className:"flex items-center justify-center gap-2",children:[i.jsx(ht,{className:"w-5 h-5 text-bambu-green animate-spin"}),i.jsx("span",{className:"text-bambu-gray",children:t("profiles.localProfiles.importing")})]}):i.jsxs(i.Fragment,{children:[i.jsx(xi,{className:"w-8 h-8 text-bambu-gray mx-auto mb-2"}),i.jsx("p",{className:"text-sm text-white font-medium",children:t("profiles.localProfiles.import")}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("profiles.localProfiles.importDesc")})]})]}),A>0&&i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:a,onChange:k=>s(k.target.value),placeholder:t("profiles.localProfiles.search"),className:"w-full pl-9 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green"})]}),A===0&&!f&&i.jsxs("div",{className:"text-center py-12",children:[i.jsx(Lx,{className:"w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50"}),i.jsx("p",{className:"text-bambu-gray",children:t("profiles.localProfiles.noPresets")}),i.jsx("p",{className:"text-xs text-bambu-gray/60 mt-1",children:t("profiles.localProfiles.importDesc")})]}),A>0&&i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[N.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(YC,{className:"w-4 h-4 text-bambu-green"}),i.jsx("h3",{className:"text-sm font-medium text-white",children:t("profiles.localProfiles.filament")}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",N.length,")"]})]}),i.jsx("div",{className:"space-y-2",children:N.map(k=>i.jsx(BD,{preset:k,onDelete:R=>m(R),onExpand:l,isExpanded:o===k.id},k.id))})]}),C.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(Gi,{className:"w-4 h-4 text-blue-400"}),i.jsx("h3",{className:"text-sm font-medium text-white",children:t("profiles.localProfiles.process")}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",C.length,")"]})]}),i.jsx("div",{className:"space-y-2",children:C.map(k=>i.jsx(BD,{preset:k,onDelete:R=>m(R),onExpand:l,isExpanded:o===k.id},k.id))})]}),T.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(jd,{className:"w-4 h-4 text-orange-400"}),i.jsx("h3",{className:"text-sm font-medium text-white",children:t("profiles.localProfiles.printer")}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",T.length,")"]})]}),i.jsx("div",{className:"space-y-2",children:T.map(k=>i.jsx(BD,{preset:k,onDelete:R=>m(R),onExpand:l,isExpanded:o===k.id},k.id))})]})]}),d!==null&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:i.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-6 max-w-sm mx-4",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(Li,{className:"w-5 h-5 text-red-400"}),i.jsx("h3",{className:"text-white font-medium",children:t("profiles.localProfiles.deleteConfirmTitle")})]}),i.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:t("profiles.localProfiles.deleteConfirm")}),i.jsxs("div",{className:"flex justify-end gap-2",children:[i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>m(null),children:t("profiles.localProfiles.cancel")}),i.jsxs(Oe,{variant:"danger",size:"sm",onClick:()=>v.mutate(d),disabled:v.isPending,children:[v.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Jt,{className:"w-4 h-4"}),t("profiles.localProfiles.delete")]})]})]})})]})}function N5(t,e){const n=`${t} ${e||""}`,r=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),a=r?r[1].trim():null,s=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=s?(s[1]||s[2])+"mm":null,l=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),c=l?l[1]+"mm":null,u=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i),d=u?u[1].toUpperCase():null;return{printer:a,nozzle:o,layerHeight:c,filamentType:d}}function ow(t){return/^(P[FPM]US|PF\d|PP\d)/.test(t)}function Ket({onSuccess:t,t:e}){const{showToast:n}=fn(),[r,a]=w.useState("email"),[s,o]=w.useState(""),[l,c]=w.useState(""),[u,d]=w.useState(""),[m,p]=w.useState(""),[f,y]=w.useState("global"),[v,x]=w.useState(null),[g,_]=w.useState(null),N=pt({mutationFn:()=>be.cloudLogin(s,l,f),onSuccess:R=>{R.success?(n(e("profiles.login.toast.loggedIn")),t()):R.needs_verification?(x(R.verification_type||"email"),_(R.tfa_key||null),R.verification_type==="totp"?n(e("profiles.login.toast.enterTotp")):n(e("profiles.login.toast.codeSent")),a("code")):n(R.message,"error")},onError:R=>n(R.message,"error")}),T=pt({mutationFn:()=>be.cloudVerify(s,u,g||void 0),onSuccess:R=>{R.success?(n(e("profiles.login.toast.loggedIn")),t()):n(R.message,"error")},onError:R=>n(R.message,"error")}),C=pt({mutationFn:()=>be.cloudSetToken(m),onSuccess:()=>{n(e("profiles.login.toast.tokenSet")),t()},onError:R=>n(R.message,"error")}),A=R=>{R.preventDefault(),r==="email"?N.mutate():r==="code"?T.mutate():r==="token"&&C.mutate()},k=N.isPending||T.isPending||C.isPending;return i.jsx(Mt,{className:"max-w-md mx-auto",children:i.jsxs(Dt,{children:[i.jsxs("div",{className:"text-center mb-6",children:[i.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3",children:i.jsx(Fx,{className:"w-6 h-6 text-bambu-green"})}),i.jsx("h2",{className:"text-xl font-semibold text-white",children:e("profiles.login.title")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:e("profiles.login.subtitle")})]}),i.jsxs("form",{onSubmit:A,className:"space-y-4",children:[r==="email"&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.email")}),i.jsx("input",{type:"email",value:s,onChange:R=>o(R.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",placeholder:"your@email.com",required:!0})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.password")}),i.jsx("input",{type:"password",value:l,onChange:R=>c(R.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",placeholder:"••••••••",required:!0})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.region")}),i.jsxs("select",{value:f,onChange:R=>y(R.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:[i.jsx("option",{value:"global",children:e("profiles.login.regionGlobal")}),i.jsx("option",{value:"china",children:e("profiles.login.regionChina")})]})]})]}),r==="code"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e(v==="totp"?"profiles.login.totpCode":"profiles.login.verificationCode")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:v==="totp"?e("profiles.login.enterTotpHint"):e("profiles.login.checkEmail",{email:s})}),i.jsx("input",{type:"text",value:u,onChange:R=>d(R.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none",placeholder:"000000",maxLength:6,required:!0})]}),r==="token"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.accessToken")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:e("profiles.login.accessTokenHint")}),i.jsx("textarea",{value:m,onChange:R=>p(R.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none resize-none",placeholder:"eyJ...",rows:4,required:!0})]}),i.jsxs("div",{className:"flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center",children:[r==="code"&&i.jsx(Oe,{type:"button",variant:"secondary",onClick:()=>a("email"),className:"flex-1",children:e("profiles.login.back")}),i.jsxs(Oe,{type:"submit",disabled:k,className:"flex-1",children:[k?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(V8,{className:"w-4 h-4"}),e(r==="email"?"profiles.login.loginButton":r==="code"?"profiles.login.verifyButton":"profiles.login.setTokenButton")]})]}),r==="email"&&i.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:i.jsxs("button",{type:"button",onClick:()=>a("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[i.jsx(Sl,{className:"w-4 h-4"}),e("profiles.login.useToken")]})}),r==="token"&&i.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:i.jsxs("button",{type:"button",onClick:()=>a("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[i.jsx(V8,{className:"w-4 h-4"}),e("profiles.login.useEmail")]})})]})]})})}function wb({label:t,value:e,options:n,onChange:r}){const[a,s]=w.useState(!1),o=n.find(l=>l.value===e);return i.jsxs("div",{className:"relative",children:[i.jsxs("button",{onClick:()=>s(!a),className:"flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors",children:[i.jsxs("span",{className:"text-bambu-gray",children:[t,":"]}),i.jsx("span",{children:o?.label||"All"}),i.jsx(Ln,{className:`w-4 h-4 text-bambu-gray transition-transform ${a?"rotate-180":""}`})]}),a&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>s(!1)}),i.jsx("div",{className:"absolute top-full left-0 mt-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 py-1 max-h-60 overflow-y-auto",children:n.map(l=>i.jsxs("button",{onClick:()=>{r(l.value),s(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${e===l.value?"text-bambu-green":"text-white"}`,children:[i.jsx("span",{children:l.label}),l.count!==void 0&&i.jsx("span",{className:"text-bambu-gray text-xs",children:l.count})]},l.value))})]})]})}function Yet(){const[t,e]=w.useState(!1);w.useEffect(()=>{const r=()=>{e(window.scrollY>300)};return window.addEventListener("scroll",r),()=>window.removeEventListener("scroll",r)},[]);const n=()=>{window.scrollTo({top:0,behavior:"smooth"})};return t?i.jsx("button",{onClick:n,className:"fixed bottom-6 right-6 p-3 bg-bambu-green hover:bg-bambu-green-light text-white rounded-full shadow-lg shadow-bambu-green/25 transition-all z-40","aria-label":"Scroll to top",children:i.jsx(yf,{className:"w-5 h-5"})}):null}function HD({setting:t,onClick:e,onDuplicate:n,compareMode:r,isCompareSelected:a,compareIndex:s,compareDisabled:o,t:l}){const c=N5(t.name),u=ow(t.setting_id);return i.jsxs("div",{className:"flex items-center gap-2 group",children:[i.jsx("button",{onClick:e,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${a?"bg-blue-500/20 border border-blue-500/50":o?"bg-bambu-dark/50 opacity-40 cursor-not-allowed":"bg-bambu-dark hover:bg-bambu-dark-tertiary"} ${r&&!o?"cursor-pointer":""}`,children:i.jsxs("div",{className:"flex items-center gap-2",children:[a&&s!==void 0&&i.jsx("span",{className:"flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium",children:s+1}),!a&&u&&i.jsx("span",{className:"flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green",title:l("profiles.presets.myPreset")}),i.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name}),c.filamentType&&t.type==="filament"&&i.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.filamentType}),c.layerHeight&&t.type==="process"&&i.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.layerHeight}),c.printer&&i.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.printer})]})}),i.jsx("button",{onClick:d=>{d.stopPropagation(),n()},className:"opacity-0 group-hover:opacity-100 text-bambu-gray hover:text-white transition-all p-1",title:l("profiles.presets.duplicate"),children:i.jsx(fo,{className:"w-4 h-4"})})]})}function xL(t,e=0){const n=" ".repeat(e);if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string"){if(t.includes("\\n")||t.includes(` `)){const a=t.replace(/\\n/g,` `).replace(/\\"/g,'"').replace(/\\t/g," ").split(` `);if(a.length>1)return`""" @@ -8712,7 +8712,7 @@ Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${Rs(t. `+n+"]";if(typeof t=="object"){const r=Object.entries(t);return r.length===0?"{}":`{ `+r.map(([s,o])=>n+" "+JSON.stringify(s)+": "+xL(o,e+1)).join(`, `)+` -`+n+"}"}return String(t)}function Xet({setting:t,onClose:e,onDeleted:n,onDuplicate:r,onEdit:a,hasPermission:s,t:o}){const{showToast:l}=fn(),c=an(),[u,d]=w.useState(!1),{data:m,isLoading:p}=et({queryKey:["cloudSettingDetail",t.setting_id],queryFn:()=>be.getCloudSettingDetail(t.setting_id)}),f=pt({mutationFn:()=>be.deleteCloudSetting(t.setting_id),onSuccess:()=>{l(o("profiles.presets.toast.deleted")),c.invalidateQueries({queryKey:["cloudSettings"]}),n()},onError:x=>l(x.message,"error")}),y=ow(t.setting_id),v=N5(t.name,m?.setting?.inherits);return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:i.jsx(Mt,{className:"w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden",children:i.jsxs(Dt,{className:"p-0 flex flex-col min-h-0 flex-1",children:[i.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("h2",{className:"text-xl font-semibold text-white truncate",children:t.name}),y&&i.jsx("span",{className:"px-2 py-0.5 text-xs font-medium bg-bambu-green/20 text-bambu-green rounded-full",children:o("profiles.presets.editable")})]}),i.jsxs("div",{className:"flex items-center gap-2 mt-1 text-sm text-bambu-gray",children:[i.jsx("span",{className:"capitalize",children:o(`profiles.presets.types.${t.type}`)}),v.printer&&i.jsxs(i.Fragment,{children:[i.jsx("span",{children:"•"}),i.jsx("span",{children:v.printer})]})]})]}),i.jsx("button",{onClick:e,className:"p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto p-4",children:p?i.jsx("div",{className:"flex items-center justify-center py-16",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):m?i.jsx("pre",{className:"text-xs text-bambu-gray font-mono whitespace-pre-wrap break-all bg-bambu-dark p-4 rounded-lg border border-bambu-dark-tertiary overflow-x-auto max-w-full",children:xL(m)}):i.jsx("div",{className:"text-center py-16 text-bambu-gray",children:o("profiles.presets.failedToLoadDetails")})}),u?i.jsxs("div",{className:"flex-shrink-0 p-4 border-t border-bambu-dark-tertiary bg-red-500/5",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3 text-red-400",children:[i.jsx(Mn,{className:"w-5 h-5"}),i.jsx("span",{className:"font-medium",children:o("profiles.presets.deleteConfirm")})]}),i.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:o("profiles.presets.deleteWarning",{name:t.name})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>d(!1),disabled:f.isPending,className:"flex-1",children:o("common.cancel")}),i.jsxs(Oe,{variant:"danger",onClick:()=>f.mutate(),disabled:f.isPending,className:"flex-1",children:[f.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Jt,{className:"w-4 h-4"}),o("common.delete")]})]})]}):i.jsx("div",{className:"flex-shrink-0 p-4 border-t border-bambu-dark-tertiary",children:i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Oe,{variant:"secondary",onClick:e,className:"flex-1",children:o("common.close")}),i.jsxs(Oe,{variant:"secondary",onClick:r,disabled:!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.presets.noDuplicatePermission"),children:[i.jsx(fo,{className:"w-4 h-4"}),o("profiles.presets.duplicate")]}),y&&i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"secondary",onClick:a,disabled:p||!m||!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.presets.noEditPermission"),children:[i.jsx(Yi,{className:"w-4 h-4"}),o("common.edit")]}),i.jsx(Oe,{variant:"danger",onClick:()=>d(!0),disabled:!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.presets.noDeletePermission"),children:i.jsx(Jt,{className:"w-4 h-4"})})]})]})})]})})})}function zoe(){try{const t=localStorage.getItem("bambusy_preset_templates");return t?JSON.parse(t):[]}catch{return[]}}function Uoe(t){localStorage.setItem("bambusy_preset_templates",JSON.stringify(t))}function Qet({onClose:t,onApply:e,t:n}){const{showToast:r}=fn(),[a,s]=w.useState(zoe),[o,l]=w.useState("all"),[c,u]=w.useState(null),[d,m]=w.useState(""),[p,f]=w.useState(""),[y,v]=w.useState("{}"),[x,g]=w.useState(null),[_,N]=w.useState(null),T=o==="all"?a:a.filter(G=>G.type===o),C=G=>{s(G),Uoe(G)},A=G=>{const I=a.filter(ee=>ee.id!==G);C(I),N(null),r(n("profiles.templates.toast.deleted"))},k=G=>{u(G.id),m(G.name),f(G.description),v(JSON.stringify(G.settings,null,2)),g(null)},R=()=>{if(!(!c||!d.trim()))try{const G=JSON.parse(y),I=a.map(ee=>ee.id===c?{...ee,name:d.trim(),description:p.trim(),settings:G}:ee);C(I),u(null),r(n("profiles.templates.toast.updated"))}catch(G){g(G.message)}},P=()=>{u(null),m(""),f(""),v("{}"),g(null)},D=G=>{const I=a.map(ee=>ee.id===G?{...ee,showInModal:!ee.showInModal}:ee);C(I)},H={filament:{label:n("profiles.presets.types.filament"),icon:YC,color:"text-amber-400"},print:{label:n("profiles.presets.types.process"),icon:jd,color:"text-blue-400"},printer:{label:n("profiles.presets.types.printer"),icon:Sr,color:"text-purple-400"}},z=_?a.find(G=>G.id===_):null;return w.useEffect(()=>{const G=I=>{I.key==="Escape"&&(_?N(null):c?P():t())};return window.addEventListener("keydown",G),()=>window.removeEventListener("keydown",G)},[_,c,t]),i.jsxs("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:[z&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-60",children:i.jsx(Mt,{className:"w-full max-w-md",children:i.jsxs(Dt,{className:"p-6",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[i.jsx("div",{className:"p-2 bg-red-500/20 rounded-lg",children:i.jsx(Mn,{className:"w-6 h-6 text-red-400"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:n("profiles.templates.deleteTitle")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:n("profiles.templates.deleteWarning")})]})]}),i.jsx("p",{className:"text-white mb-6",children:n("profiles.templates.deleteConfirm",{name:z.name})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>N(null),className:"flex-1",children:n("common.cancel")}),i.jsxs(Oe,{onClick:()=>A(_),className:"flex-1 bg-red-500 hover:bg-red-600",children:[i.jsx(Jt,{className:"w-4 h-4"}),n("common.delete")]})]})]})})}),i.jsx(Mt,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",children:i.jsxs(Dt,{className:"p-0 flex flex-col h-full",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(ax,{className:"w-5 h-5 text-amber-400"}),n("profiles.templates.title")]}),i.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"flex items-center gap-2 p-4 border-b border-bambu-dark-tertiary",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:n("profiles.templates.typeFilter")}),["all","filament","print","printer"].map(G=>i.jsx("button",{onClick:()=>l(G),className:`px-3 py-1 text-sm rounded-lg transition-colors ${o===G?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:G==="all"?n("common.all"):H[G].label},G))]}),i.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:T.length===0?i.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[i.jsx(ax,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),i.jsx("p",{children:n("profiles.templates.noTemplates")}),i.jsx("p",{className:"text-sm mt-1",children:n("profiles.templates.createFirst")})]}):i.jsx("div",{className:"space-y-2",children:T.map(G=>{const I=H[G.type],ee=I.icon;return c===G.id?i.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg border border-bambu-green",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-3 mb-3",children:[i.jsx("input",{type:"text",value:d,onChange:ie=>m(ie.target.value),placeholder:n("profiles.templates.namePlaceholder"),className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",autoFocus:!0}),i.jsx("input",{type:"text",value:p,onChange:ie=>f(ie.target.value),placeholder:n("profiles.templates.descriptionPlaceholder"),className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{className:"mb-3",children:[i.jsx("label",{className:"text-xs text-bambu-gray mb-1 block",children:n("profiles.templates.settingsJson")}),i.jsx("textarea",{value:y,onChange:ie=>{v(ie.target.value),g(null)},rows:6,className:`w-full px-3 py-2 bg-bambu-dark-secondary border rounded text-white text-sm font-mono focus:outline-none ${x?"border-red-500":"border-bambu-dark-tertiary focus:border-bambu-green"}`}),x&&i.jsx("p",{className:"text-xs text-red-400 mt-1",children:x})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Oe,{size:"sm",onClick:R,disabled:!d.trim(),children:[i.jsx(ts,{className:"w-4 h-4"}),"Save"]}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:P,children:"Cancel"})]})]},G.id):i.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary hover:border-bambu-gray-dark transition-colors",children:[i.jsx(ee,{className:`w-5 h-5 ${I.color} flex-shrink-0`}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-sm font-medium text-white",children:G.name}),i.jsx("p",{className:"text-xs text-bambu-gray truncate",children:G.description})]}),i.jsx("span",{className:"text-xs text-bambu-gray-dark px-2 py-1 bg-bambu-dark-secondary rounded",children:n("profiles.templates.fieldsCount",{count:Object.keys(G.settings).length})}),i.jsx("button",{onClick:()=>D(G.id),className:`p-1 transition-colors ${G.showInModal?"text-bambu-green hover:text-bambu-green/70":"text-bambu-gray hover:text-white"}`,title:G.showInModal?n("profiles.templates.shownInModals"):n("profiles.templates.hiddenInModals"),children:G.showInModal?i.jsx(_c,{className:"w-4 h-4"}):i.jsx(mw,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>e(G),className:"px-3 py-1 text-xs bg-bambu-green/20 text-bambu-green rounded hover:bg-bambu-green/30 transition-colors",children:n("profiles.templates.apply")}),i.jsx("button",{onClick:()=>k(G),className:"p-1 text-bambu-gray hover:text-white",title:n("common.edit"),children:i.jsx(Yi,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>N(G.id),className:"p-1 text-bambu-gray hover:text-red-400",title:n("common.delete"),children:i.jsx(Jt,{className:"w-4 h-4"})})]},G.id)})})})]})})]})}function Boe({onClose:t,leftPreset:e,rightPreset:n,leftLabel:r,rightLabel:a,t:s}){const[o,l]=w.useState("changes"),[c,u]=w.useState(""),d=w.useMemo(()=>{const y=new Set([...Object.keys(e),...Object.keys(n)]),v=[];for(const x of y){if(x==="inherits"||x==="version")continue;const g=e[x],_=n[x],N=x in e,T=x in n;let C;!N&&T?C="added":N&&!T?C="removed":JSON.stringify(g)!==JSON.stringify(_)?C="changed":C="same",v.push({key:x,left:g,right:_,status:C})}return v.sort((x,g)=>{const _={changed:0,added:1,removed:2,same:3};return _[x.status]!==_[g.status]?_[x.status]-_[g.status]:x.key.localeCompare(g.key)})},[e,n]),m=w.useMemo(()=>{let y=[...d];if(o==="changes"&&(y=y.filter(v=>v.status!=="same")),c){const v=c.toLowerCase();y=y.filter(x=>x.key.toLowerCase().includes(v)||String(x.left).toLowerCase().includes(v)||String(x.right).toLowerCase().includes(v))}return y},[d,o,c]),p=w.useMemo(()=>({added:d.filter(y=>y.status==="added").length,removed:d.filter(y=>y.status==="removed").length,changed:d.filter(y=>y.status==="changed").length,same:d.filter(y=>y.status==="same").length}),[d]),f=y=>{if(y===void 0)return"—";if(y===null)return"null";if(Array.isArray(y))return y.length===0?"[]":y.length===1?String(y[0]):y.join(", ");if(typeof y=="object")return JSON.stringify(y);const v=String(y);if(v.includes("\\n")||v.length>100){const x=v.split("\\n").length;if(x>1)return`[${x} lines of G-code/script]`;if(v.length>100)return v.substring(0,100)+"…"}return v};return w.useEffect(()=>{const y=v=>{v.key==="Escape"&&t()};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[t]),i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsx(Mt,{className:"w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden",children:i.jsxs(Dt,{className:"p-0 flex flex-col min-h-0 flex-1",children:[i.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(zb,{className:"w-5 h-5 text-blue-400"}),s("profiles.diff.title")]}),i.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"flex-shrink-0 grid grid-cols-2 gap-4 p-4 border-b border-bambu-dark-tertiary bg-bambu-dark",children:[i.jsxs("div",{className:"text-center",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:s("profiles.diff.left")}),i.jsx("p",{className:"text-white font-medium truncate",children:r})]}),i.jsxs("div",{className:"text-center",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:s("profiles.diff.right")}),i.jsx("p",{className:"text-white font-medium truncate",children:a})]})]}),i.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[i.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[i.jsx(ar,{className:"w-3.5 h-3.5"}),p.added," ",s("profiles.diff.added")]}),i.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[i.jsx(jN,{className:"w-3.5 h-3.5"}),p.removed," ",s("profiles.diff.removed")]}),i.jsxs("span",{className:"flex items-center gap-1 text-amber-400",children:[i.jsx(p3,{className:"w-3.5 h-3.5"}),p.changed," ",s("profiles.diff.changed")]}),i.jsxs("span",{className:"flex items-center gap-1 text-bambu-gray",children:[i.jsx(BM,{className:"w-3.5 h-3.5"}),p.same," ",s("profiles.diff.same")]})]}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:c,onChange:y=>u(y.target.value),placeholder:s("profiles.diff.searchFields"),className:"pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none w-48"})]}),p.same>0&&i.jsxs("div",{className:"flex rounded overflow-hidden border border-bambu-dark-tertiary",children:[i.jsx("button",{onClick:()=>l("changes"),className:`px-3 py-1.5 text-sm transition-colors ${o==="changes"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:s("profiles.diff.changes")}),i.jsx("button",{onClick:()=>l("all"),className:`px-3 py-1.5 text-sm transition-colors ${o==="all"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:s("common.all")})]})]})]}),i.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:m.length===0?i.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[i.jsx(BM,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),i.jsx("p",{children:s(o==="changes"?"profiles.diff.noDifferences":"profiles.diff.noFieldsMatch")})]}):i.jsxs("table",{className:"w-full",children:[i.jsx("thead",{className:"sticky top-0 bg-bambu-dark-secondary",children:i.jsxs("tr",{className:"text-sm text-bambu-gray border-b border-bambu-dark-tertiary",children:[i.jsx("th",{className:"text-left p-3 w-1/3",children:s("profiles.diff.field")}),i.jsx("th",{className:"text-left p-3 w-1/3",children:r}),i.jsx("th",{className:"text-left p-3 w-1/3",children:a})]})}),i.jsx("tbody",{children:m.map(y=>{const v={added:"bg-green-500/10",removed:"bg-red-500/10",changed:"bg-amber-500/10",same:""}[y.status],x={added:i.jsx(ar,{className:"w-3.5 h-3.5 text-green-400"}),removed:i.jsx(jN,{className:"w-3.5 h-3.5 text-red-400"}),changed:i.jsx(p3,{className:"w-3.5 h-3.5 text-amber-400"}),same:i.jsx(BM,{className:"w-3.5 h-3.5 text-bambu-gray-dark"})}[y.status];return i.jsxs("tr",{className:`border-b border-bambu-dark-tertiary ${v}`,children:[i.jsx("td",{className:"p-3",children:i.jsxs("div",{className:"flex items-center gap-2",children:[x,i.jsx("span",{className:"text-sm text-white font-mono",children:y.key})]})}),i.jsx("td",{className:"p-3",children:i.jsx("span",{className:`text-sm font-mono break-all ${y.status==="removed"?"text-red-300":y.status==="changed"?"text-white":"text-bambu-gray"}`,children:f(y.left)})}),i.jsx("td",{className:"p-3",children:i.jsx("span",{className:`text-sm font-mono break-all ${y.status==="added"?"text-green-300":y.status==="changed"?"text-white":"text-bambu-gray"}`,children:f(y.right)})})]},y.key)})})]})})]})})})}function Zet({onClose:t,initialData:e,allPresets:n,t:r}){const{showToast:a}=fn(),s=an(),o=!!e?.setting_id,[l,c]=w.useState("common"),[u,d]=w.useState(e?.type||"filament"),[m,p]=w.useState(e?.name?o?e.name:`${e.name} (Copy)`:""),[f,y]=w.useState(e?.base_id||""),[v,x]=w.useState(""),[g,_]=w.useState(e?.setting||{inherits:""}),[N,T]=w.useState(JSON.stringify(e?.setting||{inherits:""},null,2)),[C,A]=w.useState(null),[k,R]=w.useState(""),[P,D]=w.useState(!1),[H,z]=w.useState(""),[G,I]=w.useState(!1),[ee,ie]=w.useState(zoe),[X,me]=w.useState(!1),[he,ge]=w.useState(""),[Y,oe]=w.useState(""),[le,xe]=w.useState(!0),[Pe,q]=w.useState(null),[Z,j]=w.useState(!1),E=w.useMemo(()=>({filament:n.filament,print:n.process,printer:n.printer})[u]||[],[n,u]),U=w.useMemo(()=>E.filter(Ae=>ow(Ae.setting_id)),[E]),{data:K}=et({queryKey:["cloudFields",u],queryFn:()=>be.getCloudFields(u==="print"?"process":u),staleTime:1e3*60*60}),{data:$}=et({queryKey:["allPresetDetails",u,U.map(Ae=>Ae.setting_id).join(",")],queryFn:async()=>{const Ae={};for(let je=0;je{try{const Ce=await be.getCloudSettingDetail(Ie.setting_id);return{id:Ie.setting_id,detail:Ce}}catch{return null}}))).forEach(Ie=>{Ie&&(Ae[Ie.id]=Ie.detail)})}return Ae},enabled:U.length>0,staleTime:1e3*60*10}),{data:ne,isLoading:O}=et({queryKey:["cloudSettingDetail",f],queryFn:()=>be.getCloudSettingDetail(f),enabled:!!f});w.useEffect(()=>{l!=="json"&&T(JSON.stringify(g,null,2))},[g,l]);const V=w.useMemo(()=>({filament:n.filament,print:n.process,printer:n.printer}[u]||[]).filter(Be=>!ow(Be.setting_id)).sort((Be,je)=>Be.name.localeCompare(je.name)),[n,u]);w.useEffect(()=>{if(!f)return;const Ae=V.find(Be=>Be.setting_id===f);Ae&&(x(Ae.name),o||(_({inherits:Ae.name}),T(JSON.stringify({inherits:Ae.name},null,2))))},[f,V,o]);const J=w.useMemo(()=>{const Ae=K?.fields||[],Be=new Set(Ae.map(Ie=>Ie.key)),je=new Set,Xe=new Set(["inherits","updated_time","compatible_printers","compatible_prints"]);$&&Object.values($).forEach(Ie=>{Ie?.setting&&Object.keys(Ie.setting).forEach(Ce=>{!Be.has(Ce)&&!Xe.has(Ce)&&je.add(Ce)})}),Object.keys(g).forEach(Ie=>{!Be.has(Ie)&&!Xe.has(Ie)&&je.add(Ie)});const ce=Array.from(je).sort().map(Ie=>({key:Ie,label:Ie.replace(/_/g," ").replace(/\b\w/g,Ce=>Ce.toUpperCase()),type:"text",category:"discovered",description:r("profiles.presets.discoveredFromPresets")}));return[...Ae,...ce]},[K,$,g,r]),W=J.filter(Ae=>Ae.label.toLowerCase().includes(k.toLowerCase())||Ae.key.toLowerCase().includes(k.toLowerCase())),re=()=>{if(H.trim()){const Ae=H.trim().toLowerCase().replace(/\s+/g,"_");ue(Ae,""),z(""),I(!1),a(r("profiles.presets.toast.fieldAdded",{key:Ae}))}},ue=(Ae,Be)=>{_(je=>{const Xe={...je};return Be===""||Be===void 0?delete Xe[Ae]:Xe[Ae]=Be,Xe})},fe=Ae=>{_(Be=>({...Be,...Ae.settings})),q(Ae.name),a(r("profiles.templates.toast.applied"))},ye=()=>{if(!he.trim())return;const Ae={...g};if(delete Ae.inherits,Object.keys(Ae).length===0){a(r("profiles.presets.noOverridesToSave"),"error");return}const Be={id:Date.now().toString(),name:he.trim(),description:Y.trim()||r("profiles.presets.customTemplate"),type:u,settings:Ae,showInModal:le},je=[...ee,Be];ie(je),Uoe(je),me(!1),ge(""),oe(""),xe(!0),a(r("profiles.templates.toast.created"))},ae=w.useMemo(()=>ee.filter(Ae=>Ae.type===u&&Ae.showInModal),[u,ee]),L=Ae=>{T(Ae);try{const Be=JSON.parse(Ae);_(Be),A(null)}catch(Be){A(Be.message)}},F=Ae=>{Ae.preventDefault(),D(!1);const Be=Ae.dataTransfer.files[0];if(Be&&Be.name.endsWith(".json")){const je=new FileReader;je.onload=Xe=>{try{const ce=Xe.target?.result,Ie=JSON.parse(ce),Ce=Ie.setting||Ie;_(Ge=>({...Ge,...Ce})),T(JSON.stringify({...g,...Ce},null,2)),a(r("profiles.presets.fileImported"))}catch{a(r("profiles.presets.invalidJsonFile"),"error")}},je.readAsText(Be)}},te=pt({mutationFn:()=>{const Ae={...g},Be=u==="filament"?"filament_settings_id":u==="print"?"print_settings_id":"printer_settings_id";Ae[Be]=`"${m}"`;const je={type:u,name:m,base_id:f,setting:Ae};return be.createCloudSetting(je)},onSuccess:async()=>{a(r("profiles.presets.toast.created")),await s.refetchQueries({queryKey:["cloudSettings"]}),t()},onError:Ae=>a(Ae.message,"error")}),ve=pt({mutationFn:()=>{if(!e?.setting_id)throw new Error(r("profiles.presets.noSettingId"));return be.updateCloudSetting(e.setting_id,{name:m,setting:g})},onSuccess:async()=>{a(r("profiles.presets.toast.updated")),s.removeQueries({queryKey:["cloudSettingDetail"]}),await s.refetchQueries({queryKey:["cloudSettings"]}),t()},onError:Ae=>a(Ae.message,"error")}),pe=o?ve:te,de=ne?.setting?.inherits,Ne=de?V.find(Ae=>Ae.name===de):void 0,{data:Se}=et({queryKey:["cloudSettingDetail",Ne?.setting_id],queryFn:()=>be.getCloudSettingDetail(Ne.setting_id),enabled:!!Ne?.setting_id}),Le=w.useMemo(()=>{const Ae=Se?.setting||{},Be=ne?.setting||{},je=f&&$?.[f]?.setting?$[f].setting:{};return{...Ae,...Be,...je}},[f,ne,Se,$]),qe=Ae=>{if(Ae==null)return"";if(Array.isArray(Ae)){const Be=[...new Set(Ae.map(je=>String(je)))];return Be.length===1?Be[0]:Ae.join(", ")}return String(Ae)},Ee=Ae=>{const Be=g[Ae.key],je=Le[Ae.key],Xe=qe(je),ce=O?r("common.loading"):Xe||"",Ie="w-full px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none";if(Ae.type==="boolean"){const Ce=Be==="1"||Be===void 0&&je==="1";return i.jsx("button",{type:"button",onClick:()=>ue(Ae.key,Be==="1"?"0":"1"),className:`w-8 h-5 rounded-full transition-colors ${Ce?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:i.jsx("div",{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${Ce?"translate-x-3.5":"translate-x-0.5"}`})})}return Ae.type==="select"?i.jsxs("select",{value:Be||"",onChange:Ce=>ue(Ae.key,Ce.target.value),className:Ie,children:[i.jsx("option",{value:"",children:ce}),Ae.options?.map(Ce=>i.jsx("option",{value:Ce.value,children:Ce.label},Ce.value))]}):i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:Ae.type==="number"?"number":"text",value:Be!==void 0?String(Be):"",onChange:Ce=>ue(Ae.key,Ce.target.value),step:Ae.step,min:Ae.min,max:Ae.max,placeholder:ce,className:Ie}),Ae.unit&&i.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:Ae.unit})]})},Te=w.useMemo(()=>ne?.setting?ne.setting:{},[ne]);return i.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onDragOver:Ae=>{Ae.preventDefault(),D(!0)},onDragLeave:()=>D(!1),onDrop:F,children:[Z&&f&&i.jsx(Boe,{onClose:()=>j(!1),leftPreset:Te,rightPreset:g,leftLabel:r("profiles.presets.baseLabel",{name:v||f}),rightLabel:r("profiles.presets.currentLabel",{name:m||r("profiles.presets.newPreset")}),t:r}),i.jsx(Mt,{className:"w-full max-w-6xl max-h-[90vh] flex flex-col overflow-y-auto",children:i.jsxs(Dt,{className:"p-0 flex flex-col h-full",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("h2",{className:"text-xl font-semibold text-white",children:r(o?"profiles.presets.editPreset":e?"profiles.presets.duplicatePreset":"profiles.presets.createNewPreset")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:r("profiles.presets.customizeSettings")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[f&&i.jsxs("button",{onClick:()=>j(!0),className:"flex items-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",title:r("profiles.presets.compareWithBase"),children:[i.jsx(zb,{className:"w-4 h-4"}),r("profiles.presets.compare")]}),i.jsx("button",{onClick:t,className:"p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]})]}),P&&i.jsx("div",{className:"absolute inset-0 bg-bambu-green/10 border-2 border-dashed border-bambu-green rounded-lg flex items-center justify-center z-10",children:i.jsxs("div",{className:"text-center",children:[i.jsx(xi,{className:"w-12 h-12 text-bambu-green mx-auto mb-2"}),i.jsx("p",{className:"text-bambu-green font-medium",children:r("profiles.presets.dropJsonToImport")})]})}),i.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary space-y-3",children:[i.jsxs("div",{className:"grid grid-cols-3 gap-4 max-[640px]:grid-cols-1",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("common.type")}),i.jsxs("select",{value:u,onChange:Ae=>{d(Ae.target.value),y("")},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:[i.jsx("option",{value:"filament",children:r("profiles.presets.types.filament")}),i.jsx("option",{value:"print",children:r("profiles.presets.types.process")}),i.jsx("option",{value:"printer",children:r("profiles.presets.types.printer")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("profiles.presets.basePreset")}),i.jsxs("select",{value:f,onChange:Ae=>y(Ae.target.value),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",children:[i.jsx("option",{value:"",children:r("profiles.presets.selectBasePreset")}),V.map(Ae=>i.jsx("option",{value:Ae.setting_id,children:Ae.name},Ae.setting_id))]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("profiles.presets.presetName")}),i.jsx("input",{type:"text",value:m,onChange:Ae=>p(Ae.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",placeholder:r("profiles.presets.myCustomPreset")})]})]}),v&&i.jsx("div",{className:"text-xs text-bambu-gray",children:i.jsxs("p",{className:"flex items-center gap-1",children:[i.jsx(Yr,{className:"w-3 h-3 text-bambu-green"}),r("profiles.presets.inheritsFrom")," ",i.jsx("span",{className:"text-white",children:v}),O&&i.jsx(ht,{className:"w-3 h-3 animate-spin ml-1"})]})})]}),i.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary max-[640px]:flex-wrap max-[640px]:items-center",children:[i.jsxs("button",{onClick:()=>c("common"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l==="common"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(G8,{className:"w-4 h-4"}),r("profiles.presets.tabs.common")]}),i.jsxs("button",{onClick:()=>c("fields"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l==="fields"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(JC,{className:"w-4 h-4"}),r("profiles.presets.tabs.allFields")]}),i.jsxs("button",{onClick:()=>c("json"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l==="json"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(HX,{className:"w-4 h-4"}),"JSON",C&&i.jsx(Li,{className:"w-3 h-3 text-red-400"})]}),i.jsx("div",{className:"flex-1 max-[640px]:hidden"}),i.jsxs("button",{onClick:()=>{const Ae={name:m,type:u,base_id:f,setting:g},Be=new Blob([JSON.stringify(Ae,null,2)],{type:"application/json"}),je=URL.createObjectURL(Be),Xe=document.createElement("a");Xe.href=je,Xe.download=`${m||"preset"}.json`,document.body.appendChild(Xe),Xe.click(),document.body.removeChild(Xe),URL.revokeObjectURL(je),a(r("profiles.presets.toast.exported"))},className:"flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors",title:r("profiles.presets.exportToJson"),children:[i.jsx(pi,{className:"w-4 h-4"}),r("common.download")]}),i.jsxs("button",{onClick:()=>document.getElementById("file-import")?.click(),className:"flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors",title:r("profiles.presets.importFromJson"),children:[i.jsx(xi,{className:"w-4 h-4"}),r("common.upload")]}),i.jsx("input",{id:"file-import",type:"file",accept:".json",className:"hidden",onChange:Ae=>{const Be=Ae.target.files?.[0];if(Be){const je=new FileReader;je.onload=Xe=>{try{const ce=JSON.parse(Xe.target?.result),Ie=ce.setting||ce;_(Ce=>({...Ce,...Ie})),a(r("profiles.presets.fileImported"))}catch{a(r("profiles.presets.invalidJson"),"error")}},je.readAsText(Be)}}})]}),i.jsxs("div",{className:"flex-1 p-4",children:[l==="common"&&i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[i.jsx(ax,{className:"w-4 h-4 text-amber-400"}),r("profiles.templates.title")]}),Object.keys(g).filter(Ae=>Ae!=="inherits").length>0&&i.jsxs("button",{onClick:()=>me(!X),className:"text-xs text-bambu-gray hover:text-white flex items-center gap-1 transition-colors",children:[i.jsx(ts,{className:"w-3 h-3"}),r("profiles.presets.saveAsTemplate")]})]}),X&&i.jsxs("div",{className:"mb-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-2 mb-2",children:[i.jsx("input",{type:"text",value:he,onChange:Ae=>ge(Ae.target.value),placeholder:r("profiles.templates.namePlaceholder"),className:"px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",autoFocus:!0}),i.jsx("input",{type:"text",value:Y,onChange:Ae=>oe(Ae.target.value),placeholder:r("profiles.templates.descriptionPlaceholder"),className:"px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Oe,{size:"sm",onClick:ye,disabled:!he.trim(),children:[i.jsx(ts,{className:"w-3 h-3"}),r("common.save")]}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:()=>me(!1),children:r("common.cancel")})]}),i.jsxs("button",{onClick:()=>xe(!le),className:`flex items-center gap-1.5 text-xs transition-colors ${le?"text-bambu-green":"text-bambu-gray hover:text-white"}`,children:[le?i.jsx(_c,{className:"w-3.5 h-3.5"}):i.jsx(mw,{className:"w-3.5 h-3.5"}),r(le?"profiles.templates.shownInModals":"profiles.templates.hiddenInModals")]})]})]}),Pe&&i.jsxs("div",{className:"mb-3 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg flex items-center gap-2",children:[i.jsx(Yr,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("span",{className:"text-sm text-bambu-green",children:[r("profiles.presets.templateApplied")," ",i.jsx("span",{className:"font-medium",children:Pe})]}),i.jsx("button",{onClick:()=>q(null),className:"ml-auto text-bambu-green/70 hover:text-bambu-green",children:i.jsx(Ht,{className:"w-4 h-4"})})]}),i.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[ae.map(Ae=>i.jsxs("button",{onClick:()=>fe(Ae),className:"p-3 text-left bg-bambu-dark border border-bambu-dark-tertiary rounded-lg hover:border-bambu-gray-dark transition-colors",children:[i.jsx("p",{className:"text-sm font-medium text-white",children:Ae.name}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:Ae.description})]},Ae.id)),ae.length===0&&i.jsx("p",{className:"col-span-3 text-center text-bambu-gray text-sm py-4",children:r("profiles.presets.noTemplatesSelected")})]}),i.jsx("p",{className:"text-xs text-bambu-gray-dark mt-2 text-center",children:r("profiles.presets.manageTemplatesHint")})]}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:r("profiles.presets.commonSettings")}),i.jsx("div",{className:"grid grid-cols-2 gap-x-6 gap-y-3",children:J.slice(0,10).map(Ae=>i.jsxs("div",{className:"flex items-center justify-between gap-4 max-[640px]:flex-col max-[640px]:items-start",children:[i.jsx("label",{className:"text-sm text-bambu-gray flex-shrink-0",children:Ae.label}),i.jsx("div",{className:"w-48 max-[640px]:w-full",children:Ee(Ae)})]},Ae.key))})]}),Object.keys(g).length>1&&i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:r("profiles.presets.currentOverrides")}),i.jsx("div",{className:"flex flex-wrap gap-2",children:Object.entries(g).filter(([Ae])=>Ae!=="inherits").map(([Ae,Be])=>i.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-green/10 text-bambu-green text-xs rounded",children:[Ae,": ",String(Be).slice(0,20),i.jsx("button",{onClick:()=>ue(Ae,void 0),className:"hover:text-white",children:i.jsx(Ht,{className:"w-3 h-3"})})]},Ae))})]})]}),l==="fields"&&i.jsxs("div",{className:"grid grid-cols-2 gap-6",style:{height:"400px"},children:[i.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3 flex-shrink-0",children:[i.jsx("h3",{className:"text-sm font-medium text-white",children:r("profiles.presets.availableFields")}),i.jsx("span",{className:"text-xs text-bambu-gray",children:$?r("profiles.templates.fieldsCount",{count:J.length}):r("common.loading")})]}),i.jsxs("div",{className:"relative mb-3 flex-shrink-0",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:k,onChange:Ae=>R(Ae.target.value),placeholder:r("profiles.presets.searchFieldsPlaceholder"),className:"w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto space-y-1 pr-2 min-h-0",children:[W.filter(Ae=>!(Ae.key in g)).map(Ae=>{const Be=Le[Ae.key],je=qe(Be);return i.jsxs("div",{onClick:()=>{_(Xe=>({...Xe,[Ae.key]:je||""}))},className:"flex items-center justify-between gap-2 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors cursor-pointer group",children:[i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"text-sm text-white truncate",children:Ae.label}),i.jsx("p",{className:"text-xs text-bambu-gray-dark truncate",children:Ae.key})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[je&&i.jsxs("span",{className:"text-xs text-bambu-gray bg-bambu-dark px-2 py-0.5 rounded max-w-32 truncate",title:je,children:[je.slice(0,20),je.length>20?"...":""]}),i.jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded bg-bambu-dark-tertiary group-hover:bg-bambu-green/20 transition-colors",children:i.jsx(ar,{className:"w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors"})})]})]},Ae.key)}),W.filter(Ae=>!(Ae.key in g)).length===0&&i.jsx("p",{className:"text-center text-bambu-gray py-4 text-sm",children:r(k?"profiles.presets.noMatchingFields":"profiles.presets.allFieldsAdded")})]}),i.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0",children:G?i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"text",value:H,onChange:Ae=>z(Ae.target.value),onKeyDown:Ae=>Ae.key==="Enter"&&re(),placeholder:"custom_field_name",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",autoFocus:!0}),i.jsx(Oe,{size:"sm",onClick:re,disabled:!H.trim(),children:i.jsx(ar,{className:"w-4 h-4"})}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:()=>{I(!1),z("")},children:i.jsx(Ht,{className:"w-4 h-4"})})]}):i.jsxs("button",{onClick:()=>I(!0),className:"w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors",children:[i.jsx(ar,{className:"w-4 h-4"}),r("profiles.presets.addCustomField")]})})]}),i.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3 flex-shrink-0",children:[i.jsx("h3",{className:"text-sm font-medium text-white",children:r("profiles.presets.yourOverrides")}),i.jsx("span",{className:"text-xs text-bambu-gray",children:r("profiles.templates.fieldsCount",{count:Object.keys(g).filter(Ae=>Ae!=="inherits").length})})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto space-y-2 pr-2 min-h-0",children:[Object.entries(g).filter(([Ae])=>Ae!=="inherits").map(([Ae,Be])=>{const je=J.find(Xe=>Xe.key===Ae);return i.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm font-medium text-white",children:je?.label||Ae}),i.jsx("p",{className:"text-xs text-bambu-gray-dark",children:Ae})]}),i.jsx("button",{onClick:()=>ue(Ae,void 0),className:"p-1 text-bambu-gray hover:text-red-400 transition-colors",children:i.jsx(Ht,{className:"w-4 h-4"})})]}),je?Ee(je):i.jsx("input",{type:"text",value:String(Be),onChange:Xe=>ue(Ae,Xe.target.value),className:"w-full px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]},Ae)}),Object.keys(g).filter(Ae=>Ae!=="inherits").length===0&&i.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[i.jsx(G8,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),i.jsx("p",{className:"text-sm",children:r("profiles.presets.noOverridesYet")}),i.jsx("p",{className:"text-xs mt-1",children:r("profiles.presets.clickFieldsToAdd")})]})]}),Object.keys(g).filter(Ae=>Ae!=="inherits").length>0&&i.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0",children:i.jsxs("button",{onClick:()=>{me(!0),c("common")},className:"w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors",children:[i.jsx(ts,{className:"w-4 h-4"}),r("profiles.presets.saveAsTemplate")]})})]})]}),l==="json"&&i.jsxs("div",{className:"space-y-2",children:[C&&i.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm",children:[i.jsx(Li,{className:"w-4 h-4"}),C]}),i.jsx("textarea",{value:N,onChange:Ae=>L(Ae.target.value),className:`w-full h-80 px-3 py-2 bg-bambu-dark border rounded-lg text-white text-xs font-mono focus:outline-none resize-none ${C?"border-red-500 focus:border-red-500":"border-bambu-dark-tertiary focus:border-bambu-green"}`,spellCheck:!1}),i.jsx("p",{className:"text-xs text-bambu-gray",children:r("profiles.presets.jsonTip")})]})]}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex gap-2",children:[i.jsx(Oe,{variant:"secondary",onClick:t,className:"flex-1",children:r("common.cancel")}),i.jsxs(Oe,{onClick:()=>pe.mutate(),disabled:pe.isPending||!m.trim()||!o&&!f||!!C,className:"flex-1",children:[pe.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):o?i.jsx(ts,{className:"w-4 h-4"}):i.jsx(ar,{className:"w-4 h-4"}),r(o?"common.save":e?"common.duplicate":"common.create")]})]})]})})]})}function Jet({settings:t,lastSyncTime:e,onRefresh:n,isRefreshing:r,printers:a,hasPermission:s,t:o}){const[l,c]=w.useState(""),[u,d]=w.useState("all"),[m,p]=w.useState("all"),[f,y]=w.useState("all"),[v,x]=w.useState("all"),[g,_]=w.useState("all"),[N,T]=w.useState("all"),[C,A]=w.useState(null),[k,R]=w.useState(!1),[P,D]=w.useState(!1),[H,z]=w.useState(null),[G,I]=w.useState(null),[ee,ie]=w.useState(null),[X,me]=w.useState(!1),[he,ge]=w.useState([null,null]),[Y,oe]=w.useState(!1),[le,xe]=w.useState(null),Pe=an(),q=w.useMemo(()=>[...t.filament.map(re=>({...re,type:"filament"})),...t.printer.map(re=>({...re,type:"printer"})),...t.process.map(re=>({...re,type:"process"}))].map(re=>({...re,meta:N5(re.name)})),[t]),Z=w.useMemo(()=>{const W=new Set,re=new Set,ue=new Set;return q.forEach(fe=>{fe.meta.nozzle&&W.add(fe.meta.nozzle),fe.meta.filamentType&&re.add(fe.meta.filamentType),fe.meta.layerHeight&&ue.add(fe.meta.layerHeight)}),{printers:a.map(fe=>({id:fe.id.toString(),name:fe.name})),nozzles:Array.from(W).sort((fe,ye)=>parseFloat(fe)-parseFloat(ye)),filaments:Array.from(re).sort(),layerHeights:Array.from(ue).sort((fe,ye)=>parseFloat(fe)-parseFloat(ye))}},[q,a]),j=w.useMemo(()=>f==="all"?null:a.find(re=>re.id.toString()===f)?.model||null,[f,a]),E=w.useMemo(()=>q.filter(W=>u==="all"||W.type===u).filter(W=>{if(m==="all")return!0;const re=ow(W.setting_id);return m==="custom"?re:!re}).filter(W=>{if(f==="all"||!j)return!0;const re=W.meta.printer?.toLowerCase()||"",ue=j.toLowerCase();return re.includes(ue)||ue.includes(re)}).filter(W=>v==="all"||W.meta.nozzle===v).filter(W=>g==="all"||W.meta.filamentType===g).filter(W=>N==="all"||W.meta.layerHeight===N).filter(W=>l===""||W.name.toLowerCase().includes(l.toLowerCase())).sort((W,re)=>W.name.localeCompare(re.name)),[q,u,m,f,j,v,g,N,l]),U=W=>{if(X){const re=he[0]?.setting_id===W.setting_id,ue=he[1]?.setting_id===W.setting_id;if(re)ge([he[1],null]);else if(ue)ge([he[0],null]);else if(!he[0])ge([W,null]);else if(he[1]){if(he[0].type!==W.type)return;ge([he[0],W])}else{if(he[0].type!==W.type)return;ge([he[0],W])}}else A(W)},K=W=>{if(he[0]?.setting_id===W.setting_id)return 0;if(he[1]?.setting_id===W.setting_id)return 1},$=async W=>{try{const re=await be.getCloudSettingDetail(W.setting_id),ue=W.type==="process"?"print":W.type;z({type:ue,name:W.name,base_id:re.base_id||"GFSA00",setting:re.setting||{}}),A(null)}catch(re){console.error("Failed to fetch preset details for duplication:",re)}},ne=async W=>{try{Pe.removeQueries({queryKey:["cloudSettingDetail",W.setting_id]});const re=await be.getCloudSettingDetail(W.setting_id),ue=W.type==="process"?"print":W.type;I({type:ue,name:W.name,base_id:re.base_id||"GFSA00",setting:re.setting||{},setting_id:W.setting_id}),A(null)}catch(re){console.error("Failed to fetch preset details for editing:",re)}},O=()=>{d("all"),p("all"),y("all"),x("all"),_("all"),T("all"),c("")},V=u!=="all"||m!=="all"||f!=="all"||v!=="all"||g!=="all"||N!=="all"||l!=="",J=t.filament.length+t.printer.length+t.process.length;return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"space-y-4 mb-6",children:[i.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:l,onChange:W=>c(W.target.value),placeholder:o("profiles.cloudView.searchPlaceholder"),className:"w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{className:"flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center",children:[i.jsxs(Oe,{variant:X?"primary":"secondary",onClick:()=>{X?(me(!1),ge([null,null])):me(!0)},children:[i.jsx(zb,{className:"w-4 h-4"}),o(X?"common.cancel":"profiles.presets.compare")]}),i.jsxs(Oe,{variant:"secondary",onClick:()=>D(!0),disabled:!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.cloudView.noTemplatesPermission"),children:[i.jsx(ax,{className:"w-4 h-4"}),o("profiles.cloudView.templates")]}),i.jsxs(Oe,{variant:"secondary",onClick:n,disabled:r||!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.cloudView.noRefreshPermission"),children:[i.jsx(wr,{className:`w-4 h-4 ${r?"animate-spin":""}`}),o("profiles.cloudView.refresh")]}),i.jsxs(Oe,{onClick:()=>R(!0),disabled:!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.cloudView.noCreatePermission"),children:[i.jsx(ar,{className:"w-4 h-4"}),o("profiles.cloudView.newPreset")]})]})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx(QC,{className:"w-4 h-4 text-bambu-gray"}),i.jsx(wb,{label:o("profiles.cloudView.filters.type"),value:u,options:[{value:"all",label:o("profiles.cloudView.filters.all"),count:J},{value:"filament",label:o("profiles.cloudView.filters.filament"),count:t.filament.length},{value:"printer",label:o("profiles.cloudView.filters.printer"),count:t.printer.length},{value:"process",label:o("profiles.cloudView.filters.process"),count:t.process.length}],onChange:W=>d(W)}),i.jsx(wb,{label:o("profiles.cloudView.filters.owner"),value:m,options:[{value:"all",label:o("profiles.cloudView.filters.all")},{value:"custom",label:o("profiles.cloudView.filters.myPresets")},{value:"builtin",label:o("profiles.cloudView.filters.builtIn")}],onChange:W=>p(W)}),Z.printers.length>0&&i.jsx(wb,{label:o("profiles.cloudView.filters.printer"),value:f,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...Z.printers.map(W=>({value:W.id,label:W.name}))],onChange:y}),Z.nozzles.length>0&&i.jsx(wb,{label:o("profiles.cloudView.filters.nozzle"),value:v,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...Z.nozzles.map(W=>({value:W,label:W}))],onChange:x}),Z.filaments.length>0&&(u==="all"||u==="filament")&&i.jsx(wb,{label:o("profiles.cloudView.filters.filament"),value:g,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...Z.filaments.map(W=>({value:W,label:W}))],onChange:_}),Z.layerHeights.length>0&&(u==="all"||u==="process")&&i.jsx(wb,{label:o("profiles.cloudView.filters.layer"),value:N,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...Z.layerHeights.map(W=>({value:W,label:W}))],onChange:T}),V&&i.jsx("button",{onClick:O,className:"px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:o("profiles.cloudView.clearFilters")})]})]}),X&&i.jsx("div",{className:"mb-4 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx(zb,{className:"w-5 h-5 text-blue-400"}),i.jsx("span",{className:"text-white font-medium",children:o("profiles.cloudView.compareMode")}),i.jsx("span",{className:"text-bambu-gray",children:he[0]?o("profiles.cloudView.selectAnotherPreset",{type:he[0].type}):o("profiles.cloudView.clickTwoPresets")})]}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${he[0]?"bg-blue-500/30 text-blue-700 dark:text-blue-300":"bg-bambu-dark text-bambu-gray"}`,children:he[0]?he[0].name:o("profiles.cloudView.selectFirst")}),i.jsx(p3,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${he[1]?"bg-blue-500/30 text-blue-700 dark:text-blue-300":"bg-bambu-dark text-bambu-gray"}`,children:he[1]?he[1].name:o("profiles.cloudView.selectSecond")})]}),he[0]&&he[1]&&i.jsxs(Oe,{size:"sm",onClick:async()=>{try{const[W,re]=await Promise.all([be.getCloudSettingDetail(he[0].setting_id),be.getCloudSettingDetail(he[1].setting_id)]);xe([W.setting||{},re.setting||{}]),oe(!0)}catch{}},children:[i.jsx(zb,{className:"w-4 h-4"}),o("profiles.cloudView.compareNow")]})]})]})}),i.jsxs("div",{className:"flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray",children:[e&&i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx(er,{className:"w-3 h-3"}),o("profiles.cloudView.lastSynced")," ",x0(e.toISOString(),"system",o)]}),i.jsx("span",{children:o("profiles.cloudView.showingCount",{showing:E.length,total:J})}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-bambu-green"}),i.jsxs("span",{children:["= ",o("profiles.presets.myPreset")]})]})]}),E.length===0?i.jsxs("div",{className:"text-center py-16",children:[i.jsx(Gi,{className:"w-12 h-12 text-bambu-gray-dark mx-auto mb-4"}),i.jsx("p",{className:"text-bambu-gray",children:o("profiles.cloudView.noPresetsFound")}),V&&i.jsx("button",{onClick:O,className:"mt-2 text-sm text-bambu-green hover:text-bambu-green-light",children:o("profiles.cloudView.clearFilters")})]}):i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[i.jsx(YC,{className:"w-4 h-4 text-amber-400"}),i.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:o("profiles.cloudView.columns.filament")}),i.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",E.filter(W=>W.type==="filament").length,")"]})]}),i.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[E.filter(W=>W.type==="filament").map(W=>i.jsx(HD,{setting:W,onClick:()=>U(W),onDuplicate:()=>$(W),compareMode:X,isCompareSelected:K(W)!==void 0,compareIndex:K(W),compareDisabled:X&&!!he[0]&&he[0].type!==W.type,t:o},W.setting_id)),E.filter(W=>W.type==="filament").length===0&&i.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:o("profiles.cloudView.noFilamentPresets")})]})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[i.jsx(jd,{className:"w-4 h-4 text-blue-400"}),i.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:o("profiles.cloudView.columns.process")}),i.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",E.filter(W=>W.type==="process").length,")"]})]}),i.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[E.filter(W=>W.type==="process").map(W=>i.jsx(HD,{setting:W,onClick:()=>U(W),onDuplicate:()=>$(W),compareMode:X,isCompareSelected:K(W)!==void 0,compareIndex:K(W),compareDisabled:X&&!!he[0]&&he[0].type!==W.type,t:o},W.setting_id)),E.filter(W=>W.type==="process").length===0&&i.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:o("profiles.cloudView.noProcessPresets")})]})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[i.jsx(Sr,{className:"w-4 h-4 text-purple-400"}),i.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:o("profiles.cloudView.columns.printer")}),i.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",E.filter(W=>W.type==="printer").length,")"]})]}),i.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[E.filter(W=>W.type==="printer").map(W=>i.jsx(HD,{setting:W,onClick:()=>U(W),onDuplicate:()=>$(W),compareMode:X,isCompareSelected:K(W)!==void 0,compareIndex:K(W),compareDisabled:X&&!!he[0]&&he[0].type!==W.type,t:o},W.setting_id)),E.filter(W=>W.type==="printer").length===0&&i.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:o("profiles.cloudView.noPrinterPresets")})]})]})]}),C&&i.jsx(Xet,{setting:C,onClose:()=>A(null),onDeleted:()=>A(null),onDuplicate:()=>$(C),onEdit:()=>ne(C),hasPermission:s,t:o}),(k||H||G||ee)&&i.jsx(Zet,{onClose:()=>{R(!1),z(null),I(null),ie(null)},initialData:G||H||(ee?{type:ee.type,name:"",base_id:"",setting:ee.setting}:void 0),allPresets:t,t:o}),P&&i.jsx(Qet,{onClose:()=>D(!1),onApply:W=>{ie({type:W.type,setting:W.settings}),D(!1)},t:o}),Y&&le&&he[0]&&he[1]&&i.jsx(Boe,{onClose:()=>{oe(!1),xe(null)},leftPreset:le[0],rightPreset:le[1],leftLabel:he[0].name,rightLabel:he[1].name,t:o})]})}function ett(){const{t}=Ft(),e=an(),{showToast:n}=fn(),{hasPermission:r}=_r(),[a,s]=w.useState("cloud"),[o,l]=w.useState(),{data:c,isLoading:u}=et({queryKey:["cloudStatus"],queryFn:be.getCloudStatus}),{data:d=[]}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:m,isLoading:p,refetch:f,dataUpdatedAt:y}=et({queryKey:["cloudSettings"],queryFn:()=>be.getCloudSettings(),enabled:!!c?.is_authenticated,retry:!1,staleTime:1e3*60*5});w.useEffect(()=>{y&&l(new Date(y))},[y]);const v=pt({mutationFn:be.cloudLogout,onSuccess:()=>{e.invalidateQueries({queryKey:["cloudStatus"]}),e.removeQueries({queryKey:["cloudSettings"]}),n(t("profiles.toast.loggedOut"))}}),x=()=>{e.invalidateQueries({queryKey:["cloudStatus"]})};return u?i.jsx("div",{className:"p-4 md:p-8 flex items-center justify-center min-h-[400px]",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):i.jsxs("div",{className:"p-6 lg:p-8",children:[i.jsxs("div",{className:"mb-6",children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:t("profiles.title")}),i.jsx("p",{className:"text-bambu-gray",children:t("profiles.subtitle")})]}),i.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary mb-6",children:[i.jsxs("button",{onClick:()=>s("cloud"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${a==="cloud"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(Fx,{className:"w-4 h-4"}),t("profiles.tabs.cloud")]}),i.jsxs("button",{onClick:()=>s("local"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${a==="local"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(Lx,{className:"w-4 h-4"}),t("profiles.tabs.local")]}),i.jsxs("button",{onClick:()=>s("kprofiles"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${a==="kprofiles"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(ZC,{className:"w-4 h-4"}),t("profiles.tabs.kprofiles")]})]}),a==="cloud"&&i.jsxs(i.Fragment,{children:[c?.is_authenticated&&i.jsxs("div",{className:"flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"w-2 h-2 rounded-full bg-bambu-green animate-pulse"}),i.jsxs("span",{className:"text-sm text-bambu-gray",children:[t("profiles.connectedAs")," ",i.jsx("span",{className:"text-white",children:c.email})]})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>v.mutate(),disabled:v.isPending||!r("cloud:auth"),title:r("cloud:auth")?void 0:t("profiles.noLogoutPermission"),children:[i.jsx(x3,{className:"w-4 h-4"}),t("profiles.logout")]})]}),c?.is_authenticated?p?i.jsx("div",{className:"flex items-center justify-center py-16",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):m?i.jsx(Jet,{settings:m,lastSyncTime:o,onRefresh:()=>f(),isRefreshing:p,printers:d,hasPermission:r,t}):i.jsxs("div",{className:"text-center py-16",children:[i.jsx("p",{className:"text-bambu-gray mb-4",children:t("profiles.failedToLoad")}),i.jsx(Oe,{onClick:()=>f(),children:t("profiles.retry")})]}):i.jsx(Ket,{onSuccess:x,t})]}),a==="local"&&i.jsx(Wet,{}),a==="kprofiles"&&i.jsx($et,{}),i.jsx(Yet,{})]})}const Iv={Droplet:YC,Flame:Fp,Ruler:Tge,Sparkles:ax,Square:zl,Cable:zL,Wrench:Sf,Calendar:Wr,Timer:pd,Cog:gpe,Fan:$X,Zap:kc,Wind:nQ,Thermometer:aT,Layers:Gi,Box:ra,Target:JX,RefreshCw:wr,Settings:iT,Filter:QC,CircleDot:Qhe};function c0(t){return t&&Iv[t]||Sf}function Sb(t,e,n){if(e==="days"){if(t<1)return n?n("common.today"):"Today";if(t===1)return n?n("maintenance.day"):"1 day";if(t<7){const a=Math.round(t);return n?n("maintenance.days",{count:a}):`${a} days`}if(t<180){const a=Math.round(t/7);return a===1?n?n("maintenance.week"):"1 week":n?n("maintenance.weeks",{count:a}):`${a} weeks`}const r=Math.round(t/30);return r===1?n?n("maintenance.month"):"1 month":n?n("maintenance.months",{count:r}):`${r} months`}else{if(t<1)return`${Math.round(t*60)}m`;if(t<24)return`${t<10?t.toFixed(1):Math.round(t)}h`;const r=t/24;if(r<7)return`${r<2?r.toFixed(1):Math.round(r)}d`;const a=r/7;return a<12?`${a<2?a.toFixed(1):Math.round(a)}w`:`${Math.round(a/4)}mo`}}function $D(t,e,n){return e==="days"?t===1?n?n("maintenance.day"):"1 day":t===7?n?n("maintenance.week"):"1 week":t===14?n?n("maintenance.weeks",{count:2}):"2 weeks":t===30?n?n("maintenance.month"):"1 month":t===60?n?n("maintenance.months",{count:2}):"2 months":t===90?n?n("maintenance.months",{count:3}):"3 months":t===180?n?n("maintenance.months",{count:6}):"6 months":t===365?n?n("maintenance.year"):"1 year":n?n("maintenance.days",{count:t}):`${t} days`:`${t}h`}function ttt(t,e){const n=(e||"").toUpperCase().replace(/[- ]/g,""),r=n.includes("X1"),a=n.includes("P1"),s=n.includes("A1MINI"),o=n.includes("A1")&&!s,l=n.includes("H2D"),c=n.includes("H2C"),u=n.includes("H2S"),d=l||c||u,m=n.includes("P2S");switch(t){case"Lubricate Carbon Rods":return r?"https://wiki.bambulab.com/en/x1/maintenance/basic-maintenance":a?"https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance":null;case"Lubricate Steel Rods":return m?"https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis":null;case"Clean Steel Rods":return m?"https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis":null;case"Lubricate Linear Rails":return s?"https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis":o?"https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis":d?"https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication":null;case"Clean Nozzle/Hotend":return r||a?"https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog":s||o?"https://wiki.bambulab.com/en/a1-mini/troubleshooting/nozzle-clog":d?"https://wiki.bambulab.com/en/h2/maintenance/nozzl-cold-pull-maintenance-and-cleaning":m?"https://wiki.bambulab.com/en/p2s/maintenance/cold-pull-maintenance-hotend":"https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog";case"Check Belt Tension":return r?"https://wiki.bambulab.com/en/x1/maintenance/belt-tension":a?"https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance":s?"https://wiki.bambulab.com/en/a1-mini/maintenance/belt_tension":o?"https://wiki.bambulab.com/en/a1/maintenance/belt_tension":l?"https://wiki.bambulab.com/en/h2/maintenance/belt-tension":c?"https://wiki.bambulab.com/en/h2c/maintenance/belt-tension":u?"https://wiki.bambulab.com/en/h2s/maintenance/belt-tension":m?"https://wiki.bambulab.com/en/p2s/maintenance/belt-tension":"https://wiki.bambulab.com/en/x1/maintenance/belt-tension";case"Clean Carbon Rods":return r||a?"https://wiki.bambulab.com/en/general/carbon-rods-clearance":null;case"Clean Linear Rails":return s?"https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis":o?"https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis":d?"https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication":null;case"Clean Build Plate":return"https://wiki.bambulab.com/en/filament-acc/acc/pei-plate-clean-guide";case"Check PTFE Tube":return r||a?"https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube":s||o?"https://wiki.bambulab.com/en/a1-mini/maintenance/ptfe-tube":l?"https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer":u?"https://wiki.bambulab.com/en/h2s/maintenance/replace-ptfe-tube-on-h2s-printer":c?"https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer":"https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube";case"Replace HEPA Filter":case"HEPA Filter":case"Replace Carbon Filter":case"Carbon Filter":return d?"https://wiki.bambulab.com/en/h2/maintenance/replace-smoke-purifier-air-filte":"https://wiki.bambulab.com/en/x1/maintenance/replace-carbon-filter";case"Lubricate Left Nozzle Rail":case"Left Nozzle Rail":return d?"https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication":null;default:return null}}function ntt({item:t,onPerform:e,onToggle:n,hasPermission:r,t:a}){const s=c0(t.maintenance_type_icon),o=t.interval_type||"hours",c=(()=>{if(o==="days"){const f=t.days_since_maintenance??0;return Math.max(0,Math.min(100,f/t.interval_hours*100))}return Math.max(0,Math.min(100,(t.interval_hours-t.hours_until_due)/t.interval_hours*100))})(),u=()=>t.enabled?t.is_due?"text-red-400":t.is_warning?"text-amber-400":"text-bambu-green":"text-bambu-gray",d=()=>t.enabled?t.is_due?"bg-red-500":t.is_warning?"bg-amber-500":"bg-bambu-green":"bg-bambu-gray/30",m=()=>t.enabled?t.is_due?"bg-red-500/5 border-red-500/20":t.is_warning?"bg-amber-500/5 border-amber-500/20":"bg-bambu-dark-secondary border-bambu-dark-tertiary":"bg-bambu-dark-secondary/50",p=()=>{if(!t.enabled)return a("common.disabled");if(o==="days"){const f=t.days_until_due??0;return t.is_due?a("maintenance.overdueBy",{duration:Sb(Math.abs(f),"days",a)}):t.is_warning?a("maintenance.dueIn",{duration:Sb(f,"days",a)}):a("maintenance.timeLeft",{duration:Sb(f,"days",a)})}else return t.is_due?a("maintenance.overdueBy",{duration:Sb(Math.abs(t.hours_until_due),"hours",a)}):t.is_warning?a("maintenance.dueIn",{duration:Sb(t.hours_until_due,"hours",a)}):a("maintenance.timeLeft",{duration:Sb(t.hours_until_due,"hours",a)})};return i.jsx("div",{className:`rounded-xl border p-4 transition-all ${m()}`,children:i.jsxs("div",{className:"flex items-start gap-3 max-[550px]:flex-wrap",children:[i.jsxs("div",{className:`relative p-2.5 rounded-lg shrink-0 ${t.is_due?"bg-red-500/20":t.is_warning?"bg-amber-500/20":t.enabled?"bg-bambu-dark":"bg-bambu-dark/50"}`,children:[i.jsx(s,{className:`w-5 h-5 ${u()}`}),t.enabled&&(t.is_due||t.is_warning)&&i.jsx("span",{className:`absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full ${t.is_due?"bg-red-500":"bg-amber-500"} animate-pulse`})]}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("h3",{className:`font-medium truncate ${t.enabled?"text-white":"text-bambu-gray"}`,children:t.maintenance_type_name}),o==="days"&&i.jsx("span",{title:a("maintenance.timeBasedInterval"),children:i.jsx(Wr,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"})}),(()=>{const f=t.maintenance_type_wiki_url||ttt(t.maintenance_type_name,t.printer_model);return f?i.jsx("a",{href:f,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-bambu-green transition-colors shrink-0",title:a("maintenance.viewDocumentation"),onClick:y=>y.stopPropagation(),children:i.jsx(Jr,{className:"w-3.5 h-3.5"})}):null})()]}),i.jsx("div",{className:"mt-2 mb-1.5",children:i.jsx("div",{className:"w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden",children:i.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${d()}`,style:{width:`${c}%`}})})}),i.jsxs("div",{className:`text-xs flex items-center gap-1 ${u()}`,children:[t.is_due&&i.jsx(Mn,{className:"w-3 h-3"}),t.is_warning&&!t.is_due&&i.jsx(er,{className:"w-3 h-3"}),!t.is_due&&!t.is_warning&&t.enabled&&i.jsx(Yr,{className:"w-3 h-3"}),p()]})]}),i.jsxs("div",{className:"flex items-center gap-2 shrink-0 max-[550px]:w-full max-[550px]:justify-end max-[550px]:mt-1",children:[i.jsx("span",{title:r("maintenance:update")?void 0:a("maintenance.noPermissionUpdate"),children:i.jsx(Bn,{checked:t.enabled,onChange:f=>n(t.id,f),disabled:!r("maintenance:update")})}),i.jsxs(Oe,{size:"sm",variant:t.is_due?"primary":"secondary",onClick:()=>e(t.id),disabled:!t.enabled||!r("maintenance:update"),title:r("maintenance:update")?void 0:a("maintenance.noPermissionPerform"),className:"!px-3",children:[i.jsx(bo,{className:"w-3.5 h-3.5"}),a("common.reset")]})]})]})})}function rtt({overview:t,onPerform:e,onToggle:n,onSetHours:r,hasPermission:a,t:s}){const[o,l]=w.useState(!1),[c,u]=w.useState(!1),[d,m]=w.useState(t.total_print_hours.toFixed(1)),p=[...t.maintenance_items].sort((v,x)=>v.is_due&&!x.is_due?-1:!v.is_due&&x.is_due?1:v.is_warning&&!x.is_warning?-1:!v.is_warning&&x.is_warning?1:v.maintenance_type_id-x.maintenance_type_id),f=p.find(v=>v.enabled&&(v.is_due||v.is_warning)),y=()=>{const v=parseFloat(d);!isNaN(v)&&v>=0&&(r(t.printer_id,v),u(!1))};return i.jsxs(Mt,{className:"overflow-hidden",children:[i.jsxs("div",{className:"p-5",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx("h2",{className:"text-xl font-semibold text-white",children:t.printer_name}),i.jsxs("div",{className:"flex items-center gap-2",children:[t.due_count>0&&i.jsxs("span",{className:"px-2.5 py-1 bg-red-500/20 text-red-400 text-xs font-medium rounded-full flex items-center gap-1.5",children:[i.jsx(Mn,{className:"w-3 h-3"}),s("maintenance.overdueCount",{count:t.due_count})]}),t.warning_count>0&&i.jsxs("span",{className:"px-2.5 py-1 bg-amber-500/20 text-amber-400 text-xs font-medium rounded-full flex items-center gap-1.5",children:[i.jsx(er,{className:"w-3 h-3"}),s("maintenance.dueSoonCount",{count:t.warning_count})]}),t.due_count===0&&t.warning_count===0&&i.jsxs("span",{className:"px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1.5",children:[i.jsx(Yr,{className:"w-3 h-3"}),s("maintenance.allGood")]})]})]}),i.jsxs("button",{onClick:()=>l(!o),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded-lg transition-colors",children:[o?i.jsx(Il,{className:"w-4 h-4"}):i.jsx(Ln,{className:"w-4 h-4"}),s(o?"common.collapse":"common.expand")]})]}),i.jsxs("div",{className:"flex items-center gap-6 mt-4",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2 bg-bambu-dark/50 rounded-lg",children:i.jsx(pd,{className:"w-4 h-4 text-bambu-gray"})}),c?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",value:d,onChange:v=>m(v.target.value),onKeyDown:v=>{v.key==="Enter"&&y(),v.key==="Escape"&&u(!1)},className:"w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm",min:"0",step:"1",autoFocus:!0}),i.jsx("span",{className:"text-xs text-bambu-gray",children:s("common.hours")}),i.jsx(Oe,{size:"sm",onClick:y,children:s("common.save")}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:()=>u(!1),children:s("common.cancel")})]}):i.jsxs("button",{onClick:()=>{a("maintenance:update")&&(m(Math.round(t.total_print_hours).toString()),u(!0))},className:`group ${a("maintenance:update")?"":"cursor-not-allowed opacity-60"}`,title:a("maintenance:update")?void 0:s("maintenance.noPermissionEditHours"),children:[i.jsxs("div",{className:`text-sm font-medium text-white ${a("maintenance:update")?"group-hover:text-bambu-green":""} transition-colors flex items-center gap-1`,children:[Math.round(t.total_print_hours)," ",s("common.hours"),i.jsx(vf,{className:`w-3 h-3 text-bambu-gray ${a("maintenance:update")?"group-hover:text-bambu-green":""}`})]}),i.jsx("div",{className:"text-xs text-bambu-gray",children:s("maintenance.totalPrintTime")})]})]}),i.jsx("div",{className:"w-px h-10 bg-bambu-dark-tertiary"}),f&&i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:`p-2 rounded-lg ${f.is_due?"bg-red-500/20":"bg-amber-500/20"}`,children:(()=>{const v=c0(f.maintenance_type_icon);return i.jsx(v,{className:`w-4 h-4 ${f.is_due?"text-red-400":"text-amber-400"}`})})()}),i.jsxs("div",{children:[i.jsx("div",{className:`text-sm font-medium ${f.is_due?"text-red-400":"text-amber-400"}`,children:f.maintenance_type_name}),i.jsx("div",{className:`text-xs ${f.is_due?"text-red-400/70":"text-amber-400/70"}`,children:f.is_due?s("common.overdue"):s("maintenance.dueSoon")})]})]})]})]}),o&&i.jsx(Dt,{className:"pt-0 border-t border-bambu-dark-tertiary",children:i.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4",children:p.map(v=>i.jsx(ntt,{item:v,onPerform:e,onToggle:n,hasPermission:a,t:s},v.id))})})]})}function itt({overview:t,types:e,onUpdateInterval:n,onAddType:r,onUpdateType:a,onDeleteType:s,onRestoreDefaults:o,isRestoringDefaults:l,onAssignType:c,onRemoveItem:u,hasPermission:d,t:m}){const[p,f]=w.useState(null),[y,v]=w.useState(""),[x,g]=w.useState("hours"),[_,N]=w.useState(!1),[T,C]=w.useState(""),[A,k]=w.useState("100"),[R,P]=w.useState("hours"),[D,H]=w.useState("Wrench"),[z,G]=w.useState(""),[I,ee]=w.useState(new Set),[ie,X]=w.useState(null),[me,he]=w.useState(null),ge=w.useMemo(()=>t?t.map(L=>({id:L.printer_id,name:L.printer_name})):[],[t]),Y=L=>t?t.filter(F=>F.maintenance_items.some(te=>te.maintenance_type_id===L)).map(F=>({printerId:F.printer_id,printerName:F.printer_name,itemId:F.maintenance_items.find(te=>te.maintenance_type_id===L)?.id})):[],oe=L=>{if(!t)return[];const F=new Set(Y(L).map(te=>te.printerId));return ge.filter(te=>!F.has(te.id))},[le,xe]=w.useState(null),[Pe,q]=w.useState(""),[Z,j]=w.useState(""),[E,U]=w.useState("hours"),[K,$]=w.useState("Wrench"),[ne,O]=w.useState(""),V=L=>{xe(L),q(L.name),j(L.default_interval_hours.toString()),U(L.interval_type||"hours"),$(L.icon||"Wrench"),O(L.wiki_url||"")},J=()=>{le&&Pe.trim()&&parseFloat(Z)>0&&(a(le.id,{name:Pe.trim(),default_interval_hours:parseFloat(Z),interval_type:E,icon:K,wiki_url:ne.trim()||null}),xe(null))},W=(L,F,te)=>{const ve=parseFloat(y);if(!isNaN(ve)&&ve>0){const pe=Math.abs(ve-F)<.01?null:ve;n(L,{custom_interval_hours:pe,custom_interval_type:x!==te?x:null})}f(null)},re=L=>{L.preventDefault(),T.trim()&&parseFloat(A)>0&&I.size>0&&(r({name:T.trim(),default_interval_hours:parseFloat(A),interval_type:R,icon:D,wiki_url:z.trim()||null},Array.from(I)),C(""),k("100"),P("hours"),G(""),ee(new Set),N(!1))},ue=L=>{ee(F=>{const te=new Set(F);return te.has(L)?te.delete(L):te.add(L),te})},fe=t?.map(L=>({printerId:L.printer_id,printerName:L.printer_name,items:L.maintenance_items.sort((F,te)=>F.maintenance_type_id-te.maintenance_type_id)})).sort((L,F)=>L.printerName.localeCompare(F.printerName))||[],ye=e.filter(L=>L.is_system),ae=e.filter(L=>!L.is_system);return i.jsxs("div",{className:"space-y-8",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsxs("div",{children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:m("maintenance.maintenanceTypes")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:m("maintenance.maintenanceTypesDescription")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Oe,{variant:"secondary",onClick:o,disabled:!d("maintenance:delete")||l,title:d("maintenance:delete")?void 0:m("maintenance.noPermissionDeleteTypes"),children:m("maintenance.restoreDefaults")}),i.jsxs(Oe,{onClick:()=>N(!_),disabled:!d("maintenance:create"),title:d("maintenance:create")?void 0:m("maintenance.noPermissionEditTypes"),children:[i.jsx(ar,{className:"w-4 h-4"}),m("maintenance.addCustomType")]})]})]}),_&&i.jsx(Mt,{className:"mb-6",children:i.jsx(Dt,{className:"py-4",children:i.jsxs("form",{onSubmit:re,children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[i.jsxs("div",{className:"lg:col-span-2",children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("common.name")}),i.jsx("input",{type:"text",value:T,onChange:L=>C(L.target.value),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",placeholder:m("maintenance.exampleName"),autoFocus:!0})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.intervalType")}),i.jsxs("select",{value:R,onChange:L=>{P(L.target.value),L.target.value==="days"?k("30"):k("100")},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",children:[i.jsx("option",{value:"hours",children:m("maintenance.printHours")}),i.jsx("option",{value:"days",children:m("maintenance.calendarDays")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.intervalValue",{type:R==="days"?m("maintenance.calendarDays").toLowerCase():m("common.hours")})}),i.jsx("input",{type:"number",value:A,onChange:L=>k(L.target.value),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",min:"1"})]})]}),i.jsx("div",{className:"mt-4 flex items-end justify-between",children:i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.icon")}),i.jsx("div",{className:"flex gap-1",children:Object.keys(Iv).map(L=>{const F=Iv[L];return i.jsx("button",{type:"button",onClick:()=>H(L),className:`p-2 rounded-lg transition-colors ${D===L?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,children:i.jsx(F,{className:"w-4 h-4"})},L)})})]})}),i.jsxs("div",{className:"mt-4",children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.documentationLink")}),i.jsx("input",{type:"url",value:z,onChange:L=>G(L.target.value),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",placeholder:"https://wiki.bambulab.com/..."})]}),i.jsxs("div",{className:"mt-4",children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.assignToPrinters")}),i.jsx("div",{className:"flex flex-wrap gap-2",children:ge.map(L=>i.jsx("button",{type:"button",onClick:()=>ue(L.id),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${I.has(L.id)?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,children:L.name},L.id))}),I.size===0&&i.jsx("p",{className:"text-xs text-orange-400 mt-1",children:m("maintenance.selectAtLeastOnePrinter")})]}),i.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:()=>{N(!1),ee(new Set)},children:m("common.cancel")}),i.jsx(Oe,{type:"submit",disabled:!T.trim()||I.size===0,children:m("maintenance.addType")})]})]})})}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:[ye.map(L=>{const F=c0(L.icon),te=L.interval_type||"hours";return i.jsx("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary",children:i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2.5 bg-bambu-dark rounded-lg",children:i.jsx(F,{className:"w-5 h-5 text-bambu-gray"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm font-medium text-white truncate",children:L.name}),i.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 flex items-center gap-1",children:[te==="days"?i.jsx(Wr,{className:"w-3 h-3"}):i.jsx(pd,{className:"w-3 h-3"}),$D(L.default_interval_hours,te,m)]})]}),i.jsx("button",{onClick:()=>{d("maintenance:delete")&&he(L)},disabled:!d("maintenance:delete"),title:d("maintenance:delete")?void 0:m("maintenance.noPermissionDeleteTypes"),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors ${d("maintenance:delete")?"":"opacity-50 cursor-not-allowed"}`,children:i.jsx(Jt,{className:"w-4 h-4"})})]})},L.id)}),ae.map(L=>{const F=c0(L.icon),te=L.interval_type||"hours";if(le?.id===L.id)return i.jsx("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green",children:i.jsxs("div",{className:"space-y-3",children:[i.jsx("input",{type:"text",value:Pe,onChange:Se=>q(Se.target.value),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",placeholder:m("common.name"),autoFocus:!0}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("select",{value:E,onChange:Se=>U(Se.target.value),className:"flex-1 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",children:[i.jsx("option",{value:"hours",children:m("maintenance.printHours")}),i.jsx("option",{value:"days",children:m("maintenance.calendarDays")})]}),i.jsx("input",{type:"number",value:Z,onChange:Se=>j(Se.target.value),className:"w-24 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",min:"1"})]}),i.jsx("div",{className:"flex flex-wrap gap-1",children:Object.keys(Iv).map(Se=>{const Le=Iv[Se];return i.jsx("button",{type:"button",onClick:()=>$(Se),className:`p-1.5 rounded transition-colors ${K===Se?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:i.jsx(Le,{className:"w-3.5 h-3.5"})},Se)})}),i.jsx("input",{type:"url",value:ne,onChange:Se=>O(Se.target.value),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",placeholder:m("maintenance.documentationLink")}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Oe,{size:"sm",onClick:J,disabled:!Pe.trim(),children:m("common.save")}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:()=>xe(null),children:m("common.cancel")})]})]})},L.id);const pe=Y(L.id),de=oe(L.id),Ne=ie===L.id;return i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2.5 bg-bambu-green/20 rounded-lg",children:i.jsx(F,{className:"w-5 h-5 text-bambu-green"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-sm font-medium text-white truncate",children:L.name}),i.jsx("span",{className:"px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded",children:m("maintenance.custom")})]}),i.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 flex items-center gap-1",children:[te==="days"?i.jsx(Wr,{className:"w-3 h-3"}):i.jsx(pd,{className:"w-3 h-3"}),$D(L.default_interval_hours,te,m)]})]}),i.jsxs("button",{onClick:()=>X(Ne?null:L.id),className:`px-2 py-1 rounded-lg border transition-colors flex items-center gap-1 ${pe.length>0?"border-bambu-green/50 bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20":"border-orange-400/50 bg-orange-400/10 text-orange-400 hover:bg-orange-400/20"}`,title:m("maintenance.printersAssignedClick",{count:pe.length}),children:[i.jsx(Sr,{className:"w-3 h-3"}),i.jsx("span",{className:"text-xs font-medium",children:pe.length}),i.jsx(Ln,{className:`w-3 h-3 transition-transform ${Ne?"rotate-180":""}`})]}),i.jsx("button",{onClick:()=>V(L),disabled:!d("maintenance:update"),title:d("maintenance:update")?void 0:m("maintenance.noPermissionEditTypes"),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors ${d("maintenance:update")?"":"opacity-50 cursor-not-allowed"}`,children:i.jsx(vf,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>{confirm(m("maintenance.deleteTypeConfirm",{name:L.name}))&&s(L.id)},disabled:!d("maintenance:delete"),title:d("maintenance:delete")?void 0:m("maintenance.noPermissionDeleteTypes"),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors ${d("maintenance:delete")?"":"opacity-50 cursor-not-allowed"}`,children:i.jsx(Jt,{className:"w-4 h-4"})})]}),Ne&&i.jsxs("div",{className:"mt-3 pt-3 border-t border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:m("maintenance.assignedToPrinters")}),pe.length===0?i.jsx("p",{className:"text-xs text-orange-400",children:m("maintenance.noPrintersAssigned")}):i.jsx("div",{className:"flex flex-wrap gap-1 mb-2",children:pe.map(Se=>i.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark rounded text-xs text-white",children:[Se.printerName,i.jsx("button",{onClick:()=>Se.itemId&&u(Se.itemId),disabled:!d("maintenance:delete"),title:d("maintenance:delete")?m("maintenance.removeFromPrinter"):m("maintenance.noPermissionRemovePrinter"),className:`ml-1 ${d("maintenance:delete")?"hover:text-red-400":"opacity-50 cursor-not-allowed"}`,children:"×"})]},Se.printerId))}),de.length>0&&i.jsxs("div",{className:"flex flex-wrap gap-1",children:[i.jsx("span",{className:"text-xs text-bambu-gray mr-1",children:m("maintenance.addPrinterShort")}),de.map(Se=>i.jsxs("button",{onClick:()=>c(Se.id,L.id),disabled:!d("maintenance:create"),title:d("maintenance:create")?void 0:m("maintenance.noPermissionAssignPrinter"),className:`px-2 py-1 bg-bambu-dark rounded text-xs transition-colors ${d("maintenance:create")?"hover:bg-bambu-green/20 text-bambu-gray hover:text-bambu-green":"opacity-50 cursor-not-allowed text-bambu-gray"}`,children:["+ ",Se.name]},Se.id))]})]})]},L.id)})]})]}),fe.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"mb-4",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:m("maintenance.intervalOverrides")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:m("maintenance.intervalOverridesDescription")})]}),i.jsx("div",{className:"space-y-4",children:fe.map(L=>i.jsx(Mt,{children:i.jsxs(Dt,{className:"py-4",children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:L.printerName}),i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2",children:L.items.map(F=>{const te=c0(F.maintenance_type_icon),ve=e.find(Le=>Le.id===F.maintenance_type_id),pe=ve?.default_interval_hours||F.interval_hours,de=ve?.interval_type||"hours",Ne=F.interval_type||"hours",Se=p===F.id;return i.jsxs("div",{className:"flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg",children:[i.jsx(te,{className:"w-4 h-4 text-bambu-gray shrink-0"}),i.jsx("span",{className:"text-xs text-bambu-gray flex-1 truncate",children:F.maintenance_type_name}),Se?i.jsxs("div",{className:"flex items-center gap-1",children:[x==="days"?i.jsx(Wr,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"}):i.jsx(pd,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"}),i.jsxs("select",{value:x,onChange:Le=>g(Le.target.value),className:"px-1.5 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs",children:[i.jsx("option",{value:"hours",children:m("maintenance.printHours")}),i.jsx("option",{value:"days",children:m("maintenance.calendarDays")})]}),i.jsx("input",{type:"number",value:y,onChange:Le=>v(Le.target.value),onKeyDown:Le=>{Le.key==="Enter"&&W(F.id,pe,de),Le.key==="Escape"&&f(null)},className:"w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs",min:"1"}),i.jsx(Oe,{size:"sm",onClick:()=>W(F.id,pe,de),children:"OK"})]}):i.jsxs("button",{onClick:()=>{d("maintenance:update")&&(f(F.id),v(F.interval_hours.toString()),g(Ne))},disabled:!d("maintenance:update"),title:d("maintenance:update")?void 0:m("maintenance.noPermissionEditIntervals"),className:`px-2 py-1 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs font-medium text-white transition-colors flex items-center gap-1 ${d("maintenance:update")?"hover:bg-bambu-dark-secondary hover:border-bambu-green":"opacity-50 cursor-not-allowed"}`,children:[Ne==="days"?i.jsx(Wr,{className:"w-3 h-3"}):i.jsx(pd,{className:"w-3 h-3"}),$D(F.interval_hours,Ne,m),i.jsx(vf,{className:"w-3 h-3 text-bambu-gray"})]})]},F.id)})})]})},L.printerId))})]}),fe.length===0&&i.jsx(Mt,{children:i.jsxs(Dt,{className:"text-center py-12",children:[i.jsx(er,{className:"w-12 h-12 mx-auto mb-4 text-bambu-gray/30"}),i.jsx("p",{className:"text-bambu-gray",children:m("common.noPrinters")}),i.jsx("p",{className:"text-sm text-bambu-gray/70 mt-1",children:m("maintenance.intervalOverridesDescription")})]})}),me&&i.jsx(Sn,{title:m("maintenance.deleteSystemTypeTitle"),message:m("maintenance.deleteSystemTypeMessage",{name:me.name}),confirmText:m("common.delete"),cancelText:m("common.cancel"),variant:"danger",cancelVariant:"primary",cardClassName:"bg-red-950/70 border border-red-800/70",onConfirm:()=>{s(me.id),he(null)},onCancel:()=>he(null)})]})}function att(){const{t}=Ft(),e=an(),{showToast:n}=fn(),{hasPermission:r}=_r(),[a,s]=w.useState("status"),{data:o,isLoading:l}=et({queryKey:["maintenanceOverview"],queryFn:be.getMaintenanceOverview}),{data:c}=et({queryKey:["maintenanceTypes"],queryFn:be.getMaintenanceTypes}),u=pt({mutationFn:({id:A,notes:k})=>be.performMaintenance(A,k),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),e.invalidateQueries({queryKey:["maintenanceSummary"]}),n(t("maintenance.maintenanceComplete"))},onError:A=>{n(A.message,"error")}}),d=pt({mutationFn:({id:A,data:k})=>be.updateMaintenanceItem(A,k),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]})},onError:A=>{n(A.message,"error")}}),m=pt({mutationFn:({id:A,data:k})=>be.updateMaintenanceType(A,k),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.typeUpdated"))},onError:A=>{n(A.message,"error")}}),p=pt({mutationFn:be.deleteMaintenanceType,onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.typeDeleted"))},onError:A=>{n(A.message,"error")}}),f=pt({mutationFn:be.restoreDefaultMaintenanceTypes,onSuccess:A=>{e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.defaultsRestored",{count:A.restored}))},onError:A=>{n(A.message,"error")}}),y=pt({mutationFn:({printerId:A,hours:k})=>be.setPrinterHours(A,k),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),e.invalidateQueries({queryKey:["maintenanceSummary"]}),n(t("maintenance.printHoursUpdated"))},onError:A=>{n(A.message,"error")}}),v=pt({mutationFn:({printerId:A,typeId:k})=>be.assignMaintenanceType(A,k),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.printerAssigned"))},onError:A=>{n(A.message,"error")}}),x=pt({mutationFn:be.removeMaintenanceItem,onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.printerRemoved"))},onError:A=>{n(A.message,"error")}}),g=A=>{u.mutate({id:A})},_=(A,k)=>{d.mutate({id:A,data:{enabled:k}})},N=(A,k)=>{y.mutate({printerId:A,hours:k})};if(l)return i.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})});const T=o?.reduce((A,k)=>A+k.due_count,0)||0,C=o?.reduce((A,k)=>A+k.warning_count,0)||0;return i.jsxs("div",{className:"p-4 md:p-8",children:[i.jsxs("div",{className:"mb-6",children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:t("maintenance.title")}),i.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:a==="status"?i.jsxs(i.Fragment,{children:[T>0&&i.jsx("span",{className:"text-red-400",children:t("maintenance.dueCount",{count:T})}),T>0&&C>0&&" · ",C>0&&i.jsx("span",{className:"text-amber-400",children:t("maintenance.warningCount",{count:C})}),T===0&&C===0&&i.jsx("span",{className:"text-bambu-green",children:t("maintenance.allOk")})]}):t("maintenance.configureSettings")})]}),i.jsxs("div",{className:"flex gap-1 mb-6 border-b border-bambu-dark-tertiary",children:[i.jsx("button",{onClick:()=>s("status"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${a==="status"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:t("maintenance.statusTab")}),i.jsx("button",{onClick:()=>s("settings"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${a==="settings"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:t("maintenance.settingsTab")})]}),a==="status"?i.jsx("div",{className:"space-y-6",children:o&&o.length>0?[...o].sort((A,k)=>{const R=A.due_count*10+A.warning_count,P=k.due_count*10+k.warning_count;return R!==P?P-R:A.printer_name.localeCompare(k.printer_name)}).map(A=>i.jsx(rtt,{overview:A,onPerform:g,onToggle:_,onSetHours:N,hasPermission:r,t},A.printer_id)):i.jsx(Mt,{children:i.jsxs(Dt,{className:"text-center py-16",children:[i.jsx(Sf,{className:"w-16 h-16 mx-auto mb-4 text-bambu-gray/30"}),i.jsx("p",{className:"text-lg font-medium text-white mb-2",children:t("common.noPrinters")}),i.jsx("p",{className:"text-bambu-gray",children:t("maintenance.configureSettings")})]})})}):i.jsx(itt,{overview:o,types:c||[],onUpdateInterval:(A,k)=>d.mutate({id:A,data:k}),onAddType:async(A,k)=>{const R=await be.createMaintenanceType(A);for(const P of k)await be.assignMaintenanceType(P,R.id);e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.typeUpdated"))},onUpdateType:(A,k)=>m.mutate({id:A,data:k}),onDeleteType:A=>p.mutate(A),onRestoreDefaults:()=>f.mutate(),isRestoringDefaults:f.isPending,onAssignType:(A,k)=>v.mutate({printerId:A,typeId:k}),onRemoveItem:A=>x.mutate(A),hasPermission:r,t})]})}const PY=["#ef4444","#f97316","#eab308","#22c55e","#06b6d4","#3b82f6","#8b5cf6","#ec4899","#6b7280"];function Hoe({project:t,onClose:e,onSave:n,isLoading:r,t:a}){const[s,o]=w.useState(t?.name||""),[l,c]=w.useState(t?.description||""),[u,d]=w.useState(t?.color||PY[0]),[m,p]=w.useState(t?.target_count?.toString()||""),[f,y]=w.useState(t?.target_parts_count?.toString()||""),[v,x]=w.useState(t?.status||"active"),[g,_]=w.useState(t?.tags||""),[N,T]=w.useState(t?.due_date?.split("T")[0]||""),[C,A]=w.useState(t?.priority||"normal"),k=R=>{R.preventDefault(),n({name:s.trim(),description:l.trim()||void 0,color:u,target_count:m?parseInt(m,10):void 0,target_parts_count:f?parseInt(f,10):void 0,tags:g.trim()||void 0,due_date:N||void 0,priority:C,...t&&{status:v}})};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary",children:[i.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a(t?"projects.editProject":"projects.newProject")})}),i.jsxs("form",{onSubmit:k,className:"p-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("common.name")}),i.jsx("input",{type:"text",value:s,onChange:R=>o(R.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:a("projects.namePlaceholder"),required:!0})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("common.description")}),i.jsx("textarea",{value:l,onChange:R=>c(R.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green resize-none",placeholder:a("projects.descriptionPlaceholder"),rows:2})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("projects.color")}),i.jsx("div",{className:"flex gap-2 flex-wrap",children:PY.map(R=>i.jsx("button",{type:"button",onClick:()=>d(R),className:`w-8 h-8 rounded-full transition-transform ${u===R?"ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110":""}`,style:{backgroundColor:R}},R))})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("projects.targetPlates")}),i.jsx("input",{type:"number",value:m,onChange:R=>p(R.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:a("projects.targetPlatesPlaceholder"),min:"1"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("projects.targetPlatesHelp")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("projects.targetParts")}),i.jsx("input",{type:"number",value:f,onChange:R=>y(R.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:a("projects.targetPartsPlaceholder"),min:"1"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("projects.targetPartsHelp")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("projects.tagsLabel")}),i.jsx("input",{type:"text",value:g,onChange:R=>_(R.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:a("projects.tagsPlaceholder")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("projects.dueDate")}),i.jsx("input",{type:"date",value:N,onChange:R=>T(R.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("projects.priority")}),i.jsxs("select",{value:C,onChange:R=>A(R.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green",children:[i.jsx("option",{value:"low",children:a("projects.priorityLow")}),i.jsx("option",{value:"normal",children:a("projects.priorityNormal")}),i.jsx("option",{value:"high",children:a("projects.priorityHigh")}),i.jsx("option",{value:"urgent",children:a("projects.priorityUrgent")})]})]})]}),t&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("common.status")}),i.jsxs("select",{value:v,onChange:R=>x(R.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green",children:[i.jsx("option",{value:"active",children:a("projects.statusActive")}),i.jsx("option",{value:"completed",children:a("projects.statusCompleted")}),i.jsx("option",{value:"archived",children:a("projects.statusArchived")})]})]}),i.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,children:a("common.cancel")}),i.jsx(Oe,{type:"submit",disabled:!s.trim()||r,children:r?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):a(t?"common.save":"projects.create")})]})]})]})})}function stt({project:t,onClick:e,onEdit:n,onDelete:r,hasPermission:a,t:s}){const o=t.target_count?Math.round(t.archive_count/t.target_count*100):0,l=t.target_parts_count?Math.round(t.completed_count/t.target_parts_count*100):0,c=t.status==="completed",u=t.status==="archived",[d,m]=w.useState(!1),f=c?{icon:Jc,color:"text-bambu-green",bg:"bg-bambu-green/10"}:u?{icon:zs,color:"text-bambu-gray",bg:"bg-bambu-gray/10"}:t.queue_count>0?{icon:er,color:"text-blue-400",bg:"bg-blue-400/10"}:{icon:fs,color:"text-bambu-gray",bg:"bg-bambu-gray/10"};return i.jsxs("div",{className:"group relative bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary hover:border-bambu-green/50 hover:shadow-lg hover:shadow-bambu-green/5 transition-all duration-300 cursor-pointer overflow-hidden",onClick:e,children:[i.jsx("div",{className:"absolute top-0 left-0 w-1.5 h-full",style:{backgroundColor:t.color||"#6b7280",boxShadow:`0 0 12px ${t.color||"#6b7280"}40`}}),i.jsxs("div",{className:"p-5 pl-6",children:[i.jsxs("div",{className:"flex items-start justify-between mb-4",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[i.jsx("div",{className:`p-2 rounded-lg ${f.bg} flex-shrink-0`,children:i.jsx(f.icon,{className:`w-5 h-5 ${f.color}`})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[i.jsx("h3",{className:"font-semibold text-white truncate",children:t.name}),t.target_parts_count?i.jsxs("span",{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${l>=100?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray"}`,children:[t.completed_count,"/",t.target_parts_count," ",s("projects.parts")]}):t.target_count?i.jsxs("span",{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${o>=100?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray"}`,children:[t.archive_count,"/",t.target_count," ",s("projects.plates")]}):t.completed_count>0?i.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium bg-bambu-dark text-bambu-gray",children:[t.completed_count," ",s("projects.parts")]}):null,c&&i.jsx("span",{className:"text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full whitespace-nowrap",children:s("projects.done")}),u&&i.jsx("span",{className:"text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap",children:s("projects.statusArchived")})]}),t.description&&i.jsx("p",{className:"text-sm text-bambu-gray/70 mt-1 line-clamp-1",children:t.description}),t.archives&&t.archives.length>0&&(()=>{const y=t.archives.map(_=>_.filament_type).filter(Boolean).flatMap(_=>_.split(",").map(N=>N.trim())).filter(Boolean),v=[...new Set(y)],x=t.archives.map(_=>_.filament_color).filter(Boolean).flatMap(_=>_.split(",").map(N=>N.trim())).filter(_=>_.startsWith("#")||/^[0-9A-Fa-f]{6}$/.test(_)),g=[...new Set(x)];return v.length===0&&g.length===0?null:i.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[v.slice(0,3).map(_=>i.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-bambu-dark text-bambu-gray rounded",children:_},_)),g.length>0&&i.jsxs("div",{className:"flex items-center gap-0.5",children:[g.slice(0,5).map(_=>i.jsx("div",{className:"w-3 h-3 rounded-full border border-white/20",style:{backgroundColor:_.startsWith("#")?_:`#${_}`},title:_},_)),g.length>5&&i.jsxs("span",{className:"text-[10px] text-bambu-gray ml-0.5",children:["+",g.length-5]})]})]})})()]})]}),i.jsxs("div",{className:"relative",onClick:y=>y.stopPropagation(),children:[i.jsx("button",{className:"p-1.5 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors opacity-0 group-hover:opacity-100",onClick:()=>m(!d),children:i.jsx(ph,{className:"w-4 h-4"})}),d&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>m(!1)}),i.jsxs("div",{className:"absolute right-0 top-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]",children:[i.jsxs("button",{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${a("projects:update")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{a("projects:update")&&(n(),m(!1))},disabled:!a("projects:update"),title:a("projects:update")?void 0:s("projects.noEditPermission"),children:[i.jsx(vf,{className:"w-4 h-4"}),s("common.edit")]}),i.jsxs("button",{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${a("projects:delete")?"text-red-400 hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{a("projects:delete")&&(r(),m(!1))},disabled:!a("projects:delete"),title:a("projects:delete")?void 0:s("projects.noDeletePermission"),children:[i.jsx(Jt,{className:"w-4 h-4"}),s("common.delete")]})]})]})]})]}),i.jsx("div",{className:"mb-4",children:t.target_count||t.target_parts_count?i.jsxs("div",{className:"space-y-3",children:[t.target_count&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[i.jsx("span",{className:"text-bambu-gray",children:s("projects.plates")}),i.jsxs("span",{className:o>=100?"text-bambu-green font-medium":"text-white",children:[t.archive_count," / ",t.target_count]})]}),i.jsx("div",{className:"h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm",children:i.jsx("div",{className:"h-full transition-all duration-500 ease-out rounded-full relative",style:{width:`${Math.min(o,100)}%`,background:o>=100?"linear-gradient(90deg, #22c55e, #4ade80)":`linear-gradient(90deg, ${t.color||"#6b7280"}, ${t.color||"#6b7280"}cc)`,boxShadow:`0 0 8px ${o>=100?"#22c55e":t.color||"#6b7280"}60`}})})]}),t.target_parts_count&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[i.jsx("span",{className:"text-bambu-gray",children:s("projects.parts")}),i.jsxs("span",{className:l>=100?"text-bambu-green font-medium":"text-white",children:[t.completed_count," / ",t.target_parts_count]})]}),i.jsx("div",{className:"h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm",children:i.jsx("div",{className:"h-full transition-all duration-500 ease-out rounded-full relative",style:{width:`${Math.min(l,100)}%`,background:l>=100?"linear-gradient(90deg, #22c55e, #4ade80)":`linear-gradient(90deg, ${t.color||"#6b7280"}, ${t.color||"#6b7280"}cc)`,boxShadow:`0 0 8px ${l>=100?"#22c55e":t.color||"#6b7280"}60`}})})]}),t.failed_count>0&&i.jsxs("div",{className:"text-xs text-red-400",children:[t.failed_count," ",s("projects.failed")]})]}):t.completed_count>0||t.failed_count>0?i.jsxs("div",{className:"flex items-center gap-4 text-xs",children:[t.completed_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",children:[i.jsx(zs,{className:"w-3.5 h-3.5"}),i.jsxs("span",{children:[t.completed_count," ",s("projects.completed")]})]}),t.failed_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-red-400",children:[i.jsx(Mn,{className:"w-3.5 h-3.5"}),i.jsxs("span",{children:[t.failed_count," ",s("projects.failed")]})]}),t.queue_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-blue-400",children:[i.jsx(er,{className:"w-3.5 h-3.5"}),i.jsxs("span",{children:[t.queue_count," ",s("projects.inQueue")]})]})]}):i.jsx("div",{className:"text-xs text-bambu-gray/60 italic",children:s("projects.noPrintsYet")})}),t.archives&&t.archives.length>0&&i.jsxs("div",{className:"mb-4",children:[i.jsx("div",{className:"grid grid-cols-4 gap-1.5",children:t.archives.slice(0,4).map(y=>i.jsxs("div",{className:"relative aspect-square rounded-lg bg-bambu-dark overflow-hidden border border-bambu-dark-tertiary",title:y.print_name||"Unknown",children:[y.thumbnail_path?i.jsx("img",{src:be.getArchiveThumbnail(y.id),alt:y.print_name||"",className:"w-full h-full object-cover"}):i.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray/50",children:i.jsx(Wi,{className:"w-6 h-6"})}),y.status==="failed"&&i.jsx("div",{className:"absolute inset-0 bg-red-500/40 flex items-center justify-center",children:i.jsx(Mn,{className:"w-4 h-4 text-white"})})]},y.id))}),t.archive_count>4&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1.5 text-center",children:s("common.more",{count:t.archive_count-4})})]}),i.jsxs("div",{className:"flex items-center justify-between pt-3 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-4 text-xs text-bambu-gray",children:[i.jsxs("div",{className:"flex items-center gap-1.5",title:s("projects.printJobs"),children:[i.jsx(Gi,{className:"w-3.5 h-3.5 text-blue-400"}),i.jsxs("span",{children:[t.archive_count," ",s("projects.plates")]})]}),i.jsxs("div",{className:"flex items-center gap-1.5",title:s("projects.partsPrinted"),children:[i.jsx(Wi,{className:"w-3.5 h-3.5 text-bambu-green"}),i.jsxs("span",{children:[t.completed_count," ",s("projects.parts")]})]}),t.failed_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-red-400",title:s("projects.failedParts"),children:[i.jsx(Mn,{className:"w-3.5 h-3.5"}),i.jsx("span",{children:t.failed_count})]}),t.queue_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-yellow-400",title:s("projects.inQueue"),children:[i.jsx(b3,{className:"w-3.5 h-3.5"}),i.jsx("span",{children:t.queue_count})]})]}),i.jsx(ha,{className:"w-4 h-4 text-bambu-gray/50 group-hover:text-bambu-gray transition-colors"})]})]})]})}function ott(){const{t}=Ft(),e=Qo(),n=an(),{showToast:r}=fn(),{hasPermission:a}=_r(),[s,o]=w.useState(!1),[l,c]=w.useState(),[u,d]=w.useState("active"),[m,p]=w.useState(null),{data:f,isLoading:y}=et({queryKey:["projects",u==="all"?void 0:u],queryFn:()=>be.getProjects(u==="all"?void 0:u)}),v=pt({mutationFn:G=>be.createProject(G),onSuccess:()=>{n.invalidateQueries({queryKey:["projects"]}),o(!1),r(t("projects.toast.created"),"success")},onError:G=>{r(G.message,"error")}}),x=pt({mutationFn:({id:G,data:I})=>be.updateProject(G,I),onSuccess:()=>{n.invalidateQueries({queryKey:["projects"]}),o(!1),c(void 0),r(t("projects.toast.updated"),"success")},onError:G=>{r(G.message,"error")}}),g=pt({mutationFn:G=>be.deleteProject(G),onSuccess:()=>{p(null),r(t("projects.toast.deleted"),"success"),setTimeout(()=>window.location.reload(),100)},onError:G=>{p(null),r(G.message,"error")}}),_=pt({mutationFn:G=>be.importProject(G),onSuccess:()=>{n.invalidateQueries({queryKey:["projects"]}),r(t("projects.toast.imported"),"success")},onError:G=>{r(G.message,"error")}}),N=w.useRef(null),T=async()=>{try{const G=await be.getProjects(),I=await Promise.all(G.map(async me=>await be.exportProjectJson(me.id))),ee=new Blob([JSON.stringify(I,null,2)],{type:"application/json"}),ie=URL.createObjectURL(ee),X=document.createElement("a");X.href=ie,X.download=`bambuddy_projects_${new Date().toISOString().split("T")[0]}.json`,X.click(),URL.revokeObjectURL(ie),r(t("projects.toast.exported"),"success")}catch(G){r(G.message,"error")}},C=()=>{N.current?.click()},A=async G=>{const I=G.target.files?.[0];if(I){try{if(I.name.toLowerCase().endsWith(".zip"))await be.importProjectFile(I),n.invalidateQueries({queryKey:["projects"]}),r(t("projects.toast.imported"),"success");else{const ie=await I.text(),X=JSON.parse(ie),me=Array.isArray(X)?X:[X];for(const he of me)await _.mutateAsync(he);me.length>1&&r(t("projects.toast.multipleImported",{count:me.length}),"success")}}catch(ee){r(`${t("projects.toast.importFailed")}: ${ee.message}`,"error")}G.target.value=""}},k=G=>{l?x.mutate({id:l.id,data:G}):v.mutate(G)},R=G=>{c(G),o(!0)},P=G=>{e(`/projects/${G.id}`)},D=G=>{p(G)},H=()=>{m!==null&&g.mutate(m)},z=f?.reduce((G,I)=>(G[I.status]=(G[I.status]||0)+1,G.all=(G.all||0)+1,G),{})||{};return i.jsxs("div",{className:"p-4 md:p-8 space-y-8",children:[i.jsx("input",{ref:N,type:"file",accept:".json,.zip",onChange:A,className:"hidden"}),i.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[i.jsxs("div",{children:[i.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[i.jsx("div",{className:"p-2.5 bg-bambu-green/10 rounded-xl",children:i.jsx(fs,{className:"w-6 h-6 text-bambu-green"})}),t("projects.title")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-2 ml-14",children:t("projects.subtitle")})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Oe,{variant:"secondary",onClick:C,disabled:!a("projects:create"),title:a("projects:create")?t("projects.importProject"):t("projects.noImportPermission"),children:[i.jsx(xi,{className:"w-4 h-4 mr-2"}),t("projects.import")]}),i.jsxs(Oe,{variant:"secondary",onClick:T,disabled:!a("projects:read"),title:a("projects:read")?t("projects.exportAll"):t("projects.noExportPermission"),children:[i.jsx(pi,{className:"w-4 h-4 mr-2"}),t("projects.export")]}),i.jsxs(Oe,{onClick:()=>o(!0),className:"sm:w-auto w-full",disabled:!a("projects:create"),title:a("projects:create")?void 0:t("projects.noCreatePermission"),children:[i.jsx(ar,{className:"w-4 h-4 mr-2"}),t("projects.newProject")]})]})]}),i.jsx("div",{className:"flex gap-1 p-1 bg-bambu-dark rounded-xl w-fit",children:[{key:"active",label:t("projects.statusActive"),icon:er},{key:"completed",label:t("projects.statusCompleted"),icon:Jc},{key:"archived",label:t("projects.statusArchived"),icon:zs},{key:"all",label:t("common.all"),icon:fs}].map(({key:G,label:I,icon:ee})=>i.jsxs("button",{onClick:()=>d(G),className:`flex items-center gap-2 px-4 py-2 text-sm rounded-lg transition-all ${u===G?"bg-bambu-card text-white shadow-sm":"text-bambu-gray hover:text-white"}`,children:[i.jsx(ee,{className:"w-4 h-4"}),i.jsx("span",{children:I}),z[G]>0&&i.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded-full ${u===G?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary"}`,children:z[G]})]},G))}),y?i.jsx("div",{className:"flex items-center justify-center py-20",children:i.jsxs("div",{className:"flex flex-col items-center gap-3",children:[i.jsx(ht,{className:"w-8 h-8 animate-spin text-bambu-green"}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t("projects.loading")})]})}):f?.length===0?i.jsxs("div",{className:"flex flex-col items-center justify-center py-20 px-4",children:[i.jsx("div",{className:"p-4 bg-bambu-dark rounded-2xl mb-4",children:i.jsx(fs,{className:"w-12 h-12 text-bambu-gray/50"})}),i.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:u==="all"?t("projects.noProjects"):t("projects.noProjectsFiltered",{status:u})}),i.jsx("p",{className:"text-bambu-gray text-center max-w-md mb-6",children:u==="all"?t("projects.createFirst"):t("projects.noProjectsFilteredHelp",{status:u})}),u==="all"&&i.jsxs(Oe,{onClick:()=>o(!0),disabled:!a("projects:create"),title:a("projects:create")?void 0:t("projects.noCreatePermission"),children:[i.jsx(ar,{className:"w-4 h-4 mr-2"}),t("projects.createFirstButton")]})]}):i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-8",children:f?.map(G=>i.jsx(stt,{project:G,onClick:()=>P(G),onEdit:()=>R(G),onDelete:()=>D(G.id),hasPermission:a,t},G.id))}),m!==null&&i.jsx(Sn,{title:t("projects.deleteProject"),message:t("projects.deleteConfirm"),confirmText:t("projects.deleteProject"),variant:"danger",onConfirm:H,onCancel:()=>p(null)}),s&&i.jsx(Hoe,{project:l,onClose:()=>{o(!1),c(void 0)},onSave:k,isLoading:v.isPending||x.isPending,t})]})}function ltt(t){return t>=1e3?`${(t/1e3).toFixed(2)}kg`:`${Math.round(t)}g`}function ctt({status:t,t:e}){const n={active:"bg-bambu-green/20 text-bambu-green",completed:"bg-blue-500/20 text-blue-400",archived:"bg-bambu-gray/20 text-bambu-gray"},r=n[t]||n.active,a={active:e("projectDetail.status.active"),completed:e("projectDetail.status.completed"),archived:e("projectDetail.status.archived")};return i.jsx("span",{className:`px-2 py-1 rounded text-sm font-medium ${r}`,children:a[t]||t.charAt(0).toUpperCase()+t.slice(1)})}function MY({icon:t,label:e,value:n,subValue:r,hint:a,color:s="text-bambu-gray"}){return i.jsx(Mt,{children:i.jsx(Dt,{className:"p-4",children:i.jsxs("div",{className:"flex items-center gap-3",title:a,children:[i.jsx("div",{className:`p-2 rounded-lg bg-bambu-dark ${s}`,children:i.jsx(t,{className:"w-5 h-5"})}),i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:e}),i.jsx("p",{className:"text-xl font-semibold text-white",children:n}),r&&i.jsx("p",{className:"text-xs text-bambu-gray/70",children:r})]})]})})})}function utt({archives:t,t:e}){return t.length===0?i.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[i.jsx(Wi,{className:"w-12 h-12 mx-auto mb-2 opacity-50"}),i.jsx("p",{children:e("projectDetail.noPrints")})]}):i.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3",children:t.map(n=>i.jsxs(io,{to:`/archives?search=${encodeURIComponent(n.print_name||"")}`,className:"group relative aspect-square rounded-lg bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden hover:border-bambu-green transition-colors",children:[n.thumbnail_path?i.jsx("img",{src:be.getArchiveThumbnail(n.id),alt:n.print_name||"Print",className:"w-full h-full object-cover"}):i.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:i.jsx(Wi,{className:"w-8 h-8"})}),n.status==="failed"&&i.jsx("div",{className:"absolute inset-0 bg-red-500/30 flex items-center justify-center",children:i.jsx(Vi,{className:"w-8 h-8 text-white"})}),n.status==="completed"&&i.jsx("div",{className:"absolute top-1 right-1",children:i.jsx(fr,{className:"w-4 h-4 text-bambu-green"})}),i.jsx("div",{className:"absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity",children:i.jsx("p",{className:"text-xs text-white truncate",children:n.print_name||"Unknown"})})]},n.id))})}function dtt({priority:t,t:e}){const n={low:{color:"bg-gray-500/20 text-gray-400",label:e("projectDetail.priority.low")},normal:{color:"bg-blue-500/20 text-blue-400",label:e("projectDetail.priority.normal")},high:{color:"bg-orange-500/20 text-orange-400",label:e("projectDetail.priority.high")},urgent:{color:"bg-red-500/20 text-red-400",label:e("projectDetail.priority.urgent")}},{color:r,label:a}=n[t]||n.normal;return i.jsxs("span",{className:`px-2 py-1 rounded text-xs font-medium flex items-center gap-1 ${r}`,children:[t==="urgent"&&i.jsx(Mn,{className:"w-3 h-3"}),a]})}function qD(t,e){if(!t)return null;const n=Jn(t);if(!n)return null;const r=new Date,a=Math.ceil((n.getTime()-r.getTime())/(1e3*60*60*24));return a<0?{color:"text-red-400",label:e("projectDetail.dueDate.overdue")}:a===0?{color:"text-orange-400",label:e("projectDetail.dueDate.today")}:a<=3?{color:"text-yellow-400",label:e("projectDetail.dueDate.daysLeft",{count:a})}:{color:"text-bambu-gray",label:e("projectDetail.dueDate.daysLeft",{count:a})}}function mtt(){const{id:t}=uw(),e=Qo(),{t:n}=Ft(),r=an(),{showToast:a}=fn(),{hasPermission:s}=_r(),[o,l]=w.useState(!1),[c,u]=w.useState(!1),[d,m]=w.useState(""),p=parseInt(t||"0",10),{data:f,isLoading:y,error:v}=et({queryKey:["project",p],queryFn:()=>be.getProject(p),enabled:p>0}),{data:x,isLoading:g}=et({queryKey:["project-archives",p],queryFn:()=>be.getProjectArchives(p),enabled:p>0}),{data:_,isLoading:N}=et({queryKey:["project-bom",p],queryFn:()=>be.getProjectBOM(p),enabled:p>0}),{data:T,isLoading:C}=et({queryKey:["project-timeline",p],queryFn:()=>be.getProjectTimeline(p,20),enabled:p>0}),{data:A}=et({queryKey:["settings"],queryFn:be.getSettings}),{data:k}=et({queryKey:["project-folders",p],queryFn:()=>be.getLibraryFoldersByProject(p),enabled:p>0}),R=_l(A?.currency||"USD"),P=A?.time_format||"system",D=pt({mutationFn:je=>be.updateProject(p,je),onSuccess:()=>{r.invalidateQueries({queryKey:["project",p]}),r.invalidateQueries({queryKey:["projects"]}),l(!1),u(!1),a(n("projectDetail.toast.projectUpdated"),"success")},onError:je=>{a(je.message,"error")}}),H=()=>{m(f?.notes||""),u(!0)},z=()=>{D.mutate({notes:d})},G=()=>{u(!1),m("")},[I,ee]=w.useState(""),[ie,X]=w.useState(1),[me,he]=w.useState(""),[ge,Y]=w.useState(""),[oe,le]=w.useState(""),[xe,Pe]=w.useState(!1),[q,Z]=w.useState(!1),[j,E]=w.useState(null),[U,K]=w.useState(""),[$,ne]=w.useState(1),[O,V]=w.useState(""),[J,W]=w.useState(""),[re,ue]=w.useState(""),[fe,ye]=w.useState({isOpen:!1,title:"",message:"",onConfirm:()=>{}}),ae=pt({mutationFn:je=>be.createBOMItem(p,je),onSuccess:()=>{r.invalidateQueries({queryKey:["project-bom",p]}),r.invalidateQueries({queryKey:["project",p]}),ee(""),X(1),he(""),Y(""),le(""),Pe(!1),a(n("projectDetail.toast.partAdded"),"success")},onError:je=>a(je.message,"error")}),L=pt({mutationFn:({itemId:je,data:Xe})=>be.updateBOMItem(p,je,Xe),onSuccess:()=>{r.invalidateQueries({queryKey:["project-bom",p]}),r.invalidateQueries({queryKey:["project",p]}),E(null)},onError:je=>a(je.message,"error")}),F=pt({mutationFn:je=>be.deleteBOMItem(p,je),onSuccess:()=>{r.invalidateQueries({queryKey:["project-bom",p]}),r.invalidateQueries({queryKey:["project",p]}),a(n("projectDetail.toast.partRemoved"),"success")},onError:je=>a(je.message,"error")}),te=je=>{je.preventDefault(),I.trim()&&ae.mutate({name:I.trim(),quantity_needed:ie,unit_price:me?parseFloat(me):void 0,sourcing_url:ge.trim()||void 0,remarks:oe.trim()||void 0})},ve=je=>{const Xe=je.is_complete?0:je.quantity_needed;L.mutate({itemId:je.id,data:{quantity_acquired:Xe}})},pe=(je,Xe)=>{ye({isOpen:!0,title:n("projectDetail.bom.deletePart"),message:n("projectDetail.bom.deleteConfirm",{name:Xe}),onConfirm:()=>{ye(ce=>({...ce,isOpen:!1})),F.mutate(je)}})},de=je=>{E(je),K(je.name),ne(je.quantity_needed),V(je.unit_price?.toString()||""),W(je.sourcing_url||""),ue(je.remarks||"")},Ne=je=>{je.preventDefault(),!(!j||!U.trim())&&L.mutate({itemId:j.id,data:{name:U.trim(),quantity_needed:$,unit_price:O?parseFloat(O):void 0,sourcing_url:J.trim()||void 0,remarks:re.trim()||void 0}})},Se=()=>{E(null)},Le=async()=>{try{const{blob:je,filename:Xe}=await be.exportProjectZip(Number(p)),ce=URL.createObjectURL(je),Ie=document.createElement("a");Ie.href=ce,Ie.download=Xe||`${f?.name||"project"}_${new Date().toISOString().split("T")[0]}.zip`,Ie.click(),URL.revokeObjectURL(ce),a(n("projectDetail.toast.projectExported"),"success")}catch(je){a(je.message,"error")}},qe=pt({mutationFn:()=>be.createTemplateFromProject(p),onSuccess:()=>{r.invalidateQueries({queryKey:["projects"]}),a(n("projectDetail.toast.templateCreated"),"success")},onError:je=>a(je.message,"error")}),Ee=je=>Nf(je,P,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"});if(y)return i.jsx("div",{className:"flex items-center justify-center py-24",children:i.jsx(ht,{className:"w-8 h-8 animate-spin text-bambu-green"})});if(v||!f)return i.jsxs("div",{className:"text-center py-24",children:[i.jsx("p",{className:"text-bambu-gray",children:v?`${n("common.error")}: ${v.message}`:n("projectDetail.notFound")}),i.jsx(Oe,{variant:"secondary",className:"mt-4",onClick:()=>e("/projects"),children:n("projectDetail.backToProjects")})]});const Te=f.stats,Ae=Te?.progress_percent??0,Be=Te?.parts_progress_percent??0;return i.jsxs("div",{className:"p-4 md:p-8 space-y-8",children:[i.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[i.jsx(io,{to:"/projects",className:"hover:text-white transition-colors",children:n("navigation.projects")}),i.jsx(ha,{className:"w-4 h-4"}),i.jsx("span",{className:"text-white",children:f.name})]}),i.jsxs("div",{className:"flex items-start justify-between",children:[i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx("button",{onClick:()=>e("/projects"),className:"p-2 rounded-lg bg-bambu-card hover:bg-bambu-dark-tertiary transition-colors",children:i.jsx(IX,{className:"w-5 h-5 text-bambu-gray"})}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"w-4 h-4 rounded-full flex-shrink-0",style:{backgroundColor:f.color||"#6b7280"}}),i.jsxs("div",{children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:f.name}),f.description&&i.jsx("p",{className:"text-bambu-gray mt-1",children:f.description})]})]}),i.jsx(ctt,{status:f.status,t:n})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Oe,{variant:"secondary",onClick:Le,disabled:!s("projects:read"),title:s("projects:read")?n("projectDetail.exportProject"):n("projectDetail.noExportPermission"),children:[i.jsx(pi,{className:"w-4 h-4 mr-2"}),n("projectDetail.export")]}),i.jsxs(Oe,{onClick:()=>l(!0),disabled:!s("projects:update"),title:s("projects:update")?void 0:n("projectDetail.noEditPermission"),children:[i.jsx(vf,{className:"w-4 h-4 mr-2"}),n("common.edit")]})]})]}),(f.target_count||f.target_parts_count)&&i.jsx(Mt,{children:i.jsxs(Dt,{className:"p-4 space-y-4",children:[f.target_count&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:n("projectDetail.progress.platesProgress")}),i.jsxs("span",{className:"text-sm font-medium text-white",children:[Te?.total_archives||0," / ",f.target_count," ",n("projectDetail.progress.printJobs")]})]}),i.jsx("div",{className:"h-3 bg-bambu-dark rounded-full overflow-hidden",children:i.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${Math.min(Ae,100)}%`,backgroundColor:Ae>=100?"#22c55e":f.color||"#6b7280"}})}),i.jsxs("div",{className:"flex justify-between mt-1",children:[i.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.percentComplete",{percent:Ae.toFixed(0)})}),Te?.remaining_prints!=null&&Te.remaining_prints>0&&i.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.remaining",{count:Te.remaining_prints})})]})]}),f.target_parts_count&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:n("projectDetail.progress.partsProgress")}),i.jsxs("span",{className:"text-sm font-medium text-white",children:[Te?.completed_prints||0," / ",f.target_parts_count," ",n("projectDetail.progress.parts")]})]}),i.jsx("div",{className:"h-3 bg-bambu-dark rounded-full overflow-hidden",children:i.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${Math.min(Be,100)}%`,backgroundColor:Be>=100?"#22c55e":f.color||"#6b7280"}})}),i.jsxs("div",{className:"flex justify-between mt-1",children:[i.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.percentComplete",{percent:Be.toFixed(0)})}),Te?.remaining_parts!=null&&Te.remaining_parts>0&&i.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.remaining",{count:Te.remaining_parts})})]})]})]})}),Te&&i.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[i.jsx(Mt,{children:i.jsx(Dt,{className:"p-4",children:i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:i.jsx(Wi,{className:"w-5 h-5"})}),i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:n("projectDetail.stats.printJobs")}),i.jsxs("p",{className:"text-xl font-semibold text-white",children:[Te.total_archives," ",i.jsx("span",{className:"text-sm font-normal text-bambu-gray",children:n("projectDetail.stats.total")})]}),Te.failed_prints>0&&i.jsx("p",{className:"text-sm text-status-error",children:n("projectDetail.stats.failed",{count:Te.failed_prints})}),i.jsx("p",{className:"text-sm text-bambu-gray",children:n("projectDetail.stats.partsPrinted",{count:Te.completed_prints})})]})]})})}),i.jsx(MY,{icon:er,label:n("projectDetail.stats.printTime"),value:rxe(Te.total_print_time_hours),color:"text-yellow-400"}),i.jsx(MY,{icon:Sr,label:n("projectDetail.stats.filamentUsed"),value:ltt(Te.total_filament_grams),color:"text-purple-400"})]}),Te&&(Te.estimated_cost>0||f.budget)&&i.jsx(Mt,{children:i.jsxs(Dt,{className:"p-4",children:[i.jsx("h2",{className:"text-lg font-semibold text-white mb-3",children:n("projectDetail.cost.title")}),i.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.filamentCost")}),i.jsxs("p",{className:"text-lg font-semibold text-white",children:[R,Te.estimated_cost.toFixed(2)]})]}),Te.total_energy_kwh>0&&i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.energy")}),i.jsxs("p",{className:"text-lg font-semibold text-white",children:[Te.total_energy_kwh.toFixed(3)," kWh",Te.total_energy_cost>0&&i.jsxs("span",{className:"text-sm text-bambu-gray ml-1",children:["(",R,Te.total_energy_cost.toFixed(2),")"]})]})]}),f.budget&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.budget")}),i.jsxs("p",{className:"text-lg font-semibold text-white",children:[R,f.budget.toFixed(2)]})]}),i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.remaining")}),i.jsxs("p",{className:`text-lg font-semibold ${f.budget-Te.estimated_cost>=0?"text-bambu-green":"text-red-400"}`,children:[R,(f.budget-Te.estimated_cost).toFixed(2)]})]})]})]})]})}),f.children&&f.children.length>0&&i.jsx(Mt,{children:i.jsxs(Dt,{className:"p-4",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-3",children:[i.jsx(Zpe,{className:"w-5 h-5"}),n("projectDetail.subProjects.title",{count:f.children.length})]}),i.jsx("div",{className:"space-y-2",children:f.children.map(je=>i.jsxs(io,{to:`/projects/${je.id}`,className:"flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:je.color||"#6b7280"}}),i.jsx("span",{className:"text-white",children:je.name}),i.jsx("span",{className:`text-xs px-2 py-0.5 rounded ${je.status==="completed"?"bg-status-ok/20 text-status-ok":je.status==="archived"?"bg-bambu-gray/20 text-bambu-gray":"bg-blue-500/20 text-blue-400"}`,children:je.status})]}),je.progress_percent!==null&&i.jsxs("span",{className:"text-sm text-bambu-gray",children:[je.progress_percent.toFixed(0),"%"]})]},je.id))})]})}),f.parent_id&&f.parent_name&&i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx(Gi,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"text-bambu-gray",children:n("projectDetail.partOf")}),i.jsx(io,{to:`/projects/${f.parent_id}`,className:"text-bambu-green hover:underline",children:f.parent_name})]}),(f.tags||f.due_date||f.priority!=="normal")&&i.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[f.priority&&f.priority!=="normal"&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.priorityLabel")}),i.jsx(dtt,{priority:f.priority,t:n})]}),f.due_date&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Wr,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"text-sm text-white",children:_f(f.due_date,{year:"numeric",month:"short",day:"numeric"})}),qD(f.due_date,n)&&i.jsxs("span",{className:`text-xs ${qD(f.due_date,n).color}`,children:["(",qD(f.due_date,n).label,")"]})]}),f.tags&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Dd,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("div",{className:"flex flex-wrap gap-1",children:f.tags.split(",").map((je,Xe)=>i.jsx("span",{className:"px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded",children:je.trim()},Xe))})]})]}),i.jsx(Mt,{children:i.jsxs(Dt,{className:"p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Fs,{className:"w-5 h-5"}),n("projectDetail.notes.title")]}),c?i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:G,disabled:D.isPending,children:[i.jsx(Ht,{className:"w-4 h-4 mr-1"}),n("common.cancel")]}),i.jsxs(Oe,{size:"sm",onClick:z,disabled:D.isPending,children:[D.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin mr-1"}):i.jsx(ts,{className:"w-4 h-4 mr-1"}),n("common.save")]})]}):i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:H,disabled:!s("projects:update"),title:s("projects:update")?void 0:n("projectDetail.notes.noEditPermission"),children:[i.jsx(vf,{className:"w-4 h-4 mr-1"}),n("common.edit")]})]}),c?i.jsx(dL,{content:d,onChange:m,placeholder:n("projectDetail.notes.placeholder")}):f.notes?i.jsx("div",{className:"prose prose-invert prose-sm max-w-none",dangerouslySetInnerHTML:{__html:pie.sanitize(f.notes)}}):i.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.notes.empty")})]})}),i.jsx(Mt,{children:i.jsxs(Dt,{className:"p-4",children:[i.jsx("div",{className:"flex items-center justify-between mb-3",children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Nc,{className:"w-5 h-5"}),n("projectDetail.files.title")]})}),i.jsxs("p",{className:"text-xs text-bambu-gray mb-3",children:[i.jsx(io,{to:"/files",className:"text-bambu-green hover:underline",children:n("projectDetail.files.linkFolders")})," ",n("projectDetail.files.forQuickAccess")]}),k&&k.length>0?i.jsx("div",{className:"space-y-2",children:k.map(je=>i.jsxs(io,{to:`/files?folder=${je.id}`,className:"flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i.jsx(Nc,{className:"w-5 h-5 text-bambu-green flex-shrink-0"}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-sm text-white truncate",children:je.name}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("projectDetail.files.fileCount",{count:je.file_count})})]})]}),i.jsx(ha,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"})]},je.id))}):i.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.files.empty")})]})}),i.jsx(Mt,{children:i.jsxs(Dt,{className:"p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(XX,{className:"w-5 h-5"}),n("projectDetail.bom.title"),Te&&Te.bom_total_items>0&&i.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",n("projectDetail.bom.acquired",{completed:Te.bom_completed_items,total:Te.bom_total_items}),")"]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[_&&_.some(je=>je.is_complete)&&i.jsx("button",{onClick:()=>Z(!q),className:`text-xs px-2 py-1 rounded transition-colors ${q?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:n(q?"projectDetail.bom.showAll":"projectDetail.bom.hideDone")}),!xe&&i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>Pe(!0),disabled:!s("projects:update"),title:s("projects:update")?void 0:n("projectDetail.bom.noAddPermission"),children:[i.jsx(ar,{className:"w-4 h-4 mr-1"}),n("projectDetail.bom.addPart")]})]})]}),xe&&i.jsxs("form",{onSubmit:te,className:"bg-bambu-dark rounded-lg p-4 mb-4 space-y-3",children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[i.jsx("input",{type:"text",value:I,onChange:je=>ee(je.target.value),className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.partNamePlaceholder"),autoFocus:!0}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"number",value:ie,onChange:je=>X(parseInt(je.target.value)||1),className:"w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green",min:"1",placeholder:n("projectDetail.bom.qty")}),i.jsx("input",{type:"number",step:"0.01",value:me,onChange:je=>he(je.target.value),className:"flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.price",{currency:R})})]})]}),i.jsx("input",{type:"url",value:ge,onChange:je=>Y(je.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.sourcingUrlPlaceholder")}),i.jsx("input",{type:"text",value:oe,onChange:je=>le(je.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.remarksPlaceholder")}),i.jsxs("div",{className:"flex justify-end gap-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",size:"sm",onClick:()=>Pe(!1),children:n("common.cancel")}),i.jsx(Oe,{type:"submit",size:"sm",disabled:!I.trim()||ae.isPending,children:ae.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):n("projectDetail.bom.addPart")})]})]}),N?i.jsx("div",{className:"flex items-center justify-center py-4",children:i.jsx(ht,{className:"w-6 h-6 animate-spin text-bambu-green"})}):_&&_.length>0?i.jsxs("div",{className:"space-y-2",children:[_.filter(je=>!q||!je.is_complete).map(je=>i.jsx("div",{className:`p-3 rounded-lg transition-colors ${je.is_complete?"bg-status-ok/10":"bg-bambu-dark"}`,children:j?.id===je.id?i.jsxs("form",{onSubmit:Ne,className:"space-y-3",children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[i.jsx("input",{type:"text",value:U,onChange:Xe=>K(Xe.target.value),className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.partName"),autoFocus:!0}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"number",value:$,onChange:Xe=>ne(parseInt(Xe.target.value)||1),className:"w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green",min:"1",placeholder:n("projectDetail.bom.qty")}),i.jsx("input",{type:"number",step:"0.01",value:O,onChange:Xe=>V(Xe.target.value),className:"flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.price",{currency:R})})]})]}),i.jsx("input",{type:"url",value:J,onChange:Xe=>W(Xe.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.sourcingUrlPlaceholder")}),i.jsx("input",{type:"text",value:re,onChange:Xe=>ue(Xe.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.remarksPlaceholder")}),i.jsxs("div",{className:"flex justify-end gap-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",size:"sm",onClick:Se,children:n("common.cancel")}),i.jsx(Oe,{type:"submit",size:"sm",disabled:!U.trim()||L.isPending,children:L.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):n("common.save")})]})]}):i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx("button",{onClick:()=>s("projects:update")&&ve(je),disabled:L.isPending||!s("projects:update"),title:s("projects:update")?void 0:n("projectDetail.bom.noUpdatePermission"),className:`w-5 h-5 mt-0.5 rounded border-2 flex items-center justify-center transition-colors flex-shrink-0 ${je.is_complete?"bg-status-ok border-status-ok text-white":s("projects:update")?"border-bambu-gray hover:border-bambu-green":"border-bambu-gray/50 cursor-not-allowed"}`,children:je.is_complete&&i.jsx(fr,{className:"w-3 h-3"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[i.jsxs("p",{className:`text-sm font-medium ${je.is_complete?"text-bambu-gray line-through":"text-white"}`,children:[je.name,i.jsxs("span",{className:"text-bambu-gray font-normal ml-2",children:["x",je.quantity_needed]})]}),je.unit_price!==null&&i.jsxs("span",{className:"text-xs text-bambu-green whitespace-nowrap",children:[R,(je.unit_price*je.quantity_needed).toFixed(2)]})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("button",{onClick:()=>s("projects:update")&&de(je),disabled:!s("projects:update"),className:`p-1 rounded transition-colors flex-shrink-0 ${s("projects:update")?"hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("projects:update")?n("common.edit"):n("projectDetail.bom.noEditPermission"),children:i.jsx(Yi,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>s("projects:update")&&pe(je.id,je.name),disabled:!s("projects:update"),className:`p-1 rounded transition-colors flex-shrink-0 ${s("projects:update")?"hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-red-400":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("projects:update")?n("common.delete"):n("projectDetail.bom.noDeletePermission"),children:i.jsx(Jt,{className:"w-4 h-4"})})]})]}),je.sourcing_url&&i.jsxs("a",{href:je.sourcing_url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 mt-1 text-xs text-blue-400 hover:text-blue-300 transition-colors",onClick:Xe=>Xe.stopPropagation(),children:[i.jsx(Jr,{className:"w-3 h-3 flex-shrink-0"}),i.jsx("span",{className:"truncate",children:(()=>{try{return new URL(je.sourcing_url).hostname.replace("www.","")}catch{return je.sourcing_url}})()})]}),je.remarks&&i.jsx("p",{className:"mt-1 text-xs text-bambu-gray/80 italic",children:je.remarks})]})]})},je.id)),_.some(je=>je.unit_price!==null)&&i.jsxs("div",{className:"pt-2 mt-2 border-t border-bambu-dark-tertiary flex justify-between text-sm",children:[i.jsx("span",{className:"text-bambu-gray",children:n("projectDetail.bom.totalCost")}),i.jsxs("span",{className:"text-white font-medium",children:[R,_.reduce((je,Xe)=>je+(Xe.unit_price||0)*Xe.quantity_needed,0).toFixed(2)]})]})]}):i.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.bom.empty")})]})}),i.jsx(Mt,{children:i.jsxs(Dt,{className:"p-4",children:[i.jsx("div",{className:"flex items-center justify-between mb-3",children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(f0,{className:"w-5 h-5"}),n("projectDetail.timeline.title")]})}),C?i.jsx("div",{className:"flex items-center justify-center py-4",children:i.jsx(ht,{className:"w-6 h-6 animate-spin text-bambu-green"})}):T&&T.length>0?i.jsx("div",{className:"space-y-3",children:T.slice(0,10).map((je,Xe)=>i.jsxs("div",{className:"flex gap-3",children:[i.jsxs("div",{className:`w-8 h-8 rounded-full flex items-center justify-center flex-shrink-0 ${je.event_type==="print_completed"?"bg-status-ok/20 text-status-ok":je.event_type==="print_failed"?"bg-status-error/20 text-status-error":je.event_type==="print_started"?"bg-yellow-500/20 text-yellow-400":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:[je.event_type==="print_completed"&&i.jsx(fr,{className:"w-4 h-4"}),je.event_type==="print_failed"&&i.jsx(Vi,{className:"w-4 h-4"}),je.event_type==="print_started"&&i.jsx(Sr,{className:"w-4 h-4"}),je.event_type==="queued"&&i.jsx(b3,{className:"w-4 h-4"}),je.event_type==="project_created"&&i.jsx(ar,{className:"w-4 h-4"})]}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-sm text-white",children:je.title}),je.description&&i.jsx("p",{className:"text-xs text-bambu-gray truncate",children:je.description}),i.jsx("p",{className:"text-xs text-bambu-gray/70",children:Ee(je.timestamp)})]})]},Xe))}):i.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.timeline.empty")})]})}),!f.is_template&&i.jsx("div",{className:"flex justify-end",children:i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>qe.mutate(),disabled:qe.isPending||!s("projects:create"),title:s("projects:create")?void 0:n("projectDetail.template.noCreatePermission"),children:[qe.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin mr-2"}):i.jsx(fo,{className:"w-4 h-4 mr-2"}),n("projectDetail.template.saveAsTemplate")]})}),Te&&(Te.queued_prints>0||Te.in_progress_prints>0)&&i.jsx(Mt,{children:i.jsxs(Dt,{className:"p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(b3,{className:"w-5 h-5"}),n("projectDetail.queue.title")]}),i.jsx(io,{to:`/queue?project=${p}`,className:"text-sm text-bambu-green hover:underline",children:n("projectDetail.queue.viewAll")})]}),i.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[Te.in_progress_prints>0&&i.jsx("span",{className:"text-yellow-400",children:n("projectDetail.queue.printing",{count:Te.in_progress_prints})}),Te.queued_prints>0&&i.jsx("span",{className:"text-bambu-gray",children:n("projectDetail.queue.queued",{count:Te.queued_prints})})]})]})}),i.jsxs("div",{children:[i.jsx("div",{className:"flex items-center justify-between mb-4",children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Wi,{className:"w-5 h-5"}),n("projectDetail.prints.title",{count:x?.length||0})]})}),g?i.jsx("div",{className:"flex items-center justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 animate-spin text-bambu-green"})}):i.jsx(utt,{archives:x||[],t:n})]}),o&&i.jsx(Hoe,{t:n,project:{...f,archive_count:Te?.total_archives||0,total_items:Te?.total_items||0,completed_count:Te?.completed_prints||0,failed_count:Te?.failed_prints||0,queue_count:Te?.queued_prints||0,progress_percent:Te?.progress_percent||null,archives:[]},onClose:()=>l(!1),onSave:je=>D.mutate(je),isLoading:D.isPending}),fe.isOpen&&i.jsx(Sn,{title:fe.title,message:fe.message,confirmText:n("common.delete"),variant:"danger",onConfirm:fe.onConfirm,onCancel:()=>ye(je=>({...je,isOpen:!1}))})]})}function htt({parentId:t,onClose:e,onSave:n,isLoading:r,t:a}){const[s,o]=w.useState(""),l=c=>{c.preventDefault(),n({name:s.trim(),parent_id:t})};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary",children:[i.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("fileManager.newFolder")})}),i.jsxs("form",{onSubmit:l,className:"p-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("fileManager.folderName")}),i.jsx("input",{type:"text",value:s,onChange:c=>o(c.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:a("fileManager.folderNamePlaceholder"),autoFocus:!0,required:!0})]}),i.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,children:a("common.cancel")}),i.jsx(Oe,{type:"submit",disabled:!s.trim()||r,children:r?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):a("common.create")})]})]})]})})}function ptt({type:t,currentName:e,onClose:n,onSave:r,isLoading:a,t:s}){const[o,l]=w.useState(e),c=u=>{u.preventDefault(),o.trim()&&o.trim()!==e&&r(o.trim())};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary",children:[i.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:s(t==="file"?"fileManager.renameFile":"fileManager.renameFolder")})}),i.jsxs("form",{onSubmit:c,className:"p-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("common.name")}),i.jsx("input",{type:"text",value:o,onChange:u=>l(u.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",autoFocus:!0,required:!0})]}),i.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:n,children:s("common.cancel")}),i.jsx(Oe,{type:"submit",disabled:!o.trim()||o.trim()===e||a,children:a?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):s("common.rename")})]})]})]})})}function ftt({folders:t,selectedFiles:e,currentFolderId:n,onClose:r,onMove:a,isLoading:s,t:o}){const[l,c]=w.useState(null),u=(m,p=0)=>{const f=[];for(const y of m)f.push({id:y.id,name:y.name,depth:p}),y.children.length>0&&f.push(...u(y.children,p+1));return f},d=[{id:null,name:o("fileManager.rootNoFolder"),depth:0},...u(t)];return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary",children:[i.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:o("fileManager.moveFiles",{count:e.length})})}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1",children:d.map(m=>i.jsxs("button",{onClick:()=>c(m.id),disabled:m.id===n,className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${l===m.id?"bg-bambu-green/20 text-bambu-green":m.id===n?"opacity-50 cursor-not-allowed text-bambu-gray":"hover:bg-bambu-dark text-white"}`,style:{paddingLeft:`${12+m.depth*16}px`},children:[i.jsx(Nc,{className:"w-4 h-4"}),m.name,m.id===n&&i.jsxs("span",{className:"text-xs text-bambu-gray ml-auto",children:["(",o("fileManager.current"),")"]})]},m.id??"root"))}),i.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:r,children:o("common.cancel")}),i.jsx(Oe,{onClick:()=>a(l),disabled:s,children:s?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):o("common.move")})]})]})]})})}function gtt({folder:t,onClose:e,onLink:n,isLoading:r,t:a}){const[s,o]=w.useState("project"),[l,c]=w.useState(t.project_id||t.archive_id||null);w.useState(()=>{t.archive_id&&o("archive")});const{data:u}=et({queryKey:["projects"],queryFn:()=>be.getProjects()}),{data:d}=et({queryKey:["archives-for-link"],queryFn:()=>be.getArchives(void 0,void 0,100)}),m=()=>{n(s==="project"?{project_id:l,archive_id:0}:{project_id:0,archive_id:l})},p=()=>{n({project_id:0,archive_id:0})},f=t.project_id||t.archive_id;return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(xh,{className:"w-5 h-5 text-bambu-green"}),a("fileManager.linkFolder")]}),i.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark rounded",children:i.jsx(Ht,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("fileManager.linkFolderDescription",{name:t.name})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("button",{onClick:()=>{o("project"),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${s==="project"?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,children:[i.jsx(zX,{className:"w-4 h-4"}),a("fileManager.project")]}),i.jsxs("button",{onClick:()=>{o("archive"),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${s==="archive"?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,children:[i.jsx(zs,{className:"w-4 h-4"}),a("fileManager.archive")]})]}),i.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1 bg-bambu-dark rounded-lg p-2",children:s==="project"?u&&u.length>0?u.map(y=>i.jsxs("button",{onClick:()=>c(y.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${l===y.id?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark-tertiary text-white"}`,children:[i.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:y.color||"#00ae42"}}),i.jsx("span",{className:"truncate",children:y.name})]},y.id)):i.jsx("p",{className:"text-sm text-bambu-gray text-center py-4",children:a("fileManager.noProjectsFound")}):d&&d.length>0?d.map(y=>i.jsxs("button",{onClick:()=>c(y.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${l===y.id?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark-tertiary text-white"}`,children:[i.jsx(nf,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),i.jsx("span",{className:"truncate",children:y.print_name||y.filename})]},y.id)):i.jsx("p",{className:"text-sm text-bambu-gray text-center py-4",children:a("fileManager.noArchivesFound")})})]}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-between",children:[f&&i.jsxs(Oe,{variant:"danger",onClick:p,disabled:r,children:[i.jsx(g0,{className:"w-4 h-4 mr-2"}),a("fileManager.unlink")]}),i.jsxs("div",{className:`flex gap-2 ${f?"":"ml-auto"}`,children:[i.jsx(Oe,{variant:"secondary",onClick:e,children:a("common.cancel")}),i.jsx(Oe,{onClick:m,disabled:!l||r,children:r?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):a("fileManager.link")})]})]})]})})}function $oe({folder:t,selectedFolderId:e,onSelect:n,onDelete:r,onLink:a,onRename:s,depth:o=0,wrapNames:l=!1,hasPermission:c,t:u}){const[d,m]=w.useState(!0),[p,f]=w.useState(!1),y=t.children.length>0,v=t.project_id||t.archive_id;return i.jsxs("div",{children:[i.jsxs("div",{className:`group flex items-center gap-1 px-2 py-1.5 rounded cursor-pointer transition-colors ${e===t.id?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark text-white"}`,style:{paddingLeft:`${8+o*12}px`},onClick:()=>n(t.id),children:[y?i.jsx("button",{onClick:x=>{x.stopPropagation(),m(!d)},className:"p-0.5 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(ha,{className:`w-3.5 h-3.5 transition-transform ${d?"rotate-90":""}`})}):i.jsx("div",{className:"w-4.5"}),i.jsx(Nc,{className:"w-4 h-4 text-bambu-green flex-shrink-0"}),i.jsx("span",{className:`text-sm flex-1 min-w-0 ${l?"break-all":"truncate"}`,title:t.name,children:t.name}),v&&i.jsxs("button",{onClick:x=>{x.stopPropagation(),a(t)},className:"flex-shrink-0 flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-400 hover:bg-blue-500/30 transition-colors",title:`${t.project_name?`Project: ${t.project_name}`:`Archive: ${t.archive_name}`} (click to change)`,children:[i.jsx(xh,{className:"w-3 h-3"}),t.project_name?i.jsx(zX,{className:"w-3 h-3"}):i.jsx(zs,{className:"w-3 h-3"})]}),t.file_count>0&&i.jsx("span",{className:"flex-shrink-0 text-xs text-bambu-gray",children:t.file_count}),!v&&i.jsx("button",{onClick:x=>{x.stopPropagation(),a(t)},className:"flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary",title:u("fileManager.linkToProjectOrArchive"),children:i.jsx(xh,{className:"w-3.5 h-3.5 text-bambu-gray hover:text-bambu-green"})}),i.jsx("div",{className:`flex-shrink-0 flex items-center gap-0.5 transition-opacity ${l?"":"opacity-0 group-hover:opacity-100"}`,onClick:x=>x.stopPropagation(),children:i.jsxs("div",{className:"relative",children:[i.jsx("button",{onClick:()=>f(!p),className:"p-1 rounded hover:bg-bambu-dark-tertiary",children:i.jsx(ph,{className:"w-3.5 h-3.5 text-bambu-gray"})}),p&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>f(!1)}),i.jsxs("div",{className:"absolute right-0 top-full mt-1 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]",children:[i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${c("library:update_all")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{c("library:update_all")&&(s(t),f(!1))},disabled:!c("library:update_all"),title:c("library:update_all")?void 0:u("fileManager.noPermissionRenameFolder"),children:[i.jsx(Yi,{className:"w-3.5 h-3.5"}),u("common.rename")]}),i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${c("library:update_all")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{c("library:update_all")&&(a(t),f(!1))},disabled:!c("library:update_all"),title:c("library:update_all")?void 0:u("fileManager.noPermissionLinkFolder"),children:[i.jsx(xh,{className:"w-3.5 h-3.5"}),u(v?"fileManager.changeLink":"fileManager.linkTo")]}),i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${c("library:delete_all")?"text-red-400 hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{c("library:delete_all")&&(r(t.id),f(!1))},disabled:!c("library:delete_all"),title:c("library:delete_all")?void 0:u("fileManager.noPermissionDeleteFolder"),children:[i.jsx(Jt,{className:"w-3.5 h-3.5"}),u("common.delete")]})]})]})]})})]}),y&&d&&i.jsx("div",{children:t.children.map(x=>i.jsx($oe,{folder:x,selectedFolderId:e,onSelect:n,onDelete:r,onLink:a,onRename:s,depth:o+1,wrapNames:l,hasPermission:c,t:u},x.id))})]})}function yL(t){const e=t.toLowerCase();return e.endsWith(".gcode")||e.includes(".gcode.")}function btt({file:t,isSelected:e,isMobile:n,onSelect:r,onDelete:a,onDownload:s,onAddToQueue:o,onPrint:l,onPreview3d:c,onRename:u,onGenerateThumbnail:d,thumbnailVersion:m,hasPermission:p,canModify:f,authEnabled:y,t:v}){const[x,g]=w.useState(!1);return i.jsxs("div",{className:`group relative bg-bambu-dark-secondary rounded-lg border transition-all cursor-pointer overflow-hidden ${e?"border-bambu-green ring-1 ring-bambu-green":"border-bambu-dark-tertiary hover:border-bambu-green/50"}`,onClick:()=>r(t.id),children:[i.jsxs("div",{className:"aspect-square bg-bambu-dark flex items-center justify-center overflow-hidden",children:[t.thumbnail_path?i.jsx("img",{src:`${be.getLibraryFileThumbnailUrl(t.id)}${m?`?v=${m}`:""}`,alt:t.filename,className:"w-full h-full object-cover"}):i.jsx(nf,{className:"w-12 h-12 text-bambu-gray/30"}),i.jsx("div",{className:`absolute top-2 right-2 text-xs px-1.5 py-0.5 rounded font-medium ${t.file_type==="3mf"?"bg-bambu-green/90 text-white":t.file_type==="gcode"?"bg-blue-500/90 text-white":t.file_type==="stl"?"bg-purple-500/90 text-white":"bg-bambu-gray/90 text-white"}`,children:t.file_type.toUpperCase()})]}),i.jsxs("div",{className:"p-3",children:[i.jsx("h3",{className:"text-sm font-medium text-white truncate",title:t.print_name||t.filename,children:t.print_name||t.filename}),i.jsxs("div",{className:"flex items-center gap-3 mt-1 text-xs text-bambu-gray",children:[i.jsx("span",{children:oo(t.file_size)}),t.print_time_seconds&&i.jsxs("span",{className:"flex items-center gap-1",children:[i.jsx(er,{className:"w-3 h-3"}),Rs(t.print_time_seconds)]})]}),t.sliced_for_model&&i.jsxs("div",{className:"mt-1 text-xs text-bambu-gray flex items-center gap-1",children:[i.jsx(Sr,{className:"w-3 h-3"}),t.sliced_for_model]}),t.print_count>0&&i.jsx("div",{className:"mt-1 text-xs text-bambu-green",children:v("fileManager.printedCount",{count:t.print_count})}),y&&t.created_by_username&&i.jsxs("div",{className:"mt-1 text-xs text-bambu-gray flex items-center gap-1",children:[i.jsx(Rd,{className:"w-3 h-3"}),t.created_by_username]})]}),i.jsxs("div",{className:`absolute bottom-2 right-2 transition-opacity ${n?"opacity-100":"opacity-0 group-hover:opacity-100"}`,onClick:_=>_.stopPropagation(),children:[i.jsx("button",{onClick:()=>g(!x),className:"p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary",children:i.jsx(ph,{className:"w-4 h-4 text-bambu-gray"})}),x&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>g(!1)}),i.jsxs("div",{className:"absolute right-0 bottom-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[140px]",children:[l&&yL(t.filename)&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("printers:control")?"text-bambu-green hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("printers:control")&&(l(t),g(!1))},disabled:!p("printers:control"),title:p("printers:control")?void 0:v("fileManager.noPermissionPrint"),children:[i.jsx(Sr,{className:"w-3.5 h-3.5"}),v("common.print")]}),o&&yL(t.filename)&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("queue:create")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("queue:create")&&(o(t.id),g(!1))},disabled:!p("queue:create"),title:p("queue:create")?void 0:v("fileManager.noPermissionAddToQueue"),children:[i.jsx(er,{className:"w-3.5 h-3.5"}),v("fileManager.schedulePrint")]}),c&&(t.file_type==="3mf"||t.file_type==="gcode"||t.file_type==="stl")&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("library:read")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("library:read")&&(c(t),g(!1))},disabled:!p("library:read"),title:p("library:read")?void 0:"You do not have permission to preview files",children:[i.jsx(ra,{className:"w-3.5 h-3.5"}),"3D Preview"]}),i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("library:read")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("library:read")&&(s(t.id),g(!1))},disabled:!p("library:read"),title:p("library:read")?void 0:v("fileManager.noPermissionDownload"),children:[i.jsx(pi,{className:"w-3.5 h-3.5"}),v("common.download")]}),u&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${f("library","update",t.created_by_id)?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{f("library","update",t.created_by_id)&&(u(t),g(!1))},disabled:!f("library","update",t.created_by_id),title:f("library","update",t.created_by_id)?void 0:v("fileManager.noPermissionRenameFile"),children:[i.jsx(Yi,{className:"w-3.5 h-3.5"}),v("common.rename")]}),d&&t.file_type==="stl"&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${f("library","update",t.created_by_id)?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{f("library","update",t.created_by_id)&&(d(t),g(!1))},disabled:!f("library","update",t.created_by_id),title:f("library","update",t.created_by_id)?void 0:v("fileManager.noPermissionGenerateThumbnail"),children:[i.jsx(Ed,{className:"w-3.5 h-3.5"}),v("fileManager.generateThumbnail")]}),i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${f("library","delete",t.created_by_id)?"text-red-400 hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{f("library","delete",t.created_by_id)&&(a(t.id),g(!1))},disabled:!f("library","delete",t.created_by_id),title:f("library","delete",t.created_by_id)?void 0:v("fileManager.noPermissionDeleteFile"),children:[i.jsx(Jt,{className:"w-3.5 h-3.5"}),v("common.delete")]})]})]})]}),i.jsx("div",{className:`absolute top-2 left-2 w-5 h-5 rounded border-2 flex items-center justify-center transition-all ${e?"bg-bambu-green border-bambu-green":`border-white/30 bg-black/30 ${n?"opacity-100":"opacity-0 group-hover:opacity-100"}`}`,children:e&&i.jsx("div",{className:"w-2 h-2 bg-white rounded-sm"})})]})}function xtt(){const{t}=Ft(),e=an(),{showToast:n}=fn(),{hasPermission:r,hasAnyPermission:a,canModify:s,authEnabled:o}=_r(),[l]=ML(),c=l.get("folder"),u=c?parseInt(c,10):null,[d,m]=w.useState(u),[p,f]=w.useState([]),[y,v]=w.useState(!1),[x,g]=w.useState(!1),[_,N]=w.useState(!1),[T,C]=w.useState(null),[A,k]=w.useState(null),[R,P]=w.useState(null),[D,H]=w.useState(null),[z,G]=w.useState(null),[I,ee]=w.useState(null),[ie,X]=w.useState({}),[me,he]=w.useState(null),[ge,Y]=w.useState(()=>localStorage.getItem("library-view-mode")||"grid"),[oe,le]=w.useState(()=>localStorage.getItem("library-wrap-folders")==="true"),[xe,Pe]=w.useState(()=>{const We=localStorage.getItem("library-sidebar-width");return We?parseInt(We,10):256}),[q,Z]=w.useState(!1),j=w.useRef(null);w.useEffect(()=>{if(!q)return;document.body.style.userSelect="none",document.body.style.cursor="col-resize";const We=wt=>{if(!j.current)return;const _t=j.current.parentElement?.getBoundingClientRect();if(!_t)return;const Ot=wt.clientX-_t.left,Vt=Math.min(500,Math.max(200,Ot));Pe(Vt)},yt=()=>{Z(!1),document.body.style.userSelect="",document.body.style.cursor="",localStorage.setItem("library-sidebar-width",String(xe))};return document.addEventListener("mousemove",We),document.addEventListener("mouseup",yt),()=>{document.removeEventListener("mousemove",We),document.removeEventListener("mouseup",yt),document.body.style.userSelect="",document.body.style.cursor=""}},[q,xe]);const[E,U]=w.useState(""),[K,$]=w.useState("all"),[ne,O]=w.useState(""),[V,J]=w.useState(()=>localStorage.getItem("library-sort-field")||"name"),[W,re]=w.useState(()=>localStorage.getItem("library-sort-direction")||"asc"),ue=aie();w.useEffect(()=>{const We=l.get("folder");if(We){const yt=parseInt(We,10);m(yt)}},[l]);const{data:fe}=et({queryKey:["settings"],queryFn:()=>be.getSettings()}),{data:ye,isLoading:ae}=et({queryKey:["library-folders"],queryFn:()=>be.getLibraryFolders()}),{data:L,isLoading:F}=et({queryKey:["library-files",d],queryFn:()=>be.getLibraryFiles(d,d===null)}),{data:te}=et({queryKey:["library-stats"],queryFn:()=>be.getLibraryStats()}),{data:ve}=et({queryKey:["users"],queryFn:()=>be.getUsers()}),pe=w.useMemo(()=>{if(!L)return[];const We=new Set(L.map(yt=>yt.file_type));return Array.from(We).sort()},[L]),de=w.useMemo(()=>{if(!L)return[];let We=[...L];if(E.trim()){const yt=E.toLowerCase();We=We.filter(wt=>wt.filename.toLowerCase().includes(yt)||wt.print_name&&wt.print_name.toLowerCase().includes(yt))}if(K!=="all"&&(We=We.filter(yt=>yt.file_type===K)),ne.trim()){const yt=ne.toLowerCase();We=We.filter(wt=>wt.created_by_username&&wt.created_by_username.toLowerCase().includes(yt))}return We.sort((yt,wt)=>{let _t=0;switch(V){case"name":_t=(yt.print_name||yt.filename).localeCompare(wt.print_name||wt.filename);break;case"date":_t=(Jn(yt.created_at)?.getTime()??0)-(Jn(wt.created_at)?.getTime()??0);break;case"size":_t=yt.file_size-wt.file_size;break;case"type":_t=yt.file_type.localeCompare(wt.file_type);break;case"prints":_t=yt.print_count-wt.print_count;break}return W==="asc"?_t:-_t}),We},[L,E,K,ne,V,W]),Ne=w.useMemo(()=>{if(!te||!fe)return!1;const We=(fe.library_disk_warning_gb||5)*1024*1024*1024;return te.disk_free_bytesbe.createLibraryFolder(We),onSuccess:()=>{e.invalidateQueries({queryKey:["library-folders"]}),v(!1),n(t("fileManager.toast.folderCreated"),"success")},onError:We=>n(We.message,"error")}),Le=pt({mutationFn:We=>be.deleteLibraryFolder(We),onSuccess:()=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-stats"]}),d===A?.id&&m(null),k(null),n(t("fileManager.toast.folderDeleted"),"success")},onError:We=>{k(null),n(We.message,"error")}}),qe=pt({mutationFn:We=>be.deleteLibraryFile(We),onSuccess:()=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]}),f(We=>We.filter(yt=>yt!==A?.id)),k(null),n(t("fileManager.toast.fileDeleted"),"success")},onError:We=>{k(null),n(We.message,"error")}}),Ee=pt({mutationFn:We=>be.bulkDeleteLibrary(We,[]),onSuccess:(We,yt)=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]}),n(t("fileManager.toast.filesDeleted",{count:yt.length}),"success"),f([]),k(null)},onError:We=>{k(null),n(We.message,"error")}}),Te=pt({mutationFn:({fileIds:We,folderId:yt})=>be.moveLibraryFiles(We,yt),onSuccess:()=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),f([]),g(!1),n(t("fileManager.toast.filesMoved"),"success")},onError:We=>n(We.message,"error")}),Ae=pt({mutationFn:({id:We,data:yt})=>be.updateLibraryFolder(We,yt),onSuccess:(We,yt)=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["project-folders"]}),e.invalidateQueries({queryKey:["archive-folders"]}),C(null);const wt=yt.data.project_id===0&&yt.data.archive_id===0;n(t(wt?"fileManager.toast.folderUnlinked":"fileManager.toast.folderLinked"),"success")},onError:We=>n(We.message,"error")}),Be=pt({mutationFn:({id:We,filename:yt})=>be.updateLibraryFile(We,{filename:yt}),onSuccess:()=>{e.invalidateQueries({queryKey:["library-files"]}),ee(null),n(t("fileManager.toast.fileRenamed"),"success")},onError:We=>{ee(null),n(We.message,"error")}}),je=pt({mutationFn:({id:We,name:yt})=>be.updateLibraryFolder(We,{name:yt}),onSuccess:()=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-files"]}),ee(null),n(t("fileManager.toast.folderRenamed"),"success")},onError:We=>{ee(null),n(We.message,"error")}}),Xe=pt({mutationFn:()=>be.batchGenerateStlThumbnails({all_missing:!0}),onSuccess:We=>{if(e.invalidateQueries({queryKey:["library-files"]}),We.succeeded>0){const yt=Date.now(),wt={};We.results.forEach(_t=>{_t.success&&(wt[_t.file_id]=yt)}),X(_t=>({..._t,...wt}))}We.succeeded>0&&We.failed===0?n(t("fileManager.toast.thumbnailsGenerated",{count:We.succeeded}),"success"):We.succeeded>0&&We.failed>0?n(t("fileManager.toast.thumbnailsGeneratedPartial",{succeeded:We.succeeded,failed:We.failed}),"success"):We.processed===0?n(t("fileManager.toast.noStlMissingThumbnails"),"info"):n(t("fileManager.toast.failedToGenerateThumbnails",{error:We.results[0]?.error||"Unknown error"}),"error")},onError:We=>n(We.message,"error")}),ce=pt({mutationFn:We=>be.batchGenerateStlThumbnails({file_ids:[We]}),onSuccess:We=>{if(e.invalidateQueries({queryKey:["library-files"]}),We.succeeded>0){const yt=We.results[0]?.file_id;yt&&X(wt=>({...wt,[yt]:Date.now()})),n(t("fileManager.toast.thumbnailGenerated"),"success")}else n(t("fileManager.toast.failedToGenerateThumbnail",{error:We.results[0]?.error||"Unknown error"}),"error")},onError:We=>n(We.message,"error")}),Ie=w.useCallback(We=>{const yt=We.toLowerCase();return yt.endsWith(".gcode")||yt.includes(".gcode.")},[]),Ce=w.useMemo(()=>L?L.filter(We=>p.includes(We.id)&&Ie(We.filename)):[],[L,p,Ie]),Ge=w.useCallback(We=>{f(yt=>yt.includes(We)?yt.filter(wt=>wt!==We):[...yt,We])},[]),$e=w.useCallback(()=>{de.length>0&&f(de.map(We=>We.id))},[de]),Ue=w.useCallback(()=>{f([])},[]),De=()=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]})},Ve=We=>{be.downloadLibraryFile(We).catch(yt=>{console.error("Library file download failed:",yt)})},it=()=>{A&&(A.type==="file"?qe.mutate(A.id):A.type==="folder"?Le.mutate(A.id):A.type==="bulk"&&Ee.mutate(p))},xt=Le.isPending||qe.isPending||Ee.isPending,Nt=We=>{Y(We),localStorage.setItem("library-view-mode",We)},kt=ae||F;return i.jsxs("div",{className:"p-4 md:p-8 min-h-[calc(100vh-64px)] lg:h-[calc(100vh-64px)] flex flex-col",children:[i.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6",children:[i.jsxs("div",{children:[i.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[i.jsx("div",{className:"p-2.5 bg-bambu-green/10 rounded-xl",children:i.jsx(Nc,{className:"w-6 h-6 text-bambu-green"})}),t("fileManager.title")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-2 ml-14",children:t("fileManager.subtitle")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex items-center bg-bambu-dark rounded-lg p-1",children:[i.jsx("button",{onClick:()=>Nt("grid"),className:`p-1.5 rounded transition-colors ${ge==="grid"?"bg-bambu-dark-secondary text-white":"text-bambu-gray hover:text-white"}`,title:t("fileManager.gridView"),children:i.jsx(pw,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>Nt("list"),className:`p-1.5 rounded transition-colors ${ge==="list"?"bg-bambu-dark-secondary text-white":"text-bambu-gray hover:text-white"}`,title:t("fileManager.listView"),children:i.jsx(JC,{className:"w-4 h-4"})})]}),i.jsxs(Oe,{variant:"secondary",onClick:()=>Xe.mutate(),disabled:Xe.isPending||!a("library:update_own","library:update_all"),title:a("library:update_own","library:update_all")?t("fileManager.generateThumbnailsForMissing"):t("fileManager.noPermissionGenerateThumbnail"),children:[Xe.isPending?i.jsx(ht,{className:"w-4 h-4 mr-2 animate-spin"}):i.jsx(Ed,{className:"w-4 h-4 mr-2"}),t("fileManager.generateThumbnails")]}),i.jsxs(Oe,{variant:"secondary",onClick:()=>v(!0),disabled:!r("library:upload"),title:r("library:upload")?void 0:t("fileManager.noPermissionCreateFolder"),children:[i.jsx(Xpe,{className:"w-4 h-4 mr-2"}),t("fileManager.newFolder")]}),i.jsxs(Oe,{onClick:()=>N(!0),disabled:!r("library:upload"),title:r("library:upload")?void 0:t("fileManager.noPermissionUpload"),children:[i.jsx(xi,{className:"w-4 h-4 mr-2"}),t("common.upload")]})]})]}),Ne&&te&&fe&&i.jsxs("div",{className:"flex items-center gap-3 mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg",children:[i.jsx(Mn,{className:"w-5 h-5 text-amber-500 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-amber-500 font-medium",children:t("fileManager.lowDiskSpaceWarning")}),i.jsx("p",{className:"text-xs text-amber-500/80",children:t("fileManager.lowDiskSpaceDetails",{free:oo(te.disk_free_bytes),total:oo(te.disk_total_bytes),threshold:fe.library_disk_warning_gb})})]})]}),te&&i.jsxs("div",{className:"flex flex-wrap items-center gap-3 sm:gap-6 mb-6 p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx(XC,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.files"),":"]}),i.jsx("span",{className:"text-white font-medium",children:te.total_files})]}),i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx(Nc,{className:"w-4 h-4 text-blue-400"}),i.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.folders"),":"]}),i.jsx("span",{className:"text-white font-medium",children:te.total_folders})]}),i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx(Lx,{className:"w-4 h-4 text-amber-400"}),i.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.size"),":"]}),i.jsx("span",{className:"text-white font-medium",children:oo(te.total_size_bytes)})]}),i.jsxs("div",{className:"flex items-center gap-2 text-sm sm:ml-auto",children:[i.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.free"),":"]}),i.jsx("span",{className:`font-medium ${Ne?"text-amber-500":"text-white"}`,children:oo(te.disk_free_bytes)})]})]}),i.jsxs("div",{className:"flex-1 flex flex-col lg:flex-row gap-4 lg:gap-6 min-h-0",children:[i.jsx("div",{className:"lg:hidden",children:i.jsxs("select",{value:d??"",onChange:We=>m(We.target.value?parseInt(We.target.value,10):null),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg px-3 py-2.5 text-white focus:outline-none focus:border-bambu-green",children:[i.jsxs("option",{value:"",children:["📁 ",t("fileManager.allFiles")]}),ye&&(()=>{const We=(yt,wt=0)=>{const _t=[];for(const Ot of yt)_t.push({id:Ot.id,name:Ot.name,fileCount:Ot.file_count,depth:wt}),Ot.children.length>0&&_t.push(...We(Ot.children,wt+1));return _t};return We(ye).map(yt=>i.jsxs("option",{value:yt.id,children:["│ ".repeat(yt.depth),"📂 ",yt.name," ",yt.fileCount>0?`(${yt.fileCount})`:""]},yt.id))})()]})}),i.jsxs("div",{ref:j,className:"hidden lg:flex flex-shrink-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden flex-col relative",style:{width:`${xe}px`},children:[i.jsx("div",{className:`absolute right-0 top-0 bottom-0 w-1.5 cursor-col-resize z-10 group/resize flex items-center justify-center transition-colors ${q?"bg-bambu-green":"hover:bg-bambu-green/50"}`,onMouseDown:We=>{We.preventDefault(),Z(!0)},onDoubleClick:()=>{Pe(256),localStorage.setItem("library-sidebar-width","256")},title:t("fileManager.dragToResizeTooltip"),children:i.jsxs("div",{className:`flex flex-col gap-1 opacity-0 group-hover/resize:opacity-100 transition-opacity ${q?"opacity-100":""}`,children:[i.jsx("div",{className:"w-0.5 h-0.5 rounded-full bg-white/70"}),i.jsx("div",{className:"w-0.5 h-0.5 rounded-full bg-white/70"}),i.jsx("div",{className:"w-0.5 h-0.5 rounded-full bg-white/70"})]})}),i.jsxs("div",{className:"p-3 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[i.jsx("h2",{className:"text-sm font-medium text-white",children:t("fileManager.folders")}),i.jsx("button",{onClick:()=>{const We=!oe;le(We),localStorage.setItem("library-wrap-folders",String(We))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${oe?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:text-white hover:bg-bambu-dark"}`,title:t(oe?"fileManager.disableTextWrapping":"fileManager.enableTextWrapping"),children:t("fileManager.wrap")})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto p-2",children:[i.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${d===null?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark text-white"}`,onClick:()=>m(null),children:[i.jsx(nf,{className:"w-4 h-4"}),i.jsx("span",{className:"text-sm",children:t("fileManager.allFiles")})]}),ye?.map(We=>i.jsx($oe,{folder:We,selectedFolderId:d,onSelect:m,onDelete:yt=>k({type:"folder",id:yt}),onLink:C,onRename:yt=>ee({type:"folder",id:yt.id,name:yt.name}),wrapNames:oe,hasPermission:r,t},We.id))]})]}),i.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[L&&L.length>0&&i.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-3 mb-4 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-0 z-10 lg:static",children:[i.jsxs("div",{className:"relative w-full sm:w-auto sm:flex-1 sm:max-w-xs",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",placeholder:t("fileManager.searchFiles"),value:E,onChange:We=>U(We.target.value),className:"w-full pl-9 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green"})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(QC,{className:"w-4 h-4 text-bambu-gray hidden sm:block"}),i.jsxs("select",{value:K,onChange:We=>$(We.target.value),className:"bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green",children:[i.jsx("option",{value:"all",children:t("fileManager.allTypes")}),pe.map(We=>i.jsx("option",{value:We,children:We.toUpperCase()},We))]})]}),o&&i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"text",placeholder:t("fileManager.filterByUser",{defaultValue:"Filter by user"}),value:ne,onChange:We=>O(We.target.value),list:"usernames-list",className:`w-32 sm:w-40 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green ${ne?"pr-7":""}`,style:ne?{WebkitAppearance:"none",MozAppearance:"textfield"}:void 0}),ne&&i.jsx("button",{onClick:()=>O(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10",children:i.jsx(Ht,{className:"w-3 h-3"})}),i.jsx("datalist",{id:"usernames-list",children:ve?.map(We=>i.jsx("option",{value:We.username},We.id))})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("select",{value:V,onChange:We=>{const yt=We.target.value;J(yt),localStorage.setItem("library-sort-field",yt)},className:"bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green",children:[i.jsx("option",{value:"name",children:t("common.name")}),i.jsx("option",{value:"date",children:t("common.date")}),i.jsx("option",{value:"size",children:t("fileManager.size")}),i.jsx("option",{value:"type",children:t("common.type")}),i.jsx("option",{value:"prints",children:t("fileManager.prints")})]}),i.jsx("button",{onClick:()=>re(We=>{const yt=We==="asc"?"desc":"asc";return localStorage.setItem("library-sort-direction",yt),yt}),className:"p-1.5 rounded bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors",title:t(W==="asc"?"fileManager.ascending":"fileManager.descending"),children:W==="asc"?i.jsx(ghe,{className:"w-4 h-4 text-white"}):i.jsx(che,{className:"w-4 h-4 text-white"})})]}),(E||K!=="all"||ne)&&i.jsx("span",{className:"text-sm text-bambu-gray hidden sm:inline",children:t("fileManager.resultsCount",{showing:de.length,total:L.length})})]}),de.length>0&&i.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-4 p-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-[52px] z-10 lg:static",children:[p.length===de.length&&p.length>0?i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:Ue,children:[i.jsx(zl,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("fileManager.deselectAll")})]}):i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:$e,children:[i.jsx(xo,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("fileManager.selectAll")})]}),p.length>0&&i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"text-sm text-bambu-gray ml-2",children:t("fileManager.selected",{count:p.length})}),i.jsx("div",{className:"hidden sm:block flex-1"}),i.jsxs("div",{className:"w-full sm:w-auto flex flex-wrap items-center gap-2 mt-2 sm:mt-0",children:[Ce.length===1&&i.jsxs(Oe,{variant:"primary",size:"sm",onClick:()=>H(Ce[0]),disabled:!r("printers:control"),title:r("printers:control")?void 0:t("fileManager.noPermissionPrint"),children:[i.jsx(go,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.print")})]}),Ce.length===1&&i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>G(Ce[0]),disabled:!r("queue:create"),title:r("queue:create")?void 0:t("fileManager.noPermissionAddToQueue"),children:[i.jsx(er,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("fileManager.schedulePrint")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>g(!0),disabled:!a("library:update_own","library:update_all"),title:a("library:update_own","library:update_all")?void 0:t("fileManager.noPermissionMoveFiles"),children:[i.jsx(sge,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.move")})]}),i.jsxs(Oe,{variant:"danger",size:"sm",onClick:()=>{p.length===1?k({type:"file",id:p[0]}):k({type:"bulk",id:0,count:p.length})},disabled:!a("library:delete_own","library:delete_all"),title:a("library:delete_own","library:delete_all")?void 0:t("fileManager.noPermissionDeleteFiles"),children:[i.jsx(Jt,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.delete")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:Ue,children:[i.jsx(Ht,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.clear")})]})]})]})]}),kt?i.jsx("div",{className:"flex-1 flex items-center justify-center",children:i.jsxs("div",{className:"flex flex-col items-center gap-3",children:[i.jsx(ht,{className:"w-8 h-8 animate-spin text-bambu-green"}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t("fileManager.loadingFiles")})]})}):L?.length===0?i.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center",children:[i.jsx("div",{className:"p-4 bg-bambu-dark rounded-2xl mb-4",children:i.jsx(nf,{className:"w-12 h-12 text-bambu-gray/50"})}),i.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:t(d!==null?"fileManager.folderIsEmpty":"fileManager.noFilesYet")}),i.jsx("p",{className:"text-bambu-gray text-center max-w-md mb-6",children:t(d!==null?"fileManager.folderEmptyDescription":"fileManager.noFilesDescription")}),i.jsxs(Oe,{onClick:()=>N(!0),disabled:!r("library:upload"),title:r("library:upload")?void 0:t("fileManager.noPermissionUpload"),children:[i.jsx(ar,{className:"w-4 h-4 mr-2"}),t("fileManager.uploadFiles")]})]}):de.length===0?i.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center",children:[i.jsx("div",{className:"p-4 bg-bambu-dark rounded-2xl mb-4",children:i.jsx(jr,{className:"w-12 h-12 text-bambu-gray/50"})}),i.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:t("fileManager.noMatchingFiles")}),i.jsx("p",{className:"text-bambu-gray text-center max-w-md mb-6",children:t("fileManager.noMatchingFilesDescription")}),i.jsx(Oe,{variant:"secondary",onClick:()=>{U(""),$("all")},children:t("fileManager.clearFilters")})]}):ge==="grid"?i.jsx("div",{className:"flex-1 lg:overflow-y-auto",children:i.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4",children:de.map(We=>i.jsx(btt,{file:We,isSelected:p.includes(We.id),isMobile:ue,t,onSelect:Ge,onDelete:yt=>k({type:"file",id:yt}),onDownload:Ve,onAddToQueue:yt=>{const wt=L?.find(_t=>_t.id===yt);wt&&G(wt)},onPrint:P,onPreview3d:he,onRename:yt=>ee({type:"file",id:yt.id,name:yt.filename}),onGenerateThumbnail:yt=>ce.mutate(yt.id),thumbnailVersion:ie[We.id],hasPermission:r,canModify:s,authEnabled:o},We.id))})}):i.jsx("div",{className:"flex-1 lg:overflow-y-auto",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden",children:[i.jsxs("div",{className:`hidden sm:grid ${o?"grid-cols-[auto_1fr_120px_100px_100px_100px_80px]":"grid-cols-[auto_1fr_100px_100px_100px_80px]"} gap-4 px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary text-xs text-bambu-gray font-medium`,children:[i.jsx("div",{className:"w-6"}),i.jsx("div",{children:t("common.name")}),o&&i.jsx("div",{children:t("fileManager.uploadedBy",{defaultValue:"Uploaded By"})}),i.jsx("div",{children:t("common.type")}),i.jsx("div",{children:t("fileManager.size")}),i.jsx("div",{children:t("fileManager.prints")}),i.jsx("div",{})]}),de.map(We=>i.jsxs("div",{className:`grid ${o?"grid-cols-[auto_1fr_120px_100px_100px_100px_80px]":"grid-cols-[auto_1fr_100px_100px_100px_80px]"} gap-4 px-4 py-3 items-center border-b border-bambu-dark-tertiary last:border-b-0 cursor-pointer hover:bg-bambu-dark/50 transition-colors ${p.includes(We.id)?"bg-bambu-green/10":""}`,onClick:()=>Ge(We.id),children:[i.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${p.includes(We.id)?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:p.includes(We.id)&&i.jsx("div",{className:"w-2 h-2 bg-white rounded-sm"})}),i.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i.jsxs("div",{className:"relative group/thumb",children:[i.jsx("div",{className:"w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden",children:We.thumbnail_path?i.jsx("img",{src:`${be.getLibraryFileThumbnailUrl(We.id)}${ie[We.id]?`?v=${ie[We.id]}`:""}`,alt:"",className:"w-full h-full object-cover"}):i.jsx("div",{className:"w-full h-full flex items-center justify-center",children:i.jsx(nf,{className:"w-5 h-5 text-bambu-gray/50"})})}),We.thumbnail_path&&i.jsx("div",{className:"absolute left-0 top-full mt-2 z-50 hidden group-hover/thumb:block",children:i.jsx("div",{className:"w-48 h-48 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-xl overflow-hidden",children:i.jsx("img",{src:`${be.getLibraryFileThumbnailUrl(We.id)}${ie[We.id]?`?v=${ie[We.id]}`:""}`,alt:We.filename,className:"w-full h-full object-contain"})})})]}),i.jsx("div",{className:"min-w-0",children:i.jsx("div",{className:"text-sm text-white truncate",children:We.print_name||We.filename})})]}),o&&i.jsx("div",{className:"text-sm text-bambu-gray flex items-center gap-1",children:We.created_by_username?i.jsxs(i.Fragment,{children:[i.jsx(Rd,{className:"w-3 h-3"}),i.jsx("span",{className:"truncate",children:We.created_by_username})]}):"-"}),i.jsx("div",{children:i.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded font-medium ${We.file_type==="3mf"?"bg-bambu-green/20 text-bambu-green":We.file_type==="gcode"?"bg-blue-500/20 text-blue-400":We.file_type==="stl"?"bg-purple-500/20 text-purple-400":"bg-bambu-gray/20 text-bambu-gray"}`,children:We.file_type.toUpperCase()})}),i.jsx("div",{className:"text-sm text-bambu-gray",children:oo(We.file_size)}),i.jsx("div",{className:"text-sm text-bambu-gray",children:We.print_count>0?`${We.print_count}x`:"-"}),i.jsxs("div",{className:"flex items-center gap-1",onClick:yt=>yt.stopPropagation(),children:[yL(We.filename)&&i.jsxs(i.Fragment,{children:[i.jsx("button",{onClick:()=>r("printers:control")&&P(We),className:`p-1.5 rounded transition-colors ${r("printers:control")?"hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("printers:control")?t("common.print"):t("fileManager.noPermissionPrint"),disabled:!r("printers:control"),children:i.jsx(Sr,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>{r("queue:create")&&G(We)},className:`p-1.5 rounded transition-colors ${r("queue:create")?"hover:bg-bambu-dark text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("queue:create")?t("fileManager.schedulePrint"):t("fileManager.noPermissionAddToQueue"),disabled:!r("queue:create"),children:i.jsx(er,{className:"w-4 h-4"})})]}),(We.file_type==="3mf"||We.file_type==="gcode"||We.file_type==="stl")&&i.jsx("button",{onClick:()=>r("library:read")&&he(We),className:`p-1.5 rounded transition-colors ${r("library:read")?"hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("library:read")?"3D Preview":"You do not have permission to preview files",disabled:!r("library:read"),children:i.jsx(ra,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>r("library:read")&&Ve(We.id),className:`p-1.5 rounded transition-colors ${r("library:read")?"hover:bg-bambu-dark text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("library:read")?t("common.download"):t("fileManager.noPermissionDownload"),disabled:!r("library:read"),children:i.jsx(pi,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>s("library","update",We.created_by_id)&&ee({type:"file",id:We.id,name:We.filename}),className:`p-1.5 rounded transition-colors ${s("library","update",We.created_by_id)?"hover:bg-bambu-dark text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("library","update",We.created_by_id)?t("common.rename"):t("fileManager.noPermissionRenameFile"),disabled:!s("library","update",We.created_by_id),children:i.jsx(Yi,{className:"w-4 h-4"})}),We.file_type==="stl"&&i.jsx("button",{onClick:()=>s("library","update",We.created_by_id)&&ce.mutate(We.id),className:`p-1.5 rounded transition-colors ${s("library","update",We.created_by_id)?"hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("library","update",We.created_by_id)?t("fileManager.generateThumbnail"):t("fileManager.noPermissionGenerateThumbnail"),disabled:ce.isPending||!s("library","update",We.created_by_id),children:i.jsx(Ed,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>s("library","delete",We.created_by_id)&&k({type:"file",id:We.id}),className:`p-1.5 rounded transition-colors ${s("library","delete",We.created_by_id)?"hover:bg-bambu-dark text-bambu-gray hover:text-red-400":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("library","delete",We.created_by_id)?t("common.delete"):t("fileManager.noPermissionDeleteFile"),disabled:!s("library","delete",We.created_by_id),children:i.jsx(Jt,{className:"w-4 h-4"})})]})]},We.id))]})})]})]}),y&&i.jsx(htt,{parentId:d,onClose:()=>v(!1),onSave:We=>Se.mutate(We),isLoading:Se.isPending,t}),x&&ye&&i.jsx(ftt,{folders:ye,selectedFiles:p,currentFolderId:d,onClose:()=>g(!1),onMove:We=>Te.mutate({fileIds:p,folderId:We}),isLoading:Te.isPending,t}),_&&i.jsx(Qre,{folderId:d,onClose:()=>N(!1),onUploadComplete:De}),T&&i.jsx(gtt,{folder:T,onClose:()=>C(null),onLink:We=>Ae.mutate({id:T.id,data:We}),isLoading:Ae.isPending,t}),A&&i.jsx(Sn,{title:A.type==="folder"?t("fileManager.deleteFolder"):A.type==="bulk"?t("fileManager.deleteFilesCount",{count:A.count}):t("fileManager.deleteFile"),message:A.type==="folder"?t("fileManager.deleteFolderConfirm"):A.type==="bulk"?t("fileManager.deleteFilesConfirm",{count:A.count}):t("fileManager.deleteFileConfirm"),confirmText:t("common.delete"),variant:"danger",isLoading:xt,loadingText:t("fileManager.deleting"),onConfirm:it,onCancel:()=>k(null)}),R&&i.jsx(uu,{mode:"reprint",libraryFileId:R.id,archiveName:R.print_name||R.filename,onClose:()=>P(null),onSuccess:()=>{P(null),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["archives"]})}}),D&&i.jsx(uu,{mode:"reprint",libraryFileId:D.id,archiveName:D.print_name||D.filename,onClose:()=>H(null),onSuccess:()=>{H(null),f([]),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["archives"]})}}),z&&i.jsx(uu,{mode:"add-to-queue",libraryFileId:z.id,archiveName:z.print_name||z.filename,onClose:()=>G(null),onSuccess:()=>{G(null),f([]),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["queue"]}),e.invalidateQueries({queryKey:["archives"]})}}),me&&i.jsx(M4,{libraryFileId:me.id,title:me.print_name||me.filename,fileType:me.file_type,onClose:()=>he(null)}),I&&i.jsx(ptt,{type:I.type,currentName:I.name,onClose:()=>ee(null),onSave:We=>{I.type==="file"?Be.mutate({id:I.id,filename:We}):je.mutate({id:I.id,name:We})},isLoading:Be.isPending||je.isPending,t})]})}const VD=5,ytt=2e3,vtt=3e4,wtt=5e3;function Stt(){const{t}=Ft(),e=an(),{showToast:n}=fn(),{hasPermission:r}=_r(),{printerId:a}=uw(),s=parseInt(a||"0",10),[o,l]=w.useState("stream"),[c,u]=w.useState(!1),[d,m]=w.useState(!1),[p,f]=w.useState(!0),[y,v]=w.useState(Date.now()),[x,g]=w.useState(!1),[_,N]=w.useState(!1),[T,C]=w.useState(0),[A,k]=w.useState(!1),[R,P]=w.useState(0),[D,H]=w.useState(1),[z,G]=w.useState({x:0,y:0}),[I,ee]=w.useState(!1),[ie,X]=w.useState({x:0,y:0}),[me,he]=w.useState(null),[ge,Y]=w.useState(null),oe=w.useRef(null),le=w.useRef(null),xe=w.useRef(null),Pe=w.useRef(null),q=w.useRef(null),{data:Z}=et({queryKey:["printer",s],queryFn:()=>be.getPrinter(s),enabled:s>0}),{data:j}=et({queryKey:["printerStatus",s],queryFn:()=>be.getPrinterStatus(s),refetchInterval:3e4,enabled:s>0}),E=pt({mutationFn:Te=>be.setChamberLight(s,Te),onMutate:async Te=>{await e.cancelQueries({queryKey:["printerStatus",s]});const Ae=e.getQueryData(["printerStatus",s]);return e.setQueryData(["printerStatus",s],Be=>({...Be,chamber_light:Te})),{previousStatus:Ae}},onSuccess:(Te,Ae)=>{n(`Chamber light ${Ae?"on":"off"}`)},onError:(Te,Ae,Be)=>{Be?.previousStatus&&e.setQueryData(["printerStatus",s],Be.previousStatus),n(Te.message||t("printers.toast.failedToControlChamberLight"),"error")}}),U=(j?.state==="RUNNING"||j?.state==="PAUSE")&&(j?.printable_objects_count??0)>=2;w.useEffect(()=>(Z&&(document.title=`${Z.name} - Camera`),()=>{document.title="Bambuddy"}),[Z]);const K=w.useRef(!1);w.useEffect(()=>{const Te=`/api/v1/printers/${s}/camera/stop`;K.current=!1;const Ae=()=>{if(s>0&&!K.current){K.current=!0;const Xe={},ce=Fd();ce&&(Xe.Authorization=`Bearer ${ce}`),fetch(Te,{method:"POST",keepalive:!0,headers:Xe}).catch(()=>{})}},Be=()=>{Ae()};window.addEventListener("beforeunload",Be);const je=oe.current;return()=>{window.removeEventListener("beforeunload",Be),je&&(je.src=""),Ae()}},[s]),w.useEffect(()=>{if(p&&!x){const Ae=setTimeout(()=>{f(!1)},o==="stream"?3e3:2e4);return()=>clearTimeout(Ae)}},[o,p,y,x]),w.useEffect(()=>{const Te=()=>{const Ae=!!document.fullscreenElement;N(Ae),H(1),G({x:0,y:0}),o==="stream"&&!x&&(oe.current&&(oe.current.src=""),setTimeout(()=>{f(!0),v(Date.now())},200))};return document.addEventListener("fullscreenchange",Te),()=>document.removeEventListener("fullscreenchange",Te)},[o,x]),w.useEffect(()=>{let Te;const Ae=()=>{clearTimeout(Te),Te=setTimeout(()=>{localStorage.setItem("cameraWindowState",JSON.stringify({width:window.outerWidth,height:window.outerHeight,left:window.screenX,top:window.screenY}))},500)};return window.addEventListener("resize",Ae),()=>{clearTimeout(Te),window.removeEventListener("resize",Ae)}},[]),w.useEffect(()=>()=>{xe.current&&clearTimeout(xe.current),Pe.current&&clearInterval(Pe.current),q.current&&clearInterval(q.current)},[]);const $=w.useCallback(()=>{if(T>=VD){k(!1),m(!0);return}const Te=Math.min(ytt*Math.pow(2,T),vtt);k(!0),P(Math.ceil(Te/1e3)),Pe.current=setInterval(()=>{P(Ae=>Ae<=1?(Pe.current&&clearInterval(Pe.current),0):Ae-1)},1e3),xe.current=setTimeout(()=>{C(Ae=>Ae+1),k(!1),f(!0),m(!1),oe.current&&(oe.current.src=""),v(Date.now())},Te)},[T]);w.useEffect(()=>{if(o!=="stream"||p||A||x){q.current&&(clearInterval(q.current),q.current=null);return}return q.current=setInterval(async()=>{try{const Te=await be.getCameraStatus(s);(Te.stalled||!Te.active&&!d)&&(console.log(`Stream issue detected: stalled=${Te.stalled}, active=${Te.active}, reconnecting...`),q.current&&(clearInterval(q.current),q.current=null),f(!1),$())}catch{}},wtt),()=>{q.current&&(clearInterval(q.current),q.current=null)}},[o,p,d,A,x,s,$]);const ne=()=>{f(!1),o==="stream"&&T{if(f(!1),m(!1),C(0),k(!1),xe.current&&clearTimeout(xe.current),Pe.current&&clearInterval(Pe.current),oe.current&&!localStorage.getItem("cameraWindowState")){const Te=oe.current,Ae=Te.naturalWidth,Be=Te.naturalHeight;if(Ae>0&&Be>0){const ce=window.outerWidth-window.innerWidth,Ie=window.outerHeight-window.innerHeight,Ce=Ae+16+ce,Ge=Be+45+16+Ie;try{window.resizeTo(Ce,Ge)}catch{}}}},V=()=>{if(s>0){const Te={},Ae=Fd();Ae&&(Te.Authorization=`Bearer ${Ae}`),fetch(`/api/v1/printers/${s}/camera/stop`,{method:"POST",headers:Te}).catch(()=>{})}},J=Te=>{o===Te||x||(g(!0),f(!0),m(!1),C(0),k(!1),H(1),G({x:0,y:0}),xe.current&&clearTimeout(xe.current),Pe.current&&clearInterval(Pe.current),oe.current&&(oe.current.src=""),o==="stream"&&V(),setTimeout(()=>{l(Te),v(Date.now()),g(!1)},100))},W=()=>{x||(g(!0),f(!0),m(!1),C(0),k(!1),xe.current&&clearTimeout(xe.current),Pe.current&&clearInterval(Pe.current),oe.current&&(oe.current.src=""),o==="stream"&&V(),setTimeout(()=>{v(Date.now()),g(!1)},100))},re=()=>{le.current&&(document.fullscreenElement?document.exitFullscreen():le.current.requestFullscreen())},ue=()=>{H(Te=>Math.min(Te+.5,4))},fe=()=>{H(Te=>{const Ae=Math.max(Te-.5,1);return Ae===1&&G({x:0,y:0}),Ae})},ye=Te=>{Te.preventDefault(),Te.deltaY<0?ue():fe()},ae=Te=>{D>1&&(Te.preventDefault(),ee(!0),X({x:Te.clientX-z.x,y:Te.clientY-z.y}))},L=w.useCallback(()=>{if(!le.current)return{x:300,y:200};const Te=le.current.getBoundingClientRect(),Ae=Te.width*(D-1)/2,Be=Te.height*(D-1)/2;return{x:Math.max(50,Ae),y:Math.max(50,Be)}},[D]),F=Te=>{if(I&&D>1){const Ae=Te.clientX-ie.x,Be=Te.clientY-ie.y,je=L();G({x:Math.max(-je.x,Math.min(je.x,Ae)),y:Math.max(-je.y,Math.min(je.y,Be))})}},te=()=>{ee(!1)},ve=Te=>{if(Te.length<2)return 0;const Ae=Te[0].clientX-Te[1].clientX,Be=Te[0].clientY-Te[1].clientY;return Math.sqrt(Ae*Ae+Be*Be)},pe=Te=>Te.length<2?{x:Te[0].clientX,y:Te[0].clientY}:{x:(Te[0].clientX+Te[1].clientX)/2,y:(Te[0].clientY+Te[1].clientY)/2},de=Te=>{Te.touches.length===2?(Te.preventDefault(),he(ve(Te.touches)),Y(pe(Te.touches))):Te.touches.length===1&&D>1&&(Te.preventDefault(),ee(!0),X({x:Te.touches[0].clientX-z.x,y:Te.touches[0].clientY-z.y}))},Ne=Te=>{if(Te.touches.length===2&&me!==null){Te.preventDefault();const Ae=ve(Te.touches),Be=Ae/me;H(Xe=>{const ce=Math.max(1,Math.min(4,Xe*Be));return ce===1&&G({x:0,y:0}),ce}),he(Ae);const je=pe(Te.touches);if(ge){const Xe=L();G(ce=>({x:Math.max(-Xe.x,Math.min(Xe.x,ce.x+(je.x-ge.x))),y:Math.max(-Xe.y,Math.min(Xe.y,ce.y+(je.y-ge.y)))}))}Y(je)}else if(Te.touches.length===1&&I&&D>1){Te.preventDefault();const Ae=Te.touches[0].clientX-ie.x,Be=Te.touches[0].clientY-ie.y,je=L();G({x:Math.max(-je.x,Math.min(je.x,Ae)),y:Math.max(-je.y,Math.min(je.y,Be))})}},Se=Te=>{Te.touches.length<2&&(he(null),Y(null)),Te.touches.length===0&&ee(!1)},Le=()=>{H(1),G({x:0,y:0})},qe=x?"":o==="stream"?`/api/v1/printers/${s}/camera/stream?fps=15&t=${y}`:`/api/v1/printers/${s}/camera/snapshot?t=${y}`,Ee=p||x||A;return s?i.jsxs("div",{ref:le,className:"min-h-screen bg-black flex flex-col",children:[i.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary",children:[i.jsxs("h1",{className:"text-sm font-medium text-white flex items-center gap-2",children:[i.jsx(rx,{className:"w-4 h-4"}),Z?.name||`Printer ${s}`]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex bg-bambu-dark rounded p-0.5",children:[i.jsx("button",{onClick:()=>J("stream"),disabled:Ee,className:`px-3 py-1 text-xs rounded transition-colors ${o==="stream"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white disabled:opacity-50"}`,children:t("camera.live")}),i.jsx("button",{onClick:()=>J("snapshot"),disabled:Ee,className:`px-3 py-1 text-xs rounded transition-colors ${o==="snapshot"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white disabled:opacity-50"}`,children:t("camera.snapshot")})]}),i.jsx("button",{onClick:()=>E.mutate(!j?.chamber_light),disabled:!j?.connected||E.isPending||!r("printers:control"),className:`p-1.5 rounded disabled:opacity-50 ${j?.chamber_light?"bg-yellow-500/20 hover:bg-yellow-500/30":"hover:bg-bambu-dark-tertiary"}`,title:r("printers:control")?t("camera.chamberLight"):t("printers.permission.noControl"),children:i.jsx(_O,{on:j?.chamber_light??!1,className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>u(!0),disabled:!U||!r("printers:control"),className:`p-1.5 rounded disabled:opacity-50 ${U&&r("printers:control")?"hover:bg-bambu-dark-tertiary":""}`,title:r("printers:control")?t(U?"printers.skipObjects.tooltip":"printers.skipObjects.onlyWhilePrinting"):t("printers.permission.noControl"),children:i.jsx(bT,{className:"w-4 h-4 text-bambu-gray"})}),i.jsx("button",{onClick:W,disabled:Ee,className:"p-1.5 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50",title:t(o==="stream"?"camera.restartStream":"camera.refreshSnapshot"),children:i.jsx(wr,{className:`w-4 h-4 text-bambu-gray ${Ee?"animate-spin":""}`})}),i.jsx("button",{onClick:re,className:"p-1.5 hover:bg-bambu-dark-tertiary rounded",title:t(_?"camera.exitFullscreen":"camera.fullscreen"),children:_?i.jsx(KX,{className:"w-4 h-4 text-bambu-gray"}):i.jsx(Kfe,{className:"w-4 h-4 text-bambu-gray"})})]})]}),i.jsx("div",{className:"flex-1 flex items-center justify-center p-2 overflow-hidden",onWheel:ye,onMouseMove:F,onMouseUp:te,onMouseLeave:te,onTouchStart:de,onTouchMove:Ne,onTouchEnd:Se,style:{touchAction:"none"},children:i.jsxs("div",{className:"relative w-full h-full flex items-center justify-center",children:[(p||x)&&!A&&i.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 z-10",children:i.jsxs("div",{className:"text-center",children:[i.jsx(wr,{className:"w-8 h-8 text-bambu-gray animate-spin mx-auto mb-2"}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t(o==="stream"?"camera.connectingToCamera":"camera.capturingSnapshot")})]})}),A&&i.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/80 z-10",children:i.jsxs("div",{className:"text-center p-4",children:[i.jsx(Ph,{className:"w-10 h-10 text-orange-400 mx-auto mb-3"}),i.jsx("p",{className:"text-white mb-2",children:t("camera.connectionLost")}),i.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:t("camera.reconnecting",{countdown:R,attempt:T+1,max:VD})}),i.jsx("button",{onClick:W,className:"px-4 py-2 bg-bambu-green text-white text-sm rounded hover:bg-bambu-green/80 transition-colors",children:t("camera.reconnectNow")})]})}),d&&!A&&i.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black z-10",children:i.jsxs("div",{className:"text-center p-4",children:[i.jsx(Mn,{className:"w-12 h-12 text-orange-400 mx-auto mb-3"}),i.jsx("p",{className:"text-white mb-2",children:t("camera.cameraUnavailable")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-4 max-w-md",children:t("camera.cameraUnavailableDesc")}),i.jsx("button",{onClick:W,className:"px-4 py-2 bg-bambu-green text-white rounded hover:bg-bambu-green/80 transition-colors",children:t("camera.retry")})]})}),i.jsx("img",{ref:oe,src:qe,alt:t("camera.cameraStream"),className:"max-w-full max-h-full object-contain select-none",style:{transform:`scale(${D}) translate(${z.x/D}px, ${z.y/D}px)`,cursor:D>1?I?"grabbing":"grab":"default"},onError:qe?ne:void 0,onLoad:qe?O:void 0,onMouseDown:ae,draggable:!1},y),i.jsxs("div",{className:"absolute bottom-4 left-4 flex items-center gap-1.5 bg-black/60 rounded-lg px-2 py-1.5",children:[i.jsx("button",{onClick:fe,disabled:D<=1,className:"p-1.5 hover:bg-white/10 rounded disabled:opacity-30",title:t("camera.zoomOut"),children:i.jsx(WL,{className:"w-4 h-4 text-white"})}),i.jsxs("button",{onClick:Le,className:"px-2 py-1 text-sm text-white hover:bg-white/10 rounded min-w-[48px]",title:t("camera.resetZoom"),children:[Math.round(D*100),"%"]}),i.jsx("button",{onClick:ue,disabled:D>=4,className:"p-1.5 hover:bg-white/10 rounded disabled:opacity-30",title:t("camera.zoomIn"),children:i.jsx(GL,{className:"w-4 h-4 text-white"})})]})]})}),i.jsx(NO,{printerId:s,isOpen:c,onClose:()=>u(!1)})]}):i.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:i.jsx("p",{className:"text-white",children:t("camera.invalidPrinterId")})})}function _tt(t){const e=t.get("show")?.split(",")||["progress","layers","eta","filename","status"],n=parseInt(t.get("fps")||"15",10),r=Math.min(Math.max(isNaN(n)?15:n,1),30),a=t.get("camera"),s=a!=="false"&&a!=="0";return{size:t.get("size")||"medium",fps:r,showCamera:s,showProgress:e.includes("progress"),showLayers:e.includes("layers"),showEta:e.includes("eta"),showFilename:e.includes("filename"),showStatus:e.includes("status"),showPrinter:e.includes("printer")}}function Ntt(t,e){if(t.stg_cur_name)return t.stg_cur_name;switch(t.state){case"RUNNING":return e("streamOverlay.status.printing");case"PAUSE":return e("streamOverlay.status.paused");case"FINISH":return e("streamOverlay.status.finished");case"FAILED":return e("streamOverlay.status.failed");case"IDLE":return e("streamOverlay.status.idle");default:return t.state||e("streamOverlay.status.unknown")}}function ktt(t){switch(t){case"small":return{container:"p-3",text:"text-sm",textLarge:"text-lg",progressHeight:"h-2",icon:"w-3 h-3",gap:"gap-2",logoHeight:"h-12"};case"large":return{container:"p-6",text:"text-xl",textLarge:"text-3xl",progressHeight:"h-4",icon:"w-6 h-6",gap:"gap-4",logoHeight:"h-24"};default:return{container:"p-4",text:"text-base",textLarge:"text-xl",progressHeight:"h-3",icon:"w-4 h-4",gap:"gap-3",logoHeight:"h-16"}}}function Ctt(){const{printerId:t}=uw(),[e]=ML(),{t:n}=Ft(),r=an(),a=parseInt(t||"0",10),[s,o]=w.useState(Date.now()),l=w.useMemo(()=>_tt(e),[e]),c=ktt(l.size),{data:u}=et({queryKey:["printer",a],queryFn:()=>be.getPrinter(a),enabled:a>0}),{data:d}=et({queryKey:["printerStatus",a],queryFn:()=>be.getPrinterStatus(a),enabled:a>0,refetchInterval:2e3}),{data:m}=et({queryKey:["settings"],queryFn:be.getSettings}),p=m?.time_format||"system";w.useEffect(()=>{if(!a)return;const _=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/v1/ws`,N=new WebSocket(_);return N.onmessage=T=>{try{const C=JSON.parse(T.data);C.type==="printer_status"&&C.printer_id===a&&r.setQueryData(["printerStatus",a],C.status)}catch{}},N.onerror=()=>{},()=>{N.close()}},[a,r]),w.useEffect(()=>(document.title=u?`${u.name} - ${n("streamOverlay.title")}`:n("streamOverlay.title"),()=>{document.title="Bambuddy"}),[u,n]);const f=()=>{setTimeout(()=>{o(Date.now())},3e3)};if(!a)return i.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:i.jsx("p",{className:"text-white",children:n("streamOverlay.invalidPrinterId")})});if(!d)return i.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:i.jsx("p",{className:"text-gray-400",children:n("common.loading")})});const y=d.state==="RUNNING"||d.state==="PAUSE",v=d.progress||0,x=`/api/v1/printers/${a}/camera/stream?fps=${l.fps}&t=${s}`;return i.jsxs("div",{className:"min-h-screen bg-black relative overflow-hidden",children:[l.showCamera&&i.jsx("img",{src:x,alt:n("streamOverlay.cameraStream"),className:"absolute inset-0 w-full h-full object-contain",onError:f},s),i.jsx("a",{href:"https://github.com/maziggy/bambuddy",target:"_blank",rel:"noopener noreferrer",className:"absolute top-4 right-4 z-10",children:i.jsx("img",{src:"/img/bambuddy_logo_dark_transparent.png",alt:"Bambuddy",className:`${c.logoHeight} object-contain drop-shadow-lg hover:scale-105 transition-transform`})}),i.jsx("div",{className:"absolute bottom-0 left-0 right-0 z-10 bg-gradient-to-t from-black/80 via-black/60 to-transparent",children:i.jsxs("div",{className:`${c.container}`,children:[l.showPrinter&&u&&i.jsxs("div",{className:`flex items-center ${c.gap} mb-2`,children:[i.jsx(Sr,{className:`${c.icon} text-white/70`}),i.jsx("span",{className:`${c.text} text-white font-medium`,children:u.name})]}),l.showFilename&&d.current_print&&i.jsx("div",{className:`${c.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`,children:d.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,"")}),l.showStatus&&i.jsx("div",{className:`${c.text} text-white/70 mb-2`,children:Ntt(d,n)}),l.showProgress&&y&&i.jsxs("div",{className:"mb-3",children:[i.jsxs("div",{className:`flex items-center justify-between mb-1 ${c.text}`,children:[i.jsx("span",{className:"text-white/70",children:n("streamOverlay.progress")}),i.jsxs("span",{className:"text-white font-bold",children:[Math.round(v),"%"]})]}),i.jsx("div",{className:`w-full bg-white/20 rounded-full ${c.progressHeight}`,children:i.jsx("div",{className:`bg-bambu-green ${c.progressHeight} rounded-full transition-all duration-500`,style:{width:`${v}%`}})})]}),y&&(l.showLayers||l.showEta)&&i.jsxs("div",{className:`flex items-center ${c.gap} flex-wrap`,children:[l.showLayers&&d.layer_num!=null&&d.total_layers!=null&&d.total_layers>0&&i.jsxs("div",{className:`flex items-center ${c.gap} text-white/70`,children:[i.jsx(Gi,{className:c.icon}),i.jsxs("span",{className:c.text,children:[i.jsx("span",{className:"text-white",children:d.layer_num}),i.jsx("span",{className:"mx-1",children:"/"}),i.jsx("span",{children:d.total_layers})]})]}),l.showEta&&d.remaining_time!=null&&d.remaining_time>0&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:`flex items-center ${c.gap} text-white/70`,children:[i.jsx(pd,{className:c.icon}),i.jsx("span",{className:`${c.text} text-white`,children:Rs(d.remaining_time*60)})]}),i.jsxs("div",{className:`flex items-center ${c.gap} text-white/70`,children:[i.jsx(er,{className:c.icon}),i.jsxs("span",{className:`${c.text} text-white`,children:[n("streamOverlay.eta")," ",KL(d.remaining_time,p,n)]})]})]})]}),!y&&i.jsx("div",{className:`${c.text} text-white/70 py-2`,children:d.connected?n("streamOverlay.printerIdle"):n("streamOverlay.printerOffline")})]})})]})}function Ttt(){const{t}=Ft(),{id:e}=uw(),{mode:n}=Wf(),{data:r,isLoading:a,error:s}=et({queryKey:["external-link",e],queryFn:()=>be.getExternalLink(Number(e)),enabled:!!e});return a?i.jsx("div",{className:"flex items-center justify-center h-full",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):s||!r?i.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 text-bambu-gray",children:[i.jsx(Mn,{className:"w-12 h-12"}),i.jsx("p",{children:t("common.linkNotFound")})]}):i.jsx("iframe",{src:r.url,className:"h-full w-full border-0",style:{colorScheme:n},title:r.name,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox"})}function EY(){const{id:t}=uw(),e=Qo(),n=an(),{t:r}=Ft(),{showToast:a}=fn(),s=!!t,[o,l]=w.useState(""),[c,u]=w.useState(""),[d,m]=w.useState([]),[p,f]=w.useState(""),[y,v]=w.useState(!1),{data:x,isLoading:g}=et({queryKey:["group",t],queryFn:()=>be.getGroup(Number(t)),enabled:s}),{data:_,isLoading:N}=et({queryKey:["permissions"],queryFn:()=>be.getPermissions()});s&&x&&!y&&(l(x.name),u(x.description||""),m(x.permissions),v(!0));const T=pt({mutationFn:X=>be.createGroup(X),onSuccess:()=>{n.invalidateQueries({queryKey:["groups"]}),a(r("groups.toast.created")),e("/settings?tab=users")},onError:X=>{a(X.message,"error")}}),C=pt({mutationFn:X=>be.updateGroup(Number(t),X),onSuccess:()=>{n.invalidateQueries({queryKey:["groups"]}),a(r("groups.toast.updated")),e("/settings?tab=users")},onError:X=>{a(X.message,"error")}}),A=T.isPending||C.isPending,k=()=>{if(!o.trim()){a(r("groups.toast.enterGroupName"),"error");return}s?C.mutate({name:o!==x?.name?o:void 0,description:c,permissions:d}):T.mutate({name:o,description:c||void 0,permissions:d})},R=X=>{m(me=>me.includes(X)?me.filter(he=>he!==X):[...me,X])},P=(X,me)=>{const he=X.permissions.map(ge=>ge.value);m(ge=>{const Y=ge.filter(oe=>!he.includes(oe));return me?[...Y,...he]:Y})},D=X=>X.permissions.every(me=>d.includes(me.value)),H=X=>{const me=X.permissions.filter(he=>d.includes(he.value)).length;return me>0&&me{_&&m(_.all_permissions)},G=()=>{m([])},I=p.toLowerCase(),ee=w.useMemo(()=>_?I?_.categories.map(X=>({...X,permissions:X.permissions.filter(me=>me.label.toLowerCase().includes(I))})).filter(X=>X.permissions.length>0):_.categories:[],[_,I]),ie=_?.all_permissions.length??0;return g||N?i.jsx("div",{className:"flex items-center justify-center py-16",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):i.jsxs("div",{className:"space-y-6 max-w-5xl mx-auto",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("button",{onClick:()=>e("/settings?tab=users"),className:"p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",children:i.jsx(IX,{className:"w-5 h-5"})}),i.jsx("h1",{className:"text-xl font-bold text-white",children:r(s?"groups.editor.title":"groups.editor.createTitle")})]}),s&&x?.is_system&&i.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-lg bg-yellow-500/10 border border-yellow-500/20 text-yellow-400 text-sm",children:[i.jsx(Mn,{className:"w-4 h-4 shrink-0"}),r("groups.form.systemGroupWarning")]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:r("groups.form.groupName")}),i.jsx("input",{type:"text",value:o,onChange:X=>l(X.target.value),disabled:s&&x?.is_system,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 disabled:opacity-50",placeholder:r("groups.form.groupNamePlaceholder")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:r("groups.form.description")}),i.jsx("input",{type:"text",value:c,onChange:X=>u(X.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:r("groups.form.descriptionPlaceholder")})]})]}),i.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("span",{className:"text-sm text-bambu-gray",children:[r("groups.editor.permissionsSelected",{count:d.length})," / ",ie]}),i.jsx(Oe,{size:"sm",variant:"ghost",onClick:z,children:r("groups.editor.selectAll")}),i.jsx(Oe,{size:"sm",variant:"ghost",onClick:G,children:r("groups.editor.clearAll")})]}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray"}),i.jsx("input",{type:"text",value:p,onChange:X=>f(X.target.value),placeholder:r("groups.editor.search"),className:"pl-9 pr-4 py-2 text-sm 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 w-64"})]})]}),ee.length===0?i.jsx("div",{className:"text-center py-12 text-bambu-gray",children:r("groups.editor.noResults")}):i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:ee.map(X=>{const me=_.categories.find(le=>le.name===X.name),he=me.permissions.filter(le=>d.includes(le.value)).length,ge=me.permissions.length,Y=D(me),oe=H(me);return i.jsxs(Mt,{children:[i.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between px-4 py-3 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-t-xl",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("button",{type:"button",onClick:()=>P(me,!Y),className:`w-5 h-5 rounded border flex items-center justify-center transition-colors shrink-0 ${Y?"bg-bambu-green border-bambu-green":oe?"bg-bambu-green/50 border-bambu-green":"border-bambu-gray hover:border-white"}`,children:[Y&&i.jsx(Yr,{className:"w-3 h-3 text-white"}),oe&&!Y&&i.jsx(jN,{className:"w-3 h-3 text-white"})]}),i.jsx(v3,{className:"w-4 h-4 text-bambu-gray shrink-0"}),i.jsx("span",{className:"text-white font-medium text-sm",children:X.name})]}),i.jsxs("span",{className:"text-xs text-bambu-gray tabular-nums",children:[he,"/",ge]})]}),i.jsx("div",{className:"p-3 space-y-1",children:X.permissions.map(le=>i.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:d.includes(le.value),onChange:()=>R(le.value),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:le.label})]},le.value))})]},X.name)})}),i.jsx("div",{className:"h-16"}),i.jsxs("div",{className:"fixed bottom-0 left-0 right-0 z-20 px-6 py-3 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-center justify-center gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>e("/settings?tab=users"),children:r("common.cancel")}),i.jsx(Oe,{onClick:k,disabled:A||!o.trim(),children:A?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),r("common.saving")]}):i.jsxs(i.Fragment,{children:[i.jsx(ts,{className:"w-4 h-4"}),r("common.save")]})})]})]})}const jY={material:"",subtype:"",brand:"",color_name:"",rgba:"808080FF",label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:"",note:"",cost_per_kg:null};function Att(t,e=!1){const n={};return e?(t.material||(n.material="Material is required"),{isValid:Object.keys(n).length===0,errors:n}):(t.slicer_filament||(n.slicer_filament="Slicer preset is required"),t.material||(n.material="Material is required"),t.brand||(n.brand="Brand is required"),t.subtype||(n.subtype="Subtype is required"),{isValid:Object.keys(n).length===0,errors:n})}const Ptt=["PLA","PETG","ABS","TPU","ASA","PC","PA","PVA","HIPS","PA-CF","PETG-CF","PLA-CF"],Mtt=["Bambu","PolyLite","PolyTerra","eSUN","Overture","Fiberon","SUNLU","Inland","Hatchbox","Generic"],u0=["Basic","Matte","Silk","Tough","HF","High Flow","Engineering","Galaxy","Glow","Marble","Metal","Rainbow","Sparkle","Wood","Translucent","Transparent","Clear","Lite","Pro","Plus","Max","Super","Ultra","Flex","Soft","Hard","Strong","Impact","Heat Resistant","UV Resistant","ESD","Conductive","Magnetic","Gradient","Dual Color","Tri Color","Multicolor"],qoe=[{name:"Black",hex:"000000"},{name:"White",hex:"FFFFFF"},{name:"Gray",hex:"808080"},{name:"Red",hex:"FF0000"},{name:"Orange",hex:"FFA500"},{name:"Yellow",hex:"FFFF00"},{name:"Green",hex:"00AE42"},{name:"Blue",hex:"0066FF"},{name:"Purple",hex:"8B00FF"},{name:"Pink",hex:"FF69B4"},{name:"Brown",hex:"8B4513"},{name:"Silver",hex:"C0C0C0"}],Ett=[{name:"Dark Red",hex:"8B0000"},{name:"Crimson",hex:"DC143C"},{name:"Coral",hex:"FF7F50"},{name:"Salmon",hex:"FA8072"},{name:"Dark Orange",hex:"FF8C00"},{name:"Peach",hex:"FFDAB9"},{name:"Gold",hex:"FFD700"},{name:"Khaki",hex:"F0E68C"},{name:"Lemon",hex:"FFF44F"},{name:"Lime",hex:"32CD32"},{name:"Forest Green",hex:"228B22"},{name:"Olive",hex:"808000"},{name:"Mint",hex:"98FF98"},{name:"Teal",hex:"008080"},{name:"Navy",hex:"000080"},{name:"Sky Blue",hex:"87CEEB"},{name:"Royal Blue",hex:"4169E1"},{name:"Cyan",hex:"00FFFF"},{name:"Turquoise",hex:"40E0D0"},{name:"Violet",hex:"EE82EE"},{name:"Magenta",hex:"FF00FF"},{name:"Indigo",hex:"4B0082"},{name:"Lavender",hex:"E6E6FA"},{name:"Plum",hex:"DDA0DD"},{name:"Hot Pink",hex:"FF69B4"},{name:"Rose",hex:"FF007F"},{name:"Blush",hex:"FFB6C1"},{name:"Chocolate",hex:"D2691E"},{name:"Tan",hex:"D2B48C"},{name:"Beige",hex:"F5F5DC"},{name:"Maroon",hex:"800000"},{name:"Dark Gray",hex:"404040"},{name:"Light Gray",hex:"D3D3D3"},{name:"Charcoal",hex:"36454F"},{name:"Ivory",hex:"FFFFF0"},{name:"Bambu Green",hex:"00AE42"},{name:"Jade White",hex:"E8E8E8"},{name:"Titan Gray",hex:"5A5A5A"}],DY=[...qoe,...Ett],Voe="bambuddy-recent-colors",jtt=8,Dtt=[{code:"GFL00",name:"Bambu PLA Basic",displayName:"Bambu PLA Basic",isCustom:!1,allCodes:["GFL00"]},{code:"GFL01",name:"Bambu PLA Matte",displayName:"Bambu PLA Matte",isCustom:!1,allCodes:["GFL01"]},{code:"GFL05",name:"Generic PLA",displayName:"Generic PLA",isCustom:!1,allCodes:["GFL05"]},{code:"GFG00",name:"Bambu PETG Basic",displayName:"Bambu PETG Basic",isCustom:!1,allCodes:["GFG00"]},{code:"GFG05",name:"Generic PETG",displayName:"Generic PETG",isCustom:!1,allCodes:["GFG05"]},{code:"GFB00",name:"Bambu ABS Basic",displayName:"Bambu ABS Basic",isCustom:!1,allCodes:["GFB00"]},{code:"GFB05",name:"Generic ABS",displayName:"Generic ABS",isCustom:!1,allCodes:["GFB05"]},{code:"GFA00",name:"Bambu ASA Basic",displayName:"Bambu ASA Basic",isCustom:!1,allCodes:["GFA00"]},{code:"GFU00",name:"Bambu TPU 95A",displayName:"Bambu TPU 95A",isCustom:!1,allCodes:["GFU00"]},{code:"GFU05",name:"Generic TPU",displayName:"Generic TPU",isCustom:!1,allCodes:["GFU05"]},{code:"GFC00",name:"Bambu PC Basic",displayName:"Bambu PC Basic",isCustom:!1,allCodes:["GFC00"]},{code:"GFN00",name:"Bambu PA Basic",displayName:"Bambu PA Basic",isCustom:!1,allCodes:["GFN00"]},{code:"GFN05",name:"Generic PA",displayName:"Generic PA",isCustom:!1,allCodes:["GFN05"]},{code:"GFS00",name:"Bambu PLA-CF",displayName:"Bambu PLA-CF",isCustom:!1,allCodes:["GFS00"]},{code:"GFT00",name:"Bambu PETG-CF",displayName:"Bambu PETG-CF",isCustom:!1,allCodes:["GFT00"]},{code:"GFNC0",name:"Bambu PA-CF",displayName:"Bambu PA-CF",isCustom:!1,allCodes:["GFNC0"]},{code:"GFV00",name:"Bambu PVA",displayName:"Bambu PVA",isCustom:!1,allCodes:["GFV00"]}];function Ex(t){let e=t.replace(/@.*$/,"").trim();e=e.replace(/\(Custom\)/i,"").trim(),e=e.replace(/^[#*]+\s*/,"").trim();const n=["PLA-CF","PETG-CF","ABS-GF","ASA-CF","PA-CF","PAHT-CF","PA6-CF","PA6-GF","PPA-CF","PPA-GF","PET-CF","PPS-CF","PC-CF","PC-ABS","ABS-GF","PCTG","PETG","PLA","ABS","ASA","PC","PA","TPU","PVA","HIPS","BVOH","PPS","PEEK","PEI"];let r="",a=-1;for(const c of n){const u=e.toUpperCase().indexOf(c.toUpperCase());if(u!==-1){r=c,a=u;break}}let s="";a>0&&(s=e.substring(0,a).trim(),s=s.replace(/[-_\s]+$/,""));let o="";a!==-1&&r&&(o=e.substring(a+r.length).trim(),o=o.replace(/^[-_\s]+/,""));let l="";for(const c of u0)if(o.toLowerCase().includes(c.toLowerCase())){l=c;break}if(!l&&s)for(const c of u0){const u=new RegExp(`\\s+${c}$`,"i");if(u.test(s)){l=c,s=s.replace(u,"").trim();break}}return{brand:s,material:r,variant:l}}function Rtt(t,e){const n=new Set(Mtt);for(const r of t){const{brand:a}=Ex(r.name);a&&a.length>1&&n.add(a)}if(e)for(const r of e)if(r.filament_vendor&&r.filament_vendor.length>1)n.add(r.filament_vendor);else{const{brand:a}=Ex(r.name);a&&a.length>1&&n.add(a)}return Array.from(n).sort((r,a)=>r.localeCompare(a))}function Ftt(t){const e=t.filter(r=>r.preset_type==="filament");if(e.length===0)return[];const n=new Map;for(const r of e){const a=r.name.replace(/@.*$/,"").trim(),s=n.get(a);if(s)s.allCodes.push(String(r.id));else{const o=r.filament_type||String(r.id);n.set(a,{code:o,name:a,displayName:a,isCustom:!1,allCodes:[o]})}}return Array.from(n.values()).sort((r,a)=>r.displayName.localeCompare(a.displayName))}function Ltt(t,e,n){if(t.length>0){const r=[],a=new Map;for(const s of t)if(s.is_custom){const o=s.name.toUpperCase();(e.size===0||Array.from(e).some(c=>o.includes(c))||!o.includes("@"))&&r.push({code:s.setting_id,name:s.name,displayName:`${s.name} (Custom)`,isCustom:!0,allCodes:[s.setting_id]})}else{const o=s.name.replace(/@.*$/,"").trim(),l=a.get(o);l?l.allCodes.push(s.setting_id):a.set(o,{code:s.setting_id,name:o,displayName:o,isCustom:!1,allCodes:[s.setting_id]})}return[...r,...Array.from(a.values())].sort((s,o)=>s.displayName.localeCompare(o.displayName))}if(n&&n.length>0){const r=Ftt(n);if(r.length>0)return r}return Dtt}function Ott(t,e){if(!t)return;let n=e.find(r=>r.code===t);if(n||(n=e.find(r=>r.allCodes.includes(t))),!n){const r=t.toLowerCase();n=e.find(a=>a.code.toLowerCase()===r||a.allCodes.some(s=>s.toLowerCase()===r))}return n}function Itt(){try{const t=localStorage.getItem(Voe);if(t)return JSON.parse(t)}catch{}return[]}function ztt(t,e){const n=e.filter(a=>a.hex.toUpperCase()!==t.hex.toUpperCase()),r=[t,...n].slice(0,jtt);try{localStorage.setItem(Voe,JSON.stringify(r))}catch{}return r}function GD(t,e){if(!e.material)return!1;const r=(t.name||"").replace(/^High Flow[_\s]+/i,"").replace(/^Standard[_\s]+/i,"").replace(/^HF[_\s]+/i,"").replace(/^S[_\s]+/i,"").trim(),a=Ex(r);return!(!(a.material.toUpperCase()===e.material.toUpperCase())||e.brand&&!(a.brand.toLowerCase().includes(e.brand.toLowerCase())||e.brand.toLowerCase().includes(a.brand.toLowerCase()))||e.subtype&&!(a.variant.toLowerCase().includes(e.subtype.toLowerCase())||e.subtype.toLowerCase().includes(a.variant.toLowerCase())||r.toLowerCase().includes(e.subtype.toLowerCase())))}function Utt({formData:t,updateField:e,cloudAuthenticated:n,loadingCloudPresets:r,presetInputValue:a,setPresetInputValue:s,selectedPresetOption:o,filamentOptions:l,availableBrands:c,availableMaterials:u,quickAdd:d,quantity:m,onQuantityChange:p,errors:f}){const{t:y}=Ft(),[v,x]=w.useState(!1),[g,_]=w.useState(!1),[N,T]=w.useState(!1),[C,A]=w.useState(!1),[k,R]=w.useState(""),[P,D]=w.useState(""),[H,z]=w.useState(""),[G,I]=w.useState(String(t.label_weight)),[ee,ie]=w.useState(!1),X=w.useRef(null),me=w.useRef(null),he=w.useRef(null),ge=w.useRef(null);w.useEffect(()=>{const q=Z=>{X.current&&!X.current.contains(Z.target)&&x(!1),ge.current&&!ge.current.contains(Z.target)&&A(!1),me.current&&!me.current.contains(Z.target)&&_(!1),he.current&&!he.current.contains(Z.target)&&T(!1)};return document.addEventListener("mousedown",q),()=>document.removeEventListener("mousedown",q)},[]);const Y=w.useMemo(()=>{if(!a)return l;const q=a.toLowerCase();return l.filter(Z=>Z.displayName.toLowerCase().includes(q)||Z.code.toLowerCase().includes(q))},[l,a]),oe=w.useMemo(()=>{if(!k)return c;const q=k.toLowerCase();return c.filter(j=>j.toLowerCase().includes(q)).sort((j,E)=>{const U=j.toLowerCase()===q,K=E.toLowerCase()===q;return U&&!K?-1:!U&&K?1:j.localeCompare(E)})},[c,k]),le=w.useMemo(()=>{if(!P)return u0;const q=P.toLowerCase();return u0.filter(Z=>Z.toLowerCase().includes(q))},[P]),xe=w.useMemo(()=>{if(!H)return u;const q=H.toLowerCase();return u.filter(j=>j.toLowerCase().includes(q)).sort((j,E)=>{const U=j.toLowerCase()===q,K=E.toLowerCase()===q;return U&&!K?-1:!U&&K?1:j.localeCompare(E)})},[H,u]);w.useEffect(()=>{ee||I(String(t.label_weight))},[t.label_weight,ee]);const Pe=q=>{e("slicer_filament",q.code),s(q.displayName),x(!1);const Z=Ex(q.name);Z.material&&e("material",Z.material),Z.brand&&e("brand",Z.brand),Z.variant&&e("subtype",Z.variant)};return i.jsxs("div",{className:"space-y-4",children:[!d&&i.jsx("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:r?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-3 h-3 animate-spin"})," ",y("inventory.loadingPresets")]}):n?i.jsxs(i.Fragment,{children:[i.jsx(Fx,{className:"w-3 h-3 text-bambu-green"})," ",y("inventory.cloudConnected")]}):i.jsxs(i.Fragment,{children:[i.jsx(spe,{className:"w-3 h-3"})," ",y("inventory.cloudNotConnected")]})}),!d&&i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:[y("inventory.slicerPreset")," *"]}),i.jsxs("div",{className:"relative",ref:X,children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),i.jsx("input",{type:"text",className:"w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:y("inventory.searchPresets"),value:a,onChange:q=>{s(q.target.value),x(!0)},onFocus:()=>{x(!0),s("")}}),v&&i.jsx("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto",children:Y.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:y("inventory.noPresetsFound")}):Y.map(q=>i.jsx("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary truncate ${o?.code===q.code?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>Pe(q),children:q.displayName},q.code))})]}),o&&i.jsxs("div",{className:"mt-1 text-xs text-bambu-gray",children:[y("inventory.selectedPreset"),": ",i.jsx("span",{className:"font-mono text-bambu-green",children:o.code})]}),f?.slicer_filament&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:f.slicer_filament})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:[y("inventory.material")," *"]}),i.jsxs("div",{className:"relative",ref:ge,children:[i.jsx("input",{type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:y("inventory.selectMaterial"),value:C?H:t.material,onChange:q=>{z(q.target.value),A(!0)},onFocus:()=>{A(!0),z("")}}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),C&&i.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[xe.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:y("inventory.noResults")}):xe.map(q=>i.jsx("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${t.material===q?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>{e("material",q),A(!1),z("")},children:q},q)),H&&!xe.includes(H)&&i.jsx("button",{type:"button",className:"w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary",onClick:()=>{e("material",H),A(!1),z("")},children:y("inventory.useCustomMaterial",{material:H})})]})]}),f?.material&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:f.material})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:[y("inventory.brand"),!d&&" *"]}),i.jsxs("div",{className:"relative",ref:me,children:[i.jsx("input",{type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:y("inventory.searchBrand"),value:g?k:t.brand,onChange:q=>{R(q.target.value),_(!0)},onFocus:()=>{_(!0),R("")}}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),g&&i.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[oe.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:y("inventory.noResults")}):oe.map(q=>i.jsx("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${t.brand===q?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>{e("brand",q),_(!1),R("")},children:q},q)),k&&!oe.includes(k)&&i.jsx("button",{type:"button",className:"w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary",onClick:()=>{e("brand",k),_(!1),R("")},children:y("inventory.useCustomBrand",{brand:k})})]})]}),f?.brand&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:f.brand})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:[y("inventory.subtype"),!d&&" *"]}),i.jsxs("div",{className:"relative",ref:he,children:[i.jsx("input",{type:"text",value:N?P:t.subtype,onChange:q=>{D(q.target.value),T(!0)},onFocus:()=>{T(!0),D("")},placeholder:"Basic, Matte, Silk...",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green"}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),N&&i.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[le.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:y("inventory.noResults")}):le.map(q=>i.jsx("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${t.subtype===q?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>{e("subtype",q),T(!1),D("")},children:q},q)),P&&!u0.some(q=>q.toLowerCase()===P.toLowerCase().trim())&&i.jsx("button",{type:"button",className:"w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary",onClick:()=>{e("subtype",P),T(!1),D("")},children:y("inventory.useCustomBrand",{brand:P})})]})]}),f?.subtype&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:f.subtype})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:y("inventory.labelWeight")}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"number",className:"w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green",value:G,min:0,onFocus:()=>ie(!0),onChange:q=>I(q.target.value),onBlur:()=>{ie(!1);const q=G.trim(),Z=Number(q);if(!q||!Number.isFinite(Z)||Z<0){I(String(t.label_weight));return}const j=Math.round(Z);e("label_weight",j),I(String(j))}}),i.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray",children:"g"})]})]}),d&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:y("inventory.quantity")}),i.jsx("input",{type:"number",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",value:m,min:1,max:100,onChange:q=>{const Z=Math.max(1,Math.min(100,parseInt(q.target.value)||1));p(Z)}})]})]})}function Btt({formData:t,updateField:e,recentColors:n,onColorUsed:r,catalogColors:a}){const{t:s}=Ft(),[o,l]=w.useState(!1),[c,u]=w.useState(""),d=t.rgba.replace("#","").substring(0,6),m=g=>d.toUpperCase()===g.toUpperCase(),p=(g,_)=>{e("rgba",g.toUpperCase()+"FF"),e("color_name",_),r({name:_,hex:g})},f=w.useMemo(()=>{if(a.length===0)return[];const g=t.brand?.trim(),_=t.material?.toLowerCase().trim(),N=t.subtype?.toLowerCase().trim();if(!g&&!_)return[];const T=g?g.toLowerCase().split(/[\s\-_]+/).filter(k=>k.length>=2):[],C=k=>{if(T.length===0)return!0;const R=k.toLowerCase();return T.some(P=>R.includes(P))};if(g&&!_){const k=a.filter(R=>C(R.manufacturer));if(k.length>0)return k.map(R=>({name:R.color_name,hex:R.hex_color.replace("#","").substring(0,6),manufacturer:R.manufacturer,material:typeof R.material=="string"?R.material:void 0}))}const A=_&&N?`${_} ${N}`:"";if(A){const k=a.filter(P=>C(P.manufacturer)&&P.material?.toLowerCase()===A);if(k.length>0)return k.map(P=>({name:P.color_name,hex:P.hex_color.replace("#","").substring(0,6),manufacturer:P.manufacturer,material:typeof P.material=="string"?P.material:void 0}));const R=A.replace(/\+$/,"");if(R!==A){const P=a.filter(D=>C(D.manufacturer)&&D.material?.toLowerCase()===R);if(P.length>0)return P.map(D=>({name:D.color_name,hex:D.hex_color.replace("#","").substring(0,6),manufacturer:D.manufacturer,material:typeof D.material=="string"?D.material:void 0}))}}if(_){const k=a.filter(R=>C(R.manufacturer)&&(!R.material||R.material.toLowerCase().startsWith(_)));if(k.length>0)return k.map(R=>({name:R.color_name,hex:R.hex_color.replace("#","").substring(0,6),manufacturer:R.manufacturer,material:typeof R.material=="string"?R.material:void 0}))}return[]},[a,t.brand,t.material,t.subtype]),y=w.useMemo(()=>{if(!c)return f;if(f.length===0)return[];const g=c.toLowerCase();return f.filter(N=>N.name.toLowerCase().includes(g)||(N.manufacturer?.toLowerCase().includes(g)??!1)||(N.material?.toLowerCase().includes(g)??!1))},[c,f]),v=f.length>0,x=w.useMemo(()=>c?DY.filter(g=>g.name.toLowerCase().includes(c.toLowerCase())):o?DY:qoe,[c,o]);return i.jsxs("div",{className:"space-y-3",children:[i.jsx("div",{className:"h-10 rounded-lg border border-bambu-dark-tertiary",style:{backgroundColor:`#${d}`}}),n.length>0&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-bambu-gray shrink-0",children:[i.jsx(er,{className:"w-3 h-3"}),i.jsx("span",{children:s("inventory.recentColors")})]}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:n.map(g=>i.jsx("button",{type:"button",onClick:()=>p(g.hex,g.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 ${m(g.hex)?"border-bambu-green ring-1 ring-bambu-green/30 scale-110":"border-bambu-dark-tertiary"}`,style:{backgroundColor:`#${g.hex}`},title:g.name},g.hex))})]}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),i.jsx("input",{type:"text",className:"w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:s("inventory.searchColors"),value:c,onChange:g=>u(g.target.value)})]}),v?i.jsxs("div",{className:"space-y-1.5",children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:c?s("inventory.searchResults"):`${t.brand}${t.material?` ${t.material}`:""}`}),i.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[y.map(g=>i.jsx("button",{type:"button",onClick:()=>p(g.hex,g.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${m(g.hex)?"border-bambu-green ring-1 ring-bambu-green/30 scale-110":"border-bambu-dark-tertiary"}`,style:{backgroundColor:`#${g.hex}`},title:g.manufacturer&&g.material?`${g.name} (${g.manufacturer} — ${g.material})`:g.manufacturer?`${g.name} (${g.manufacturer})`:g.name,children:i.jsx("span",{className:"absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white",children:g.manufacturer&&g.material?`${g.name} (${g.manufacturer} — ${g.material})`:g.manufacturer?`${g.name} (${g.manufacturer})`:g.name})},`${g.hex}-${g.name}-${g.manufacturer??""}`)),y.length===0&&i.jsx("p",{className:"text-sm text-bambu-gray py-1",children:s("inventory.noColorsFound")})]})]}):i.jsxs("div",{className:"space-y-1.5",children:[i.jsxs("div",{className:"flex items-center justify-between text-xs text-bambu-gray",children:[i.jsx("span",{children:s(c?"inventory.searchResults":o?"inventory.allColors":"inventory.commonColors")}),!c&&i.jsx("button",{type:"button",onClick:()=>l(!o),className:"flex items-center gap-1 hover:text-white transition-colors",children:o?i.jsxs(i.Fragment,{children:[s("inventory.showLess")," ",i.jsx(Il,{className:"w-3 h-3"})]}):i.jsxs(i.Fragment,{children:[s("inventory.showAll")," ",i.jsx(Ln,{className:"w-3 h-3"})]})})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[x.map(g=>i.jsx("button",{type:"button",onClick:()=>p(g.hex,g.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${m(g.hex)?"border-bambu-green ring-1 ring-bambu-green/30 scale-110":"border-bambu-dark-tertiary"}`,style:{backgroundColor:`#${g.hex}`},title:g.name,children:i.jsx("span",{className:"absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white",children:g.name})},g.hex)),x.length===0&&i.jsx("p",{className:"text-sm text-bambu-gray py-1",children:s("inventory.noColorsFound")})]})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:s("inventory.colorName")}),i.jsx("input",{type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:s("inventory.colorNamePlaceholder"),value:t.color_name,onChange:g=>e("color_name",g.target.value)})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:s("inventory.hexColor")}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray",children:"#"}),i.jsx("input",{type:"text",className:"w-full pl-7 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono uppercase focus:outline-none focus:border-bambu-green",placeholder:"RRGGBB",value:d.toUpperCase(),onChange:g=>{const _=g.target.value.replace("#","").replace(/[^0-9A-Fa-f]/g,"");_.length<=8&&e("rgba",_.toUpperCase()+(_.length<=6?"FF":""))}})]}),i.jsx("input",{type:"color",className:"w-11 h-[38px] rounded-lg cursor-pointer border border-bambu-dark-tertiary shrink-0 bg-transparent",value:`#${d}`,onChange:g=>{const _=g.target.value.replace("#","").toUpperCase();e("rgba",_+"FF")},title:s("inventory.pickColor")})]})]})]})]})}function Htt({catalog:t,value:e,onChange:n,catalogId:r,onCatalogIdChange:a}){const{t:s}=Ft(),[o,l]=w.useState(!1),[c,u]=w.useState(""),d=w.useRef(null),m=w.useRef(null);w.useEffect(()=>{const v=x=>{d.current&&!d.current.contains(x.target)&&l(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]),w.useEffect(()=>{if(t.length===0)return;const v=t.filter(x=>x.weight===e);if(r){const x=t.find(g=>g.id===r);if(x&&x.weight===e)return}v.length===1?a(v[0].id):v.length===0&&r!==null&&a(null)},[e,t,r,a]);const p=w.useMemo(()=>{if(!c)return t;const v=c.toLowerCase();return t.filter(x=>x.name.toLowerCase().includes(v)||x.weight.toString().includes(v))},[t,c]),f=w.useMemo(()=>t.filter(v=>v.weight===e),[t,e]),y=w.useMemo(()=>{if(o)return c;if(r){const v=t.find(x=>x.id===r);if(v)return v.name}return f.length>0?f[0].name:""},[o,c,r,t,f]);return i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(Mge,{className:"w-3.5 h-3.5 text-bambu-gray"}),s("inventory.coreWeight")]})}),i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsxs("div",{className:"flex-1 min-w-0 relative",ref:d,children:[i.jsx("input",{ref:m,type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:s("inventory.searchSpoolWeight"),value:y,onFocus:()=>{l(!0),u("")},onChange:v=>{u(v.target.value),l(!0)}}),o&&i.jsx("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto",children:p.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:s("inventory.noResults")}):p.map(v=>i.jsxs("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex justify-between items-center ${(r?v.id===r:v.weight===e)?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>{a(v.id),n(v.weight),l(!1),u("")},children:[i.jsx("span",{className:"truncate",children:v.name}),i.jsxs("span",{className:"font-mono text-xs text-bambu-gray ml-2 shrink-0",children:[v.weight,"g"]})]},v.id))})]}),i.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[i.jsx("input",{type:"number",className:"w-16 px-2 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm text-center font-mono focus:outline-none focus:border-bambu-green",value:e,min:0,max:2e3,onChange:v=>{const x=parseInt(v.target.value);!isNaN(x)&&x>=0&&n(x)}}),i.jsx("span",{className:"text-bambu-gray text-sm",children:"g"})]})]})]})}function $tt({formData:t,updateField:e,spoolCatalog:n,currencySymbol:r}){const{t:a}=Ft(),{showToast:s}=fn(),[o,l]=w.useState(""),[c,u]=w.useState(!1),[d,m]=w.useState(""),[p,f]=w.useState(!1),y=Math.max(0,t.label_weight-t.weight_used),v=t.core_weight+y;return w.useEffect(()=>{c||l(String(v))},[c,v]),w.useEffect(()=>{p||m(String(y))},[p,y]),i.jsxs("div",{className:"space-y-4",children:[i.jsx(Htt,{catalog:n,value:t.core_weight,onChange:x=>e("core_weight",x),catalogId:t.core_weight_catalog_id,onCatalogIdChange:x=>e("core_weight_catalog_id",x)}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:a("inventory.currentWeight")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("input",{type:"number",value:d,min:0,max:t.label_weight,onFocus:()=>f(!0),onChange:x=>{m(x.target.value)},onBlur:()=>{f(!1);const x=d.trim(),g=Number(x);if(!x||!Number.isFinite(g)||g<0||g>t.label_weight){m(String(y));return}const _=Math.round(g);e("weight_used",Math.max(0,t.label_weight-_)),m(String(_))},className:"w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"}),i.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray",children:"g"})]}),i.jsxs("span",{className:"text-xs text-bambu-gray shrink-0",children:["/ ",t.label_weight,"g"]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:a("inventory.measuredWeight")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("input",{type:"number",value:o,min:0,onFocus:()=>u(!0),onChange:x=>{l(x.target.value)},onBlur:()=>{u(!1);const x=o.trim(),g=Number(x),_=t.core_weight,N=t.core_weight+t.label_weight;if(!x||!Number.isFinite(g)||g<_||g>N){s(a("inventory.measuredWeightError",{min:_,max:N}),"error"),l(String(v));return}const T=Math.round(g),C=Math.max(0,Math.min(t.label_weight,T-t.core_weight));e("weight_used",Math.max(0,t.label_weight-C)),l(String(T))},className:"w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"}),i.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray",children:"g"})]}),i.jsxs("span",{className:"text-xs text-bambu-gray shrink-0",children:["/ ",t.core_weight+t.label_weight,"g"]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:a("inventory.costPerKg","Cost per kg")}),i.jsx("div",{className:"flex items-center gap-2",children:i.jsxs("div",{className:"relative flex-1",children:[i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none",children:r}),i.jsx("input",{type:"number",value:t.cost_per_kg??"",min:0,step:.01,placeholder:"0.00",onChange:x=>{const g=x.target.value===""?null:parseFloat(x.target.value);e("cost_per_kg",g)},style:{paddingLeft:`${Math.max(2,r.length*.6+1)}rem`},className:"w-full py-2 pr-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"})]})})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:a("inventory.note")}),i.jsx("textarea",{className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green resize-none min-h-[80px]",placeholder:a("inventory.notePlaceholder"),value:t.note,onChange:x=>e("note",x.target.value)})]})]})}function qtt({formData:t,printersWithCalibrations:e,selectedProfiles:n,setSelectedProfiles:r,expandedPrinters:a,setExpandedPrinters:s}){const{t:o}=Ft(),l=p=>{s(f=>{const y=new Set(f);return y.has(p)?y.delete(p):y.add(p),y})},c=(p,f,y)=>{const v=`${p}:${f}:${y??"null"}`,x=`${p}:${y??"null"}`;r(g=>{const _=new Set(g);if(_.has(v))_.delete(v);else{for(const N of Array.from(_)){const T=N.split(":");`${T[0]}:${T[2]}`===x&&_.delete(N)}_.add(v)}return _})},u=()=>{const p=new Set;for(const{printer:f,calibrations:y}of e){if(!f.connected)continue;const v=y.filter(g=>GD(g,t)),x=new Map;for(const g of v){const _=`${g.extruder_id??"null"}`;x.has(_)||x.set(_,[]),x.get(_).push(g)}for(const[g,_]of x)if(_.length>0){const T=[..._].sort((C,A)=>A.k_value-C.k_value)[0];p.add(`${f.id}:${T.cali_idx}:${g}`)}}r(p)};if(!t.material)return i.jsx("div",{className:"p-6 bg-bambu-dark rounded-lg text-center",children:i.jsx("p",{className:"text-bambu-gray",children:o("inventory.selectMaterialFirst")})});if(e.length===0)return i.jsx("div",{className:"p-6 bg-bambu-dark rounded-lg text-center",children:i.jsx("p",{className:"text-bambu-gray",children:o("inventory.noPrintersConfigured")})});const d=e.reduce((p,{printer:f,calibrations:y})=>f.connected?p+y.filter(v=>GD(v,t)).length:p,0),m=(p,f)=>{const y=`${p.id}:${f.cali_idx}:${f.extruder_id??"null"}`,v=n.has(y);return i.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg cursor-pointer transition-all border ${v?"bg-bambu-green/10 border-bambu-green/30":"bg-bambu-dark border-transparent hover:bg-bambu-dark/80"}`,children:[i.jsx("input",{type:"checkbox",checked:v,onChange:()=>c(String(p.id),f.cali_idx,f.extruder_id),className:"w-4 h-4 rounded border-bambu-dark-tertiary text-bambu-green focus:ring-bambu-green"}),i.jsx("div",{className:"flex-1 min-w-0",children:i.jsx("span",{className:`text-sm font-medium ${v?"text-bambu-green":"text-white"}`,children:f.name||f.filament_id})}),i.jsx("div",{className:"flex items-center gap-2 shrink-0",children:i.jsxs("span",{className:"text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray",children:["K=",f.k_value.toFixed(3)]})})]},`${f.cali_idx}-${f.extruder_id}`)};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("p",{className:"text-xs text-bambu-gray",children:[o("inventory.matchingFilter"),": ",t.brand||o("inventory.anyBrand")," / ",t.material," / ",t.subtype||o("inventory.anyVariant")]}),d>0&&i.jsxs("button",{type:"button",onClick:u,className:"flex items-center gap-1.5 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white hover:border-bambu-green transition-colors",children:[i.jsx(ax,{className:"w-3.5 h-3.5"}),o("inventory.autoSelect")," (",d,")"]})]}),i.jsx("div",{className:"space-y-3",children:e.map(({printer:p,calibrations:f})=>{const y=a.has(String(p.id)),v=f.filter(T=>GD(T,t)),x=v.length,g=v.some(T=>T.extruder_id!==void 0&&T.extruder_id!==null&&T.extruder_id>0),_=v.filter(T=>T.extruder_id===1),N=v.filter(T=>T.extruder_id===0||T.extruder_id===void 0||T.extruder_id===null);return i.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[i.jsxs("button",{type:"button",onClick:()=>l(String(p.id)),className:"w-full px-4 py-3 flex items-center justify-between bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary transition-colors",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[y?i.jsx(Ln,{className:"w-4 h-4 text-bambu-gray"}):i.jsx(ha,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"font-medium text-white",children:p.name}),x>0?i.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green",children:[x," ",o(x!==1?"inventory.matches":"inventory.match")]}):i.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray",children:o("inventory.noMatches")})]}),i.jsx("span",{className:`text-xs px-2 py-1 rounded-full ${p.connected?"bg-green-500/20 text-green-500":"bg-bambu-gray/20 text-bambu-gray"}`,children:p.connected?o("inventory.connected"):o("inventory.offline")})]}),y&&i.jsx("div",{className:"px-4 py-3 space-y-3 bg-bambu-dark border-t border-bambu-dark-tertiary",children:p.connected?x===0?i.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:o("inventory.noKProfilesMatch")}):g?i.jsxs(i.Fragment,{children:[_.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wide",children:o("inventory.leftNozzle")}),i.jsx("div",{className:"space-y-2",children:_.map(T=>m(p,T))})]}),N.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wide",children:o("inventory.rightNozzle")}),i.jsx("div",{className:"space-y-2",children:N.map(T=>m(p,T))})]})]}):i.jsx("div",{className:"space-y-2",children:v.map(T=>m(p,T))}):i.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:o("inventory.printerOffline")})})]},p.id)})}),n.size>0&&i.jsx("div",{className:"p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:i.jsxs("p",{className:"text-sm text-white",children:[i.jsx("span",{className:"font-semibold",children:n.size})," ",o("inventory.profilesSelected")]})})]})}function Vtt(t){const e=new Date(t);return e.toLocaleDateString("en-GB",{day:"2-digit",month:"2-digit",year:"2-digit"})+" "+e.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"})}const Gtt={completed:"text-bambu-green",failed:"text-red-400",aborted:"text-yellow-400"};function Wtt({spoolId:t}){const{t:e}=Ft(),n=an(),{showToast:r}=fn(),{data:a,isLoading:s}=et({queryKey:["spool-usage",t],queryFn:()=>be.getSpoolUsageHistory(t)}),o=pt({mutationFn:()=>be.clearSpoolUsageHistory(t),onSuccess:()=>{n.invalidateQueries({queryKey:["spool-usage",t]}),r(e("inventory.historyCleared"),"success")}});return s?i.jsx("div",{className:"flex justify-center py-4",children:i.jsx(ht,{className:"w-5 h-5 animate-spin text-bambu-green"})}):!a||a.length===0?i.jsxs("div",{className:"text-center py-4 text-bambu-gray text-sm",children:[i.jsx(er,{className:"w-5 h-5 mx-auto mb-2 opacity-50"}),e("inventory.noUsageHistory")]}):i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("h4",{className:"text-sm font-medium text-white",children:e("inventory.usageHistory")}),i.jsxs(Oe,{variant:"ghost",size:"sm",onClick:()=>o.mutate(),disabled:o.isPending,className:"text-xs text-bambu-gray hover:text-red-400",children:[i.jsx(Jt,{className:"w-3 h-3 mr-1"}),e("inventory.clearHistory")]})]}),i.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:a.map(l=>i.jsxs("div",{className:"flex items-center justify-between p-2 rounded bg-bambu-dark/50 text-xs",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("span",{className:"text-bambu-gray",children:Vtt(l.created_at)}),l.print_name&&i.jsx("span",{className:"text-white ml-2 truncate",title:l.print_name,children:l.print_name})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0 ml-2",children:[i.jsxs("span",{className:"text-white font-medium",children:[l.weight_used.toFixed(1),"g"]}),i.jsxs("span",{className:"text-bambu-gray",children:["(",l.percent_used,"%)"]}),i.jsx("span",{className:Gtt[l.status]||"text-bambu-gray",children:l.status})]})]},l.id))})]})}function Ktt({isOpen:t,onClose:e,spool:n,printersWithCalibrations:r=[],currencySymbol:a}){const{t:s}=Ft(),o=an(),{showToast:l}=fn(),c=!!n,[u,d]=w.useState(jY),[m,p]=w.useState({}),[f,y]=w.useState("filament"),[v,x]=w.useState(!1),[g,_]=w.useState(!1),[N,T]=w.useState(1),[C,A]=w.useState(!1),[k,R]=w.useState(!1),[P,D]=w.useState([]),[H,z]=w.useState(""),[G,I]=w.useState([]),[ee,ie]=w.useState([]),[X,me]=w.useState([]),[he,ge]=w.useState([]),[Y,oe]=w.useState([]),[le,xe]=w.useState(new Set),[Pe,q]=w.useState(new Set),Z=r.length>0?r:Y,j=w.useMemo(()=>le.size,[le]);w.useEffect(()=>{ge(Itt())},[]),w.useEffect(()=>{t&&((async()=>{R(!0);try{const de=await be.getCloudStatus();if(A(de.is_authenticated),de.is_authenticated){const Ne=await be.getFilamentPresets();D(Ne)}}catch(de){console.error("Failed to fetch cloud presets:",de),A(!1)}finally{R(!1)}})(),be.getSpoolCatalog().then(I).catch(console.error),be.getColorCatalog().then(me).catch(console.error),be.getLocalPresets().then(de=>ie(de.filament)).catch(console.error),r.length===0&&(async()=>{try{const de=await be.getPrinters(),Ne=await Promise.all(de.map(Le=>be.getPrinterStatus(Le.id).catch(()=>null))),Se=[];for(let Le=0;Le({cali_idx:je.slot_id,filament_id:je.filament_id,setting_id:je.setting_id||"",name:je.name,k_value:parseFloat(je.k_value)||0,n_coef:parseFloat(je.n_coef)||0,extruder_id:je.extruder_id,nozzle_diameter:je.nozzle_diameter}))}catch{}Se.push({printer:{...qe,connected:Te},calibrations:Ae})}oe(Se)}catch(de){console.error("Failed to fetch printer calibrations:",de)}})())},[t,r.length]);const E=w.useMemo(()=>Ltt(P,new Set,ee),[P,ee]),U=w.useMemo(()=>{const pe=Rtt(P,ee),de=X.map(Se=>Se.manufacturer?.trim()).filter(Se=>!!Se),Ne=new Set([...pe,...de]);return Array.from(Ne).sort((Se,Le)=>Se.localeCompare(Le))},[P,ee,X]),K=w.useMemo(()=>{const pe=X.map(Ne=>Ne.material?.trim()).filter(Ne=>!!Ne),de=new Set([...Ptt,...pe]);return Array.from(de).sort((Ne,Se)=>Ne.localeCompare(Se))},[X]),$=w.useMemo(()=>{const pe=[];for(const de of X){const Ne=de.manufacturer?.trim(),Se=de.material?.trim();Ne&&Se&&pe.push({brand:Ne,material:Se})}for(const de of P){const Ne=Ex(de.name);Ne.brand&&Ne.material&&pe.push({brand:Ne.brand,material:Ne.material})}for(const de of ee){const Ne=Ex(de.name),Se=de.filament_vendor?.trim()||Ne.brand,Le=Ne.material;Se&&Le&&pe.push({brand:Se,material:Le})}return pe},[P,X,ee]),ne=w.useMemo(()=>{const pe=new Map;for(const de of $){const Ne=de.brand.toLowerCase(),Se=de.material.toLowerCase();pe.has(Ne)||pe.set(Ne,new Set),pe.get(Ne).add(Se)}return pe},[$]),O=w.useMemo(()=>{const pe=new Map;for(const de of $){const Ne=de.brand.toLowerCase(),Se=de.material.toLowerCase();pe.has(Se)||pe.set(Se,new Set),pe.get(Se).add(Ne)}return pe},[$]),V=w.useMemo(()=>{if(!u.material)return U;const pe=u.material.toLowerCase(),de=O.get(pe);return!de||de.size===0?U:U.filter(Ne=>de.has(Ne.toLowerCase()))},[U,u.material,O]),J=w.useMemo(()=>{if(!u.brand)return K;const pe=u.brand.toLowerCase(),de=ne.get(pe);return!de||de.size===0?K:K.filter(Ne=>de.has(Ne.toLowerCase()))},[K,u.brand,ne]),W=w.useMemo(()=>Ott(u.slicer_filament,E),[u.slicer_filament,E]);w.useEffect(()=>{if(t){if(n)if(d({material:n.material||"",subtype:n.subtype||"",brand:n.brand||"",color_name:n.color_name||"",rgba:n.rgba||"808080FF",label_weight:n.label_weight||1e3,core_weight:n.core_weight||250,core_weight_catalog_id:n.core_weight_catalog_id??null,weight_used:n.weight_used||0,slicer_filament:n.slicer_filament||"",note:n.note||"",cost_per_kg:n.cost_per_kg??null}),z(n.slicer_filament_name||n.slicer_filament||""),n.k_profiles&&n.k_profiles.length>0){const pe=new Set;for(const de of n.k_profiles)de.cali_idx!==null&&de.cali_idx!==void 0&&pe.add(`${de.printer_id}:${de.cali_idx}:${de.extruder??"null"}`);xe(pe)}else xe(new Set);else d(jY),z(""),xe(new Set),_(!1),T(1);p({}),y("filament"),x(!1)}},[t,n]),w.useEffect(()=>{t&&Z.length>0&&q(new Set(Z.map(pe=>String(pe.printer.id))))},[t,Z]);const re=(pe,de)=>{d(Ne=>({...Ne,[pe]:de})),pe==="weight_used"&&x(!0),m[pe]&&p(Ne=>({...Ne,[pe]:void 0}))},ue=pe=>{ge(de=>ztt(pe,de))},fe=pt({mutationFn:pe=>be.createSpool(pe),onSuccess:async pe=>{le.size>0&&pe?.id&&await F(pe.id),await o.invalidateQueries({queryKey:["inventory-spools"]}),l(s("inventory.spoolCreated"),"success"),e()},onError:pe=>{l(pe.message,"error")}}),ye=pt({mutationFn:({data:pe,qty:de})=>be.bulkCreateSpools(pe,de),onSuccess:async pe=>{if(le.size>0)for(const de of pe)await F(de.id);await o.invalidateQueries({queryKey:["inventory-spools"]}),l(s("inventory.spoolsCreated",{count:pe.length}),"success"),e()},onError:pe=>{l(pe.message,"error")}}),ae=pt({mutationFn:pe=>be.updateSpool(n.id,pe),onSuccess:async()=>{n?.id&&await F(n.id),await o.invalidateQueries({queryKey:["inventory-spools"]}),l(s("inventory.spoolUpdated"),"success"),e()},onError:pe=>{l(pe.message,"error")}}),L=pt({mutationFn:()=>be.updateSpool(n.id,{tag_uid:null}),onSuccess:async()=>{await o.invalidateQueries({queryKey:["inventory-spools"]}),l(s("inventory.tagDeleted","Tag removed"),"success"),e()},onError:pe=>{l(pe.message,"error")}}),F=async pe=>{if(le.size===0){try{await be.saveSpoolKProfiles(pe,[])}catch{}return}const de=[];for(const Ne of le){const[Se,Le,qe]=Ne.split(":"),Ee=parseInt(Se),Te=parseInt(Le),Ae=qe==="null"?0:parseInt(qe),Be=Z.find(je=>je.printer.id===Ee);if(Be){const je=Be.calibrations.find(Xe=>Xe.cali_idx===Te);je&&de.push({printer_id:Ee,extruder:Ae,nozzle_diameter:je.nozzle_diameter||"0.4",k_value:je.k_value,name:je.name||null,cali_idx:je.cali_idx,setting_id:je.setting_id||null})}}if(de.length>0)try{await be.saveSpoolKProfiles(pe,de)}catch(Ne){console.error("Failed to save K-profiles:",Ne)}};if(w.useEffect(()=>{if(!t)return;const pe=de=>{de.key==="Escape"&&e()};return document.addEventListener("keydown",pe),()=>document.removeEventListener("keydown",pe)},[t,e]),!t)return null;const te=()=>{const pe=Att(u,g);if(!pe.isValid){p(pe.errors),(pe.errors.slicer_filament||pe.errors.material||pe.errors.brand||pe.errors.subtype)&&y("filament");return}const de=W?.displayName||H||null,Ne={material:u.material,subtype:u.subtype||null,brand:u.brand||null,color_name:u.color_name||null,rgba:u.rgba||null,label_weight:u.label_weight,core_weight:u.core_weight,core_weight_catalog_id:u.core_weight_catalog_id,slicer_filament:u.slicer_filament||null,slicer_filament_name:de,nozzle_temp_min:null,nozzle_temp_max:null,note:u.note||null,cost_per_kg:u.cost_per_kg};(!c||v)&&(Ne.weight_used=u.weight_used),c?ae.mutate(Ne):N>1?ye.mutate({data:Ne,qty:N}):fe.mutate(Ne)},ve=fe.isPending||ye.isPending||ae.isPending||L.isPending;return i.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[i.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),i.jsxs("div",{className:"relative w-full max-w-xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:s(c?"inventory.editSpool":"inventory.addSpool")}),i.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),!c&&i.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-bambu-dark-tertiary flex-shrink-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(kc,{className:"w-4 h-4 text-amber-400"}),i.jsx("span",{className:"text-sm text-white",children:s("inventory.quickAdd")})]}),i.jsx("button",{type:"button",onClick:()=>{_(!g),g||y("filament")},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${g?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:i.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${g?"translate-x-4":"translate-x-0.5"}`})})]}),i.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary flex-shrink-0",children:[i.jsxs("button",{onClick:()=>y("filament"),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${f==="filament"?"text-bambu-green border-b-2 border-bambu-green":"text-bambu-gray hover:text-white"}`,children:[i.jsx(fw,{className:"w-4 h-4"}),s("inventory.filamentInfoTab")]}),!g&&i.jsxs("button",{onClick:()=>y("pa-profile"),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${f==="pa-profile"?"text-bambu-green border-b-2 border-bambu-green":"text-bambu-gray hover:text-white"}`,children:[i.jsx(yhe,{className:"w-4 h-4"}),s("inventory.paProfileTab"),j>0&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green",children:j})]})]}),i.jsx("div",{className:"p-4 overflow-y-auto flex-1",style:{scrollbarGutter:"stable"},children:f==="filament"?i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3",children:s("inventory.filamentInfo")}),i.jsx(Utt,{formData:u,updateField:re,cloudAuthenticated:C,loadingCloudPresets:k,presetInputValue:H,setPresetInputValue:z,selectedPresetOption:W,filamentOptions:E,availableBrands:V,availableMaterials:J,quickAdd:g,quantity:N,onQuantityChange:T,errors:m})]}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3",children:s("inventory.color")}),i.jsx(Btt,{formData:u,updateField:re,recentColors:he,onColorUsed:ue,catalogColors:X})]}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3",children:s("inventory.additional")}),i.jsx($tt,{formData:u,updateField:re,spoolCatalog:G,currencySymbol:a})]}),c&&n&&i.jsx("div",{children:i.jsx(Wtt,{spoolId:n.id})})]}):i.jsx(qtt,{formData:u,updateField:re,printersWithCalibrations:Z,selectedProfiles:le,setSelectedProfiles:xe,expandedPrinters:Pe,setExpandedPrinters:q})}),i.jsxs("div",{className:"flex gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0",children:[c&&i.jsxs(Oe,{variant:"secondary",onClick:()=>L.mutate(),disabled:ve||!n?.tag_uid,className:"mr-auto",children:[i.jsx(Dd,{className:"w-4 h-4"}),s("inventory.deleteTag","Delete Tag")]}),i.jsxs("div",{className:"flex gap-2 ml-auto",children:[i.jsx(Oe,{variant:"secondary",onClick:e,children:s("common.cancel")}),i.jsx(Oe,{onClick:te,disabled:ve,children:ve?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),s("common.saving")]}):i.jsxs(i.Fragment,{children:[i.jsx(ts,{className:"w-4 h-4"}),s(c?"common.save":"inventory.addSpool")]})})]})]})]})]})}function Ytt({isOpen:t,onClose:e,columns:n,defaultColumns:r,onSave:a}){const{t:s}=Ft(),[o,l]=w.useState(n),[c,u]=w.useState(null),d=w.useRef(null);if(w.useEffect(()=>{t&&l(n.map(T=>({...T})))},[t,n]),w.useEffect(()=>{if(!t)return;const T=C=>{C.key==="Escape"&&e()};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[t,e]),!t)return null;const m=T=>{l(C=>C.map((A,k)=>k===T?{...A,visible:!A.visible}:A))},p=(T,C)=>{C<0||C>=o.length||l(A=>{const k=[...A],[R]=k.splice(T,1);return k.splice(C,0,R),k})},f=(T,C)=>{d.current=C,u(C),T.dataTransfer.effectAllowed="move"},y=(T,C)=>{T.preventDefault(),T.dataTransfer.dropEffect="move";const A=d.current;A!==null&&A!==C&&(p(A,C),d.current=C,u(C))},v=T=>{T.preventDefault()},x=()=>{d.current=null,u(null)},g=()=>{l(r.map(T=>({...T})))},_=()=>{a(o),e()},N=o.filter(T=>T.visible).length;return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:e,children:i.jsx(Mt,{className:"w-full max-w-md max-h-[80vh] flex flex-col",onClick:T=>T.stopPropagation(),children:i.jsxs(Dt,{className:"p-6 flex flex-col min-h-0",children:[i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:s("inventory.configureColumns")}),i.jsxs("p",{className:"text-sm text-bambu-gray mb-4",children:[s("inventory.configureColumnsDesc"),i.jsxs("span",{className:"ml-2 text-bambu-gray/60",children:["(",N," ",s("inventory.of")," ",o.length," ",s("inventory.visible"),")"]})]}),i.jsx("div",{className:"space-y-1 overflow-y-auto flex-1 min-h-0 pr-1",children:o.map((T,C)=>i.jsxs("div",{className:`flex items-center gap-2 p-2 rounded-lg border transition-colors ${c===C?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark-tertiary/50"} ${T.visible?"":"opacity-50"}`,draggable:!0,onDragStart:A=>f(A,C),onDragOver:A=>y(A,C),onDrop:v,onDragEnd:x,children:[i.jsx("div",{className:"cursor-grab text-bambu-gray/50 hover:text-bambu-gray",children:i.jsx(bh,{className:"w-4 h-4"})}),i.jsx("span",{className:"flex-1 font-medium text-sm text-white",children:T.label}),i.jsxs("div",{className:"flex items-center gap-0.5",children:[i.jsx("button",{onClick:()=>p(C,C-1),disabled:C===0,className:"p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed",title:s("inventory.moveUp"),children:i.jsx(Il,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>p(C,C+1),disabled:C===o.length-1,className:"p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed",title:s("inventory.moveDown"),children:i.jsx(Ln,{className:"w-4 h-4"})})]}),i.jsx("button",{onClick:()=>m(C),className:`p-1.5 rounded transition-colors ${T.visible?"text-bambu-green hover:bg-bambu-green/10":"text-bambu-gray/50 hover:bg-bambu-dark-secondary"}`,title:T.visible?s("inventory.hideColumn"):s("inventory.showColumn"),children:T.visible?i.jsx(_c,{className:"w-4 h-4"}):i.jsx(mw,{className:"w-4 h-4"})})]},T.id))}),i.jsxs("div",{className:"flex items-center gap-3 mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs(Oe,{variant:"secondary",onClick:g,className:"mr-auto",children:[i.jsx(bo,{className:"w-4 h-4"}),s("inventory.reset")]}),i.jsx(Oe,{variant:"secondary",onClick:e,children:s("inventory.cancel")}),i.jsx(Oe,{onClick:_,children:s("inventory.applyChanges")})]})]})})})}function RY(t){return`${t.material}|${t.subtype||""}|${t.brand||""}|${t.color_name||""}|${t.rgba||""}|${t.label_weight}`}const Goe="bambuddy-inventory-columns",vN=[{id:"id",label:"#",visible:!0},{id:"added_time",label:"Added",visible:!0},{id:"encode_time",label:"Encoded",visible:!1},{id:"last_used_time",label:"Last Used",visible:!1},{id:"rgba",label:"Color",visible:!0},{id:"material",label:"Material",visible:!0},{id:"subtype",label:"Subtype",visible:!0},{id:"color_name",label:"Color Name",visible:!1},{id:"brand",label:"Brand",visible:!0},{id:"slicer_filament",label:"Slicer Filament",visible:!1},{id:"location",label:"Location",visible:!0},{id:"label_weight",label:"Label",visible:!0},{id:"net",label:"Net",visible:!0},{id:"gross",label:"Gross",visible:!1},{id:"added_full",label:"Full",visible:!1},{id:"used",label:"Used",visible:!1},{id:"printed_total",label:"Printed Total",visible:!1},{id:"printed_since_weight",label:"Printed Since Weight",visible:!1},{id:"note",label:"Note",visible:!1},{id:"pa_k",label:"PA(K)",visible:!0},{id:"tag_id",label:"Tag ID",visible:!1},{id:"data_origin",label:"Data Origin",visible:!1},{id:"tag_type",label:"Linked Tag Type",visible:!1},{id:"stock",label:"Stock",visible:!1},{id:"remaining",label:"Remaining",visible:!0},{id:"cost_per_kg",label:"Cost/kg",visible:!1},{id:"weight_check",label:"Weight Check",visible:!1}];function Xtt(){try{const t=localStorage.getItem(Goe);if(t){const e=JSON.parse(t),n=new Set(vN.map(o=>o.id)),r=new Set(e.map(o=>o.id)),a=e.filter(o=>n.has(o.id)),s=vN.filter(o=>!r.has(o.id));return[...a,...s]}}catch{}return vN.map(t=>({...t}))}function Qtt(t){try{localStorage.setItem(Goe,JSON.stringify(t))}catch{}}function iu(t,e=!1){return e&&t>=1e3?`${(t/1e3).toFixed(1)}kg`:`${Math.round(t)}g`}const Ztt={PLA:"bg-green-500/20 text-green-400",ABS:"bg-red-500/20 text-red-400",PETG:"bg-blue-500/20 text-blue-400",TPU:"bg-purple-500/20 text-purple-400",ASA:"bg-orange-500/20 text-orange-400",PA:"bg-yellow-500/20 text-yellow-400",PC:"bg-cyan-500/20 text-cyan-400",PET:"bg-sky-500/20 text-sky-400"};function WD(t,e="system"){if(!t)return"-";const n=Jn(t);return n?S3(n,e):"-"}const Jtt={id:()=>"#",added_time:()=>"Added",encode_time:()=>"Encoded",last_used_time:()=>"Last Used",rgba:t=>t("inventory.color"),material:t=>t("inventory.material"),subtype:t=>t("inventory.subtype"),color_name:t=>t("inventory.colorName"),brand:t=>t("inventory.brand"),slicer_filament:t=>t("inventory.slicerFilament"),location:()=>"Location",label_weight:t=>t("inventory.labelWeight"),net:t=>t("inventory.net"),gross:()=>"Gross",added_full:()=>"Full",used:t=>t("inventory.weightUsed"),printed_total:()=>"Printed Total",printed_since_weight:()=>"Printed Since Weight",note:t=>t("inventory.note"),pa_k:()=>"PA(K)",tag_id:()=>"Tag ID",data_origin:()=>"Data Origin",tag_type:()=>"Linked Tag Type",stock:t=>t("inventory.stock"),remaining:t=>t("inventory.remaining"),cost_per_kg:t=>t("inventory.costPerKg"),weight_check:t=>t("inventory.weightCheck")},vL={id:({spool:t})=>i.jsx("span",{className:"text-sm font-medium text-white",children:t.id}),added_time:({spool:t,dateFormat:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:WD(t.created_at,e)}),encode_time:({spool:t,dateFormat:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:WD(t.encode_time,e)}),last_used_time:({spool:t,dateFormat:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.last_used?WD(t.last_used,e):"Never"}),rgba:({spool:t})=>i.jsx("div",{className:"flex items-center justify-center",children:i.jsx("span",{className:"w-5 h-5 rounded-full border border-white/20 flex-shrink-0",style:{backgroundColor:t.rgba?`#${t.rgba.substring(0,6)}`:"#808080"},title:t.rgba?`#${t.rgba.substring(0,6)}`:void 0})}),material:({spool:t})=>i.jsx("span",{className:"text-sm text-white",children:t.material}),subtype:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.subtype||"-"}),color_name:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:T4(t.color_name,t.rgba)||"-"}),brand:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.brand||"-"}),slicer_filament:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",title:t.slicer_filament||void 0,children:t.slicer_filament_name||t.slicer_filament||"-"}),location:({spool:t,assignmentMap:e})=>{const n=e[t.id];if(!n)return i.jsx("span",{className:"text-sm text-bambu-gray",children:"-"});const r=n.printer_name||`Printer ${n.printer_id}`,a=n.ams_id===254||n.ams_id===255,s=!a&&n.ams_id>=128,o=P4(n.ams_id,n.tray_id,s,a);return i.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-purple-500/20 text-purple-400",children:[r," ",o,n.ams_label?` (${n.ams_label})`:""]})},label_weight:({spool:t})=>i.jsx("span",{className:"text-sm text-white",children:iu(t.label_weight)}),net:({remaining:t})=>i.jsx("span",{className:"text-sm text-white",children:iu(t)}),gross:({spool:t,remaining:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:iu(e+t.core_weight)}),added_full:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.added_full==null?"-":t.added_full?"Yes":"No"}),used:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.weight_used>0?iu(t.weight_used):"-"}),printed_total:()=>i.jsx("span",{className:"text-sm text-bambu-gray/50",children:"-"}),printed_since_weight:()=>i.jsx("span",{className:"text-sm text-bambu-gray/50",children:"-"}),note:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray max-w-[150px] truncate block",title:t.note||void 0,children:t.note||"-"}),pa_k:({spool:t})=>(t.k_profiles?.length??0)===0?i.jsx("span",{className:"text-sm text-bambu-gray",children:"-"}):i.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-bambu-green/20 text-bambu-green",children:"K"}),tag_id:({spool:t})=>{const e=t.tag_uid||t.tray_uuid;return e?i.jsx("span",{className:"text-sm text-bambu-gray font-mono",title:e,children:e.length>12?`${e.slice(0,6)}...${e.slice(-4)}`:e}):i.jsx("span",{className:"text-sm text-bambu-gray/50",children:"-"})},data_origin:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.data_origin||"-"}),tag_type:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.tag_type||"-"}),stock:({spool:t,t:e})=>t.slicer_filament?i.jsx("span",{className:"text-sm text-bambu-gray",children:"-"}):i.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-amber-500/20 text-amber-400",children:e("inventory.stock")}),remaining:({remaining:t,pct:e})=>i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("div",{className:"flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden",children:i.jsx("div",{className:`h-full rounded-full ${e>50?"bg-bambu-green":e>20?"bg-yellow-500":"bg-red-500"}`,style:{width:`${Math.min(e,100)}%`}})}),i.jsxs("span",{className:"text-xs text-bambu-gray min-w-[40px] text-right",children:[Math.round(t),"g"]})]}),cost_per_kg:({spool:t,currencySymbol:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.cost_per_kg!=null?`${e}${t.cost_per_kg.toFixed(2)}`:"-"}),weight_check:({spool:t,onSyncWeight:e})=>{const n=t.last_scale_weight;if(n==null)return i.jsx("span",{className:"text-sm text-bambu-gray/50",title:"No scale measurement",children:"-"});const r=t.core_weight||0,a=Math.max(0,t.label_weight-t.weight_used)+r;let s,o;n0?`+${Math.round(s)}`:`${Math.round(s)}`,c=o?`Scale: ${Math.round(n)}g +`+n+"}"}return String(t)}function Xet({setting:t,onClose:e,onDeleted:n,onDuplicate:r,onEdit:a,hasPermission:s,t:o}){const{showToast:l}=fn(),c=an(),[u,d]=w.useState(!1),{data:m,isLoading:p}=et({queryKey:["cloudSettingDetail",t.setting_id],queryFn:()=>be.getCloudSettingDetail(t.setting_id)}),f=pt({mutationFn:()=>be.deleteCloudSetting(t.setting_id),onSuccess:()=>{l(o("profiles.presets.toast.deleted")),c.invalidateQueries({queryKey:["cloudSettings"]}),n()},onError:x=>l(x.message,"error")}),y=ow(t.setting_id),v=N5(t.name,m?.setting?.inherits);return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:i.jsx(Mt,{className:"w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden",children:i.jsxs(Dt,{className:"p-0 flex flex-col min-h-0 flex-1",children:[i.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("h2",{className:"text-xl font-semibold text-white truncate",children:t.name}),y&&i.jsx("span",{className:"px-2 py-0.5 text-xs font-medium bg-bambu-green/20 text-bambu-green rounded-full",children:o("profiles.presets.editable")})]}),i.jsxs("div",{className:"flex items-center gap-2 mt-1 text-sm text-bambu-gray",children:[i.jsx("span",{className:"capitalize",children:o(`profiles.presets.types.${t.type}`)}),v.printer&&i.jsxs(i.Fragment,{children:[i.jsx("span",{children:"•"}),i.jsx("span",{children:v.printer})]})]})]}),i.jsx("button",{onClick:e,className:"p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto p-4",children:p?i.jsx("div",{className:"flex items-center justify-center py-16",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):m?i.jsx("pre",{className:"text-xs text-bambu-gray font-mono whitespace-pre-wrap break-all bg-bambu-dark p-4 rounded-lg border border-bambu-dark-tertiary overflow-x-auto max-w-full",children:xL(m)}):i.jsx("div",{className:"text-center py-16 text-bambu-gray",children:o("profiles.presets.failedToLoadDetails")})}),u?i.jsxs("div",{className:"flex-shrink-0 p-4 border-t border-bambu-dark-tertiary bg-red-500/5",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3 text-red-400",children:[i.jsx(Mn,{className:"w-5 h-5"}),i.jsx("span",{className:"font-medium",children:o("profiles.presets.deleteConfirm")})]}),i.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:o("profiles.presets.deleteWarning",{name:t.name})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>d(!1),disabled:f.isPending,className:"flex-1",children:o("common.cancel")}),i.jsxs(Oe,{variant:"danger",onClick:()=>f.mutate(),disabled:f.isPending,className:"flex-1",children:[f.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):i.jsx(Jt,{className:"w-4 h-4"}),o("common.delete")]})]})]}):i.jsx("div",{className:"flex-shrink-0 p-4 border-t border-bambu-dark-tertiary",children:i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Oe,{variant:"secondary",onClick:e,className:"flex-1",children:o("common.close")}),i.jsxs(Oe,{variant:"secondary",onClick:r,disabled:!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.presets.noDuplicatePermission"),children:[i.jsx(fo,{className:"w-4 h-4"}),o("profiles.presets.duplicate")]}),y&&i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"secondary",onClick:a,disabled:p||!m||!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.presets.noEditPermission"),children:[i.jsx(Yi,{className:"w-4 h-4"}),o("common.edit")]}),i.jsx(Oe,{variant:"danger",onClick:()=>d(!0),disabled:!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.presets.noDeletePermission"),children:i.jsx(Jt,{className:"w-4 h-4"})})]})]})})]})})})}function zoe(){try{const t=localStorage.getItem("bambusy_preset_templates");return t?JSON.parse(t):[]}catch{return[]}}function Uoe(t){localStorage.setItem("bambusy_preset_templates",JSON.stringify(t))}function Qet({onClose:t,onApply:e,t:n}){const{showToast:r}=fn(),[a,s]=w.useState(zoe),[o,l]=w.useState("all"),[c,u]=w.useState(null),[d,m]=w.useState(""),[p,f]=w.useState(""),[y,v]=w.useState("{}"),[x,g]=w.useState(null),[_,N]=w.useState(null),T=o==="all"?a:a.filter(G=>G.type===o),C=G=>{s(G),Uoe(G)},A=G=>{const I=a.filter(ee=>ee.id!==G);C(I),N(null),r(n("profiles.templates.toast.deleted"))},k=G=>{u(G.id),m(G.name),f(G.description),v(JSON.stringify(G.settings,null,2)),g(null)},R=()=>{if(!(!c||!d.trim()))try{const G=JSON.parse(y),I=a.map(ee=>ee.id===c?{...ee,name:d.trim(),description:p.trim(),settings:G}:ee);C(I),u(null),r(n("profiles.templates.toast.updated"))}catch(G){g(G.message)}},P=()=>{u(null),m(""),f(""),v("{}"),g(null)},D=G=>{const I=a.map(ee=>ee.id===G?{...ee,showInModal:!ee.showInModal}:ee);C(I)},H={filament:{label:n("profiles.presets.types.filament"),icon:YC,color:"text-amber-400"},print:{label:n("profiles.presets.types.process"),icon:jd,color:"text-blue-400"},printer:{label:n("profiles.presets.types.printer"),icon:Sr,color:"text-purple-400"}},z=_?a.find(G=>G.id===_):null;return w.useEffect(()=>{const G=I=>{I.key==="Escape"&&(_?N(null):c?P():t())};return window.addEventListener("keydown",G),()=>window.removeEventListener("keydown",G)},[_,c,t]),i.jsxs("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:[z&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-60",children:i.jsx(Mt,{className:"w-full max-w-md",children:i.jsxs(Dt,{className:"p-6",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[i.jsx("div",{className:"p-2 bg-red-500/20 rounded-lg",children:i.jsx(Mn,{className:"w-6 h-6 text-red-400"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:n("profiles.templates.deleteTitle")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:n("profiles.templates.deleteWarning")})]})]}),i.jsx("p",{className:"text-white mb-6",children:n("profiles.templates.deleteConfirm",{name:z.name})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>N(null),className:"flex-1",children:n("common.cancel")}),i.jsxs(Oe,{onClick:()=>A(_),className:"flex-1 bg-red-500 hover:bg-red-600",children:[i.jsx(Jt,{className:"w-4 h-4"}),n("common.delete")]})]})]})})}),i.jsx(Mt,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",children:i.jsxs(Dt,{className:"p-0 flex flex-col h-full",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(ax,{className:"w-5 h-5 text-amber-400"}),n("profiles.templates.title")]}),i.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"flex items-center gap-2 p-4 border-b border-bambu-dark-tertiary",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:n("profiles.templates.typeFilter")}),["all","filament","print","printer"].map(G=>i.jsx("button",{onClick:()=>l(G),className:`px-3 py-1 text-sm rounded-lg transition-colors ${o===G?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:G==="all"?n("common.all"):H[G].label},G))]}),i.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:T.length===0?i.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[i.jsx(ax,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),i.jsx("p",{children:n("profiles.templates.noTemplates")}),i.jsx("p",{className:"text-sm mt-1",children:n("profiles.templates.createFirst")})]}):i.jsx("div",{className:"space-y-2",children:T.map(G=>{const I=H[G.type],ee=I.icon;return c===G.id?i.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg border border-bambu-green",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-3 mb-3",children:[i.jsx("input",{type:"text",value:d,onChange:ie=>m(ie.target.value),placeholder:n("profiles.templates.namePlaceholder"),className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",autoFocus:!0}),i.jsx("input",{type:"text",value:p,onChange:ie=>f(ie.target.value),placeholder:n("profiles.templates.descriptionPlaceholder"),className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{className:"mb-3",children:[i.jsx("label",{className:"text-xs text-bambu-gray mb-1 block",children:n("profiles.templates.settingsJson")}),i.jsx("textarea",{value:y,onChange:ie=>{v(ie.target.value),g(null)},rows:6,className:`w-full px-3 py-2 bg-bambu-dark-secondary border rounded text-white text-sm font-mono focus:outline-none ${x?"border-red-500":"border-bambu-dark-tertiary focus:border-bambu-green"}`}),x&&i.jsx("p",{className:"text-xs text-red-400 mt-1",children:x})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Oe,{size:"sm",onClick:R,disabled:!d.trim(),children:[i.jsx(ts,{className:"w-4 h-4"}),"Save"]}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:P,children:"Cancel"})]})]},G.id):i.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary hover:border-bambu-gray-dark transition-colors",children:[i.jsx(ee,{className:`w-5 h-5 ${I.color} flex-shrink-0`}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-sm font-medium text-white",children:G.name}),i.jsx("p",{className:"text-xs text-bambu-gray truncate",children:G.description})]}),i.jsx("span",{className:"text-xs text-bambu-gray-dark px-2 py-1 bg-bambu-dark-secondary rounded",children:n("profiles.templates.fieldsCount",{count:Object.keys(G.settings).length})}),i.jsx("button",{onClick:()=>D(G.id),className:`p-1 transition-colors ${G.showInModal?"text-bambu-green hover:text-bambu-green/70":"text-bambu-gray hover:text-white"}`,title:G.showInModal?n("profiles.templates.shownInModals"):n("profiles.templates.hiddenInModals"),children:G.showInModal?i.jsx(_c,{className:"w-4 h-4"}):i.jsx(mw,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>e(G),className:"px-3 py-1 text-xs bg-bambu-green/20 text-bambu-green rounded hover:bg-bambu-green/30 transition-colors",children:n("profiles.templates.apply")}),i.jsx("button",{onClick:()=>k(G),className:"p-1 text-bambu-gray hover:text-white",title:n("common.edit"),children:i.jsx(Yi,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>N(G.id),className:"p-1 text-bambu-gray hover:text-red-400",title:n("common.delete"),children:i.jsx(Jt,{className:"w-4 h-4"})})]},G.id)})})})]})})]})}function Boe({onClose:t,leftPreset:e,rightPreset:n,leftLabel:r,rightLabel:a,t:s}){const[o,l]=w.useState("changes"),[c,u]=w.useState(""),d=w.useMemo(()=>{const y=new Set([...Object.keys(e),...Object.keys(n)]),v=[];for(const x of y){if(x==="inherits"||x==="version")continue;const g=e[x],_=n[x],N=x in e,T=x in n;let C;!N&&T?C="added":N&&!T?C="removed":JSON.stringify(g)!==JSON.stringify(_)?C="changed":C="same",v.push({key:x,left:g,right:_,status:C})}return v.sort((x,g)=>{const _={changed:0,added:1,removed:2,same:3};return _[x.status]!==_[g.status]?_[x.status]-_[g.status]:x.key.localeCompare(g.key)})},[e,n]),m=w.useMemo(()=>{let y=[...d];if(o==="changes"&&(y=y.filter(v=>v.status!=="same")),c){const v=c.toLowerCase();y=y.filter(x=>x.key.toLowerCase().includes(v)||String(x.left).toLowerCase().includes(v)||String(x.right).toLowerCase().includes(v))}return y},[d,o,c]),p=w.useMemo(()=>({added:d.filter(y=>y.status==="added").length,removed:d.filter(y=>y.status==="removed").length,changed:d.filter(y=>y.status==="changed").length,same:d.filter(y=>y.status==="same").length}),[d]),f=y=>{if(y===void 0)return"—";if(y===null)return"null";if(Array.isArray(y))return y.length===0?"[]":y.length===1?String(y[0]):y.join(", ");if(typeof y=="object")return JSON.stringify(y);const v=String(y);if(v.includes("\\n")||v.length>100){const x=v.split("\\n").length;if(x>1)return`[${x} lines of G-code/script]`;if(v.length>100)return v.substring(0,100)+"…"}return v};return w.useEffect(()=>{const y=v=>{v.key==="Escape"&&t()};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[t]),i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsx(Mt,{className:"w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden",children:i.jsxs(Dt,{className:"p-0 flex flex-col min-h-0 flex-1",children:[i.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(zb,{className:"w-5 h-5 text-blue-400"}),s("profiles.diff.title")]}),i.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"flex-shrink-0 grid grid-cols-2 gap-4 p-4 border-b border-bambu-dark-tertiary bg-bambu-dark",children:[i.jsxs("div",{className:"text-center",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:s("profiles.diff.left")}),i.jsx("p",{className:"text-white font-medium truncate",children:r})]}),i.jsxs("div",{className:"text-center",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:s("profiles.diff.right")}),i.jsx("p",{className:"text-white font-medium truncate",children:a})]})]}),i.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[i.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[i.jsx(ar,{className:"w-3.5 h-3.5"}),p.added," ",s("profiles.diff.added")]}),i.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[i.jsx(jN,{className:"w-3.5 h-3.5"}),p.removed," ",s("profiles.diff.removed")]}),i.jsxs("span",{className:"flex items-center gap-1 text-amber-400",children:[i.jsx(p3,{className:"w-3.5 h-3.5"}),p.changed," ",s("profiles.diff.changed")]}),i.jsxs("span",{className:"flex items-center gap-1 text-bambu-gray",children:[i.jsx(BM,{className:"w-3.5 h-3.5"}),p.same," ",s("profiles.diff.same")]})]}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:c,onChange:y=>u(y.target.value),placeholder:s("profiles.diff.searchFields"),className:"pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none w-48"})]}),p.same>0&&i.jsxs("div",{className:"flex rounded overflow-hidden border border-bambu-dark-tertiary",children:[i.jsx("button",{onClick:()=>l("changes"),className:`px-3 py-1.5 text-sm transition-colors ${o==="changes"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:s("profiles.diff.changes")}),i.jsx("button",{onClick:()=>l("all"),className:`px-3 py-1.5 text-sm transition-colors ${o==="all"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:s("common.all")})]})]})]}),i.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:m.length===0?i.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[i.jsx(BM,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),i.jsx("p",{children:s(o==="changes"?"profiles.diff.noDifferences":"profiles.diff.noFieldsMatch")})]}):i.jsxs("table",{className:"w-full",children:[i.jsx("thead",{className:"sticky top-0 bg-bambu-dark-secondary",children:i.jsxs("tr",{className:"text-sm text-bambu-gray border-b border-bambu-dark-tertiary",children:[i.jsx("th",{className:"text-left p-3 w-1/3",children:s("profiles.diff.field")}),i.jsx("th",{className:"text-left p-3 w-1/3",children:r}),i.jsx("th",{className:"text-left p-3 w-1/3",children:a})]})}),i.jsx("tbody",{children:m.map(y=>{const v={added:"bg-green-500/10",removed:"bg-red-500/10",changed:"bg-amber-500/10",same:""}[y.status],x={added:i.jsx(ar,{className:"w-3.5 h-3.5 text-green-400"}),removed:i.jsx(jN,{className:"w-3.5 h-3.5 text-red-400"}),changed:i.jsx(p3,{className:"w-3.5 h-3.5 text-amber-400"}),same:i.jsx(BM,{className:"w-3.5 h-3.5 text-bambu-gray-dark"})}[y.status];return i.jsxs("tr",{className:`border-b border-bambu-dark-tertiary ${v}`,children:[i.jsx("td",{className:"p-3",children:i.jsxs("div",{className:"flex items-center gap-2",children:[x,i.jsx("span",{className:"text-sm text-white font-mono",children:y.key})]})}),i.jsx("td",{className:"p-3",children:i.jsx("span",{className:`text-sm font-mono break-all ${y.status==="removed"?"text-red-300":y.status==="changed"?"text-white":"text-bambu-gray"}`,children:f(y.left)})}),i.jsx("td",{className:"p-3",children:i.jsx("span",{className:`text-sm font-mono break-all ${y.status==="added"?"text-green-300":y.status==="changed"?"text-white":"text-bambu-gray"}`,children:f(y.right)})})]},y.key)})})]})})]})})})}function Zet({onClose:t,initialData:e,allPresets:n,t:r}){const{showToast:a}=fn(),s=an(),o=!!e?.setting_id,[l,c]=w.useState("common"),[u,d]=w.useState(e?.type||"filament"),[m,p]=w.useState(e?.name?o?e.name:`${e.name} (Copy)`:""),[f,y]=w.useState(e?.base_id||""),[v,x]=w.useState(""),[g,_]=w.useState(e?.setting||{inherits:""}),[N,T]=w.useState(JSON.stringify(e?.setting||{inherits:""},null,2)),[C,A]=w.useState(null),[k,R]=w.useState(""),[P,D]=w.useState(!1),[H,z]=w.useState(""),[G,I]=w.useState(!1),[ee,ie]=w.useState(zoe),[X,me]=w.useState(!1),[he,ge]=w.useState(""),[Y,oe]=w.useState(""),[le,xe]=w.useState(!0),[Pe,q]=w.useState(null),[Z,j]=w.useState(!1),E=w.useMemo(()=>({filament:n.filament,print:n.process,printer:n.printer})[u]||[],[n,u]),U=w.useMemo(()=>E.filter(Ae=>ow(Ae.setting_id)),[E]),{data:K}=et({queryKey:["cloudFields",u],queryFn:()=>be.getCloudFields(u==="print"?"process":u),staleTime:1e3*60*60}),{data:$}=et({queryKey:["allPresetDetails",u,U.map(Ae=>Ae.setting_id).join(",")],queryFn:async()=>{const Ae={};for(let je=0;je{try{const Ce=await be.getCloudSettingDetail(Ie.setting_id);return{id:Ie.setting_id,detail:Ce}}catch{return null}}))).forEach(Ie=>{Ie&&(Ae[Ie.id]=Ie.detail)})}return Ae},enabled:U.length>0,staleTime:1e3*60*10}),{data:ne,isLoading:O}=et({queryKey:["cloudSettingDetail",f],queryFn:()=>be.getCloudSettingDetail(f),enabled:!!f});w.useEffect(()=>{l!=="json"&&T(JSON.stringify(g,null,2))},[g,l]);const V=w.useMemo(()=>({filament:n.filament,print:n.process,printer:n.printer}[u]||[]).filter(Be=>!ow(Be.setting_id)).sort((Be,je)=>Be.name.localeCompare(je.name)),[n,u]);w.useEffect(()=>{if(!f)return;const Ae=V.find(Be=>Be.setting_id===f);Ae&&(x(Ae.name),o||(_({inherits:Ae.name}),T(JSON.stringify({inherits:Ae.name},null,2))))},[f,V,o]);const J=w.useMemo(()=>{const Ae=K?.fields||[],Be=new Set(Ae.map(Ie=>Ie.key)),je=new Set,Xe=new Set(["inherits","updated_time","compatible_printers","compatible_prints"]);$&&Object.values($).forEach(Ie=>{Ie?.setting&&Object.keys(Ie.setting).forEach(Ce=>{!Be.has(Ce)&&!Xe.has(Ce)&&je.add(Ce)})}),Object.keys(g).forEach(Ie=>{!Be.has(Ie)&&!Xe.has(Ie)&&je.add(Ie)});const ce=Array.from(je).sort().map(Ie=>({key:Ie,label:Ie.replace(/_/g," ").replace(/\b\w/g,Ce=>Ce.toUpperCase()),type:"text",category:"discovered",description:r("profiles.presets.discoveredFromPresets")}));return[...Ae,...ce]},[K,$,g,r]),W=J.filter(Ae=>Ae.label.toLowerCase().includes(k.toLowerCase())||Ae.key.toLowerCase().includes(k.toLowerCase())),re=()=>{if(H.trim()){const Ae=H.trim().toLowerCase().replace(/\s+/g,"_");ue(Ae,""),z(""),I(!1),a(r("profiles.presets.toast.fieldAdded",{key:Ae}))}},ue=(Ae,Be)=>{_(je=>{const Xe={...je};return Be===""||Be===void 0?delete Xe[Ae]:Xe[Ae]=Be,Xe})},fe=Ae=>{_(Be=>({...Be,...Ae.settings})),q(Ae.name),a(r("profiles.templates.toast.applied"))},ye=()=>{if(!he.trim())return;const Ae={...g};if(delete Ae.inherits,Object.keys(Ae).length===0){a(r("profiles.presets.noOverridesToSave"),"error");return}const Be={id:Date.now().toString(),name:he.trim(),description:Y.trim()||r("profiles.presets.customTemplate"),type:u,settings:Ae,showInModal:le},je=[...ee,Be];ie(je),Uoe(je),me(!1),ge(""),oe(""),xe(!0),a(r("profiles.templates.toast.created"))},ae=w.useMemo(()=>ee.filter(Ae=>Ae.type===u&&Ae.showInModal),[u,ee]),L=Ae=>{T(Ae);try{const Be=JSON.parse(Ae);_(Be),A(null)}catch(Be){A(Be.message)}},F=Ae=>{Ae.preventDefault(),D(!1);const Be=Ae.dataTransfer.files[0];if(Be&&Be.name.endsWith(".json")){const je=new FileReader;je.onload=Xe=>{try{const ce=Xe.target?.result,Ie=JSON.parse(ce),Ce=Ie.setting||Ie;_(Ge=>({...Ge,...Ce})),T(JSON.stringify({...g,...Ce},null,2)),a(r("profiles.presets.fileImported"))}catch{a(r("profiles.presets.invalidJsonFile"),"error")}},je.readAsText(Be)}},te=pt({mutationFn:()=>{const Ae={...g},Be=u==="filament"?"filament_settings_id":u==="print"?"print_settings_id":"printer_settings_id";Ae[Be]=`"${m}"`;const je={type:u,name:m,base_id:f,setting:Ae};return be.createCloudSetting(je)},onSuccess:async()=>{a(r("profiles.presets.toast.created")),await s.refetchQueries({queryKey:["cloudSettings"]}),t()},onError:Ae=>a(Ae.message,"error")}),ve=pt({mutationFn:()=>{if(!e?.setting_id)throw new Error(r("profiles.presets.noSettingId"));return be.updateCloudSetting(e.setting_id,{name:m,setting:g})},onSuccess:async()=>{a(r("profiles.presets.toast.updated")),s.removeQueries({queryKey:["cloudSettingDetail"]}),await s.refetchQueries({queryKey:["cloudSettings"]}),t()},onError:Ae=>a(Ae.message,"error")}),pe=o?ve:te,de=ne?.setting?.inherits,Ne=de?V.find(Ae=>Ae.name===de):void 0,{data:Se}=et({queryKey:["cloudSettingDetail",Ne?.setting_id],queryFn:()=>be.getCloudSettingDetail(Ne.setting_id),enabled:!!Ne?.setting_id}),Le=w.useMemo(()=>{const Ae=Se?.setting||{},Be=ne?.setting||{},je=f&&$?.[f]?.setting?$[f].setting:{};return{...Ae,...Be,...je}},[f,ne,Se,$]),qe=Ae=>{if(Ae==null)return"";if(Array.isArray(Ae)){const Be=[...new Set(Ae.map(je=>String(je)))];return Be.length===1?Be[0]:Ae.join(", ")}return String(Ae)},Ee=Ae=>{const Be=g[Ae.key],je=Le[Ae.key],Xe=qe(je),ce=O?r("common.loading"):Xe||"",Ie="w-full px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none";if(Ae.type==="boolean"){const Ce=Be==="1"||Be===void 0&&je==="1";return i.jsx("button",{type:"button",onClick:()=>ue(Ae.key,Be==="1"?"0":"1"),className:`w-8 h-5 rounded-full transition-colors ${Ce?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:i.jsx("div",{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${Ce?"translate-x-3.5":"translate-x-0.5"}`})})}return Ae.type==="select"?i.jsxs("select",{value:Be||"",onChange:Ce=>ue(Ae.key,Ce.target.value),className:Ie,children:[i.jsx("option",{value:"",children:ce}),Ae.options?.map(Ce=>i.jsx("option",{value:Ce.value,children:Ce.label},Ce.value))]}):i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:Ae.type==="number"?"number":"text",value:Be!==void 0?String(Be):"",onChange:Ce=>ue(Ae.key,Ce.target.value),step:Ae.step,min:Ae.min,max:Ae.max,placeholder:ce,className:Ie}),Ae.unit&&i.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:Ae.unit})]})},Te=w.useMemo(()=>ne?.setting?ne.setting:{},[ne]);return i.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onDragOver:Ae=>{Ae.preventDefault(),D(!0)},onDragLeave:()=>D(!1),onDrop:F,children:[Z&&f&&i.jsx(Boe,{onClose:()=>j(!1),leftPreset:Te,rightPreset:g,leftLabel:r("profiles.presets.baseLabel",{name:v||f}),rightLabel:r("profiles.presets.currentLabel",{name:m||r("profiles.presets.newPreset")}),t:r}),i.jsx(Mt,{className:"w-full max-w-6xl max-h-[90vh] flex flex-col overflow-y-auto",children:i.jsxs(Dt,{className:"p-0 flex flex-col h-full",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("h2",{className:"text-xl font-semibold text-white",children:r(o?"profiles.presets.editPreset":e?"profiles.presets.duplicatePreset":"profiles.presets.createNewPreset")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:r("profiles.presets.customizeSettings")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[f&&i.jsxs("button",{onClick:()=>j(!0),className:"flex items-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",title:r("profiles.presets.compareWithBase"),children:[i.jsx(zb,{className:"w-4 h-4"}),r("profiles.presets.compare")]}),i.jsx("button",{onClick:t,className:"p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]})]}),P&&i.jsx("div",{className:"absolute inset-0 bg-bambu-green/10 border-2 border-dashed border-bambu-green rounded-lg flex items-center justify-center z-10",children:i.jsxs("div",{className:"text-center",children:[i.jsx(xi,{className:"w-12 h-12 text-bambu-green mx-auto mb-2"}),i.jsx("p",{className:"text-bambu-green font-medium",children:r("profiles.presets.dropJsonToImport")})]})}),i.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary space-y-3",children:[i.jsxs("div",{className:"grid grid-cols-3 gap-4 max-[640px]:grid-cols-1",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("common.type")}),i.jsxs("select",{value:u,onChange:Ae=>{d(Ae.target.value),y("")},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:[i.jsx("option",{value:"filament",children:r("profiles.presets.types.filament")}),i.jsx("option",{value:"print",children:r("profiles.presets.types.process")}),i.jsx("option",{value:"printer",children:r("profiles.presets.types.printer")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("profiles.presets.basePreset")}),i.jsxs("select",{value:f,onChange:Ae=>y(Ae.target.value),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",children:[i.jsx("option",{value:"",children:r("profiles.presets.selectBasePreset")}),V.map(Ae=>i.jsx("option",{value:Ae.setting_id,children:Ae.name},Ae.setting_id))]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("profiles.presets.presetName")}),i.jsx("input",{type:"text",value:m,onChange:Ae=>p(Ae.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",placeholder:r("profiles.presets.myCustomPreset")})]})]}),v&&i.jsx("div",{className:"text-xs text-bambu-gray",children:i.jsxs("p",{className:"flex items-center gap-1",children:[i.jsx(Yr,{className:"w-3 h-3 text-bambu-green"}),r("profiles.presets.inheritsFrom")," ",i.jsx("span",{className:"text-white",children:v}),O&&i.jsx(ht,{className:"w-3 h-3 animate-spin ml-1"})]})})]}),i.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary max-[640px]:flex-wrap max-[640px]:items-center",children:[i.jsxs("button",{onClick:()=>c("common"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l==="common"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(G8,{className:"w-4 h-4"}),r("profiles.presets.tabs.common")]}),i.jsxs("button",{onClick:()=>c("fields"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l==="fields"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(JC,{className:"w-4 h-4"}),r("profiles.presets.tabs.allFields")]}),i.jsxs("button",{onClick:()=>c("json"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l==="json"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(HX,{className:"w-4 h-4"}),"JSON",C&&i.jsx(Li,{className:"w-3 h-3 text-red-400"})]}),i.jsx("div",{className:"flex-1 max-[640px]:hidden"}),i.jsxs("button",{onClick:()=>{const Ae={name:m,type:u,base_id:f,setting:g},Be=new Blob([JSON.stringify(Ae,null,2)],{type:"application/json"}),je=URL.createObjectURL(Be),Xe=document.createElement("a");Xe.href=je,Xe.download=`${m||"preset"}.json`,document.body.appendChild(Xe),Xe.click(),document.body.removeChild(Xe),URL.revokeObjectURL(je),a(r("profiles.presets.toast.exported"))},className:"flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors",title:r("profiles.presets.exportToJson"),children:[i.jsx(pi,{className:"w-4 h-4"}),r("common.download")]}),i.jsxs("button",{onClick:()=>document.getElementById("file-import")?.click(),className:"flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors",title:r("profiles.presets.importFromJson"),children:[i.jsx(xi,{className:"w-4 h-4"}),r("common.upload")]}),i.jsx("input",{id:"file-import",type:"file",accept:".json",className:"hidden",onChange:Ae=>{const Be=Ae.target.files?.[0];if(Be){const je=new FileReader;je.onload=Xe=>{try{const ce=JSON.parse(Xe.target?.result),Ie=ce.setting||ce;_(Ce=>({...Ce,...Ie})),a(r("profiles.presets.fileImported"))}catch{a(r("profiles.presets.invalidJson"),"error")}},je.readAsText(Be)}}})]}),i.jsxs("div",{className:"flex-1 p-4",children:[l==="common"&&i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[i.jsx(ax,{className:"w-4 h-4 text-amber-400"}),r("profiles.templates.title")]}),Object.keys(g).filter(Ae=>Ae!=="inherits").length>0&&i.jsxs("button",{onClick:()=>me(!X),className:"text-xs text-bambu-gray hover:text-white flex items-center gap-1 transition-colors",children:[i.jsx(ts,{className:"w-3 h-3"}),r("profiles.presets.saveAsTemplate")]})]}),X&&i.jsxs("div",{className:"mb-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-2 mb-2",children:[i.jsx("input",{type:"text",value:he,onChange:Ae=>ge(Ae.target.value),placeholder:r("profiles.templates.namePlaceholder"),className:"px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",autoFocus:!0}),i.jsx("input",{type:"text",value:Y,onChange:Ae=>oe(Ae.target.value),placeholder:r("profiles.templates.descriptionPlaceholder"),className:"px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Oe,{size:"sm",onClick:ye,disabled:!he.trim(),children:[i.jsx(ts,{className:"w-3 h-3"}),r("common.save")]}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:()=>me(!1),children:r("common.cancel")})]}),i.jsxs("button",{onClick:()=>xe(!le),className:`flex items-center gap-1.5 text-xs transition-colors ${le?"text-bambu-green":"text-bambu-gray hover:text-white"}`,children:[le?i.jsx(_c,{className:"w-3.5 h-3.5"}):i.jsx(mw,{className:"w-3.5 h-3.5"}),r(le?"profiles.templates.shownInModals":"profiles.templates.hiddenInModals")]})]})]}),Pe&&i.jsxs("div",{className:"mb-3 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg flex items-center gap-2",children:[i.jsx(Yr,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("span",{className:"text-sm text-bambu-green",children:[r("profiles.presets.templateApplied")," ",i.jsx("span",{className:"font-medium",children:Pe})]}),i.jsx("button",{onClick:()=>q(null),className:"ml-auto text-bambu-green/70 hover:text-bambu-green",children:i.jsx(Ht,{className:"w-4 h-4"})})]}),i.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[ae.map(Ae=>i.jsxs("button",{onClick:()=>fe(Ae),className:"p-3 text-left bg-bambu-dark border border-bambu-dark-tertiary rounded-lg hover:border-bambu-gray-dark transition-colors",children:[i.jsx("p",{className:"text-sm font-medium text-white",children:Ae.name}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:Ae.description})]},Ae.id)),ae.length===0&&i.jsx("p",{className:"col-span-3 text-center text-bambu-gray text-sm py-4",children:r("profiles.presets.noTemplatesSelected")})]}),i.jsx("p",{className:"text-xs text-bambu-gray-dark mt-2 text-center",children:r("profiles.presets.manageTemplatesHint")})]}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:r("profiles.presets.commonSettings")}),i.jsx("div",{className:"grid grid-cols-2 gap-x-6 gap-y-3",children:J.slice(0,10).map(Ae=>i.jsxs("div",{className:"flex items-center justify-between gap-4 max-[640px]:flex-col max-[640px]:items-start",children:[i.jsx("label",{className:"text-sm text-bambu-gray flex-shrink-0",children:Ae.label}),i.jsx("div",{className:"w-48 max-[640px]:w-full",children:Ee(Ae)})]},Ae.key))})]}),Object.keys(g).length>1&&i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:r("profiles.presets.currentOverrides")}),i.jsx("div",{className:"flex flex-wrap gap-2",children:Object.entries(g).filter(([Ae])=>Ae!=="inherits").map(([Ae,Be])=>i.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-green/10 text-bambu-green text-xs rounded",children:[Ae,": ",String(Be).slice(0,20),i.jsx("button",{onClick:()=>ue(Ae,void 0),className:"hover:text-white",children:i.jsx(Ht,{className:"w-3 h-3"})})]},Ae))})]})]}),l==="fields"&&i.jsxs("div",{className:"grid grid-cols-2 gap-6",style:{height:"400px"},children:[i.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3 flex-shrink-0",children:[i.jsx("h3",{className:"text-sm font-medium text-white",children:r("profiles.presets.availableFields")}),i.jsx("span",{className:"text-xs text-bambu-gray",children:$?r("profiles.templates.fieldsCount",{count:J.length}):r("common.loading")})]}),i.jsxs("div",{className:"relative mb-3 flex-shrink-0",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:k,onChange:Ae=>R(Ae.target.value),placeholder:r("profiles.presets.searchFieldsPlaceholder"),className:"w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto space-y-1 pr-2 min-h-0",children:[W.filter(Ae=>!(Ae.key in g)).map(Ae=>{const Be=Le[Ae.key],je=qe(Be);return i.jsxs("div",{onClick:()=>{_(Xe=>({...Xe,[Ae.key]:je||""}))},className:"flex items-center justify-between gap-2 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors cursor-pointer group",children:[i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"text-sm text-white truncate",children:Ae.label}),i.jsx("p",{className:"text-xs text-bambu-gray-dark truncate",children:Ae.key})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[je&&i.jsxs("span",{className:"text-xs text-bambu-gray bg-bambu-dark px-2 py-0.5 rounded max-w-32 truncate",title:je,children:[je.slice(0,20),je.length>20?"...":""]}),i.jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded bg-bambu-dark-tertiary group-hover:bg-bambu-green/20 transition-colors",children:i.jsx(ar,{className:"w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors"})})]})]},Ae.key)}),W.filter(Ae=>!(Ae.key in g)).length===0&&i.jsx("p",{className:"text-center text-bambu-gray py-4 text-sm",children:r(k?"profiles.presets.noMatchingFields":"profiles.presets.allFieldsAdded")})]}),i.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0",children:G?i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"text",value:H,onChange:Ae=>z(Ae.target.value),onKeyDown:Ae=>Ae.key==="Enter"&&re(),placeholder:"custom_field_name",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",autoFocus:!0}),i.jsx(Oe,{size:"sm",onClick:re,disabled:!H.trim(),children:i.jsx(ar,{className:"w-4 h-4"})}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:()=>{I(!1),z("")},children:i.jsx(Ht,{className:"w-4 h-4"})})]}):i.jsxs("button",{onClick:()=>I(!0),className:"w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors",children:[i.jsx(ar,{className:"w-4 h-4"}),r("profiles.presets.addCustomField")]})})]}),i.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3 flex-shrink-0",children:[i.jsx("h3",{className:"text-sm font-medium text-white",children:r("profiles.presets.yourOverrides")}),i.jsx("span",{className:"text-xs text-bambu-gray",children:r("profiles.templates.fieldsCount",{count:Object.keys(g).filter(Ae=>Ae!=="inherits").length})})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto space-y-2 pr-2 min-h-0",children:[Object.entries(g).filter(([Ae])=>Ae!=="inherits").map(([Ae,Be])=>{const je=J.find(Xe=>Xe.key===Ae);return i.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm font-medium text-white",children:je?.label||Ae}),i.jsx("p",{className:"text-xs text-bambu-gray-dark",children:Ae})]}),i.jsx("button",{onClick:()=>ue(Ae,void 0),className:"p-1 text-bambu-gray hover:text-red-400 transition-colors",children:i.jsx(Ht,{className:"w-4 h-4"})})]}),je?Ee(je):i.jsx("input",{type:"text",value:String(Be),onChange:Xe=>ue(Ae,Xe.target.value),className:"w-full px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]},Ae)}),Object.keys(g).filter(Ae=>Ae!=="inherits").length===0&&i.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[i.jsx(G8,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),i.jsx("p",{className:"text-sm",children:r("profiles.presets.noOverridesYet")}),i.jsx("p",{className:"text-xs mt-1",children:r("profiles.presets.clickFieldsToAdd")})]})]}),Object.keys(g).filter(Ae=>Ae!=="inherits").length>0&&i.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0",children:i.jsxs("button",{onClick:()=>{me(!0),c("common")},className:"w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors",children:[i.jsx(ts,{className:"w-4 h-4"}),r("profiles.presets.saveAsTemplate")]})})]})]}),l==="json"&&i.jsxs("div",{className:"space-y-2",children:[C&&i.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm",children:[i.jsx(Li,{className:"w-4 h-4"}),C]}),i.jsx("textarea",{value:N,onChange:Ae=>L(Ae.target.value),className:`w-full h-80 px-3 py-2 bg-bambu-dark border rounded-lg text-white text-xs font-mono focus:outline-none resize-none ${C?"border-red-500 focus:border-red-500":"border-bambu-dark-tertiary focus:border-bambu-green"}`,spellCheck:!1}),i.jsx("p",{className:"text-xs text-bambu-gray",children:r("profiles.presets.jsonTip")})]})]}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex gap-2",children:[i.jsx(Oe,{variant:"secondary",onClick:t,className:"flex-1",children:r("common.cancel")}),i.jsxs(Oe,{onClick:()=>pe.mutate(),disabled:pe.isPending||!m.trim()||!o&&!f||!!C,className:"flex-1",children:[pe.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):o?i.jsx(ts,{className:"w-4 h-4"}):i.jsx(ar,{className:"w-4 h-4"}),r(o?"common.save":e?"common.duplicate":"common.create")]})]})]})})]})}function Jet({settings:t,lastSyncTime:e,onRefresh:n,isRefreshing:r,printers:a,hasPermission:s,t:o}){const[l,c]=w.useState(""),[u,d]=w.useState("all"),[m,p]=w.useState("all"),[f,y]=w.useState("all"),[v,x]=w.useState("all"),[g,_]=w.useState("all"),[N,T]=w.useState("all"),[C,A]=w.useState(null),[k,R]=w.useState(!1),[P,D]=w.useState(!1),[H,z]=w.useState(null),[G,I]=w.useState(null),[ee,ie]=w.useState(null),[X,me]=w.useState(!1),[he,ge]=w.useState([null,null]),[Y,oe]=w.useState(!1),[le,xe]=w.useState(null),Pe=an(),q=w.useMemo(()=>[...t.filament.map(re=>({...re,type:"filament"})),...t.printer.map(re=>({...re,type:"printer"})),...t.process.map(re=>({...re,type:"process"}))].map(re=>({...re,meta:N5(re.name)})),[t]),Z=w.useMemo(()=>{const W=new Set,re=new Set,ue=new Set;return q.forEach(fe=>{fe.meta.nozzle&&W.add(fe.meta.nozzle),fe.meta.filamentType&&re.add(fe.meta.filamentType),fe.meta.layerHeight&&ue.add(fe.meta.layerHeight)}),{printers:a.map(fe=>({id:fe.id.toString(),name:fe.name})),nozzles:Array.from(W).sort((fe,ye)=>parseFloat(fe)-parseFloat(ye)),filaments:Array.from(re).sort(),layerHeights:Array.from(ue).sort((fe,ye)=>parseFloat(fe)-parseFloat(ye))}},[q,a]),j=w.useMemo(()=>f==="all"?null:a.find(re=>re.id.toString()===f)?.model||null,[f,a]),E=w.useMemo(()=>q.filter(W=>u==="all"||W.type===u).filter(W=>{if(m==="all")return!0;const re=ow(W.setting_id);return m==="custom"?re:!re}).filter(W=>{if(f==="all"||!j)return!0;const re=W.meta.printer?.toLowerCase()||"",ue=j.toLowerCase();return re.includes(ue)||ue.includes(re)}).filter(W=>v==="all"||W.meta.nozzle===v).filter(W=>g==="all"||W.meta.filamentType===g).filter(W=>N==="all"||W.meta.layerHeight===N).filter(W=>l===""||W.name.toLowerCase().includes(l.toLowerCase())).sort((W,re)=>W.name.localeCompare(re.name)),[q,u,m,f,j,v,g,N,l]),U=W=>{if(X){const re=he[0]?.setting_id===W.setting_id,ue=he[1]?.setting_id===W.setting_id;if(re)ge([he[1],null]);else if(ue)ge([he[0],null]);else if(!he[0])ge([W,null]);else if(he[1]){if(he[0].type!==W.type)return;ge([he[0],W])}else{if(he[0].type!==W.type)return;ge([he[0],W])}}else A(W)},K=W=>{if(he[0]?.setting_id===W.setting_id)return 0;if(he[1]?.setting_id===W.setting_id)return 1},$=async W=>{try{const re=await be.getCloudSettingDetail(W.setting_id),ue=W.type==="process"?"print":W.type;z({type:ue,name:W.name,base_id:re.base_id||"GFSA00",setting:re.setting||{}}),A(null)}catch(re){console.error("Failed to fetch preset details for duplication:",re)}},ne=async W=>{try{Pe.removeQueries({queryKey:["cloudSettingDetail",W.setting_id]});const re=await be.getCloudSettingDetail(W.setting_id),ue=W.type==="process"?"print":W.type;I({type:ue,name:W.name,base_id:re.base_id||"GFSA00",setting:re.setting||{},setting_id:W.setting_id}),A(null)}catch(re){console.error("Failed to fetch preset details for editing:",re)}},O=()=>{d("all"),p("all"),y("all"),x("all"),_("all"),T("all"),c("")},V=u!=="all"||m!=="all"||f!=="all"||v!=="all"||g!=="all"||N!=="all"||l!=="",J=t.filament.length+t.printer.length+t.process.length;return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"space-y-4 mb-6",children:[i.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:l,onChange:W=>c(W.target.value),placeholder:o("profiles.cloudView.searchPlaceholder"),className:"w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{className:"flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center",children:[i.jsxs(Oe,{variant:X?"primary":"secondary",onClick:()=>{X?(me(!1),ge([null,null])):me(!0)},children:[i.jsx(zb,{className:"w-4 h-4"}),o(X?"common.cancel":"profiles.presets.compare")]}),i.jsxs(Oe,{variant:"secondary",onClick:()=>D(!0),disabled:!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.cloudView.noTemplatesPermission"),children:[i.jsx(ax,{className:"w-4 h-4"}),o("profiles.cloudView.templates")]}),i.jsxs(Oe,{variant:"secondary",onClick:n,disabled:r||!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.cloudView.noRefreshPermission"),children:[i.jsx(wr,{className:`w-4 h-4 ${r?"animate-spin":""}`}),o("profiles.cloudView.refresh")]}),i.jsxs(Oe,{onClick:()=>R(!0),disabled:!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.cloudView.noCreatePermission"),children:[i.jsx(ar,{className:"w-4 h-4"}),o("profiles.cloudView.newPreset")]})]})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx(QC,{className:"w-4 h-4 text-bambu-gray"}),i.jsx(wb,{label:o("profiles.cloudView.filters.type"),value:u,options:[{value:"all",label:o("profiles.cloudView.filters.all"),count:J},{value:"filament",label:o("profiles.cloudView.filters.filament"),count:t.filament.length},{value:"printer",label:o("profiles.cloudView.filters.printer"),count:t.printer.length},{value:"process",label:o("profiles.cloudView.filters.process"),count:t.process.length}],onChange:W=>d(W)}),i.jsx(wb,{label:o("profiles.cloudView.filters.owner"),value:m,options:[{value:"all",label:o("profiles.cloudView.filters.all")},{value:"custom",label:o("profiles.cloudView.filters.myPresets")},{value:"builtin",label:o("profiles.cloudView.filters.builtIn")}],onChange:W=>p(W)}),Z.printers.length>0&&i.jsx(wb,{label:o("profiles.cloudView.filters.printer"),value:f,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...Z.printers.map(W=>({value:W.id,label:W.name}))],onChange:y}),Z.nozzles.length>0&&i.jsx(wb,{label:o("profiles.cloudView.filters.nozzle"),value:v,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...Z.nozzles.map(W=>({value:W,label:W}))],onChange:x}),Z.filaments.length>0&&(u==="all"||u==="filament")&&i.jsx(wb,{label:o("profiles.cloudView.filters.filament"),value:g,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...Z.filaments.map(W=>({value:W,label:W}))],onChange:_}),Z.layerHeights.length>0&&(u==="all"||u==="process")&&i.jsx(wb,{label:o("profiles.cloudView.filters.layer"),value:N,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...Z.layerHeights.map(W=>({value:W,label:W}))],onChange:T}),V&&i.jsx("button",{onClick:O,className:"px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:o("profiles.cloudView.clearFilters")})]})]}),X&&i.jsx("div",{className:"mb-4 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx(zb,{className:"w-5 h-5 text-blue-400"}),i.jsx("span",{className:"text-white font-medium",children:o("profiles.cloudView.compareMode")}),i.jsx("span",{className:"text-bambu-gray",children:he[0]?o("profiles.cloudView.selectAnotherPreset",{type:he[0].type}):o("profiles.cloudView.clickTwoPresets")})]}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${he[0]?"bg-blue-500/30 text-blue-700 dark:text-blue-300":"bg-bambu-dark text-bambu-gray"}`,children:he[0]?he[0].name:o("profiles.cloudView.selectFirst")}),i.jsx(p3,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${he[1]?"bg-blue-500/30 text-blue-700 dark:text-blue-300":"bg-bambu-dark text-bambu-gray"}`,children:he[1]?he[1].name:o("profiles.cloudView.selectSecond")})]}),he[0]&&he[1]&&i.jsxs(Oe,{size:"sm",onClick:async()=>{try{const[W,re]=await Promise.all([be.getCloudSettingDetail(he[0].setting_id),be.getCloudSettingDetail(he[1].setting_id)]);xe([W.setting||{},re.setting||{}]),oe(!0)}catch{}},children:[i.jsx(zb,{className:"w-4 h-4"}),o("profiles.cloudView.compareNow")]})]})]})}),i.jsxs("div",{className:"flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray",children:[e&&i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx(er,{className:"w-3 h-3"}),o("profiles.cloudView.lastSynced")," ",x0(e.toISOString(),"system",o)]}),i.jsx("span",{children:o("profiles.cloudView.showingCount",{showing:E.length,total:J})}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-bambu-green"}),i.jsxs("span",{children:["= ",o("profiles.presets.myPreset")]})]})]}),E.length===0?i.jsxs("div",{className:"text-center py-16",children:[i.jsx(Gi,{className:"w-12 h-12 text-bambu-gray-dark mx-auto mb-4"}),i.jsx("p",{className:"text-bambu-gray",children:o("profiles.cloudView.noPresetsFound")}),V&&i.jsx("button",{onClick:O,className:"mt-2 text-sm text-bambu-green hover:text-bambu-green-light",children:o("profiles.cloudView.clearFilters")})]}):i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[i.jsx(YC,{className:"w-4 h-4 text-amber-400"}),i.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:o("profiles.cloudView.columns.filament")}),i.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",E.filter(W=>W.type==="filament").length,")"]})]}),i.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[E.filter(W=>W.type==="filament").map(W=>i.jsx(HD,{setting:W,onClick:()=>U(W),onDuplicate:()=>$(W),compareMode:X,isCompareSelected:K(W)!==void 0,compareIndex:K(W),compareDisabled:X&&!!he[0]&&he[0].type!==W.type,t:o},W.setting_id)),E.filter(W=>W.type==="filament").length===0&&i.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:o("profiles.cloudView.noFilamentPresets")})]})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[i.jsx(jd,{className:"w-4 h-4 text-blue-400"}),i.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:o("profiles.cloudView.columns.process")}),i.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",E.filter(W=>W.type==="process").length,")"]})]}),i.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[E.filter(W=>W.type==="process").map(W=>i.jsx(HD,{setting:W,onClick:()=>U(W),onDuplicate:()=>$(W),compareMode:X,isCompareSelected:K(W)!==void 0,compareIndex:K(W),compareDisabled:X&&!!he[0]&&he[0].type!==W.type,t:o},W.setting_id)),E.filter(W=>W.type==="process").length===0&&i.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:o("profiles.cloudView.noProcessPresets")})]})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[i.jsx(Sr,{className:"w-4 h-4 text-purple-400"}),i.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:o("profiles.cloudView.columns.printer")}),i.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",E.filter(W=>W.type==="printer").length,")"]})]}),i.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[E.filter(W=>W.type==="printer").map(W=>i.jsx(HD,{setting:W,onClick:()=>U(W),onDuplicate:()=>$(W),compareMode:X,isCompareSelected:K(W)!==void 0,compareIndex:K(W),compareDisabled:X&&!!he[0]&&he[0].type!==W.type,t:o},W.setting_id)),E.filter(W=>W.type==="printer").length===0&&i.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:o("profiles.cloudView.noPrinterPresets")})]})]})]}),C&&i.jsx(Xet,{setting:C,onClose:()=>A(null),onDeleted:()=>A(null),onDuplicate:()=>$(C),onEdit:()=>ne(C),hasPermission:s,t:o}),(k||H||G||ee)&&i.jsx(Zet,{onClose:()=>{R(!1),z(null),I(null),ie(null)},initialData:G||H||(ee?{type:ee.type,name:"",base_id:"",setting:ee.setting}:void 0),allPresets:t,t:o}),P&&i.jsx(Qet,{onClose:()=>D(!1),onApply:W=>{ie({type:W.type,setting:W.settings}),D(!1)},t:o}),Y&&le&&he[0]&&he[1]&&i.jsx(Boe,{onClose:()=>{oe(!1),xe(null)},leftPreset:le[0],rightPreset:le[1],leftLabel:he[0].name,rightLabel:he[1].name,t:o})]})}function ett(){const{t}=Ft(),e=an(),{showToast:n}=fn(),{hasPermission:r}=_r(),[a,s]=w.useState("cloud"),[o,l]=w.useState(),{data:c,isLoading:u}=et({queryKey:["cloudStatus"],queryFn:be.getCloudStatus}),{data:d=[]}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:m,isLoading:p,refetch:f,dataUpdatedAt:y}=et({queryKey:["cloudSettings"],queryFn:()=>be.getCloudSettings(),enabled:!!c?.is_authenticated,retry:!1,staleTime:1e3*60*5});w.useEffect(()=>{y&&l(new Date(y))},[y]);const v=pt({mutationFn:be.cloudLogout,onSuccess:()=>{e.invalidateQueries({queryKey:["cloudStatus"]}),e.removeQueries({queryKey:["cloudSettings"]}),n(t("profiles.toast.loggedOut"))}}),x=()=>{e.invalidateQueries({queryKey:["cloudStatus"]})};return u?i.jsx("div",{className:"p-4 md:p-8 flex items-center justify-center min-h-[400px]",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):i.jsxs("div",{className:"p-6 lg:p-8",children:[i.jsxs("div",{className:"mb-6",children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:t("profiles.title")}),i.jsx("p",{className:"text-bambu-gray",children:t("profiles.subtitle")})]}),i.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary mb-6",children:[i.jsxs("button",{onClick:()=>s("cloud"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${a==="cloud"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(Fx,{className:"w-4 h-4"}),t("profiles.tabs.cloud")]}),i.jsxs("button",{onClick:()=>s("local"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${a==="local"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(Lx,{className:"w-4 h-4"}),t("profiles.tabs.local")]}),i.jsxs("button",{onClick:()=>s("kprofiles"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${a==="kprofiles"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(ZC,{className:"w-4 h-4"}),t("profiles.tabs.kprofiles")]})]}),a==="cloud"&&i.jsxs(i.Fragment,{children:[c?.is_authenticated&&i.jsxs("div",{className:"flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"w-2 h-2 rounded-full bg-bambu-green animate-pulse"}),i.jsxs("span",{className:"text-sm text-bambu-gray",children:[t("profiles.connectedAs")," ",i.jsx("span",{className:"text-white",children:c.email})]})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>v.mutate(),disabled:v.isPending||!r("cloud:auth"),title:r("cloud:auth")?void 0:t("profiles.noLogoutPermission"),children:[i.jsx(x3,{className:"w-4 h-4"}),t("profiles.logout")]})]}),c?.is_authenticated?p?i.jsx("div",{className:"flex items-center justify-center py-16",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):m?i.jsx(Jet,{settings:m,lastSyncTime:o,onRefresh:()=>f(),isRefreshing:p,printers:d,hasPermission:r,t}):i.jsxs("div",{className:"text-center py-16",children:[i.jsx("p",{className:"text-bambu-gray mb-4",children:t("profiles.failedToLoad")}),i.jsx(Oe,{onClick:()=>f(),children:t("profiles.retry")})]}):i.jsx(Ket,{onSuccess:x,t})]}),a==="local"&&i.jsx(Wet,{}),a==="kprofiles"&&i.jsx($et,{}),i.jsx(Yet,{})]})}const Iv={Droplet:YC,Flame:Fp,Ruler:Tge,Sparkles:ax,Square:zl,Cable:zL,Wrench:Sf,Calendar:Wr,Timer:pd,Cog:gpe,Fan:$X,Zap:kc,Wind:nQ,Thermometer:aT,Layers:Gi,Box:ra,Target:JX,RefreshCw:wr,Settings:iT,Filter:QC,CircleDot:Qhe};function c0(t){return t&&Iv[t]||Sf}function Sb(t,e,n){if(e==="days"){if(t<1)return n?n("common.today"):"Today";if(t===1)return n?n("maintenance.day"):"1 day";if(t<7){const a=Math.round(t);return n?n("maintenance.days",{count:a}):`${a} days`}if(t<180){const a=Math.round(t/7);return a===1?n?n("maintenance.week"):"1 week":n?n("maintenance.weeks",{count:a}):`${a} weeks`}const r=Math.round(t/30);return r===1?n?n("maintenance.month"):"1 month":n?n("maintenance.months",{count:r}):`${r} months`}else{if(t<1)return`${Math.round(t*60)}m`;if(t<24)return`${t<10?t.toFixed(1):Math.round(t)}h`;const r=t/24;if(r<7)return`${r<2?r.toFixed(1):Math.round(r)}d`;const a=r/7;return a<12?`${a<2?a.toFixed(1):Math.round(a)}w`:`${Math.round(a/4)}mo`}}function $D(t,e,n){return e==="days"?t===1?n?n("maintenance.day"):"1 day":t===7?n?n("maintenance.week"):"1 week":t===14?n?n("maintenance.weeks",{count:2}):"2 weeks":t===30?n?n("maintenance.month"):"1 month":t===60?n?n("maintenance.months",{count:2}):"2 months":t===90?n?n("maintenance.months",{count:3}):"3 months":t===180?n?n("maintenance.months",{count:6}):"6 months":t===365?n?n("maintenance.year"):"1 year":n?n("maintenance.days",{count:t}):`${t} days`:`${t}h`}function ttt(t,e){const n=(e||"").toUpperCase().replace(/[- ]/g,""),r=n.includes("X1"),a=n.includes("P1"),s=n.includes("A1MINI"),o=n.includes("A1")&&!s,l=n.includes("H2D"),c=n.includes("H2C"),u=n.includes("H2S"),d=l||c||u,m=n.includes("P2S");switch(t){case"Lubricate Carbon Rods":return r?"https://wiki.bambulab.com/en/x1/maintenance/basic-maintenance":a?"https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance":null;case"Lubricate Steel Rods":return m?"https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis":null;case"Clean Steel Rods":return m?"https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis":null;case"Lubricate Linear Rails":return s?"https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis":o?"https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis":d?"https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication":null;case"Clean Nozzle/Hotend":return r||a?"https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog":s||o?"https://wiki.bambulab.com/en/a1-mini/troubleshooting/nozzle-clog":d?"https://wiki.bambulab.com/en/h2/maintenance/nozzl-cold-pull-maintenance-and-cleaning":m?"https://wiki.bambulab.com/en/p2s/maintenance/cold-pull-maintenance-hotend":"https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog";case"Check Belt Tension":return r?"https://wiki.bambulab.com/en/x1/maintenance/belt-tension":a?"https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance":s?"https://wiki.bambulab.com/en/a1-mini/maintenance/belt_tension":o?"https://wiki.bambulab.com/en/a1/maintenance/belt_tension":l?"https://wiki.bambulab.com/en/h2/maintenance/belt-tension":c?"https://wiki.bambulab.com/en/h2c/maintenance/belt-tension":u?"https://wiki.bambulab.com/en/h2s/maintenance/belt-tension":m?"https://wiki.bambulab.com/en/p2s/maintenance/belt-tension":"https://wiki.bambulab.com/en/x1/maintenance/belt-tension";case"Clean Carbon Rods":return r||a?"https://wiki.bambulab.com/en/general/carbon-rods-clearance":null;case"Clean Linear Rails":return s?"https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis":o?"https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis":d?"https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication":null;case"Clean Build Plate":return"https://wiki.bambulab.com/en/filament-acc/acc/pei-plate-clean-guide";case"Check PTFE Tube":return r||a?"https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube":s||o?"https://wiki.bambulab.com/en/a1-mini/maintenance/ptfe-tube":l?"https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer":u?"https://wiki.bambulab.com/en/h2s/maintenance/replace-ptfe-tube-on-h2s-printer":c?"https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer":"https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube";case"Replace HEPA Filter":case"HEPA Filter":case"Replace Carbon Filter":case"Carbon Filter":return d?"https://wiki.bambulab.com/en/h2/maintenance/replace-smoke-purifier-air-filte":"https://wiki.bambulab.com/en/x1/maintenance/replace-carbon-filter";case"Lubricate Left Nozzle Rail":case"Left Nozzle Rail":return d?"https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication":null;default:return null}}function ntt({item:t,onPerform:e,onToggle:n,hasPermission:r,t:a}){const s=c0(t.maintenance_type_icon),o=t.interval_type||"hours",c=(()=>{if(o==="days"){const f=t.days_since_maintenance??0;return Math.max(0,Math.min(100,f/t.interval_hours*100))}return Math.max(0,Math.min(100,(t.interval_hours-t.hours_until_due)/t.interval_hours*100))})(),u=()=>t.enabled?t.is_due?"text-red-400":t.is_warning?"text-amber-400":"text-bambu-green":"text-bambu-gray",d=()=>t.enabled?t.is_due?"bg-red-500":t.is_warning?"bg-amber-500":"bg-bambu-green":"bg-bambu-gray/30",m=()=>t.enabled?t.is_due?"bg-red-500/5 border-red-500/20":t.is_warning?"bg-amber-500/5 border-amber-500/20":"bg-bambu-dark-secondary border-bambu-dark-tertiary":"bg-bambu-dark-secondary/50",p=()=>{if(!t.enabled)return a("common.disabled");if(o==="days"){const f=t.days_until_due??0;return t.is_due?a("maintenance.overdueBy",{duration:Sb(Math.abs(f),"days",a)}):t.is_warning?a("maintenance.dueIn",{duration:Sb(f,"days",a)}):a("maintenance.timeLeft",{duration:Sb(f,"days",a)})}else return t.is_due?a("maintenance.overdueBy",{duration:Sb(Math.abs(t.hours_until_due),"hours",a)}):t.is_warning?a("maintenance.dueIn",{duration:Sb(t.hours_until_due,"hours",a)}):a("maintenance.timeLeft",{duration:Sb(t.hours_until_due,"hours",a)})};return i.jsx("div",{className:`rounded-xl border p-4 transition-all ${m()}`,children:i.jsxs("div",{className:"flex items-start gap-3 max-[550px]:flex-wrap",children:[i.jsxs("div",{className:`relative p-2.5 rounded-lg shrink-0 ${t.is_due?"bg-red-500/20":t.is_warning?"bg-amber-500/20":t.enabled?"bg-bambu-dark":"bg-bambu-dark/50"}`,children:[i.jsx(s,{className:`w-5 h-5 ${u()}`}),t.enabled&&(t.is_due||t.is_warning)&&i.jsx("span",{className:`absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full ${t.is_due?"bg-red-500":"bg-amber-500"} animate-pulse`})]}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("h3",{className:`font-medium truncate ${t.enabled?"text-white":"text-bambu-gray"}`,children:t.maintenance_type_name}),o==="days"&&i.jsx("span",{title:a("maintenance.timeBasedInterval"),children:i.jsx(Wr,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"})}),(()=>{const f=t.maintenance_type_wiki_url||ttt(t.maintenance_type_name,t.printer_model);return f?i.jsx("a",{href:f,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-bambu-green transition-colors shrink-0",title:a("maintenance.viewDocumentation"),onClick:y=>y.stopPropagation(),children:i.jsx(Jr,{className:"w-3.5 h-3.5"})}):null})()]}),i.jsx("div",{className:"mt-2 mb-1.5",children:i.jsx("div",{className:"w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden",children:i.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${d()}`,style:{width:`${c}%`}})})}),i.jsxs("div",{className:`text-xs flex items-center gap-1 ${u()}`,children:[t.is_due&&i.jsx(Mn,{className:"w-3 h-3"}),t.is_warning&&!t.is_due&&i.jsx(er,{className:"w-3 h-3"}),!t.is_due&&!t.is_warning&&t.enabled&&i.jsx(Yr,{className:"w-3 h-3"}),p()]})]}),i.jsxs("div",{className:"flex items-center gap-2 shrink-0 max-[550px]:w-full max-[550px]:justify-end max-[550px]:mt-1",children:[i.jsx("span",{title:r("maintenance:update")?void 0:a("maintenance.noPermissionUpdate"),children:i.jsx(Bn,{checked:t.enabled,onChange:f=>n(t.id,f),disabled:!r("maintenance:update")})}),i.jsxs(Oe,{size:"sm",variant:t.is_due?"primary":"secondary",onClick:()=>e(t.id),disabled:!t.enabled||!r("maintenance:update"),title:r("maintenance:update")?void 0:a("maintenance.noPermissionPerform"),className:"!px-3",children:[i.jsx(bo,{className:"w-3.5 h-3.5"}),a("common.reset")]})]})]})})}function rtt({overview:t,onPerform:e,onToggle:n,onSetHours:r,hasPermission:a,t:s}){const[o,l]=w.useState(!1),[c,u]=w.useState(!1),[d,m]=w.useState(t.total_print_hours.toFixed(1)),p=[...t.maintenance_items].sort((v,x)=>v.is_due&&!x.is_due?-1:!v.is_due&&x.is_due?1:v.is_warning&&!x.is_warning?-1:!v.is_warning&&x.is_warning?1:v.maintenance_type_id-x.maintenance_type_id),f=p.find(v=>v.enabled&&(v.is_due||v.is_warning)),y=()=>{const v=parseFloat(d);!isNaN(v)&&v>=0&&(r(t.printer_id,v),u(!1))};return i.jsxs(Mt,{className:"overflow-hidden",children:[i.jsxs("div",{className:"p-5",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx("h2",{className:"text-xl font-semibold text-white",children:t.printer_name}),i.jsxs("div",{className:"flex items-center gap-2",children:[t.due_count>0&&i.jsxs("span",{className:"px-2.5 py-1 bg-red-500/20 text-red-400 text-xs font-medium rounded-full flex items-center gap-1.5",children:[i.jsx(Mn,{className:"w-3 h-3"}),s("maintenance.overdueCount",{count:t.due_count})]}),t.warning_count>0&&i.jsxs("span",{className:"px-2.5 py-1 bg-amber-500/20 text-amber-400 text-xs font-medium rounded-full flex items-center gap-1.5",children:[i.jsx(er,{className:"w-3 h-3"}),s("maintenance.dueSoonCount",{count:t.warning_count})]}),t.due_count===0&&t.warning_count===0&&i.jsxs("span",{className:"px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1.5",children:[i.jsx(Yr,{className:"w-3 h-3"}),s("maintenance.allGood")]})]})]}),i.jsxs("button",{onClick:()=>l(!o),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded-lg transition-colors",children:[o?i.jsx(Il,{className:"w-4 h-4"}):i.jsx(Ln,{className:"w-4 h-4"}),s(o?"common.collapse":"common.expand")]})]}),i.jsxs("div",{className:"flex items-center gap-6 mt-4",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2 bg-bambu-dark/50 rounded-lg",children:i.jsx(pd,{className:"w-4 h-4 text-bambu-gray"})}),c?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",value:d,onChange:v=>m(v.target.value),onKeyDown:v=>{v.key==="Enter"&&y(),v.key==="Escape"&&u(!1)},className:"w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm",min:"0",step:"1",autoFocus:!0}),i.jsx("span",{className:"text-xs text-bambu-gray",children:s("common.hours")}),i.jsx(Oe,{size:"sm",onClick:y,children:s("common.save")}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:()=>u(!1),children:s("common.cancel")})]}):i.jsxs("button",{onClick:()=>{a("maintenance:update")&&(m(Math.round(t.total_print_hours).toString()),u(!0))},className:`group ${a("maintenance:update")?"":"cursor-not-allowed opacity-60"}`,title:a("maintenance:update")?void 0:s("maintenance.noPermissionEditHours"),children:[i.jsxs("div",{className:`text-sm font-medium text-white ${a("maintenance:update")?"group-hover:text-bambu-green":""} transition-colors flex items-center gap-1`,children:[Math.round(t.total_print_hours)," ",s("common.hours"),i.jsx(vf,{className:`w-3 h-3 text-bambu-gray ${a("maintenance:update")?"group-hover:text-bambu-green":""}`})]}),i.jsx("div",{className:"text-xs text-bambu-gray",children:s("maintenance.totalPrintTime")})]})]}),i.jsx("div",{className:"w-px h-10 bg-bambu-dark-tertiary"}),f&&i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:`p-2 rounded-lg ${f.is_due?"bg-red-500/20":"bg-amber-500/20"}`,children:(()=>{const v=c0(f.maintenance_type_icon);return i.jsx(v,{className:`w-4 h-4 ${f.is_due?"text-red-400":"text-amber-400"}`})})()}),i.jsxs("div",{children:[i.jsx("div",{className:`text-sm font-medium ${f.is_due?"text-red-400":"text-amber-400"}`,children:f.maintenance_type_name}),i.jsx("div",{className:`text-xs ${f.is_due?"text-red-400/70":"text-amber-400/70"}`,children:f.is_due?s("common.overdue"):s("maintenance.dueSoon")})]})]})]})]}),o&&i.jsx(Dt,{className:"pt-0 border-t border-bambu-dark-tertiary",children:i.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4",children:p.map(v=>i.jsx(ntt,{item:v,onPerform:e,onToggle:n,hasPermission:a,t:s},v.id))})})]})}function itt({overview:t,types:e,onUpdateInterval:n,onAddType:r,onUpdateType:a,onDeleteType:s,onRestoreDefaults:o,isRestoringDefaults:l,onAssignType:c,onRemoveItem:u,hasPermission:d,t:m}){const[p,f]=w.useState(null),[y,v]=w.useState(""),[x,g]=w.useState("hours"),[_,N]=w.useState(!1),[T,C]=w.useState(""),[A,k]=w.useState("100"),[R,P]=w.useState("hours"),[D,H]=w.useState("Wrench"),[z,G]=w.useState(""),[I,ee]=w.useState(new Set),[ie,X]=w.useState(null),[me,he]=w.useState(null),ge=w.useMemo(()=>t?t.map(L=>({id:L.printer_id,name:L.printer_name})):[],[t]),Y=L=>t?t.filter(F=>F.maintenance_items.some(te=>te.maintenance_type_id===L)).map(F=>({printerId:F.printer_id,printerName:F.printer_name,itemId:F.maintenance_items.find(te=>te.maintenance_type_id===L)?.id})):[],oe=L=>{if(!t)return[];const F=new Set(Y(L).map(te=>te.printerId));return ge.filter(te=>!F.has(te.id))},[le,xe]=w.useState(null),[Pe,q]=w.useState(""),[Z,j]=w.useState(""),[E,U]=w.useState("hours"),[K,$]=w.useState("Wrench"),[ne,O]=w.useState(""),V=L=>{xe(L),q(L.name),j(L.default_interval_hours.toString()),U(L.interval_type||"hours"),$(L.icon||"Wrench"),O(L.wiki_url||"")},J=()=>{le&&Pe.trim()&&parseFloat(Z)>0&&(a(le.id,{name:Pe.trim(),default_interval_hours:parseFloat(Z),interval_type:E,icon:K,wiki_url:ne.trim()||null}),xe(null))},W=(L,F,te)=>{const ve=parseFloat(y);if(!isNaN(ve)&&ve>0){const pe=Math.abs(ve-F)<.01?null:ve;n(L,{custom_interval_hours:pe,custom_interval_type:x!==te?x:null})}f(null)},re=L=>{L.preventDefault(),T.trim()&&parseFloat(A)>0&&I.size>0&&(r({name:T.trim(),default_interval_hours:parseFloat(A),interval_type:R,icon:D,wiki_url:z.trim()||null},Array.from(I)),C(""),k("100"),P("hours"),G(""),ee(new Set),N(!1))},ue=L=>{ee(F=>{const te=new Set(F);return te.has(L)?te.delete(L):te.add(L),te})},fe=t?.map(L=>({printerId:L.printer_id,printerName:L.printer_name,items:L.maintenance_items.sort((F,te)=>F.maintenance_type_id-te.maintenance_type_id)})).sort((L,F)=>L.printerName.localeCompare(F.printerName))||[],ye=e.filter(L=>L.is_system),ae=e.filter(L=>!L.is_system);return i.jsxs("div",{className:"space-y-8",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsxs("div",{children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:m("maintenance.maintenanceTypes")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:m("maintenance.maintenanceTypesDescription")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Oe,{variant:"secondary",onClick:o,disabled:!d("maintenance:delete")||l,title:d("maintenance:delete")?void 0:m("maintenance.noPermissionDeleteTypes"),children:m("maintenance.restoreDefaults")}),i.jsxs(Oe,{onClick:()=>N(!_),disabled:!d("maintenance:create"),title:d("maintenance:create")?void 0:m("maintenance.noPermissionEditTypes"),children:[i.jsx(ar,{className:"w-4 h-4"}),m("maintenance.addCustomType")]})]})]}),_&&i.jsx(Mt,{className:"mb-6",children:i.jsx(Dt,{className:"py-4",children:i.jsxs("form",{onSubmit:re,children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[i.jsxs("div",{className:"lg:col-span-2",children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("common.name")}),i.jsx("input",{type:"text",value:T,onChange:L=>C(L.target.value),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",placeholder:m("maintenance.exampleName"),autoFocus:!0})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.intervalType")}),i.jsxs("select",{value:R,onChange:L=>{P(L.target.value),L.target.value==="days"?k("30"):k("100")},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",children:[i.jsx("option",{value:"hours",children:m("maintenance.printHours")}),i.jsx("option",{value:"days",children:m("maintenance.calendarDays")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.intervalValue",{type:R==="days"?m("maintenance.calendarDays").toLowerCase():m("common.hours")})}),i.jsx("input",{type:"number",value:A,onChange:L=>k(L.target.value),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",min:"1"})]})]}),i.jsx("div",{className:"mt-4 flex items-end justify-between",children:i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.icon")}),i.jsx("div",{className:"flex gap-1",children:Object.keys(Iv).map(L=>{const F=Iv[L];return i.jsx("button",{type:"button",onClick:()=>H(L),className:`p-2 rounded-lg transition-colors ${D===L?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,children:i.jsx(F,{className:"w-4 h-4"})},L)})})]})}),i.jsxs("div",{className:"mt-4",children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.documentationLink")}),i.jsx("input",{type:"url",value:z,onChange:L=>G(L.target.value),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",placeholder:"https://wiki.bambulab.com/..."})]}),i.jsxs("div",{className:"mt-4",children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.assignToPrinters")}),i.jsx("div",{className:"flex flex-wrap gap-2",children:ge.map(L=>i.jsx("button",{type:"button",onClick:()=>ue(L.id),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${I.has(L.id)?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,children:L.name},L.id))}),I.size===0&&i.jsx("p",{className:"text-xs text-orange-400 mt-1",children:m("maintenance.selectAtLeastOnePrinter")})]}),i.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:()=>{N(!1),ee(new Set)},children:m("common.cancel")}),i.jsx(Oe,{type:"submit",disabled:!T.trim()||I.size===0,children:m("maintenance.addType")})]})]})})}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:[ye.map(L=>{const F=c0(L.icon),te=L.interval_type||"hours";return i.jsx("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary",children:i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2.5 bg-bambu-dark rounded-lg",children:i.jsx(F,{className:"w-5 h-5 text-bambu-gray"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm font-medium text-white truncate",children:L.name}),i.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 flex items-center gap-1",children:[te==="days"?i.jsx(Wr,{className:"w-3 h-3"}):i.jsx(pd,{className:"w-3 h-3"}),$D(L.default_interval_hours,te,m)]})]}),i.jsx("button",{onClick:()=>{d("maintenance:delete")&&he(L)},disabled:!d("maintenance:delete"),title:d("maintenance:delete")?void 0:m("maintenance.noPermissionDeleteTypes"),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors ${d("maintenance:delete")?"":"opacity-50 cursor-not-allowed"}`,children:i.jsx(Jt,{className:"w-4 h-4"})})]})},L.id)}),ae.map(L=>{const F=c0(L.icon),te=L.interval_type||"hours";if(le?.id===L.id)return i.jsx("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green",children:i.jsxs("div",{className:"space-y-3",children:[i.jsx("input",{type:"text",value:Pe,onChange:Se=>q(Se.target.value),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",placeholder:m("common.name"),autoFocus:!0}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("select",{value:E,onChange:Se=>U(Se.target.value),className:"flex-1 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",children:[i.jsx("option",{value:"hours",children:m("maintenance.printHours")}),i.jsx("option",{value:"days",children:m("maintenance.calendarDays")})]}),i.jsx("input",{type:"number",value:Z,onChange:Se=>j(Se.target.value),className:"w-24 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",min:"1"})]}),i.jsx("div",{className:"flex flex-wrap gap-1",children:Object.keys(Iv).map(Se=>{const Le=Iv[Se];return i.jsx("button",{type:"button",onClick:()=>$(Se),className:`p-1.5 rounded transition-colors ${K===Se?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:i.jsx(Le,{className:"w-3.5 h-3.5"})},Se)})}),i.jsx("input",{type:"url",value:ne,onChange:Se=>O(Se.target.value),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",placeholder:m("maintenance.documentationLink")}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Oe,{size:"sm",onClick:J,disabled:!Pe.trim(),children:m("common.save")}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:()=>xe(null),children:m("common.cancel")})]})]})},L.id);const pe=Y(L.id),de=oe(L.id),Ne=ie===L.id;return i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2.5 bg-bambu-green/20 rounded-lg",children:i.jsx(F,{className:"w-5 h-5 text-bambu-green"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-sm font-medium text-white truncate",children:L.name}),i.jsx("span",{className:"px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded",children:m("maintenance.custom")})]}),i.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 flex items-center gap-1",children:[te==="days"?i.jsx(Wr,{className:"w-3 h-3"}):i.jsx(pd,{className:"w-3 h-3"}),$D(L.default_interval_hours,te,m)]})]}),i.jsxs("button",{onClick:()=>X(Ne?null:L.id),className:`px-2 py-1 rounded-lg border transition-colors flex items-center gap-1 ${pe.length>0?"border-bambu-green/50 bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20":"border-orange-400/50 bg-orange-400/10 text-orange-400 hover:bg-orange-400/20"}`,title:m("maintenance.printersAssignedClick",{count:pe.length}),children:[i.jsx(Sr,{className:"w-3 h-3"}),i.jsx("span",{className:"text-xs font-medium",children:pe.length}),i.jsx(Ln,{className:`w-3 h-3 transition-transform ${Ne?"rotate-180":""}`})]}),i.jsx("button",{onClick:()=>V(L),disabled:!d("maintenance:update"),title:d("maintenance:update")?void 0:m("maintenance.noPermissionEditTypes"),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors ${d("maintenance:update")?"":"opacity-50 cursor-not-allowed"}`,children:i.jsx(vf,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>{confirm(m("maintenance.deleteTypeConfirm",{name:L.name}))&&s(L.id)},disabled:!d("maintenance:delete"),title:d("maintenance:delete")?void 0:m("maintenance.noPermissionDeleteTypes"),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors ${d("maintenance:delete")?"":"opacity-50 cursor-not-allowed"}`,children:i.jsx(Jt,{className:"w-4 h-4"})})]}),Ne&&i.jsxs("div",{className:"mt-3 pt-3 border-t border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:m("maintenance.assignedToPrinters")}),pe.length===0?i.jsx("p",{className:"text-xs text-orange-400",children:m("maintenance.noPrintersAssigned")}):i.jsx("div",{className:"flex flex-wrap gap-1 mb-2",children:pe.map(Se=>i.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark rounded text-xs text-white",children:[Se.printerName,i.jsx("button",{onClick:()=>Se.itemId&&u(Se.itemId),disabled:!d("maintenance:delete"),title:d("maintenance:delete")?m("maintenance.removeFromPrinter"):m("maintenance.noPermissionRemovePrinter"),className:`ml-1 ${d("maintenance:delete")?"hover:text-red-400":"opacity-50 cursor-not-allowed"}`,children:"×"})]},Se.printerId))}),de.length>0&&i.jsxs("div",{className:"flex flex-wrap gap-1",children:[i.jsx("span",{className:"text-xs text-bambu-gray mr-1",children:m("maintenance.addPrinterShort")}),de.map(Se=>i.jsxs("button",{onClick:()=>c(Se.id,L.id),disabled:!d("maintenance:create"),title:d("maintenance:create")?void 0:m("maintenance.noPermissionAssignPrinter"),className:`px-2 py-1 bg-bambu-dark rounded text-xs transition-colors ${d("maintenance:create")?"hover:bg-bambu-green/20 text-bambu-gray hover:text-bambu-green":"opacity-50 cursor-not-allowed text-bambu-gray"}`,children:["+ ",Se.name]},Se.id))]})]})]},L.id)})]})]}),fe.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"mb-4",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:m("maintenance.intervalOverrides")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:m("maintenance.intervalOverridesDescription")})]}),i.jsx("div",{className:"space-y-4",children:fe.map(L=>i.jsx(Mt,{children:i.jsxs(Dt,{className:"py-4",children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:L.printerName}),i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2",children:L.items.map(F=>{const te=c0(F.maintenance_type_icon),ve=e.find(Le=>Le.id===F.maintenance_type_id),pe=ve?.default_interval_hours||F.interval_hours,de=ve?.interval_type||"hours",Ne=F.interval_type||"hours",Se=p===F.id;return i.jsxs("div",{className:"flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg",children:[i.jsx(te,{className:"w-4 h-4 text-bambu-gray shrink-0"}),i.jsx("span",{className:"text-xs text-bambu-gray flex-1 truncate",children:F.maintenance_type_name}),Se?i.jsxs("div",{className:"flex items-center gap-1",children:[x==="days"?i.jsx(Wr,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"}):i.jsx(pd,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"}),i.jsxs("select",{value:x,onChange:Le=>g(Le.target.value),className:"px-1.5 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs",children:[i.jsx("option",{value:"hours",children:m("maintenance.printHours")}),i.jsx("option",{value:"days",children:m("maintenance.calendarDays")})]}),i.jsx("input",{type:"number",value:y,onChange:Le=>v(Le.target.value),onKeyDown:Le=>{Le.key==="Enter"&&W(F.id,pe,de),Le.key==="Escape"&&f(null)},className:"w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs",min:"1"}),i.jsx(Oe,{size:"sm",onClick:()=>W(F.id,pe,de),children:"OK"})]}):i.jsxs("button",{onClick:()=>{d("maintenance:update")&&(f(F.id),v(F.interval_hours.toString()),g(Ne))},disabled:!d("maintenance:update"),title:d("maintenance:update")?void 0:m("maintenance.noPermissionEditIntervals"),className:`px-2 py-1 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs font-medium text-white transition-colors flex items-center gap-1 ${d("maintenance:update")?"hover:bg-bambu-dark-secondary hover:border-bambu-green":"opacity-50 cursor-not-allowed"}`,children:[Ne==="days"?i.jsx(Wr,{className:"w-3 h-3"}):i.jsx(pd,{className:"w-3 h-3"}),$D(F.interval_hours,Ne,m),i.jsx(vf,{className:"w-3 h-3 text-bambu-gray"})]})]},F.id)})})]})},L.printerId))})]}),fe.length===0&&i.jsx(Mt,{children:i.jsxs(Dt,{className:"text-center py-12",children:[i.jsx(er,{className:"w-12 h-12 mx-auto mb-4 text-bambu-gray/30"}),i.jsx("p",{className:"text-bambu-gray",children:m("common.noPrinters")}),i.jsx("p",{className:"text-sm text-bambu-gray/70 mt-1",children:m("maintenance.intervalOverridesDescription")})]})}),me&&i.jsx(Sn,{title:m("maintenance.deleteSystemTypeTitle"),message:m("maintenance.deleteSystemTypeMessage",{name:me.name}),confirmText:m("common.delete"),cancelText:m("common.cancel"),variant:"danger",cancelVariant:"primary",cardClassName:"bg-red-950/70 border border-red-800/70",onConfirm:()=>{s(me.id),he(null)},onCancel:()=>he(null)})]})}function att(){const{t}=Ft(),e=an(),{showToast:n}=fn(),{hasPermission:r}=_r(),[a,s]=w.useState("status"),{data:o,isLoading:l}=et({queryKey:["maintenanceOverview"],queryFn:be.getMaintenanceOverview}),{data:c}=et({queryKey:["maintenanceTypes"],queryFn:be.getMaintenanceTypes}),u=pt({mutationFn:({id:A,notes:k})=>be.performMaintenance(A,k),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),e.invalidateQueries({queryKey:["maintenanceSummary"]}),n(t("maintenance.maintenanceComplete"))},onError:A=>{n(A.message,"error")}}),d=pt({mutationFn:({id:A,data:k})=>be.updateMaintenanceItem(A,k),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]})},onError:A=>{n(A.message,"error")}}),m=pt({mutationFn:({id:A,data:k})=>be.updateMaintenanceType(A,k),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.typeUpdated"))},onError:A=>{n(A.message,"error")}}),p=pt({mutationFn:be.deleteMaintenanceType,onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.typeDeleted"))},onError:A=>{n(A.message,"error")}}),f=pt({mutationFn:be.restoreDefaultMaintenanceTypes,onSuccess:A=>{e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.defaultsRestored",{count:A.restored}))},onError:A=>{n(A.message,"error")}}),y=pt({mutationFn:({printerId:A,hours:k})=>be.setPrinterHours(A,k),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),e.invalidateQueries({queryKey:["maintenanceSummary"]}),n(t("maintenance.printHoursUpdated"))},onError:A=>{n(A.message,"error")}}),v=pt({mutationFn:({printerId:A,typeId:k})=>be.assignMaintenanceType(A,k),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.printerAssigned"))},onError:A=>{n(A.message,"error")}}),x=pt({mutationFn:be.removeMaintenanceItem,onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.printerRemoved"))},onError:A=>{n(A.message,"error")}}),g=A=>{u.mutate({id:A})},_=(A,k)=>{d.mutate({id:A,data:{enabled:k}})},N=(A,k)=>{y.mutate({printerId:A,hours:k})};if(l)return i.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})});const T=o?.reduce((A,k)=>A+k.due_count,0)||0,C=o?.reduce((A,k)=>A+k.warning_count,0)||0;return i.jsxs("div",{className:"p-4 md:p-8",children:[i.jsxs("div",{className:"mb-6",children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:t("maintenance.title")}),i.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:a==="status"?i.jsxs(i.Fragment,{children:[T>0&&i.jsx("span",{className:"text-red-400",children:t("maintenance.dueCount",{count:T})}),T>0&&C>0&&" · ",C>0&&i.jsx("span",{className:"text-amber-400",children:t("maintenance.warningCount",{count:C})}),T===0&&C===0&&i.jsx("span",{className:"text-bambu-green",children:t("maintenance.allOk")})]}):t("maintenance.configureSettings")})]}),i.jsxs("div",{className:"flex gap-1 mb-6 border-b border-bambu-dark-tertiary",children:[i.jsx("button",{onClick:()=>s("status"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${a==="status"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:t("maintenance.statusTab")}),i.jsx("button",{onClick:()=>s("settings"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${a==="settings"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:t("maintenance.settingsTab")})]}),a==="status"?i.jsx("div",{className:"space-y-6",children:o&&o.length>0?[...o].sort((A,k)=>{const R=A.due_count*10+A.warning_count,P=k.due_count*10+k.warning_count;return R!==P?P-R:A.printer_name.localeCompare(k.printer_name)}).map(A=>i.jsx(rtt,{overview:A,onPerform:g,onToggle:_,onSetHours:N,hasPermission:r,t},A.printer_id)):i.jsx(Mt,{children:i.jsxs(Dt,{className:"text-center py-16",children:[i.jsx(Sf,{className:"w-16 h-16 mx-auto mb-4 text-bambu-gray/30"}),i.jsx("p",{className:"text-lg font-medium text-white mb-2",children:t("common.noPrinters")}),i.jsx("p",{className:"text-bambu-gray",children:t("maintenance.configureSettings")})]})})}):i.jsx(itt,{overview:o,types:c||[],onUpdateInterval:(A,k)=>d.mutate({id:A,data:k}),onAddType:async(A,k)=>{const R=await be.createMaintenanceType(A);for(const P of k)await be.assignMaintenanceType(P,R.id);e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.typeUpdated"))},onUpdateType:(A,k)=>m.mutate({id:A,data:k}),onDeleteType:A=>p.mutate(A),onRestoreDefaults:()=>f.mutate(),isRestoringDefaults:f.isPending,onAssignType:(A,k)=>v.mutate({printerId:A,typeId:k}),onRemoveItem:A=>x.mutate(A),hasPermission:r,t})]})}const PY=["#ef4444","#f97316","#eab308","#22c55e","#06b6d4","#3b82f6","#8b5cf6","#ec4899","#6b7280"];function Hoe({project:t,onClose:e,onSave:n,isLoading:r,t:a}){const[s,o]=w.useState(t?.name||""),[l,c]=w.useState(t?.description||""),[u,d]=w.useState(t?.color||PY[0]),[m,p]=w.useState(t?.target_count?.toString()||""),[f,y]=w.useState(t?.target_parts_count?.toString()||""),[v,x]=w.useState(t?.status||"active"),[g,_]=w.useState(t?.tags||""),[N,T]=w.useState(t?.due_date?.split("T")[0]||""),[C,A]=w.useState(t?.priority||"normal"),k=R=>{R.preventDefault(),n({name:s.trim(),description:l.trim()||void 0,color:u,target_count:m?parseInt(m,10):void 0,target_parts_count:f?parseInt(f,10):void 0,tags:g.trim()||void 0,due_date:N||void 0,priority:C,...t&&{status:v}})};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary",children:[i.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a(t?"projects.editProject":"projects.newProject")})}),i.jsxs("form",{onSubmit:k,className:"p-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("common.name")}),i.jsx("input",{type:"text",value:s,onChange:R=>o(R.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:a("projects.namePlaceholder"),required:!0})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("common.description")}),i.jsx("textarea",{value:l,onChange:R=>c(R.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green resize-none",placeholder:a("projects.descriptionPlaceholder"),rows:2})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("projects.color")}),i.jsx("div",{className:"flex gap-2 flex-wrap",children:PY.map(R=>i.jsx("button",{type:"button",onClick:()=>d(R),className:`w-8 h-8 rounded-full transition-transform ${u===R?"ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110":""}`,style:{backgroundColor:R}},R))})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("projects.targetPlates")}),i.jsx("input",{type:"number",value:m,onChange:R=>p(R.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:a("projects.targetPlatesPlaceholder"),min:"1"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("projects.targetPlatesHelp")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("projects.targetParts")}),i.jsx("input",{type:"number",value:f,onChange:R=>y(R.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:a("projects.targetPartsPlaceholder"),min:"1"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("projects.targetPartsHelp")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("projects.tagsLabel")}),i.jsx("input",{type:"text",value:g,onChange:R=>_(R.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:a("projects.tagsPlaceholder")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("projects.dueDate")}),i.jsx("input",{type:"date",value:N,onChange:R=>T(R.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("projects.priority")}),i.jsxs("select",{value:C,onChange:R=>A(R.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green",children:[i.jsx("option",{value:"low",children:a("projects.priorityLow")}),i.jsx("option",{value:"normal",children:a("projects.priorityNormal")}),i.jsx("option",{value:"high",children:a("projects.priorityHigh")}),i.jsx("option",{value:"urgent",children:a("projects.priorityUrgent")})]})]})]}),t&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("common.status")}),i.jsxs("select",{value:v,onChange:R=>x(R.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green",children:[i.jsx("option",{value:"active",children:a("projects.statusActive")}),i.jsx("option",{value:"completed",children:a("projects.statusCompleted")}),i.jsx("option",{value:"archived",children:a("projects.statusArchived")})]})]}),i.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,children:a("common.cancel")}),i.jsx(Oe,{type:"submit",disabled:!s.trim()||r,children:r?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):a(t?"common.save":"projects.create")})]})]})]})})}function stt({project:t,onClick:e,onEdit:n,onDelete:r,hasPermission:a,t:s}){const o=t.target_count?Math.round(t.archive_count/t.target_count*100):0,l=t.target_parts_count?Math.round(t.completed_count/t.target_parts_count*100):0,c=t.status==="completed",u=t.status==="archived",[d,m]=w.useState(!1),f=c?{icon:Jc,color:"text-bambu-green",bg:"bg-bambu-green/10"}:u?{icon:zs,color:"text-bambu-gray",bg:"bg-bambu-gray/10"}:t.queue_count>0?{icon:er,color:"text-blue-400",bg:"bg-blue-400/10"}:{icon:fs,color:"text-bambu-gray",bg:"bg-bambu-gray/10"};return i.jsxs("div",{className:"group relative bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary hover:border-bambu-green/50 hover:shadow-lg hover:shadow-bambu-green/5 transition-all duration-300 cursor-pointer overflow-hidden",onClick:e,children:[i.jsx("div",{className:"absolute top-0 left-0 w-1.5 h-full",style:{backgroundColor:t.color||"#6b7280",boxShadow:`0 0 12px ${t.color||"#6b7280"}40`}}),i.jsxs("div",{className:"p-5 pl-6",children:[i.jsxs("div",{className:"flex items-start justify-between mb-4",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[i.jsx("div",{className:`p-2 rounded-lg ${f.bg} flex-shrink-0`,children:i.jsx(f.icon,{className:`w-5 h-5 ${f.color}`})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[i.jsx("h3",{className:"font-semibold text-white truncate",children:t.name}),t.target_parts_count?i.jsxs("span",{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${l>=100?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray"}`,children:[t.completed_count,"/",t.target_parts_count," ",s("projects.parts")]}):t.target_count?i.jsxs("span",{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${o>=100?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray"}`,children:[t.archive_count,"/",t.target_count," ",s("projects.plates")]}):t.completed_count>0?i.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium bg-bambu-dark text-bambu-gray",children:[t.completed_count," ",s("projects.parts")]}):null,c&&i.jsx("span",{className:"text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full whitespace-nowrap",children:s("projects.done")}),u&&i.jsx("span",{className:"text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap",children:s("projects.statusArchived")})]}),t.description&&i.jsx("p",{className:"text-sm text-bambu-gray/70 mt-1 line-clamp-1",children:t.description}),t.archives&&t.archives.length>0&&(()=>{const y=t.archives.map(_=>_.filament_type).filter(Boolean).flatMap(_=>_.split(",").map(N=>N.trim())).filter(Boolean),v=[...new Set(y)],x=t.archives.map(_=>_.filament_color).filter(Boolean).flatMap(_=>_.split(",").map(N=>N.trim())).filter(_=>_.startsWith("#")||/^[0-9A-Fa-f]{6}$/.test(_)),g=[...new Set(x)];return v.length===0&&g.length===0?null:i.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[v.slice(0,3).map(_=>i.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-bambu-dark text-bambu-gray rounded",children:_},_)),g.length>0&&i.jsxs("div",{className:"flex items-center gap-0.5",children:[g.slice(0,5).map(_=>i.jsx("div",{className:"w-3 h-3 rounded-full border border-black/20",style:{backgroundColor:_.startsWith("#")?_:`#${_}`},title:_},_)),g.length>5&&i.jsxs("span",{className:"text-[10px] text-bambu-gray ml-0.5",children:["+",g.length-5]})]})]})})()]})]}),i.jsxs("div",{className:"relative",onClick:y=>y.stopPropagation(),children:[i.jsx("button",{className:"p-1.5 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors opacity-0 group-hover:opacity-100",onClick:()=>m(!d),children:i.jsx(ph,{className:"w-4 h-4"})}),d&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>m(!1)}),i.jsxs("div",{className:"absolute right-0 top-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]",children:[i.jsxs("button",{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${a("projects:update")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{a("projects:update")&&(n(),m(!1))},disabled:!a("projects:update"),title:a("projects:update")?void 0:s("projects.noEditPermission"),children:[i.jsx(vf,{className:"w-4 h-4"}),s("common.edit")]}),i.jsxs("button",{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${a("projects:delete")?"text-red-400 hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{a("projects:delete")&&(r(),m(!1))},disabled:!a("projects:delete"),title:a("projects:delete")?void 0:s("projects.noDeletePermission"),children:[i.jsx(Jt,{className:"w-4 h-4"}),s("common.delete")]})]})]})]})]}),i.jsx("div",{className:"mb-4",children:t.target_count||t.target_parts_count?i.jsxs("div",{className:"space-y-3",children:[t.target_count&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[i.jsx("span",{className:"text-bambu-gray",children:s("projects.plates")}),i.jsxs("span",{className:o>=100?"text-bambu-green font-medium":"text-white",children:[t.archive_count," / ",t.target_count]})]}),i.jsx("div",{className:"h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm",children:i.jsx("div",{className:"h-full transition-all duration-500 ease-out rounded-full relative",style:{width:`${Math.min(o,100)}%`,background:o>=100?"linear-gradient(90deg, #22c55e, #4ade80)":`linear-gradient(90deg, ${t.color||"#6b7280"}, ${t.color||"#6b7280"}cc)`,boxShadow:`0 0 8px ${o>=100?"#22c55e":t.color||"#6b7280"}60`}})})]}),t.target_parts_count&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[i.jsx("span",{className:"text-bambu-gray",children:s("projects.parts")}),i.jsxs("span",{className:l>=100?"text-bambu-green font-medium":"text-white",children:[t.completed_count," / ",t.target_parts_count]})]}),i.jsx("div",{className:"h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm",children:i.jsx("div",{className:"h-full transition-all duration-500 ease-out rounded-full relative",style:{width:`${Math.min(l,100)}%`,background:l>=100?"linear-gradient(90deg, #22c55e, #4ade80)":`linear-gradient(90deg, ${t.color||"#6b7280"}, ${t.color||"#6b7280"}cc)`,boxShadow:`0 0 8px ${l>=100?"#22c55e":t.color||"#6b7280"}60`}})})]}),t.failed_count>0&&i.jsxs("div",{className:"text-xs text-red-400",children:[t.failed_count," ",s("projects.failed")]})]}):t.completed_count>0||t.failed_count>0?i.jsxs("div",{className:"flex items-center gap-4 text-xs",children:[t.completed_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",children:[i.jsx(zs,{className:"w-3.5 h-3.5"}),i.jsxs("span",{children:[t.completed_count," ",s("projects.completed")]})]}),t.failed_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-red-400",children:[i.jsx(Mn,{className:"w-3.5 h-3.5"}),i.jsxs("span",{children:[t.failed_count," ",s("projects.failed")]})]}),t.queue_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-blue-400",children:[i.jsx(er,{className:"w-3.5 h-3.5"}),i.jsxs("span",{children:[t.queue_count," ",s("projects.inQueue")]})]})]}):i.jsx("div",{className:"text-xs text-bambu-gray/60 italic",children:s("projects.noPrintsYet")})}),t.archives&&t.archives.length>0&&i.jsxs("div",{className:"mb-4",children:[i.jsx("div",{className:"grid grid-cols-4 gap-1.5",children:t.archives.slice(0,4).map(y=>i.jsxs("div",{className:"relative aspect-square rounded-lg bg-bambu-dark overflow-hidden border border-bambu-dark-tertiary",title:y.print_name||"Unknown",children:[y.thumbnail_path?i.jsx("img",{src:be.getArchiveThumbnail(y.id),alt:y.print_name||"",className:"w-full h-full object-cover"}):i.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray/50",children:i.jsx(Wi,{className:"w-6 h-6"})}),y.status==="failed"&&i.jsx("div",{className:"absolute inset-0 bg-red-500/40 flex items-center justify-center",children:i.jsx(Mn,{className:"w-4 h-4 text-white"})})]},y.id))}),t.archive_count>4&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1.5 text-center",children:s("common.more",{count:t.archive_count-4})})]}),i.jsxs("div",{className:"flex items-center justify-between pt-3 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-4 text-xs text-bambu-gray",children:[i.jsxs("div",{className:"flex items-center gap-1.5",title:s("projects.printJobs"),children:[i.jsx(Gi,{className:"w-3.5 h-3.5 text-blue-400"}),i.jsxs("span",{children:[t.archive_count," ",s("projects.plates")]})]}),i.jsxs("div",{className:"flex items-center gap-1.5",title:s("projects.partsPrinted"),children:[i.jsx(Wi,{className:"w-3.5 h-3.5 text-bambu-green"}),i.jsxs("span",{children:[t.completed_count," ",s("projects.parts")]})]}),t.failed_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-red-400",title:s("projects.failedParts"),children:[i.jsx(Mn,{className:"w-3.5 h-3.5"}),i.jsx("span",{children:t.failed_count})]}),t.queue_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-yellow-400",title:s("projects.inQueue"),children:[i.jsx(b3,{className:"w-3.5 h-3.5"}),i.jsx("span",{children:t.queue_count})]})]}),i.jsx(ha,{className:"w-4 h-4 text-bambu-gray/50 group-hover:text-bambu-gray transition-colors"})]})]})]})}function ott(){const{t}=Ft(),e=Qo(),n=an(),{showToast:r}=fn(),{hasPermission:a}=_r(),[s,o]=w.useState(!1),[l,c]=w.useState(),[u,d]=w.useState("active"),[m,p]=w.useState(null),{data:f,isLoading:y}=et({queryKey:["projects",u==="all"?void 0:u],queryFn:()=>be.getProjects(u==="all"?void 0:u)}),v=pt({mutationFn:G=>be.createProject(G),onSuccess:()=>{n.invalidateQueries({queryKey:["projects"]}),o(!1),r(t("projects.toast.created"),"success")},onError:G=>{r(G.message,"error")}}),x=pt({mutationFn:({id:G,data:I})=>be.updateProject(G,I),onSuccess:()=>{n.invalidateQueries({queryKey:["projects"]}),o(!1),c(void 0),r(t("projects.toast.updated"),"success")},onError:G=>{r(G.message,"error")}}),g=pt({mutationFn:G=>be.deleteProject(G),onSuccess:()=>{p(null),r(t("projects.toast.deleted"),"success"),setTimeout(()=>window.location.reload(),100)},onError:G=>{p(null),r(G.message,"error")}}),_=pt({mutationFn:G=>be.importProject(G),onSuccess:()=>{n.invalidateQueries({queryKey:["projects"]}),r(t("projects.toast.imported"),"success")},onError:G=>{r(G.message,"error")}}),N=w.useRef(null),T=async()=>{try{const G=await be.getProjects(),I=await Promise.all(G.map(async me=>await be.exportProjectJson(me.id))),ee=new Blob([JSON.stringify(I,null,2)],{type:"application/json"}),ie=URL.createObjectURL(ee),X=document.createElement("a");X.href=ie,X.download=`bambuddy_projects_${new Date().toISOString().split("T")[0]}.json`,X.click(),URL.revokeObjectURL(ie),r(t("projects.toast.exported"),"success")}catch(G){r(G.message,"error")}},C=()=>{N.current?.click()},A=async G=>{const I=G.target.files?.[0];if(I){try{if(I.name.toLowerCase().endsWith(".zip"))await be.importProjectFile(I),n.invalidateQueries({queryKey:["projects"]}),r(t("projects.toast.imported"),"success");else{const ie=await I.text(),X=JSON.parse(ie),me=Array.isArray(X)?X:[X];for(const he of me)await _.mutateAsync(he);me.length>1&&r(t("projects.toast.multipleImported",{count:me.length}),"success")}}catch(ee){r(`${t("projects.toast.importFailed")}: ${ee.message}`,"error")}G.target.value=""}},k=G=>{l?x.mutate({id:l.id,data:G}):v.mutate(G)},R=G=>{c(G),o(!0)},P=G=>{e(`/projects/${G.id}`)},D=G=>{p(G)},H=()=>{m!==null&&g.mutate(m)},z=f?.reduce((G,I)=>(G[I.status]=(G[I.status]||0)+1,G.all=(G.all||0)+1,G),{})||{};return i.jsxs("div",{className:"p-4 md:p-8 space-y-8",children:[i.jsx("input",{ref:N,type:"file",accept:".json,.zip",onChange:A,className:"hidden"}),i.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[i.jsxs("div",{children:[i.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[i.jsx("div",{className:"p-2.5 bg-bambu-green/10 rounded-xl",children:i.jsx(fs,{className:"w-6 h-6 text-bambu-green"})}),t("projects.title")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-2 ml-14",children:t("projects.subtitle")})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Oe,{variant:"secondary",onClick:C,disabled:!a("projects:create"),title:a("projects:create")?t("projects.importProject"):t("projects.noImportPermission"),children:[i.jsx(xi,{className:"w-4 h-4 mr-2"}),t("projects.import")]}),i.jsxs(Oe,{variant:"secondary",onClick:T,disabled:!a("projects:read"),title:a("projects:read")?t("projects.exportAll"):t("projects.noExportPermission"),children:[i.jsx(pi,{className:"w-4 h-4 mr-2"}),t("projects.export")]}),i.jsxs(Oe,{onClick:()=>o(!0),className:"sm:w-auto w-full",disabled:!a("projects:create"),title:a("projects:create")?void 0:t("projects.noCreatePermission"),children:[i.jsx(ar,{className:"w-4 h-4 mr-2"}),t("projects.newProject")]})]})]}),i.jsx("div",{className:"flex gap-1 p-1 bg-bambu-dark rounded-xl w-fit",children:[{key:"active",label:t("projects.statusActive"),icon:er},{key:"completed",label:t("projects.statusCompleted"),icon:Jc},{key:"archived",label:t("projects.statusArchived"),icon:zs},{key:"all",label:t("common.all"),icon:fs}].map(({key:G,label:I,icon:ee})=>i.jsxs("button",{onClick:()=>d(G),className:`flex items-center gap-2 px-4 py-2 text-sm rounded-lg transition-all ${u===G?"bg-bambu-card text-white shadow-sm":"text-bambu-gray hover:text-white"}`,children:[i.jsx(ee,{className:"w-4 h-4"}),i.jsx("span",{children:I}),z[G]>0&&i.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded-full ${u===G?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary"}`,children:z[G]})]},G))}),y?i.jsx("div",{className:"flex items-center justify-center py-20",children:i.jsxs("div",{className:"flex flex-col items-center gap-3",children:[i.jsx(ht,{className:"w-8 h-8 animate-spin text-bambu-green"}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t("projects.loading")})]})}):f?.length===0?i.jsxs("div",{className:"flex flex-col items-center justify-center py-20 px-4",children:[i.jsx("div",{className:"p-4 bg-bambu-dark rounded-2xl mb-4",children:i.jsx(fs,{className:"w-12 h-12 text-bambu-gray/50"})}),i.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:u==="all"?t("projects.noProjects"):t("projects.noProjectsFiltered",{status:u})}),i.jsx("p",{className:"text-bambu-gray text-center max-w-md mb-6",children:u==="all"?t("projects.createFirst"):t("projects.noProjectsFilteredHelp",{status:u})}),u==="all"&&i.jsxs(Oe,{onClick:()=>o(!0),disabled:!a("projects:create"),title:a("projects:create")?void 0:t("projects.noCreatePermission"),children:[i.jsx(ar,{className:"w-4 h-4 mr-2"}),t("projects.createFirstButton")]})]}):i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-8",children:f?.map(G=>i.jsx(stt,{project:G,onClick:()=>P(G),onEdit:()=>R(G),onDelete:()=>D(G.id),hasPermission:a,t},G.id))}),m!==null&&i.jsx(Sn,{title:t("projects.deleteProject"),message:t("projects.deleteConfirm"),confirmText:t("projects.deleteProject"),variant:"danger",onConfirm:H,onCancel:()=>p(null)}),s&&i.jsx(Hoe,{project:l,onClose:()=>{o(!1),c(void 0)},onSave:k,isLoading:v.isPending||x.isPending,t})]})}function ltt(t){return t>=1e3?`${(t/1e3).toFixed(2)}kg`:`${Math.round(t)}g`}function ctt({status:t,t:e}){const n={active:"bg-bambu-green/20 text-bambu-green",completed:"bg-blue-500/20 text-blue-400",archived:"bg-bambu-gray/20 text-bambu-gray"},r=n[t]||n.active,a={active:e("projectDetail.status.active"),completed:e("projectDetail.status.completed"),archived:e("projectDetail.status.archived")};return i.jsx("span",{className:`px-2 py-1 rounded text-sm font-medium ${r}`,children:a[t]||t.charAt(0).toUpperCase()+t.slice(1)})}function MY({icon:t,label:e,value:n,subValue:r,hint:a,color:s="text-bambu-gray"}){return i.jsx(Mt,{children:i.jsx(Dt,{className:"p-4",children:i.jsxs("div",{className:"flex items-center gap-3",title:a,children:[i.jsx("div",{className:`p-2 rounded-lg bg-bambu-dark ${s}`,children:i.jsx(t,{className:"w-5 h-5"})}),i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:e}),i.jsx("p",{className:"text-xl font-semibold text-white",children:n}),r&&i.jsx("p",{className:"text-xs text-bambu-gray/70",children:r})]})]})})})}function utt({archives:t,t:e}){return t.length===0?i.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[i.jsx(Wi,{className:"w-12 h-12 mx-auto mb-2 opacity-50"}),i.jsx("p",{children:e("projectDetail.noPrints")})]}):i.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3",children:t.map(n=>i.jsxs(io,{to:`/archives?search=${encodeURIComponent(n.print_name||"")}`,className:"group relative aspect-square rounded-lg bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden hover:border-bambu-green transition-colors",children:[n.thumbnail_path?i.jsx("img",{src:be.getArchiveThumbnail(n.id),alt:n.print_name||"Print",className:"w-full h-full object-cover"}):i.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:i.jsx(Wi,{className:"w-8 h-8"})}),n.status==="failed"&&i.jsx("div",{className:"absolute inset-0 bg-red-500/30 flex items-center justify-center",children:i.jsx(Vi,{className:"w-8 h-8 text-white"})}),n.status==="completed"&&i.jsx("div",{className:"absolute top-1 right-1",children:i.jsx(fr,{className:"w-4 h-4 text-bambu-green"})}),i.jsx("div",{className:"absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity",children:i.jsx("p",{className:"text-xs text-white truncate",children:n.print_name||"Unknown"})})]},n.id))})}function dtt({priority:t,t:e}){const n={low:{color:"bg-gray-500/20 text-gray-400",label:e("projectDetail.priority.low")},normal:{color:"bg-blue-500/20 text-blue-400",label:e("projectDetail.priority.normal")},high:{color:"bg-orange-500/20 text-orange-400",label:e("projectDetail.priority.high")},urgent:{color:"bg-red-500/20 text-red-400",label:e("projectDetail.priority.urgent")}},{color:r,label:a}=n[t]||n.normal;return i.jsxs("span",{className:`px-2 py-1 rounded text-xs font-medium flex items-center gap-1 ${r}`,children:[t==="urgent"&&i.jsx(Mn,{className:"w-3 h-3"}),a]})}function qD(t,e){if(!t)return null;const n=Jn(t);if(!n)return null;const r=new Date,a=Math.ceil((n.getTime()-r.getTime())/(1e3*60*60*24));return a<0?{color:"text-red-400",label:e("projectDetail.dueDate.overdue")}:a===0?{color:"text-orange-400",label:e("projectDetail.dueDate.today")}:a<=3?{color:"text-yellow-400",label:e("projectDetail.dueDate.daysLeft",{count:a})}:{color:"text-bambu-gray",label:e("projectDetail.dueDate.daysLeft",{count:a})}}function mtt(){const{id:t}=uw(),e=Qo(),{t:n}=Ft(),r=an(),{showToast:a}=fn(),{hasPermission:s}=_r(),[o,l]=w.useState(!1),[c,u]=w.useState(!1),[d,m]=w.useState(""),p=parseInt(t||"0",10),{data:f,isLoading:y,error:v}=et({queryKey:["project",p],queryFn:()=>be.getProject(p),enabled:p>0}),{data:x,isLoading:g}=et({queryKey:["project-archives",p],queryFn:()=>be.getProjectArchives(p),enabled:p>0}),{data:_,isLoading:N}=et({queryKey:["project-bom",p],queryFn:()=>be.getProjectBOM(p),enabled:p>0}),{data:T,isLoading:C}=et({queryKey:["project-timeline",p],queryFn:()=>be.getProjectTimeline(p,20),enabled:p>0}),{data:A}=et({queryKey:["settings"],queryFn:be.getSettings}),{data:k}=et({queryKey:["project-folders",p],queryFn:()=>be.getLibraryFoldersByProject(p),enabled:p>0}),R=_l(A?.currency||"USD"),P=A?.time_format||"system",D=pt({mutationFn:je=>be.updateProject(p,je),onSuccess:()=>{r.invalidateQueries({queryKey:["project",p]}),r.invalidateQueries({queryKey:["projects"]}),l(!1),u(!1),a(n("projectDetail.toast.projectUpdated"),"success")},onError:je=>{a(je.message,"error")}}),H=()=>{m(f?.notes||""),u(!0)},z=()=>{D.mutate({notes:d})},G=()=>{u(!1),m("")},[I,ee]=w.useState(""),[ie,X]=w.useState(1),[me,he]=w.useState(""),[ge,Y]=w.useState(""),[oe,le]=w.useState(""),[xe,Pe]=w.useState(!1),[q,Z]=w.useState(!1),[j,E]=w.useState(null),[U,K]=w.useState(""),[$,ne]=w.useState(1),[O,V]=w.useState(""),[J,W]=w.useState(""),[re,ue]=w.useState(""),[fe,ye]=w.useState({isOpen:!1,title:"",message:"",onConfirm:()=>{}}),ae=pt({mutationFn:je=>be.createBOMItem(p,je),onSuccess:()=>{r.invalidateQueries({queryKey:["project-bom",p]}),r.invalidateQueries({queryKey:["project",p]}),ee(""),X(1),he(""),Y(""),le(""),Pe(!1),a(n("projectDetail.toast.partAdded"),"success")},onError:je=>a(je.message,"error")}),L=pt({mutationFn:({itemId:je,data:Xe})=>be.updateBOMItem(p,je,Xe),onSuccess:()=>{r.invalidateQueries({queryKey:["project-bom",p]}),r.invalidateQueries({queryKey:["project",p]}),E(null)},onError:je=>a(je.message,"error")}),F=pt({mutationFn:je=>be.deleteBOMItem(p,je),onSuccess:()=>{r.invalidateQueries({queryKey:["project-bom",p]}),r.invalidateQueries({queryKey:["project",p]}),a(n("projectDetail.toast.partRemoved"),"success")},onError:je=>a(je.message,"error")}),te=je=>{je.preventDefault(),I.trim()&&ae.mutate({name:I.trim(),quantity_needed:ie,unit_price:me?parseFloat(me):void 0,sourcing_url:ge.trim()||void 0,remarks:oe.trim()||void 0})},ve=je=>{const Xe=je.is_complete?0:je.quantity_needed;L.mutate({itemId:je.id,data:{quantity_acquired:Xe}})},pe=(je,Xe)=>{ye({isOpen:!0,title:n("projectDetail.bom.deletePart"),message:n("projectDetail.bom.deleteConfirm",{name:Xe}),onConfirm:()=>{ye(ce=>({...ce,isOpen:!1})),F.mutate(je)}})},de=je=>{E(je),K(je.name),ne(je.quantity_needed),V(je.unit_price?.toString()||""),W(je.sourcing_url||""),ue(je.remarks||"")},Ne=je=>{je.preventDefault(),!(!j||!U.trim())&&L.mutate({itemId:j.id,data:{name:U.trim(),quantity_needed:$,unit_price:O?parseFloat(O):void 0,sourcing_url:J.trim()||void 0,remarks:re.trim()||void 0}})},Se=()=>{E(null)},Le=async()=>{try{const{blob:je,filename:Xe}=await be.exportProjectZip(Number(p)),ce=URL.createObjectURL(je),Ie=document.createElement("a");Ie.href=ce,Ie.download=Xe||`${f?.name||"project"}_${new Date().toISOString().split("T")[0]}.zip`,Ie.click(),URL.revokeObjectURL(ce),a(n("projectDetail.toast.projectExported"),"success")}catch(je){a(je.message,"error")}},qe=pt({mutationFn:()=>be.createTemplateFromProject(p),onSuccess:()=>{r.invalidateQueries({queryKey:["projects"]}),a(n("projectDetail.toast.templateCreated"),"success")},onError:je=>a(je.message,"error")}),Ee=je=>Nf(je,P,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"});if(y)return i.jsx("div",{className:"flex items-center justify-center py-24",children:i.jsx(ht,{className:"w-8 h-8 animate-spin text-bambu-green"})});if(v||!f)return i.jsxs("div",{className:"text-center py-24",children:[i.jsx("p",{className:"text-bambu-gray",children:v?`${n("common.error")}: ${v.message}`:n("projectDetail.notFound")}),i.jsx(Oe,{variant:"secondary",className:"mt-4",onClick:()=>e("/projects"),children:n("projectDetail.backToProjects")})]});const Te=f.stats,Ae=Te?.progress_percent??0,Be=Te?.parts_progress_percent??0;return i.jsxs("div",{className:"p-4 md:p-8 space-y-8",children:[i.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[i.jsx(io,{to:"/projects",className:"hover:text-white transition-colors",children:n("navigation.projects")}),i.jsx(ha,{className:"w-4 h-4"}),i.jsx("span",{className:"text-white",children:f.name})]}),i.jsxs("div",{className:"flex items-start justify-between",children:[i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx("button",{onClick:()=>e("/projects"),className:"p-2 rounded-lg bg-bambu-card hover:bg-bambu-dark-tertiary transition-colors",children:i.jsx(IX,{className:"w-5 h-5 text-bambu-gray"})}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"w-4 h-4 rounded-full flex-shrink-0",style:{backgroundColor:f.color||"#6b7280"}}),i.jsxs("div",{children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:f.name}),f.description&&i.jsx("p",{className:"text-bambu-gray mt-1",children:f.description})]})]}),i.jsx(ctt,{status:f.status,t:n})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Oe,{variant:"secondary",onClick:Le,disabled:!s("projects:read"),title:s("projects:read")?n("projectDetail.exportProject"):n("projectDetail.noExportPermission"),children:[i.jsx(pi,{className:"w-4 h-4 mr-2"}),n("projectDetail.export")]}),i.jsxs(Oe,{onClick:()=>l(!0),disabled:!s("projects:update"),title:s("projects:update")?void 0:n("projectDetail.noEditPermission"),children:[i.jsx(vf,{className:"w-4 h-4 mr-2"}),n("common.edit")]})]})]}),(f.target_count||f.target_parts_count)&&i.jsx(Mt,{children:i.jsxs(Dt,{className:"p-4 space-y-4",children:[f.target_count&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:n("projectDetail.progress.platesProgress")}),i.jsxs("span",{className:"text-sm font-medium text-white",children:[Te?.total_archives||0," / ",f.target_count," ",n("projectDetail.progress.printJobs")]})]}),i.jsx("div",{className:"h-3 bg-bambu-dark rounded-full overflow-hidden",children:i.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${Math.min(Ae,100)}%`,backgroundColor:Ae>=100?"#22c55e":f.color||"#6b7280"}})}),i.jsxs("div",{className:"flex justify-between mt-1",children:[i.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.percentComplete",{percent:Ae.toFixed(0)})}),Te?.remaining_prints!=null&&Te.remaining_prints>0&&i.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.remaining",{count:Te.remaining_prints})})]})]}),f.target_parts_count&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:n("projectDetail.progress.partsProgress")}),i.jsxs("span",{className:"text-sm font-medium text-white",children:[Te?.completed_prints||0," / ",f.target_parts_count," ",n("projectDetail.progress.parts")]})]}),i.jsx("div",{className:"h-3 bg-bambu-dark rounded-full overflow-hidden",children:i.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${Math.min(Be,100)}%`,backgroundColor:Be>=100?"#22c55e":f.color||"#6b7280"}})}),i.jsxs("div",{className:"flex justify-between mt-1",children:[i.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.percentComplete",{percent:Be.toFixed(0)})}),Te?.remaining_parts!=null&&Te.remaining_parts>0&&i.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.remaining",{count:Te.remaining_parts})})]})]})]})}),Te&&i.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[i.jsx(Mt,{children:i.jsx(Dt,{className:"p-4",children:i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:i.jsx(Wi,{className:"w-5 h-5"})}),i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:n("projectDetail.stats.printJobs")}),i.jsxs("p",{className:"text-xl font-semibold text-white",children:[Te.total_archives," ",i.jsx("span",{className:"text-sm font-normal text-bambu-gray",children:n("projectDetail.stats.total")})]}),Te.failed_prints>0&&i.jsx("p",{className:"text-sm text-status-error",children:n("projectDetail.stats.failed",{count:Te.failed_prints})}),i.jsx("p",{className:"text-sm text-bambu-gray",children:n("projectDetail.stats.partsPrinted",{count:Te.completed_prints})})]})]})})}),i.jsx(MY,{icon:er,label:n("projectDetail.stats.printTime"),value:rxe(Te.total_print_time_hours),color:"text-yellow-400"}),i.jsx(MY,{icon:Sr,label:n("projectDetail.stats.filamentUsed"),value:ltt(Te.total_filament_grams),color:"text-purple-400"})]}),Te&&(Te.estimated_cost>0||f.budget)&&i.jsx(Mt,{children:i.jsxs(Dt,{className:"p-4",children:[i.jsx("h2",{className:"text-lg font-semibold text-white mb-3",children:n("projectDetail.cost.title")}),i.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.filamentCost")}),i.jsxs("p",{className:"text-lg font-semibold text-white",children:[R,Te.estimated_cost.toFixed(2)]})]}),Te.total_energy_kwh>0&&i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.energy")}),i.jsxs("p",{className:"text-lg font-semibold text-white",children:[Te.total_energy_kwh.toFixed(3)," kWh",Te.total_energy_cost>0&&i.jsxs("span",{className:"text-sm text-bambu-gray ml-1",children:["(",R,Te.total_energy_cost.toFixed(2),")"]})]})]}),f.budget&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.budget")}),i.jsxs("p",{className:"text-lg font-semibold text-white",children:[R,f.budget.toFixed(2)]})]}),i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.remaining")}),i.jsxs("p",{className:`text-lg font-semibold ${f.budget-Te.estimated_cost>=0?"text-bambu-green":"text-red-400"}`,children:[R,(f.budget-Te.estimated_cost).toFixed(2)]})]})]})]})]})}),f.children&&f.children.length>0&&i.jsx(Mt,{children:i.jsxs(Dt,{className:"p-4",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-3",children:[i.jsx(Zpe,{className:"w-5 h-5"}),n("projectDetail.subProjects.title",{count:f.children.length})]}),i.jsx("div",{className:"space-y-2",children:f.children.map(je=>i.jsxs(io,{to:`/projects/${je.id}`,className:"flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:je.color||"#6b7280"}}),i.jsx("span",{className:"text-white",children:je.name}),i.jsx("span",{className:`text-xs px-2 py-0.5 rounded ${je.status==="completed"?"bg-status-ok/20 text-status-ok":je.status==="archived"?"bg-bambu-gray/20 text-bambu-gray":"bg-blue-500/20 text-blue-400"}`,children:je.status})]}),je.progress_percent!==null&&i.jsxs("span",{className:"text-sm text-bambu-gray",children:[je.progress_percent.toFixed(0),"%"]})]},je.id))})]})}),f.parent_id&&f.parent_name&&i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx(Gi,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"text-bambu-gray",children:n("projectDetail.partOf")}),i.jsx(io,{to:`/projects/${f.parent_id}`,className:"text-bambu-green hover:underline",children:f.parent_name})]}),(f.tags||f.due_date||f.priority!=="normal")&&i.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[f.priority&&f.priority!=="normal"&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.priorityLabel")}),i.jsx(dtt,{priority:f.priority,t:n})]}),f.due_date&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Wr,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"text-sm text-white",children:_f(f.due_date,{year:"numeric",month:"short",day:"numeric"})}),qD(f.due_date,n)&&i.jsxs("span",{className:`text-xs ${qD(f.due_date,n).color}`,children:["(",qD(f.due_date,n).label,")"]})]}),f.tags&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Dd,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("div",{className:"flex flex-wrap gap-1",children:f.tags.split(",").map((je,Xe)=>i.jsx("span",{className:"px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded",children:je.trim()},Xe))})]})]}),i.jsx(Mt,{children:i.jsxs(Dt,{className:"p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Fs,{className:"w-5 h-5"}),n("projectDetail.notes.title")]}),c?i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:G,disabled:D.isPending,children:[i.jsx(Ht,{className:"w-4 h-4 mr-1"}),n("common.cancel")]}),i.jsxs(Oe,{size:"sm",onClick:z,disabled:D.isPending,children:[D.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin mr-1"}):i.jsx(ts,{className:"w-4 h-4 mr-1"}),n("common.save")]})]}):i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:H,disabled:!s("projects:update"),title:s("projects:update")?void 0:n("projectDetail.notes.noEditPermission"),children:[i.jsx(vf,{className:"w-4 h-4 mr-1"}),n("common.edit")]})]}),c?i.jsx(dL,{content:d,onChange:m,placeholder:n("projectDetail.notes.placeholder")}):f.notes?i.jsx("div",{className:"prose prose-invert prose-sm max-w-none",dangerouslySetInnerHTML:{__html:pie.sanitize(f.notes)}}):i.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.notes.empty")})]})}),i.jsx(Mt,{children:i.jsxs(Dt,{className:"p-4",children:[i.jsx("div",{className:"flex items-center justify-between mb-3",children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Nc,{className:"w-5 h-5"}),n("projectDetail.files.title")]})}),i.jsxs("p",{className:"text-xs text-bambu-gray mb-3",children:[i.jsx(io,{to:"/files",className:"text-bambu-green hover:underline",children:n("projectDetail.files.linkFolders")})," ",n("projectDetail.files.forQuickAccess")]}),k&&k.length>0?i.jsx("div",{className:"space-y-2",children:k.map(je=>i.jsxs(io,{to:`/files?folder=${je.id}`,className:"flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i.jsx(Nc,{className:"w-5 h-5 text-bambu-green flex-shrink-0"}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-sm text-white truncate",children:je.name}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("projectDetail.files.fileCount",{count:je.file_count})})]})]}),i.jsx(ha,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"})]},je.id))}):i.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.files.empty")})]})}),i.jsx(Mt,{children:i.jsxs(Dt,{className:"p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(XX,{className:"w-5 h-5"}),n("projectDetail.bom.title"),Te&&Te.bom_total_items>0&&i.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",n("projectDetail.bom.acquired",{completed:Te.bom_completed_items,total:Te.bom_total_items}),")"]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[_&&_.some(je=>je.is_complete)&&i.jsx("button",{onClick:()=>Z(!q),className:`text-xs px-2 py-1 rounded transition-colors ${q?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:n(q?"projectDetail.bom.showAll":"projectDetail.bom.hideDone")}),!xe&&i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>Pe(!0),disabled:!s("projects:update"),title:s("projects:update")?void 0:n("projectDetail.bom.noAddPermission"),children:[i.jsx(ar,{className:"w-4 h-4 mr-1"}),n("projectDetail.bom.addPart")]})]})]}),xe&&i.jsxs("form",{onSubmit:te,className:"bg-bambu-dark rounded-lg p-4 mb-4 space-y-3",children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[i.jsx("input",{type:"text",value:I,onChange:je=>ee(je.target.value),className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.partNamePlaceholder"),autoFocus:!0}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"number",value:ie,onChange:je=>X(parseInt(je.target.value)||1),className:"w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green",min:"1",placeholder:n("projectDetail.bom.qty")}),i.jsx("input",{type:"number",step:"0.01",value:me,onChange:je=>he(je.target.value),className:"flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.price",{currency:R})})]})]}),i.jsx("input",{type:"url",value:ge,onChange:je=>Y(je.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.sourcingUrlPlaceholder")}),i.jsx("input",{type:"text",value:oe,onChange:je=>le(je.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.remarksPlaceholder")}),i.jsxs("div",{className:"flex justify-end gap-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",size:"sm",onClick:()=>Pe(!1),children:n("common.cancel")}),i.jsx(Oe,{type:"submit",size:"sm",disabled:!I.trim()||ae.isPending,children:ae.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):n("projectDetail.bom.addPart")})]})]}),N?i.jsx("div",{className:"flex items-center justify-center py-4",children:i.jsx(ht,{className:"w-6 h-6 animate-spin text-bambu-green"})}):_&&_.length>0?i.jsxs("div",{className:"space-y-2",children:[_.filter(je=>!q||!je.is_complete).map(je=>i.jsx("div",{className:`p-3 rounded-lg transition-colors ${je.is_complete?"bg-status-ok/10":"bg-bambu-dark"}`,children:j?.id===je.id?i.jsxs("form",{onSubmit:Ne,className:"space-y-3",children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[i.jsx("input",{type:"text",value:U,onChange:Xe=>K(Xe.target.value),className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.partName"),autoFocus:!0}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"number",value:$,onChange:Xe=>ne(parseInt(Xe.target.value)||1),className:"w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green",min:"1",placeholder:n("projectDetail.bom.qty")}),i.jsx("input",{type:"number",step:"0.01",value:O,onChange:Xe=>V(Xe.target.value),className:"flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.price",{currency:R})})]})]}),i.jsx("input",{type:"url",value:J,onChange:Xe=>W(Xe.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.sourcingUrlPlaceholder")}),i.jsx("input",{type:"text",value:re,onChange:Xe=>ue(Xe.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.remarksPlaceholder")}),i.jsxs("div",{className:"flex justify-end gap-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",size:"sm",onClick:Se,children:n("common.cancel")}),i.jsx(Oe,{type:"submit",size:"sm",disabled:!U.trim()||L.isPending,children:L.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):n("common.save")})]})]}):i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx("button",{onClick:()=>s("projects:update")&&ve(je),disabled:L.isPending||!s("projects:update"),title:s("projects:update")?void 0:n("projectDetail.bom.noUpdatePermission"),className:`w-5 h-5 mt-0.5 rounded border-2 flex items-center justify-center transition-colors flex-shrink-0 ${je.is_complete?"bg-status-ok border-status-ok text-white":s("projects:update")?"border-bambu-gray hover:border-bambu-green":"border-bambu-gray/50 cursor-not-allowed"}`,children:je.is_complete&&i.jsx(fr,{className:"w-3 h-3"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[i.jsxs("p",{className:`text-sm font-medium ${je.is_complete?"text-bambu-gray line-through":"text-white"}`,children:[je.name,i.jsxs("span",{className:"text-bambu-gray font-normal ml-2",children:["x",je.quantity_needed]})]}),je.unit_price!==null&&i.jsxs("span",{className:"text-xs text-bambu-green whitespace-nowrap",children:[R,(je.unit_price*je.quantity_needed).toFixed(2)]})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("button",{onClick:()=>s("projects:update")&&de(je),disabled:!s("projects:update"),className:`p-1 rounded transition-colors flex-shrink-0 ${s("projects:update")?"hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("projects:update")?n("common.edit"):n("projectDetail.bom.noEditPermission"),children:i.jsx(Yi,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>s("projects:update")&&pe(je.id,je.name),disabled:!s("projects:update"),className:`p-1 rounded transition-colors flex-shrink-0 ${s("projects:update")?"hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-red-400":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("projects:update")?n("common.delete"):n("projectDetail.bom.noDeletePermission"),children:i.jsx(Jt,{className:"w-4 h-4"})})]})]}),je.sourcing_url&&i.jsxs("a",{href:je.sourcing_url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 mt-1 text-xs text-blue-400 hover:text-blue-300 transition-colors",onClick:Xe=>Xe.stopPropagation(),children:[i.jsx(Jr,{className:"w-3 h-3 flex-shrink-0"}),i.jsx("span",{className:"truncate",children:(()=>{try{return new URL(je.sourcing_url).hostname.replace("www.","")}catch{return je.sourcing_url}})()})]}),je.remarks&&i.jsx("p",{className:"mt-1 text-xs text-bambu-gray/80 italic",children:je.remarks})]})]})},je.id)),_.some(je=>je.unit_price!==null)&&i.jsxs("div",{className:"pt-2 mt-2 border-t border-bambu-dark-tertiary flex justify-between text-sm",children:[i.jsx("span",{className:"text-bambu-gray",children:n("projectDetail.bom.totalCost")}),i.jsxs("span",{className:"text-white font-medium",children:[R,_.reduce((je,Xe)=>je+(Xe.unit_price||0)*Xe.quantity_needed,0).toFixed(2)]})]})]}):i.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.bom.empty")})]})}),i.jsx(Mt,{children:i.jsxs(Dt,{className:"p-4",children:[i.jsx("div",{className:"flex items-center justify-between mb-3",children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(f0,{className:"w-5 h-5"}),n("projectDetail.timeline.title")]})}),C?i.jsx("div",{className:"flex items-center justify-center py-4",children:i.jsx(ht,{className:"w-6 h-6 animate-spin text-bambu-green"})}):T&&T.length>0?i.jsx("div",{className:"space-y-3",children:T.slice(0,10).map((je,Xe)=>i.jsxs("div",{className:"flex gap-3",children:[i.jsxs("div",{className:`w-8 h-8 rounded-full flex items-center justify-center flex-shrink-0 ${je.event_type==="print_completed"?"bg-status-ok/20 text-status-ok":je.event_type==="print_failed"?"bg-status-error/20 text-status-error":je.event_type==="print_started"?"bg-yellow-500/20 text-yellow-400":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:[je.event_type==="print_completed"&&i.jsx(fr,{className:"w-4 h-4"}),je.event_type==="print_failed"&&i.jsx(Vi,{className:"w-4 h-4"}),je.event_type==="print_started"&&i.jsx(Sr,{className:"w-4 h-4"}),je.event_type==="queued"&&i.jsx(b3,{className:"w-4 h-4"}),je.event_type==="project_created"&&i.jsx(ar,{className:"w-4 h-4"})]}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-sm text-white",children:je.title}),je.description&&i.jsx("p",{className:"text-xs text-bambu-gray truncate",children:je.description}),i.jsx("p",{className:"text-xs text-bambu-gray/70",children:Ee(je.timestamp)})]})]},Xe))}):i.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.timeline.empty")})]})}),!f.is_template&&i.jsx("div",{className:"flex justify-end",children:i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>qe.mutate(),disabled:qe.isPending||!s("projects:create"),title:s("projects:create")?void 0:n("projectDetail.template.noCreatePermission"),children:[qe.isPending?i.jsx(ht,{className:"w-4 h-4 animate-spin mr-2"}):i.jsx(fo,{className:"w-4 h-4 mr-2"}),n("projectDetail.template.saveAsTemplate")]})}),Te&&(Te.queued_prints>0||Te.in_progress_prints>0)&&i.jsx(Mt,{children:i.jsxs(Dt,{className:"p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(b3,{className:"w-5 h-5"}),n("projectDetail.queue.title")]}),i.jsx(io,{to:`/queue?project=${p}`,className:"text-sm text-bambu-green hover:underline",children:n("projectDetail.queue.viewAll")})]}),i.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[Te.in_progress_prints>0&&i.jsx("span",{className:"text-yellow-400",children:n("projectDetail.queue.printing",{count:Te.in_progress_prints})}),Te.queued_prints>0&&i.jsx("span",{className:"text-bambu-gray",children:n("projectDetail.queue.queued",{count:Te.queued_prints})})]})]})}),i.jsxs("div",{children:[i.jsx("div",{className:"flex items-center justify-between mb-4",children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Wi,{className:"w-5 h-5"}),n("projectDetail.prints.title",{count:x?.length||0})]})}),g?i.jsx("div",{className:"flex items-center justify-center py-8",children:i.jsx(ht,{className:"w-6 h-6 animate-spin text-bambu-green"})}):i.jsx(utt,{archives:x||[],t:n})]}),o&&i.jsx(Hoe,{t:n,project:{...f,archive_count:Te?.total_archives||0,total_items:Te?.total_items||0,completed_count:Te?.completed_prints||0,failed_count:Te?.failed_prints||0,queue_count:Te?.queued_prints||0,progress_percent:Te?.progress_percent||null,archives:[]},onClose:()=>l(!1),onSave:je=>D.mutate(je),isLoading:D.isPending}),fe.isOpen&&i.jsx(Sn,{title:fe.title,message:fe.message,confirmText:n("common.delete"),variant:"danger",onConfirm:fe.onConfirm,onCancel:()=>ye(je=>({...je,isOpen:!1}))})]})}function htt({parentId:t,onClose:e,onSave:n,isLoading:r,t:a}){const[s,o]=w.useState(""),l=c=>{c.preventDefault(),n({name:s.trim(),parent_id:t})};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary",children:[i.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("fileManager.newFolder")})}),i.jsxs("form",{onSubmit:l,className:"p-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("fileManager.folderName")}),i.jsx("input",{type:"text",value:s,onChange:c=>o(c.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:a("fileManager.folderNamePlaceholder"),autoFocus:!0,required:!0})]}),i.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,children:a("common.cancel")}),i.jsx(Oe,{type:"submit",disabled:!s.trim()||r,children:r?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):a("common.create")})]})]})]})})}function ptt({type:t,currentName:e,onClose:n,onSave:r,isLoading:a,t:s}){const[o,l]=w.useState(e),c=u=>{u.preventDefault(),o.trim()&&o.trim()!==e&&r(o.trim())};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary",children:[i.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:s(t==="file"?"fileManager.renameFile":"fileManager.renameFolder")})}),i.jsxs("form",{onSubmit:c,className:"p-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("common.name")}),i.jsx("input",{type:"text",value:o,onChange:u=>l(u.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",autoFocus:!0,required:!0})]}),i.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:n,children:s("common.cancel")}),i.jsx(Oe,{type:"submit",disabled:!o.trim()||o.trim()===e||a,children:a?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):s("common.rename")})]})]})]})})}function ftt({folders:t,selectedFiles:e,currentFolderId:n,onClose:r,onMove:a,isLoading:s,t:o}){const[l,c]=w.useState(null),u=(m,p=0)=>{const f=[];for(const y of m)f.push({id:y.id,name:y.name,depth:p}),y.children.length>0&&f.push(...u(y.children,p+1));return f},d=[{id:null,name:o("fileManager.rootNoFolder"),depth:0},...u(t)];return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary",children:[i.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:o("fileManager.moveFiles",{count:e.length})})}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1",children:d.map(m=>i.jsxs("button",{onClick:()=>c(m.id),disabled:m.id===n,className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${l===m.id?"bg-bambu-green/20 text-bambu-green":m.id===n?"opacity-50 cursor-not-allowed text-bambu-gray":"hover:bg-bambu-dark text-white"}`,style:{paddingLeft:`${12+m.depth*16}px`},children:[i.jsx(Nc,{className:"w-4 h-4"}),m.name,m.id===n&&i.jsxs("span",{className:"text-xs text-bambu-gray ml-auto",children:["(",o("fileManager.current"),")"]})]},m.id??"root"))}),i.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:r,children:o("common.cancel")}),i.jsx(Oe,{onClick:()=>a(l),disabled:s,children:s?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):o("common.move")})]})]})]})})}function gtt({folder:t,onClose:e,onLink:n,isLoading:r,t:a}){const[s,o]=w.useState("project"),[l,c]=w.useState(t.project_id||t.archive_id||null);w.useState(()=>{t.archive_id&&o("archive")});const{data:u}=et({queryKey:["projects"],queryFn:()=>be.getProjects()}),{data:d}=et({queryKey:["archives-for-link"],queryFn:()=>be.getArchives(void 0,void 0,100)}),m=()=>{n(s==="project"?{project_id:l,archive_id:0}:{project_id:0,archive_id:l})},p=()=>{n({project_id:0,archive_id:0})},f=t.project_id||t.archive_id;return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(xh,{className:"w-5 h-5 text-bambu-green"}),a("fileManager.linkFolder")]}),i.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark rounded",children:i.jsx(Ht,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("fileManager.linkFolderDescription",{name:t.name})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("button",{onClick:()=>{o("project"),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${s==="project"?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,children:[i.jsx(zX,{className:"w-4 h-4"}),a("fileManager.project")]}),i.jsxs("button",{onClick:()=>{o("archive"),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${s==="archive"?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,children:[i.jsx(zs,{className:"w-4 h-4"}),a("fileManager.archive")]})]}),i.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1 bg-bambu-dark rounded-lg p-2",children:s==="project"?u&&u.length>0?u.map(y=>i.jsxs("button",{onClick:()=>c(y.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${l===y.id?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark-tertiary text-white"}`,children:[i.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:y.color||"#00ae42"}}),i.jsx("span",{className:"truncate",children:y.name})]},y.id)):i.jsx("p",{className:"text-sm text-bambu-gray text-center py-4",children:a("fileManager.noProjectsFound")}):d&&d.length>0?d.map(y=>i.jsxs("button",{onClick:()=>c(y.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${l===y.id?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark-tertiary text-white"}`,children:[i.jsx(nf,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),i.jsx("span",{className:"truncate",children:y.print_name||y.filename})]},y.id)):i.jsx("p",{className:"text-sm text-bambu-gray text-center py-4",children:a("fileManager.noArchivesFound")})})]}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-between",children:[f&&i.jsxs(Oe,{variant:"danger",onClick:p,disabled:r,children:[i.jsx(g0,{className:"w-4 h-4 mr-2"}),a("fileManager.unlink")]}),i.jsxs("div",{className:`flex gap-2 ${f?"":"ml-auto"}`,children:[i.jsx(Oe,{variant:"secondary",onClick:e,children:a("common.cancel")}),i.jsx(Oe,{onClick:m,disabled:!l||r,children:r?i.jsx(ht,{className:"w-4 h-4 animate-spin"}):a("fileManager.link")})]})]})]})})}function $oe({folder:t,selectedFolderId:e,onSelect:n,onDelete:r,onLink:a,onRename:s,depth:o=0,wrapNames:l=!1,hasPermission:c,t:u}){const[d,m]=w.useState(!0),[p,f]=w.useState(!1),y=t.children.length>0,v=t.project_id||t.archive_id;return i.jsxs("div",{children:[i.jsxs("div",{className:`group flex items-center gap-1 px-2 py-1.5 rounded cursor-pointer transition-colors ${e===t.id?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark text-white"}`,style:{paddingLeft:`${8+o*12}px`},onClick:()=>n(t.id),children:[y?i.jsx("button",{onClick:x=>{x.stopPropagation(),m(!d)},className:"p-0.5 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(ha,{className:`w-3.5 h-3.5 transition-transform ${d?"rotate-90":""}`})}):i.jsx("div",{className:"w-4.5"}),i.jsx(Nc,{className:"w-4 h-4 text-bambu-green flex-shrink-0"}),i.jsx("span",{className:`text-sm flex-1 min-w-0 ${l?"break-all":"truncate"}`,title:t.name,children:t.name}),v&&i.jsxs("button",{onClick:x=>{x.stopPropagation(),a(t)},className:"flex-shrink-0 flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-400 hover:bg-blue-500/30 transition-colors",title:`${t.project_name?`Project: ${t.project_name}`:`Archive: ${t.archive_name}`} (click to change)`,children:[i.jsx(xh,{className:"w-3 h-3"}),t.project_name?i.jsx(zX,{className:"w-3 h-3"}):i.jsx(zs,{className:"w-3 h-3"})]}),t.file_count>0&&i.jsx("span",{className:"flex-shrink-0 text-xs text-bambu-gray",children:t.file_count}),!v&&i.jsx("button",{onClick:x=>{x.stopPropagation(),a(t)},className:"flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary",title:u("fileManager.linkToProjectOrArchive"),children:i.jsx(xh,{className:"w-3.5 h-3.5 text-bambu-gray hover:text-bambu-green"})}),i.jsx("div",{className:`flex-shrink-0 flex items-center gap-0.5 transition-opacity ${l?"":"opacity-0 group-hover:opacity-100"}`,onClick:x=>x.stopPropagation(),children:i.jsxs("div",{className:"relative",children:[i.jsx("button",{onClick:()=>f(!p),className:"p-1 rounded hover:bg-bambu-dark-tertiary",children:i.jsx(ph,{className:"w-3.5 h-3.5 text-bambu-gray"})}),p&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>f(!1)}),i.jsxs("div",{className:"absolute right-0 top-full mt-1 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]",children:[i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${c("library:update_all")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{c("library:update_all")&&(s(t),f(!1))},disabled:!c("library:update_all"),title:c("library:update_all")?void 0:u("fileManager.noPermissionRenameFolder"),children:[i.jsx(Yi,{className:"w-3.5 h-3.5"}),u("common.rename")]}),i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${c("library:update_all")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{c("library:update_all")&&(a(t),f(!1))},disabled:!c("library:update_all"),title:c("library:update_all")?void 0:u("fileManager.noPermissionLinkFolder"),children:[i.jsx(xh,{className:"w-3.5 h-3.5"}),u(v?"fileManager.changeLink":"fileManager.linkTo")]}),i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${c("library:delete_all")?"text-red-400 hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{c("library:delete_all")&&(r(t.id),f(!1))},disabled:!c("library:delete_all"),title:c("library:delete_all")?void 0:u("fileManager.noPermissionDeleteFolder"),children:[i.jsx(Jt,{className:"w-3.5 h-3.5"}),u("common.delete")]})]})]})]})})]}),y&&d&&i.jsx("div",{children:t.children.map(x=>i.jsx($oe,{folder:x,selectedFolderId:e,onSelect:n,onDelete:r,onLink:a,onRename:s,depth:o+1,wrapNames:l,hasPermission:c,t:u},x.id))})]})}function yL(t){const e=t.toLowerCase();return e.endsWith(".gcode")||e.includes(".gcode.")}function btt({file:t,isSelected:e,isMobile:n,onSelect:r,onDelete:a,onDownload:s,onAddToQueue:o,onPrint:l,onPreview3d:c,onRename:u,onGenerateThumbnail:d,thumbnailVersion:m,hasPermission:p,canModify:f,authEnabled:y,t:v}){const[x,g]=w.useState(!1);return i.jsxs("div",{className:`group relative bg-bambu-dark-secondary rounded-lg border transition-all cursor-pointer overflow-hidden ${e?"border-bambu-green ring-1 ring-bambu-green":"border-bambu-dark-tertiary hover:border-bambu-green/50"}`,onClick:()=>r(t.id),children:[i.jsxs("div",{className:"aspect-square bg-bambu-dark flex items-center justify-center overflow-hidden",children:[t.thumbnail_path?i.jsx("img",{src:`${be.getLibraryFileThumbnailUrl(t.id)}${m?`?v=${m}`:""}`,alt:t.filename,className:"w-full h-full object-cover"}):i.jsx(nf,{className:"w-12 h-12 text-bambu-gray/30"}),i.jsx("div",{className:`absolute top-2 right-2 text-xs px-1.5 py-0.5 rounded font-medium ${t.file_type==="3mf"?"bg-bambu-green/90 text-white":t.file_type==="gcode"?"bg-blue-500/90 text-white":t.file_type==="stl"?"bg-purple-500/90 text-white":"bg-bambu-gray/90 text-white"}`,children:t.file_type.toUpperCase()})]}),i.jsxs("div",{className:"p-3",children:[i.jsx("h3",{className:"text-sm font-medium text-white truncate",title:t.print_name||t.filename,children:t.print_name||t.filename}),i.jsxs("div",{className:"flex items-center gap-3 mt-1 text-xs text-bambu-gray",children:[i.jsx("span",{children:oo(t.file_size)}),t.print_time_seconds&&i.jsxs("span",{className:"flex items-center gap-1",children:[i.jsx(er,{className:"w-3 h-3"}),Rs(t.print_time_seconds)]})]}),t.sliced_for_model&&i.jsxs("div",{className:"mt-1 text-xs text-bambu-gray flex items-center gap-1",children:[i.jsx(Sr,{className:"w-3 h-3"}),t.sliced_for_model]}),t.print_count>0&&i.jsx("div",{className:"mt-1 text-xs text-bambu-green",children:v("fileManager.printedCount",{count:t.print_count})}),y&&t.created_by_username&&i.jsxs("div",{className:"mt-1 text-xs text-bambu-gray flex items-center gap-1",children:[i.jsx(Rd,{className:"w-3 h-3"}),t.created_by_username]})]}),i.jsxs("div",{className:`absolute bottom-2 right-2 transition-opacity ${n?"opacity-100":"opacity-0 group-hover:opacity-100"}`,onClick:_=>_.stopPropagation(),children:[i.jsx("button",{onClick:()=>g(!x),className:"p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary",children:i.jsx(ph,{className:"w-4 h-4 text-bambu-gray"})}),x&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>g(!1)}),i.jsxs("div",{className:"absolute right-0 bottom-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[140px]",children:[l&&yL(t.filename)&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("printers:control")?"text-bambu-green hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("printers:control")&&(l(t),g(!1))},disabled:!p("printers:control"),title:p("printers:control")?void 0:v("fileManager.noPermissionPrint"),children:[i.jsx(Sr,{className:"w-3.5 h-3.5"}),v("common.print")]}),o&&yL(t.filename)&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("queue:create")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("queue:create")&&(o(t.id),g(!1))},disabled:!p("queue:create"),title:p("queue:create")?void 0:v("fileManager.noPermissionAddToQueue"),children:[i.jsx(er,{className:"w-3.5 h-3.5"}),v("fileManager.schedulePrint")]}),c&&(t.file_type==="3mf"||t.file_type==="gcode"||t.file_type==="stl")&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("library:read")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("library:read")&&(c(t),g(!1))},disabled:!p("library:read"),title:p("library:read")?void 0:"You do not have permission to preview files",children:[i.jsx(ra,{className:"w-3.5 h-3.5"}),"3D Preview"]}),i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("library:read")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("library:read")&&(s(t.id),g(!1))},disabled:!p("library:read"),title:p("library:read")?void 0:v("fileManager.noPermissionDownload"),children:[i.jsx(pi,{className:"w-3.5 h-3.5"}),v("common.download")]}),u&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${f("library","update",t.created_by_id)?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{f("library","update",t.created_by_id)&&(u(t),g(!1))},disabled:!f("library","update",t.created_by_id),title:f("library","update",t.created_by_id)?void 0:v("fileManager.noPermissionRenameFile"),children:[i.jsx(Yi,{className:"w-3.5 h-3.5"}),v("common.rename")]}),d&&t.file_type==="stl"&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${f("library","update",t.created_by_id)?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{f("library","update",t.created_by_id)&&(d(t),g(!1))},disabled:!f("library","update",t.created_by_id),title:f("library","update",t.created_by_id)?void 0:v("fileManager.noPermissionGenerateThumbnail"),children:[i.jsx(Ed,{className:"w-3.5 h-3.5"}),v("fileManager.generateThumbnail")]}),i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${f("library","delete",t.created_by_id)?"text-red-400 hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{f("library","delete",t.created_by_id)&&(a(t.id),g(!1))},disabled:!f("library","delete",t.created_by_id),title:f("library","delete",t.created_by_id)?void 0:v("fileManager.noPermissionDeleteFile"),children:[i.jsx(Jt,{className:"w-3.5 h-3.5"}),v("common.delete")]})]})]})]}),i.jsx("div",{className:`absolute top-2 left-2 w-5 h-5 rounded border-2 flex items-center justify-center transition-all ${e?"bg-bambu-green border-bambu-green":`border-white/30 bg-black/30 ${n?"opacity-100":"opacity-0 group-hover:opacity-100"}`}`,children:e&&i.jsx("div",{className:"w-2 h-2 bg-white rounded-sm"})})]})}function xtt(){const{t}=Ft(),e=an(),{showToast:n}=fn(),{hasPermission:r,hasAnyPermission:a,canModify:s,authEnabled:o}=_r(),[l]=ML(),c=l.get("folder"),u=c?parseInt(c,10):null,[d,m]=w.useState(u),[p,f]=w.useState([]),[y,v]=w.useState(!1),[x,g]=w.useState(!1),[_,N]=w.useState(!1),[T,C]=w.useState(null),[A,k]=w.useState(null),[R,P]=w.useState(null),[D,H]=w.useState(null),[z,G]=w.useState(null),[I,ee]=w.useState(null),[ie,X]=w.useState({}),[me,he]=w.useState(null),[ge,Y]=w.useState(()=>localStorage.getItem("library-view-mode")||"grid"),[oe,le]=w.useState(()=>localStorage.getItem("library-wrap-folders")==="true"),[xe,Pe]=w.useState(()=>{const We=localStorage.getItem("library-sidebar-width");return We?parseInt(We,10):256}),[q,Z]=w.useState(!1),j=w.useRef(null);w.useEffect(()=>{if(!q)return;document.body.style.userSelect="none",document.body.style.cursor="col-resize";const We=wt=>{if(!j.current)return;const _t=j.current.parentElement?.getBoundingClientRect();if(!_t)return;const Ot=wt.clientX-_t.left,Vt=Math.min(500,Math.max(200,Ot));Pe(Vt)},yt=()=>{Z(!1),document.body.style.userSelect="",document.body.style.cursor="",localStorage.setItem("library-sidebar-width",String(xe))};return document.addEventListener("mousemove",We),document.addEventListener("mouseup",yt),()=>{document.removeEventListener("mousemove",We),document.removeEventListener("mouseup",yt),document.body.style.userSelect="",document.body.style.cursor=""}},[q,xe]);const[E,U]=w.useState(""),[K,$]=w.useState("all"),[ne,O]=w.useState(""),[V,J]=w.useState(()=>localStorage.getItem("library-sort-field")||"name"),[W,re]=w.useState(()=>localStorage.getItem("library-sort-direction")||"asc"),ue=aie();w.useEffect(()=>{const We=l.get("folder");if(We){const yt=parseInt(We,10);m(yt)}},[l]);const{data:fe}=et({queryKey:["settings"],queryFn:()=>be.getSettings()}),{data:ye,isLoading:ae}=et({queryKey:["library-folders"],queryFn:()=>be.getLibraryFolders()}),{data:L,isLoading:F}=et({queryKey:["library-files",d],queryFn:()=>be.getLibraryFiles(d,d===null)}),{data:te}=et({queryKey:["library-stats"],queryFn:()=>be.getLibraryStats()}),{data:ve}=et({queryKey:["users"],queryFn:()=>be.getUsers()}),pe=w.useMemo(()=>{if(!L)return[];const We=new Set(L.map(yt=>yt.file_type));return Array.from(We).sort()},[L]),de=w.useMemo(()=>{if(!L)return[];let We=[...L];if(E.trim()){const yt=E.toLowerCase();We=We.filter(wt=>wt.filename.toLowerCase().includes(yt)||wt.print_name&&wt.print_name.toLowerCase().includes(yt))}if(K!=="all"&&(We=We.filter(yt=>yt.file_type===K)),ne.trim()){const yt=ne.toLowerCase();We=We.filter(wt=>wt.created_by_username&&wt.created_by_username.toLowerCase().includes(yt))}return We.sort((yt,wt)=>{let _t=0;switch(V){case"name":_t=(yt.print_name||yt.filename).localeCompare(wt.print_name||wt.filename);break;case"date":_t=(Jn(yt.created_at)?.getTime()??0)-(Jn(wt.created_at)?.getTime()??0);break;case"size":_t=yt.file_size-wt.file_size;break;case"type":_t=yt.file_type.localeCompare(wt.file_type);break;case"prints":_t=yt.print_count-wt.print_count;break}return W==="asc"?_t:-_t}),We},[L,E,K,ne,V,W]),Ne=w.useMemo(()=>{if(!te||!fe)return!1;const We=(fe.library_disk_warning_gb||5)*1024*1024*1024;return te.disk_free_bytesbe.createLibraryFolder(We),onSuccess:()=>{e.invalidateQueries({queryKey:["library-folders"]}),v(!1),n(t("fileManager.toast.folderCreated"),"success")},onError:We=>n(We.message,"error")}),Le=pt({mutationFn:We=>be.deleteLibraryFolder(We),onSuccess:()=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-stats"]}),d===A?.id&&m(null),k(null),n(t("fileManager.toast.folderDeleted"),"success")},onError:We=>{k(null),n(We.message,"error")}}),qe=pt({mutationFn:We=>be.deleteLibraryFile(We),onSuccess:()=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]}),f(We=>We.filter(yt=>yt!==A?.id)),k(null),n(t("fileManager.toast.fileDeleted"),"success")},onError:We=>{k(null),n(We.message,"error")}}),Ee=pt({mutationFn:We=>be.bulkDeleteLibrary(We,[]),onSuccess:(We,yt)=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]}),n(t("fileManager.toast.filesDeleted",{count:yt.length}),"success"),f([]),k(null)},onError:We=>{k(null),n(We.message,"error")}}),Te=pt({mutationFn:({fileIds:We,folderId:yt})=>be.moveLibraryFiles(We,yt),onSuccess:()=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),f([]),g(!1),n(t("fileManager.toast.filesMoved"),"success")},onError:We=>n(We.message,"error")}),Ae=pt({mutationFn:({id:We,data:yt})=>be.updateLibraryFolder(We,yt),onSuccess:(We,yt)=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["project-folders"]}),e.invalidateQueries({queryKey:["archive-folders"]}),C(null);const wt=yt.data.project_id===0&&yt.data.archive_id===0;n(t(wt?"fileManager.toast.folderUnlinked":"fileManager.toast.folderLinked"),"success")},onError:We=>n(We.message,"error")}),Be=pt({mutationFn:({id:We,filename:yt})=>be.updateLibraryFile(We,{filename:yt}),onSuccess:()=>{e.invalidateQueries({queryKey:["library-files"]}),ee(null),n(t("fileManager.toast.fileRenamed"),"success")},onError:We=>{ee(null),n(We.message,"error")}}),je=pt({mutationFn:({id:We,name:yt})=>be.updateLibraryFolder(We,{name:yt}),onSuccess:()=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-files"]}),ee(null),n(t("fileManager.toast.folderRenamed"),"success")},onError:We=>{ee(null),n(We.message,"error")}}),Xe=pt({mutationFn:()=>be.batchGenerateStlThumbnails({all_missing:!0}),onSuccess:We=>{if(e.invalidateQueries({queryKey:["library-files"]}),We.succeeded>0){const yt=Date.now(),wt={};We.results.forEach(_t=>{_t.success&&(wt[_t.file_id]=yt)}),X(_t=>({..._t,...wt}))}We.succeeded>0&&We.failed===0?n(t("fileManager.toast.thumbnailsGenerated",{count:We.succeeded}),"success"):We.succeeded>0&&We.failed>0?n(t("fileManager.toast.thumbnailsGeneratedPartial",{succeeded:We.succeeded,failed:We.failed}),"success"):We.processed===0?n(t("fileManager.toast.noStlMissingThumbnails"),"info"):n(t("fileManager.toast.failedToGenerateThumbnails",{error:We.results[0]?.error||"Unknown error"}),"error")},onError:We=>n(We.message,"error")}),ce=pt({mutationFn:We=>be.batchGenerateStlThumbnails({file_ids:[We]}),onSuccess:We=>{if(e.invalidateQueries({queryKey:["library-files"]}),We.succeeded>0){const yt=We.results[0]?.file_id;yt&&X(wt=>({...wt,[yt]:Date.now()})),n(t("fileManager.toast.thumbnailGenerated"),"success")}else n(t("fileManager.toast.failedToGenerateThumbnail",{error:We.results[0]?.error||"Unknown error"}),"error")},onError:We=>n(We.message,"error")}),Ie=w.useCallback(We=>{const yt=We.toLowerCase();return yt.endsWith(".gcode")||yt.includes(".gcode.")},[]),Ce=w.useMemo(()=>L?L.filter(We=>p.includes(We.id)&&Ie(We.filename)):[],[L,p,Ie]),Ge=w.useCallback(We=>{f(yt=>yt.includes(We)?yt.filter(wt=>wt!==We):[...yt,We])},[]),$e=w.useCallback(()=>{de.length>0&&f(de.map(We=>We.id))},[de]),Ue=w.useCallback(()=>{f([])},[]),De=()=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]})},Ve=We=>{be.downloadLibraryFile(We).catch(yt=>{console.error("Library file download failed:",yt)})},it=()=>{A&&(A.type==="file"?qe.mutate(A.id):A.type==="folder"?Le.mutate(A.id):A.type==="bulk"&&Ee.mutate(p))},xt=Le.isPending||qe.isPending||Ee.isPending,Nt=We=>{Y(We),localStorage.setItem("library-view-mode",We)},kt=ae||F;return i.jsxs("div",{className:"p-4 md:p-8 min-h-[calc(100vh-64px)] lg:h-[calc(100vh-64px)] flex flex-col",children:[i.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6",children:[i.jsxs("div",{children:[i.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[i.jsx("div",{className:"p-2.5 bg-bambu-green/10 rounded-xl",children:i.jsx(Nc,{className:"w-6 h-6 text-bambu-green"})}),t("fileManager.title")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-2 ml-14",children:t("fileManager.subtitle")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex items-center bg-bambu-dark rounded-lg p-1",children:[i.jsx("button",{onClick:()=>Nt("grid"),className:`p-1.5 rounded transition-colors ${ge==="grid"?"bg-bambu-dark-secondary text-white":"text-bambu-gray hover:text-white"}`,title:t("fileManager.gridView"),children:i.jsx(pw,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>Nt("list"),className:`p-1.5 rounded transition-colors ${ge==="list"?"bg-bambu-dark-secondary text-white":"text-bambu-gray hover:text-white"}`,title:t("fileManager.listView"),children:i.jsx(JC,{className:"w-4 h-4"})})]}),i.jsxs(Oe,{variant:"secondary",onClick:()=>Xe.mutate(),disabled:Xe.isPending||!a("library:update_own","library:update_all"),title:a("library:update_own","library:update_all")?t("fileManager.generateThumbnailsForMissing"):t("fileManager.noPermissionGenerateThumbnail"),children:[Xe.isPending?i.jsx(ht,{className:"w-4 h-4 mr-2 animate-spin"}):i.jsx(Ed,{className:"w-4 h-4 mr-2"}),t("fileManager.generateThumbnails")]}),i.jsxs(Oe,{variant:"secondary",onClick:()=>v(!0),disabled:!r("library:upload"),title:r("library:upload")?void 0:t("fileManager.noPermissionCreateFolder"),children:[i.jsx(Xpe,{className:"w-4 h-4 mr-2"}),t("fileManager.newFolder")]}),i.jsxs(Oe,{onClick:()=>N(!0),disabled:!r("library:upload"),title:r("library:upload")?void 0:t("fileManager.noPermissionUpload"),children:[i.jsx(xi,{className:"w-4 h-4 mr-2"}),t("common.upload")]})]})]}),Ne&&te&&fe&&i.jsxs("div",{className:"flex items-center gap-3 mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg",children:[i.jsx(Mn,{className:"w-5 h-5 text-amber-500 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-amber-500 font-medium",children:t("fileManager.lowDiskSpaceWarning")}),i.jsx("p",{className:"text-xs text-amber-500/80",children:t("fileManager.lowDiskSpaceDetails",{free:oo(te.disk_free_bytes),total:oo(te.disk_total_bytes),threshold:fe.library_disk_warning_gb})})]})]}),te&&i.jsxs("div",{className:"flex flex-wrap items-center gap-3 sm:gap-6 mb-6 p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx(XC,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.files"),":"]}),i.jsx("span",{className:"text-white font-medium",children:te.total_files})]}),i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx(Nc,{className:"w-4 h-4 text-blue-400"}),i.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.folders"),":"]}),i.jsx("span",{className:"text-white font-medium",children:te.total_folders})]}),i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx(Lx,{className:"w-4 h-4 text-amber-400"}),i.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.size"),":"]}),i.jsx("span",{className:"text-white font-medium",children:oo(te.total_size_bytes)})]}),i.jsxs("div",{className:"flex items-center gap-2 text-sm sm:ml-auto",children:[i.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.free"),":"]}),i.jsx("span",{className:`font-medium ${Ne?"text-amber-500":"text-white"}`,children:oo(te.disk_free_bytes)})]})]}),i.jsxs("div",{className:"flex-1 flex flex-col lg:flex-row gap-4 lg:gap-6 min-h-0",children:[i.jsx("div",{className:"lg:hidden",children:i.jsxs("select",{value:d??"",onChange:We=>m(We.target.value?parseInt(We.target.value,10):null),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg px-3 py-2.5 text-white focus:outline-none focus:border-bambu-green",children:[i.jsxs("option",{value:"",children:["📁 ",t("fileManager.allFiles")]}),ye&&(()=>{const We=(yt,wt=0)=>{const _t=[];for(const Ot of yt)_t.push({id:Ot.id,name:Ot.name,fileCount:Ot.file_count,depth:wt}),Ot.children.length>0&&_t.push(...We(Ot.children,wt+1));return _t};return We(ye).map(yt=>i.jsxs("option",{value:yt.id,children:["│ ".repeat(yt.depth),"📂 ",yt.name," ",yt.fileCount>0?`(${yt.fileCount})`:""]},yt.id))})()]})}),i.jsxs("div",{ref:j,className:"hidden lg:flex flex-shrink-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden flex-col relative",style:{width:`${xe}px`},children:[i.jsx("div",{className:`absolute right-0 top-0 bottom-0 w-1.5 cursor-col-resize z-10 group/resize flex items-center justify-center transition-colors ${q?"bg-bambu-green":"hover:bg-bambu-green/50"}`,onMouseDown:We=>{We.preventDefault(),Z(!0)},onDoubleClick:()=>{Pe(256),localStorage.setItem("library-sidebar-width","256")},title:t("fileManager.dragToResizeTooltip"),children:i.jsxs("div",{className:`flex flex-col gap-1 opacity-0 group-hover/resize:opacity-100 transition-opacity ${q?"opacity-100":""}`,children:[i.jsx("div",{className:"w-0.5 h-0.5 rounded-full bg-white/70"}),i.jsx("div",{className:"w-0.5 h-0.5 rounded-full bg-white/70"}),i.jsx("div",{className:"w-0.5 h-0.5 rounded-full bg-white/70"})]})}),i.jsxs("div",{className:"p-3 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[i.jsx("h2",{className:"text-sm font-medium text-white",children:t("fileManager.folders")}),i.jsx("button",{onClick:()=>{const We=!oe;le(We),localStorage.setItem("library-wrap-folders",String(We))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${oe?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:text-white hover:bg-bambu-dark"}`,title:t(oe?"fileManager.disableTextWrapping":"fileManager.enableTextWrapping"),children:t("fileManager.wrap")})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto p-2",children:[i.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${d===null?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark text-white"}`,onClick:()=>m(null),children:[i.jsx(nf,{className:"w-4 h-4"}),i.jsx("span",{className:"text-sm",children:t("fileManager.allFiles")})]}),ye?.map(We=>i.jsx($oe,{folder:We,selectedFolderId:d,onSelect:m,onDelete:yt=>k({type:"folder",id:yt}),onLink:C,onRename:yt=>ee({type:"folder",id:yt.id,name:yt.name}),wrapNames:oe,hasPermission:r,t},We.id))]})]}),i.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[L&&L.length>0&&i.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-3 mb-4 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-0 z-10 lg:static",children:[i.jsxs("div",{className:"relative w-full sm:w-auto sm:flex-1 sm:max-w-xs",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",placeholder:t("fileManager.searchFiles"),value:E,onChange:We=>U(We.target.value),className:"w-full pl-9 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green"})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(QC,{className:"w-4 h-4 text-bambu-gray hidden sm:block"}),i.jsxs("select",{value:K,onChange:We=>$(We.target.value),className:"bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green",children:[i.jsx("option",{value:"all",children:t("fileManager.allTypes")}),pe.map(We=>i.jsx("option",{value:We,children:We.toUpperCase()},We))]})]}),o&&i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"text",placeholder:t("fileManager.filterByUser",{defaultValue:"Filter by user"}),value:ne,onChange:We=>O(We.target.value),list:"usernames-list",className:`w-32 sm:w-40 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green ${ne?"pr-7":""}`,style:ne?{WebkitAppearance:"none",MozAppearance:"textfield"}:void 0}),ne&&i.jsx("button",{onClick:()=>O(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10",children:i.jsx(Ht,{className:"w-3 h-3"})}),i.jsx("datalist",{id:"usernames-list",children:ve?.map(We=>i.jsx("option",{value:We.username},We.id))})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("select",{value:V,onChange:We=>{const yt=We.target.value;J(yt),localStorage.setItem("library-sort-field",yt)},className:"bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green",children:[i.jsx("option",{value:"name",children:t("common.name")}),i.jsx("option",{value:"date",children:t("common.date")}),i.jsx("option",{value:"size",children:t("fileManager.size")}),i.jsx("option",{value:"type",children:t("common.type")}),i.jsx("option",{value:"prints",children:t("fileManager.prints")})]}),i.jsx("button",{onClick:()=>re(We=>{const yt=We==="asc"?"desc":"asc";return localStorage.setItem("library-sort-direction",yt),yt}),className:"p-1.5 rounded bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors",title:t(W==="asc"?"fileManager.ascending":"fileManager.descending"),children:W==="asc"?i.jsx(ghe,{className:"w-4 h-4 text-white"}):i.jsx(che,{className:"w-4 h-4 text-white"})})]}),(E||K!=="all"||ne)&&i.jsx("span",{className:"text-sm text-bambu-gray hidden sm:inline",children:t("fileManager.resultsCount",{showing:de.length,total:L.length})})]}),de.length>0&&i.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-4 p-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-[52px] z-10 lg:static",children:[p.length===de.length&&p.length>0?i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:Ue,children:[i.jsx(zl,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("fileManager.deselectAll")})]}):i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:$e,children:[i.jsx(xo,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("fileManager.selectAll")})]}),p.length>0&&i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"text-sm text-bambu-gray ml-2",children:t("fileManager.selected",{count:p.length})}),i.jsx("div",{className:"hidden sm:block flex-1"}),i.jsxs("div",{className:"w-full sm:w-auto flex flex-wrap items-center gap-2 mt-2 sm:mt-0",children:[Ce.length===1&&i.jsxs(Oe,{variant:"primary",size:"sm",onClick:()=>H(Ce[0]),disabled:!r("printers:control"),title:r("printers:control")?void 0:t("fileManager.noPermissionPrint"),children:[i.jsx(go,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.print")})]}),Ce.length===1&&i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>G(Ce[0]),disabled:!r("queue:create"),title:r("queue:create")?void 0:t("fileManager.noPermissionAddToQueue"),children:[i.jsx(er,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("fileManager.schedulePrint")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>g(!0),disabled:!a("library:update_own","library:update_all"),title:a("library:update_own","library:update_all")?void 0:t("fileManager.noPermissionMoveFiles"),children:[i.jsx(sge,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.move")})]}),i.jsxs(Oe,{variant:"danger",size:"sm",onClick:()=>{p.length===1?k({type:"file",id:p[0]}):k({type:"bulk",id:0,count:p.length})},disabled:!a("library:delete_own","library:delete_all"),title:a("library:delete_own","library:delete_all")?void 0:t("fileManager.noPermissionDeleteFiles"),children:[i.jsx(Jt,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.delete")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:Ue,children:[i.jsx(Ht,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.clear")})]})]})]})]}),kt?i.jsx("div",{className:"flex-1 flex items-center justify-center",children:i.jsxs("div",{className:"flex flex-col items-center gap-3",children:[i.jsx(ht,{className:"w-8 h-8 animate-spin text-bambu-green"}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t("fileManager.loadingFiles")})]})}):L?.length===0?i.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center",children:[i.jsx("div",{className:"p-4 bg-bambu-dark rounded-2xl mb-4",children:i.jsx(nf,{className:"w-12 h-12 text-bambu-gray/50"})}),i.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:t(d!==null?"fileManager.folderIsEmpty":"fileManager.noFilesYet")}),i.jsx("p",{className:"text-bambu-gray text-center max-w-md mb-6",children:t(d!==null?"fileManager.folderEmptyDescription":"fileManager.noFilesDescription")}),i.jsxs(Oe,{onClick:()=>N(!0),disabled:!r("library:upload"),title:r("library:upload")?void 0:t("fileManager.noPermissionUpload"),children:[i.jsx(ar,{className:"w-4 h-4 mr-2"}),t("fileManager.uploadFiles")]})]}):de.length===0?i.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center",children:[i.jsx("div",{className:"p-4 bg-bambu-dark rounded-2xl mb-4",children:i.jsx(jr,{className:"w-12 h-12 text-bambu-gray/50"})}),i.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:t("fileManager.noMatchingFiles")}),i.jsx("p",{className:"text-bambu-gray text-center max-w-md mb-6",children:t("fileManager.noMatchingFilesDescription")}),i.jsx(Oe,{variant:"secondary",onClick:()=>{U(""),$("all")},children:t("fileManager.clearFilters")})]}):ge==="grid"?i.jsx("div",{className:"flex-1 lg:overflow-y-auto",children:i.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4",children:de.map(We=>i.jsx(btt,{file:We,isSelected:p.includes(We.id),isMobile:ue,t,onSelect:Ge,onDelete:yt=>k({type:"file",id:yt}),onDownload:Ve,onAddToQueue:yt=>{const wt=L?.find(_t=>_t.id===yt);wt&&G(wt)},onPrint:P,onPreview3d:he,onRename:yt=>ee({type:"file",id:yt.id,name:yt.filename}),onGenerateThumbnail:yt=>ce.mutate(yt.id),thumbnailVersion:ie[We.id],hasPermission:r,canModify:s,authEnabled:o},We.id))})}):i.jsx("div",{className:"flex-1 lg:overflow-y-auto",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden",children:[i.jsxs("div",{className:`hidden sm:grid ${o?"grid-cols-[auto_1fr_120px_100px_100px_100px_80px]":"grid-cols-[auto_1fr_100px_100px_100px_80px]"} gap-4 px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary text-xs text-bambu-gray font-medium`,children:[i.jsx("div",{className:"w-6"}),i.jsx("div",{children:t("common.name")}),o&&i.jsx("div",{children:t("fileManager.uploadedBy",{defaultValue:"Uploaded By"})}),i.jsx("div",{children:t("common.type")}),i.jsx("div",{children:t("fileManager.size")}),i.jsx("div",{children:t("fileManager.prints")}),i.jsx("div",{})]}),de.map(We=>i.jsxs("div",{className:`grid ${o?"grid-cols-[auto_1fr_120px_100px_100px_100px_80px]":"grid-cols-[auto_1fr_100px_100px_100px_80px]"} gap-4 px-4 py-3 items-center border-b border-bambu-dark-tertiary last:border-b-0 cursor-pointer hover:bg-bambu-dark/50 transition-colors ${p.includes(We.id)?"bg-bambu-green/10":""}`,onClick:()=>Ge(We.id),children:[i.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${p.includes(We.id)?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:p.includes(We.id)&&i.jsx("div",{className:"w-2 h-2 bg-white rounded-sm"})}),i.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i.jsxs("div",{className:"relative group/thumb",children:[i.jsx("div",{className:"w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden",children:We.thumbnail_path?i.jsx("img",{src:`${be.getLibraryFileThumbnailUrl(We.id)}${ie[We.id]?`?v=${ie[We.id]}`:""}`,alt:"",className:"w-full h-full object-cover"}):i.jsx("div",{className:"w-full h-full flex items-center justify-center",children:i.jsx(nf,{className:"w-5 h-5 text-bambu-gray/50"})})}),We.thumbnail_path&&i.jsx("div",{className:"absolute left-0 top-full mt-2 z-50 hidden group-hover/thumb:block",children:i.jsx("div",{className:"w-48 h-48 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-xl overflow-hidden",children:i.jsx("img",{src:`${be.getLibraryFileThumbnailUrl(We.id)}${ie[We.id]?`?v=${ie[We.id]}`:""}`,alt:We.filename,className:"w-full h-full object-contain"})})})]}),i.jsx("div",{className:"min-w-0",children:i.jsx("div",{className:"text-sm text-white truncate",children:We.print_name||We.filename})})]}),o&&i.jsx("div",{className:"text-sm text-bambu-gray flex items-center gap-1",children:We.created_by_username?i.jsxs(i.Fragment,{children:[i.jsx(Rd,{className:"w-3 h-3"}),i.jsx("span",{className:"truncate",children:We.created_by_username})]}):"-"}),i.jsx("div",{children:i.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded font-medium ${We.file_type==="3mf"?"bg-bambu-green/20 text-bambu-green":We.file_type==="gcode"?"bg-blue-500/20 text-blue-400":We.file_type==="stl"?"bg-purple-500/20 text-purple-400":"bg-bambu-gray/20 text-bambu-gray"}`,children:We.file_type.toUpperCase()})}),i.jsx("div",{className:"text-sm text-bambu-gray",children:oo(We.file_size)}),i.jsx("div",{className:"text-sm text-bambu-gray",children:We.print_count>0?`${We.print_count}x`:"-"}),i.jsxs("div",{className:"flex items-center gap-1",onClick:yt=>yt.stopPropagation(),children:[yL(We.filename)&&i.jsxs(i.Fragment,{children:[i.jsx("button",{onClick:()=>r("printers:control")&&P(We),className:`p-1.5 rounded transition-colors ${r("printers:control")?"hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("printers:control")?t("common.print"):t("fileManager.noPermissionPrint"),disabled:!r("printers:control"),children:i.jsx(Sr,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>{r("queue:create")&&G(We)},className:`p-1.5 rounded transition-colors ${r("queue:create")?"hover:bg-bambu-dark text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("queue:create")?t("fileManager.schedulePrint"):t("fileManager.noPermissionAddToQueue"),disabled:!r("queue:create"),children:i.jsx(er,{className:"w-4 h-4"})})]}),(We.file_type==="3mf"||We.file_type==="gcode"||We.file_type==="stl")&&i.jsx("button",{onClick:()=>r("library:read")&&he(We),className:`p-1.5 rounded transition-colors ${r("library:read")?"hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("library:read")?"3D Preview":"You do not have permission to preview files",disabled:!r("library:read"),children:i.jsx(ra,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>r("library:read")&&Ve(We.id),className:`p-1.5 rounded transition-colors ${r("library:read")?"hover:bg-bambu-dark text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("library:read")?t("common.download"):t("fileManager.noPermissionDownload"),disabled:!r("library:read"),children:i.jsx(pi,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>s("library","update",We.created_by_id)&&ee({type:"file",id:We.id,name:We.filename}),className:`p-1.5 rounded transition-colors ${s("library","update",We.created_by_id)?"hover:bg-bambu-dark text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("library","update",We.created_by_id)?t("common.rename"):t("fileManager.noPermissionRenameFile"),disabled:!s("library","update",We.created_by_id),children:i.jsx(Yi,{className:"w-4 h-4"})}),We.file_type==="stl"&&i.jsx("button",{onClick:()=>s("library","update",We.created_by_id)&&ce.mutate(We.id),className:`p-1.5 rounded transition-colors ${s("library","update",We.created_by_id)?"hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("library","update",We.created_by_id)?t("fileManager.generateThumbnail"):t("fileManager.noPermissionGenerateThumbnail"),disabled:ce.isPending||!s("library","update",We.created_by_id),children:i.jsx(Ed,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>s("library","delete",We.created_by_id)&&k({type:"file",id:We.id}),className:`p-1.5 rounded transition-colors ${s("library","delete",We.created_by_id)?"hover:bg-bambu-dark text-bambu-gray hover:text-red-400":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("library","delete",We.created_by_id)?t("common.delete"):t("fileManager.noPermissionDeleteFile"),disabled:!s("library","delete",We.created_by_id),children:i.jsx(Jt,{className:"w-4 h-4"})})]})]},We.id))]})})]})]}),y&&i.jsx(htt,{parentId:d,onClose:()=>v(!1),onSave:We=>Se.mutate(We),isLoading:Se.isPending,t}),x&&ye&&i.jsx(ftt,{folders:ye,selectedFiles:p,currentFolderId:d,onClose:()=>g(!1),onMove:We=>Te.mutate({fileIds:p,folderId:We}),isLoading:Te.isPending,t}),_&&i.jsx(Qre,{folderId:d,onClose:()=>N(!1),onUploadComplete:De}),T&&i.jsx(gtt,{folder:T,onClose:()=>C(null),onLink:We=>Ae.mutate({id:T.id,data:We}),isLoading:Ae.isPending,t}),A&&i.jsx(Sn,{title:A.type==="folder"?t("fileManager.deleteFolder"):A.type==="bulk"?t("fileManager.deleteFilesCount",{count:A.count}):t("fileManager.deleteFile"),message:A.type==="folder"?t("fileManager.deleteFolderConfirm"):A.type==="bulk"?t("fileManager.deleteFilesConfirm",{count:A.count}):t("fileManager.deleteFileConfirm"),confirmText:t("common.delete"),variant:"danger",isLoading:xt,loadingText:t("fileManager.deleting"),onConfirm:it,onCancel:()=>k(null)}),R&&i.jsx(uu,{mode:"reprint",libraryFileId:R.id,archiveName:R.print_name||R.filename,onClose:()=>P(null),onSuccess:()=>{P(null),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["archives"]})}}),D&&i.jsx(uu,{mode:"reprint",libraryFileId:D.id,archiveName:D.print_name||D.filename,onClose:()=>H(null),onSuccess:()=>{H(null),f([]),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["archives"]})}}),z&&i.jsx(uu,{mode:"add-to-queue",libraryFileId:z.id,archiveName:z.print_name||z.filename,onClose:()=>G(null),onSuccess:()=>{G(null),f([]),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["queue"]}),e.invalidateQueries({queryKey:["archives"]})}}),me&&i.jsx(M4,{libraryFileId:me.id,title:me.print_name||me.filename,fileType:me.file_type,onClose:()=>he(null)}),I&&i.jsx(ptt,{type:I.type,currentName:I.name,onClose:()=>ee(null),onSave:We=>{I.type==="file"?Be.mutate({id:I.id,filename:We}):je.mutate({id:I.id,name:We})},isLoading:Be.isPending||je.isPending,t})]})}const VD=5,ytt=2e3,vtt=3e4,wtt=5e3;function Stt(){const{t}=Ft(),e=an(),{showToast:n}=fn(),{hasPermission:r}=_r(),{printerId:a}=uw(),s=parseInt(a||"0",10),[o,l]=w.useState("stream"),[c,u]=w.useState(!1),[d,m]=w.useState(!1),[p,f]=w.useState(!0),[y,v]=w.useState(Date.now()),[x,g]=w.useState(!1),[_,N]=w.useState(!1),[T,C]=w.useState(0),[A,k]=w.useState(!1),[R,P]=w.useState(0),[D,H]=w.useState(1),[z,G]=w.useState({x:0,y:0}),[I,ee]=w.useState(!1),[ie,X]=w.useState({x:0,y:0}),[me,he]=w.useState(null),[ge,Y]=w.useState(null),oe=w.useRef(null),le=w.useRef(null),xe=w.useRef(null),Pe=w.useRef(null),q=w.useRef(null),{data:Z}=et({queryKey:["printer",s],queryFn:()=>be.getPrinter(s),enabled:s>0}),{data:j}=et({queryKey:["printerStatus",s],queryFn:()=>be.getPrinterStatus(s),refetchInterval:3e4,enabled:s>0}),E=pt({mutationFn:Te=>be.setChamberLight(s,Te),onMutate:async Te=>{await e.cancelQueries({queryKey:["printerStatus",s]});const Ae=e.getQueryData(["printerStatus",s]);return e.setQueryData(["printerStatus",s],Be=>({...Be,chamber_light:Te})),{previousStatus:Ae}},onSuccess:(Te,Ae)=>{n(`Chamber light ${Ae?"on":"off"}`)},onError:(Te,Ae,Be)=>{Be?.previousStatus&&e.setQueryData(["printerStatus",s],Be.previousStatus),n(Te.message||t("printers.toast.failedToControlChamberLight"),"error")}}),U=(j?.state==="RUNNING"||j?.state==="PAUSE")&&(j?.printable_objects_count??0)>=2;w.useEffect(()=>(Z&&(document.title=`${Z.name} - Camera`),()=>{document.title="Bambuddy"}),[Z]);const K=w.useRef(!1);w.useEffect(()=>{const Te=`/api/v1/printers/${s}/camera/stop`;K.current=!1;const Ae=()=>{if(s>0&&!K.current){K.current=!0;const Xe={},ce=Fd();ce&&(Xe.Authorization=`Bearer ${ce}`),fetch(Te,{method:"POST",keepalive:!0,headers:Xe}).catch(()=>{})}},Be=()=>{Ae()};window.addEventListener("beforeunload",Be);const je=oe.current;return()=>{window.removeEventListener("beforeunload",Be),je&&(je.src=""),Ae()}},[s]),w.useEffect(()=>{if(p&&!x){const Ae=setTimeout(()=>{f(!1)},o==="stream"?3e3:2e4);return()=>clearTimeout(Ae)}},[o,p,y,x]),w.useEffect(()=>{const Te=()=>{const Ae=!!document.fullscreenElement;N(Ae),H(1),G({x:0,y:0}),o==="stream"&&!x&&(oe.current&&(oe.current.src=""),setTimeout(()=>{f(!0),v(Date.now())},200))};return document.addEventListener("fullscreenchange",Te),()=>document.removeEventListener("fullscreenchange",Te)},[o,x]),w.useEffect(()=>{let Te;const Ae=()=>{clearTimeout(Te),Te=setTimeout(()=>{localStorage.setItem("cameraWindowState",JSON.stringify({width:window.outerWidth,height:window.outerHeight,left:window.screenX,top:window.screenY}))},500)};return window.addEventListener("resize",Ae),()=>{clearTimeout(Te),window.removeEventListener("resize",Ae)}},[]),w.useEffect(()=>()=>{xe.current&&clearTimeout(xe.current),Pe.current&&clearInterval(Pe.current),q.current&&clearInterval(q.current)},[]);const $=w.useCallback(()=>{if(T>=VD){k(!1),m(!0);return}const Te=Math.min(ytt*Math.pow(2,T),vtt);k(!0),P(Math.ceil(Te/1e3)),Pe.current=setInterval(()=>{P(Ae=>Ae<=1?(Pe.current&&clearInterval(Pe.current),0):Ae-1)},1e3),xe.current=setTimeout(()=>{C(Ae=>Ae+1),k(!1),f(!0),m(!1),oe.current&&(oe.current.src=""),v(Date.now())},Te)},[T]);w.useEffect(()=>{if(o!=="stream"||p||A||x){q.current&&(clearInterval(q.current),q.current=null);return}return q.current=setInterval(async()=>{try{const Te=await be.getCameraStatus(s);(Te.stalled||!Te.active&&!d)&&(console.log(`Stream issue detected: stalled=${Te.stalled}, active=${Te.active}, reconnecting...`),q.current&&(clearInterval(q.current),q.current=null),f(!1),$())}catch{}},wtt),()=>{q.current&&(clearInterval(q.current),q.current=null)}},[o,p,d,A,x,s,$]);const ne=()=>{f(!1),o==="stream"&&T{if(f(!1),m(!1),C(0),k(!1),xe.current&&clearTimeout(xe.current),Pe.current&&clearInterval(Pe.current),oe.current&&!localStorage.getItem("cameraWindowState")){const Te=oe.current,Ae=Te.naturalWidth,Be=Te.naturalHeight;if(Ae>0&&Be>0){const ce=window.outerWidth-window.innerWidth,Ie=window.outerHeight-window.innerHeight,Ce=Ae+16+ce,Ge=Be+45+16+Ie;try{window.resizeTo(Ce,Ge)}catch{}}}},V=()=>{if(s>0){const Te={},Ae=Fd();Ae&&(Te.Authorization=`Bearer ${Ae}`),fetch(`/api/v1/printers/${s}/camera/stop`,{method:"POST",headers:Te}).catch(()=>{})}},J=Te=>{o===Te||x||(g(!0),f(!0),m(!1),C(0),k(!1),H(1),G({x:0,y:0}),xe.current&&clearTimeout(xe.current),Pe.current&&clearInterval(Pe.current),oe.current&&(oe.current.src=""),o==="stream"&&V(),setTimeout(()=>{l(Te),v(Date.now()),g(!1)},100))},W=()=>{x||(g(!0),f(!0),m(!1),C(0),k(!1),xe.current&&clearTimeout(xe.current),Pe.current&&clearInterval(Pe.current),oe.current&&(oe.current.src=""),o==="stream"&&V(),setTimeout(()=>{v(Date.now()),g(!1)},100))},re=()=>{le.current&&(document.fullscreenElement?document.exitFullscreen():le.current.requestFullscreen())},ue=()=>{H(Te=>Math.min(Te+.5,4))},fe=()=>{H(Te=>{const Ae=Math.max(Te-.5,1);return Ae===1&&G({x:0,y:0}),Ae})},ye=Te=>{Te.preventDefault(),Te.deltaY<0?ue():fe()},ae=Te=>{D>1&&(Te.preventDefault(),ee(!0),X({x:Te.clientX-z.x,y:Te.clientY-z.y}))},L=w.useCallback(()=>{if(!le.current)return{x:300,y:200};const Te=le.current.getBoundingClientRect(),Ae=Te.width*(D-1)/2,Be=Te.height*(D-1)/2;return{x:Math.max(50,Ae),y:Math.max(50,Be)}},[D]),F=Te=>{if(I&&D>1){const Ae=Te.clientX-ie.x,Be=Te.clientY-ie.y,je=L();G({x:Math.max(-je.x,Math.min(je.x,Ae)),y:Math.max(-je.y,Math.min(je.y,Be))})}},te=()=>{ee(!1)},ve=Te=>{if(Te.length<2)return 0;const Ae=Te[0].clientX-Te[1].clientX,Be=Te[0].clientY-Te[1].clientY;return Math.sqrt(Ae*Ae+Be*Be)},pe=Te=>Te.length<2?{x:Te[0].clientX,y:Te[0].clientY}:{x:(Te[0].clientX+Te[1].clientX)/2,y:(Te[0].clientY+Te[1].clientY)/2},de=Te=>{Te.touches.length===2?(Te.preventDefault(),he(ve(Te.touches)),Y(pe(Te.touches))):Te.touches.length===1&&D>1&&(Te.preventDefault(),ee(!0),X({x:Te.touches[0].clientX-z.x,y:Te.touches[0].clientY-z.y}))},Ne=Te=>{if(Te.touches.length===2&&me!==null){Te.preventDefault();const Ae=ve(Te.touches),Be=Ae/me;H(Xe=>{const ce=Math.max(1,Math.min(4,Xe*Be));return ce===1&&G({x:0,y:0}),ce}),he(Ae);const je=pe(Te.touches);if(ge){const Xe=L();G(ce=>({x:Math.max(-Xe.x,Math.min(Xe.x,ce.x+(je.x-ge.x))),y:Math.max(-Xe.y,Math.min(Xe.y,ce.y+(je.y-ge.y)))}))}Y(je)}else if(Te.touches.length===1&&I&&D>1){Te.preventDefault();const Ae=Te.touches[0].clientX-ie.x,Be=Te.touches[0].clientY-ie.y,je=L();G({x:Math.max(-je.x,Math.min(je.x,Ae)),y:Math.max(-je.y,Math.min(je.y,Be))})}},Se=Te=>{Te.touches.length<2&&(he(null),Y(null)),Te.touches.length===0&&ee(!1)},Le=()=>{H(1),G({x:0,y:0})},qe=x?"":o==="stream"?`/api/v1/printers/${s}/camera/stream?fps=15&t=${y}`:`/api/v1/printers/${s}/camera/snapshot?t=${y}`,Ee=p||x||A;return s?i.jsxs("div",{ref:le,className:"min-h-screen bg-black flex flex-col",children:[i.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary",children:[i.jsxs("h1",{className:"text-sm font-medium text-white flex items-center gap-2",children:[i.jsx(rx,{className:"w-4 h-4"}),Z?.name||`Printer ${s}`]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex bg-bambu-dark rounded p-0.5",children:[i.jsx("button",{onClick:()=>J("stream"),disabled:Ee,className:`px-3 py-1 text-xs rounded transition-colors ${o==="stream"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white disabled:opacity-50"}`,children:t("camera.live")}),i.jsx("button",{onClick:()=>J("snapshot"),disabled:Ee,className:`px-3 py-1 text-xs rounded transition-colors ${o==="snapshot"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white disabled:opacity-50"}`,children:t("camera.snapshot")})]}),i.jsx("button",{onClick:()=>E.mutate(!j?.chamber_light),disabled:!j?.connected||E.isPending||!r("printers:control"),className:`p-1.5 rounded disabled:opacity-50 ${j?.chamber_light?"bg-yellow-500/20 hover:bg-yellow-500/30":"hover:bg-bambu-dark-tertiary"}`,title:r("printers:control")?t("camera.chamberLight"):t("printers.permission.noControl"),children:i.jsx(_O,{on:j?.chamber_light??!1,className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>u(!0),disabled:!U||!r("printers:control"),className:`p-1.5 rounded disabled:opacity-50 ${U&&r("printers:control")?"hover:bg-bambu-dark-tertiary":""}`,title:r("printers:control")?t(U?"printers.skipObjects.tooltip":"printers.skipObjects.onlyWhilePrinting"):t("printers.permission.noControl"),children:i.jsx(bT,{className:"w-4 h-4 text-bambu-gray"})}),i.jsx("button",{onClick:W,disabled:Ee,className:"p-1.5 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50",title:t(o==="stream"?"camera.restartStream":"camera.refreshSnapshot"),children:i.jsx(wr,{className:`w-4 h-4 text-bambu-gray ${Ee?"animate-spin":""}`})}),i.jsx("button",{onClick:re,className:"p-1.5 hover:bg-bambu-dark-tertiary rounded",title:t(_?"camera.exitFullscreen":"camera.fullscreen"),children:_?i.jsx(KX,{className:"w-4 h-4 text-bambu-gray"}):i.jsx(Kfe,{className:"w-4 h-4 text-bambu-gray"})})]})]}),i.jsx("div",{className:"flex-1 flex items-center justify-center p-2 overflow-hidden",onWheel:ye,onMouseMove:F,onMouseUp:te,onMouseLeave:te,onTouchStart:de,onTouchMove:Ne,onTouchEnd:Se,style:{touchAction:"none"},children:i.jsxs("div",{className:"relative w-full h-full flex items-center justify-center",children:[(p||x)&&!A&&i.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 z-10",children:i.jsxs("div",{className:"text-center",children:[i.jsx(wr,{className:"w-8 h-8 text-bambu-gray animate-spin mx-auto mb-2"}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t(o==="stream"?"camera.connectingToCamera":"camera.capturingSnapshot")})]})}),A&&i.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/80 z-10",children:i.jsxs("div",{className:"text-center p-4",children:[i.jsx(Ph,{className:"w-10 h-10 text-orange-400 mx-auto mb-3"}),i.jsx("p",{className:"text-white mb-2",children:t("camera.connectionLost")}),i.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:t("camera.reconnecting",{countdown:R,attempt:T+1,max:VD})}),i.jsx("button",{onClick:W,className:"px-4 py-2 bg-bambu-green text-white text-sm rounded hover:bg-bambu-green/80 transition-colors",children:t("camera.reconnectNow")})]})}),d&&!A&&i.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black z-10",children:i.jsxs("div",{className:"text-center p-4",children:[i.jsx(Mn,{className:"w-12 h-12 text-orange-400 mx-auto mb-3"}),i.jsx("p",{className:"text-white mb-2",children:t("camera.cameraUnavailable")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-4 max-w-md",children:t("camera.cameraUnavailableDesc")}),i.jsx("button",{onClick:W,className:"px-4 py-2 bg-bambu-green text-white rounded hover:bg-bambu-green/80 transition-colors",children:t("camera.retry")})]})}),i.jsx("img",{ref:oe,src:qe,alt:t("camera.cameraStream"),className:"max-w-full max-h-full object-contain select-none",style:{transform:`scale(${D}) translate(${z.x/D}px, ${z.y/D}px)`,cursor:D>1?I?"grabbing":"grab":"default"},onError:qe?ne:void 0,onLoad:qe?O:void 0,onMouseDown:ae,draggable:!1},y),i.jsxs("div",{className:"absolute bottom-4 left-4 flex items-center gap-1.5 bg-black/60 rounded-lg px-2 py-1.5",children:[i.jsx("button",{onClick:fe,disabled:D<=1,className:"p-1.5 hover:bg-white/10 rounded disabled:opacity-30",title:t("camera.zoomOut"),children:i.jsx(WL,{className:"w-4 h-4 text-white"})}),i.jsxs("button",{onClick:Le,className:"px-2 py-1 text-sm text-white hover:bg-white/10 rounded min-w-[48px]",title:t("camera.resetZoom"),children:[Math.round(D*100),"%"]}),i.jsx("button",{onClick:ue,disabled:D>=4,className:"p-1.5 hover:bg-white/10 rounded disabled:opacity-30",title:t("camera.zoomIn"),children:i.jsx(GL,{className:"w-4 h-4 text-white"})})]})]})}),i.jsx(NO,{printerId:s,isOpen:c,onClose:()=>u(!1)})]}):i.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:i.jsx("p",{className:"text-white",children:t("camera.invalidPrinterId")})})}function _tt(t){const e=t.get("show")?.split(",")||["progress","layers","eta","filename","status"],n=parseInt(t.get("fps")||"15",10),r=Math.min(Math.max(isNaN(n)?15:n,1),30),a=t.get("camera"),s=a!=="false"&&a!=="0";return{size:t.get("size")||"medium",fps:r,showCamera:s,showProgress:e.includes("progress"),showLayers:e.includes("layers"),showEta:e.includes("eta"),showFilename:e.includes("filename"),showStatus:e.includes("status"),showPrinter:e.includes("printer")}}function Ntt(t,e){if(t.stg_cur_name)return t.stg_cur_name;switch(t.state){case"RUNNING":return e("streamOverlay.status.printing");case"PAUSE":return e("streamOverlay.status.paused");case"FINISH":return e("streamOverlay.status.finished");case"FAILED":return e("streamOverlay.status.failed");case"IDLE":return e("streamOverlay.status.idle");default:return t.state||e("streamOverlay.status.unknown")}}function ktt(t){switch(t){case"small":return{container:"p-3",text:"text-sm",textLarge:"text-lg",progressHeight:"h-2",icon:"w-3 h-3",gap:"gap-2",logoHeight:"h-12"};case"large":return{container:"p-6",text:"text-xl",textLarge:"text-3xl",progressHeight:"h-4",icon:"w-6 h-6",gap:"gap-4",logoHeight:"h-24"};default:return{container:"p-4",text:"text-base",textLarge:"text-xl",progressHeight:"h-3",icon:"w-4 h-4",gap:"gap-3",logoHeight:"h-16"}}}function Ctt(){const{printerId:t}=uw(),[e]=ML(),{t:n}=Ft(),r=an(),a=parseInt(t||"0",10),[s,o]=w.useState(Date.now()),l=w.useMemo(()=>_tt(e),[e]),c=ktt(l.size),{data:u}=et({queryKey:["printer",a],queryFn:()=>be.getPrinter(a),enabled:a>0}),{data:d}=et({queryKey:["printerStatus",a],queryFn:()=>be.getPrinterStatus(a),enabled:a>0,refetchInterval:2e3}),{data:m}=et({queryKey:["settings"],queryFn:be.getSettings}),p=m?.time_format||"system";w.useEffect(()=>{if(!a)return;const _=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/v1/ws`,N=new WebSocket(_);return N.onmessage=T=>{try{const C=JSON.parse(T.data);C.type==="printer_status"&&C.printer_id===a&&r.setQueryData(["printerStatus",a],C.status)}catch{}},N.onerror=()=>{},()=>{N.close()}},[a,r]),w.useEffect(()=>(document.title=u?`${u.name} - ${n("streamOverlay.title")}`:n("streamOverlay.title"),()=>{document.title="Bambuddy"}),[u,n]);const f=()=>{setTimeout(()=>{o(Date.now())},3e3)};if(!a)return i.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:i.jsx("p",{className:"text-white",children:n("streamOverlay.invalidPrinterId")})});if(!d)return i.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:i.jsx("p",{className:"text-gray-400",children:n("common.loading")})});const y=d.state==="RUNNING"||d.state==="PAUSE",v=d.progress||0,x=`/api/v1/printers/${a}/camera/stream?fps=${l.fps}&t=${s}`;return i.jsxs("div",{className:"min-h-screen bg-black relative overflow-hidden",children:[l.showCamera&&i.jsx("img",{src:x,alt:n("streamOverlay.cameraStream"),className:"absolute inset-0 w-full h-full object-contain",onError:f},s),i.jsx("a",{href:"https://github.com/maziggy/bambuddy",target:"_blank",rel:"noopener noreferrer",className:"absolute top-4 right-4 z-10",children:i.jsx("img",{src:"/img/bambuddy_logo_dark_transparent.png",alt:"Bambuddy",className:`${c.logoHeight} object-contain drop-shadow-lg hover:scale-105 transition-transform`})}),i.jsx("div",{className:"absolute bottom-0 left-0 right-0 z-10 bg-gradient-to-t from-black/80 via-black/60 to-transparent",children:i.jsxs("div",{className:`${c.container}`,children:[l.showPrinter&&u&&i.jsxs("div",{className:`flex items-center ${c.gap} mb-2`,children:[i.jsx(Sr,{className:`${c.icon} text-white/70`}),i.jsx("span",{className:`${c.text} text-white font-medium`,children:u.name})]}),l.showFilename&&d.current_print&&i.jsx("div",{className:`${c.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`,children:d.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,"")}),l.showStatus&&i.jsx("div",{className:`${c.text} text-white/70 mb-2`,children:Ntt(d,n)}),l.showProgress&&y&&i.jsxs("div",{className:"mb-3",children:[i.jsxs("div",{className:`flex items-center justify-between mb-1 ${c.text}`,children:[i.jsx("span",{className:"text-white/70",children:n("streamOverlay.progress")}),i.jsxs("span",{className:"text-white font-bold",children:[Math.round(v),"%"]})]}),i.jsx("div",{className:`w-full bg-white/20 rounded-full ${c.progressHeight}`,children:i.jsx("div",{className:`bg-bambu-green ${c.progressHeight} rounded-full transition-all duration-500`,style:{width:`${v}%`}})})]}),y&&(l.showLayers||l.showEta)&&i.jsxs("div",{className:`flex items-center ${c.gap} flex-wrap`,children:[l.showLayers&&d.layer_num!=null&&d.total_layers!=null&&d.total_layers>0&&i.jsxs("div",{className:`flex items-center ${c.gap} text-white/70`,children:[i.jsx(Gi,{className:c.icon}),i.jsxs("span",{className:c.text,children:[i.jsx("span",{className:"text-white",children:d.layer_num}),i.jsx("span",{className:"mx-1",children:"/"}),i.jsx("span",{children:d.total_layers})]})]}),l.showEta&&d.remaining_time!=null&&d.remaining_time>0&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:`flex items-center ${c.gap} text-white/70`,children:[i.jsx(pd,{className:c.icon}),i.jsx("span",{className:`${c.text} text-white`,children:Rs(d.remaining_time*60)})]}),i.jsxs("div",{className:`flex items-center ${c.gap} text-white/70`,children:[i.jsx(er,{className:c.icon}),i.jsxs("span",{className:`${c.text} text-white`,children:[n("streamOverlay.eta")," ",KL(d.remaining_time,p,n)]})]})]})]}),!y&&i.jsx("div",{className:`${c.text} text-white/70 py-2`,children:d.connected?n("streamOverlay.printerIdle"):n("streamOverlay.printerOffline")})]})})]})}function Ttt(){const{t}=Ft(),{id:e}=uw(),{mode:n}=Wf(),{data:r,isLoading:a,error:s}=et({queryKey:["external-link",e],queryFn:()=>be.getExternalLink(Number(e)),enabled:!!e});return a?i.jsx("div",{className:"flex items-center justify-center h-full",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):s||!r?i.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 text-bambu-gray",children:[i.jsx(Mn,{className:"w-12 h-12"}),i.jsx("p",{children:t("common.linkNotFound")})]}):i.jsx("iframe",{src:r.url,className:"h-full w-full border-0",style:{colorScheme:n},title:r.name,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox"})}function EY(){const{id:t}=uw(),e=Qo(),n=an(),{t:r}=Ft(),{showToast:a}=fn(),s=!!t,[o,l]=w.useState(""),[c,u]=w.useState(""),[d,m]=w.useState([]),[p,f]=w.useState(""),[y,v]=w.useState(!1),{data:x,isLoading:g}=et({queryKey:["group",t],queryFn:()=>be.getGroup(Number(t)),enabled:s}),{data:_,isLoading:N}=et({queryKey:["permissions"],queryFn:()=>be.getPermissions()});s&&x&&!y&&(l(x.name),u(x.description||""),m(x.permissions),v(!0));const T=pt({mutationFn:X=>be.createGroup(X),onSuccess:()=>{n.invalidateQueries({queryKey:["groups"]}),a(r("groups.toast.created")),e("/settings?tab=users")},onError:X=>{a(X.message,"error")}}),C=pt({mutationFn:X=>be.updateGroup(Number(t),X),onSuccess:()=>{n.invalidateQueries({queryKey:["groups"]}),a(r("groups.toast.updated")),e("/settings?tab=users")},onError:X=>{a(X.message,"error")}}),A=T.isPending||C.isPending,k=()=>{if(!o.trim()){a(r("groups.toast.enterGroupName"),"error");return}s?C.mutate({name:o!==x?.name?o:void 0,description:c,permissions:d}):T.mutate({name:o,description:c||void 0,permissions:d})},R=X=>{m(me=>me.includes(X)?me.filter(he=>he!==X):[...me,X])},P=(X,me)=>{const he=X.permissions.map(ge=>ge.value);m(ge=>{const Y=ge.filter(oe=>!he.includes(oe));return me?[...Y,...he]:Y})},D=X=>X.permissions.every(me=>d.includes(me.value)),H=X=>{const me=X.permissions.filter(he=>d.includes(he.value)).length;return me>0&&me{_&&m(_.all_permissions)},G=()=>{m([])},I=p.toLowerCase(),ee=w.useMemo(()=>_?I?_.categories.map(X=>({...X,permissions:X.permissions.filter(me=>me.label.toLowerCase().includes(I))})).filter(X=>X.permissions.length>0):_.categories:[],[_,I]),ie=_?.all_permissions.length??0;return g||N?i.jsx("div",{className:"flex items-center justify-center py-16",children:i.jsx(ht,{className:"w-8 h-8 text-bambu-green animate-spin"})}):i.jsxs("div",{className:"space-y-6 max-w-5xl mx-auto",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("button",{onClick:()=>e("/settings?tab=users"),className:"p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",children:i.jsx(IX,{className:"w-5 h-5"})}),i.jsx("h1",{className:"text-xl font-bold text-white",children:r(s?"groups.editor.title":"groups.editor.createTitle")})]}),s&&x?.is_system&&i.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-lg bg-yellow-500/10 border border-yellow-500/20 text-yellow-400 text-sm",children:[i.jsx(Mn,{className:"w-4 h-4 shrink-0"}),r("groups.form.systemGroupWarning")]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:r("groups.form.groupName")}),i.jsx("input",{type:"text",value:o,onChange:X=>l(X.target.value),disabled:s&&x?.is_system,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 disabled:opacity-50",placeholder:r("groups.form.groupNamePlaceholder")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:r("groups.form.description")}),i.jsx("input",{type:"text",value:c,onChange:X=>u(X.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:r("groups.form.descriptionPlaceholder")})]})]}),i.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("span",{className:"text-sm text-bambu-gray",children:[r("groups.editor.permissionsSelected",{count:d.length})," / ",ie]}),i.jsx(Oe,{size:"sm",variant:"ghost",onClick:z,children:r("groups.editor.selectAll")}),i.jsx(Oe,{size:"sm",variant:"ghost",onClick:G,children:r("groups.editor.clearAll")})]}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray"}),i.jsx("input",{type:"text",value:p,onChange:X=>f(X.target.value),placeholder:r("groups.editor.search"),className:"pl-9 pr-4 py-2 text-sm 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 w-64"})]})]}),ee.length===0?i.jsx("div",{className:"text-center py-12 text-bambu-gray",children:r("groups.editor.noResults")}):i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:ee.map(X=>{const me=_.categories.find(le=>le.name===X.name),he=me.permissions.filter(le=>d.includes(le.value)).length,ge=me.permissions.length,Y=D(me),oe=H(me);return i.jsxs(Mt,{children:[i.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between px-4 py-3 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-t-xl",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("button",{type:"button",onClick:()=>P(me,!Y),className:`w-5 h-5 rounded border flex items-center justify-center transition-colors shrink-0 ${Y?"bg-bambu-green border-bambu-green":oe?"bg-bambu-green/50 border-bambu-green":"border-bambu-gray hover:border-white"}`,children:[Y&&i.jsx(Yr,{className:"w-3 h-3 text-white"}),oe&&!Y&&i.jsx(jN,{className:"w-3 h-3 text-white"})]}),i.jsx(v3,{className:"w-4 h-4 text-bambu-gray shrink-0"}),i.jsx("span",{className:"text-white font-medium text-sm",children:X.name})]}),i.jsxs("span",{className:"text-xs text-bambu-gray tabular-nums",children:[he,"/",ge]})]}),i.jsx("div",{className:"p-3 space-y-1",children:X.permissions.map(le=>i.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:d.includes(le.value),onChange:()=>R(le.value),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:le.label})]},le.value))})]},X.name)})}),i.jsx("div",{className:"h-16"}),i.jsxs("div",{className:"fixed bottom-0 left-0 right-0 z-20 px-6 py-3 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-center justify-center gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>e("/settings?tab=users"),children:r("common.cancel")}),i.jsx(Oe,{onClick:k,disabled:A||!o.trim(),children:A?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),r("common.saving")]}):i.jsxs(i.Fragment,{children:[i.jsx(ts,{className:"w-4 h-4"}),r("common.save")]})})]})]})}const jY={material:"",subtype:"",brand:"",color_name:"",rgba:"808080FF",label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:"",note:"",cost_per_kg:null};function Att(t,e=!1){const n={};return e?(t.material||(n.material="Material is required"),{isValid:Object.keys(n).length===0,errors:n}):(t.slicer_filament||(n.slicer_filament="Slicer preset is required"),t.material||(n.material="Material is required"),t.brand||(n.brand="Brand is required"),t.subtype||(n.subtype="Subtype is required"),{isValid:Object.keys(n).length===0,errors:n})}const Ptt=["PLA","PETG","ABS","TPU","ASA","PC","PA","PVA","HIPS","PA-CF","PETG-CF","PLA-CF"],Mtt=["Bambu","PolyLite","PolyTerra","eSUN","Overture","Fiberon","SUNLU","Inland","Hatchbox","Generic"],u0=["Basic","Matte","Silk","Tough","HF","High Flow","Engineering","Galaxy","Glow","Marble","Metal","Rainbow","Sparkle","Wood","Translucent","Transparent","Clear","Lite","Pro","Plus","Max","Super","Ultra","Flex","Soft","Hard","Strong","Impact","Heat Resistant","UV Resistant","ESD","Conductive","Magnetic","Gradient","Dual Color","Tri Color","Multicolor"],qoe=[{name:"Black",hex:"000000"},{name:"White",hex:"FFFFFF"},{name:"Gray",hex:"808080"},{name:"Red",hex:"FF0000"},{name:"Orange",hex:"FFA500"},{name:"Yellow",hex:"FFFF00"},{name:"Green",hex:"00AE42"},{name:"Blue",hex:"0066FF"},{name:"Purple",hex:"8B00FF"},{name:"Pink",hex:"FF69B4"},{name:"Brown",hex:"8B4513"},{name:"Silver",hex:"C0C0C0"}],Ett=[{name:"Dark Red",hex:"8B0000"},{name:"Crimson",hex:"DC143C"},{name:"Coral",hex:"FF7F50"},{name:"Salmon",hex:"FA8072"},{name:"Dark Orange",hex:"FF8C00"},{name:"Peach",hex:"FFDAB9"},{name:"Gold",hex:"FFD700"},{name:"Khaki",hex:"F0E68C"},{name:"Lemon",hex:"FFF44F"},{name:"Lime",hex:"32CD32"},{name:"Forest Green",hex:"228B22"},{name:"Olive",hex:"808000"},{name:"Mint",hex:"98FF98"},{name:"Teal",hex:"008080"},{name:"Navy",hex:"000080"},{name:"Sky Blue",hex:"87CEEB"},{name:"Royal Blue",hex:"4169E1"},{name:"Cyan",hex:"00FFFF"},{name:"Turquoise",hex:"40E0D0"},{name:"Violet",hex:"EE82EE"},{name:"Magenta",hex:"FF00FF"},{name:"Indigo",hex:"4B0082"},{name:"Lavender",hex:"E6E6FA"},{name:"Plum",hex:"DDA0DD"},{name:"Hot Pink",hex:"FF69B4"},{name:"Rose",hex:"FF007F"},{name:"Blush",hex:"FFB6C1"},{name:"Chocolate",hex:"D2691E"},{name:"Tan",hex:"D2B48C"},{name:"Beige",hex:"F5F5DC"},{name:"Maroon",hex:"800000"},{name:"Dark Gray",hex:"404040"},{name:"Light Gray",hex:"D3D3D3"},{name:"Charcoal",hex:"36454F"},{name:"Ivory",hex:"FFFFF0"},{name:"Bambu Green",hex:"00AE42"},{name:"Jade White",hex:"E8E8E8"},{name:"Titan Gray",hex:"5A5A5A"}],DY=[...qoe,...Ett],Voe="bambuddy-recent-colors",jtt=8,Dtt=[{code:"GFL00",name:"Bambu PLA Basic",displayName:"Bambu PLA Basic",isCustom:!1,allCodes:["GFL00"]},{code:"GFL01",name:"Bambu PLA Matte",displayName:"Bambu PLA Matte",isCustom:!1,allCodes:["GFL01"]},{code:"GFL05",name:"Generic PLA",displayName:"Generic PLA",isCustom:!1,allCodes:["GFL05"]},{code:"GFG00",name:"Bambu PETG Basic",displayName:"Bambu PETG Basic",isCustom:!1,allCodes:["GFG00"]},{code:"GFG05",name:"Generic PETG",displayName:"Generic PETG",isCustom:!1,allCodes:["GFG05"]},{code:"GFB00",name:"Bambu ABS Basic",displayName:"Bambu ABS Basic",isCustom:!1,allCodes:["GFB00"]},{code:"GFB05",name:"Generic ABS",displayName:"Generic ABS",isCustom:!1,allCodes:["GFB05"]},{code:"GFA00",name:"Bambu ASA Basic",displayName:"Bambu ASA Basic",isCustom:!1,allCodes:["GFA00"]},{code:"GFU00",name:"Bambu TPU 95A",displayName:"Bambu TPU 95A",isCustom:!1,allCodes:["GFU00"]},{code:"GFU05",name:"Generic TPU",displayName:"Generic TPU",isCustom:!1,allCodes:["GFU05"]},{code:"GFC00",name:"Bambu PC Basic",displayName:"Bambu PC Basic",isCustom:!1,allCodes:["GFC00"]},{code:"GFN00",name:"Bambu PA Basic",displayName:"Bambu PA Basic",isCustom:!1,allCodes:["GFN00"]},{code:"GFN05",name:"Generic PA",displayName:"Generic PA",isCustom:!1,allCodes:["GFN05"]},{code:"GFS00",name:"Bambu PLA-CF",displayName:"Bambu PLA-CF",isCustom:!1,allCodes:["GFS00"]},{code:"GFT00",name:"Bambu PETG-CF",displayName:"Bambu PETG-CF",isCustom:!1,allCodes:["GFT00"]},{code:"GFNC0",name:"Bambu PA-CF",displayName:"Bambu PA-CF",isCustom:!1,allCodes:["GFNC0"]},{code:"GFV00",name:"Bambu PVA",displayName:"Bambu PVA",isCustom:!1,allCodes:["GFV00"]}];function Ex(t){let e=t.replace(/@.*$/,"").trim();e=e.replace(/\(Custom\)/i,"").trim(),e=e.replace(/^[#*]+\s*/,"").trim();const n=["PLA-CF","PETG-CF","ABS-GF","ASA-CF","PA-CF","PAHT-CF","PA6-CF","PA6-GF","PPA-CF","PPA-GF","PET-CF","PPS-CF","PC-CF","PC-ABS","ABS-GF","PCTG","PETG","PLA","ABS","ASA","PC","PA","TPU","PVA","HIPS","BVOH","PPS","PEEK","PEI"];let r="",a=-1;for(const c of n){const u=e.toUpperCase().indexOf(c.toUpperCase());if(u!==-1){r=c,a=u;break}}let s="";a>0&&(s=e.substring(0,a).trim(),s=s.replace(/[-_\s]+$/,""));let o="";a!==-1&&r&&(o=e.substring(a+r.length).trim(),o=o.replace(/^[-_\s]+/,""));let l="";for(const c of u0)if(o.toLowerCase().includes(c.toLowerCase())){l=c;break}if(!l&&s)for(const c of u0){const u=new RegExp(`\\s+${c}$`,"i");if(u.test(s)){l=c,s=s.replace(u,"").trim();break}}return{brand:s,material:r,variant:l}}function Rtt(t,e){const n=new Set(Mtt);for(const r of t){const{brand:a}=Ex(r.name);a&&a.length>1&&n.add(a)}if(e)for(const r of e)if(r.filament_vendor&&r.filament_vendor.length>1)n.add(r.filament_vendor);else{const{brand:a}=Ex(r.name);a&&a.length>1&&n.add(a)}return Array.from(n).sort((r,a)=>r.localeCompare(a))}function Ftt(t){const e=t.filter(r=>r.preset_type==="filament");if(e.length===0)return[];const n=new Map;for(const r of e){const a=r.name.replace(/@.*$/,"").trim(),s=n.get(a);if(s)s.allCodes.push(String(r.id));else{const o=r.filament_type||String(r.id);n.set(a,{code:o,name:a,displayName:a,isCustom:!1,allCodes:[o]})}}return Array.from(n.values()).sort((r,a)=>r.displayName.localeCompare(a.displayName))}function Ltt(t,e,n){if(t.length>0){const r=[],a=new Map;for(const s of t)if(s.is_custom){const o=s.name.toUpperCase();(e.size===0||Array.from(e).some(c=>o.includes(c))||!o.includes("@"))&&r.push({code:s.setting_id,name:s.name,displayName:`${s.name} (Custom)`,isCustom:!0,allCodes:[s.setting_id]})}else{const o=s.name.replace(/@.*$/,"").trim(),l=a.get(o);l?l.allCodes.push(s.setting_id):a.set(o,{code:s.setting_id,name:o,displayName:o,isCustom:!1,allCodes:[s.setting_id]})}return[...r,...Array.from(a.values())].sort((s,o)=>s.displayName.localeCompare(o.displayName))}if(n&&n.length>0){const r=Ftt(n);if(r.length>0)return r}return Dtt}function Ott(t,e){if(!t)return;let n=e.find(r=>r.code===t);if(n||(n=e.find(r=>r.allCodes.includes(t))),!n){const r=t.toLowerCase();n=e.find(a=>a.code.toLowerCase()===r||a.allCodes.some(s=>s.toLowerCase()===r))}return n}function Itt(){try{const t=localStorage.getItem(Voe);if(t)return JSON.parse(t)}catch{}return[]}function ztt(t,e){const n=e.filter(a=>a.hex.toUpperCase()!==t.hex.toUpperCase()),r=[t,...n].slice(0,jtt);try{localStorage.setItem(Voe,JSON.stringify(r))}catch{}return r}function GD(t,e){if(!e.material)return!1;const r=(t.name||"").replace(/^High Flow[_\s]+/i,"").replace(/^Standard[_\s]+/i,"").replace(/^HF[_\s]+/i,"").replace(/^S[_\s]+/i,"").trim(),a=Ex(r);return!(!(a.material.toUpperCase()===e.material.toUpperCase())||e.brand&&!(a.brand.toLowerCase().includes(e.brand.toLowerCase())||e.brand.toLowerCase().includes(a.brand.toLowerCase()))||e.subtype&&!(a.variant.toLowerCase().includes(e.subtype.toLowerCase())||e.subtype.toLowerCase().includes(a.variant.toLowerCase())||r.toLowerCase().includes(e.subtype.toLowerCase())))}function Utt({formData:t,updateField:e,cloudAuthenticated:n,loadingCloudPresets:r,presetInputValue:a,setPresetInputValue:s,selectedPresetOption:o,filamentOptions:l,availableBrands:c,availableMaterials:u,quickAdd:d,quantity:m,onQuantityChange:p,errors:f}){const{t:y}=Ft(),[v,x]=w.useState(!1),[g,_]=w.useState(!1),[N,T]=w.useState(!1),[C,A]=w.useState(!1),[k,R]=w.useState(""),[P,D]=w.useState(""),[H,z]=w.useState(""),[G,I]=w.useState(String(t.label_weight)),[ee,ie]=w.useState(!1),X=w.useRef(null),me=w.useRef(null),he=w.useRef(null),ge=w.useRef(null);w.useEffect(()=>{const q=Z=>{X.current&&!X.current.contains(Z.target)&&x(!1),ge.current&&!ge.current.contains(Z.target)&&A(!1),me.current&&!me.current.contains(Z.target)&&_(!1),he.current&&!he.current.contains(Z.target)&&T(!1)};return document.addEventListener("mousedown",q),()=>document.removeEventListener("mousedown",q)},[]);const Y=w.useMemo(()=>{if(!a)return l;const q=a.toLowerCase();return l.filter(Z=>Z.displayName.toLowerCase().includes(q)||Z.code.toLowerCase().includes(q))},[l,a]),oe=w.useMemo(()=>{if(!k)return c;const q=k.toLowerCase();return c.filter(j=>j.toLowerCase().includes(q)).sort((j,E)=>{const U=j.toLowerCase()===q,K=E.toLowerCase()===q;return U&&!K?-1:!U&&K?1:j.localeCompare(E)})},[c,k]),le=w.useMemo(()=>{if(!P)return u0;const q=P.toLowerCase();return u0.filter(Z=>Z.toLowerCase().includes(q))},[P]),xe=w.useMemo(()=>{if(!H)return u;const q=H.toLowerCase();return u.filter(j=>j.toLowerCase().includes(q)).sort((j,E)=>{const U=j.toLowerCase()===q,K=E.toLowerCase()===q;return U&&!K?-1:!U&&K?1:j.localeCompare(E)})},[H,u]);w.useEffect(()=>{ee||I(String(t.label_weight))},[t.label_weight,ee]);const Pe=q=>{e("slicer_filament",q.code),s(q.displayName),x(!1);const Z=Ex(q.name);Z.material&&e("material",Z.material),Z.brand&&e("brand",Z.brand),Z.variant&&e("subtype",Z.variant)};return i.jsxs("div",{className:"space-y-4",children:[!d&&i.jsx("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:r?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-3 h-3 animate-spin"})," ",y("inventory.loadingPresets")]}):n?i.jsxs(i.Fragment,{children:[i.jsx(Fx,{className:"w-3 h-3 text-bambu-green"})," ",y("inventory.cloudConnected")]}):i.jsxs(i.Fragment,{children:[i.jsx(spe,{className:"w-3 h-3"})," ",y("inventory.cloudNotConnected")]})}),!d&&i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:[y("inventory.slicerPreset")," *"]}),i.jsxs("div",{className:"relative",ref:X,children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),i.jsx("input",{type:"text",className:"w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:y("inventory.searchPresets"),value:a,onChange:q=>{s(q.target.value),x(!0)},onFocus:()=>{x(!0),s("")}}),v&&i.jsx("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto",children:Y.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:y("inventory.noPresetsFound")}):Y.map(q=>i.jsx("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary truncate ${o?.code===q.code?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>Pe(q),children:q.displayName},q.code))})]}),o&&i.jsxs("div",{className:"mt-1 text-xs text-bambu-gray",children:[y("inventory.selectedPreset"),": ",i.jsx("span",{className:"font-mono text-bambu-green",children:o.code})]}),f?.slicer_filament&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:f.slicer_filament})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:[y("inventory.material")," *"]}),i.jsxs("div",{className:"relative",ref:ge,children:[i.jsx("input",{type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:y("inventory.selectMaterial"),value:C?H:t.material,onChange:q=>{z(q.target.value),A(!0)},onFocus:()=>{A(!0),z("")}}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),C&&i.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[xe.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:y("inventory.noResults")}):xe.map(q=>i.jsx("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${t.material===q?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>{e("material",q),A(!1),z("")},children:q},q)),H&&!xe.includes(H)&&i.jsx("button",{type:"button",className:"w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary",onClick:()=>{e("material",H),A(!1),z("")},children:y("inventory.useCustomMaterial",{material:H})})]})]}),f?.material&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:f.material})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:[y("inventory.brand"),!d&&" *"]}),i.jsxs("div",{className:"relative",ref:me,children:[i.jsx("input",{type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:y("inventory.searchBrand"),value:g?k:t.brand,onChange:q=>{R(q.target.value),_(!0)},onFocus:()=>{_(!0),R("")}}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),g&&i.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[oe.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:y("inventory.noResults")}):oe.map(q=>i.jsx("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${t.brand===q?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>{e("brand",q),_(!1),R("")},children:q},q)),k&&!oe.includes(k)&&i.jsx("button",{type:"button",className:"w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary",onClick:()=>{e("brand",k),_(!1),R("")},children:y("inventory.useCustomBrand",{brand:k})})]})]}),f?.brand&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:f.brand})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:[y("inventory.subtype"),!d&&" *"]}),i.jsxs("div",{className:"relative",ref:he,children:[i.jsx("input",{type:"text",value:N?P:t.subtype,onChange:q=>{D(q.target.value),T(!0)},onFocus:()=>{T(!0),D("")},placeholder:"Basic, Matte, Silk...",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green"}),i.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),N&&i.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[le.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:y("inventory.noResults")}):le.map(q=>i.jsx("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${t.subtype===q?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>{e("subtype",q),T(!1),D("")},children:q},q)),P&&!u0.some(q=>q.toLowerCase()===P.toLowerCase().trim())&&i.jsx("button",{type:"button",className:"w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary",onClick:()=>{e("subtype",P),T(!1),D("")},children:y("inventory.useCustomBrand",{brand:P})})]})]}),f?.subtype&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:f.subtype})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:y("inventory.labelWeight")}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"number",className:"w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green",value:G,min:0,onFocus:()=>ie(!0),onChange:q=>I(q.target.value),onBlur:()=>{ie(!1);const q=G.trim(),Z=Number(q);if(!q||!Number.isFinite(Z)||Z<0){I(String(t.label_weight));return}const j=Math.round(Z);e("label_weight",j),I(String(j))}}),i.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray",children:"g"})]})]}),d&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:y("inventory.quantity")}),i.jsx("input",{type:"number",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",value:m,min:1,max:100,onChange:q=>{const Z=Math.max(1,Math.min(100,parseInt(q.target.value)||1));p(Z)}})]})]})}function Btt({formData:t,updateField:e,recentColors:n,onColorUsed:r,catalogColors:a}){const{t:s}=Ft(),[o,l]=w.useState(!1),[c,u]=w.useState(""),d=t.rgba.replace("#","").substring(0,6),m=g=>d.toUpperCase()===g.toUpperCase(),p=(g,_)=>{e("rgba",g.toUpperCase()+"FF"),e("color_name",_),r({name:_,hex:g})},f=w.useMemo(()=>{if(a.length===0)return[];const g=t.brand?.trim(),_=t.material?.toLowerCase().trim(),N=t.subtype?.toLowerCase().trim();if(!g&&!_)return[];const T=g?g.toLowerCase().split(/[\s\-_]+/).filter(k=>k.length>=2):[],C=k=>{if(T.length===0)return!0;const R=k.toLowerCase();return T.some(P=>R.includes(P))};if(g&&!_){const k=a.filter(R=>C(R.manufacturer));if(k.length>0)return k.map(R=>({name:R.color_name,hex:R.hex_color.replace("#","").substring(0,6),manufacturer:R.manufacturer,material:typeof R.material=="string"?R.material:void 0}))}const A=_&&N?`${_} ${N}`:"";if(A){const k=a.filter(P=>C(P.manufacturer)&&P.material?.toLowerCase()===A);if(k.length>0)return k.map(P=>({name:P.color_name,hex:P.hex_color.replace("#","").substring(0,6),manufacturer:P.manufacturer,material:typeof P.material=="string"?P.material:void 0}));const R=A.replace(/\+$/,"");if(R!==A){const P=a.filter(D=>C(D.manufacturer)&&D.material?.toLowerCase()===R);if(P.length>0)return P.map(D=>({name:D.color_name,hex:D.hex_color.replace("#","").substring(0,6),manufacturer:D.manufacturer,material:typeof D.material=="string"?D.material:void 0}))}}if(_){const k=a.filter(R=>C(R.manufacturer)&&(!R.material||R.material.toLowerCase().startsWith(_)));if(k.length>0)return k.map(R=>({name:R.color_name,hex:R.hex_color.replace("#","").substring(0,6),manufacturer:R.manufacturer,material:typeof R.material=="string"?R.material:void 0}))}return[]},[a,t.brand,t.material,t.subtype]),y=w.useMemo(()=>{if(!c)return f;if(f.length===0)return[];const g=c.toLowerCase();return f.filter(N=>N.name.toLowerCase().includes(g)||(N.manufacturer?.toLowerCase().includes(g)??!1)||(N.material?.toLowerCase().includes(g)??!1))},[c,f]),v=f.length>0,x=w.useMemo(()=>c?DY.filter(g=>g.name.toLowerCase().includes(c.toLowerCase())):o?DY:qoe,[c,o]);return i.jsxs("div",{className:"space-y-3",children:[i.jsx("div",{className:"h-10 rounded-lg border border-bambu-dark-tertiary",style:{backgroundColor:`#${d}`}}),n.length>0&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-bambu-gray shrink-0",children:[i.jsx(er,{className:"w-3 h-3"}),i.jsx("span",{children:s("inventory.recentColors")})]}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:n.map(g=>i.jsx("button",{type:"button",onClick:()=>p(g.hex,g.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 ${m(g.hex)?"border-bambu-green ring-1 ring-bambu-green/30 scale-110":"border-bambu-dark-tertiary"}`,style:{backgroundColor:`#${g.hex}`},title:g.name},g.hex))})]}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),i.jsx("input",{type:"text",className:"w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:s("inventory.searchColors"),value:c,onChange:g=>u(g.target.value)})]}),v?i.jsxs("div",{className:"space-y-1.5",children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:c?s("inventory.searchResults"):`${t.brand}${t.material?` ${t.material}`:""}`}),i.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[y.map(g=>i.jsx("button",{type:"button",onClick:()=>p(g.hex,g.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${m(g.hex)?"border-bambu-green ring-1 ring-bambu-green/30 scale-110":"border-bambu-dark-tertiary"}`,style:{backgroundColor:`#${g.hex}`},title:g.manufacturer&&g.material?`${g.name} (${g.manufacturer} — ${g.material})`:g.manufacturer?`${g.name} (${g.manufacturer})`:g.name,children:i.jsx("span",{className:"absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white",children:g.manufacturer&&g.material?`${g.name} (${g.manufacturer} — ${g.material})`:g.manufacturer?`${g.name} (${g.manufacturer})`:g.name})},`${g.hex}-${g.name}-${g.manufacturer??""}`)),y.length===0&&i.jsx("p",{className:"text-sm text-bambu-gray py-1",children:s("inventory.noColorsFound")})]})]}):i.jsxs("div",{className:"space-y-1.5",children:[i.jsxs("div",{className:"flex items-center justify-between text-xs text-bambu-gray",children:[i.jsx("span",{children:s(c?"inventory.searchResults":o?"inventory.allColors":"inventory.commonColors")}),!c&&i.jsx("button",{type:"button",onClick:()=>l(!o),className:"flex items-center gap-1 hover:text-white transition-colors",children:o?i.jsxs(i.Fragment,{children:[s("inventory.showLess")," ",i.jsx(Il,{className:"w-3 h-3"})]}):i.jsxs(i.Fragment,{children:[s("inventory.showAll")," ",i.jsx(Ln,{className:"w-3 h-3"})]})})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[x.map(g=>i.jsx("button",{type:"button",onClick:()=>p(g.hex,g.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${m(g.hex)?"border-bambu-green ring-1 ring-bambu-green/30 scale-110":"border-bambu-dark-tertiary"}`,style:{backgroundColor:`#${g.hex}`},title:g.name,children:i.jsx("span",{className:"absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white",children:g.name})},g.hex)),x.length===0&&i.jsx("p",{className:"text-sm text-bambu-gray py-1",children:s("inventory.noColorsFound")})]})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:s("inventory.colorName")}),i.jsx("input",{type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:s("inventory.colorNamePlaceholder"),value:t.color_name,onChange:g=>e("color_name",g.target.value)})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:s("inventory.hexColor")}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray",children:"#"}),i.jsx("input",{type:"text",className:"w-full pl-7 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono uppercase focus:outline-none focus:border-bambu-green",placeholder:"RRGGBB",value:d.toUpperCase(),onChange:g=>{const _=g.target.value.replace("#","").replace(/[^0-9A-Fa-f]/g,"");_.length<=8&&e("rgba",_.toUpperCase()+(_.length<=6?"FF":""))}})]}),i.jsx("input",{type:"color",className:"w-11 h-[38px] rounded-lg cursor-pointer border border-bambu-dark-tertiary shrink-0 bg-transparent",value:`#${d}`,onChange:g=>{const _=g.target.value.replace("#","").toUpperCase();e("rgba",_+"FF")},title:s("inventory.pickColor")})]})]})]})]})}function Htt({catalog:t,value:e,onChange:n,catalogId:r,onCatalogIdChange:a}){const{t:s}=Ft(),[o,l]=w.useState(!1),[c,u]=w.useState(""),d=w.useRef(null),m=w.useRef(null);w.useEffect(()=>{const v=x=>{d.current&&!d.current.contains(x.target)&&l(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]),w.useEffect(()=>{if(t.length===0)return;const v=t.filter(x=>x.weight===e);if(r){const x=t.find(g=>g.id===r);if(x&&x.weight===e)return}v.length===1?a(v[0].id):v.length===0&&r!==null&&a(null)},[e,t,r,a]);const p=w.useMemo(()=>{if(!c)return t;const v=c.toLowerCase();return t.filter(x=>x.name.toLowerCase().includes(v)||x.weight.toString().includes(v))},[t,c]),f=w.useMemo(()=>t.filter(v=>v.weight===e),[t,e]),y=w.useMemo(()=>{if(o)return c;if(r){const v=t.find(x=>x.id===r);if(v)return v.name}return f.length>0?f[0].name:""},[o,c,r,t,f]);return i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(Mge,{className:"w-3.5 h-3.5 text-bambu-gray"}),s("inventory.coreWeight")]})}),i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsxs("div",{className:"flex-1 min-w-0 relative",ref:d,children:[i.jsx("input",{ref:m,type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:s("inventory.searchSpoolWeight"),value:y,onFocus:()=>{l(!0),u("")},onChange:v=>{u(v.target.value),l(!0)}}),o&&i.jsx("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto",children:p.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:s("inventory.noResults")}):p.map(v=>i.jsxs("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex justify-between items-center ${(r?v.id===r:v.weight===e)?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>{a(v.id),n(v.weight),l(!1),u("")},children:[i.jsx("span",{className:"truncate",children:v.name}),i.jsxs("span",{className:"font-mono text-xs text-bambu-gray ml-2 shrink-0",children:[v.weight,"g"]})]},v.id))})]}),i.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[i.jsx("input",{type:"number",className:"w-16 px-2 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm text-center font-mono focus:outline-none focus:border-bambu-green",value:e,min:0,max:2e3,onChange:v=>{const x=parseInt(v.target.value);!isNaN(x)&&x>=0&&n(x)}}),i.jsx("span",{className:"text-bambu-gray text-sm",children:"g"})]})]})]})}function $tt({formData:t,updateField:e,spoolCatalog:n,currencySymbol:r}){const{t:a}=Ft(),{showToast:s}=fn(),[o,l]=w.useState(""),[c,u]=w.useState(!1),[d,m]=w.useState(""),[p,f]=w.useState(!1),y=Math.max(0,t.label_weight-t.weight_used),v=t.core_weight+y;return w.useEffect(()=>{c||l(String(v))},[c,v]),w.useEffect(()=>{p||m(String(y))},[p,y]),i.jsxs("div",{className:"space-y-4",children:[i.jsx(Htt,{catalog:n,value:t.core_weight,onChange:x=>e("core_weight",x),catalogId:t.core_weight_catalog_id,onCatalogIdChange:x=>e("core_weight_catalog_id",x)}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:a("inventory.currentWeight")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("input",{type:"number",value:d,min:0,max:t.label_weight,onFocus:()=>f(!0),onChange:x=>{m(x.target.value)},onBlur:()=>{f(!1);const x=d.trim(),g=Number(x);if(!x||!Number.isFinite(g)||g<0||g>t.label_weight){m(String(y));return}const _=Math.round(g);e("weight_used",Math.max(0,t.label_weight-_)),m(String(_))},className:"w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"}),i.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray",children:"g"})]}),i.jsxs("span",{className:"text-xs text-bambu-gray shrink-0",children:["/ ",t.label_weight,"g"]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:a("inventory.measuredWeight")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("input",{type:"number",value:o,min:0,onFocus:()=>u(!0),onChange:x=>{l(x.target.value)},onBlur:()=>{u(!1);const x=o.trim(),g=Number(x),_=t.core_weight,N=t.core_weight+t.label_weight;if(!x||!Number.isFinite(g)||g<_||g>N){s(a("inventory.measuredWeightError",{min:_,max:N}),"error"),l(String(v));return}const T=Math.round(g),C=Math.max(0,Math.min(t.label_weight,T-t.core_weight));e("weight_used",Math.max(0,t.label_weight-C)),l(String(T))},className:"w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"}),i.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray",children:"g"})]}),i.jsxs("span",{className:"text-xs text-bambu-gray shrink-0",children:["/ ",t.core_weight+t.label_weight,"g"]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:a("inventory.costPerKg","Cost per kg")}),i.jsx("div",{className:"flex items-center gap-2",children:i.jsxs("div",{className:"relative flex-1",children:[i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none",children:r}),i.jsx("input",{type:"number",value:t.cost_per_kg??"",min:0,step:.01,placeholder:"0.00",onChange:x=>{const g=x.target.value===""?null:parseFloat(x.target.value);e("cost_per_kg",g)},style:{paddingLeft:`${Math.max(2,r.length*.6+1)}rem`},className:"w-full py-2 pr-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"})]})})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:a("inventory.note")}),i.jsx("textarea",{className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green resize-none min-h-[80px]",placeholder:a("inventory.notePlaceholder"),value:t.note,onChange:x=>e("note",x.target.value)})]})]})}function qtt({formData:t,printersWithCalibrations:e,selectedProfiles:n,setSelectedProfiles:r,expandedPrinters:a,setExpandedPrinters:s}){const{t:o}=Ft(),l=p=>{s(f=>{const y=new Set(f);return y.has(p)?y.delete(p):y.add(p),y})},c=(p,f,y)=>{const v=`${p}:${f}:${y??"null"}`,x=`${p}:${y??"null"}`;r(g=>{const _=new Set(g);if(_.has(v))_.delete(v);else{for(const N of Array.from(_)){const T=N.split(":");`${T[0]}:${T[2]}`===x&&_.delete(N)}_.add(v)}return _})},u=()=>{const p=new Set;for(const{printer:f,calibrations:y}of e){if(!f.connected)continue;const v=y.filter(g=>GD(g,t)),x=new Map;for(const g of v){const _=`${g.extruder_id??"null"}`;x.has(_)||x.set(_,[]),x.get(_).push(g)}for(const[g,_]of x)if(_.length>0){const T=[..._].sort((C,A)=>A.k_value-C.k_value)[0];p.add(`${f.id}:${T.cali_idx}:${g}`)}}r(p)};if(!t.material)return i.jsx("div",{className:"p-6 bg-bambu-dark rounded-lg text-center",children:i.jsx("p",{className:"text-bambu-gray",children:o("inventory.selectMaterialFirst")})});if(e.length===0)return i.jsx("div",{className:"p-6 bg-bambu-dark rounded-lg text-center",children:i.jsx("p",{className:"text-bambu-gray",children:o("inventory.noPrintersConfigured")})});const d=e.reduce((p,{printer:f,calibrations:y})=>f.connected?p+y.filter(v=>GD(v,t)).length:p,0),m=(p,f)=>{const y=`${p.id}:${f.cali_idx}:${f.extruder_id??"null"}`,v=n.has(y);return i.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg cursor-pointer transition-all border ${v?"bg-bambu-green/10 border-bambu-green/30":"bg-bambu-dark border-transparent hover:bg-bambu-dark/80"}`,children:[i.jsx("input",{type:"checkbox",checked:v,onChange:()=>c(String(p.id),f.cali_idx,f.extruder_id),className:"w-4 h-4 rounded border-bambu-dark-tertiary text-bambu-green focus:ring-bambu-green"}),i.jsx("div",{className:"flex-1 min-w-0",children:i.jsx("span",{className:`text-sm font-medium ${v?"text-bambu-green":"text-white"}`,children:f.name||f.filament_id})}),i.jsx("div",{className:"flex items-center gap-2 shrink-0",children:i.jsxs("span",{className:"text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray",children:["K=",f.k_value.toFixed(3)]})})]},`${f.cali_idx}-${f.extruder_id}`)};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("p",{className:"text-xs text-bambu-gray",children:[o("inventory.matchingFilter"),": ",t.brand||o("inventory.anyBrand")," / ",t.material," / ",t.subtype||o("inventory.anyVariant")]}),d>0&&i.jsxs("button",{type:"button",onClick:u,className:"flex items-center gap-1.5 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white hover:border-bambu-green transition-colors",children:[i.jsx(ax,{className:"w-3.5 h-3.5"}),o("inventory.autoSelect")," (",d,")"]})]}),i.jsx("div",{className:"space-y-3",children:e.map(({printer:p,calibrations:f})=>{const y=a.has(String(p.id)),v=f.filter(T=>GD(T,t)),x=v.length,g=v.some(T=>T.extruder_id!==void 0&&T.extruder_id!==null&&T.extruder_id>0),_=v.filter(T=>T.extruder_id===1),N=v.filter(T=>T.extruder_id===0||T.extruder_id===void 0||T.extruder_id===null);return i.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[i.jsxs("button",{type:"button",onClick:()=>l(String(p.id)),className:"w-full px-4 py-3 flex items-center justify-between bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary transition-colors",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[y?i.jsx(Ln,{className:"w-4 h-4 text-bambu-gray"}):i.jsx(ha,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"font-medium text-white",children:p.name}),x>0?i.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green",children:[x," ",o(x!==1?"inventory.matches":"inventory.match")]}):i.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray",children:o("inventory.noMatches")})]}),i.jsx("span",{className:`text-xs px-2 py-1 rounded-full ${p.connected?"bg-green-500/20 text-green-500":"bg-bambu-gray/20 text-bambu-gray"}`,children:p.connected?o("inventory.connected"):o("inventory.offline")})]}),y&&i.jsx("div",{className:"px-4 py-3 space-y-3 bg-bambu-dark border-t border-bambu-dark-tertiary",children:p.connected?x===0?i.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:o("inventory.noKProfilesMatch")}):g?i.jsxs(i.Fragment,{children:[_.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wide",children:o("inventory.leftNozzle")}),i.jsx("div",{className:"space-y-2",children:_.map(T=>m(p,T))})]}),N.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wide",children:o("inventory.rightNozzle")}),i.jsx("div",{className:"space-y-2",children:N.map(T=>m(p,T))})]})]}):i.jsx("div",{className:"space-y-2",children:v.map(T=>m(p,T))}):i.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:o("inventory.printerOffline")})})]},p.id)})}),n.size>0&&i.jsx("div",{className:"p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:i.jsxs("p",{className:"text-sm text-white",children:[i.jsx("span",{className:"font-semibold",children:n.size})," ",o("inventory.profilesSelected")]})})]})}function Vtt(t){const e=new Date(t);return e.toLocaleDateString("en-GB",{day:"2-digit",month:"2-digit",year:"2-digit"})+" "+e.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"})}const Gtt={completed:"text-bambu-green",failed:"text-red-400",aborted:"text-yellow-400"};function Wtt({spoolId:t}){const{t:e}=Ft(),n=an(),{showToast:r}=fn(),{data:a,isLoading:s}=et({queryKey:["spool-usage",t],queryFn:()=>be.getSpoolUsageHistory(t)}),o=pt({mutationFn:()=>be.clearSpoolUsageHistory(t),onSuccess:()=>{n.invalidateQueries({queryKey:["spool-usage",t]}),r(e("inventory.historyCleared"),"success")}});return s?i.jsx("div",{className:"flex justify-center py-4",children:i.jsx(ht,{className:"w-5 h-5 animate-spin text-bambu-green"})}):!a||a.length===0?i.jsxs("div",{className:"text-center py-4 text-bambu-gray text-sm",children:[i.jsx(er,{className:"w-5 h-5 mx-auto mb-2 opacity-50"}),e("inventory.noUsageHistory")]}):i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("h4",{className:"text-sm font-medium text-white",children:e("inventory.usageHistory")}),i.jsxs(Oe,{variant:"ghost",size:"sm",onClick:()=>o.mutate(),disabled:o.isPending,className:"text-xs text-bambu-gray hover:text-red-400",children:[i.jsx(Jt,{className:"w-3 h-3 mr-1"}),e("inventory.clearHistory")]})]}),i.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:a.map(l=>i.jsxs("div",{className:"flex items-center justify-between p-2 rounded bg-bambu-dark/50 text-xs",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("span",{className:"text-bambu-gray",children:Vtt(l.created_at)}),l.print_name&&i.jsx("span",{className:"text-white ml-2 truncate",title:l.print_name,children:l.print_name})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0 ml-2",children:[i.jsxs("span",{className:"text-white font-medium",children:[l.weight_used.toFixed(1),"g"]}),i.jsxs("span",{className:"text-bambu-gray",children:["(",l.percent_used,"%)"]}),i.jsx("span",{className:Gtt[l.status]||"text-bambu-gray",children:l.status})]})]},l.id))})]})}function Ktt({isOpen:t,onClose:e,spool:n,printersWithCalibrations:r=[],currencySymbol:a}){const{t:s}=Ft(),o=an(),{showToast:l}=fn(),c=!!n,[u,d]=w.useState(jY),[m,p]=w.useState({}),[f,y]=w.useState("filament"),[v,x]=w.useState(!1),[g,_]=w.useState(!1),[N,T]=w.useState(1),[C,A]=w.useState(!1),[k,R]=w.useState(!1),[P,D]=w.useState([]),[H,z]=w.useState(""),[G,I]=w.useState([]),[ee,ie]=w.useState([]),[X,me]=w.useState([]),[he,ge]=w.useState([]),[Y,oe]=w.useState([]),[le,xe]=w.useState(new Set),[Pe,q]=w.useState(new Set),Z=r.length>0?r:Y,j=w.useMemo(()=>le.size,[le]);w.useEffect(()=>{ge(Itt())},[]),w.useEffect(()=>{t&&((async()=>{R(!0);try{const de=await be.getCloudStatus();if(A(de.is_authenticated),de.is_authenticated){const Ne=await be.getFilamentPresets();D(Ne)}}catch(de){console.error("Failed to fetch cloud presets:",de),A(!1)}finally{R(!1)}})(),be.getSpoolCatalog().then(I).catch(console.error),be.getColorCatalog().then(me).catch(console.error),be.getLocalPresets().then(de=>ie(de.filament)).catch(console.error),r.length===0&&(async()=>{try{const de=await be.getPrinters(),Ne=await Promise.all(de.map(Le=>be.getPrinterStatus(Le.id).catch(()=>null))),Se=[];for(let Le=0;Le({cali_idx:je.slot_id,filament_id:je.filament_id,setting_id:je.setting_id||"",name:je.name,k_value:parseFloat(je.k_value)||0,n_coef:parseFloat(je.n_coef)||0,extruder_id:je.extruder_id,nozzle_diameter:je.nozzle_diameter}))}catch{}Se.push({printer:{...qe,connected:Te},calibrations:Ae})}oe(Se)}catch(de){console.error("Failed to fetch printer calibrations:",de)}})())},[t,r.length]);const E=w.useMemo(()=>Ltt(P,new Set,ee),[P,ee]),U=w.useMemo(()=>{const pe=Rtt(P,ee),de=X.map(Se=>Se.manufacturer?.trim()).filter(Se=>!!Se),Ne=new Set([...pe,...de]);return Array.from(Ne).sort((Se,Le)=>Se.localeCompare(Le))},[P,ee,X]),K=w.useMemo(()=>{const pe=X.map(Ne=>Ne.material?.trim()).filter(Ne=>!!Ne),de=new Set([...Ptt,...pe]);return Array.from(de).sort((Ne,Se)=>Ne.localeCompare(Se))},[X]),$=w.useMemo(()=>{const pe=[];for(const de of X){const Ne=de.manufacturer?.trim(),Se=de.material?.trim();Ne&&Se&&pe.push({brand:Ne,material:Se})}for(const de of P){const Ne=Ex(de.name);Ne.brand&&Ne.material&&pe.push({brand:Ne.brand,material:Ne.material})}for(const de of ee){const Ne=Ex(de.name),Se=de.filament_vendor?.trim()||Ne.brand,Le=Ne.material;Se&&Le&&pe.push({brand:Se,material:Le})}return pe},[P,X,ee]),ne=w.useMemo(()=>{const pe=new Map;for(const de of $){const Ne=de.brand.toLowerCase(),Se=de.material.toLowerCase();pe.has(Ne)||pe.set(Ne,new Set),pe.get(Ne).add(Se)}return pe},[$]),O=w.useMemo(()=>{const pe=new Map;for(const de of $){const Ne=de.brand.toLowerCase(),Se=de.material.toLowerCase();pe.has(Se)||pe.set(Se,new Set),pe.get(Se).add(Ne)}return pe},[$]),V=w.useMemo(()=>{if(!u.material)return U;const pe=u.material.toLowerCase(),de=O.get(pe);return!de||de.size===0?U:U.filter(Ne=>de.has(Ne.toLowerCase()))},[U,u.material,O]),J=w.useMemo(()=>{if(!u.brand)return K;const pe=u.brand.toLowerCase(),de=ne.get(pe);return!de||de.size===0?K:K.filter(Ne=>de.has(Ne.toLowerCase()))},[K,u.brand,ne]),W=w.useMemo(()=>Ott(u.slicer_filament,E),[u.slicer_filament,E]);w.useEffect(()=>{if(t){if(n)if(d({material:n.material||"",subtype:n.subtype||"",brand:n.brand||"",color_name:n.color_name||"",rgba:n.rgba||"808080FF",label_weight:n.label_weight||1e3,core_weight:n.core_weight||250,core_weight_catalog_id:n.core_weight_catalog_id??null,weight_used:n.weight_used||0,slicer_filament:n.slicer_filament||"",note:n.note||"",cost_per_kg:n.cost_per_kg??null}),z(n.slicer_filament_name||n.slicer_filament||""),n.k_profiles&&n.k_profiles.length>0){const pe=new Set;for(const de of n.k_profiles)de.cali_idx!==null&&de.cali_idx!==void 0&&pe.add(`${de.printer_id}:${de.cali_idx}:${de.extruder??"null"}`);xe(pe)}else xe(new Set);else d(jY),z(""),xe(new Set),_(!1),T(1);p({}),y("filament"),x(!1)}},[t,n]),w.useEffect(()=>{t&&Z.length>0&&q(new Set(Z.map(pe=>String(pe.printer.id))))},[t,Z]);const re=(pe,de)=>{d(Ne=>({...Ne,[pe]:de})),pe==="weight_used"&&x(!0),m[pe]&&p(Ne=>({...Ne,[pe]:void 0}))},ue=pe=>{ge(de=>ztt(pe,de))},fe=pt({mutationFn:pe=>be.createSpool(pe),onSuccess:async pe=>{le.size>0&&pe?.id&&await F(pe.id),await o.invalidateQueries({queryKey:["inventory-spools"]}),l(s("inventory.spoolCreated"),"success"),e()},onError:pe=>{l(pe.message,"error")}}),ye=pt({mutationFn:({data:pe,qty:de})=>be.bulkCreateSpools(pe,de),onSuccess:async pe=>{if(le.size>0)for(const de of pe)await F(de.id);await o.invalidateQueries({queryKey:["inventory-spools"]}),l(s("inventory.spoolsCreated",{count:pe.length}),"success"),e()},onError:pe=>{l(pe.message,"error")}}),ae=pt({mutationFn:pe=>be.updateSpool(n.id,pe),onSuccess:async()=>{n?.id&&await F(n.id),await o.invalidateQueries({queryKey:["inventory-spools"]}),l(s("inventory.spoolUpdated"),"success"),e()},onError:pe=>{l(pe.message,"error")}}),L=pt({mutationFn:()=>be.updateSpool(n.id,{tag_uid:null}),onSuccess:async()=>{await o.invalidateQueries({queryKey:["inventory-spools"]}),l(s("inventory.tagDeleted","Tag removed"),"success"),e()},onError:pe=>{l(pe.message,"error")}}),F=async pe=>{if(le.size===0){try{await be.saveSpoolKProfiles(pe,[])}catch{}return}const de=[];for(const Ne of le){const[Se,Le,qe]=Ne.split(":"),Ee=parseInt(Se),Te=parseInt(Le),Ae=qe==="null"?0:parseInt(qe),Be=Z.find(je=>je.printer.id===Ee);if(Be){const je=Be.calibrations.find(Xe=>Xe.cali_idx===Te);je&&de.push({printer_id:Ee,extruder:Ae,nozzle_diameter:je.nozzle_diameter||"0.4",k_value:je.k_value,name:je.name||null,cali_idx:je.cali_idx,setting_id:je.setting_id||null})}}if(de.length>0)try{await be.saveSpoolKProfiles(pe,de)}catch(Ne){console.error("Failed to save K-profiles:",Ne)}};if(w.useEffect(()=>{if(!t)return;const pe=de=>{de.key==="Escape"&&e()};return document.addEventListener("keydown",pe),()=>document.removeEventListener("keydown",pe)},[t,e]),!t)return null;const te=()=>{const pe=Att(u,g);if(!pe.isValid){p(pe.errors),(pe.errors.slicer_filament||pe.errors.material||pe.errors.brand||pe.errors.subtype)&&y("filament");return}const de=W?.displayName||H||null,Ne={material:u.material,subtype:u.subtype||null,brand:u.brand||null,color_name:u.color_name||null,rgba:u.rgba||null,label_weight:u.label_weight,core_weight:u.core_weight,core_weight_catalog_id:u.core_weight_catalog_id,slicer_filament:u.slicer_filament||null,slicer_filament_name:de,nozzle_temp_min:null,nozzle_temp_max:null,note:u.note||null,cost_per_kg:u.cost_per_kg};(!c||v)&&(Ne.weight_used=u.weight_used),c?ae.mutate(Ne):N>1?ye.mutate({data:Ne,qty:N}):fe.mutate(Ne)},ve=fe.isPending||ye.isPending||ae.isPending||L.isPending;return i.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[i.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),i.jsxs("div",{className:"relative w-full max-w-xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:s(c?"inventory.editSpool":"inventory.addSpool")}),i.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:i.jsx(Ht,{className:"w-5 h-5"})})]}),!c&&i.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-bambu-dark-tertiary flex-shrink-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(kc,{className:"w-4 h-4 text-amber-400"}),i.jsx("span",{className:"text-sm text-white",children:s("inventory.quickAdd")})]}),i.jsx("button",{type:"button",onClick:()=>{_(!g),g||y("filament")},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${g?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:i.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${g?"translate-x-4":"translate-x-0.5"}`})})]}),i.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary flex-shrink-0",children:[i.jsxs("button",{onClick:()=>y("filament"),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${f==="filament"?"text-bambu-green border-b-2 border-bambu-green":"text-bambu-gray hover:text-white"}`,children:[i.jsx(fw,{className:"w-4 h-4"}),s("inventory.filamentInfoTab")]}),!g&&i.jsxs("button",{onClick:()=>y("pa-profile"),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${f==="pa-profile"?"text-bambu-green border-b-2 border-bambu-green":"text-bambu-gray hover:text-white"}`,children:[i.jsx(yhe,{className:"w-4 h-4"}),s("inventory.paProfileTab"),j>0&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green",children:j})]})]}),i.jsx("div",{className:"p-4 overflow-y-auto flex-1",style:{scrollbarGutter:"stable"},children:f==="filament"?i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3",children:s("inventory.filamentInfo")}),i.jsx(Utt,{formData:u,updateField:re,cloudAuthenticated:C,loadingCloudPresets:k,presetInputValue:H,setPresetInputValue:z,selectedPresetOption:W,filamentOptions:E,availableBrands:V,availableMaterials:J,quickAdd:g,quantity:N,onQuantityChange:T,errors:m})]}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3",children:s("inventory.color")}),i.jsx(Btt,{formData:u,updateField:re,recentColors:he,onColorUsed:ue,catalogColors:X})]}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3",children:s("inventory.additional")}),i.jsx($tt,{formData:u,updateField:re,spoolCatalog:G,currencySymbol:a})]}),c&&n&&i.jsx("div",{children:i.jsx(Wtt,{spoolId:n.id})})]}):i.jsx(qtt,{formData:u,updateField:re,printersWithCalibrations:Z,selectedProfiles:le,setSelectedProfiles:xe,expandedPrinters:Pe,setExpandedPrinters:q})}),i.jsxs("div",{className:"flex gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0",children:[c&&i.jsxs(Oe,{variant:"secondary",onClick:()=>L.mutate(),disabled:ve||!n?.tag_uid,className:"mr-auto",children:[i.jsx(Dd,{className:"w-4 h-4"}),s("inventory.deleteTag","Delete Tag")]}),i.jsxs("div",{className:"flex gap-2 ml-auto",children:[i.jsx(Oe,{variant:"secondary",onClick:e,children:s("common.cancel")}),i.jsx(Oe,{onClick:te,disabled:ve,children:ve?i.jsxs(i.Fragment,{children:[i.jsx(ht,{className:"w-4 h-4 animate-spin"}),s("common.saving")]}):i.jsxs(i.Fragment,{children:[i.jsx(ts,{className:"w-4 h-4"}),s(c?"common.save":"inventory.addSpool")]})})]})]})]})]})}function Ytt({isOpen:t,onClose:e,columns:n,defaultColumns:r,onSave:a}){const{t:s}=Ft(),[o,l]=w.useState(n),[c,u]=w.useState(null),d=w.useRef(null);if(w.useEffect(()=>{t&&l(n.map(T=>({...T})))},[t,n]),w.useEffect(()=>{if(!t)return;const T=C=>{C.key==="Escape"&&e()};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[t,e]),!t)return null;const m=T=>{l(C=>C.map((A,k)=>k===T?{...A,visible:!A.visible}:A))},p=(T,C)=>{C<0||C>=o.length||l(A=>{const k=[...A],[R]=k.splice(T,1);return k.splice(C,0,R),k})},f=(T,C)=>{d.current=C,u(C),T.dataTransfer.effectAllowed="move"},y=(T,C)=>{T.preventDefault(),T.dataTransfer.dropEffect="move";const A=d.current;A!==null&&A!==C&&(p(A,C),d.current=C,u(C))},v=T=>{T.preventDefault()},x=()=>{d.current=null,u(null)},g=()=>{l(r.map(T=>({...T})))},_=()=>{a(o),e()},N=o.filter(T=>T.visible).length;return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:e,children:i.jsx(Mt,{className:"w-full max-w-md max-h-[80vh] flex flex-col",onClick:T=>T.stopPropagation(),children:i.jsxs(Dt,{className:"p-6 flex flex-col min-h-0",children:[i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:s("inventory.configureColumns")}),i.jsxs("p",{className:"text-sm text-bambu-gray mb-4",children:[s("inventory.configureColumnsDesc"),i.jsxs("span",{className:"ml-2 text-bambu-gray/60",children:["(",N," ",s("inventory.of")," ",o.length," ",s("inventory.visible"),")"]})]}),i.jsx("div",{className:"space-y-1 overflow-y-auto flex-1 min-h-0 pr-1",children:o.map((T,C)=>i.jsxs("div",{className:`flex items-center gap-2 p-2 rounded-lg border transition-colors ${c===C?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark-tertiary/50"} ${T.visible?"":"opacity-50"}`,draggable:!0,onDragStart:A=>f(A,C),onDragOver:A=>y(A,C),onDrop:v,onDragEnd:x,children:[i.jsx("div",{className:"cursor-grab text-bambu-gray/50 hover:text-bambu-gray",children:i.jsx(bh,{className:"w-4 h-4"})}),i.jsx("span",{className:"flex-1 font-medium text-sm text-white",children:T.label}),i.jsxs("div",{className:"flex items-center gap-0.5",children:[i.jsx("button",{onClick:()=>p(C,C-1),disabled:C===0,className:"p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed",title:s("inventory.moveUp"),children:i.jsx(Il,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>p(C,C+1),disabled:C===o.length-1,className:"p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed",title:s("inventory.moveDown"),children:i.jsx(Ln,{className:"w-4 h-4"})})]}),i.jsx("button",{onClick:()=>m(C),className:`p-1.5 rounded transition-colors ${T.visible?"text-bambu-green hover:bg-bambu-green/10":"text-bambu-gray/50 hover:bg-bambu-dark-secondary"}`,title:T.visible?s("inventory.hideColumn"):s("inventory.showColumn"),children:T.visible?i.jsx(_c,{className:"w-4 h-4"}):i.jsx(mw,{className:"w-4 h-4"})})]},T.id))}),i.jsxs("div",{className:"flex items-center gap-3 mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs(Oe,{variant:"secondary",onClick:g,className:"mr-auto",children:[i.jsx(bo,{className:"w-4 h-4"}),s("inventory.reset")]}),i.jsx(Oe,{variant:"secondary",onClick:e,children:s("inventory.cancel")}),i.jsx(Oe,{onClick:_,children:s("inventory.applyChanges")})]})]})})})}function RY(t){return`${t.material}|${t.subtype||""}|${t.brand||""}|${t.color_name||""}|${t.rgba||""}|${t.label_weight}`}const Goe="bambuddy-inventory-columns",vN=[{id:"id",label:"#",visible:!0},{id:"added_time",label:"Added",visible:!0},{id:"encode_time",label:"Encoded",visible:!1},{id:"last_used_time",label:"Last Used",visible:!1},{id:"rgba",label:"Color",visible:!0},{id:"material",label:"Material",visible:!0},{id:"subtype",label:"Subtype",visible:!0},{id:"color_name",label:"Color Name",visible:!1},{id:"brand",label:"Brand",visible:!0},{id:"slicer_filament",label:"Slicer Filament",visible:!1},{id:"location",label:"Location",visible:!0},{id:"label_weight",label:"Label",visible:!0},{id:"net",label:"Net",visible:!0},{id:"gross",label:"Gross",visible:!1},{id:"added_full",label:"Full",visible:!1},{id:"used",label:"Used",visible:!1},{id:"printed_total",label:"Printed Total",visible:!1},{id:"printed_since_weight",label:"Printed Since Weight",visible:!1},{id:"note",label:"Note",visible:!1},{id:"pa_k",label:"PA(K)",visible:!0},{id:"tag_id",label:"Tag ID",visible:!1},{id:"data_origin",label:"Data Origin",visible:!1},{id:"tag_type",label:"Linked Tag Type",visible:!1},{id:"stock",label:"Stock",visible:!1},{id:"remaining",label:"Remaining",visible:!0},{id:"cost_per_kg",label:"Cost/kg",visible:!1},{id:"weight_check",label:"Weight Check",visible:!1}];function Xtt(){try{const t=localStorage.getItem(Goe);if(t){const e=JSON.parse(t),n=new Set(vN.map(o=>o.id)),r=new Set(e.map(o=>o.id)),a=e.filter(o=>n.has(o.id)),s=vN.filter(o=>!r.has(o.id));return[...a,...s]}}catch{}return vN.map(t=>({...t}))}function Qtt(t){try{localStorage.setItem(Goe,JSON.stringify(t))}catch{}}function iu(t,e=!1){return e&&t>=1e3?`${(t/1e3).toFixed(1)}kg`:`${Math.round(t)}g`}const Ztt={PLA:"bg-green-500/20 text-green-400",ABS:"bg-red-500/20 text-red-400",PETG:"bg-blue-500/20 text-blue-400",TPU:"bg-purple-500/20 text-purple-400",ASA:"bg-orange-500/20 text-orange-400",PA:"bg-yellow-500/20 text-yellow-400",PC:"bg-cyan-500/20 text-cyan-400",PET:"bg-sky-500/20 text-sky-400"};function WD(t,e="system"){if(!t)return"-";const n=Jn(t);return n?S3(n,e):"-"}const Jtt={id:()=>"#",added_time:()=>"Added",encode_time:()=>"Encoded",last_used_time:()=>"Last Used",rgba:t=>t("inventory.color"),material:t=>t("inventory.material"),subtype:t=>t("inventory.subtype"),color_name:t=>t("inventory.colorName"),brand:t=>t("inventory.brand"),slicer_filament:t=>t("inventory.slicerFilament"),location:()=>"Location",label_weight:t=>t("inventory.labelWeight"),net:t=>t("inventory.net"),gross:()=>"Gross",added_full:()=>"Full",used:t=>t("inventory.weightUsed"),printed_total:()=>"Printed Total",printed_since_weight:()=>"Printed Since Weight",note:t=>t("inventory.note"),pa_k:()=>"PA(K)",tag_id:()=>"Tag ID",data_origin:()=>"Data Origin",tag_type:()=>"Linked Tag Type",stock:t=>t("inventory.stock"),remaining:t=>t("inventory.remaining"),cost_per_kg:t=>t("inventory.costPerKg"),weight_check:t=>t("inventory.weightCheck")},vL={id:({spool:t})=>i.jsx("span",{className:"text-sm font-medium text-white",children:t.id}),added_time:({spool:t,dateFormat:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:WD(t.created_at,e)}),encode_time:({spool:t,dateFormat:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:WD(t.encode_time,e)}),last_used_time:({spool:t,dateFormat:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.last_used?WD(t.last_used,e):"Never"}),rgba:({spool:t})=>i.jsx("div",{className:"flex items-center justify-center",children:i.jsx("span",{className:"w-5 h-5 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:t.rgba?`#${t.rgba.substring(0,6)}`:"#808080"},title:t.rgba?`#${t.rgba.substring(0,6)}`:void 0})}),material:({spool:t})=>i.jsx("span",{className:"text-sm text-white",children:t.material}),subtype:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.subtype||"-"}),color_name:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:T4(t.color_name,t.rgba)||"-"}),brand:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.brand||"-"}),slicer_filament:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",title:t.slicer_filament||void 0,children:t.slicer_filament_name||t.slicer_filament||"-"}),location:({spool:t,assignmentMap:e})=>{const n=e[t.id];if(!n)return i.jsx("span",{className:"text-sm text-bambu-gray",children:"-"});const r=n.printer_name||`Printer ${n.printer_id}`,a=n.ams_id===254||n.ams_id===255,s=!a&&n.ams_id>=128,o=P4(n.ams_id,n.tray_id,s,a);return i.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-purple-500/20 text-purple-400",children:[r," ",o,n.ams_label?` (${n.ams_label})`:""]})},label_weight:({spool:t})=>i.jsx("span",{className:"text-sm text-white",children:iu(t.label_weight)}),net:({remaining:t})=>i.jsx("span",{className:"text-sm text-white",children:iu(t)}),gross:({spool:t,remaining:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:iu(e+t.core_weight)}),added_full:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.added_full==null?"-":t.added_full?"Yes":"No"}),used:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.weight_used>0?iu(t.weight_used):"-"}),printed_total:()=>i.jsx("span",{className:"text-sm text-bambu-gray/50",children:"-"}),printed_since_weight:()=>i.jsx("span",{className:"text-sm text-bambu-gray/50",children:"-"}),note:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray max-w-[150px] truncate block",title:t.note||void 0,children:t.note||"-"}),pa_k:({spool:t})=>(t.k_profiles?.length??0)===0?i.jsx("span",{className:"text-sm text-bambu-gray",children:"-"}):i.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-bambu-green/20 text-bambu-green",children:"K"}),tag_id:({spool:t})=>{const e=t.tag_uid||t.tray_uuid;return e?i.jsx("span",{className:"text-sm text-bambu-gray font-mono",title:e,children:e.length>12?`${e.slice(0,6)}...${e.slice(-4)}`:e}):i.jsx("span",{className:"text-sm text-bambu-gray/50",children:"-"})},data_origin:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.data_origin||"-"}),tag_type:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.tag_type||"-"}),stock:({spool:t,t:e})=>t.slicer_filament?i.jsx("span",{className:"text-sm text-bambu-gray",children:"-"}):i.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-amber-500/20 text-amber-400",children:e("inventory.stock")}),remaining:({remaining:t,pct:e})=>i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("div",{className:"flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden",children:i.jsx("div",{className:`h-full rounded-full ${e>50?"bg-bambu-green":e>20?"bg-yellow-500":"bg-red-500"}`,style:{width:`${Math.min(e,100)}%`}})}),i.jsxs("span",{className:"text-xs text-bambu-gray min-w-[40px] text-right",children:[Math.round(t),"g"]})]}),cost_per_kg:({spool:t,currencySymbol:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.cost_per_kg!=null?`${e}${t.cost_per_kg.toFixed(2)}`:"-"}),weight_check:({spool:t,onSyncWeight:e})=>{const n=t.last_scale_weight;if(n==null)return i.jsx("span",{className:"text-sm text-bambu-gray/50",title:"No scale measurement",children:"-"});const r=t.core_weight||0,a=Math.max(0,t.label_weight-t.weight_used)+r;let s,o;n0?`+${Math.round(s)}`:`${Math.round(s)}`,c=o?`Scale: ${Math.round(n)}g Calculated: ${Math.round(a)}g Difference: ${l}g (within tolerance)`:`Scale: ${Math.round(n)}g Calculated: ${Math.round(a)}g diff --git a/static/assets/index-Dq3gZWq6.css b/static/assets/index-Dq3gZWq6.css deleted file mode 100644 index 8abccdf18..000000000 --- a/static/assets/index-Dq3gZWq6.css +++ /dev/null @@ -1 +0,0 @@ -@import"https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap";@layer properties,theme,base,components,utilities;@layer theme{:root,:host{--font-sans:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--font-mono:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;--color-red-50:oklch(97.1% .013 17.38);--color-red-100:oklch(93.6% .032 17.717);--color-red-200:oklch(88.5% .062 18.334);--color-red-300:oklch(80.8% .114 19.571);--color-red-400:oklch(70.4% .191 22.216);--color-red-500:oklch(63.7% .237 25.331);--color-red-600:oklch(57.7% .245 27.325);--color-red-700:oklch(50.5% .213 27.518);--color-red-800:oklch(44.4% .177 26.899);--color-red-900:oklch(39.6% .141 25.723);--color-red-950:oklch(25.8% .092 26.042);--color-orange-200:oklch(90.1% .076 70.697);--color-orange-300:oklch(83.7% .128 66.29);--color-orange-400:oklch(75% .183 55.934);--color-orange-500:oklch(70.5% .213 47.604);--color-orange-600:oklch(64.6% .222 41.116);--color-orange-700:oklch(55.3% .195 38.402);--color-amber-50:oklch(98.7% .022 95.277);--color-amber-200:oklch(92.4% .12 95.746);--color-amber-300:oklch(87.9% .169 91.605);--color-amber-400:oklch(82.8% .189 84.429);--color-amber-500:oklch(76.9% .188 70.08);--color-amber-600:oklch(66.6% .179 58.318);--color-amber-700:oklch(55.5% .163 48.998);--color-amber-800:oklch(47.3% .137 46.201);--color-amber-900:oklch(41.4% .112 45.904);--color-yellow-200:oklch(94.5% .129 101.54);--color-yellow-300:oklch(90.5% .182 98.111);--color-yellow-400:oklch(85.2% .199 91.936);--color-yellow-500:oklch(79.5% .184 86.047);--color-yellow-600:oklch(68.1% .162 75.834);--color-yellow-700:oklch(55.4% .135 66.442);--color-lime-500:oklch(76.8% .233 130.85);--color-green-100:oklch(96.2% .044 156.743);--color-green-200:oklch(92.5% .084 155.995);--color-green-300:oklch(87.1% .15 154.449);--color-green-400:oklch(79.2% .209 151.711);--color-green-500:oklch(72.3% .219 149.579);--color-green-600:oklch(62.7% .194 149.214);--color-green-700:oklch(52.7% .154 150.069);--color-green-800:oklch(44.8% .119 151.328);--color-green-900:oklch(39.3% .095 152.535);--color-emerald-300:oklch(84.5% .143 164.978);--color-emerald-400:oklch(76.5% .177 163.223);--color-emerald-500:oklch(69.6% .17 162.48);--color-emerald-600:oklch(59.6% .145 163.225);--color-emerald-700:oklch(50.8% .118 165.612);--color-teal-400:oklch(77.7% .152 181.912);--color-teal-500:oklch(70.4% .14 182.503);--color-cyan-300:oklch(86.5% .127 207.078);--color-cyan-400:oklch(78.9% .154 211.53);--color-cyan-500:oklch(71.5% .143 215.221);--color-cyan-600:oklch(60.9% .126 221.723);--color-sky-400:oklch(74.6% .16 232.661);--color-sky-500:oklch(68.5% .169 237.323);--color-blue-50:oklch(97% .014 254.604);--color-blue-100:oklch(93.2% .032 255.585);--color-blue-200:oklch(88.2% .059 254.128);--color-blue-300:oklch(80.9% .105 251.813);--color-blue-400:oklch(70.7% .165 254.624);--color-blue-500:oklch(62.3% .214 259.815);--color-blue-600:oklch(54.6% .245 262.881);--color-blue-700:oklch(48.8% .243 264.376);--color-blue-900:oklch(37.9% .146 265.522);--color-indigo-400:oklch(67.3% .182 276.935);--color-indigo-500:oklch(58.5% .233 277.117);--color-violet-500:oklch(60.6% .25 292.717);--color-purple-300:oklch(82.7% .119 306.383);--color-purple-400:oklch(71.4% .203 305.504);--color-purple-500:oklch(62.7% .265 303.9);--color-purple-600:oklch(55.8% .288 302.321);--color-purple-700:oklch(49.6% .265 301.924);--color-fuchsia-500:oklch(66.7% .295 322.15);--color-rose-300:oklch(81% .117 11.638);--color-rose-400:oklch(71.2% .194 13.428);--color-rose-500:oklch(64.5% .246 16.439);--color-rose-600:oklch(58.6% .253 17.585);--color-slate-300:oklch(86.9% .022 252.894);--color-slate-500:oklch(55.4% .046 257.417);--color-gray-50:oklch(98.5% .002 247.839);--color-gray-100:oklch(96.7% .003 264.542);--color-gray-200:oklch(92.8% .006 264.531);--color-gray-300:oklch(87.2% .01 258.338);--color-gray-400:oklch(70.7% .022 261.325);--color-gray-500:oklch(55.1% .027 264.364);--color-gray-600:oklch(44.6% .03 256.802);--color-gray-700:oklch(37.3% .034 259.733);--color-gray-800:oklch(27.8% .033 256.848);--color-gray-900:oklch(21% .034 264.665);--color-zinc-100:oklch(96.7% .001 286.375);--color-zinc-200:oklch(92% .004 286.32);--color-zinc-300:oklch(87.1% .006 286.286);--color-zinc-400:oklch(70.5% .015 286.067);--color-zinc-500:oklch(55.2% .016 285.938);--color-zinc-600:oklch(44.2% .017 285.786);--color-zinc-700:oklch(37% .013 285.805);--color-zinc-800:oklch(27.4% .006 286.033);--color-zinc-900:oklch(21% .006 285.885);--color-black:#000;--color-white:#fff;--spacing:.25rem;--container-xs:20rem;--container-sm:24rem;--container-md:28rem;--container-lg:32rem;--container-xl:36rem;--container-2xl:42rem;--container-3xl:48rem;--container-4xl:56rem;--container-5xl:64rem;--container-6xl:72rem;--text-xs:.75rem;--text-xs--line-height:calc(1/.75);--text-sm:.875rem;--text-sm--line-height:calc(1.25/.875);--text-base:1rem;--text-base--line-height: 1.5 ;--text-lg:1.125rem;--text-lg--line-height:calc(1.75/1.125);--text-xl:1.25rem;--text-xl--line-height:calc(1.75/1.25);--text-2xl:1.5rem;--text-2xl--line-height:calc(2/1.5);--text-3xl:1.875rem;--text-3xl--line-height: 1.2 ;--text-5xl:3rem;--text-5xl--line-height:1;--font-weight-light:300;--font-weight-normal:400;--font-weight-medium:500;--font-weight-semibold:600;--font-weight-bold:700;--tracking-wide:.025em;--tracking-wider:.05em;--tracking-widest:.1em;--leading-tight:1.25;--radius-sm:.25rem;--radius-md:.375rem;--radius-lg:.5rem;--radius-xl:.75rem;--radius-2xl:1rem;--drop-shadow-md:0 3px 3px #0000001f;--drop-shadow-lg:0 4px 4px #00000026;--ease-out:cubic-bezier(0,0,.2,1);--ease-in-out:cubic-bezier(.4,0,.2,1);--animate-spin:spin 1s linear infinite;--animate-ping:ping 1s cubic-bezier(0,0,.2,1)infinite;--animate-pulse:pulse 2s cubic-bezier(.4,0,.6,1)infinite;--blur-sm:8px;--blur-2xl:40px;--aspect-video:16/9;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4,0,.2,1);--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono);--color-bambu-green:var(--accent);--color-bambu-green-light:var(--accent-light);--color-bambu-green-dark:var(--accent-dark);--color-status-ok:var(--status-ok);--color-status-error:var(--status-error);--color-status-warning:var(--status-warning);--color-bambu-dark:var(--bg-primary);--color-bambu-dark-secondary:var(--bg-secondary);--color-bambu-dark-tertiary:var(--bg-tertiary);--color-bambu-gray:var(--text-muted);--color-bambu-gray-light:var(--text-secondary);--color-bambu-gray-dark:var(--text-tertiary)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab,red,red)){::placeholder{color:color-mix(in oklab,currentcolor 50%,transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer utilities{.pointer-events-none{pointer-events:none}.collapse{visibility:collapse}.visible{visibility:visible}.sr-only{clip-path:inset(50%);white-space:nowrap;border-width:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.static{position:static}.sticky{position:sticky}.-inset-4{inset:calc(var(--spacing)*-4)}.inset-0{inset:calc(var(--spacing)*0)}.inset-2{inset:calc(var(--spacing)*2)}.inset-x-0{inset-inline:calc(var(--spacing)*0)}.inset-y-0{inset-block:calc(var(--spacing)*0)}.-top-0\.5{top:calc(var(--spacing)*-.5)}.-top-1{top:calc(var(--spacing)*-1)}.-top-1\.5{top:calc(var(--spacing)*-1.5)}.top-0{top:calc(var(--spacing)*0)}.top-0\.5{top:calc(var(--spacing)*.5)}.top-1{top:calc(var(--spacing)*1)}.top-1\.5{top:calc(var(--spacing)*1.5)}.top-1\/2{top:50%}.top-2{top:calc(var(--spacing)*2)}.top-2\.5{top:calc(var(--spacing)*2.5)}.top-3{top:calc(var(--spacing)*3)}.top-4{top:calc(var(--spacing)*4)}.top-8{top:calc(var(--spacing)*8)}.top-\[2px\]{top:2px}.top-\[3px\]{top:3px}.top-\[52px\]{top:52px}.top-full{top:100%}.-right-0\.5{right:calc(var(--spacing)*-.5)}.-right-1{right:calc(var(--spacing)*-1)}.-right-1\.5{right:calc(var(--spacing)*-1.5)}.-right-2{right:calc(var(--spacing)*-2)}.right-0{right:calc(var(--spacing)*0)}.right-1{right:calc(var(--spacing)*1)}.right-1\.5{right:calc(var(--spacing)*1.5)}.right-2{right:calc(var(--spacing)*2)}.right-3{right:calc(var(--spacing)*3)}.right-4{right:calc(var(--spacing)*4)}.right-6{right:calc(var(--spacing)*6)}.right-12{right:calc(var(--spacing)*12)}.right-20{right:calc(var(--spacing)*20)}.right-\[5\.5rem\]{right:5.5rem}.right-full{right:100%}.-bottom-0\.5{bottom:calc(var(--spacing)*-.5)}.-bottom-1{bottom:calc(var(--spacing)*-1)}.-bottom-2{bottom:calc(var(--spacing)*-2)}.-bottom-7{bottom:calc(var(--spacing)*-7)}.bottom-0{bottom:calc(var(--spacing)*0)}.bottom-1{bottom:calc(var(--spacing)*1)}.bottom-2{bottom:calc(var(--spacing)*2)}.bottom-3{bottom:calc(var(--spacing)*3)}.bottom-4{bottom:calc(var(--spacing)*4)}.bottom-6{bottom:calc(var(--spacing)*6)}.bottom-8{bottom:calc(var(--spacing)*8)}.bottom-20{bottom:calc(var(--spacing)*20)}.bottom-full{bottom:100%}.-left-2{left:calc(var(--spacing)*-2)}.left-0{left:calc(var(--spacing)*0)}.left-0\.5{left:calc(var(--spacing)*.5)}.left-1{left:calc(var(--spacing)*1)}.left-1\/2{left:50%}.left-2{left:calc(var(--spacing)*2)}.left-2\.5{left:calc(var(--spacing)*2.5)}.left-3{left:calc(var(--spacing)*3)}.left-4{left:calc(var(--spacing)*4)}.left-10{left:calc(var(--spacing)*10)}.left-12{left:calc(var(--spacing)*12)}.left-\[2px\]{left:2px}.left-\[3px\]{left:3px}.left-full{left:100%}.z-0{z-index:0}.z-10{z-index:10}.z-20{z-index:20}.z-30{z-index:30}.z-40{z-index:40}.z-50{z-index:50}.z-60,.z-\[60\]{z-index:60}.z-\[100\]{z-index:100}.z-\[101\]{z-index:101}.z-\[9998\]{z-index:9998}.z-\[9999\]{z-index:9999}.col-span-1{grid-column:span 1/span 1}.col-span-2{grid-column:span 2/span 2}.col-span-3{grid-column:span 3/span 3}.col-span-4{grid-column:span 4/span 4}.col-span-full{grid-column:1/-1}.container{width:100%}@media(min-width:40rem){.container{max-width:40rem}}@media(min-width:48rem){.container{max-width:48rem}}@media(min-width:64rem){.container{max-width:64rem}}@media(min-width:80rem){.container{max-width:80rem}}@media(min-width:96rem){.container{max-width:96rem}}.-m-4{margin:calc(var(--spacing)*-4)}.-mx-4{margin-inline:calc(var(--spacing)*-4)}.mx-1{margin-inline:calc(var(--spacing)*1)}.mx-1\.5{margin-inline:calc(var(--spacing)*1.5)}.mx-2{margin-inline:calc(var(--spacing)*2)}.mx-4{margin-inline:calc(var(--spacing)*4)}.mx-5{margin-inline:calc(var(--spacing)*5)}.mx-auto{margin-inline:auto}.my-1{margin-block:calc(var(--spacing)*1)}.my-2{margin-block:calc(var(--spacing)*2)}.my-8{margin-block:calc(var(--spacing)*8)}.-mt-0\.5{margin-top:calc(var(--spacing)*-.5)}.-mt-2{margin-top:calc(var(--spacing)*-2)}.mt-0\.5{margin-top:calc(var(--spacing)*.5)}.mt-1{margin-top:calc(var(--spacing)*1)}.mt-1\.5{margin-top:calc(var(--spacing)*1.5)}.mt-2{margin-top:calc(var(--spacing)*2)}.mt-3{margin-top:calc(var(--spacing)*3)}.mt-4{margin-top:calc(var(--spacing)*4)}.mt-6{margin-top:calc(var(--spacing)*6)}.mt-8{margin-top:calc(var(--spacing)*8)}.mt-14{margin-top:calc(var(--spacing)*14)}.mt-auto{margin-top:auto}.mr-1{margin-right:calc(var(--spacing)*1)}.mr-1\.5{margin-right:calc(var(--spacing)*1.5)}.mr-2{margin-right:calc(var(--spacing)*2)}.mr-3{margin-right:calc(var(--spacing)*3)}.mr-4{margin-right:calc(var(--spacing)*4)}.mr-auto{margin-right:auto}.-mb-px{margin-bottom:-1px}.mb-0\.5{margin-bottom:calc(var(--spacing)*.5)}.mb-1{margin-bottom:calc(var(--spacing)*1)}.mb-1\.5{margin-bottom:calc(var(--spacing)*1.5)}.mb-2{margin-bottom:calc(var(--spacing)*2)}.mb-2\.5{margin-bottom:calc(var(--spacing)*2.5)}.mb-3{margin-bottom:calc(var(--spacing)*3)}.mb-4{margin-bottom:calc(var(--spacing)*4)}.mb-5{margin-bottom:calc(var(--spacing)*5)}.mb-6{margin-bottom:calc(var(--spacing)*6)}.mb-8{margin-bottom:calc(var(--spacing)*8)}.-ml-1{margin-left:calc(var(--spacing)*-1)}.-ml-2{margin-left:calc(var(--spacing)*-2)}.ml-0\.5{margin-left:calc(var(--spacing)*.5)}.ml-1{margin-left:calc(var(--spacing)*1)}.ml-1\.5{margin-left:calc(var(--spacing)*1.5)}.ml-2{margin-left:calc(var(--spacing)*2)}.ml-3{margin-left:calc(var(--spacing)*3)}.ml-4{margin-left:calc(var(--spacing)*4)}.ml-6{margin-left:calc(var(--spacing)*6)}.ml-7{margin-left:calc(var(--spacing)*7)}.ml-9{margin-left:calc(var(--spacing)*9)}.ml-14{margin-left:calc(var(--spacing)*14)}.ml-16{margin-left:calc(var(--spacing)*16)}.ml-64{margin-left:calc(var(--spacing)*64)}.ml-auto{margin-left:auto}.line-clamp-1{-webkit-line-clamp:1;-webkit-box-orient:vertical;display:-webkit-box;overflow:hidden}.block{display:block}.flex{display:flex}.grid{display:grid}.hidden{display:none}.inline{display:inline}.inline-block{display:inline-block}.inline-flex{display:inline-flex}.table{display:table}.aspect-square{aspect-ratio:1}.aspect-video{aspect-ratio:var(--aspect-video)}.h-0{height:calc(var(--spacing)*0)}.h-0\.5{height:calc(var(--spacing)*.5)}.h-1{height:calc(var(--spacing)*1)}.h-1\.5{height:calc(var(--spacing)*1.5)}.h-2{height:calc(var(--spacing)*2)}.h-2\.5{height:calc(var(--spacing)*2.5)}.h-3{height:calc(var(--spacing)*3)}.h-3\.5{height:calc(var(--spacing)*3.5)}.h-4{height:calc(var(--spacing)*4)}.h-5{height:calc(var(--spacing)*5)}.h-6{height:calc(var(--spacing)*6)}.h-7{height:calc(var(--spacing)*7)}.h-8{height:calc(var(--spacing)*8)}.h-9{height:calc(var(--spacing)*9)}.h-10{height:calc(var(--spacing)*10)}.h-12{height:calc(var(--spacing)*12)}.h-14{height:calc(var(--spacing)*14)}.h-16{height:calc(var(--spacing)*16)}.h-20{height:calc(var(--spacing)*20)}.h-24{height:calc(var(--spacing)*24)}.h-32{height:calc(var(--spacing)*32)}.h-40{height:calc(var(--spacing)*40)}.h-48{height:calc(var(--spacing)*48)}.h-64{height:calc(var(--spacing)*64)}.h-80{height:calc(var(--spacing)*80)}.h-\[18px\]{height:18px}.h-\[38px\]{height:38px}.h-\[40px\]{height:40px}.h-\[48px\]{height:48px}.h-\[80vh\]{height:80vh}.h-\[160px\]{height:160px}.h-\[300px\]{height:300px}.h-\[calc\(100\%-40px\)\]{height:calc(100% - 40px)}.h-full{height:100%}.h-px{height:1px}.h-screen{height:100vh}.max-h-40{max-height:calc(var(--spacing)*40)}.max-h-48{max-height:calc(var(--spacing)*48)}.max-h-60{max-height:calc(var(--spacing)*60)}.max-h-64{max-height:calc(var(--spacing)*64)}.max-h-80{max-height:calc(var(--spacing)*80)}.max-h-96{max-height:calc(var(--spacing)*96)}.max-h-\[60vh\]{max-height:60vh}.max-h-\[80vh\]{max-height:80vh}.max-h-\[85vh\]{max-height:85vh}.max-h-\[90vh\]{max-height:90vh}.max-h-\[300px\]{max-height:300px}.max-h-\[400px\]{max-height:400px}.max-h-\[500px\]{max-height:500px}.max-h-\[600px\]{max-height:600px}.max-h-\[calc\(90vh-80px\)\]{max-height:calc(90vh - 80px)}.max-h-\[calc\(100vh-320px\)\]{max-height:calc(100vh - 320px)}.max-h-full{max-height:100%}.min-h-0{min-height:calc(var(--spacing)*0)}.min-h-\[36px\]{min-height:36px}.min-h-\[40px\]{min-height:40px}.min-h-\[44px\]{min-height:44px}.min-h-\[48px\]{min-height:48px}.min-h-\[80px\]{min-height:80px}.min-h-\[120px\]{min-height:120px}.min-h-\[300px\]{min-height:300px}.min-h-\[400px\]{min-height:400px}.min-h-\[calc\(100vh-64px\)\]{min-height:calc(100vh - 64px)}.min-h-screen{min-height:100vh}.w-0{width:calc(var(--spacing)*0)}.w-0\.5{width:calc(var(--spacing)*.5)}.w-1{width:calc(var(--spacing)*1)}.w-1\.5{width:calc(var(--spacing)*1.5)}.w-1\/2{width:50%}.w-1\/3{width:33.3333%}.w-2{width:calc(var(--spacing)*2)}.w-2\.5{width:calc(var(--spacing)*2.5)}.w-3{width:calc(var(--spacing)*3)}.w-3\.5{width:calc(var(--spacing)*3.5)}.w-4{width:calc(var(--spacing)*4)}.w-4\.5{width:calc(var(--spacing)*4.5)}.w-5{width:calc(var(--spacing)*5)}.w-5\/12{width:41.6667%}.w-6{width:calc(var(--spacing)*6)}.w-7{width:calc(var(--spacing)*7)}.w-7\/12{width:58.3333%}.w-8{width:calc(var(--spacing)*8)}.w-9{width:calc(var(--spacing)*9)}.w-10{width:calc(var(--spacing)*10)}.w-11{width:calc(var(--spacing)*11)}.w-12{width:calc(var(--spacing)*12)}.w-14{width:calc(var(--spacing)*14)}.w-16{width:calc(var(--spacing)*16)}.w-20{width:calc(var(--spacing)*20)}.w-24{width:calc(var(--spacing)*24)}.w-32{width:calc(var(--spacing)*32)}.w-36{width:calc(var(--spacing)*36)}.w-40{width:calc(var(--spacing)*40)}.w-44{width:calc(var(--spacing)*44)}.w-48{width:calc(var(--spacing)*48)}.w-52{width:calc(var(--spacing)*52)}.w-56{width:calc(var(--spacing)*56)}.w-64{width:calc(var(--spacing)*64)}.w-72{width:calc(var(--spacing)*72)}.w-96{width:calc(var(--spacing)*96)}.w-\[240px\]{width:240px}.w-\[340px\]{width:340px}.w-\[420px\]{width:420px}.w-\[560px\]{width:560px}.w-auto{width:auto}.w-fit{width:fit-content}.w-full{width:100%}.w-px{width:1px}.w-screen{width:100vw}.max-w-2xl{max-width:var(--container-2xl)}.max-w-3xl{max-width:var(--container-3xl)}.max-w-4xl{max-width:var(--container-4xl)}.max-w-5xl{max-width:var(--container-5xl)}.max-w-6xl{max-width:var(--container-6xl)}.max-w-32{max-width:calc(var(--spacing)*32)}.max-w-\[40\%\]{max-width:40%}.max-w-\[50\%\]{max-width:50%}.max-w-\[80px\]{max-width:80px}.max-w-\[90vw\]{max-width:90vw}.max-w-\[100px\]{max-width:100px}.max-w-\[120px\]{max-width:120px}.max-w-\[150px\]{max-width:150px}.max-w-\[160px\]{max-width:160px}.max-w-\[200px\]{max-width:200px}.max-w-\[280px\]{max-width:280px}.max-w-\[600px\]{max-width:600px}.max-w-full{max-width:100%}.max-w-lg{max-width:var(--container-lg)}.max-w-md{max-width:var(--container-md)}.max-w-none{max-width:none}.max-w-sm{max-width:var(--container-sm)}.max-w-xl{max-width:var(--container-xl)}.max-w-xs{max-width:var(--container-xs)}.min-w-0{min-width:calc(var(--spacing)*0)}.min-w-48{min-width:calc(var(--spacing)*48)}.min-w-\[16px\]{min-width:16px}.min-w-\[18px\]{min-width:18px}.min-w-\[32px\]{min-width:32px}.min-w-\[40px\]{min-width:40px}.min-w-\[48px\]{min-width:48px}.min-w-\[50px\]{min-width:50px}.min-w-\[80px\]{min-width:80px}.min-w-\[100px\]{min-width:100px}.min-w-\[120px\]{min-width:120px}.min-w-\[140px\]{min-width:140px}.min-w-\[150px\]{min-width:150px}.min-w-\[160px\]{min-width:160px}.min-w-\[180px\]{min-width:180px}.min-w-\[200px\]{min-width:200px}.min-w-full{min-width:100%}.flex-1{flex:1}.flex-\[2_1_190px\]{flex:2 190px}.flex-shrink{flex-shrink:1}.flex-shrink-0,.shrink-0{flex-shrink:0}.-translate-x-1\/2{--tw-translate-x: -50% ;translate:var(--tw-translate-x)var(--tw-translate-y)}.-translate-x-full{--tw-translate-x:-100%;translate:var(--tw-translate-x)var(--tw-translate-y)}.translate-x-0{--tw-translate-x:calc(var(--spacing)*0);translate:var(--tw-translate-x)var(--tw-translate-y)}.translate-x-0\.5{--tw-translate-x:calc(var(--spacing)*.5);translate:var(--tw-translate-x)var(--tw-translate-y)}.translate-x-1{--tw-translate-x:calc(var(--spacing)*1);translate:var(--tw-translate-x)var(--tw-translate-y)}.translate-x-3\.5{--tw-translate-x:calc(var(--spacing)*3.5);translate:var(--tw-translate-x)var(--tw-translate-y)}.translate-x-4{--tw-translate-x:calc(var(--spacing)*4);translate:var(--tw-translate-x)var(--tw-translate-y)}.translate-x-5{--tw-translate-x:calc(var(--spacing)*5);translate:var(--tw-translate-x)var(--tw-translate-y)}.translate-x-6{--tw-translate-x:calc(var(--spacing)*6);translate:var(--tw-translate-x)var(--tw-translate-y)}.-translate-y-1\/2{--tw-translate-y: -50% ;translate:var(--tw-translate-x)var(--tw-translate-y)}.scale-105{--tw-scale-x:105%;--tw-scale-y:105%;--tw-scale-z:105%;scale:var(--tw-scale-x)var(--tw-scale-y)}.scale-110{--tw-scale-x:110%;--tw-scale-y:110%;--tw-scale-z:110%;scale:var(--tw-scale-x)var(--tw-scale-y)}.scale-\[1\.02\]{scale:1.02}.-rotate-90{rotate:-90deg}.rotate-90{rotate:90deg}.rotate-180{rotate:180deg}.transform{transform:var(--tw-rotate-x,)var(--tw-rotate-y,)var(--tw-rotate-z,)var(--tw-skew-x,)var(--tw-skew-y,)}.animate-ping{animation:var(--animate-ping)}.animate-pulse{animation:var(--animate-pulse)}.animate-spin{animation:var(--animate-spin)}.cursor-col-resize{cursor:col-resize}.cursor-default{cursor:default}.cursor-ew-resize{cursor:ew-resize}.cursor-grab{cursor:grab}.cursor-not-allowed{cursor:not-allowed}.cursor-pointer{cursor:pointer}.cursor-row-resize{cursor:row-resize}.cursor-se-resize{cursor:se-resize}.touch-manipulation{touch-action:manipulation}.resize{resize:both}.resize-none{resize:none}.resize-y{resize:vertical}.list-inside{list-style-position:inside}.list-decimal{list-style-type:decimal}.list-disc{list-style-type:disc}.\[appearance\:textfield\]{appearance:textfield}.appearance-none{appearance:none}.grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}.grid-cols-5{grid-template-columns:repeat(5,minmax(0,1fr))}.grid-cols-7{grid-template-columns:repeat(7,minmax(0,1fr))}.grid-cols-12{grid-template-columns:repeat(12,minmax(0,1fr))}.grid-cols-\[auto_1fr_100px_100px_100px_80px\]{grid-template-columns:auto 1fr 100px 100px 100px 80px}.grid-cols-\[auto_1fr_120px_100px_100px_100px_80px\]{grid-template-columns:auto 1fr 120px 100px 100px 100px 80px}.flex-col{flex-direction:column}.flex-col-reverse{flex-direction:column-reverse}.flex-row{flex-direction:row}.flex-wrap{flex-wrap:wrap}.items-baseline{align-items:baseline}.items-center{align-items:center}.items-end{align-items:flex-end}.items-start{align-items:flex-start}.items-stretch{align-items:stretch}.justify-between{justify-content:space-between}.justify-center{justify-content:center}.justify-end{justify-content:flex-end}.gap-0{gap:calc(var(--spacing)*0)}.gap-0\.5{gap:calc(var(--spacing)*.5)}.gap-1{gap:calc(var(--spacing)*1)}.gap-1\.5{gap:calc(var(--spacing)*1.5)}.gap-2{gap:calc(var(--spacing)*2)}.gap-2\.5{gap:calc(var(--spacing)*2.5)}.gap-3{gap:calc(var(--spacing)*3)}.gap-4{gap:calc(var(--spacing)*4)}.gap-5{gap:calc(var(--spacing)*5)}.gap-6{gap:calc(var(--spacing)*6)}.gap-8{gap:calc(var(--spacing)*8)}.gap-\[3px\]{gap:3px}:where(.space-y-0>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*0)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*0)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-0\.5>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*.5)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*.5)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-1>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*1)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*1)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-1\.5>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*1.5)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*1.5)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-2>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*2)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*2)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-2\.5>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*2.5)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*2.5)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-3>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*3)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*3)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-4>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*4)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*4)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-5>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*5)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*5)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-6>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*6)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*6)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-8>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*8)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*8)*calc(1 - var(--tw-space-y-reverse)))}.gap-x-3{column-gap:calc(var(--spacing)*3)}.gap-x-4{column-gap:calc(var(--spacing)*4)}.gap-x-6{column-gap:calc(var(--spacing)*6)}.gap-y-1{row-gap:calc(var(--spacing)*1)}.gap-y-2{row-gap:calc(var(--spacing)*2)}.gap-y-3{row-gap:calc(var(--spacing)*3)}:where(.divide-y>:not(:last-child)){--tw-divide-y-reverse:0;border-bottom-style:var(--tw-border-style);border-top-style:var(--tw-border-style);border-top-width:calc(1px*var(--tw-divide-y-reverse));border-bottom-width:calc(1px*calc(1 - var(--tw-divide-y-reverse)))}:where(.divide-bambu-dark-tertiary>:not(:last-child)),:where(.divide-bambu-dark-tertiary\/30>:not(:last-child)){border-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){:where(.divide-bambu-dark-tertiary\/30>:not(:last-child)){border-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)30%,transparent)}}:where(.divide-bambu-gray\/20>:not(:last-child)){border-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){:where(.divide-bambu-gray\/20>:not(:last-child)){border-color:color-mix(in oklab,var(--color-bambu-gray)20%,transparent)}}.truncate{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.overflow-auto{overflow:auto}.overflow-hidden{overflow:hidden}.overflow-x-auto{overflow-x:auto}.overflow-y-auto{overflow-y:auto}.rounded{border-radius:.25rem}.rounded-2xl{border-radius:var(--radius-2xl)}.rounded-full{border-radius:3.40282e38px}.rounded-lg{border-radius:var(--radius-lg)}.rounded-md{border-radius:var(--radius-md)}.rounded-none{border-radius:0}.rounded-sm{border-radius:var(--radius-sm)}.rounded-xl{border-radius:var(--radius-xl)}.rounded-t-lg{border-top-left-radius:var(--radius-lg);border-top-right-radius:var(--radius-lg)}.rounded-t-xl{border-top-left-radius:var(--radius-xl);border-top-right-radius:var(--radius-xl)}.\!rounded-l-none{border-top-left-radius:0!important;border-bottom-left-radius:0!important}.rounded-l{border-top-left-radius:.25rem;border-bottom-left-radius:.25rem}.rounded-l-lg{border-top-left-radius:var(--radius-lg);border-bottom-left-radius:var(--radius-lg)}.rounded-tl{border-top-left-radius:.25rem}.\!rounded-r-none{border-top-right-radius:0!important;border-bottom-right-radius:0!important}.rounded-r{border-top-right-radius:.25rem;border-bottom-right-radius:.25rem}.rounded-r-lg{border-top-right-radius:var(--radius-lg);border-bottom-right-radius:var(--radius-lg)}.rounded-b-lg{border-bottom-right-radius:var(--radius-lg);border-bottom-left-radius:var(--radius-lg)}.border{border-style:var(--tw-border-style);border-width:1px}.border-0{border-style:var(--tw-border-style);border-width:0}.border-2{border-style:var(--tw-border-style);border-width:2px}.border-4{border-style:var(--tw-border-style);border-width:4px}.border-t{border-top-style:var(--tw-border-style);border-top-width:1px}.border-t-2{border-top-style:var(--tw-border-style);border-top-width:2px}.border-t-\[5px\]{border-top-style:var(--tw-border-style);border-top-width:5px}.border-t-\[6px\]{border-top-style:var(--tw-border-style);border-top-width:6px}.\!border-r-0{border-right-style:var(--tw-border-style)!important;border-right-width:0!important}.border-r{border-right-style:var(--tw-border-style);border-right-width:1px}.border-r-\[5px\]{border-right-style:var(--tw-border-style);border-right-width:5px}.border-r-\[6px\]{border-right-style:var(--tw-border-style);border-right-width:6px}.border-b{border-bottom-style:var(--tw-border-style);border-bottom-width:1px}.border-b-2{border-bottom-style:var(--tw-border-style);border-bottom-width:2px}.border-b-\[6px\]{border-bottom-style:var(--tw-border-style);border-bottom-width:6px}.border-l{border-left-style:var(--tw-border-style);border-left-width:1px}.border-l-2{border-left-style:var(--tw-border-style);border-left-width:2px}.border-l-4{border-left-style:var(--tw-border-style);border-left-width:4px}.border-l-\[5px\]{border-left-style:var(--tw-border-style);border-left-width:5px}.border-l-\[6px\]{border-left-style:var(--tw-border-style);border-left-width:6px}.border-dashed{--tw-border-style:dashed;border-style:dashed}.\!border-green-500{border-color:var(--color-green-500)!important}.\!border-yellow-500{border-color:var(--color-yellow-500)!important}.border-amber-200{border-color:var(--color-amber-200)}.border-amber-300{border-color:var(--color-amber-300)}.border-amber-500{border-color:var(--color-amber-500)}.border-amber-500\/20{border-color:#f99c0033}@supports (color:color-mix(in lab,red,red)){.border-amber-500\/20{border-color:color-mix(in oklab,var(--color-amber-500)20%,transparent)}}.border-amber-500\/30{border-color:#f99c004d}@supports (color:color-mix(in lab,red,red)){.border-amber-500\/30{border-color:color-mix(in oklab,var(--color-amber-500)30%,transparent)}}.border-bambu-dark-secondary{border-color:var(--color-bambu-dark-secondary)}.border-bambu-dark-tertiary,.border-bambu-dark-tertiary\/20{border-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.border-bambu-dark-tertiary\/20{border-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)20%,transparent)}}.border-bambu-dark-tertiary\/30{border-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.border-bambu-dark-tertiary\/30{border-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)30%,transparent)}}.border-bambu-dark-tertiary\/40{border-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.border-bambu-dark-tertiary\/40{border-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)40%,transparent)}}.border-bambu-dark-tertiary\/50{border-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.border-bambu-dark-tertiary\/50{border-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)50%,transparent)}}.border-bambu-gray,.border-bambu-gray\/20{border-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.border-bambu-gray\/20{border-color:color-mix(in oklab,var(--color-bambu-gray)20%,transparent)}}.border-bambu-gray\/30{border-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.border-bambu-gray\/30{border-color:color-mix(in oklab,var(--color-bambu-gray)30%,transparent)}}.border-bambu-gray\/50{border-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.border-bambu-gray\/50{border-color:color-mix(in oklab,var(--color-bambu-gray)50%,transparent)}}.border-bambu-green,.border-bambu-green\/20{border-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.border-bambu-green\/20{border-color:color-mix(in oklab,var(--color-bambu-green)20%,transparent)}}.border-bambu-green\/30{border-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.border-bambu-green\/30{border-color:color-mix(in oklab,var(--color-bambu-green)30%,transparent)}}.border-bambu-green\/40{border-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.border-bambu-green\/40{border-color:color-mix(in oklab,var(--color-bambu-green)40%,transparent)}}.border-bambu-green\/50{border-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.border-bambu-green\/50{border-color:color-mix(in oklab,var(--color-bambu-green)50%,transparent)}}.border-blue-400\/20{border-color:#54a2ff33}@supports (color:color-mix(in lab,red,red)){.border-blue-400\/20{border-color:color-mix(in oklab,var(--color-blue-400)20%,transparent)}}.border-blue-400\/50{border-color:#54a2ff80}@supports (color:color-mix(in lab,red,red)){.border-blue-400\/50{border-color:color-mix(in oklab,var(--color-blue-400)50%,transparent)}}.border-blue-500{border-color:var(--color-blue-500)}.border-blue-500\/20{border-color:#3080ff33}@supports (color:color-mix(in lab,red,red)){.border-blue-500\/20{border-color:color-mix(in oklab,var(--color-blue-500)20%,transparent)}}.border-blue-500\/30{border-color:#3080ff4d}@supports (color:color-mix(in lab,red,red)){.border-blue-500\/30{border-color:color-mix(in oklab,var(--color-blue-500)30%,transparent)}}.border-blue-500\/40{border-color:#3080ff66}@supports (color:color-mix(in lab,red,red)){.border-blue-500\/40{border-color:color-mix(in oklab,var(--color-blue-500)40%,transparent)}}.border-blue-500\/50{border-color:#3080ff80}@supports (color:color-mix(in lab,red,red)){.border-blue-500\/50{border-color:color-mix(in oklab,var(--color-blue-500)50%,transparent)}}.border-gray-200{border-color:var(--color-gray-200)}.border-gray-300{border-color:var(--color-gray-300)}.border-gray-400\/20{border-color:#99a1af33}@supports (color:color-mix(in lab,red,red)){.border-gray-400\/20{border-color:color-mix(in oklab,var(--color-gray-400)20%,transparent)}}.border-gray-500{border-color:var(--color-gray-500)}.border-gray-500\/20{border-color:#6a728233}@supports (color:color-mix(in lab,red,red)){.border-gray-500\/20{border-color:color-mix(in oklab,var(--color-gray-500)20%,transparent)}}.border-gray-700{border-color:var(--color-gray-700)}.border-green-300{border-color:var(--color-green-300)}.border-green-500{border-color:var(--color-green-500)}.border-green-500\/10{border-color:#00c7581a}@supports (color:color-mix(in lab,red,red)){.border-green-500\/10{border-color:color-mix(in oklab,var(--color-green-500)10%,transparent)}}.border-green-500\/20{border-color:#00c75833}@supports (color:color-mix(in lab,red,red)){.border-green-500\/20{border-color:color-mix(in oklab,var(--color-green-500)20%,transparent)}}.border-green-500\/30{border-color:#00c7584d}@supports (color:color-mix(in lab,red,red)){.border-green-500\/30{border-color:color-mix(in oklab,var(--color-green-500)30%,transparent)}}.border-green-500\/40{border-color:#00c75866}@supports (color:color-mix(in lab,red,red)){.border-green-500\/40{border-color:color-mix(in oklab,var(--color-green-500)40%,transparent)}}.border-green-500\/50{border-color:#00c75880}@supports (color:color-mix(in lab,red,red)){.border-green-500\/50{border-color:color-mix(in oklab,var(--color-green-500)50%,transparent)}}.border-green-800{border-color:var(--color-green-800)}.border-orange-400\/20{border-color:#ff8b1a33}@supports (color:color-mix(in lab,red,red)){.border-orange-400\/20{border-color:color-mix(in oklab,var(--color-orange-400)20%,transparent)}}.border-orange-400\/50{border-color:#ff8b1a80}@supports (color:color-mix(in lab,red,red)){.border-orange-400\/50{border-color:color-mix(in oklab,var(--color-orange-400)50%,transparent)}}.border-orange-500\/20{border-color:#fe6e0033}@supports (color:color-mix(in lab,red,red)){.border-orange-500\/20{border-color:color-mix(in oklab,var(--color-orange-500)20%,transparent)}}.border-orange-500\/30{border-color:#fe6e004d}@supports (color:color-mix(in lab,red,red)){.border-orange-500\/30{border-color:color-mix(in oklab,var(--color-orange-500)30%,transparent)}}.border-purple-400\/20{border-color:#c07eff33}@supports (color:color-mix(in lab,red,red)){.border-purple-400\/20{border-color:color-mix(in oklab,var(--color-purple-400)20%,transparent)}}.border-purple-500{border-color:var(--color-purple-500)}.border-purple-500\/20{border-color:#ac4bff33}@supports (color:color-mix(in lab,red,red)){.border-purple-500\/20{border-color:color-mix(in oklab,var(--color-purple-500)20%,transparent)}}.border-purple-500\/30{border-color:#ac4bff4d}@supports (color:color-mix(in lab,red,red)){.border-purple-500\/30{border-color:color-mix(in oklab,var(--color-purple-500)30%,transparent)}}.border-red-300{border-color:var(--color-red-300)}.border-red-500{border-color:var(--color-red-500)}.border-red-500\/20{border-color:#fb2c3633}@supports (color:color-mix(in lab,red,red)){.border-red-500\/20{border-color:color-mix(in oklab,var(--color-red-500)20%,transparent)}}.border-red-500\/30{border-color:#fb2c364d}@supports (color:color-mix(in lab,red,red)){.border-red-500\/30{border-color:color-mix(in oklab,var(--color-red-500)30%,transparent)}}.border-red-500\/40{border-color:#fb2c3666}@supports (color:color-mix(in lab,red,red)){.border-red-500\/40{border-color:color-mix(in oklab,var(--color-red-500)40%,transparent)}}.border-red-500\/50{border-color:#fb2c3680}@supports (color:color-mix(in lab,red,red)){.border-red-500\/50{border-color:color-mix(in oklab,var(--color-red-500)50%,transparent)}}.border-red-800{border-color:var(--color-red-800)}.border-red-800\/70{border-color:#9f0712b3}@supports (color:color-mix(in lab,red,red)){.border-red-800\/70{border-color:color-mix(in oklab,var(--color-red-800)70%,transparent)}}.border-slate-500{border-color:var(--color-slate-500)}.border-status-error\/20{border-color:var(--color-status-error)}@supports (color:color-mix(in lab,red,red)){.border-status-error\/20{border-color:color-mix(in oklab,var(--color-status-error)20%,transparent)}}.border-status-ok,.border-status-ok\/20{border-color:var(--color-status-ok)}@supports (color:color-mix(in lab,red,red)){.border-status-ok\/20{border-color:color-mix(in oklab,var(--color-status-ok)20%,transparent)}}.border-status-warning\/20{border-color:var(--color-status-warning)}@supports (color:color-mix(in lab,red,red)){.border-status-warning\/20{border-color:color-mix(in oklab,var(--color-status-warning)20%,transparent)}}.border-transparent{border-color:#0000}.border-white\/10{border-color:#ffffff1a}@supports (color:color-mix(in lab,red,red)){.border-white\/10{border-color:color-mix(in oklab,var(--color-white)10%,transparent)}}.border-white\/20{border-color:#fff3}@supports (color:color-mix(in lab,red,red)){.border-white\/20{border-color:color-mix(in oklab,var(--color-white)20%,transparent)}}.border-white\/30{border-color:#ffffff4d}@supports (color:color-mix(in lab,red,red)){.border-white\/30{border-color:color-mix(in oklab,var(--color-white)30%,transparent)}}.border-yellow-400\/20{border-color:#fac80033}@supports (color:color-mix(in lab,red,red)){.border-yellow-400\/20{border-color:color-mix(in oklab,var(--color-yellow-400)20%,transparent)}}.border-yellow-400\/30{border-color:#fac8004d}@supports (color:color-mix(in lab,red,red)){.border-yellow-400\/30{border-color:color-mix(in oklab,var(--color-yellow-400)30%,transparent)}}.border-yellow-400\/50{border-color:#fac80080}@supports (color:color-mix(in lab,red,red)){.border-yellow-400\/50{border-color:color-mix(in oklab,var(--color-yellow-400)50%,transparent)}}.border-yellow-500{border-color:var(--color-yellow-500)}.border-yellow-500\/20{border-color:#edb20033}@supports (color:color-mix(in lab,red,red)){.border-yellow-500\/20{border-color:color-mix(in oklab,var(--color-yellow-500)20%,transparent)}}.border-yellow-500\/30{border-color:#edb2004d}@supports (color:color-mix(in lab,red,red)){.border-yellow-500\/30{border-color:color-mix(in oklab,var(--color-yellow-500)30%,transparent)}}.border-yellow-500\/50{border-color:#edb20080}@supports (color:color-mix(in lab,red,red)){.border-yellow-500\/50{border-color:color-mix(in oklab,var(--color-yellow-500)50%,transparent)}}.border-zinc-500{border-color:var(--color-zinc-500)}.border-zinc-600{border-color:var(--color-zinc-600)}.border-zinc-700{border-color:var(--color-zinc-700)}.border-zinc-700\/50{border-color:#3f3f4680}@supports (color:color-mix(in lab,red,red)){.border-zinc-700\/50{border-color:color-mix(in oklab,var(--color-zinc-700)50%,transparent)}}.border-zinc-800{border-color:var(--color-zinc-800)}.border-t-bambu-dark-tertiary{border-top-color:var(--color-bambu-dark-tertiary)}.border-t-transparent{border-top-color:#0000}.border-r-transparent{border-right-color:#0000}.border-b-bambu-dark-tertiary{border-bottom-color:var(--color-bambu-dark-tertiary)}.border-l-transparent{border-left-color:#0000}.border-l-yellow-500{border-left-color:var(--color-yellow-500)}.\!bg-bambu-green{background-color:var(--color-bambu-green)!important}.bg-amber-50{background-color:var(--color-amber-50)}.bg-amber-500{background-color:var(--color-amber-500)}.bg-amber-500\/5{background-color:#f99c000d}@supports (color:color-mix(in lab,red,red)){.bg-amber-500\/5{background-color:color-mix(in oklab,var(--color-amber-500)5%,transparent)}}.bg-amber-500\/10{background-color:#f99c001a}@supports (color:color-mix(in lab,red,red)){.bg-amber-500\/10{background-color:color-mix(in oklab,var(--color-amber-500)10%,transparent)}}.bg-amber-500\/20{background-color:#f99c0033}@supports (color:color-mix(in lab,red,red)){.bg-amber-500\/20{background-color:color-mix(in oklab,var(--color-amber-500)20%,transparent)}}.bg-amber-600\/20{background-color:#dd740033}@supports (color:color-mix(in lab,red,red)){.bg-amber-600\/20{background-color:color-mix(in oklab,var(--color-amber-600)20%,transparent)}}.bg-bambu-dark{background-color:var(--color-bambu-dark)}.bg-bambu-dark-secondary,.bg-bambu-dark-secondary\/30{background-color:var(--color-bambu-dark-secondary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-secondary\/30{background-color:color-mix(in oklab,var(--color-bambu-dark-secondary)30%,transparent)}}.bg-bambu-dark-secondary\/50{background-color:var(--color-bambu-dark-secondary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-secondary\/50{background-color:color-mix(in oklab,var(--color-bambu-dark-secondary)50%,transparent)}}.bg-bambu-dark-secondary\/60{background-color:var(--color-bambu-dark-secondary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-secondary\/60{background-color:color-mix(in oklab,var(--color-bambu-dark-secondary)60%,transparent)}}.bg-bambu-dark-secondary\/90{background-color:var(--color-bambu-dark-secondary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-secondary\/90{background-color:color-mix(in oklab,var(--color-bambu-dark-secondary)90%,transparent)}}.bg-bambu-dark-secondary\/95{background-color:var(--color-bambu-dark-secondary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-secondary\/95{background-color:color-mix(in oklab,var(--color-bambu-dark-secondary)95%,transparent)}}.bg-bambu-dark-tertiary,.bg-bambu-dark-tertiary\/20{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-tertiary\/20{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)20%,transparent)}}.bg-bambu-dark-tertiary\/30{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-tertiary\/30{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)30%,transparent)}}.bg-bambu-dark-tertiary\/40{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-tertiary\/40{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)40%,transparent)}}.bg-bambu-dark-tertiary\/50{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-tertiary\/50{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)50%,transparent)}}.bg-bambu-dark-tertiary\/70{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-tertiary\/70{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)70%,transparent)}}.bg-bambu-dark-tertiary\/80{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-tertiary\/80{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)80%,transparent)}}.bg-bambu-dark\/20{background-color:var(--color-bambu-dark)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark\/20{background-color:color-mix(in oklab,var(--color-bambu-dark)20%,transparent)}}.bg-bambu-dark\/30{background-color:var(--color-bambu-dark)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark\/30{background-color:color-mix(in oklab,var(--color-bambu-dark)30%,transparent)}}.bg-bambu-dark\/50{background-color:var(--color-bambu-dark)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark\/50{background-color:color-mix(in oklab,var(--color-bambu-dark)50%,transparent)}}.bg-bambu-dark\/80{background-color:var(--color-bambu-dark)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark\/80{background-color:color-mix(in oklab,var(--color-bambu-dark)80%,transparent)}}.bg-bambu-dark\/90{background-color:var(--color-bambu-dark)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark\/90{background-color:color-mix(in oklab,var(--color-bambu-dark)90%,transparent)}}.bg-bambu-gray,.bg-bambu-gray\/10{background-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-gray\/10{background-color:color-mix(in oklab,var(--color-bambu-gray)10%,transparent)}}.bg-bambu-gray\/20{background-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-gray\/20{background-color:color-mix(in oklab,var(--color-bambu-gray)20%,transparent)}}.bg-bambu-gray\/30{background-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-gray\/30{background-color:color-mix(in oklab,var(--color-bambu-gray)30%,transparent)}}.bg-bambu-gray\/50{background-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-gray\/50{background-color:color-mix(in oklab,var(--color-bambu-gray)50%,transparent)}}.bg-bambu-gray\/60{background-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-gray\/60{background-color:color-mix(in oklab,var(--color-bambu-gray)60%,transparent)}}.bg-bambu-gray\/90{background-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-gray\/90{background-color:color-mix(in oklab,var(--color-bambu-gray)90%,transparent)}}.bg-bambu-green,.bg-bambu-green\/5{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-green\/5{background-color:color-mix(in oklab,var(--color-bambu-green)5%,transparent)}}.bg-bambu-green\/10{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-green\/10{background-color:color-mix(in oklab,var(--color-bambu-green)10%,transparent)}}.bg-bambu-green\/15{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-green\/15{background-color:color-mix(in oklab,var(--color-bambu-green)15%,transparent)}}.bg-bambu-green\/20{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-green\/20{background-color:color-mix(in oklab,var(--color-bambu-green)20%,transparent)}}.bg-bambu-green\/30{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-green\/30{background-color:color-mix(in oklab,var(--color-bambu-green)30%,transparent)}}.bg-bambu-green\/50{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-green\/50{background-color:color-mix(in oklab,var(--color-bambu-green)50%,transparent)}}.bg-bambu-green\/75{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-green\/75{background-color:color-mix(in oklab,var(--color-bambu-green)75%,transparent)}}.bg-bambu-green\/90{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-green\/90{background-color:color-mix(in oklab,var(--color-bambu-green)90%,transparent)}}.bg-black{background-color:var(--color-black)}.bg-black\/15{background-color:#00000026}@supports (color:color-mix(in lab,red,red)){.bg-black\/15{background-color:color-mix(in oklab,var(--color-black)15%,transparent)}}.bg-black\/30{background-color:#0000004d}@supports (color:color-mix(in lab,red,red)){.bg-black\/30{background-color:color-mix(in oklab,var(--color-black)30%,transparent)}}.bg-black\/40{background-color:#0006}@supports (color:color-mix(in lab,red,red)){.bg-black\/40{background-color:color-mix(in oklab,var(--color-black)40%,transparent)}}.bg-black\/50{background-color:#00000080}@supports (color:color-mix(in lab,red,red)){.bg-black\/50{background-color:color-mix(in oklab,var(--color-black)50%,transparent)}}.bg-black\/60{background-color:#0009}@supports (color:color-mix(in lab,red,red)){.bg-black\/60{background-color:color-mix(in oklab,var(--color-black)60%,transparent)}}.bg-black\/70{background-color:#000000b3}@supports (color:color-mix(in lab,red,red)){.bg-black\/70{background-color:color-mix(in oklab,var(--color-black)70%,transparent)}}.bg-black\/80{background-color:#000c}@supports (color:color-mix(in lab,red,red)){.bg-black\/80{background-color:color-mix(in oklab,var(--color-black)80%,transparent)}}.bg-black\/90{background-color:#000000e6}@supports (color:color-mix(in lab,red,red)){.bg-black\/90{background-color:color-mix(in oklab,var(--color-black)90%,transparent)}}.bg-blue-50{background-color:var(--color-blue-50)}.bg-blue-100{background-color:var(--color-blue-100)}.bg-blue-400{background-color:var(--color-blue-400)}.bg-blue-400\/10{background-color:#54a2ff1a}@supports (color:color-mix(in lab,red,red)){.bg-blue-400\/10{background-color:color-mix(in oklab,var(--color-blue-400)10%,transparent)}}.bg-blue-500{background-color:var(--color-blue-500)}.bg-blue-500\/5{background-color:#3080ff0d}@supports (color:color-mix(in lab,red,red)){.bg-blue-500\/5{background-color:color-mix(in oklab,var(--color-blue-500)5%,transparent)}}.bg-blue-500\/10{background-color:#3080ff1a}@supports (color:color-mix(in lab,red,red)){.bg-blue-500\/10{background-color:color-mix(in oklab,var(--color-blue-500)10%,transparent)}}.bg-blue-500\/20{background-color:#3080ff33}@supports (color:color-mix(in lab,red,red)){.bg-blue-500\/20{background-color:color-mix(in oklab,var(--color-blue-500)20%,transparent)}}.bg-blue-500\/30{background-color:#3080ff4d}@supports (color:color-mix(in lab,red,red)){.bg-blue-500\/30{background-color:color-mix(in oklab,var(--color-blue-500)30%,transparent)}}.bg-blue-500\/90{background-color:#3080ffe6}@supports (color:color-mix(in lab,red,red)){.bg-blue-500\/90{background-color:color-mix(in oklab,var(--color-blue-500)90%,transparent)}}.bg-blue-600{background-color:var(--color-blue-600)}.bg-blue-600\/20{background-color:#155dfc33}@supports (color:color-mix(in lab,red,red)){.bg-blue-600\/20{background-color:color-mix(in oklab,var(--color-blue-600)20%,transparent)}}.bg-cyan-500{background-color:var(--color-cyan-500)}.bg-cyan-500\/10{background-color:#00b7d71a}@supports (color:color-mix(in lab,red,red)){.bg-cyan-500\/10{background-color:color-mix(in oklab,var(--color-cyan-500)10%,transparent)}}.bg-cyan-500\/20{background-color:#00b7d733}@supports (color:color-mix(in lab,red,red)){.bg-cyan-500\/20{background-color:color-mix(in oklab,var(--color-cyan-500)20%,transparent)}}.bg-cyan-600\/20{background-color:#0092b533}@supports (color:color-mix(in lab,red,red)){.bg-cyan-600\/20{background-color:color-mix(in oklab,var(--color-cyan-600)20%,transparent)}}.bg-emerald-500\/20{background-color:#00bb7f33}@supports (color:color-mix(in lab,red,red)){.bg-emerald-500\/20{background-color:color-mix(in oklab,var(--color-emerald-500)20%,transparent)}}.bg-emerald-600\/20{background-color:#00976733}@supports (color:color-mix(in lab,red,red)){.bg-emerald-600\/20{background-color:color-mix(in oklab,var(--color-emerald-600)20%,transparent)}}.bg-emerald-700{background-color:var(--color-emerald-700)}.bg-fuchsia-500{background-color:var(--color-fuchsia-500)}.bg-gray-50{background-color:var(--color-gray-50)}.bg-gray-100{background-color:var(--color-gray-100)}.bg-gray-400{background-color:var(--color-gray-400)}.bg-gray-400\/10{background-color:#99a1af1a}@supports (color:color-mix(in lab,red,red)){.bg-gray-400\/10{background-color:color-mix(in oklab,var(--color-gray-400)10%,transparent)}}.bg-gray-500{background-color:var(--color-gray-500)}.bg-gray-500\/20{background-color:#6a728233}@supports (color:color-mix(in lab,red,red)){.bg-gray-500\/20{background-color:color-mix(in oklab,var(--color-gray-500)20%,transparent)}}.bg-gray-600{background-color:var(--color-gray-600)}.bg-gray-800{background-color:var(--color-gray-800)}.bg-gray-900{background-color:var(--color-gray-900)}.bg-green-100{background-color:var(--color-green-100)}.bg-green-400{background-color:var(--color-green-400)}.bg-green-500{background-color:var(--color-green-500)}.bg-green-500\/10{background-color:#00c7581a}@supports (color:color-mix(in lab,red,red)){.bg-green-500\/10{background-color:color-mix(in oklab,var(--color-green-500)10%,transparent)}}.bg-green-500\/15{background-color:#00c75826}@supports (color:color-mix(in lab,red,red)){.bg-green-500\/15{background-color:color-mix(in oklab,var(--color-green-500)15%,transparent)}}.bg-green-500\/20{background-color:#00c75833}@supports (color:color-mix(in lab,red,red)){.bg-green-500\/20{background-color:color-mix(in oklab,var(--color-green-500)20%,transparent)}}.bg-green-600{background-color:var(--color-green-600)}.bg-green-600\/20{background-color:#00a54433}@supports (color:color-mix(in lab,red,red)){.bg-green-600\/20{background-color:color-mix(in oklab,var(--color-green-600)20%,transparent)}}.bg-green-600\/40{background-color:#00a54466}@supports (color:color-mix(in lab,red,red)){.bg-green-600\/40{background-color:color-mix(in oklab,var(--color-green-600)40%,transparent)}}.bg-green-900\/30{background-color:#0d542b4d}@supports (color:color-mix(in lab,red,red)){.bg-green-900\/30{background-color:color-mix(in oklab,var(--color-green-900)30%,transparent)}}.bg-green-900\/50{background-color:#0d542b80}@supports (color:color-mix(in lab,red,red)){.bg-green-900\/50{background-color:color-mix(in oklab,var(--color-green-900)50%,transparent)}}.bg-indigo-500\/20{background-color:#625fff33}@supports (color:color-mix(in lab,red,red)){.bg-indigo-500\/20{background-color:color-mix(in oklab,var(--color-indigo-500)20%,transparent)}}.bg-lime-500{background-color:var(--color-lime-500)}.bg-orange-400\/10{background-color:#ff8b1a1a}@supports (color:color-mix(in lab,red,red)){.bg-orange-400\/10{background-color:color-mix(in oklab,var(--color-orange-400)10%,transparent)}}.bg-orange-500{background-color:var(--color-orange-500)}.bg-orange-500\/10{background-color:#fe6e001a}@supports (color:color-mix(in lab,red,red)){.bg-orange-500\/10{background-color:color-mix(in oklab,var(--color-orange-500)10%,transparent)}}.bg-orange-500\/20{background-color:#fe6e0033}@supports (color:color-mix(in lab,red,red)){.bg-orange-500\/20{background-color:color-mix(in oklab,var(--color-orange-500)20%,transparent)}}.bg-orange-600{background-color:var(--color-orange-600)}.bg-orange-600\/20{background-color:#f0510033}@supports (color:color-mix(in lab,red,red)){.bg-orange-600\/20{background-color:color-mix(in oklab,var(--color-orange-600)20%,transparent)}}.bg-purple-400\/10{background-color:#c07eff1a}@supports (color:color-mix(in lab,red,red)){.bg-purple-400\/10{background-color:color-mix(in oklab,var(--color-purple-400)10%,transparent)}}.bg-purple-500{background-color:var(--color-purple-500)}.bg-purple-500\/10{background-color:#ac4bff1a}@supports (color:color-mix(in lab,red,red)){.bg-purple-500\/10{background-color:color-mix(in oklab,var(--color-purple-500)10%,transparent)}}.bg-purple-500\/20{background-color:#ac4bff33}@supports (color:color-mix(in lab,red,red)){.bg-purple-500\/20{background-color:color-mix(in oklab,var(--color-purple-500)20%,transparent)}}.bg-purple-500\/80{background-color:#ac4bffcc}@supports (color:color-mix(in lab,red,red)){.bg-purple-500\/80{background-color:color-mix(in oklab,var(--color-purple-500)80%,transparent)}}.bg-purple-500\/90{background-color:#ac4bffe6}@supports (color:color-mix(in lab,red,red)){.bg-purple-500\/90{background-color:color-mix(in oklab,var(--color-purple-500)90%,transparent)}}.bg-purple-700{background-color:var(--color-purple-700)}.bg-red-50{background-color:var(--color-red-50)}.bg-red-100{background-color:var(--color-red-100)}.bg-red-400{background-color:var(--color-red-400)}.bg-red-500{background-color:var(--color-red-500)}.bg-red-500\/5{background-color:#fb2c360d}@supports (color:color-mix(in lab,red,red)){.bg-red-500\/5{background-color:color-mix(in oklab,var(--color-red-500)5%,transparent)}}.bg-red-500\/10{background-color:#fb2c361a}@supports (color:color-mix(in lab,red,red)){.bg-red-500\/10{background-color:color-mix(in oklab,var(--color-red-500)10%,transparent)}}.bg-red-500\/15{background-color:#fb2c3626}@supports (color:color-mix(in lab,red,red)){.bg-red-500\/15{background-color:color-mix(in oklab,var(--color-red-500)15%,transparent)}}.bg-red-500\/20{background-color:#fb2c3633}@supports (color:color-mix(in lab,red,red)){.bg-red-500\/20{background-color:color-mix(in oklab,var(--color-red-500)20%,transparent)}}.bg-red-500\/30{background-color:#fb2c364d}@supports (color:color-mix(in lab,red,red)){.bg-red-500\/30{background-color:color-mix(in oklab,var(--color-red-500)30%,transparent)}}.bg-red-500\/40{background-color:#fb2c3666}@supports (color:color-mix(in lab,red,red)){.bg-red-500\/40{background-color:color-mix(in oklab,var(--color-red-500)40%,transparent)}}.bg-red-500\/80{background-color:#fb2c36cc}@supports (color:color-mix(in lab,red,red)){.bg-red-500\/80{background-color:color-mix(in oklab,var(--color-red-500)80%,transparent)}}.bg-red-600{background-color:var(--color-red-600)}.bg-red-900\/30{background-color:#82181a4d}@supports (color:color-mix(in lab,red,red)){.bg-red-900\/30{background-color:color-mix(in oklab,var(--color-red-900)30%,transparent)}}.bg-red-950\/70{background-color:#460809b3}@supports (color:color-mix(in lab,red,red)){.bg-red-950\/70{background-color:color-mix(in oklab,var(--color-red-950)70%,transparent)}}.bg-rose-500\/20{background-color:#ff235733}@supports (color:color-mix(in lab,red,red)){.bg-rose-500\/20{background-color:color-mix(in oklab,var(--color-rose-500)20%,transparent)}}.bg-rose-600\/20{background-color:#e7004433}@supports (color:color-mix(in lab,red,red)){.bg-rose-600\/20{background-color:color-mix(in oklab,var(--color-rose-600)20%,transparent)}}.bg-sky-500{background-color:var(--color-sky-500)}.bg-sky-500\/20{background-color:#00a5ef33}@supports (color:color-mix(in lab,red,red)){.bg-sky-500\/20{background-color:color-mix(in oklab,var(--color-sky-500)20%,transparent)}}.bg-status-error,.bg-status-error\/10{background-color:var(--color-status-error)}@supports (color:color-mix(in lab,red,red)){.bg-status-error\/10{background-color:color-mix(in oklab,var(--color-status-error)10%,transparent)}}.bg-status-error\/20{background-color:var(--color-status-error)}@supports (color:color-mix(in lab,red,red)){.bg-status-error\/20{background-color:color-mix(in oklab,var(--color-status-error)20%,transparent)}}.bg-status-error\/80{background-color:var(--color-status-error)}@supports (color:color-mix(in lab,red,red)){.bg-status-error\/80{background-color:color-mix(in oklab,var(--color-status-error)80%,transparent)}}.bg-status-ok,.bg-status-ok\/10{background-color:var(--color-status-ok)}@supports (color:color-mix(in lab,red,red)){.bg-status-ok\/10{background-color:color-mix(in oklab,var(--color-status-ok)10%,transparent)}}.bg-status-ok\/20{background-color:var(--color-status-ok)}@supports (color:color-mix(in lab,red,red)){.bg-status-ok\/20{background-color:color-mix(in oklab,var(--color-status-ok)20%,transparent)}}.bg-status-warning,.bg-status-warning\/10{background-color:var(--color-status-warning)}@supports (color:color-mix(in lab,red,red)){.bg-status-warning\/10{background-color:color-mix(in oklab,var(--color-status-warning)10%,transparent)}}.bg-status-warning\/20{background-color:var(--color-status-warning)}@supports (color:color-mix(in lab,red,red)){.bg-status-warning\/20{background-color:color-mix(in oklab,var(--color-status-warning)20%,transparent)}}.bg-teal-500{background-color:var(--color-teal-500)}.bg-teal-500\/20{background-color:#00baa733}@supports (color:color-mix(in lab,red,red)){.bg-teal-500\/20{background-color:color-mix(in oklab,var(--color-teal-500)20%,transparent)}}.bg-transparent{background-color:#0000}.bg-violet-500{background-color:var(--color-violet-500)}.bg-white{background-color:var(--color-white)}.bg-white\/10{background-color:#ffffff1a}@supports (color:color-mix(in lab,red,red)){.bg-white\/10{background-color:color-mix(in oklab,var(--color-white)10%,transparent)}}.bg-white\/20{background-color:#fff3}@supports (color:color-mix(in lab,red,red)){.bg-white\/20{background-color:color-mix(in oklab,var(--color-white)20%,transparent)}}.bg-white\/50{background-color:#ffffff80}@supports (color:color-mix(in lab,red,red)){.bg-white\/50{background-color:color-mix(in oklab,var(--color-white)50%,transparent)}}.bg-white\/70{background-color:#ffffffb3}@supports (color:color-mix(in lab,red,red)){.bg-white\/70{background-color:color-mix(in oklab,var(--color-white)70%,transparent)}}.bg-white\/90{background-color:#ffffffe6}@supports (color:color-mix(in lab,red,red)){.bg-white\/90{background-color:color-mix(in oklab,var(--color-white)90%,transparent)}}.bg-yellow-400{background-color:var(--color-yellow-400)}.bg-yellow-400\/10{background-color:#fac8001a}@supports (color:color-mix(in lab,red,red)){.bg-yellow-400\/10{background-color:color-mix(in oklab,var(--color-yellow-400)10%,transparent)}}.bg-yellow-400\/20{background-color:#fac80033}@supports (color:color-mix(in lab,red,red)){.bg-yellow-400\/20{background-color:color-mix(in oklab,var(--color-yellow-400)20%,transparent)}}.bg-yellow-500{background-color:var(--color-yellow-500)}.bg-yellow-500\/5{background-color:#edb2000d}@supports (color:color-mix(in lab,red,red)){.bg-yellow-500\/5{background-color:color-mix(in oklab,var(--color-yellow-500)5%,transparent)}}.bg-yellow-500\/10{background-color:#edb2001a}@supports (color:color-mix(in lab,red,red)){.bg-yellow-500\/10{background-color:color-mix(in oklab,var(--color-yellow-500)10%,transparent)}}.bg-yellow-500\/20{background-color:#edb20033}@supports (color:color-mix(in lab,red,red)){.bg-yellow-500\/20{background-color:color-mix(in oklab,var(--color-yellow-500)20%,transparent)}}.bg-zinc-600{background-color:var(--color-zinc-600)}.bg-zinc-700{background-color:var(--color-zinc-700)}.bg-zinc-700\/50{background-color:#3f3f4680}@supports (color:color-mix(in lab,red,red)){.bg-zinc-700\/50{background-color:color-mix(in oklab,var(--color-zinc-700)50%,transparent)}}.bg-zinc-800{background-color:var(--color-zinc-800)}.bg-zinc-800\/50{background-color:#27272a80}@supports (color:color-mix(in lab,red,red)){.bg-zinc-800\/50{background-color:color-mix(in oklab,var(--color-zinc-800)50%,transparent)}}.bg-zinc-900{background-color:var(--color-zinc-900)}.bg-zinc-900\/50{background-color:#18181b80}@supports (color:color-mix(in lab,red,red)){.bg-zinc-900\/50{background-color:color-mix(in oklab,var(--color-zinc-900)50%,transparent)}}.bg-gradient-to-b{--tw-gradient-position:to bottom in oklab;background-image:linear-gradient(var(--tw-gradient-stops))}.bg-gradient-to-br{--tw-gradient-position:to bottom right in oklab;background-image:linear-gradient(var(--tw-gradient-stops))}.bg-gradient-to-r{--tw-gradient-position:to right in oklab;background-image:linear-gradient(var(--tw-gradient-stops))}.bg-gradient-to-t{--tw-gradient-position:to top in oklab;background-image:linear-gradient(var(--tw-gradient-stops))}.from-bambu-dark-secondary{--tw-gradient-from:var(--color-bambu-dark-secondary);--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-bambu-green\/10{--tw-gradient-from:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.from-bambu-green\/10{--tw-gradient-from:color-mix(in oklab,var(--color-bambu-green)10%,transparent)}}.from-bambu-green\/10{--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-black\/80{--tw-gradient-from:#000c}@supports (color:color-mix(in lab,red,red)){.from-black\/80{--tw-gradient-from:color-mix(in oklab,var(--color-black)80%,transparent)}}.from-black\/80{--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-blue-500\/5{--tw-gradient-from:#3080ff0d}@supports (color:color-mix(in lab,red,red)){.from-blue-500\/5{--tw-gradient-from:color-mix(in oklab,var(--color-blue-500)5%,transparent)}}.from-blue-500\/5{--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-blue-500\/10{--tw-gradient-from:#3080ff1a}@supports (color:color-mix(in lab,red,red)){.from-blue-500\/10{--tw-gradient-from:color-mix(in oklab,var(--color-blue-500)10%,transparent)}}.from-blue-500\/10{--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-gray-500\/10{--tw-gradient-from:#6a72821a}@supports (color:color-mix(in lab,red,red)){.from-gray-500\/10{--tw-gradient-from:color-mix(in oklab,var(--color-gray-500)10%,transparent)}}.from-gray-500\/10{--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-purple-500\/10{--tw-gradient-from:#ac4bff1a}@supports (color:color-mix(in lab,red,red)){.from-purple-500\/10{--tw-gradient-from:color-mix(in oklab,var(--color-purple-500)10%,transparent)}}.from-purple-500\/10{--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-white\/10{--tw-gradient-from:#ffffff1a}@supports (color:color-mix(in lab,red,red)){.from-white\/10{--tw-gradient-from:color-mix(in oklab,var(--color-white)10%,transparent)}}.from-white\/10{--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-yellow-500\/10{--tw-gradient-from:#edb2001a}@supports (color:color-mix(in lab,red,red)){.from-yellow-500\/10{--tw-gradient-from:color-mix(in oklab,var(--color-yellow-500)10%,transparent)}}.from-yellow-500\/10{--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.via-black\/60{--tw-gradient-via:#0009}@supports (color:color-mix(in lab,red,red)){.via-black\/60{--tw-gradient-via:color-mix(in oklab,var(--color-black)60%,transparent)}}.via-black\/60{--tw-gradient-via-stops:var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-via)var(--tw-gradient-via-position),var(--tw-gradient-to)var(--tw-gradient-to-position);--tw-gradient-stops:var(--tw-gradient-via-stops)}.to-bambu-dark-secondary{--tw-gradient-to:var(--color-bambu-dark-secondary);--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.to-bambu-dark-tertiary{--tw-gradient-to:var(--color-bambu-dark-tertiary);--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.to-transparent{--tw-gradient-to:transparent;--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.bg-cover{background-size:cover}.bg-center{background-position:50%}.fill-yellow-400{fill:var(--color-yellow-400)}.object-contain{object-fit:contain}.object-cover{object-fit:cover}.object-left{object-position:left}.p-0{padding:calc(var(--spacing)*0)}.p-0\.5{padding:calc(var(--spacing)*.5)}.p-1{padding:calc(var(--spacing)*1)}.p-1\.5{padding:calc(var(--spacing)*1.5)}.p-2{padding:calc(var(--spacing)*2)}.p-2\.5{padding:calc(var(--spacing)*2.5)}.p-3{padding:calc(var(--spacing)*3)}.p-4{padding:calc(var(--spacing)*4)}.p-5{padding:calc(var(--spacing)*5)}.p-6{padding:calc(var(--spacing)*6)}.p-8{padding:calc(var(--spacing)*8)}.p-12{padding:calc(var(--spacing)*12)}.\!px-1\.5{padding-inline:calc(var(--spacing)*1.5)!important}.\!px-3{padding-inline:calc(var(--spacing)*3)!important}.px-1{padding-inline:calc(var(--spacing)*1)}.px-1\.5{padding-inline:calc(var(--spacing)*1.5)}.px-2{padding-inline:calc(var(--spacing)*2)}.px-2\.5{padding-inline:calc(var(--spacing)*2.5)}.px-3{padding-inline:calc(var(--spacing)*3)}.px-4{padding-inline:calc(var(--spacing)*4)}.px-5{padding-inline:calc(var(--spacing)*5)}.px-6{padding-inline:calc(var(--spacing)*6)}.py-0\.5{padding-block:calc(var(--spacing)*.5)}.py-1{padding-block:calc(var(--spacing)*1)}.py-1\.5{padding-block:calc(var(--spacing)*1.5)}.py-2{padding-block:calc(var(--spacing)*2)}.py-2\.5{padding-block:calc(var(--spacing)*2.5)}.py-3{padding-block:calc(var(--spacing)*3)}.py-4{padding-block:calc(var(--spacing)*4)}.py-6{padding-block:calc(var(--spacing)*6)}.py-8{padding-block:calc(var(--spacing)*8)}.py-12{padding-block:calc(var(--spacing)*12)}.py-16{padding-block:calc(var(--spacing)*16)}.py-20{padding-block:calc(var(--spacing)*20)}.py-24{padding-block:calc(var(--spacing)*24)}.pt-0{padding-top:calc(var(--spacing)*0)}.pt-1{padding-top:calc(var(--spacing)*1)}.pt-2{padding-top:calc(var(--spacing)*2)}.pt-3{padding-top:calc(var(--spacing)*3)}.pt-4{padding-top:calc(var(--spacing)*4)}.pr-1{padding-right:calc(var(--spacing)*1)}.pr-2{padding-right:calc(var(--spacing)*2)}.pr-3{padding-right:calc(var(--spacing)*3)}.pr-4{padding-right:calc(var(--spacing)*4)}.pr-6{padding-right:calc(var(--spacing)*6)}.pr-7{padding-right:calc(var(--spacing)*7)}.pr-8{padding-right:calc(var(--spacing)*8)}.pr-10{padding-right:calc(var(--spacing)*10)}.pb-1{padding-bottom:calc(var(--spacing)*1)}.pb-2{padding-bottom:calc(var(--spacing)*2)}.pb-3{padding-bottom:calc(var(--spacing)*3)}.pb-4{padding-bottom:calc(var(--spacing)*4)}.pl-2{padding-left:calc(var(--spacing)*2)}.pl-4{padding-left:calc(var(--spacing)*4)}.pl-5{padding-left:calc(var(--spacing)*5)}.pl-6{padding-left:calc(var(--spacing)*6)}.pl-7{padding-left:calc(var(--spacing)*7)}.pl-8{padding-left:calc(var(--spacing)*8)}.pl-9{padding-left:calc(var(--spacing)*9)}.pl-10{padding-left:calc(var(--spacing)*10)}.text-center{text-align:center}.text-left{text-align:left}.text-right{text-align:right}.font-mono{font-family:var(--font-mono)}.font-sans{font-family:var(--font-sans)}.text-2xl{font-size:var(--text-2xl);line-height:var(--tw-leading,var(--text-2xl--line-height))}.text-3xl{font-size:var(--text-3xl);line-height:var(--tw-leading,var(--text-3xl--line-height))}.text-5xl{font-size:var(--text-5xl);line-height:var(--tw-leading,var(--text-5xl--line-height))}.text-base{font-size:var(--text-base);line-height:var(--tw-leading,var(--text-base--line-height))}.text-lg{font-size:var(--text-lg);line-height:var(--tw-leading,var(--text-lg--line-height))}.text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.text-xl{font-size:var(--text-xl);line-height:var(--tw-leading,var(--text-xl--line-height))}.text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}.text-\[6px\]{font-size:6px}.text-\[7px\]{font-size:7px}.text-\[8px\]{font-size:8px}.text-\[9px\]{font-size:9px}.text-\[10px\]{font-size:10px}.text-\[11px\]{font-size:11px}.leading-none{--tw-leading:1;line-height:1}.leading-tight{--tw-leading:var(--leading-tight);line-height:var(--leading-tight)}.font-bold{--tw-font-weight:var(--font-weight-bold);font-weight:var(--font-weight-bold)}.font-light{--tw-font-weight:var(--font-weight-light);font-weight:var(--font-weight-light)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.font-normal{--tw-font-weight:var(--font-weight-normal);font-weight:var(--font-weight-normal)}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.tracking-wide{--tw-tracking:var(--tracking-wide);letter-spacing:var(--tracking-wide)}.tracking-wider{--tw-tracking:var(--tracking-wider);letter-spacing:var(--tracking-wider)}.tracking-widest{--tw-tracking:var(--tracking-widest);letter-spacing:var(--tracking-widest)}.break-words{overflow-wrap:break-word}.break-all{word-break:break-all}.whitespace-nowrap{white-space:nowrap}.whitespace-pre-line{white-space:pre-line}.whitespace-pre-wrap{white-space:pre-wrap}.\!text-green-400{color:var(--color-green-400)!important}.\!text-white{color:var(--color-white)!important}.\!text-yellow-400{color:var(--color-yellow-400)!important}.text-amber-200{color:var(--color-amber-200)}.text-amber-200\/80{color:#fee685cc}@supports (color:color-mix(in lab,red,red)){.text-amber-200\/80{color:color-mix(in oklab,var(--color-amber-200)80%,transparent)}}.text-amber-300{color:var(--color-amber-300)}.text-amber-300\/60{color:#ffd23699}@supports (color:color-mix(in lab,red,red)){.text-amber-300\/60{color:color-mix(in oklab,var(--color-amber-300)60%,transparent)}}.text-amber-300\/70{color:#ffd236b3}@supports (color:color-mix(in lab,red,red)){.text-amber-300\/70{color:color-mix(in oklab,var(--color-amber-300)70%,transparent)}}.text-amber-300\/80{color:#ffd236cc}@supports (color:color-mix(in lab,red,red)){.text-amber-300\/80{color:color-mix(in oklab,var(--color-amber-300)80%,transparent)}}.text-amber-400{color:var(--color-amber-400)}.text-amber-400\/70{color:#fcbb00b3}@supports (color:color-mix(in lab,red,red)){.text-amber-400\/70{color:color-mix(in oklab,var(--color-amber-400)70%,transparent)}}.text-amber-500{color:var(--color-amber-500)}.text-amber-500\/80{color:#f99c00cc}@supports (color:color-mix(in lab,red,red)){.text-amber-500\/80{color:color-mix(in oklab,var(--color-amber-500)80%,transparent)}}.text-amber-600{color:var(--color-amber-600)}.text-amber-700{color:var(--color-amber-700)}.text-amber-800{color:var(--color-amber-800)}.text-bambu-dark-tertiary{color:var(--color-bambu-dark-tertiary)}.text-bambu-gray{color:var(--color-bambu-gray)}.text-bambu-gray-dark{color:var(--color-bambu-gray-dark)}.text-bambu-gray-light{color:var(--color-bambu-gray-light)}.text-bambu-gray\/30{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.text-bambu-gray\/30{color:color-mix(in oklab,var(--color-bambu-gray)30%,transparent)}}.text-bambu-gray\/40{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.text-bambu-gray\/40{color:color-mix(in oklab,var(--color-bambu-gray)40%,transparent)}}.text-bambu-gray\/50{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.text-bambu-gray\/50{color:color-mix(in oklab,var(--color-bambu-gray)50%,transparent)}}.text-bambu-gray\/60{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.text-bambu-gray\/60{color:color-mix(in oklab,var(--color-bambu-gray)60%,transparent)}}.text-bambu-gray\/70{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.text-bambu-gray\/70{color:color-mix(in oklab,var(--color-bambu-gray)70%,transparent)}}.text-bambu-gray\/80{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.text-bambu-gray\/80{color:color-mix(in oklab,var(--color-bambu-gray)80%,transparent)}}.text-bambu-green,.text-bambu-green\/70{color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.text-bambu-green\/70{color:color-mix(in oklab,var(--color-bambu-green)70%,transparent)}}.text-black{color:var(--color-black)}.text-black\/80{color:#000c}@supports (color:color-mix(in lab,red,red)){.text-black\/80{color:color-mix(in oklab,var(--color-black)80%,transparent)}}.text-blue-300{color:var(--color-blue-300)}.text-blue-300\/70{color:#90c5ffb3}@supports (color:color-mix(in lab,red,red)){.text-blue-300\/70{color:color-mix(in oklab,var(--color-blue-300)70%,transparent)}}.text-blue-300\/80{color:#90c5ffcc}@supports (color:color-mix(in lab,red,red)){.text-blue-300\/80{color:color-mix(in oklab,var(--color-blue-300)80%,transparent)}}.text-blue-400{color:var(--color-blue-400)}.text-blue-500{color:var(--color-blue-500)}.text-blue-500\/70{color:#3080ffb3}@supports (color:color-mix(in lab,red,red)){.text-blue-500\/70{color:color-mix(in oklab,var(--color-blue-500)70%,transparent)}}.text-blue-600{color:var(--color-blue-600)}.text-blue-700{color:var(--color-blue-700)}.text-cyan-300{color:var(--color-cyan-300)}.text-cyan-400{color:var(--color-cyan-400)}.text-emerald-300{color:var(--color-emerald-300)}.text-emerald-400{color:var(--color-emerald-400)}.text-gray-300{color:var(--color-gray-300)}.text-gray-400{color:var(--color-gray-400)}.text-gray-500{color:var(--color-gray-500)}.text-gray-600{color:var(--color-gray-600)}.text-gray-700{color:var(--color-gray-700)}.text-gray-800{color:var(--color-gray-800)}.text-gray-900{color:var(--color-gray-900)}.text-green-200{color:var(--color-green-200)}.text-green-300{color:var(--color-green-300)}.text-green-400{color:var(--color-green-400)}.text-green-400\/60{color:#05df7299}@supports (color:color-mix(in lab,red,red)){.text-green-400\/60{color:color-mix(in oklab,var(--color-green-400)60%,transparent)}}.text-green-500{color:var(--color-green-500)}.text-green-500\/60{color:#00c75899}@supports (color:color-mix(in lab,red,red)){.text-green-500\/60{color:color-mix(in oklab,var(--color-green-500)60%,transparent)}}.text-green-600{color:var(--color-green-600)}.text-indigo-400{color:var(--color-indigo-400)}.text-orange-200{color:var(--color-orange-200)}.text-orange-300{color:var(--color-orange-300)}.text-orange-400{color:var(--color-orange-400)}.text-orange-500{color:var(--color-orange-500)}.text-orange-600{color:var(--color-orange-600)}.text-orange-700{color:var(--color-orange-700)}.text-purple-300{color:var(--color-purple-300)}.text-purple-300\/70{color:#d9b3ffb3}@supports (color:color-mix(in lab,red,red)){.text-purple-300\/70{color:color-mix(in oklab,var(--color-purple-300)70%,transparent)}}.text-purple-400{color:var(--color-purple-400)}.text-purple-400\/80{color:#c07effcc}@supports (color:color-mix(in lab,red,red)){.text-purple-400\/80{color:color-mix(in oklab,var(--color-purple-400)80%,transparent)}}.text-purple-500{color:var(--color-purple-500)}.text-red-200{color:var(--color-red-200)}.text-red-300{color:var(--color-red-300)}.text-red-300\/80{color:#ffa3a3cc}@supports (color:color-mix(in lab,red,red)){.text-red-300\/80{color:color-mix(in oklab,var(--color-red-300)80%,transparent)}}.text-red-400{color:var(--color-red-400)}.text-red-400\/50{color:#ff656880}@supports (color:color-mix(in lab,red,red)){.text-red-400\/50{color:color-mix(in oklab,var(--color-red-400)50%,transparent)}}.text-red-400\/60{color:#ff656899}@supports (color:color-mix(in lab,red,red)){.text-red-400\/60{color:color-mix(in oklab,var(--color-red-400)60%,transparent)}}.text-red-400\/70{color:#ff6568b3}@supports (color:color-mix(in lab,red,red)){.text-red-400\/70{color:color-mix(in oklab,var(--color-red-400)70%,transparent)}}.text-red-500{color:var(--color-red-500)}.text-red-600{color:var(--color-red-600)}.text-rose-300{color:var(--color-rose-300)}.text-rose-400{color:var(--color-rose-400)}.text-sky-400{color:var(--color-sky-400)}.text-slate-300{color:var(--color-slate-300)}.text-status-error{color:var(--color-status-error)}.text-status-ok{color:var(--color-status-ok)}.text-status-warning{color:var(--color-status-warning)}.text-teal-400{color:var(--color-teal-400)}.text-white{color:var(--color-white)}.text-white\/30{color:#ffffff4d}@supports (color:color-mix(in lab,red,red)){.text-white\/30{color:color-mix(in oklab,var(--color-white)30%,transparent)}}.text-white\/40{color:#fff6}@supports (color:color-mix(in lab,red,red)){.text-white\/40{color:color-mix(in oklab,var(--color-white)40%,transparent)}}.text-white\/50{color:#ffffff80}@supports (color:color-mix(in lab,red,red)){.text-white\/50{color:color-mix(in oklab,var(--color-white)50%,transparent)}}.text-white\/60{color:#fff9}@supports (color:color-mix(in lab,red,red)){.text-white\/60{color:color-mix(in oklab,var(--color-white)60%,transparent)}}.text-white\/70{color:#ffffffb3}@supports (color:color-mix(in lab,red,red)){.text-white\/70{color:color-mix(in oklab,var(--color-white)70%,transparent)}}.text-white\/80{color:#fffc}@supports (color:color-mix(in lab,red,red)){.text-white\/80{color:color-mix(in oklab,var(--color-white)80%,transparent)}}.text-white\/90{color:#ffffffe6}@supports (color:color-mix(in lab,red,red)){.text-white\/90{color:color-mix(in oklab,var(--color-white)90%,transparent)}}.text-yellow-200{color:var(--color-yellow-200)}.text-yellow-200\/70{color:#fff085b3}@supports (color:color-mix(in lab,red,red)){.text-yellow-200\/70{color:color-mix(in oklab,var(--color-yellow-200)70%,transparent)}}.text-yellow-300{color:var(--color-yellow-300)}.text-yellow-400{color:var(--color-yellow-400)}.text-yellow-500{color:var(--color-yellow-500)}.text-yellow-500\/70{color:#edb200b3}@supports (color:color-mix(in lab,red,red)){.text-yellow-500\/70{color:color-mix(in oklab,var(--color-yellow-500)70%,transparent)}}.text-yellow-500\/80{color:#edb200cc}@supports (color:color-mix(in lab,red,red)){.text-yellow-500\/80{color:color-mix(in oklab,var(--color-yellow-500)80%,transparent)}}.text-yellow-600{color:var(--color-yellow-600)}.text-yellow-700{color:var(--color-yellow-700)}.text-zinc-100{color:var(--color-zinc-100)}.text-zinc-200{color:var(--color-zinc-200)}.text-zinc-300{color:var(--color-zinc-300)}.text-zinc-400{color:var(--color-zinc-400)}.text-zinc-500{color:var(--color-zinc-500)}.text-zinc-600{color:var(--color-zinc-600)}.capitalize{text-transform:capitalize}.uppercase{text-transform:uppercase}.italic{font-style:italic}.tabular-nums{--tw-numeric-spacing:tabular-nums;font-variant-numeric:var(--tw-ordinal,)var(--tw-slashed-zero,)var(--tw-numeric-figure,)var(--tw-numeric-spacing,)var(--tw-numeric-fraction,)}.line-through{text-decoration-line:line-through}.underline{text-decoration-line:underline}.placeholder-bambu-gray::placeholder{color:var(--color-bambu-gray)}.placeholder-bambu-gray-dark::placeholder{color:var(--color-bambu-gray-dark)}.placeholder-bambu-gray\/40::placeholder{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.placeholder-bambu-gray\/40::placeholder{color:color-mix(in oklab,var(--color-bambu-gray)40%,transparent)}}.placeholder-bambu-gray\/50::placeholder{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.placeholder-bambu-gray\/50::placeholder{color:color-mix(in oklab,var(--color-bambu-gray)50%,transparent)}}.placeholder-bambu-gray\/60::placeholder{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.placeholder-bambu-gray\/60::placeholder{color:color-mix(in oklab,var(--color-bambu-gray)60%,transparent)}}.placeholder-gray-400::placeholder{color:var(--color-gray-400)}.placeholder-zinc-500::placeholder{color:var(--color-zinc-500)}.accent-amber-500{accent-color:var(--color-amber-500)}.accent-bambu-green{accent-color:var(--color-bambu-green)}.accent-green-500{accent-color:var(--color-green-500)}.\[color-scheme\:dark\]{color-scheme:dark}.opacity-0{opacity:0}.opacity-20{opacity:.2}.opacity-25{opacity:.25}.opacity-30{opacity:.3}.opacity-40{opacity:.4}.opacity-50{opacity:.5}.opacity-60{opacity:.6}.opacity-70{opacity:.7}.opacity-75{opacity:.75}.opacity-80{opacity:.8}.opacity-100{opacity:1}.shadow{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a),0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-2xl{--tw-shadow:0 25px 50px -12px var(--tw-shadow-color,#00000040);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-\[0_0_6px_rgba\(34\,197\,94\,0\.5\)\]{--tw-shadow:0 0 6px var(--tw-shadow-color,#22c55e80);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-lg{--tw-shadow:0 10px 15px -3px var(--tw-shadow-color,#0000001a),0 4px 6px -4px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-md{--tw-shadow:0 4px 6px -1px var(--tw-shadow-color,#0000001a),0 2px 4px -2px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-sm{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a),0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-xl{--tw-shadow:0 20px 25px -5px var(--tw-shadow-color,#0000001a),0 8px 10px -6px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow\/depth{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a),0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.ring,.ring-1{--tw-ring-shadow:var(--tw-ring-inset,)0 0 0 calc(1px + var(--tw-ring-offset-width))var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.ring-2{--tw-ring-shadow:var(--tw-ring-inset,)0 0 0 calc(2px + var(--tw-ring-offset-width))var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-bambu-green\/20{--tw-shadow-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.shadow-bambu-green\/20{--tw-shadow-color:color-mix(in oklab,color-mix(in oklab,var(--color-bambu-green)20%,transparent)var(--tw-shadow-alpha),transparent)}}.shadow-bambu-green\/25{--tw-shadow-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.shadow-bambu-green\/25{--tw-shadow-color:color-mix(in oklab,color-mix(in oklab,var(--color-bambu-green)25%,transparent)var(--tw-shadow-alpha),transparent)}}.ring-bambu-green,.ring-bambu-green\/30{--tw-ring-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.ring-bambu-green\/30{--tw-ring-color:color-mix(in oklab,var(--color-bambu-green)30%,transparent)}}.ring-blue-400\/50{--tw-ring-color:#54a2ff80}@supports (color:color-mix(in lab,red,red)){.ring-blue-400\/50{--tw-ring-color:color-mix(in oklab,var(--color-blue-400)50%,transparent)}}.ring-green-500{--tw-ring-color:var(--color-green-500)}.ring-white{--tw-ring-color:var(--color-white)}.ring-offset-1{--tw-ring-offset-width:1px;--tw-ring-offset-shadow:var(--tw-ring-inset,)0 0 0 var(--tw-ring-offset-width)var(--tw-ring-offset-color)}.ring-offset-2{--tw-ring-offset-width:2px;--tw-ring-offset-shadow:var(--tw-ring-inset,)0 0 0 var(--tw-ring-offset-width)var(--tw-ring-offset-color)}.ring-offset-bambu-dark{--tw-ring-offset-color:var(--color-bambu-dark)}.ring-offset-bambu-dark-secondary{--tw-ring-offset-color:var(--color-bambu-dark-secondary)}.outline{outline-style:var(--tw-outline-style);outline-width:1px}.blur{--tw-blur:blur(8px);filter:var(--tw-blur,)var(--tw-brightness,)var(--tw-contrast,)var(--tw-grayscale,)var(--tw-hue-rotate,)var(--tw-invert,)var(--tw-saturate,)var(--tw-sepia,)var(--tw-drop-shadow,)}.blur-2xl{--tw-blur:blur(var(--blur-2xl));filter:var(--tw-blur,)var(--tw-brightness,)var(--tw-contrast,)var(--tw-grayscale,)var(--tw-hue-rotate,)var(--tw-invert,)var(--tw-saturate,)var(--tw-sepia,)var(--tw-drop-shadow,)}.drop-shadow-lg{--tw-drop-shadow-size:drop-shadow(0 4px 4px var(--tw-drop-shadow-color,#00000026));--tw-drop-shadow:drop-shadow(var(--drop-shadow-lg));filter:var(--tw-blur,)var(--tw-brightness,)var(--tw-contrast,)var(--tw-grayscale,)var(--tw-hue-rotate,)var(--tw-invert,)var(--tw-saturate,)var(--tw-sepia,)var(--tw-drop-shadow,)}.drop-shadow-md{--tw-drop-shadow-size:drop-shadow(0 3px 3px var(--tw-drop-shadow-color,#0000001f));--tw-drop-shadow:drop-shadow(var(--drop-shadow-md));filter:var(--tw-blur,)var(--tw-brightness,)var(--tw-contrast,)var(--tw-grayscale,)var(--tw-hue-rotate,)var(--tw-invert,)var(--tw-saturate,)var(--tw-sepia,)var(--tw-drop-shadow,)}.filter{filter:var(--tw-blur,)var(--tw-brightness,)var(--tw-contrast,)var(--tw-grayscale,)var(--tw-hue-rotate,)var(--tw-invert,)var(--tw-saturate,)var(--tw-sepia,)var(--tw-drop-shadow,)}.backdrop-blur-sm{--tw-backdrop-blur:blur(var(--blur-sm));-webkit-backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,);backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,)}.transition{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to,opacity,box-shadow,transform,translate,scale,rotate,filter,-webkit-backdrop-filter,backdrop-filter,display,content-visibility,overlay,pointer-events;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-all{transition-property:all;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-colors{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-opacity{transition-property:opacity;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-transform{transition-property:transform,translate,scale,rotate;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.duration-150{--tw-duration:.15s;transition-duration:.15s}.duration-200{--tw-duration:.2s;transition-duration:.2s}.duration-300{--tw-duration:.3s;transition-duration:.3s}.duration-500{--tw-duration:.5s;transition-duration:.5s}.duration-1000{--tw-duration:1s;transition-duration:1s}.ease-in-out{--tw-ease:var(--ease-in-out);transition-timing-function:var(--ease-in-out)}.ease-out{--tw-ease:var(--ease-out);transition-timing-function:var(--ease-out)}.select-none{-webkit-user-select:none;user-select:none}@media(hover:hover){.group-hover\:bg-bambu-green\/20:is(:where(.group):hover *){background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.group-hover\:bg-bambu-green\/20:is(:where(.group):hover *){background-color:color-mix(in oklab,var(--color-bambu-green)20%,transparent)}}.group-hover\:text-bambu-gray:is(:where(.group):hover *){color:var(--color-bambu-gray)}.group-hover\:text-bambu-green:is(:where(.group):hover *){color:var(--color-bambu-green)}.group-hover\:opacity-50:is(:where(.group):hover *){opacity:.5}.group-hover\:opacity-100:is(:where(.group):hover *),.group-hover\/resize\:opacity-100:is(:where(.group\/resize):hover *){opacity:1}.group-hover\/thumb\:block:is(:where(.group\/thumb):hover *){display:block}}.peer-checked\:bg-amber-500:is(:where(.peer):checked~*){background-color:var(--color-amber-500)}.peer-checked\:bg-bambu-green:is(:where(.peer):checked~*){background-color:var(--color-bambu-green)}.peer-focus\:outline-none:is(:where(.peer):focus~*){--tw-outline-style:none;outline-style:none}.peer-disabled\:cursor-not-allowed:is(:where(.peer):disabled~*){cursor:not-allowed}.placeholder\:text-bambu-gray::placeholder,.placeholder\:text-bambu-gray\/50::placeholder{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.placeholder\:text-bambu-gray\/50::placeholder{color:color-mix(in oklab,var(--color-bambu-gray)50%,transparent)}}.before\:absolute:before{content:var(--tw-content);position:absolute}.before\:top-0:before{content:var(--tw-content);top:calc(var(--spacing)*0)}.before\:right-0:before{content:var(--tw-content);right:calc(var(--spacing)*0)}.before\:left-0:before{content:var(--tw-content);left:calc(var(--spacing)*0)}.before\:h-0\.5:before{content:var(--tw-content);height:calc(var(--spacing)*.5)}.before\:bg-bambu-green:before{content:var(--tw-content);background-color:var(--color-bambu-green)}.after\:absolute:after{content:var(--tw-content);position:absolute}.after\:top-\[2px\]:after{content:var(--tw-content);top:2px}.after\:left-\[2px\]:after{content:var(--tw-content);left:2px}.after\:h-4:after{content:var(--tw-content);height:calc(var(--spacing)*4)}.after\:h-5:after{content:var(--tw-content);height:calc(var(--spacing)*5)}.after\:w-4:after{content:var(--tw-content);width:calc(var(--spacing)*4)}.after\:w-5:after{content:var(--tw-content);width:calc(var(--spacing)*5)}.after\:rounded-full:after{content:var(--tw-content);border-radius:3.40282e38px}.after\:border:after{content:var(--tw-content);border-style:var(--tw-border-style);border-width:1px}.after\:border-gray-300:after{content:var(--tw-content);border-color:var(--color-gray-300)}.after\:bg-white:after{content:var(--tw-content);background-color:var(--color-white)}.after\:transition-all:after{content:var(--tw-content);transition-property:all;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.after\:content-\[\'\'\]:after{--tw-content:"";content:var(--tw-content)}.peer-checked\:after\:translate-x-full:is(:where(.peer):checked~*):after{content:var(--tw-content);--tw-translate-x:100%;translate:var(--tw-translate-x)var(--tw-translate-y)}.peer-checked\:after\:border-white:is(:where(.peer):checked~*):after{content:var(--tw-content);border-color:var(--color-white)}.last\:border-0:last-child{border-style:var(--tw-border-style);border-width:0}.last\:border-b-0:last-child{border-bottom-style:var(--tw-border-style);border-bottom-width:0}@media(hover:hover){.hover\:z-20:hover{z-index:20}.hover\:scale-105:hover{--tw-scale-x:105%;--tw-scale-y:105%;--tw-scale-z:105%;scale:var(--tw-scale-x)var(--tw-scale-y)}.hover\:scale-110:hover{--tw-scale-x:110%;--tw-scale-y:110%;--tw-scale-z:110%;scale:var(--tw-scale-x)var(--tw-scale-y)}.hover\:border-bambu-dark-tertiary\/80:hover{border-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.hover\:border-bambu-dark-tertiary\/80:hover{border-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)80%,transparent)}}.hover\:border-bambu-gray:hover{border-color:var(--color-bambu-gray)}.hover\:border-bambu-gray-dark:hover{border-color:var(--color-bambu-gray-dark)}.hover\:border-bambu-gray\/50:hover{border-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.hover\:border-bambu-gray\/50:hover{border-color:color-mix(in oklab,var(--color-bambu-gray)50%,transparent)}}.hover\:border-bambu-green:hover,.hover\:border-bambu-green\/50:hover{border-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:border-bambu-green\/50:hover{border-color:color-mix(in oklab,var(--color-bambu-green)50%,transparent)}}.hover\:border-gray-400:hover{border-color:var(--color-gray-400)}.hover\:border-green-500\/50:hover{border-color:#00c75880}@supports (color:color-mix(in lab,red,red)){.hover\:border-green-500\/50:hover{border-color:color-mix(in oklab,var(--color-green-500)50%,transparent)}}.hover\:border-white:hover{border-color:var(--color-white)}.hover\:border-white\/40:hover{border-color:#fff6}@supports (color:color-mix(in lab,red,red)){.hover\:border-white\/40:hover{border-color:color-mix(in oklab,var(--color-white)40%,transparent)}}.hover\:\!bg-bambu-green\/80:hover{background-color:var(--color-bambu-green)!important}@supports (color:color-mix(in lab,red,red)){.hover\:\!bg-bambu-green\/80:hover{background-color:color-mix(in oklab,var(--color-bambu-green)80%,transparent)!important}}.hover\:\!bg-green-500\/20:hover{background-color:#00c75833!important}@supports (color:color-mix(in lab,red,red)){.hover\:\!bg-green-500\/20:hover{background-color:color-mix(in oklab,var(--color-green-500)20%,transparent)!important}}.hover\:\!bg-yellow-500\/20:hover{background-color:#edb20033!important}@supports (color:color-mix(in lab,red,red)){.hover\:\!bg-yellow-500\/20:hover{background-color:color-mix(in oklab,var(--color-yellow-500)20%,transparent)!important}}.hover\:bg-amber-400:hover{background-color:var(--color-amber-400)}.hover\:bg-amber-500\/30:hover{background-color:#f99c004d}@supports (color:color-mix(in lab,red,red)){.hover\:bg-amber-500\/30:hover{background-color:color-mix(in oklab,var(--color-amber-500)30%,transparent)}}.hover\:bg-bambu-dark:hover{background-color:var(--color-bambu-dark)}.hover\:bg-bambu-dark-secondary:hover,.hover\:bg-bambu-dark-secondary\/50:hover{background-color:var(--color-bambu-dark-secondary)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-dark-secondary\/50:hover{background-color:color-mix(in oklab,var(--color-bambu-dark-secondary)50%,transparent)}}.hover\:bg-bambu-dark-secondary\/80:hover{background-color:var(--color-bambu-dark-secondary)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-dark-secondary\/80:hover{background-color:color-mix(in oklab,var(--color-bambu-dark-secondary)80%,transparent)}}.hover\:bg-bambu-dark-tertiary:hover,.hover\:bg-bambu-dark-tertiary\/30:hover{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-dark-tertiary\/30:hover{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)30%,transparent)}}.hover\:bg-bambu-dark-tertiary\/50:hover{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-dark-tertiary\/50:hover{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)50%,transparent)}}.hover\:bg-bambu-dark-tertiary\/70:hover{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-dark-tertiary\/70:hover{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)70%,transparent)}}.hover\:bg-bambu-dark-tertiary\/80:hover{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-dark-tertiary\/80:hover{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)80%,transparent)}}.hover\:bg-bambu-dark\/50:hover{background-color:var(--color-bambu-dark)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-dark\/50:hover{background-color:color-mix(in oklab,var(--color-bambu-dark)50%,transparent)}}.hover\:bg-bambu-dark\/80:hover{background-color:var(--color-bambu-dark)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-dark\/80:hover{background-color:color-mix(in oklab,var(--color-bambu-dark)80%,transparent)}}.hover\:bg-bambu-gray-dark:hover{background-color:var(--color-bambu-gray-dark)}.hover\:bg-bambu-green:hover{background-color:var(--color-bambu-green)}.hover\:bg-bambu-green-dark:hover{background-color:var(--color-bambu-green-dark)}.hover\:bg-bambu-green-light:hover{background-color:var(--color-bambu-green-light)}.hover\:bg-bambu-green\/10:hover{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-green\/10:hover{background-color:color-mix(in oklab,var(--color-bambu-green)10%,transparent)}}.hover\:bg-bambu-green\/20:hover{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-green\/20:hover{background-color:color-mix(in oklab,var(--color-bambu-green)20%,transparent)}}.hover\:bg-bambu-green\/30:hover{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-green\/30:hover{background-color:color-mix(in oklab,var(--color-bambu-green)30%,transparent)}}.hover\:bg-bambu-green\/50:hover{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-green\/50:hover{background-color:color-mix(in oklab,var(--color-bambu-green)50%,transparent)}}.hover\:bg-bambu-green\/80:hover{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-green\/80:hover{background-color:color-mix(in oklab,var(--color-bambu-green)80%,transparent)}}.hover\:bg-black\/40:hover{background-color:#0006}@supports (color:color-mix(in lab,red,red)){.hover\:bg-black\/40:hover{background-color:color-mix(in oklab,var(--color-black)40%,transparent)}}.hover\:bg-black\/70:hover{background-color:#000000b3}@supports (color:color-mix(in lab,red,red)){.hover\:bg-black\/70:hover{background-color:color-mix(in oklab,var(--color-black)70%,transparent)}}.hover\:bg-black\/80:hover{background-color:#000c}@supports (color:color-mix(in lab,red,red)){.hover\:bg-black\/80:hover{background-color:color-mix(in oklab,var(--color-black)80%,transparent)}}.hover\:bg-blue-500\/30:hover{background-color:#3080ff4d}@supports (color:color-mix(in lab,red,red)){.hover\:bg-blue-500\/30:hover{background-color:color-mix(in oklab,var(--color-blue-500)30%,transparent)}}.hover\:bg-gray-50:hover{background-color:var(--color-gray-50)}.hover\:bg-gray-100:hover{background-color:var(--color-gray-100)}.hover\:bg-gray-200:hover{background-color:var(--color-gray-200)}.hover\:bg-gray-700:hover{background-color:var(--color-gray-700)}.hover\:bg-green-500\/20:hover{background-color:#00c75833}@supports (color:color-mix(in lab,red,red)){.hover\:bg-green-500\/20:hover{background-color:color-mix(in oklab,var(--color-green-500)20%,transparent)}}.hover\:bg-green-700:hover{background-color:var(--color-green-700)}.hover\:bg-orange-400\/20:hover{background-color:#ff8b1a33}@supports (color:color-mix(in lab,red,red)){.hover\:bg-orange-400\/20:hover{background-color:color-mix(in oklab,var(--color-orange-400)20%,transparent)}}.hover\:bg-purple-600\/90:hover{background-color:#9810fae6}@supports (color:color-mix(in lab,red,red)){.hover\:bg-purple-600\/90:hover{background-color:color-mix(in oklab,var(--color-purple-600)90%,transparent)}}.hover\:bg-red-200:hover{background-color:var(--color-red-200)}.hover\:bg-red-400\/10:hover{background-color:#ff65681a}@supports (color:color-mix(in lab,red,red)){.hover\:bg-red-400\/10:hover{background-color:color-mix(in oklab,var(--color-red-400)10%,transparent)}}.hover\:bg-red-500\/10:hover{background-color:#fb2c361a}@supports (color:color-mix(in lab,red,red)){.hover\:bg-red-500\/10:hover{background-color:color-mix(in oklab,var(--color-red-500)10%,transparent)}}.hover\:bg-red-500\/20:hover{background-color:#fb2c3633}@supports (color:color-mix(in lab,red,red)){.hover\:bg-red-500\/20:hover{background-color:color-mix(in oklab,var(--color-red-500)20%,transparent)}}.hover\:bg-red-500\/30:hover{background-color:#fb2c364d}@supports (color:color-mix(in lab,red,red)){.hover\:bg-red-500\/30:hover{background-color:color-mix(in oklab,var(--color-red-500)30%,transparent)}}.hover\:bg-red-600:hover{background-color:var(--color-red-600)}.hover\:bg-red-700:hover{background-color:var(--color-red-700)}.hover\:bg-white\/5:hover{background-color:#ffffff0d}@supports (color:color-mix(in lab,red,red)){.hover\:bg-white\/5:hover{background-color:color-mix(in oklab,var(--color-white)5%,transparent)}}.hover\:bg-white\/10:hover{background-color:#ffffff1a}@supports (color:color-mix(in lab,red,red)){.hover\:bg-white\/10:hover{background-color:color-mix(in oklab,var(--color-white)10%,transparent)}}.hover\:bg-white\/80:hover{background-color:#fffc}@supports (color:color-mix(in lab,red,red)){.hover\:bg-white\/80:hover{background-color:color-mix(in oklab,var(--color-white)80%,transparent)}}.hover\:bg-yellow-500\/30:hover{background-color:#edb2004d}@supports (color:color-mix(in lab,red,red)){.hover\:bg-yellow-500\/30:hover{background-color:color-mix(in oklab,var(--color-yellow-500)30%,transparent)}}.hover\:bg-yellow-600:hover{background-color:var(--color-yellow-600)}.hover\:bg-zinc-600:hover{background-color:var(--color-zinc-600)}.hover\:bg-zinc-700:hover{background-color:var(--color-zinc-700)}.hover\:bg-zinc-700\/50:hover{background-color:#3f3f4680}@supports (color:color-mix(in lab,red,red)){.hover\:bg-zinc-700\/50:hover{background-color:color-mix(in oklab,var(--color-zinc-700)50%,transparent)}}.hover\:bg-zinc-800:hover{background-color:var(--color-zinc-800)}.hover\:text-amber-300:hover{color:var(--color-amber-300)}.hover\:text-amber-800:hover{color:var(--color-amber-800)}.hover\:text-bambu-gray:hover{color:var(--color-bambu-gray)}.hover\:text-bambu-green:hover{color:var(--color-bambu-green)}.hover\:text-bambu-green-light:hover{color:var(--color-bambu-green-light)}.hover\:text-bambu-green\/70:hover{color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:text-bambu-green\/70:hover{color:color-mix(in oklab,var(--color-bambu-green)70%,transparent)}}.hover\:text-bambu-green\/80:hover{color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:text-bambu-green\/80:hover{color:color-mix(in oklab,var(--color-bambu-green)80%,transparent)}}.hover\:text-blue-300:hover{color:var(--color-blue-300)}.hover\:text-blue-600:hover{color:var(--color-blue-600)}.hover\:text-gray-600:hover{color:var(--color-gray-600)}.hover\:text-gray-900:hover{color:var(--color-gray-900)}.hover\:text-orange-300:hover{color:var(--color-orange-300)}.hover\:text-red-200:hover{color:var(--color-red-200)}.hover\:text-red-300:hover{color:var(--color-red-300)}.hover\:text-red-400:hover{color:var(--color-red-400)}.hover\:text-white:hover{color:var(--color-white)}.hover\:text-white\/70:hover{color:#ffffffb3}@supports (color:color-mix(in lab,red,red)){.hover\:text-white\/70:hover{color:color-mix(in oklab,var(--color-white)70%,transparent)}}.hover\:text-white\/80:hover{color:#fffc}@supports (color:color-mix(in lab,red,red)){.hover\:text-white\/80:hover{color:color-mix(in oklab,var(--color-white)80%,transparent)}}.hover\:text-yellow-400:hover{color:var(--color-yellow-400)}.hover\:text-zinc-200:hover{color:var(--color-zinc-200)}.hover\:text-zinc-300:hover{color:var(--color-zinc-300)}.hover\:underline:hover{text-decoration-line:underline}.hover\:opacity-70:hover{opacity:.7}.hover\:opacity-80:hover{opacity:.8}.hover\:shadow-lg:hover{--tw-shadow:0 10px 15px -3px var(--tw-shadow-color,#0000001a),0 4px 6px -4px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.hover\:shadow-xl:hover{--tw-shadow:0 20px 25px -5px var(--tw-shadow-color,#0000001a),0 8px 10px -6px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.hover\:shadow-bambu-green\/5:hover{--tw-shadow-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:shadow-bambu-green\/5:hover{--tw-shadow-color:color-mix(in oklab,color-mix(in oklab,var(--color-bambu-green)5%,transparent)var(--tw-shadow-alpha),transparent)}}.hover\:shadow-bambu-green\/30:hover{--tw-shadow-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:shadow-bambu-green\/30:hover{--tw-shadow-color:color-mix(in oklab,color-mix(in oklab,var(--color-bambu-green)30%,transparent)var(--tw-shadow-alpha),transparent)}}}.focus\:border-amber-500\/50:focus{border-color:#f99c0080}@supports (color:color-mix(in lab,red,red)){.focus\:border-amber-500\/50:focus{border-color:color-mix(in oklab,var(--color-amber-500)50%,transparent)}}.focus\:border-bambu-green:focus{border-color:var(--color-bambu-green)}.focus\:border-red-500:focus{border-color:var(--color-red-500)}.focus\:border-transparent:focus{border-color:#0000}.focus\:ring-1:focus{--tw-ring-shadow:var(--tw-ring-inset,)0 0 0 calc(1px + var(--tw-ring-offset-width))var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.focus\:ring-2:focus{--tw-ring-shadow:var(--tw-ring-inset,)0 0 0 calc(2px + var(--tw-ring-offset-width))var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.focus\:ring-bambu-gray:focus{--tw-ring-color:var(--color-bambu-gray)}.focus\:ring-bambu-green:focus,.focus\:ring-bambu-green\/50:focus{--tw-ring-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.focus\:ring-bambu-green\/50:focus{--tw-ring-color:color-mix(in oklab,var(--color-bambu-green)50%,transparent)}}.focus\:ring-blue-500:focus{--tw-ring-color:var(--color-blue-500)}.focus\:ring-red-500:focus{--tw-ring-color:var(--color-red-500)}.focus\:ring-offset-0:focus{--tw-ring-offset-width:0px;--tw-ring-offset-shadow:var(--tw-ring-inset,)0 0 0 var(--tw-ring-offset-width)var(--tw-ring-offset-color)}.focus\:ring-offset-2:focus{--tw-ring-offset-width:2px;--tw-ring-offset-shadow:var(--tw-ring-inset,)0 0 0 var(--tw-ring-offset-width)var(--tw-ring-offset-color)}.focus\:ring-offset-bambu-dark:focus{--tw-ring-offset-color:var(--color-bambu-dark)}.focus\:ring-offset-bambu-dark-secondary:focus{--tw-ring-offset-color:var(--color-bambu-dark-secondary)}.focus\:outline-none:focus{--tw-outline-style:none;outline-style:none}.active\:scale-95:active{--tw-scale-x:95%;--tw-scale-y:95%;--tw-scale-z:95%;scale:var(--tw-scale-x)var(--tw-scale-y)}.active\:cursor-grabbing:active{cursor:grabbing}.disabled\:cursor-not-allowed:disabled{cursor:not-allowed}.disabled\:opacity-30:disabled{opacity:.3}.disabled\:opacity-40:disabled{opacity:.4}.disabled\:opacity-50:disabled{opacity:.5}@media(hover:hover){.disabled\:hover\:bg-bambu-green:disabled:hover{background-color:var(--color-bambu-green)}}@media not all and (min-width:640px){.max-\[640px\]\:hidden{display:none}.max-\[640px\]\:w-full{width:100%}.max-\[640px\]\:grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.max-\[640px\]\:flex-col{flex-direction:column}.max-\[640px\]\:flex-wrap{flex-wrap:wrap}.max-\[640px\]\:items-center{align-items:center}.max-\[640px\]\:items-start{align-items:flex-start}}@media not all and (min-width:550px){.max-\[550px\]\:order-1{order:1}.max-\[550px\]\:order-2{order:2}.max-\[550px\]\:order-3{order:3}.max-\[550px\]\:order-4{order:4}.max-\[550px\]\:mt-1{margin-top:calc(var(--spacing)*1)}.max-\[550px\]\:w-full{width:100%}.max-\[550px\]\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.max-\[550px\]\:flex-col{flex-direction:column}.max-\[550px\]\:flex-wrap{flex-wrap:wrap}.max-\[550px\]\:items-center{align-items:center}.max-\[550px\]\:items-start{align-items:flex-start}.max-\[550px\]\:justify-end{justify-content:flex-end}.max-\[550px\]\:gap-1\.5{gap:calc(var(--spacing)*1.5)}.max-\[550px\]\:gap-3{gap:calc(var(--spacing)*3)}.max-\[550px\]\:self-start{align-self:flex-start}}@media(min-width:40rem){.sm\:col-span-1{grid-column:span 1/span 1}.sm\:mt-0{margin-top:calc(var(--spacing)*0)}.sm\:mt-2{margin-top:calc(var(--spacing)*2)}.sm\:mt-3{margin-top:calc(var(--spacing)*3)}.sm\:mr-1{margin-right:calc(var(--spacing)*1)}.sm\:mb-4{margin-bottom:calc(var(--spacing)*4)}.sm\:ml-auto{margin-left:auto}.sm\:block{display:block}.sm\:flex{display:flex}.sm\:grid{display:grid}.sm\:hidden{display:none}.sm\:inline{display:inline}.sm\:h-2{height:calc(var(--spacing)*2)}.sm\:h-3{height:calc(var(--spacing)*3)}.sm\:h-3\.5{height:calc(var(--spacing)*3.5)}.sm\:h-4{height:calc(var(--spacing)*4)}.sm\:h-5{height:calc(var(--spacing)*5)}.sm\:h-6{height:calc(var(--spacing)*6)}.sm\:h-10{height:calc(var(--spacing)*10)}.sm\:h-14{height:calc(var(--spacing)*14)}.sm\:w-3{width:calc(var(--spacing)*3)}.sm\:w-3\.5{width:calc(var(--spacing)*3.5)}.sm\:w-4{width:calc(var(--spacing)*4)}.sm\:w-5{width:calc(var(--spacing)*5)}.sm\:w-6{width:calc(var(--spacing)*6)}.sm\:w-10{width:calc(var(--spacing)*10)}.sm\:w-14{width:calc(var(--spacing)*14)}.sm\:w-16{width:calc(var(--spacing)*16)}.sm\:w-40{width:calc(var(--spacing)*40)}.sm\:w-auto{width:auto}.sm\:max-w-none{max-width:none}.sm\:max-w-xs{max-width:var(--container-xs)}.sm\:flex-1{flex:1}.sm\:flex-none{flex:none}.sm\:cursor-default{cursor:default}.sm\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.sm\:grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.sm\:grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}.sm\:flex-row{flex-direction:row}.sm\:items-center{align-items:center}.sm\:justify-between{justify-content:space-between}.sm\:gap-1{gap:calc(var(--spacing)*1)}.sm\:gap-1\.5{gap:calc(var(--spacing)*1.5)}.sm\:gap-2{gap:calc(var(--spacing)*2)}.sm\:gap-3{gap:calc(var(--spacing)*3)}.sm\:gap-4{gap:calc(var(--spacing)*4)}.sm\:gap-6{gap:calc(var(--spacing)*6)}:where(.sm\:space-y-3>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*3)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*3)*calc(1 - var(--tw-space-y-reverse)))}:where(.sm\:space-y-8>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*8)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*8)*calc(1 - var(--tw-space-y-reverse)))}.sm\:border-bambu-dark-tertiary{border-color:var(--color-bambu-dark-tertiary)}.sm\:p-1\.5{padding:calc(var(--spacing)*1.5)}.sm\:p-2{padding:calc(var(--spacing)*2)}.sm\:p-3{padding:calc(var(--spacing)*3)}.sm\:p-4{padding:calc(var(--spacing)*4)}.sm\:px-2{padding-inline:calc(var(--spacing)*2)}.sm\:px-3{padding-inline:calc(var(--spacing)*3)}.sm\:text-2xl{font-size:var(--text-2xl);line-height:var(--tw-leading,var(--text-2xl--line-height))}.sm\:text-base{font-size:var(--text-base);line-height:var(--tw-leading,var(--text-base--line-height))}.sm\:text-lg{font-size:var(--text-lg);line-height:var(--tw-leading,var(--text-lg--line-height))}.sm\:text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.sm\:text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}}@media(min-width:48rem){.md\:top-\[2px\]{top:2px}.md\:left-\[2px\]{left:2px}.md\:mx-0{margin-inline:calc(var(--spacing)*0)}.md\:block{display:block}.md\:inline{display:inline}.md\:h-4{height:calc(var(--spacing)*4)}.md\:h-5{height:calc(var(--spacing)*5)}.md\:min-h-0{min-height:calc(var(--spacing)*0)}.md\:w-4{width:calc(var(--spacing)*4)}.md\:w-9{width:calc(var(--spacing)*9)}.md\:min-w-\[200px\]{min-width:200px}.md\:flex-1{flex:1}.md\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.md\:grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.md\:grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}.md\:grid-cols-5{grid-template-columns:repeat(5,minmax(0,1fr))}.md\:flex-row{flex-direction:row}.md\:flex-wrap{flex-wrap:wrap}.md\:items-center{align-items:center}.md\:gap-4{gap:calc(var(--spacing)*4)}.md\:p-6{padding:calc(var(--spacing)*6)}.md\:p-8{padding:calc(var(--spacing)*8)}.md\:px-0{padding-inline:calc(var(--spacing)*0)}.md\:py-2{padding-block:calc(var(--spacing)*2)}.md\:pb-0{padding-bottom:calc(var(--spacing)*0)}}@media(min-width:64rem){.lg\:static{position:static}.lg\:col-span-2{grid-column:span 2/span 2}.lg\:col-span-3{grid-column:span 3/span 3}.lg\:flex{display:flex}.lg\:hidden{display:none}.lg\:h-\[calc\(100vh-64px\)\]{height:calc(100vh - 64px)}.lg\:w-1\/3{width:33.3333%}.lg\:w-2\/3{width:66.6667%}.lg\:w-80{width:calc(var(--spacing)*80)}.lg\:w-\[480px\]{width:480px}.lg\:max-w-md{max-width:var(--container-md)}.lg\:max-w-sm{max-width:var(--container-sm)}.lg\:max-w-xl{max-width:var(--container-xl)}.lg\:flex-shrink-0{flex-shrink:0}.lg\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.lg\:grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.lg\:grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}.lg\:grid-cols-5{grid-template-columns:repeat(5,minmax(0,1fr))}.lg\:flex-row{flex-direction:row}.lg\:gap-4{gap:calc(var(--spacing)*4)}.lg\:gap-6{gap:calc(var(--spacing)*6)}.lg\:gap-8{gap:calc(var(--spacing)*8)}.lg\:overflow-y-auto{overflow-y:auto}.lg\:p-8{padding:calc(var(--spacing)*8)}}@media(min-width:80rem){.xl\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.xl\:grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.xl\:grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}.xl\:grid-cols-5{grid-template-columns:repeat(5,minmax(0,1fr))}.xl\:grid-cols-6{grid-template-columns:repeat(6,minmax(0,1fr))}}@media(min-width:96rem){.\32xl\:grid-cols-6{grid-template-columns:repeat(6,minmax(0,1fr))}}.dark\:border-amber-700:where(.dark,.dark *){border-color:var(--color-amber-700)}.dark\:border-amber-800:where(.dark,.dark *){border-color:var(--color-amber-800)}.dark\:border-bambu-dark-tertiary:where(.dark,.dark *),.dark\:border-bambu-dark-tertiary\/50:where(.dark,.dark *){border-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.dark\:border-bambu-dark-tertiary\/50:where(.dark,.dark *){border-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)50%,transparent)}}.dark\:border-bambu-green\/40:where(.dark,.dark *){border-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.dark\:border-bambu-green\/40:where(.dark,.dark *){border-color:color-mix(in oklab,var(--color-bambu-green)40%,transparent)}}.dark\:border-gray-600:where(.dark,.dark *){border-color:var(--color-gray-600)}.dark\:border-gray-700:where(.dark,.dark *){border-color:var(--color-gray-700)}.dark\:border-red-500\/30:where(.dark,.dark *){border-color:#fb2c364d}@supports (color:color-mix(in lab,red,red)){.dark\:border-red-500\/30:where(.dark,.dark *){border-color:color-mix(in oklab,var(--color-red-500)30%,transparent)}}.dark\:border-red-500\/40:where(.dark,.dark *){border-color:#fb2c3666}@supports (color:color-mix(in lab,red,red)){.dark\:border-red-500\/40:where(.dark,.dark *){border-color:color-mix(in oklab,var(--color-red-500)40%,transparent)}}.dark\:bg-amber-500\/10:where(.dark,.dark *){background-color:#f99c001a}@supports (color:color-mix(in lab,red,red)){.dark\:bg-amber-500\/10:where(.dark,.dark *){background-color:color-mix(in oklab,var(--color-amber-500)10%,transparent)}}.dark\:bg-amber-900\/20:where(.dark,.dark *){background-color:#7b330633}@supports (color:color-mix(in lab,red,red)){.dark\:bg-amber-900\/20:where(.dark,.dark *){background-color:color-mix(in oklab,var(--color-amber-900)20%,transparent)}}.dark\:bg-bambu-dark:where(.dark,.dark *){background-color:var(--color-bambu-dark)}.dark\:bg-bambu-dark-secondary:where(.dark,.dark *){background-color:var(--color-bambu-dark-secondary)}.dark\:bg-bambu-green\/20:where(.dark,.dark *){background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.dark\:bg-bambu-green\/20:where(.dark,.dark *){background-color:color-mix(in oklab,var(--color-bambu-green)20%,transparent)}}.dark\:bg-black\/80:where(.dark,.dark *){background-color:#000c}@supports (color:color-mix(in lab,red,red)){.dark\:bg-black\/80:where(.dark,.dark *){background-color:color-mix(in oklab,var(--color-black)80%,transparent)}}.dark\:bg-blue-500\/10:where(.dark,.dark *){background-color:#3080ff1a}@supports (color:color-mix(in lab,red,red)){.dark\:bg-blue-500\/10:where(.dark,.dark *){background-color:color-mix(in oklab,var(--color-blue-500)10%,transparent)}}.dark\:bg-blue-500\/20:where(.dark,.dark *){background-color:#3080ff33}@supports (color:color-mix(in lab,red,red)){.dark\:bg-blue-500\/20:where(.dark,.dark *){background-color:color-mix(in oklab,var(--color-blue-500)20%,transparent)}}.dark\:bg-blue-900\/20:where(.dark,.dark *){background-color:#1c398e33}@supports (color:color-mix(in lab,red,red)){.dark\:bg-blue-900\/20:where(.dark,.dark *){background-color:color-mix(in oklab,var(--color-blue-900)20%,transparent)}}.dark\:bg-gray-700:where(.dark,.dark *){background-color:var(--color-gray-700)}.dark\:bg-gray-800:where(.dark,.dark *){background-color:var(--color-gray-800)}.dark\:bg-gray-900:where(.dark,.dark *){background-color:var(--color-gray-900)}.dark\:bg-red-500\/10:where(.dark,.dark *){background-color:#fb2c361a}@supports (color:color-mix(in lab,red,red)){.dark\:bg-red-500\/10:where(.dark,.dark *){background-color:color-mix(in oklab,var(--color-red-500)10%,transparent)}}.dark\:bg-red-500\/20:where(.dark,.dark *){background-color:#fb2c3633}@supports (color:color-mix(in lab,red,red)){.dark\:bg-red-500\/20:where(.dark,.dark *){background-color:color-mix(in oklab,var(--color-red-500)20%,transparent)}}.dark\:text-amber-200:where(.dark,.dark *){color:var(--color-amber-200)}.dark\:text-amber-300:where(.dark,.dark *){color:var(--color-amber-300)}.dark\:text-amber-400:where(.dark,.dark *){color:var(--color-amber-400)}.dark\:text-bambu-gray:where(.dark,.dark *),.dark\:text-bambu-gray\/30:where(.dark,.dark *){color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.dark\:text-bambu-gray\/30:where(.dark,.dark *){color:color-mix(in oklab,var(--color-bambu-gray)30%,transparent)}}.dark\:text-bambu-gray\/50:where(.dark,.dark *){color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.dark\:text-bambu-gray\/50:where(.dark,.dark *){color:color-mix(in oklab,var(--color-bambu-gray)50%,transparent)}}.dark\:text-bambu-green:where(.dark,.dark *),.dark\:text-bambu-green\/60:where(.dark,.dark *){color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.dark\:text-bambu-green\/60:where(.dark,.dark *){color:color-mix(in oklab,var(--color-bambu-green)60%,transparent)}}.dark\:text-blue-200:where(.dark,.dark *){color:var(--color-blue-200)}.dark\:text-blue-200\/80:where(.dark,.dark *){color:#bedbffcc}@supports (color:color-mix(in lab,red,red)){.dark\:text-blue-200\/80:where(.dark,.dark *){color:color-mix(in oklab,var(--color-blue-200)80%,transparent)}}.dark\:text-blue-300:where(.dark,.dark *){color:var(--color-blue-300)}.dark\:text-blue-300\/60:where(.dark,.dark *){color:#90c5ff99}@supports (color:color-mix(in lab,red,red)){.dark\:text-blue-300\/60:where(.dark,.dark *){color:color-mix(in oklab,var(--color-blue-300)60%,transparent)}}.dark\:text-blue-400:where(.dark,.dark *){color:var(--color-blue-400)}.dark\:text-gray-300:where(.dark,.dark *){color:var(--color-gray-300)}.dark\:text-gray-400:where(.dark,.dark *){color:var(--color-gray-400)}.dark\:text-orange-200:where(.dark,.dark *){color:var(--color-orange-200)}.dark\:text-orange-400:where(.dark,.dark *){color:var(--color-orange-400)}.dark\:text-red-400:where(.dark,.dark *){color:var(--color-red-400)}.dark\:text-red-400\/70:where(.dark,.dark *){color:#ff6568b3}@supports (color:color-mix(in lab,red,red)){.dark\:text-red-400\/70:where(.dark,.dark *){color:color-mix(in oklab,var(--color-red-400)70%,transparent)}}.dark\:text-white:where(.dark,.dark *){color:var(--color-white)}.dark\:text-yellow-200:where(.dark,.dark *){color:var(--color-yellow-200)}.dark\:text-yellow-200\/70:where(.dark,.dark *){color:#fff085b3}@supports (color:color-mix(in lab,red,red)){.dark\:text-yellow-200\/70:where(.dark,.dark *){color:color-mix(in oklab,var(--color-yellow-200)70%,transparent)}}@media(hover:hover){.dark\:hover\:border-gray-500:where(.dark,.dark *):hover{border-color:var(--color-gray-500)}.dark\:hover\:bg-bambu-dark-tertiary:where(.dark,.dark *):hover{background-color:var(--color-bambu-dark-tertiary)}.dark\:hover\:bg-bambu-dark\/50:where(.dark,.dark *):hover{background-color:var(--color-bambu-dark)}@supports (color:color-mix(in lab,red,red)){.dark\:hover\:bg-bambu-dark\/50:where(.dark,.dark *):hover{background-color:color-mix(in oklab,var(--color-bambu-dark)50%,transparent)}}.dark\:hover\:bg-gray-600:where(.dark,.dark *):hover{background-color:var(--color-gray-600)}.dark\:hover\:bg-red-500\/30:where(.dark,.dark *):hover{background-color:#fb2c364d}@supports (color:color-mix(in lab,red,red)){.dark\:hover\:bg-red-500\/30:where(.dark,.dark *):hover{background-color:color-mix(in oklab,var(--color-red-500)30%,transparent)}}.dark\:hover\:text-amber-200:where(.dark,.dark *):hover{color:var(--color-amber-200)}.dark\:hover\:text-gray-300:where(.dark,.dark *):hover{color:var(--color-gray-300)}.dark\:hover\:text-white:where(.dark,.dark *):hover{color:var(--color-white)}}.\[\&\:\:-webkit-inner-spin-button\]\:appearance-none::-webkit-inner-spin-button{appearance:none}.\[\&\:\:-webkit-outer-spin-button\]\:appearance-none::-webkit-outer-spin-button{appearance:none}.\[\&\:\:-webkit-slider-thumb\]\:h-3::-webkit-slider-thumb{height:calc(var(--spacing)*3)}.\[\&\:\:-webkit-slider-thumb\]\:w-3::-webkit-slider-thumb{width:calc(var(--spacing)*3)}.\[\&\:\:-webkit-slider-thumb\]\:cursor-pointer::-webkit-slider-thumb{cursor:pointer}.\[\&\:\:-webkit-slider-thumb\]\:appearance-none::-webkit-slider-thumb{appearance:none}.\[\&\:\:-webkit-slider-thumb\]\:rounded-full::-webkit-slider-thumb{border-radius:3.40282e38px}.\[\&\:\:-webkit-slider-thumb\]\:bg-bambu-green::-webkit-slider-thumb{background-color:var(--color-bambu-green)}}:root{--accent:#00ae42;--accent-light:#00c64d;--accent-dark:#009438;--status-ok:#22c55e;--status-error:#ef4444;--status-warning:#f59e0b;--bg-primary:#f5f5f5;--bg-secondary:#fff;--bg-tertiary:#e5e5e5;--text-primary:#1a1a1a;--text-secondary:#4a4a4a;--text-muted:#6b6b6b;--text-tertiary:gray;--border-color:#d4d4d4;--card-shadow:0 2px 8px #00000014;--glow-color:transparent;font-synthesis:none;text-rendering:optimizeLegibility;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-family:Inter,system-ui,sans-serif;font-weight:400;line-height:1.5}.dark{--bg-primary:#1a1a1a;--bg-secondary:#2d2d2d;--bg-tertiary:#3d3d3d;--text-primary:#fff;--text-secondary:#a0a0a0;--text-muted:gray;--text-tertiary:#4a4a4a;--border-color:#3d3d3d;--card-shadow:0 4px 16px #0006}.bg-warm{--bg-primary:#faf8f5;--bg-secondary:#fffefa;--bg-tertiary:#e8e4dd;--text-primary:#2d2a26;--text-secondary:#5c5750;--text-muted:#7a756c;--text-tertiary:#9a9590;--border-color:#d8d4cc}.bg-cool{--bg-primary:#f0f4f8;--bg-secondary:#fff;--bg-tertiary:#dce4ec;--text-primary:#1a2530;--text-secondary:#4a5568;--text-muted:#6b7a8a;--text-tertiary:#8a9aaa;--border-color:#c8d4e0}.dark.bg-neutral{--bg-primary:#1a1a1a;--bg-secondary:#2d2d2d;--bg-tertiary:#3d3d3d;--text-primary:#fff;--text-secondary:#a0a0a0;--text-muted:gray;--text-tertiary:#4a4a4a;--border-color:#3d3d3d}.dark.bg-warm{--bg-primary:#1c1a18;--bg-secondary:#2e2a26;--bg-tertiary:#3e3a36;--text-primary:#f5f0ea;--text-secondary:#b0a898;--text-muted:#8a8278;--text-tertiary:#5a5248;--border-color:#3e3a36}.dark.bg-cool{--bg-primary:#181c20;--bg-secondary:#262c32;--bg-tertiary:#363e46;--text-primary:#f0f4f8;--text-secondary:#98a8b8;--text-muted:#788898;--text-tertiary:#4a5a6a;--border-color:#363e46}.dark.bg-oled{--bg-primary:#000;--bg-secondary:#141414;--bg-tertiary:#1f1f1f;--text-primary:#fff;--text-secondary:#a0a0a0;--text-muted:#707070;--text-tertiary:#404040;--border-color:#2a2a2a}.dark.bg-slate{--bg-primary:#0f172a;--bg-secondary:#1e293b;--bg-tertiary:#334155;--text-primary:#f1f5f9;--text-secondary:#94a3b8;--text-muted:#64748b;--text-tertiary:#475569;--border-color:#334155}.dark.bg-forest{--bg-primary:#121a16;--bg-secondary:#1c2a22;--bg-tertiary:#2a3d30;--text-primary:#e8f5ec;--text-secondary:#8aa894;--text-muted:#6a8874;--text-tertiary:#4a6854;--border-color:#2a3d30}.printer-control-buttons-container{container-type:inline-size}@container (max-width:220px){.printer-control-buttons{flex-direction:column;align-items:stretch}.printer-control-buttons>button{width:100%}}.style-glow{--card-shadow:0 2px 8px #00000014,0 0 25px var(--accent)}@supports (color:color-mix(in lab,red,red)){.style-glow{--card-shadow:0 2px 8px #00000014,0 0 25px color-mix(in srgb,var(--accent)12%,transparent)}}.dark.style-glow{--card-shadow:0 4px 20px #00000080,0 0 40px var(--accent)}@supports (color:color-mix(in lab,red,red)){.dark.style-glow{--card-shadow:0 4px 20px #00000080,0 0 40px color-mix(in srgb,var(--accent)15%,transparent)}}.style-vibrant{--card-shadow:0 8px 30px #00000026,0 2px 8px #0000001a}.dark.style-vibrant{--card-shadow:0 10px 40px #0009,0 4px 12px #0006}.accent-green{--accent:#00ae42;--accent-light:#00c64d;--accent-dark:#009438}.accent-teal{--accent:#14b8a6;--accent-light:#2dd4bf;--accent-dark:#0d9488}.accent-blue{--accent:#3b82f6;--accent-light:#60a5fa;--accent-dark:#2563eb}.accent-orange{--accent:#f97316;--accent-light:#fb923c;--accent-dark:#ea580c}.accent-purple{--accent:#8b5cf6;--accent-light:#a78bfa;--accent-dark:#7c3aed}.accent-red{--accent:#ef4444;--accent-light:#f87171;--accent-dark:#dc2626}body{background-color:var(--bg-primary);color:var(--text-primary);min-height:100vh;margin:0;transition:background-color .2s,color .2s}#root{min-height:100vh}.text-white{color:var(--text-primary)}.bg-bambu-dark,.bg-bambu-dark-secondary,.bg-bambu-dark-tertiary,.border-bambu-dark-tertiary{transition:background-color .2s,border-color .2s}@keyframes slide-in{0%{opacity:0;transform:translate(100%)}to{opacity:1;transform:translate(0)}}.animate-slide-in{animation:.2s ease-out slide-in}.icon-theme{opacity:.5}.dark .icon-theme{filter:invert();opacity:.4}.icon-green{filter:invert(48%)sepia(89%)saturate(459%)hue-rotate(93deg)brightness(95%)contrast(92%);opacity:1}.icon-heating{filter:invert(50%)sepia()saturate(1000%)hue-rotate(360deg)brightness()contrast();opacity:1}.dark .jogpad-theme{filter:brightness(.35)contrast(1.2)}.ams-empty-slot{background:repeating-linear-gradient(45deg,#444,#444 2px,#222 2px 4px)}.dark .ams-empty-slot{background:repeating-linear-gradient(45deg,#555,#555 2px,#333 2px 4px)}.touch-manipulation{touch-action:manipulation}.safe-area-bottom{padding-bottom:env(safe-area-inset-bottom,0)}.safe-area-top{padding-top:env(safe-area-inset-top,0)}.scrollbar-hide{-ms-overflow-style:none;scrollbar-width:none}.scrollbar-hide::-webkit-scrollbar{display:none}@keyframes slide-in-left{0%{transform:translate(-100%)}to{transform:translate(0)}}.animate-slide-in-left{animation:.3s ease-out slide-in-left}.card-shadow{box-shadow:var(--card-shadow)}.calendar-scroll{scrollbar-width:thin;scrollbar-color:var(--text-muted)transparent}@supports (color:color-mix(in lab,red,red)){.calendar-scroll{scrollbar-color:color-mix(in srgb,var(--text-muted)60%,transparent)transparent}}.calendar-scroll::-webkit-scrollbar{width:8px}.calendar-scroll::-webkit-scrollbar-track{background:0 0}.calendar-scroll::-webkit-scrollbar-thumb{background-color:var(--text-muted)}@supports (color:color-mix(in lab,red,red)){.calendar-scroll::-webkit-scrollbar-thumb{background-color:color-mix(in srgb,var(--text-muted)60%,transparent)}}.calendar-scroll::-webkit-scrollbar-thumb{border:2px solid var(--bg-secondary);border-radius:999px}@supports (color:color-mix(in lab,red,red)){.calendar-scroll::-webkit-scrollbar-thumb{border:2px solid color-mix(in srgb,var(--bg-secondary)70%,transparent)}}.calendar-scroll::-webkit-scrollbar-thumb:hover{background-color:var(--text-muted)}@supports (color:color-mix(in lab,red,red)){.calendar-scroll::-webkit-scrollbar-thumb:hover{background-color:color-mix(in srgb,var(--text-muted)80%,transparent)}}@property --tw-translate-x{syntax:"*";inherits:false;initial-value:0}@property --tw-translate-y{syntax:"*";inherits:false;initial-value:0}@property --tw-translate-z{syntax:"*";inherits:false;initial-value:0}@property --tw-scale-x{syntax:"*";inherits:false;initial-value:1}@property --tw-scale-y{syntax:"*";inherits:false;initial-value:1}@property --tw-scale-z{syntax:"*";inherits:false;initial-value:1}@property --tw-rotate-x{syntax:"*";inherits:false}@property --tw-rotate-y{syntax:"*";inherits:false}@property --tw-rotate-z{syntax:"*";inherits:false}@property --tw-skew-x{syntax:"*";inherits:false}@property --tw-skew-y{syntax:"*";inherits:false}@property --tw-space-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-divide-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-gradient-position{syntax:"*";inherits:false}@property --tw-gradient-from{syntax:"";inherits:false;initial-value:#0000}@property --tw-gradient-via{syntax:"";inherits:false;initial-value:#0000}@property --tw-gradient-to{syntax:"";inherits:false;initial-value:#0000}@property --tw-gradient-stops{syntax:"*";inherits:false}@property --tw-gradient-via-stops{syntax:"*";inherits:false}@property --tw-gradient-from-position{syntax:"";inherits:false;initial-value:0%}@property --tw-gradient-via-position{syntax:"";inherits:false;initial-value:50%}@property --tw-gradient-to-position{syntax:"";inherits:false;initial-value:100%}@property --tw-leading{syntax:"*";inherits:false}@property --tw-font-weight{syntax:"*";inherits:false}@property --tw-tracking{syntax:"*";inherits:false}@property --tw-ordinal{syntax:"*";inherits:false}@property --tw-slashed-zero{syntax:"*";inherits:false}@property --tw-numeric-figure{syntax:"*";inherits:false}@property --tw-numeric-spacing{syntax:"*";inherits:false}@property --tw-numeric-fraction{syntax:"*";inherits:false}@property --tw-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:"*";inherits:false}@property --tw-shadow-alpha{syntax:"";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:"*";inherits:false}@property --tw-inset-shadow-alpha{syntax:"";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:"*";inherits:false}@property --tw-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:"*";inherits:false}@property --tw-inset-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:"*";inherits:false}@property --tw-ring-offset-width{syntax:"";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:"*";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-outline-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-blur{syntax:"*";inherits:false}@property --tw-brightness{syntax:"*";inherits:false}@property --tw-contrast{syntax:"*";inherits:false}@property --tw-grayscale{syntax:"*";inherits:false}@property --tw-hue-rotate{syntax:"*";inherits:false}@property --tw-invert{syntax:"*";inherits:false}@property --tw-opacity{syntax:"*";inherits:false}@property --tw-saturate{syntax:"*";inherits:false}@property --tw-sepia{syntax:"*";inherits:false}@property --tw-drop-shadow{syntax:"*";inherits:false}@property --tw-drop-shadow-color{syntax:"*";inherits:false}@property --tw-drop-shadow-alpha{syntax:"";inherits:false;initial-value:100%}@property --tw-drop-shadow-size{syntax:"*";inherits:false}@property --tw-backdrop-blur{syntax:"*";inherits:false}@property --tw-backdrop-brightness{syntax:"*";inherits:false}@property --tw-backdrop-contrast{syntax:"*";inherits:false}@property --tw-backdrop-grayscale{syntax:"*";inherits:false}@property --tw-backdrop-hue-rotate{syntax:"*";inherits:false}@property --tw-backdrop-invert{syntax:"*";inherits:false}@property --tw-backdrop-opacity{syntax:"*";inherits:false}@property --tw-backdrop-saturate{syntax:"*";inherits:false}@property --tw-backdrop-sepia{syntax:"*";inherits:false}@property --tw-duration{syntax:"*";inherits:false}@property --tw-ease{syntax:"*";inherits:false}@property --tw-content{syntax:"*";inherits:false;initial-value:""}@keyframes spin{to{transform:rotate(360deg)}}@keyframes ping{75%,to{opacity:0;transform:scale(2)}}@keyframes pulse{50%{opacity:.5}}@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-translate-x:0;--tw-translate-y:0;--tw-translate-z:0;--tw-scale-x:1;--tw-scale-y:1;--tw-scale-z:1;--tw-rotate-x:initial;--tw-rotate-y:initial;--tw-rotate-z:initial;--tw-skew-x:initial;--tw-skew-y:initial;--tw-space-y-reverse:0;--tw-divide-y-reverse:0;--tw-border-style:solid;--tw-gradient-position:initial;--tw-gradient-from:#0000;--tw-gradient-via:#0000;--tw-gradient-to:#0000;--tw-gradient-stops:initial;--tw-gradient-via-stops:initial;--tw-gradient-from-position:0%;--tw-gradient-via-position:50%;--tw-gradient-to-position:100%;--tw-leading:initial;--tw-font-weight:initial;--tw-tracking:initial;--tw-ordinal:initial;--tw-slashed-zero:initial;--tw-numeric-figure:initial;--tw-numeric-spacing:initial;--tw-numeric-fraction:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-outline-style:solid;--tw-blur:initial;--tw-brightness:initial;--tw-contrast:initial;--tw-grayscale:initial;--tw-hue-rotate:initial;--tw-invert:initial;--tw-opacity:initial;--tw-saturate:initial;--tw-sepia:initial;--tw-drop-shadow:initial;--tw-drop-shadow-color:initial;--tw-drop-shadow-alpha:100%;--tw-drop-shadow-size:initial;--tw-backdrop-blur:initial;--tw-backdrop-brightness:initial;--tw-backdrop-contrast:initial;--tw-backdrop-grayscale:initial;--tw-backdrop-hue-rotate:initial;--tw-backdrop-invert:initial;--tw-backdrop-opacity:initial;--tw-backdrop-saturate:initial;--tw-backdrop-sepia:initial;--tw-duration:initial;--tw-ease:initial;--tw-content:""}}}.hg-theme-default{background-color:#ececec;border-radius:5px;box-sizing:border-box;font-family:HelveticaNeue-Light,Helvetica Neue Light,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;overflow:hidden;padding:5px;touch-action:manipulation;-webkit-user-select:none;-moz-user-select:none;user-select:none;width:100%}.hg-theme-default .hg-button span,.hg-theme-default .hg-button span svg{pointer-events:none}.hg-theme-default button.hg-button{border-width:0;font-size:inherit}.hg-theme-default .hg-button{display:inline-block;flex-grow:1}.hg-theme-default .hg-row{display:flex}.hg-theme-default .hg-row:not(:last-child){margin-bottom:5px}.hg-theme-default .hg-row .hg-button-container,.hg-theme-default .hg-row .hg-button:not(:last-child){margin-right:5px}.hg-theme-default .hg-row>div:last-child{margin-right:0}.hg-theme-default .hg-row .hg-button-container{display:flex}.hg-theme-default .hg-button{align-items:center;background:#fff;border-bottom:1px solid #b5b5b5;border-radius:5px;box-shadow:0 0 3px -1px #0000004d;box-sizing:border-box;cursor:pointer;display:flex;height:40px;justify-content:center;padding:5px;-webkit-tap-highlight-color:rgba(0,0,0,0)}.hg-theme-default .hg-button.hg-standardBtn{width:20px}.hg-theme-default .hg-button.hg-activeButton{background:#efefef}.hg-theme-default.hg-layout-numeric .hg-button{align-items:center;display:flex;height:60px;justify-content:center;width:33.3%}.hg-theme-default .hg-button.hg-button-numpadadd,.hg-theme-default .hg-button.hg-button-numpadenter{height:85px}.hg-theme-default .hg-button.hg-button-numpad0{width:105px}.hg-theme-default .hg-button.hg-button-com{max-width:85px}.hg-theme-default .hg-button.hg-standardBtn.hg-button-at{max-width:45px}.hg-theme-default .hg-button.hg-selectedButton{background:#05194687;color:#fff}.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=".com"]{max-width:82px}.hg-theme-default .hg-button.hg-standardBtn[data-skbtn="@"]{max-width:60px}.hg-candidate-box{background:#ececec;border-bottom:2px solid #b5b5b5;border-radius:5px;display:inline-flex;margin-top:-10px;position:absolute;transform:translateY(-100%);-webkit-user-select:none;-moz-user-select:none;user-select:none}ul.hg-candidate-box-list{display:flex;flex:1;list-style:none;margin:0;padding:0}li.hg-candidate-box-list-item{align-items:center;display:flex;height:40px;justify-content:center;width:40px}li.hg-candidate-box-list-item:hover{background:#00000008;cursor:pointer}li.hg-candidate-box-list-item:active{background:#0000001a}.hg-candidate-box-prev:before{content:"◄"}.hg-candidate-box-next:before{content:"►"}.hg-candidate-box-next,.hg-candidate-box-prev{align-items:center;color:#969696;cursor:pointer;display:flex;padding:0 10px}.hg-candidate-box-next{border-bottom-right-radius:5px;border-top-right-radius:5px}.hg-candidate-box-prev{border-bottom-left-radius:5px;border-top-left-radius:5px}.hg-candidate-box-btn-active{color:#444}.simple-keyboard.vkb-theme{background:#1a1a1a;border-top:1px solid #333;padding:8px 4px;font-family:inherit}.simple-keyboard.vkb-theme .hg-row{display:flex!important;flex-direction:row!important;flex-wrap:nowrap!important;gap:4px;margin-bottom:4px}.simple-keyboard.vkb-theme .hg-row:last-child{margin-bottom:0}.simple-keyboard.vkb-theme .hg-button{display:inline-flex!important;align-items:center;justify-content:center;flex-grow:1;flex-shrink:1;flex-basis:auto;background:#2d2d2d;color:#e0e0e0;border:none;border-radius:6px;height:44px;font-size:16px;font-weight:500;box-shadow:0 1px 2px #0000004d;transition:background .1s;cursor:pointer;padding:0 2px;min-width:0}.simple-keyboard.vkb-theme .hg-button:active{background:#00ae42;color:#fff}.simple-keyboard.vkb-theme .hg-button-bksp,.simple-keyboard.vkb-theme .hg-button-shift,.simple-keyboard.vkb-theme .hg-button-lock{background:#3a3a3a;color:#aaa;flex-grow:1.5}.simple-keyboard.vkb-theme .hg-button-close{background:#3a3a3a;color:#aaa;flex-grow:2;font-weight:600}.simple-keyboard.vkb-theme .hg-button-close:active{background:#555}.simple-keyboard.vkb-theme .hg-button-space{flex-grow:7}.simple-keyboard.vkb-theme .hg-activeButton{background:#00ae42;color:#fff} diff --git a/static/assets/index-hKLgfdEQ.css b/static/assets/index-hKLgfdEQ.css new file mode 100644 index 000000000..d9a4bed24 --- /dev/null +++ b/static/assets/index-hKLgfdEQ.css @@ -0,0 +1 @@ +@import"https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap";@layer properties,theme,base,components,utilities;@layer theme{:root,:host{--font-sans:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--font-mono:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;--color-red-50:oklch(97.1% .013 17.38);--color-red-100:oklch(93.6% .032 17.717);--color-red-200:oklch(88.5% .062 18.334);--color-red-300:oklch(80.8% .114 19.571);--color-red-400:oklch(70.4% .191 22.216);--color-red-500:oklch(63.7% .237 25.331);--color-red-600:oklch(57.7% .245 27.325);--color-red-700:oklch(50.5% .213 27.518);--color-red-800:oklch(44.4% .177 26.899);--color-red-900:oklch(39.6% .141 25.723);--color-red-950:oklch(25.8% .092 26.042);--color-orange-200:oklch(90.1% .076 70.697);--color-orange-300:oklch(83.7% .128 66.29);--color-orange-400:oklch(75% .183 55.934);--color-orange-500:oklch(70.5% .213 47.604);--color-orange-600:oklch(64.6% .222 41.116);--color-orange-700:oklch(55.3% .195 38.402);--color-amber-50:oklch(98.7% .022 95.277);--color-amber-200:oklch(92.4% .12 95.746);--color-amber-300:oklch(87.9% .169 91.605);--color-amber-400:oklch(82.8% .189 84.429);--color-amber-500:oklch(76.9% .188 70.08);--color-amber-600:oklch(66.6% .179 58.318);--color-amber-700:oklch(55.5% .163 48.998);--color-amber-800:oklch(47.3% .137 46.201);--color-amber-900:oklch(41.4% .112 45.904);--color-yellow-200:oklch(94.5% .129 101.54);--color-yellow-300:oklch(90.5% .182 98.111);--color-yellow-400:oklch(85.2% .199 91.936);--color-yellow-500:oklch(79.5% .184 86.047);--color-yellow-600:oklch(68.1% .162 75.834);--color-yellow-700:oklch(55.4% .135 66.442);--color-lime-500:oklch(76.8% .233 130.85);--color-green-100:oklch(96.2% .044 156.743);--color-green-200:oklch(92.5% .084 155.995);--color-green-300:oklch(87.1% .15 154.449);--color-green-400:oklch(79.2% .209 151.711);--color-green-500:oklch(72.3% .219 149.579);--color-green-600:oklch(62.7% .194 149.214);--color-green-700:oklch(52.7% .154 150.069);--color-green-800:oklch(44.8% .119 151.328);--color-green-900:oklch(39.3% .095 152.535);--color-emerald-300:oklch(84.5% .143 164.978);--color-emerald-400:oklch(76.5% .177 163.223);--color-emerald-500:oklch(69.6% .17 162.48);--color-emerald-600:oklch(59.6% .145 163.225);--color-emerald-700:oklch(50.8% .118 165.612);--color-teal-400:oklch(77.7% .152 181.912);--color-teal-500:oklch(70.4% .14 182.503);--color-cyan-300:oklch(86.5% .127 207.078);--color-cyan-400:oklch(78.9% .154 211.53);--color-cyan-500:oklch(71.5% .143 215.221);--color-cyan-600:oklch(60.9% .126 221.723);--color-sky-400:oklch(74.6% .16 232.661);--color-sky-500:oklch(68.5% .169 237.323);--color-blue-50:oklch(97% .014 254.604);--color-blue-100:oklch(93.2% .032 255.585);--color-blue-200:oklch(88.2% .059 254.128);--color-blue-300:oklch(80.9% .105 251.813);--color-blue-400:oklch(70.7% .165 254.624);--color-blue-500:oklch(62.3% .214 259.815);--color-blue-600:oklch(54.6% .245 262.881);--color-blue-700:oklch(48.8% .243 264.376);--color-blue-900:oklch(37.9% .146 265.522);--color-indigo-400:oklch(67.3% .182 276.935);--color-indigo-500:oklch(58.5% .233 277.117);--color-violet-500:oklch(60.6% .25 292.717);--color-purple-300:oklch(82.7% .119 306.383);--color-purple-400:oklch(71.4% .203 305.504);--color-purple-500:oklch(62.7% .265 303.9);--color-purple-600:oklch(55.8% .288 302.321);--color-purple-700:oklch(49.6% .265 301.924);--color-fuchsia-500:oklch(66.7% .295 322.15);--color-rose-300:oklch(81% .117 11.638);--color-rose-400:oklch(71.2% .194 13.428);--color-rose-500:oklch(64.5% .246 16.439);--color-rose-600:oklch(58.6% .253 17.585);--color-slate-300:oklch(86.9% .022 252.894);--color-slate-500:oklch(55.4% .046 257.417);--color-gray-50:oklch(98.5% .002 247.839);--color-gray-100:oklch(96.7% .003 264.542);--color-gray-200:oklch(92.8% .006 264.531);--color-gray-300:oklch(87.2% .01 258.338);--color-gray-400:oklch(70.7% .022 261.325);--color-gray-500:oklch(55.1% .027 264.364);--color-gray-600:oklch(44.6% .03 256.802);--color-gray-700:oklch(37.3% .034 259.733);--color-gray-800:oklch(27.8% .033 256.848);--color-gray-900:oklch(21% .034 264.665);--color-zinc-100:oklch(96.7% .001 286.375);--color-zinc-200:oklch(92% .004 286.32);--color-zinc-300:oklch(87.1% .006 286.286);--color-zinc-400:oklch(70.5% .015 286.067);--color-zinc-500:oklch(55.2% .016 285.938);--color-zinc-600:oklch(44.2% .017 285.786);--color-zinc-700:oklch(37% .013 285.805);--color-zinc-800:oklch(27.4% .006 286.033);--color-zinc-900:oklch(21% .006 285.885);--color-black:#000;--color-white:#fff;--spacing:.25rem;--container-xs:20rem;--container-sm:24rem;--container-md:28rem;--container-lg:32rem;--container-xl:36rem;--container-2xl:42rem;--container-3xl:48rem;--container-4xl:56rem;--container-5xl:64rem;--container-6xl:72rem;--text-xs:.75rem;--text-xs--line-height:calc(1/.75);--text-sm:.875rem;--text-sm--line-height:calc(1.25/.875);--text-base:1rem;--text-base--line-height: 1.5 ;--text-lg:1.125rem;--text-lg--line-height:calc(1.75/1.125);--text-xl:1.25rem;--text-xl--line-height:calc(1.75/1.25);--text-2xl:1.5rem;--text-2xl--line-height:calc(2/1.5);--text-3xl:1.875rem;--text-3xl--line-height: 1.2 ;--text-5xl:3rem;--text-5xl--line-height:1;--font-weight-light:300;--font-weight-normal:400;--font-weight-medium:500;--font-weight-semibold:600;--font-weight-bold:700;--tracking-wide:.025em;--tracking-wider:.05em;--tracking-widest:.1em;--leading-tight:1.25;--radius-sm:.25rem;--radius-md:.375rem;--radius-lg:.5rem;--radius-xl:.75rem;--radius-2xl:1rem;--drop-shadow-md:0 3px 3px #0000001f;--drop-shadow-lg:0 4px 4px #00000026;--ease-out:cubic-bezier(0,0,.2,1);--ease-in-out:cubic-bezier(.4,0,.2,1);--animate-spin:spin 1s linear infinite;--animate-ping:ping 1s cubic-bezier(0,0,.2,1)infinite;--animate-pulse:pulse 2s cubic-bezier(.4,0,.6,1)infinite;--blur-sm:8px;--blur-2xl:40px;--aspect-video:16/9;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4,0,.2,1);--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono);--color-bambu-green:var(--accent);--color-bambu-green-light:var(--accent-light);--color-bambu-green-dark:var(--accent-dark);--color-status-ok:var(--status-ok);--color-status-error:var(--status-error);--color-status-warning:var(--status-warning);--color-bambu-dark:var(--bg-primary);--color-bambu-dark-secondary:var(--bg-secondary);--color-bambu-dark-tertiary:var(--bg-tertiary);--color-bambu-gray:var(--text-muted);--color-bambu-gray-light:var(--text-secondary);--color-bambu-gray-dark:var(--text-tertiary)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab,red,red)){::placeholder{color:color-mix(in oklab,currentcolor 50%,transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer utilities{.pointer-events-none{pointer-events:none}.collapse{visibility:collapse}.visible{visibility:visible}.sr-only{clip-path:inset(50%);white-space:nowrap;border-width:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.static{position:static}.sticky{position:sticky}.-inset-4{inset:calc(var(--spacing)*-4)}.inset-0{inset:calc(var(--spacing)*0)}.inset-2{inset:calc(var(--spacing)*2)}.inset-x-0{inset-inline:calc(var(--spacing)*0)}.inset-y-0{inset-block:calc(var(--spacing)*0)}.-top-0\.5{top:calc(var(--spacing)*-.5)}.-top-1{top:calc(var(--spacing)*-1)}.-top-1\.5{top:calc(var(--spacing)*-1.5)}.top-0{top:calc(var(--spacing)*0)}.top-0\.5{top:calc(var(--spacing)*.5)}.top-1{top:calc(var(--spacing)*1)}.top-1\.5{top:calc(var(--spacing)*1.5)}.top-1\/2{top:50%}.top-2{top:calc(var(--spacing)*2)}.top-2\.5{top:calc(var(--spacing)*2.5)}.top-3{top:calc(var(--spacing)*3)}.top-4{top:calc(var(--spacing)*4)}.top-8{top:calc(var(--spacing)*8)}.top-\[2px\]{top:2px}.top-\[3px\]{top:3px}.top-\[52px\]{top:52px}.top-full{top:100%}.-right-0\.5{right:calc(var(--spacing)*-.5)}.-right-1{right:calc(var(--spacing)*-1)}.-right-1\.5{right:calc(var(--spacing)*-1.5)}.-right-2{right:calc(var(--spacing)*-2)}.right-0{right:calc(var(--spacing)*0)}.right-1{right:calc(var(--spacing)*1)}.right-1\.5{right:calc(var(--spacing)*1.5)}.right-2{right:calc(var(--spacing)*2)}.right-3{right:calc(var(--spacing)*3)}.right-4{right:calc(var(--spacing)*4)}.right-6{right:calc(var(--spacing)*6)}.right-12{right:calc(var(--spacing)*12)}.right-20{right:calc(var(--spacing)*20)}.right-\[5\.5rem\]{right:5.5rem}.right-full{right:100%}.-bottom-0\.5{bottom:calc(var(--spacing)*-.5)}.-bottom-1{bottom:calc(var(--spacing)*-1)}.-bottom-2{bottom:calc(var(--spacing)*-2)}.-bottom-7{bottom:calc(var(--spacing)*-7)}.bottom-0{bottom:calc(var(--spacing)*0)}.bottom-1{bottom:calc(var(--spacing)*1)}.bottom-2{bottom:calc(var(--spacing)*2)}.bottom-3{bottom:calc(var(--spacing)*3)}.bottom-4{bottom:calc(var(--spacing)*4)}.bottom-6{bottom:calc(var(--spacing)*6)}.bottom-8{bottom:calc(var(--spacing)*8)}.bottom-20{bottom:calc(var(--spacing)*20)}.bottom-full{bottom:100%}.-left-2{left:calc(var(--spacing)*-2)}.left-0{left:calc(var(--spacing)*0)}.left-0\.5{left:calc(var(--spacing)*.5)}.left-1{left:calc(var(--spacing)*1)}.left-1\/2{left:50%}.left-2{left:calc(var(--spacing)*2)}.left-2\.5{left:calc(var(--spacing)*2.5)}.left-3{left:calc(var(--spacing)*3)}.left-4{left:calc(var(--spacing)*4)}.left-10{left:calc(var(--spacing)*10)}.left-12{left:calc(var(--spacing)*12)}.left-\[2px\]{left:2px}.left-\[3px\]{left:3px}.left-full{left:100%}.z-0{z-index:0}.z-10{z-index:10}.z-20{z-index:20}.z-30{z-index:30}.z-40{z-index:40}.z-50{z-index:50}.z-60,.z-\[60\]{z-index:60}.z-\[100\]{z-index:100}.z-\[101\]{z-index:101}.z-\[9998\]{z-index:9998}.z-\[9999\]{z-index:9999}.col-span-1{grid-column:span 1/span 1}.col-span-2{grid-column:span 2/span 2}.col-span-3{grid-column:span 3/span 3}.col-span-4{grid-column:span 4/span 4}.col-span-full{grid-column:1/-1}.container{width:100%}@media(min-width:40rem){.container{max-width:40rem}}@media(min-width:48rem){.container{max-width:48rem}}@media(min-width:64rem){.container{max-width:64rem}}@media(min-width:80rem){.container{max-width:80rem}}@media(min-width:96rem){.container{max-width:96rem}}.-m-4{margin:calc(var(--spacing)*-4)}.-mx-4{margin-inline:calc(var(--spacing)*-4)}.mx-1{margin-inline:calc(var(--spacing)*1)}.mx-1\.5{margin-inline:calc(var(--spacing)*1.5)}.mx-2{margin-inline:calc(var(--spacing)*2)}.mx-4{margin-inline:calc(var(--spacing)*4)}.mx-5{margin-inline:calc(var(--spacing)*5)}.mx-auto{margin-inline:auto}.my-1{margin-block:calc(var(--spacing)*1)}.my-2{margin-block:calc(var(--spacing)*2)}.my-8{margin-block:calc(var(--spacing)*8)}.-mt-0\.5{margin-top:calc(var(--spacing)*-.5)}.-mt-2{margin-top:calc(var(--spacing)*-2)}.mt-0\.5{margin-top:calc(var(--spacing)*.5)}.mt-1{margin-top:calc(var(--spacing)*1)}.mt-1\.5{margin-top:calc(var(--spacing)*1.5)}.mt-2{margin-top:calc(var(--spacing)*2)}.mt-3{margin-top:calc(var(--spacing)*3)}.mt-4{margin-top:calc(var(--spacing)*4)}.mt-6{margin-top:calc(var(--spacing)*6)}.mt-8{margin-top:calc(var(--spacing)*8)}.mt-14{margin-top:calc(var(--spacing)*14)}.mt-auto{margin-top:auto}.mr-1{margin-right:calc(var(--spacing)*1)}.mr-1\.5{margin-right:calc(var(--spacing)*1.5)}.mr-2{margin-right:calc(var(--spacing)*2)}.mr-3{margin-right:calc(var(--spacing)*3)}.mr-4{margin-right:calc(var(--spacing)*4)}.mr-auto{margin-right:auto}.-mb-px{margin-bottom:-1px}.mb-0\.5{margin-bottom:calc(var(--spacing)*.5)}.mb-1{margin-bottom:calc(var(--spacing)*1)}.mb-1\.5{margin-bottom:calc(var(--spacing)*1.5)}.mb-2{margin-bottom:calc(var(--spacing)*2)}.mb-2\.5{margin-bottom:calc(var(--spacing)*2.5)}.mb-3{margin-bottom:calc(var(--spacing)*3)}.mb-4{margin-bottom:calc(var(--spacing)*4)}.mb-5{margin-bottom:calc(var(--spacing)*5)}.mb-6{margin-bottom:calc(var(--spacing)*6)}.mb-8{margin-bottom:calc(var(--spacing)*8)}.-ml-1{margin-left:calc(var(--spacing)*-1)}.-ml-2{margin-left:calc(var(--spacing)*-2)}.ml-0\.5{margin-left:calc(var(--spacing)*.5)}.ml-1{margin-left:calc(var(--spacing)*1)}.ml-1\.5{margin-left:calc(var(--spacing)*1.5)}.ml-2{margin-left:calc(var(--spacing)*2)}.ml-3{margin-left:calc(var(--spacing)*3)}.ml-4{margin-left:calc(var(--spacing)*4)}.ml-6{margin-left:calc(var(--spacing)*6)}.ml-7{margin-left:calc(var(--spacing)*7)}.ml-9{margin-left:calc(var(--spacing)*9)}.ml-14{margin-left:calc(var(--spacing)*14)}.ml-16{margin-left:calc(var(--spacing)*16)}.ml-64{margin-left:calc(var(--spacing)*64)}.ml-auto{margin-left:auto}.line-clamp-1{-webkit-line-clamp:1;-webkit-box-orient:vertical;display:-webkit-box;overflow:hidden}.block{display:block}.flex{display:flex}.grid{display:grid}.hidden{display:none}.inline{display:inline}.inline-block{display:inline-block}.inline-flex{display:inline-flex}.table{display:table}.aspect-square{aspect-ratio:1}.aspect-video{aspect-ratio:var(--aspect-video)}.h-0{height:calc(var(--spacing)*0)}.h-0\.5{height:calc(var(--spacing)*.5)}.h-1{height:calc(var(--spacing)*1)}.h-1\.5{height:calc(var(--spacing)*1.5)}.h-2{height:calc(var(--spacing)*2)}.h-2\.5{height:calc(var(--spacing)*2.5)}.h-3{height:calc(var(--spacing)*3)}.h-3\.5{height:calc(var(--spacing)*3.5)}.h-4{height:calc(var(--spacing)*4)}.h-5{height:calc(var(--spacing)*5)}.h-6{height:calc(var(--spacing)*6)}.h-7{height:calc(var(--spacing)*7)}.h-8{height:calc(var(--spacing)*8)}.h-9{height:calc(var(--spacing)*9)}.h-10{height:calc(var(--spacing)*10)}.h-12{height:calc(var(--spacing)*12)}.h-14{height:calc(var(--spacing)*14)}.h-16{height:calc(var(--spacing)*16)}.h-20{height:calc(var(--spacing)*20)}.h-24{height:calc(var(--spacing)*24)}.h-32{height:calc(var(--spacing)*32)}.h-40{height:calc(var(--spacing)*40)}.h-48{height:calc(var(--spacing)*48)}.h-64{height:calc(var(--spacing)*64)}.h-80{height:calc(var(--spacing)*80)}.h-\[18px\]{height:18px}.h-\[38px\]{height:38px}.h-\[40px\]{height:40px}.h-\[48px\]{height:48px}.h-\[80vh\]{height:80vh}.h-\[160px\]{height:160px}.h-\[300px\]{height:300px}.h-\[calc\(100\%-40px\)\]{height:calc(100% - 40px)}.h-full{height:100%}.h-px{height:1px}.h-screen{height:100vh}.max-h-40{max-height:calc(var(--spacing)*40)}.max-h-48{max-height:calc(var(--spacing)*48)}.max-h-60{max-height:calc(var(--spacing)*60)}.max-h-64{max-height:calc(var(--spacing)*64)}.max-h-80{max-height:calc(var(--spacing)*80)}.max-h-96{max-height:calc(var(--spacing)*96)}.max-h-\[60vh\]{max-height:60vh}.max-h-\[80vh\]{max-height:80vh}.max-h-\[85vh\]{max-height:85vh}.max-h-\[90vh\]{max-height:90vh}.max-h-\[300px\]{max-height:300px}.max-h-\[400px\]{max-height:400px}.max-h-\[500px\]{max-height:500px}.max-h-\[600px\]{max-height:600px}.max-h-\[calc\(90vh-80px\)\]{max-height:calc(90vh - 80px)}.max-h-\[calc\(100vh-320px\)\]{max-height:calc(100vh - 320px)}.max-h-full{max-height:100%}.min-h-0{min-height:calc(var(--spacing)*0)}.min-h-\[36px\]{min-height:36px}.min-h-\[40px\]{min-height:40px}.min-h-\[44px\]{min-height:44px}.min-h-\[48px\]{min-height:48px}.min-h-\[80px\]{min-height:80px}.min-h-\[120px\]{min-height:120px}.min-h-\[300px\]{min-height:300px}.min-h-\[400px\]{min-height:400px}.min-h-\[calc\(100vh-64px\)\]{min-height:calc(100vh - 64px)}.min-h-screen{min-height:100vh}.w-0{width:calc(var(--spacing)*0)}.w-0\.5{width:calc(var(--spacing)*.5)}.w-1{width:calc(var(--spacing)*1)}.w-1\.5{width:calc(var(--spacing)*1.5)}.w-1\/2{width:50%}.w-1\/3{width:33.3333%}.w-2{width:calc(var(--spacing)*2)}.w-2\.5{width:calc(var(--spacing)*2.5)}.w-3{width:calc(var(--spacing)*3)}.w-3\.5{width:calc(var(--spacing)*3.5)}.w-4{width:calc(var(--spacing)*4)}.w-4\.5{width:calc(var(--spacing)*4.5)}.w-5{width:calc(var(--spacing)*5)}.w-5\/12{width:41.6667%}.w-6{width:calc(var(--spacing)*6)}.w-7{width:calc(var(--spacing)*7)}.w-7\/12{width:58.3333%}.w-8{width:calc(var(--spacing)*8)}.w-9{width:calc(var(--spacing)*9)}.w-10{width:calc(var(--spacing)*10)}.w-11{width:calc(var(--spacing)*11)}.w-12{width:calc(var(--spacing)*12)}.w-14{width:calc(var(--spacing)*14)}.w-16{width:calc(var(--spacing)*16)}.w-20{width:calc(var(--spacing)*20)}.w-24{width:calc(var(--spacing)*24)}.w-32{width:calc(var(--spacing)*32)}.w-36{width:calc(var(--spacing)*36)}.w-40{width:calc(var(--spacing)*40)}.w-44{width:calc(var(--spacing)*44)}.w-48{width:calc(var(--spacing)*48)}.w-52{width:calc(var(--spacing)*52)}.w-56{width:calc(var(--spacing)*56)}.w-64{width:calc(var(--spacing)*64)}.w-72{width:calc(var(--spacing)*72)}.w-96{width:calc(var(--spacing)*96)}.w-\[240px\]{width:240px}.w-\[340px\]{width:340px}.w-\[420px\]{width:420px}.w-\[560px\]{width:560px}.w-auto{width:auto}.w-fit{width:fit-content}.w-full{width:100%}.w-px{width:1px}.w-screen{width:100vw}.max-w-2xl{max-width:var(--container-2xl)}.max-w-3xl{max-width:var(--container-3xl)}.max-w-4xl{max-width:var(--container-4xl)}.max-w-5xl{max-width:var(--container-5xl)}.max-w-6xl{max-width:var(--container-6xl)}.max-w-32{max-width:calc(var(--spacing)*32)}.max-w-\[40\%\]{max-width:40%}.max-w-\[50\%\]{max-width:50%}.max-w-\[80px\]{max-width:80px}.max-w-\[90vw\]{max-width:90vw}.max-w-\[100px\]{max-width:100px}.max-w-\[120px\]{max-width:120px}.max-w-\[150px\]{max-width:150px}.max-w-\[160px\]{max-width:160px}.max-w-\[200px\]{max-width:200px}.max-w-\[280px\]{max-width:280px}.max-w-\[600px\]{max-width:600px}.max-w-full{max-width:100%}.max-w-lg{max-width:var(--container-lg)}.max-w-md{max-width:var(--container-md)}.max-w-none{max-width:none}.max-w-sm{max-width:var(--container-sm)}.max-w-xl{max-width:var(--container-xl)}.max-w-xs{max-width:var(--container-xs)}.min-w-0{min-width:calc(var(--spacing)*0)}.min-w-48{min-width:calc(var(--spacing)*48)}.min-w-\[16px\]{min-width:16px}.min-w-\[18px\]{min-width:18px}.min-w-\[32px\]{min-width:32px}.min-w-\[40px\]{min-width:40px}.min-w-\[48px\]{min-width:48px}.min-w-\[50px\]{min-width:50px}.min-w-\[80px\]{min-width:80px}.min-w-\[100px\]{min-width:100px}.min-w-\[120px\]{min-width:120px}.min-w-\[140px\]{min-width:140px}.min-w-\[150px\]{min-width:150px}.min-w-\[160px\]{min-width:160px}.min-w-\[180px\]{min-width:180px}.min-w-\[200px\]{min-width:200px}.min-w-full{min-width:100%}.flex-1{flex:1}.flex-\[2_1_190px\]{flex:2 190px}.flex-shrink{flex-shrink:1}.flex-shrink-0,.shrink-0{flex-shrink:0}.-translate-x-1\/2{--tw-translate-x: -50% ;translate:var(--tw-translate-x)var(--tw-translate-y)}.-translate-x-full{--tw-translate-x:-100%;translate:var(--tw-translate-x)var(--tw-translate-y)}.translate-x-0{--tw-translate-x:calc(var(--spacing)*0);translate:var(--tw-translate-x)var(--tw-translate-y)}.translate-x-0\.5{--tw-translate-x:calc(var(--spacing)*.5);translate:var(--tw-translate-x)var(--tw-translate-y)}.translate-x-1{--tw-translate-x:calc(var(--spacing)*1);translate:var(--tw-translate-x)var(--tw-translate-y)}.translate-x-3\.5{--tw-translate-x:calc(var(--spacing)*3.5);translate:var(--tw-translate-x)var(--tw-translate-y)}.translate-x-4{--tw-translate-x:calc(var(--spacing)*4);translate:var(--tw-translate-x)var(--tw-translate-y)}.translate-x-5{--tw-translate-x:calc(var(--spacing)*5);translate:var(--tw-translate-x)var(--tw-translate-y)}.translate-x-6{--tw-translate-x:calc(var(--spacing)*6);translate:var(--tw-translate-x)var(--tw-translate-y)}.-translate-y-1\/2{--tw-translate-y: -50% ;translate:var(--tw-translate-x)var(--tw-translate-y)}.scale-105{--tw-scale-x:105%;--tw-scale-y:105%;--tw-scale-z:105%;scale:var(--tw-scale-x)var(--tw-scale-y)}.scale-110{--tw-scale-x:110%;--tw-scale-y:110%;--tw-scale-z:110%;scale:var(--tw-scale-x)var(--tw-scale-y)}.scale-\[1\.02\]{scale:1.02}.-rotate-90{rotate:-90deg}.rotate-90{rotate:90deg}.rotate-180{rotate:180deg}.transform{transform:var(--tw-rotate-x,)var(--tw-rotate-y,)var(--tw-rotate-z,)var(--tw-skew-x,)var(--tw-skew-y,)}.animate-ping{animation:var(--animate-ping)}.animate-pulse{animation:var(--animate-pulse)}.animate-spin{animation:var(--animate-spin)}.cursor-col-resize{cursor:col-resize}.cursor-default{cursor:default}.cursor-ew-resize{cursor:ew-resize}.cursor-grab{cursor:grab}.cursor-not-allowed{cursor:not-allowed}.cursor-pointer{cursor:pointer}.cursor-row-resize{cursor:row-resize}.cursor-se-resize{cursor:se-resize}.touch-manipulation{touch-action:manipulation}.resize{resize:both}.resize-none{resize:none}.resize-y{resize:vertical}.list-inside{list-style-position:inside}.list-decimal{list-style-type:decimal}.list-disc{list-style-type:disc}.\[appearance\:textfield\]{appearance:textfield}.appearance-none{appearance:none}.grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}.grid-cols-5{grid-template-columns:repeat(5,minmax(0,1fr))}.grid-cols-7{grid-template-columns:repeat(7,minmax(0,1fr))}.grid-cols-12{grid-template-columns:repeat(12,minmax(0,1fr))}.grid-cols-\[auto_1fr_100px_100px_100px_80px\]{grid-template-columns:auto 1fr 100px 100px 100px 80px}.grid-cols-\[auto_1fr_120px_100px_100px_100px_80px\]{grid-template-columns:auto 1fr 120px 100px 100px 100px 80px}.flex-col{flex-direction:column}.flex-col-reverse{flex-direction:column-reverse}.flex-row{flex-direction:row}.flex-wrap{flex-wrap:wrap}.items-baseline{align-items:baseline}.items-center{align-items:center}.items-end{align-items:flex-end}.items-start{align-items:flex-start}.items-stretch{align-items:stretch}.justify-between{justify-content:space-between}.justify-center{justify-content:center}.justify-end{justify-content:flex-end}.gap-0{gap:calc(var(--spacing)*0)}.gap-0\.5{gap:calc(var(--spacing)*.5)}.gap-1{gap:calc(var(--spacing)*1)}.gap-1\.5{gap:calc(var(--spacing)*1.5)}.gap-2{gap:calc(var(--spacing)*2)}.gap-2\.5{gap:calc(var(--spacing)*2.5)}.gap-3{gap:calc(var(--spacing)*3)}.gap-4{gap:calc(var(--spacing)*4)}.gap-5{gap:calc(var(--spacing)*5)}.gap-6{gap:calc(var(--spacing)*6)}.gap-8{gap:calc(var(--spacing)*8)}.gap-\[3px\]{gap:3px}:where(.space-y-0>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*0)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*0)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-0\.5>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*.5)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*.5)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-1>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*1)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*1)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-1\.5>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*1.5)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*1.5)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-2>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*2)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*2)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-2\.5>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*2.5)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*2.5)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-3>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*3)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*3)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-4>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*4)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*4)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-5>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*5)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*5)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-6>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*6)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*6)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-8>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*8)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*8)*calc(1 - var(--tw-space-y-reverse)))}.gap-x-3{column-gap:calc(var(--spacing)*3)}.gap-x-4{column-gap:calc(var(--spacing)*4)}.gap-x-6{column-gap:calc(var(--spacing)*6)}.gap-y-1{row-gap:calc(var(--spacing)*1)}.gap-y-2{row-gap:calc(var(--spacing)*2)}.gap-y-3{row-gap:calc(var(--spacing)*3)}:where(.divide-y>:not(:last-child)){--tw-divide-y-reverse:0;border-bottom-style:var(--tw-border-style);border-top-style:var(--tw-border-style);border-top-width:calc(1px*var(--tw-divide-y-reverse));border-bottom-width:calc(1px*calc(1 - var(--tw-divide-y-reverse)))}:where(.divide-bambu-dark-tertiary>:not(:last-child)),:where(.divide-bambu-dark-tertiary\/30>:not(:last-child)){border-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){:where(.divide-bambu-dark-tertiary\/30>:not(:last-child)){border-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)30%,transparent)}}:where(.divide-bambu-gray\/20>:not(:last-child)){border-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){:where(.divide-bambu-gray\/20>:not(:last-child)){border-color:color-mix(in oklab,var(--color-bambu-gray)20%,transparent)}}.truncate{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.overflow-auto{overflow:auto}.overflow-hidden{overflow:hidden}.overflow-x-auto{overflow-x:auto}.overflow-y-auto{overflow-y:auto}.rounded{border-radius:.25rem}.rounded-2xl{border-radius:var(--radius-2xl)}.rounded-full{border-radius:3.40282e38px}.rounded-lg{border-radius:var(--radius-lg)}.rounded-md{border-radius:var(--radius-md)}.rounded-none{border-radius:0}.rounded-sm{border-radius:var(--radius-sm)}.rounded-xl{border-radius:var(--radius-xl)}.rounded-t-lg{border-top-left-radius:var(--radius-lg);border-top-right-radius:var(--radius-lg)}.rounded-t-xl{border-top-left-radius:var(--radius-xl);border-top-right-radius:var(--radius-xl)}.\!rounded-l-none{border-top-left-radius:0!important;border-bottom-left-radius:0!important}.rounded-l{border-top-left-radius:.25rem;border-bottom-left-radius:.25rem}.rounded-l-lg{border-top-left-radius:var(--radius-lg);border-bottom-left-radius:var(--radius-lg)}.rounded-tl{border-top-left-radius:.25rem}.\!rounded-r-none{border-top-right-radius:0!important;border-bottom-right-radius:0!important}.rounded-r{border-top-right-radius:.25rem;border-bottom-right-radius:.25rem}.rounded-r-lg{border-top-right-radius:var(--radius-lg);border-bottom-right-radius:var(--radius-lg)}.rounded-b-lg{border-bottom-right-radius:var(--radius-lg);border-bottom-left-radius:var(--radius-lg)}.border{border-style:var(--tw-border-style);border-width:1px}.border-0{border-style:var(--tw-border-style);border-width:0}.border-2{border-style:var(--tw-border-style);border-width:2px}.border-4{border-style:var(--tw-border-style);border-width:4px}.border-t{border-top-style:var(--tw-border-style);border-top-width:1px}.border-t-2{border-top-style:var(--tw-border-style);border-top-width:2px}.border-t-\[5px\]{border-top-style:var(--tw-border-style);border-top-width:5px}.border-t-\[6px\]{border-top-style:var(--tw-border-style);border-top-width:6px}.\!border-r-0{border-right-style:var(--tw-border-style)!important;border-right-width:0!important}.border-r{border-right-style:var(--tw-border-style);border-right-width:1px}.border-r-\[5px\]{border-right-style:var(--tw-border-style);border-right-width:5px}.border-r-\[6px\]{border-right-style:var(--tw-border-style);border-right-width:6px}.border-b{border-bottom-style:var(--tw-border-style);border-bottom-width:1px}.border-b-2{border-bottom-style:var(--tw-border-style);border-bottom-width:2px}.border-b-\[6px\]{border-bottom-style:var(--tw-border-style);border-bottom-width:6px}.border-l{border-left-style:var(--tw-border-style);border-left-width:1px}.border-l-2{border-left-style:var(--tw-border-style);border-left-width:2px}.border-l-4{border-left-style:var(--tw-border-style);border-left-width:4px}.border-l-\[5px\]{border-left-style:var(--tw-border-style);border-left-width:5px}.border-l-\[6px\]{border-left-style:var(--tw-border-style);border-left-width:6px}.border-dashed{--tw-border-style:dashed;border-style:dashed}.\!border-green-500{border-color:var(--color-green-500)!important}.\!border-yellow-500{border-color:var(--color-yellow-500)!important}.border-amber-200{border-color:var(--color-amber-200)}.border-amber-300{border-color:var(--color-amber-300)}.border-amber-500{border-color:var(--color-amber-500)}.border-amber-500\/20{border-color:#f99c0033}@supports (color:color-mix(in lab,red,red)){.border-amber-500\/20{border-color:color-mix(in oklab,var(--color-amber-500)20%,transparent)}}.border-amber-500\/30{border-color:#f99c004d}@supports (color:color-mix(in lab,red,red)){.border-amber-500\/30{border-color:color-mix(in oklab,var(--color-amber-500)30%,transparent)}}.border-bambu-dark-secondary{border-color:var(--color-bambu-dark-secondary)}.border-bambu-dark-tertiary,.border-bambu-dark-tertiary\/20{border-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.border-bambu-dark-tertiary\/20{border-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)20%,transparent)}}.border-bambu-dark-tertiary\/30{border-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.border-bambu-dark-tertiary\/30{border-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)30%,transparent)}}.border-bambu-dark-tertiary\/40{border-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.border-bambu-dark-tertiary\/40{border-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)40%,transparent)}}.border-bambu-dark-tertiary\/50{border-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.border-bambu-dark-tertiary\/50{border-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)50%,transparent)}}.border-bambu-gray,.border-bambu-gray\/20{border-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.border-bambu-gray\/20{border-color:color-mix(in oklab,var(--color-bambu-gray)20%,transparent)}}.border-bambu-gray\/30{border-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.border-bambu-gray\/30{border-color:color-mix(in oklab,var(--color-bambu-gray)30%,transparent)}}.border-bambu-gray\/50{border-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.border-bambu-gray\/50{border-color:color-mix(in oklab,var(--color-bambu-gray)50%,transparent)}}.border-bambu-green,.border-bambu-green\/20{border-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.border-bambu-green\/20{border-color:color-mix(in oklab,var(--color-bambu-green)20%,transparent)}}.border-bambu-green\/30{border-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.border-bambu-green\/30{border-color:color-mix(in oklab,var(--color-bambu-green)30%,transparent)}}.border-bambu-green\/40{border-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.border-bambu-green\/40{border-color:color-mix(in oklab,var(--color-bambu-green)40%,transparent)}}.border-bambu-green\/50{border-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.border-bambu-green\/50{border-color:color-mix(in oklab,var(--color-bambu-green)50%,transparent)}}.border-black\/20{border-color:#0003}@supports (color:color-mix(in lab,red,red)){.border-black\/20{border-color:color-mix(in oklab,var(--color-black)20%,transparent)}}.border-blue-400\/20{border-color:#54a2ff33}@supports (color:color-mix(in lab,red,red)){.border-blue-400\/20{border-color:color-mix(in oklab,var(--color-blue-400)20%,transparent)}}.border-blue-400\/50{border-color:#54a2ff80}@supports (color:color-mix(in lab,red,red)){.border-blue-400\/50{border-color:color-mix(in oklab,var(--color-blue-400)50%,transparent)}}.border-blue-500{border-color:var(--color-blue-500)}.border-blue-500\/20{border-color:#3080ff33}@supports (color:color-mix(in lab,red,red)){.border-blue-500\/20{border-color:color-mix(in oklab,var(--color-blue-500)20%,transparent)}}.border-blue-500\/30{border-color:#3080ff4d}@supports (color:color-mix(in lab,red,red)){.border-blue-500\/30{border-color:color-mix(in oklab,var(--color-blue-500)30%,transparent)}}.border-blue-500\/40{border-color:#3080ff66}@supports (color:color-mix(in lab,red,red)){.border-blue-500\/40{border-color:color-mix(in oklab,var(--color-blue-500)40%,transparent)}}.border-blue-500\/50{border-color:#3080ff80}@supports (color:color-mix(in lab,red,red)){.border-blue-500\/50{border-color:color-mix(in oklab,var(--color-blue-500)50%,transparent)}}.border-gray-200{border-color:var(--color-gray-200)}.border-gray-300{border-color:var(--color-gray-300)}.border-gray-400\/20{border-color:#99a1af33}@supports (color:color-mix(in lab,red,red)){.border-gray-400\/20{border-color:color-mix(in oklab,var(--color-gray-400)20%,transparent)}}.border-gray-500{border-color:var(--color-gray-500)}.border-gray-500\/20{border-color:#6a728233}@supports (color:color-mix(in lab,red,red)){.border-gray-500\/20{border-color:color-mix(in oklab,var(--color-gray-500)20%,transparent)}}.border-gray-700{border-color:var(--color-gray-700)}.border-green-300{border-color:var(--color-green-300)}.border-green-500{border-color:var(--color-green-500)}.border-green-500\/10{border-color:#00c7581a}@supports (color:color-mix(in lab,red,red)){.border-green-500\/10{border-color:color-mix(in oklab,var(--color-green-500)10%,transparent)}}.border-green-500\/20{border-color:#00c75833}@supports (color:color-mix(in lab,red,red)){.border-green-500\/20{border-color:color-mix(in oklab,var(--color-green-500)20%,transparent)}}.border-green-500\/30{border-color:#00c7584d}@supports (color:color-mix(in lab,red,red)){.border-green-500\/30{border-color:color-mix(in oklab,var(--color-green-500)30%,transparent)}}.border-green-500\/40{border-color:#00c75866}@supports (color:color-mix(in lab,red,red)){.border-green-500\/40{border-color:color-mix(in oklab,var(--color-green-500)40%,transparent)}}.border-green-500\/50{border-color:#00c75880}@supports (color:color-mix(in lab,red,red)){.border-green-500\/50{border-color:color-mix(in oklab,var(--color-green-500)50%,transparent)}}.border-green-800{border-color:var(--color-green-800)}.border-orange-400\/20{border-color:#ff8b1a33}@supports (color:color-mix(in lab,red,red)){.border-orange-400\/20{border-color:color-mix(in oklab,var(--color-orange-400)20%,transparent)}}.border-orange-400\/50{border-color:#ff8b1a80}@supports (color:color-mix(in lab,red,red)){.border-orange-400\/50{border-color:color-mix(in oklab,var(--color-orange-400)50%,transparent)}}.border-orange-500\/20{border-color:#fe6e0033}@supports (color:color-mix(in lab,red,red)){.border-orange-500\/20{border-color:color-mix(in oklab,var(--color-orange-500)20%,transparent)}}.border-orange-500\/30{border-color:#fe6e004d}@supports (color:color-mix(in lab,red,red)){.border-orange-500\/30{border-color:color-mix(in oklab,var(--color-orange-500)30%,transparent)}}.border-purple-400\/20{border-color:#c07eff33}@supports (color:color-mix(in lab,red,red)){.border-purple-400\/20{border-color:color-mix(in oklab,var(--color-purple-400)20%,transparent)}}.border-purple-500{border-color:var(--color-purple-500)}.border-purple-500\/20{border-color:#ac4bff33}@supports (color:color-mix(in lab,red,red)){.border-purple-500\/20{border-color:color-mix(in oklab,var(--color-purple-500)20%,transparent)}}.border-purple-500\/30{border-color:#ac4bff4d}@supports (color:color-mix(in lab,red,red)){.border-purple-500\/30{border-color:color-mix(in oklab,var(--color-purple-500)30%,transparent)}}.border-red-300{border-color:var(--color-red-300)}.border-red-500{border-color:var(--color-red-500)}.border-red-500\/20{border-color:#fb2c3633}@supports (color:color-mix(in lab,red,red)){.border-red-500\/20{border-color:color-mix(in oklab,var(--color-red-500)20%,transparent)}}.border-red-500\/30{border-color:#fb2c364d}@supports (color:color-mix(in lab,red,red)){.border-red-500\/30{border-color:color-mix(in oklab,var(--color-red-500)30%,transparent)}}.border-red-500\/40{border-color:#fb2c3666}@supports (color:color-mix(in lab,red,red)){.border-red-500\/40{border-color:color-mix(in oklab,var(--color-red-500)40%,transparent)}}.border-red-500\/50{border-color:#fb2c3680}@supports (color:color-mix(in lab,red,red)){.border-red-500\/50{border-color:color-mix(in oklab,var(--color-red-500)50%,transparent)}}.border-red-800{border-color:var(--color-red-800)}.border-red-800\/70{border-color:#9f0712b3}@supports (color:color-mix(in lab,red,red)){.border-red-800\/70{border-color:color-mix(in oklab,var(--color-red-800)70%,transparent)}}.border-slate-500{border-color:var(--color-slate-500)}.border-status-error\/20{border-color:var(--color-status-error)}@supports (color:color-mix(in lab,red,red)){.border-status-error\/20{border-color:color-mix(in oklab,var(--color-status-error)20%,transparent)}}.border-status-ok,.border-status-ok\/20{border-color:var(--color-status-ok)}@supports (color:color-mix(in lab,red,red)){.border-status-ok\/20{border-color:color-mix(in oklab,var(--color-status-ok)20%,transparent)}}.border-status-warning\/20{border-color:var(--color-status-warning)}@supports (color:color-mix(in lab,red,red)){.border-status-warning\/20{border-color:color-mix(in oklab,var(--color-status-warning)20%,transparent)}}.border-transparent{border-color:#0000}.border-white\/10{border-color:#ffffff1a}@supports (color:color-mix(in lab,red,red)){.border-white\/10{border-color:color-mix(in oklab,var(--color-white)10%,transparent)}}.border-white\/20{border-color:#fff3}@supports (color:color-mix(in lab,red,red)){.border-white\/20{border-color:color-mix(in oklab,var(--color-white)20%,transparent)}}.border-white\/30{border-color:#ffffff4d}@supports (color:color-mix(in lab,red,red)){.border-white\/30{border-color:color-mix(in oklab,var(--color-white)30%,transparent)}}.border-yellow-400\/20{border-color:#fac80033}@supports (color:color-mix(in lab,red,red)){.border-yellow-400\/20{border-color:color-mix(in oklab,var(--color-yellow-400)20%,transparent)}}.border-yellow-400\/30{border-color:#fac8004d}@supports (color:color-mix(in lab,red,red)){.border-yellow-400\/30{border-color:color-mix(in oklab,var(--color-yellow-400)30%,transparent)}}.border-yellow-400\/50{border-color:#fac80080}@supports (color:color-mix(in lab,red,red)){.border-yellow-400\/50{border-color:color-mix(in oklab,var(--color-yellow-400)50%,transparent)}}.border-yellow-500{border-color:var(--color-yellow-500)}.border-yellow-500\/20{border-color:#edb20033}@supports (color:color-mix(in lab,red,red)){.border-yellow-500\/20{border-color:color-mix(in oklab,var(--color-yellow-500)20%,transparent)}}.border-yellow-500\/30{border-color:#edb2004d}@supports (color:color-mix(in lab,red,red)){.border-yellow-500\/30{border-color:color-mix(in oklab,var(--color-yellow-500)30%,transparent)}}.border-yellow-500\/50{border-color:#edb20080}@supports (color:color-mix(in lab,red,red)){.border-yellow-500\/50{border-color:color-mix(in oklab,var(--color-yellow-500)50%,transparent)}}.border-zinc-500{border-color:var(--color-zinc-500)}.border-zinc-600{border-color:var(--color-zinc-600)}.border-zinc-700{border-color:var(--color-zinc-700)}.border-zinc-700\/50{border-color:#3f3f4680}@supports (color:color-mix(in lab,red,red)){.border-zinc-700\/50{border-color:color-mix(in oklab,var(--color-zinc-700)50%,transparent)}}.border-zinc-800{border-color:var(--color-zinc-800)}.border-t-bambu-dark-tertiary{border-top-color:var(--color-bambu-dark-tertiary)}.border-t-transparent{border-top-color:#0000}.border-r-transparent{border-right-color:#0000}.border-b-bambu-dark-tertiary{border-bottom-color:var(--color-bambu-dark-tertiary)}.border-l-transparent{border-left-color:#0000}.border-l-yellow-500{border-left-color:var(--color-yellow-500)}.\!bg-bambu-green{background-color:var(--color-bambu-green)!important}.bg-amber-50{background-color:var(--color-amber-50)}.bg-amber-500{background-color:var(--color-amber-500)}.bg-amber-500\/5{background-color:#f99c000d}@supports (color:color-mix(in lab,red,red)){.bg-amber-500\/5{background-color:color-mix(in oklab,var(--color-amber-500)5%,transparent)}}.bg-amber-500\/10{background-color:#f99c001a}@supports (color:color-mix(in lab,red,red)){.bg-amber-500\/10{background-color:color-mix(in oklab,var(--color-amber-500)10%,transparent)}}.bg-amber-500\/20{background-color:#f99c0033}@supports (color:color-mix(in lab,red,red)){.bg-amber-500\/20{background-color:color-mix(in oklab,var(--color-amber-500)20%,transparent)}}.bg-amber-600\/20{background-color:#dd740033}@supports (color:color-mix(in lab,red,red)){.bg-amber-600\/20{background-color:color-mix(in oklab,var(--color-amber-600)20%,transparent)}}.bg-bambu-dark{background-color:var(--color-bambu-dark)}.bg-bambu-dark-secondary,.bg-bambu-dark-secondary\/30{background-color:var(--color-bambu-dark-secondary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-secondary\/30{background-color:color-mix(in oklab,var(--color-bambu-dark-secondary)30%,transparent)}}.bg-bambu-dark-secondary\/50{background-color:var(--color-bambu-dark-secondary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-secondary\/50{background-color:color-mix(in oklab,var(--color-bambu-dark-secondary)50%,transparent)}}.bg-bambu-dark-secondary\/60{background-color:var(--color-bambu-dark-secondary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-secondary\/60{background-color:color-mix(in oklab,var(--color-bambu-dark-secondary)60%,transparent)}}.bg-bambu-dark-secondary\/90{background-color:var(--color-bambu-dark-secondary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-secondary\/90{background-color:color-mix(in oklab,var(--color-bambu-dark-secondary)90%,transparent)}}.bg-bambu-dark-secondary\/95{background-color:var(--color-bambu-dark-secondary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-secondary\/95{background-color:color-mix(in oklab,var(--color-bambu-dark-secondary)95%,transparent)}}.bg-bambu-dark-tertiary,.bg-bambu-dark-tertiary\/20{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-tertiary\/20{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)20%,transparent)}}.bg-bambu-dark-tertiary\/30{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-tertiary\/30{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)30%,transparent)}}.bg-bambu-dark-tertiary\/40{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-tertiary\/40{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)40%,transparent)}}.bg-bambu-dark-tertiary\/50{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-tertiary\/50{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)50%,transparent)}}.bg-bambu-dark-tertiary\/70{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-tertiary\/70{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)70%,transparent)}}.bg-bambu-dark-tertiary\/80{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark-tertiary\/80{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)80%,transparent)}}.bg-bambu-dark\/20{background-color:var(--color-bambu-dark)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark\/20{background-color:color-mix(in oklab,var(--color-bambu-dark)20%,transparent)}}.bg-bambu-dark\/30{background-color:var(--color-bambu-dark)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark\/30{background-color:color-mix(in oklab,var(--color-bambu-dark)30%,transparent)}}.bg-bambu-dark\/50{background-color:var(--color-bambu-dark)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark\/50{background-color:color-mix(in oklab,var(--color-bambu-dark)50%,transparent)}}.bg-bambu-dark\/80{background-color:var(--color-bambu-dark)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark\/80{background-color:color-mix(in oklab,var(--color-bambu-dark)80%,transparent)}}.bg-bambu-dark\/90{background-color:var(--color-bambu-dark)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-dark\/90{background-color:color-mix(in oklab,var(--color-bambu-dark)90%,transparent)}}.bg-bambu-gray,.bg-bambu-gray\/10{background-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-gray\/10{background-color:color-mix(in oklab,var(--color-bambu-gray)10%,transparent)}}.bg-bambu-gray\/20{background-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-gray\/20{background-color:color-mix(in oklab,var(--color-bambu-gray)20%,transparent)}}.bg-bambu-gray\/30{background-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-gray\/30{background-color:color-mix(in oklab,var(--color-bambu-gray)30%,transparent)}}.bg-bambu-gray\/50{background-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-gray\/50{background-color:color-mix(in oklab,var(--color-bambu-gray)50%,transparent)}}.bg-bambu-gray\/60{background-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-gray\/60{background-color:color-mix(in oklab,var(--color-bambu-gray)60%,transparent)}}.bg-bambu-gray\/90{background-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-gray\/90{background-color:color-mix(in oklab,var(--color-bambu-gray)90%,transparent)}}.bg-bambu-green,.bg-bambu-green\/5{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-green\/5{background-color:color-mix(in oklab,var(--color-bambu-green)5%,transparent)}}.bg-bambu-green\/10{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-green\/10{background-color:color-mix(in oklab,var(--color-bambu-green)10%,transparent)}}.bg-bambu-green\/15{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-green\/15{background-color:color-mix(in oklab,var(--color-bambu-green)15%,transparent)}}.bg-bambu-green\/20{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-green\/20{background-color:color-mix(in oklab,var(--color-bambu-green)20%,transparent)}}.bg-bambu-green\/30{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-green\/30{background-color:color-mix(in oklab,var(--color-bambu-green)30%,transparent)}}.bg-bambu-green\/50{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-green\/50{background-color:color-mix(in oklab,var(--color-bambu-green)50%,transparent)}}.bg-bambu-green\/75{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-green\/75{background-color:color-mix(in oklab,var(--color-bambu-green)75%,transparent)}}.bg-bambu-green\/90{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.bg-bambu-green\/90{background-color:color-mix(in oklab,var(--color-bambu-green)90%,transparent)}}.bg-black{background-color:var(--color-black)}.bg-black\/15{background-color:#00000026}@supports (color:color-mix(in lab,red,red)){.bg-black\/15{background-color:color-mix(in oklab,var(--color-black)15%,transparent)}}.bg-black\/30{background-color:#0000004d}@supports (color:color-mix(in lab,red,red)){.bg-black\/30{background-color:color-mix(in oklab,var(--color-black)30%,transparent)}}.bg-black\/40{background-color:#0006}@supports (color:color-mix(in lab,red,red)){.bg-black\/40{background-color:color-mix(in oklab,var(--color-black)40%,transparent)}}.bg-black\/50{background-color:#00000080}@supports (color:color-mix(in lab,red,red)){.bg-black\/50{background-color:color-mix(in oklab,var(--color-black)50%,transparent)}}.bg-black\/60{background-color:#0009}@supports (color:color-mix(in lab,red,red)){.bg-black\/60{background-color:color-mix(in oklab,var(--color-black)60%,transparent)}}.bg-black\/70{background-color:#000000b3}@supports (color:color-mix(in lab,red,red)){.bg-black\/70{background-color:color-mix(in oklab,var(--color-black)70%,transparent)}}.bg-black\/80{background-color:#000c}@supports (color:color-mix(in lab,red,red)){.bg-black\/80{background-color:color-mix(in oklab,var(--color-black)80%,transparent)}}.bg-black\/90{background-color:#000000e6}@supports (color:color-mix(in lab,red,red)){.bg-black\/90{background-color:color-mix(in oklab,var(--color-black)90%,transparent)}}.bg-blue-50{background-color:var(--color-blue-50)}.bg-blue-100{background-color:var(--color-blue-100)}.bg-blue-400{background-color:var(--color-blue-400)}.bg-blue-400\/10{background-color:#54a2ff1a}@supports (color:color-mix(in lab,red,red)){.bg-blue-400\/10{background-color:color-mix(in oklab,var(--color-blue-400)10%,transparent)}}.bg-blue-500{background-color:var(--color-blue-500)}.bg-blue-500\/5{background-color:#3080ff0d}@supports (color:color-mix(in lab,red,red)){.bg-blue-500\/5{background-color:color-mix(in oklab,var(--color-blue-500)5%,transparent)}}.bg-blue-500\/10{background-color:#3080ff1a}@supports (color:color-mix(in lab,red,red)){.bg-blue-500\/10{background-color:color-mix(in oklab,var(--color-blue-500)10%,transparent)}}.bg-blue-500\/20{background-color:#3080ff33}@supports (color:color-mix(in lab,red,red)){.bg-blue-500\/20{background-color:color-mix(in oklab,var(--color-blue-500)20%,transparent)}}.bg-blue-500\/30{background-color:#3080ff4d}@supports (color:color-mix(in lab,red,red)){.bg-blue-500\/30{background-color:color-mix(in oklab,var(--color-blue-500)30%,transparent)}}.bg-blue-500\/90{background-color:#3080ffe6}@supports (color:color-mix(in lab,red,red)){.bg-blue-500\/90{background-color:color-mix(in oklab,var(--color-blue-500)90%,transparent)}}.bg-blue-600{background-color:var(--color-blue-600)}.bg-blue-600\/20{background-color:#155dfc33}@supports (color:color-mix(in lab,red,red)){.bg-blue-600\/20{background-color:color-mix(in oklab,var(--color-blue-600)20%,transparent)}}.bg-cyan-500{background-color:var(--color-cyan-500)}.bg-cyan-500\/10{background-color:#00b7d71a}@supports (color:color-mix(in lab,red,red)){.bg-cyan-500\/10{background-color:color-mix(in oklab,var(--color-cyan-500)10%,transparent)}}.bg-cyan-500\/20{background-color:#00b7d733}@supports (color:color-mix(in lab,red,red)){.bg-cyan-500\/20{background-color:color-mix(in oklab,var(--color-cyan-500)20%,transparent)}}.bg-cyan-600\/20{background-color:#0092b533}@supports (color:color-mix(in lab,red,red)){.bg-cyan-600\/20{background-color:color-mix(in oklab,var(--color-cyan-600)20%,transparent)}}.bg-emerald-500\/20{background-color:#00bb7f33}@supports (color:color-mix(in lab,red,red)){.bg-emerald-500\/20{background-color:color-mix(in oklab,var(--color-emerald-500)20%,transparent)}}.bg-emerald-600\/20{background-color:#00976733}@supports (color:color-mix(in lab,red,red)){.bg-emerald-600\/20{background-color:color-mix(in oklab,var(--color-emerald-600)20%,transparent)}}.bg-emerald-700{background-color:var(--color-emerald-700)}.bg-fuchsia-500{background-color:var(--color-fuchsia-500)}.bg-gray-50{background-color:var(--color-gray-50)}.bg-gray-100{background-color:var(--color-gray-100)}.bg-gray-400{background-color:var(--color-gray-400)}.bg-gray-400\/10{background-color:#99a1af1a}@supports (color:color-mix(in lab,red,red)){.bg-gray-400\/10{background-color:color-mix(in oklab,var(--color-gray-400)10%,transparent)}}.bg-gray-500{background-color:var(--color-gray-500)}.bg-gray-500\/20{background-color:#6a728233}@supports (color:color-mix(in lab,red,red)){.bg-gray-500\/20{background-color:color-mix(in oklab,var(--color-gray-500)20%,transparent)}}.bg-gray-600{background-color:var(--color-gray-600)}.bg-gray-800{background-color:var(--color-gray-800)}.bg-gray-900{background-color:var(--color-gray-900)}.bg-green-100{background-color:var(--color-green-100)}.bg-green-400{background-color:var(--color-green-400)}.bg-green-500{background-color:var(--color-green-500)}.bg-green-500\/10{background-color:#00c7581a}@supports (color:color-mix(in lab,red,red)){.bg-green-500\/10{background-color:color-mix(in oklab,var(--color-green-500)10%,transparent)}}.bg-green-500\/15{background-color:#00c75826}@supports (color:color-mix(in lab,red,red)){.bg-green-500\/15{background-color:color-mix(in oklab,var(--color-green-500)15%,transparent)}}.bg-green-500\/20{background-color:#00c75833}@supports (color:color-mix(in lab,red,red)){.bg-green-500\/20{background-color:color-mix(in oklab,var(--color-green-500)20%,transparent)}}.bg-green-600{background-color:var(--color-green-600)}.bg-green-600\/20{background-color:#00a54433}@supports (color:color-mix(in lab,red,red)){.bg-green-600\/20{background-color:color-mix(in oklab,var(--color-green-600)20%,transparent)}}.bg-green-600\/40{background-color:#00a54466}@supports (color:color-mix(in lab,red,red)){.bg-green-600\/40{background-color:color-mix(in oklab,var(--color-green-600)40%,transparent)}}.bg-green-900\/30{background-color:#0d542b4d}@supports (color:color-mix(in lab,red,red)){.bg-green-900\/30{background-color:color-mix(in oklab,var(--color-green-900)30%,transparent)}}.bg-green-900\/50{background-color:#0d542b80}@supports (color:color-mix(in lab,red,red)){.bg-green-900\/50{background-color:color-mix(in oklab,var(--color-green-900)50%,transparent)}}.bg-indigo-500\/20{background-color:#625fff33}@supports (color:color-mix(in lab,red,red)){.bg-indigo-500\/20{background-color:color-mix(in oklab,var(--color-indigo-500)20%,transparent)}}.bg-lime-500{background-color:var(--color-lime-500)}.bg-orange-400\/10{background-color:#ff8b1a1a}@supports (color:color-mix(in lab,red,red)){.bg-orange-400\/10{background-color:color-mix(in oklab,var(--color-orange-400)10%,transparent)}}.bg-orange-500{background-color:var(--color-orange-500)}.bg-orange-500\/10{background-color:#fe6e001a}@supports (color:color-mix(in lab,red,red)){.bg-orange-500\/10{background-color:color-mix(in oklab,var(--color-orange-500)10%,transparent)}}.bg-orange-500\/20{background-color:#fe6e0033}@supports (color:color-mix(in lab,red,red)){.bg-orange-500\/20{background-color:color-mix(in oklab,var(--color-orange-500)20%,transparent)}}.bg-orange-600{background-color:var(--color-orange-600)}.bg-orange-600\/20{background-color:#f0510033}@supports (color:color-mix(in lab,red,red)){.bg-orange-600\/20{background-color:color-mix(in oklab,var(--color-orange-600)20%,transparent)}}.bg-purple-400\/10{background-color:#c07eff1a}@supports (color:color-mix(in lab,red,red)){.bg-purple-400\/10{background-color:color-mix(in oklab,var(--color-purple-400)10%,transparent)}}.bg-purple-500{background-color:var(--color-purple-500)}.bg-purple-500\/10{background-color:#ac4bff1a}@supports (color:color-mix(in lab,red,red)){.bg-purple-500\/10{background-color:color-mix(in oklab,var(--color-purple-500)10%,transparent)}}.bg-purple-500\/20{background-color:#ac4bff33}@supports (color:color-mix(in lab,red,red)){.bg-purple-500\/20{background-color:color-mix(in oklab,var(--color-purple-500)20%,transparent)}}.bg-purple-500\/80{background-color:#ac4bffcc}@supports (color:color-mix(in lab,red,red)){.bg-purple-500\/80{background-color:color-mix(in oklab,var(--color-purple-500)80%,transparent)}}.bg-purple-500\/90{background-color:#ac4bffe6}@supports (color:color-mix(in lab,red,red)){.bg-purple-500\/90{background-color:color-mix(in oklab,var(--color-purple-500)90%,transparent)}}.bg-purple-700{background-color:var(--color-purple-700)}.bg-red-50{background-color:var(--color-red-50)}.bg-red-100{background-color:var(--color-red-100)}.bg-red-400{background-color:var(--color-red-400)}.bg-red-500{background-color:var(--color-red-500)}.bg-red-500\/5{background-color:#fb2c360d}@supports (color:color-mix(in lab,red,red)){.bg-red-500\/5{background-color:color-mix(in oklab,var(--color-red-500)5%,transparent)}}.bg-red-500\/10{background-color:#fb2c361a}@supports (color:color-mix(in lab,red,red)){.bg-red-500\/10{background-color:color-mix(in oklab,var(--color-red-500)10%,transparent)}}.bg-red-500\/15{background-color:#fb2c3626}@supports (color:color-mix(in lab,red,red)){.bg-red-500\/15{background-color:color-mix(in oklab,var(--color-red-500)15%,transparent)}}.bg-red-500\/20{background-color:#fb2c3633}@supports (color:color-mix(in lab,red,red)){.bg-red-500\/20{background-color:color-mix(in oklab,var(--color-red-500)20%,transparent)}}.bg-red-500\/30{background-color:#fb2c364d}@supports (color:color-mix(in lab,red,red)){.bg-red-500\/30{background-color:color-mix(in oklab,var(--color-red-500)30%,transparent)}}.bg-red-500\/40{background-color:#fb2c3666}@supports (color:color-mix(in lab,red,red)){.bg-red-500\/40{background-color:color-mix(in oklab,var(--color-red-500)40%,transparent)}}.bg-red-500\/80{background-color:#fb2c36cc}@supports (color:color-mix(in lab,red,red)){.bg-red-500\/80{background-color:color-mix(in oklab,var(--color-red-500)80%,transparent)}}.bg-red-600{background-color:var(--color-red-600)}.bg-red-900\/30{background-color:#82181a4d}@supports (color:color-mix(in lab,red,red)){.bg-red-900\/30{background-color:color-mix(in oklab,var(--color-red-900)30%,transparent)}}.bg-red-950\/70{background-color:#460809b3}@supports (color:color-mix(in lab,red,red)){.bg-red-950\/70{background-color:color-mix(in oklab,var(--color-red-950)70%,transparent)}}.bg-rose-500\/20{background-color:#ff235733}@supports (color:color-mix(in lab,red,red)){.bg-rose-500\/20{background-color:color-mix(in oklab,var(--color-rose-500)20%,transparent)}}.bg-rose-600\/20{background-color:#e7004433}@supports (color:color-mix(in lab,red,red)){.bg-rose-600\/20{background-color:color-mix(in oklab,var(--color-rose-600)20%,transparent)}}.bg-sky-500{background-color:var(--color-sky-500)}.bg-sky-500\/20{background-color:#00a5ef33}@supports (color:color-mix(in lab,red,red)){.bg-sky-500\/20{background-color:color-mix(in oklab,var(--color-sky-500)20%,transparent)}}.bg-status-error,.bg-status-error\/10{background-color:var(--color-status-error)}@supports (color:color-mix(in lab,red,red)){.bg-status-error\/10{background-color:color-mix(in oklab,var(--color-status-error)10%,transparent)}}.bg-status-error\/20{background-color:var(--color-status-error)}@supports (color:color-mix(in lab,red,red)){.bg-status-error\/20{background-color:color-mix(in oklab,var(--color-status-error)20%,transparent)}}.bg-status-error\/80{background-color:var(--color-status-error)}@supports (color:color-mix(in lab,red,red)){.bg-status-error\/80{background-color:color-mix(in oklab,var(--color-status-error)80%,transparent)}}.bg-status-ok,.bg-status-ok\/10{background-color:var(--color-status-ok)}@supports (color:color-mix(in lab,red,red)){.bg-status-ok\/10{background-color:color-mix(in oklab,var(--color-status-ok)10%,transparent)}}.bg-status-ok\/20{background-color:var(--color-status-ok)}@supports (color:color-mix(in lab,red,red)){.bg-status-ok\/20{background-color:color-mix(in oklab,var(--color-status-ok)20%,transparent)}}.bg-status-warning,.bg-status-warning\/10{background-color:var(--color-status-warning)}@supports (color:color-mix(in lab,red,red)){.bg-status-warning\/10{background-color:color-mix(in oklab,var(--color-status-warning)10%,transparent)}}.bg-status-warning\/20{background-color:var(--color-status-warning)}@supports (color:color-mix(in lab,red,red)){.bg-status-warning\/20{background-color:color-mix(in oklab,var(--color-status-warning)20%,transparent)}}.bg-teal-500{background-color:var(--color-teal-500)}.bg-teal-500\/20{background-color:#00baa733}@supports (color:color-mix(in lab,red,red)){.bg-teal-500\/20{background-color:color-mix(in oklab,var(--color-teal-500)20%,transparent)}}.bg-transparent{background-color:#0000}.bg-violet-500{background-color:var(--color-violet-500)}.bg-white{background-color:var(--color-white)}.bg-white\/10{background-color:#ffffff1a}@supports (color:color-mix(in lab,red,red)){.bg-white\/10{background-color:color-mix(in oklab,var(--color-white)10%,transparent)}}.bg-white\/20{background-color:#fff3}@supports (color:color-mix(in lab,red,red)){.bg-white\/20{background-color:color-mix(in oklab,var(--color-white)20%,transparent)}}.bg-white\/50{background-color:#ffffff80}@supports (color:color-mix(in lab,red,red)){.bg-white\/50{background-color:color-mix(in oklab,var(--color-white)50%,transparent)}}.bg-white\/70{background-color:#ffffffb3}@supports (color:color-mix(in lab,red,red)){.bg-white\/70{background-color:color-mix(in oklab,var(--color-white)70%,transparent)}}.bg-white\/90{background-color:#ffffffe6}@supports (color:color-mix(in lab,red,red)){.bg-white\/90{background-color:color-mix(in oklab,var(--color-white)90%,transparent)}}.bg-yellow-400{background-color:var(--color-yellow-400)}.bg-yellow-400\/10{background-color:#fac8001a}@supports (color:color-mix(in lab,red,red)){.bg-yellow-400\/10{background-color:color-mix(in oklab,var(--color-yellow-400)10%,transparent)}}.bg-yellow-400\/20{background-color:#fac80033}@supports (color:color-mix(in lab,red,red)){.bg-yellow-400\/20{background-color:color-mix(in oklab,var(--color-yellow-400)20%,transparent)}}.bg-yellow-500{background-color:var(--color-yellow-500)}.bg-yellow-500\/5{background-color:#edb2000d}@supports (color:color-mix(in lab,red,red)){.bg-yellow-500\/5{background-color:color-mix(in oklab,var(--color-yellow-500)5%,transparent)}}.bg-yellow-500\/10{background-color:#edb2001a}@supports (color:color-mix(in lab,red,red)){.bg-yellow-500\/10{background-color:color-mix(in oklab,var(--color-yellow-500)10%,transparent)}}.bg-yellow-500\/20{background-color:#edb20033}@supports (color:color-mix(in lab,red,red)){.bg-yellow-500\/20{background-color:color-mix(in oklab,var(--color-yellow-500)20%,transparent)}}.bg-zinc-600{background-color:var(--color-zinc-600)}.bg-zinc-700{background-color:var(--color-zinc-700)}.bg-zinc-700\/50{background-color:#3f3f4680}@supports (color:color-mix(in lab,red,red)){.bg-zinc-700\/50{background-color:color-mix(in oklab,var(--color-zinc-700)50%,transparent)}}.bg-zinc-800{background-color:var(--color-zinc-800)}.bg-zinc-800\/50{background-color:#27272a80}@supports (color:color-mix(in lab,red,red)){.bg-zinc-800\/50{background-color:color-mix(in oklab,var(--color-zinc-800)50%,transparent)}}.bg-zinc-900{background-color:var(--color-zinc-900)}.bg-zinc-900\/50{background-color:#18181b80}@supports (color:color-mix(in lab,red,red)){.bg-zinc-900\/50{background-color:color-mix(in oklab,var(--color-zinc-900)50%,transparent)}}.bg-gradient-to-b{--tw-gradient-position:to bottom in oklab;background-image:linear-gradient(var(--tw-gradient-stops))}.bg-gradient-to-br{--tw-gradient-position:to bottom right in oklab;background-image:linear-gradient(var(--tw-gradient-stops))}.bg-gradient-to-r{--tw-gradient-position:to right in oklab;background-image:linear-gradient(var(--tw-gradient-stops))}.bg-gradient-to-t{--tw-gradient-position:to top in oklab;background-image:linear-gradient(var(--tw-gradient-stops))}.from-bambu-dark-secondary{--tw-gradient-from:var(--color-bambu-dark-secondary);--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-bambu-green\/10{--tw-gradient-from:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.from-bambu-green\/10{--tw-gradient-from:color-mix(in oklab,var(--color-bambu-green)10%,transparent)}}.from-bambu-green\/10{--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-black\/80{--tw-gradient-from:#000c}@supports (color:color-mix(in lab,red,red)){.from-black\/80{--tw-gradient-from:color-mix(in oklab,var(--color-black)80%,transparent)}}.from-black\/80{--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-blue-500\/5{--tw-gradient-from:#3080ff0d}@supports (color:color-mix(in lab,red,red)){.from-blue-500\/5{--tw-gradient-from:color-mix(in oklab,var(--color-blue-500)5%,transparent)}}.from-blue-500\/5{--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-blue-500\/10{--tw-gradient-from:#3080ff1a}@supports (color:color-mix(in lab,red,red)){.from-blue-500\/10{--tw-gradient-from:color-mix(in oklab,var(--color-blue-500)10%,transparent)}}.from-blue-500\/10{--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-gray-500\/10{--tw-gradient-from:#6a72821a}@supports (color:color-mix(in lab,red,red)){.from-gray-500\/10{--tw-gradient-from:color-mix(in oklab,var(--color-gray-500)10%,transparent)}}.from-gray-500\/10{--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-purple-500\/10{--tw-gradient-from:#ac4bff1a}@supports (color:color-mix(in lab,red,red)){.from-purple-500\/10{--tw-gradient-from:color-mix(in oklab,var(--color-purple-500)10%,transparent)}}.from-purple-500\/10{--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-white\/10{--tw-gradient-from:#ffffff1a}@supports (color:color-mix(in lab,red,red)){.from-white\/10{--tw-gradient-from:color-mix(in oklab,var(--color-white)10%,transparent)}}.from-white\/10{--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-yellow-500\/10{--tw-gradient-from:#edb2001a}@supports (color:color-mix(in lab,red,red)){.from-yellow-500\/10{--tw-gradient-from:color-mix(in oklab,var(--color-yellow-500)10%,transparent)}}.from-yellow-500\/10{--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.via-black\/60{--tw-gradient-via:#0009}@supports (color:color-mix(in lab,red,red)){.via-black\/60{--tw-gradient-via:color-mix(in oklab,var(--color-black)60%,transparent)}}.via-black\/60{--tw-gradient-via-stops:var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-via)var(--tw-gradient-via-position),var(--tw-gradient-to)var(--tw-gradient-to-position);--tw-gradient-stops:var(--tw-gradient-via-stops)}.to-bambu-dark-secondary{--tw-gradient-to:var(--color-bambu-dark-secondary);--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.to-bambu-dark-tertiary{--tw-gradient-to:var(--color-bambu-dark-tertiary);--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.to-transparent{--tw-gradient-to:transparent;--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.bg-cover{background-size:cover}.bg-center{background-position:50%}.fill-yellow-400{fill:var(--color-yellow-400)}.object-contain{object-fit:contain}.object-cover{object-fit:cover}.object-left{object-position:left}.p-0{padding:calc(var(--spacing)*0)}.p-0\.5{padding:calc(var(--spacing)*.5)}.p-1{padding:calc(var(--spacing)*1)}.p-1\.5{padding:calc(var(--spacing)*1.5)}.p-2{padding:calc(var(--spacing)*2)}.p-2\.5{padding:calc(var(--spacing)*2.5)}.p-3{padding:calc(var(--spacing)*3)}.p-4{padding:calc(var(--spacing)*4)}.p-5{padding:calc(var(--spacing)*5)}.p-6{padding:calc(var(--spacing)*6)}.p-8{padding:calc(var(--spacing)*8)}.p-12{padding:calc(var(--spacing)*12)}.\!px-1\.5{padding-inline:calc(var(--spacing)*1.5)!important}.\!px-3{padding-inline:calc(var(--spacing)*3)!important}.px-1{padding-inline:calc(var(--spacing)*1)}.px-1\.5{padding-inline:calc(var(--spacing)*1.5)}.px-2{padding-inline:calc(var(--spacing)*2)}.px-2\.5{padding-inline:calc(var(--spacing)*2.5)}.px-3{padding-inline:calc(var(--spacing)*3)}.px-4{padding-inline:calc(var(--spacing)*4)}.px-5{padding-inline:calc(var(--spacing)*5)}.px-6{padding-inline:calc(var(--spacing)*6)}.py-0\.5{padding-block:calc(var(--spacing)*.5)}.py-1{padding-block:calc(var(--spacing)*1)}.py-1\.5{padding-block:calc(var(--spacing)*1.5)}.py-2{padding-block:calc(var(--spacing)*2)}.py-2\.5{padding-block:calc(var(--spacing)*2.5)}.py-3{padding-block:calc(var(--spacing)*3)}.py-4{padding-block:calc(var(--spacing)*4)}.py-6{padding-block:calc(var(--spacing)*6)}.py-8{padding-block:calc(var(--spacing)*8)}.py-12{padding-block:calc(var(--spacing)*12)}.py-16{padding-block:calc(var(--spacing)*16)}.py-20{padding-block:calc(var(--spacing)*20)}.py-24{padding-block:calc(var(--spacing)*24)}.pt-0{padding-top:calc(var(--spacing)*0)}.pt-1{padding-top:calc(var(--spacing)*1)}.pt-2{padding-top:calc(var(--spacing)*2)}.pt-3{padding-top:calc(var(--spacing)*3)}.pt-4{padding-top:calc(var(--spacing)*4)}.pr-1{padding-right:calc(var(--spacing)*1)}.pr-2{padding-right:calc(var(--spacing)*2)}.pr-3{padding-right:calc(var(--spacing)*3)}.pr-4{padding-right:calc(var(--spacing)*4)}.pr-6{padding-right:calc(var(--spacing)*6)}.pr-7{padding-right:calc(var(--spacing)*7)}.pr-8{padding-right:calc(var(--spacing)*8)}.pr-10{padding-right:calc(var(--spacing)*10)}.pb-1{padding-bottom:calc(var(--spacing)*1)}.pb-2{padding-bottom:calc(var(--spacing)*2)}.pb-3{padding-bottom:calc(var(--spacing)*3)}.pb-4{padding-bottom:calc(var(--spacing)*4)}.pl-2{padding-left:calc(var(--spacing)*2)}.pl-4{padding-left:calc(var(--spacing)*4)}.pl-5{padding-left:calc(var(--spacing)*5)}.pl-6{padding-left:calc(var(--spacing)*6)}.pl-7{padding-left:calc(var(--spacing)*7)}.pl-8{padding-left:calc(var(--spacing)*8)}.pl-9{padding-left:calc(var(--spacing)*9)}.pl-10{padding-left:calc(var(--spacing)*10)}.text-center{text-align:center}.text-left{text-align:left}.text-right{text-align:right}.font-mono{font-family:var(--font-mono)}.font-sans{font-family:var(--font-sans)}.text-2xl{font-size:var(--text-2xl);line-height:var(--tw-leading,var(--text-2xl--line-height))}.text-3xl{font-size:var(--text-3xl);line-height:var(--tw-leading,var(--text-3xl--line-height))}.text-5xl{font-size:var(--text-5xl);line-height:var(--tw-leading,var(--text-5xl--line-height))}.text-base{font-size:var(--text-base);line-height:var(--tw-leading,var(--text-base--line-height))}.text-lg{font-size:var(--text-lg);line-height:var(--tw-leading,var(--text-lg--line-height))}.text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.text-xl{font-size:var(--text-xl);line-height:var(--tw-leading,var(--text-xl--line-height))}.text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}.text-\[6px\]{font-size:6px}.text-\[7px\]{font-size:7px}.text-\[8px\]{font-size:8px}.text-\[9px\]{font-size:9px}.text-\[10px\]{font-size:10px}.text-\[11px\]{font-size:11px}.leading-none{--tw-leading:1;line-height:1}.leading-tight{--tw-leading:var(--leading-tight);line-height:var(--leading-tight)}.font-bold{--tw-font-weight:var(--font-weight-bold);font-weight:var(--font-weight-bold)}.font-light{--tw-font-weight:var(--font-weight-light);font-weight:var(--font-weight-light)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.font-normal{--tw-font-weight:var(--font-weight-normal);font-weight:var(--font-weight-normal)}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.tracking-wide{--tw-tracking:var(--tracking-wide);letter-spacing:var(--tracking-wide)}.tracking-wider{--tw-tracking:var(--tracking-wider);letter-spacing:var(--tracking-wider)}.tracking-widest{--tw-tracking:var(--tracking-widest);letter-spacing:var(--tracking-widest)}.break-words{overflow-wrap:break-word}.break-all{word-break:break-all}.whitespace-nowrap{white-space:nowrap}.whitespace-pre-line{white-space:pre-line}.whitespace-pre-wrap{white-space:pre-wrap}.\!text-green-400{color:var(--color-green-400)!important}.\!text-white{color:var(--color-white)!important}.\!text-yellow-400{color:var(--color-yellow-400)!important}.text-amber-200{color:var(--color-amber-200)}.text-amber-200\/80{color:#fee685cc}@supports (color:color-mix(in lab,red,red)){.text-amber-200\/80{color:color-mix(in oklab,var(--color-amber-200)80%,transparent)}}.text-amber-300{color:var(--color-amber-300)}.text-amber-300\/60{color:#ffd23699}@supports (color:color-mix(in lab,red,red)){.text-amber-300\/60{color:color-mix(in oklab,var(--color-amber-300)60%,transparent)}}.text-amber-300\/70{color:#ffd236b3}@supports (color:color-mix(in lab,red,red)){.text-amber-300\/70{color:color-mix(in oklab,var(--color-amber-300)70%,transparent)}}.text-amber-300\/80{color:#ffd236cc}@supports (color:color-mix(in lab,red,red)){.text-amber-300\/80{color:color-mix(in oklab,var(--color-amber-300)80%,transparent)}}.text-amber-400{color:var(--color-amber-400)}.text-amber-400\/70{color:#fcbb00b3}@supports (color:color-mix(in lab,red,red)){.text-amber-400\/70{color:color-mix(in oklab,var(--color-amber-400)70%,transparent)}}.text-amber-500{color:var(--color-amber-500)}.text-amber-500\/80{color:#f99c00cc}@supports (color:color-mix(in lab,red,red)){.text-amber-500\/80{color:color-mix(in oklab,var(--color-amber-500)80%,transparent)}}.text-amber-600{color:var(--color-amber-600)}.text-amber-700{color:var(--color-amber-700)}.text-amber-800{color:var(--color-amber-800)}.text-bambu-dark-tertiary{color:var(--color-bambu-dark-tertiary)}.text-bambu-gray{color:var(--color-bambu-gray)}.text-bambu-gray-dark{color:var(--color-bambu-gray-dark)}.text-bambu-gray-light{color:var(--color-bambu-gray-light)}.text-bambu-gray\/30{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.text-bambu-gray\/30{color:color-mix(in oklab,var(--color-bambu-gray)30%,transparent)}}.text-bambu-gray\/40{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.text-bambu-gray\/40{color:color-mix(in oklab,var(--color-bambu-gray)40%,transparent)}}.text-bambu-gray\/50{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.text-bambu-gray\/50{color:color-mix(in oklab,var(--color-bambu-gray)50%,transparent)}}.text-bambu-gray\/60{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.text-bambu-gray\/60{color:color-mix(in oklab,var(--color-bambu-gray)60%,transparent)}}.text-bambu-gray\/70{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.text-bambu-gray\/70{color:color-mix(in oklab,var(--color-bambu-gray)70%,transparent)}}.text-bambu-gray\/80{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.text-bambu-gray\/80{color:color-mix(in oklab,var(--color-bambu-gray)80%,transparent)}}.text-bambu-green,.text-bambu-green\/70{color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.text-bambu-green\/70{color:color-mix(in oklab,var(--color-bambu-green)70%,transparent)}}.text-black{color:var(--color-black)}.text-black\/80{color:#000c}@supports (color:color-mix(in lab,red,red)){.text-black\/80{color:color-mix(in oklab,var(--color-black)80%,transparent)}}.text-blue-300{color:var(--color-blue-300)}.text-blue-300\/70{color:#90c5ffb3}@supports (color:color-mix(in lab,red,red)){.text-blue-300\/70{color:color-mix(in oklab,var(--color-blue-300)70%,transparent)}}.text-blue-300\/80{color:#90c5ffcc}@supports (color:color-mix(in lab,red,red)){.text-blue-300\/80{color:color-mix(in oklab,var(--color-blue-300)80%,transparent)}}.text-blue-400{color:var(--color-blue-400)}.text-blue-500{color:var(--color-blue-500)}.text-blue-500\/70{color:#3080ffb3}@supports (color:color-mix(in lab,red,red)){.text-blue-500\/70{color:color-mix(in oklab,var(--color-blue-500)70%,transparent)}}.text-blue-600{color:var(--color-blue-600)}.text-blue-700{color:var(--color-blue-700)}.text-cyan-300{color:var(--color-cyan-300)}.text-cyan-400{color:var(--color-cyan-400)}.text-emerald-300{color:var(--color-emerald-300)}.text-emerald-400{color:var(--color-emerald-400)}.text-gray-300{color:var(--color-gray-300)}.text-gray-400{color:var(--color-gray-400)}.text-gray-500{color:var(--color-gray-500)}.text-gray-600{color:var(--color-gray-600)}.text-gray-700{color:var(--color-gray-700)}.text-gray-800{color:var(--color-gray-800)}.text-gray-900{color:var(--color-gray-900)}.text-green-200{color:var(--color-green-200)}.text-green-300{color:var(--color-green-300)}.text-green-400{color:var(--color-green-400)}.text-green-400\/60{color:#05df7299}@supports (color:color-mix(in lab,red,red)){.text-green-400\/60{color:color-mix(in oklab,var(--color-green-400)60%,transparent)}}.text-green-500{color:var(--color-green-500)}.text-green-500\/60{color:#00c75899}@supports (color:color-mix(in lab,red,red)){.text-green-500\/60{color:color-mix(in oklab,var(--color-green-500)60%,transparent)}}.text-green-600{color:var(--color-green-600)}.text-indigo-400{color:var(--color-indigo-400)}.text-orange-200{color:var(--color-orange-200)}.text-orange-300{color:var(--color-orange-300)}.text-orange-400{color:var(--color-orange-400)}.text-orange-500{color:var(--color-orange-500)}.text-orange-600{color:var(--color-orange-600)}.text-orange-700{color:var(--color-orange-700)}.text-purple-300{color:var(--color-purple-300)}.text-purple-300\/70{color:#d9b3ffb3}@supports (color:color-mix(in lab,red,red)){.text-purple-300\/70{color:color-mix(in oklab,var(--color-purple-300)70%,transparent)}}.text-purple-400{color:var(--color-purple-400)}.text-purple-400\/80{color:#c07effcc}@supports (color:color-mix(in lab,red,red)){.text-purple-400\/80{color:color-mix(in oklab,var(--color-purple-400)80%,transparent)}}.text-purple-500{color:var(--color-purple-500)}.text-red-200{color:var(--color-red-200)}.text-red-300{color:var(--color-red-300)}.text-red-300\/80{color:#ffa3a3cc}@supports (color:color-mix(in lab,red,red)){.text-red-300\/80{color:color-mix(in oklab,var(--color-red-300)80%,transparent)}}.text-red-400{color:var(--color-red-400)}.text-red-400\/50{color:#ff656880}@supports (color:color-mix(in lab,red,red)){.text-red-400\/50{color:color-mix(in oklab,var(--color-red-400)50%,transparent)}}.text-red-400\/60{color:#ff656899}@supports (color:color-mix(in lab,red,red)){.text-red-400\/60{color:color-mix(in oklab,var(--color-red-400)60%,transparent)}}.text-red-400\/70{color:#ff6568b3}@supports (color:color-mix(in lab,red,red)){.text-red-400\/70{color:color-mix(in oklab,var(--color-red-400)70%,transparent)}}.text-red-500{color:var(--color-red-500)}.text-red-600{color:var(--color-red-600)}.text-rose-300{color:var(--color-rose-300)}.text-rose-400{color:var(--color-rose-400)}.text-sky-400{color:var(--color-sky-400)}.text-slate-300{color:var(--color-slate-300)}.text-status-error{color:var(--color-status-error)}.text-status-ok{color:var(--color-status-ok)}.text-status-warning{color:var(--color-status-warning)}.text-teal-400{color:var(--color-teal-400)}.text-white{color:var(--color-white)}.text-white\/30{color:#ffffff4d}@supports (color:color-mix(in lab,red,red)){.text-white\/30{color:color-mix(in oklab,var(--color-white)30%,transparent)}}.text-white\/40{color:#fff6}@supports (color:color-mix(in lab,red,red)){.text-white\/40{color:color-mix(in oklab,var(--color-white)40%,transparent)}}.text-white\/50{color:#ffffff80}@supports (color:color-mix(in lab,red,red)){.text-white\/50{color:color-mix(in oklab,var(--color-white)50%,transparent)}}.text-white\/60{color:#fff9}@supports (color:color-mix(in lab,red,red)){.text-white\/60{color:color-mix(in oklab,var(--color-white)60%,transparent)}}.text-white\/70{color:#ffffffb3}@supports (color:color-mix(in lab,red,red)){.text-white\/70{color:color-mix(in oklab,var(--color-white)70%,transparent)}}.text-white\/80{color:#fffc}@supports (color:color-mix(in lab,red,red)){.text-white\/80{color:color-mix(in oklab,var(--color-white)80%,transparent)}}.text-white\/90{color:#ffffffe6}@supports (color:color-mix(in lab,red,red)){.text-white\/90{color:color-mix(in oklab,var(--color-white)90%,transparent)}}.text-yellow-200{color:var(--color-yellow-200)}.text-yellow-200\/70{color:#fff085b3}@supports (color:color-mix(in lab,red,red)){.text-yellow-200\/70{color:color-mix(in oklab,var(--color-yellow-200)70%,transparent)}}.text-yellow-300{color:var(--color-yellow-300)}.text-yellow-400{color:var(--color-yellow-400)}.text-yellow-500{color:var(--color-yellow-500)}.text-yellow-500\/70{color:#edb200b3}@supports (color:color-mix(in lab,red,red)){.text-yellow-500\/70{color:color-mix(in oklab,var(--color-yellow-500)70%,transparent)}}.text-yellow-500\/80{color:#edb200cc}@supports (color:color-mix(in lab,red,red)){.text-yellow-500\/80{color:color-mix(in oklab,var(--color-yellow-500)80%,transparent)}}.text-yellow-600{color:var(--color-yellow-600)}.text-yellow-700{color:var(--color-yellow-700)}.text-zinc-100{color:var(--color-zinc-100)}.text-zinc-200{color:var(--color-zinc-200)}.text-zinc-300{color:var(--color-zinc-300)}.text-zinc-400{color:var(--color-zinc-400)}.text-zinc-500{color:var(--color-zinc-500)}.text-zinc-600{color:var(--color-zinc-600)}.capitalize{text-transform:capitalize}.uppercase{text-transform:uppercase}.italic{font-style:italic}.tabular-nums{--tw-numeric-spacing:tabular-nums;font-variant-numeric:var(--tw-ordinal,)var(--tw-slashed-zero,)var(--tw-numeric-figure,)var(--tw-numeric-spacing,)var(--tw-numeric-fraction,)}.line-through{text-decoration-line:line-through}.underline{text-decoration-line:underline}.placeholder-bambu-gray::placeholder{color:var(--color-bambu-gray)}.placeholder-bambu-gray-dark::placeholder{color:var(--color-bambu-gray-dark)}.placeholder-bambu-gray\/40::placeholder{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.placeholder-bambu-gray\/40::placeholder{color:color-mix(in oklab,var(--color-bambu-gray)40%,transparent)}}.placeholder-bambu-gray\/50::placeholder{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.placeholder-bambu-gray\/50::placeholder{color:color-mix(in oklab,var(--color-bambu-gray)50%,transparent)}}.placeholder-bambu-gray\/60::placeholder{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.placeholder-bambu-gray\/60::placeholder{color:color-mix(in oklab,var(--color-bambu-gray)60%,transparent)}}.placeholder-gray-400::placeholder{color:var(--color-gray-400)}.placeholder-zinc-500::placeholder{color:var(--color-zinc-500)}.accent-amber-500{accent-color:var(--color-amber-500)}.accent-bambu-green{accent-color:var(--color-bambu-green)}.accent-green-500{accent-color:var(--color-green-500)}.\[color-scheme\:dark\]{color-scheme:dark}.opacity-0{opacity:0}.opacity-20{opacity:.2}.opacity-25{opacity:.25}.opacity-30{opacity:.3}.opacity-40{opacity:.4}.opacity-50{opacity:.5}.opacity-60{opacity:.6}.opacity-70{opacity:.7}.opacity-75{opacity:.75}.opacity-80{opacity:.8}.opacity-100{opacity:1}.shadow{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a),0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-2xl{--tw-shadow:0 25px 50px -12px var(--tw-shadow-color,#00000040);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-\[0_0_6px_rgba\(34\,197\,94\,0\.5\)\]{--tw-shadow:0 0 6px var(--tw-shadow-color,#22c55e80);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-lg{--tw-shadow:0 10px 15px -3px var(--tw-shadow-color,#0000001a),0 4px 6px -4px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-md{--tw-shadow:0 4px 6px -1px var(--tw-shadow-color,#0000001a),0 2px 4px -2px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-sm{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a),0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-xl{--tw-shadow:0 20px 25px -5px var(--tw-shadow-color,#0000001a),0 8px 10px -6px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow\/depth{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a),0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.ring,.ring-1{--tw-ring-shadow:var(--tw-ring-inset,)0 0 0 calc(1px + var(--tw-ring-offset-width))var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.ring-2{--tw-ring-shadow:var(--tw-ring-inset,)0 0 0 calc(2px + var(--tw-ring-offset-width))var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-bambu-green\/20{--tw-shadow-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.shadow-bambu-green\/20{--tw-shadow-color:color-mix(in oklab,color-mix(in oklab,var(--color-bambu-green)20%,transparent)var(--tw-shadow-alpha),transparent)}}.shadow-bambu-green\/25{--tw-shadow-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.shadow-bambu-green\/25{--tw-shadow-color:color-mix(in oklab,color-mix(in oklab,var(--color-bambu-green)25%,transparent)var(--tw-shadow-alpha),transparent)}}.ring-bambu-green,.ring-bambu-green\/30{--tw-ring-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.ring-bambu-green\/30{--tw-ring-color:color-mix(in oklab,var(--color-bambu-green)30%,transparent)}}.ring-blue-400\/50{--tw-ring-color:#54a2ff80}@supports (color:color-mix(in lab,red,red)){.ring-blue-400\/50{--tw-ring-color:color-mix(in oklab,var(--color-blue-400)50%,transparent)}}.ring-green-500{--tw-ring-color:var(--color-green-500)}.ring-white{--tw-ring-color:var(--color-white)}.ring-offset-1{--tw-ring-offset-width:1px;--tw-ring-offset-shadow:var(--tw-ring-inset,)0 0 0 var(--tw-ring-offset-width)var(--tw-ring-offset-color)}.ring-offset-2{--tw-ring-offset-width:2px;--tw-ring-offset-shadow:var(--tw-ring-inset,)0 0 0 var(--tw-ring-offset-width)var(--tw-ring-offset-color)}.ring-offset-bambu-dark{--tw-ring-offset-color:var(--color-bambu-dark)}.ring-offset-bambu-dark-secondary{--tw-ring-offset-color:var(--color-bambu-dark-secondary)}.outline{outline-style:var(--tw-outline-style);outline-width:1px}.blur{--tw-blur:blur(8px);filter:var(--tw-blur,)var(--tw-brightness,)var(--tw-contrast,)var(--tw-grayscale,)var(--tw-hue-rotate,)var(--tw-invert,)var(--tw-saturate,)var(--tw-sepia,)var(--tw-drop-shadow,)}.blur-2xl{--tw-blur:blur(var(--blur-2xl));filter:var(--tw-blur,)var(--tw-brightness,)var(--tw-contrast,)var(--tw-grayscale,)var(--tw-hue-rotate,)var(--tw-invert,)var(--tw-saturate,)var(--tw-sepia,)var(--tw-drop-shadow,)}.drop-shadow-lg{--tw-drop-shadow-size:drop-shadow(0 4px 4px var(--tw-drop-shadow-color,#00000026));--tw-drop-shadow:drop-shadow(var(--drop-shadow-lg));filter:var(--tw-blur,)var(--tw-brightness,)var(--tw-contrast,)var(--tw-grayscale,)var(--tw-hue-rotate,)var(--tw-invert,)var(--tw-saturate,)var(--tw-sepia,)var(--tw-drop-shadow,)}.drop-shadow-md{--tw-drop-shadow-size:drop-shadow(0 3px 3px var(--tw-drop-shadow-color,#0000001f));--tw-drop-shadow:drop-shadow(var(--drop-shadow-md));filter:var(--tw-blur,)var(--tw-brightness,)var(--tw-contrast,)var(--tw-grayscale,)var(--tw-hue-rotate,)var(--tw-invert,)var(--tw-saturate,)var(--tw-sepia,)var(--tw-drop-shadow,)}.filter{filter:var(--tw-blur,)var(--tw-brightness,)var(--tw-contrast,)var(--tw-grayscale,)var(--tw-hue-rotate,)var(--tw-invert,)var(--tw-saturate,)var(--tw-sepia,)var(--tw-drop-shadow,)}.backdrop-blur-sm{--tw-backdrop-blur:blur(var(--blur-sm));-webkit-backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,);backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,)}.transition{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to,opacity,box-shadow,transform,translate,scale,rotate,filter,-webkit-backdrop-filter,backdrop-filter,display,content-visibility,overlay,pointer-events;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-all{transition-property:all;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-colors{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-opacity{transition-property:opacity;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-transform{transition-property:transform,translate,scale,rotate;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.duration-150{--tw-duration:.15s;transition-duration:.15s}.duration-200{--tw-duration:.2s;transition-duration:.2s}.duration-300{--tw-duration:.3s;transition-duration:.3s}.duration-500{--tw-duration:.5s;transition-duration:.5s}.duration-1000{--tw-duration:1s;transition-duration:1s}.ease-in-out{--tw-ease:var(--ease-in-out);transition-timing-function:var(--ease-in-out)}.ease-out{--tw-ease:var(--ease-out);transition-timing-function:var(--ease-out)}.select-none{-webkit-user-select:none;user-select:none}@media(hover:hover){.group-hover\:bg-bambu-green\/20:is(:where(.group):hover *){background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.group-hover\:bg-bambu-green\/20:is(:where(.group):hover *){background-color:color-mix(in oklab,var(--color-bambu-green)20%,transparent)}}.group-hover\:text-bambu-gray:is(:where(.group):hover *){color:var(--color-bambu-gray)}.group-hover\:text-bambu-green:is(:where(.group):hover *){color:var(--color-bambu-green)}.group-hover\:opacity-50:is(:where(.group):hover *){opacity:.5}.group-hover\:opacity-100:is(:where(.group):hover *),.group-hover\/resize\:opacity-100:is(:where(.group\/resize):hover *){opacity:1}.group-hover\/thumb\:block:is(:where(.group\/thumb):hover *){display:block}}.peer-checked\:bg-amber-500:is(:where(.peer):checked~*){background-color:var(--color-amber-500)}.peer-checked\:bg-bambu-green:is(:where(.peer):checked~*){background-color:var(--color-bambu-green)}.peer-focus\:outline-none:is(:where(.peer):focus~*){--tw-outline-style:none;outline-style:none}.peer-disabled\:cursor-not-allowed:is(:where(.peer):disabled~*){cursor:not-allowed}.placeholder\:text-bambu-gray::placeholder,.placeholder\:text-bambu-gray\/50::placeholder{color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.placeholder\:text-bambu-gray\/50::placeholder{color:color-mix(in oklab,var(--color-bambu-gray)50%,transparent)}}.before\:absolute:before{content:var(--tw-content);position:absolute}.before\:top-0:before{content:var(--tw-content);top:calc(var(--spacing)*0)}.before\:right-0:before{content:var(--tw-content);right:calc(var(--spacing)*0)}.before\:left-0:before{content:var(--tw-content);left:calc(var(--spacing)*0)}.before\:h-0\.5:before{content:var(--tw-content);height:calc(var(--spacing)*.5)}.before\:bg-bambu-green:before{content:var(--tw-content);background-color:var(--color-bambu-green)}.after\:absolute:after{content:var(--tw-content);position:absolute}.after\:top-\[2px\]:after{content:var(--tw-content);top:2px}.after\:left-\[2px\]:after{content:var(--tw-content);left:2px}.after\:h-4:after{content:var(--tw-content);height:calc(var(--spacing)*4)}.after\:h-5:after{content:var(--tw-content);height:calc(var(--spacing)*5)}.after\:w-4:after{content:var(--tw-content);width:calc(var(--spacing)*4)}.after\:w-5:after{content:var(--tw-content);width:calc(var(--spacing)*5)}.after\:rounded-full:after{content:var(--tw-content);border-radius:3.40282e38px}.after\:border:after{content:var(--tw-content);border-style:var(--tw-border-style);border-width:1px}.after\:border-gray-300:after{content:var(--tw-content);border-color:var(--color-gray-300)}.after\:bg-white:after{content:var(--tw-content);background-color:var(--color-white)}.after\:transition-all:after{content:var(--tw-content);transition-property:all;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.after\:content-\[\'\'\]:after{--tw-content:"";content:var(--tw-content)}.peer-checked\:after\:translate-x-full:is(:where(.peer):checked~*):after{content:var(--tw-content);--tw-translate-x:100%;translate:var(--tw-translate-x)var(--tw-translate-y)}.peer-checked\:after\:border-white:is(:where(.peer):checked~*):after{content:var(--tw-content);border-color:var(--color-white)}.last\:border-0:last-child{border-style:var(--tw-border-style);border-width:0}.last\:border-b-0:last-child{border-bottom-style:var(--tw-border-style);border-bottom-width:0}@media(hover:hover){.hover\:z-20:hover{z-index:20}.hover\:scale-105:hover{--tw-scale-x:105%;--tw-scale-y:105%;--tw-scale-z:105%;scale:var(--tw-scale-x)var(--tw-scale-y)}.hover\:scale-110:hover{--tw-scale-x:110%;--tw-scale-y:110%;--tw-scale-z:110%;scale:var(--tw-scale-x)var(--tw-scale-y)}.hover\:border-bambu-dark-tertiary\/80:hover{border-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.hover\:border-bambu-dark-tertiary\/80:hover{border-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)80%,transparent)}}.hover\:border-bambu-gray:hover{border-color:var(--color-bambu-gray)}.hover\:border-bambu-gray-dark:hover{border-color:var(--color-bambu-gray-dark)}.hover\:border-bambu-gray\/50:hover{border-color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.hover\:border-bambu-gray\/50:hover{border-color:color-mix(in oklab,var(--color-bambu-gray)50%,transparent)}}.hover\:border-bambu-green:hover,.hover\:border-bambu-green\/50:hover{border-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:border-bambu-green\/50:hover{border-color:color-mix(in oklab,var(--color-bambu-green)50%,transparent)}}.hover\:border-gray-400:hover{border-color:var(--color-gray-400)}.hover\:border-green-500\/50:hover{border-color:#00c75880}@supports (color:color-mix(in lab,red,red)){.hover\:border-green-500\/50:hover{border-color:color-mix(in oklab,var(--color-green-500)50%,transparent)}}.hover\:border-white:hover{border-color:var(--color-white)}.hover\:border-white\/40:hover{border-color:#fff6}@supports (color:color-mix(in lab,red,red)){.hover\:border-white\/40:hover{border-color:color-mix(in oklab,var(--color-white)40%,transparent)}}.hover\:\!bg-bambu-green\/80:hover{background-color:var(--color-bambu-green)!important}@supports (color:color-mix(in lab,red,red)){.hover\:\!bg-bambu-green\/80:hover{background-color:color-mix(in oklab,var(--color-bambu-green)80%,transparent)!important}}.hover\:\!bg-green-500\/20:hover{background-color:#00c75833!important}@supports (color:color-mix(in lab,red,red)){.hover\:\!bg-green-500\/20:hover{background-color:color-mix(in oklab,var(--color-green-500)20%,transparent)!important}}.hover\:\!bg-yellow-500\/20:hover{background-color:#edb20033!important}@supports (color:color-mix(in lab,red,red)){.hover\:\!bg-yellow-500\/20:hover{background-color:color-mix(in oklab,var(--color-yellow-500)20%,transparent)!important}}.hover\:bg-amber-400:hover{background-color:var(--color-amber-400)}.hover\:bg-amber-500\/30:hover{background-color:#f99c004d}@supports (color:color-mix(in lab,red,red)){.hover\:bg-amber-500\/30:hover{background-color:color-mix(in oklab,var(--color-amber-500)30%,transparent)}}.hover\:bg-bambu-dark:hover{background-color:var(--color-bambu-dark)}.hover\:bg-bambu-dark-secondary:hover,.hover\:bg-bambu-dark-secondary\/50:hover{background-color:var(--color-bambu-dark-secondary)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-dark-secondary\/50:hover{background-color:color-mix(in oklab,var(--color-bambu-dark-secondary)50%,transparent)}}.hover\:bg-bambu-dark-secondary\/80:hover{background-color:var(--color-bambu-dark-secondary)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-dark-secondary\/80:hover{background-color:color-mix(in oklab,var(--color-bambu-dark-secondary)80%,transparent)}}.hover\:bg-bambu-dark-tertiary:hover,.hover\:bg-bambu-dark-tertiary\/30:hover{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-dark-tertiary\/30:hover{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)30%,transparent)}}.hover\:bg-bambu-dark-tertiary\/50:hover{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-dark-tertiary\/50:hover{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)50%,transparent)}}.hover\:bg-bambu-dark-tertiary\/70:hover{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-dark-tertiary\/70:hover{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)70%,transparent)}}.hover\:bg-bambu-dark-tertiary\/80:hover{background-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-dark-tertiary\/80:hover{background-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)80%,transparent)}}.hover\:bg-bambu-dark\/50:hover{background-color:var(--color-bambu-dark)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-dark\/50:hover{background-color:color-mix(in oklab,var(--color-bambu-dark)50%,transparent)}}.hover\:bg-bambu-dark\/80:hover{background-color:var(--color-bambu-dark)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-dark\/80:hover{background-color:color-mix(in oklab,var(--color-bambu-dark)80%,transparent)}}.hover\:bg-bambu-gray-dark:hover{background-color:var(--color-bambu-gray-dark)}.hover\:bg-bambu-green:hover{background-color:var(--color-bambu-green)}.hover\:bg-bambu-green-dark:hover{background-color:var(--color-bambu-green-dark)}.hover\:bg-bambu-green-light:hover{background-color:var(--color-bambu-green-light)}.hover\:bg-bambu-green\/10:hover{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-green\/10:hover{background-color:color-mix(in oklab,var(--color-bambu-green)10%,transparent)}}.hover\:bg-bambu-green\/20:hover{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-green\/20:hover{background-color:color-mix(in oklab,var(--color-bambu-green)20%,transparent)}}.hover\:bg-bambu-green\/30:hover{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-green\/30:hover{background-color:color-mix(in oklab,var(--color-bambu-green)30%,transparent)}}.hover\:bg-bambu-green\/50:hover{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-green\/50:hover{background-color:color-mix(in oklab,var(--color-bambu-green)50%,transparent)}}.hover\:bg-bambu-green\/80:hover{background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:bg-bambu-green\/80:hover{background-color:color-mix(in oklab,var(--color-bambu-green)80%,transparent)}}.hover\:bg-black\/40:hover{background-color:#0006}@supports (color:color-mix(in lab,red,red)){.hover\:bg-black\/40:hover{background-color:color-mix(in oklab,var(--color-black)40%,transparent)}}.hover\:bg-black\/70:hover{background-color:#000000b3}@supports (color:color-mix(in lab,red,red)){.hover\:bg-black\/70:hover{background-color:color-mix(in oklab,var(--color-black)70%,transparent)}}.hover\:bg-black\/80:hover{background-color:#000c}@supports (color:color-mix(in lab,red,red)){.hover\:bg-black\/80:hover{background-color:color-mix(in oklab,var(--color-black)80%,transparent)}}.hover\:bg-blue-500\/30:hover{background-color:#3080ff4d}@supports (color:color-mix(in lab,red,red)){.hover\:bg-blue-500\/30:hover{background-color:color-mix(in oklab,var(--color-blue-500)30%,transparent)}}.hover\:bg-gray-50:hover{background-color:var(--color-gray-50)}.hover\:bg-gray-100:hover{background-color:var(--color-gray-100)}.hover\:bg-gray-200:hover{background-color:var(--color-gray-200)}.hover\:bg-gray-700:hover{background-color:var(--color-gray-700)}.hover\:bg-green-500\/20:hover{background-color:#00c75833}@supports (color:color-mix(in lab,red,red)){.hover\:bg-green-500\/20:hover{background-color:color-mix(in oklab,var(--color-green-500)20%,transparent)}}.hover\:bg-green-700:hover{background-color:var(--color-green-700)}.hover\:bg-orange-400\/20:hover{background-color:#ff8b1a33}@supports (color:color-mix(in lab,red,red)){.hover\:bg-orange-400\/20:hover{background-color:color-mix(in oklab,var(--color-orange-400)20%,transparent)}}.hover\:bg-purple-600\/90:hover{background-color:#9810fae6}@supports (color:color-mix(in lab,red,red)){.hover\:bg-purple-600\/90:hover{background-color:color-mix(in oklab,var(--color-purple-600)90%,transparent)}}.hover\:bg-red-200:hover{background-color:var(--color-red-200)}.hover\:bg-red-400\/10:hover{background-color:#ff65681a}@supports (color:color-mix(in lab,red,red)){.hover\:bg-red-400\/10:hover{background-color:color-mix(in oklab,var(--color-red-400)10%,transparent)}}.hover\:bg-red-500\/10:hover{background-color:#fb2c361a}@supports (color:color-mix(in lab,red,red)){.hover\:bg-red-500\/10:hover{background-color:color-mix(in oklab,var(--color-red-500)10%,transparent)}}.hover\:bg-red-500\/20:hover{background-color:#fb2c3633}@supports (color:color-mix(in lab,red,red)){.hover\:bg-red-500\/20:hover{background-color:color-mix(in oklab,var(--color-red-500)20%,transparent)}}.hover\:bg-red-500\/30:hover{background-color:#fb2c364d}@supports (color:color-mix(in lab,red,red)){.hover\:bg-red-500\/30:hover{background-color:color-mix(in oklab,var(--color-red-500)30%,transparent)}}.hover\:bg-red-600:hover{background-color:var(--color-red-600)}.hover\:bg-red-700:hover{background-color:var(--color-red-700)}.hover\:bg-white\/5:hover{background-color:#ffffff0d}@supports (color:color-mix(in lab,red,red)){.hover\:bg-white\/5:hover{background-color:color-mix(in oklab,var(--color-white)5%,transparent)}}.hover\:bg-white\/10:hover{background-color:#ffffff1a}@supports (color:color-mix(in lab,red,red)){.hover\:bg-white\/10:hover{background-color:color-mix(in oklab,var(--color-white)10%,transparent)}}.hover\:bg-white\/80:hover{background-color:#fffc}@supports (color:color-mix(in lab,red,red)){.hover\:bg-white\/80:hover{background-color:color-mix(in oklab,var(--color-white)80%,transparent)}}.hover\:bg-yellow-500\/30:hover{background-color:#edb2004d}@supports (color:color-mix(in lab,red,red)){.hover\:bg-yellow-500\/30:hover{background-color:color-mix(in oklab,var(--color-yellow-500)30%,transparent)}}.hover\:bg-yellow-600:hover{background-color:var(--color-yellow-600)}.hover\:bg-zinc-600:hover{background-color:var(--color-zinc-600)}.hover\:bg-zinc-700:hover{background-color:var(--color-zinc-700)}.hover\:bg-zinc-700\/50:hover{background-color:#3f3f4680}@supports (color:color-mix(in lab,red,red)){.hover\:bg-zinc-700\/50:hover{background-color:color-mix(in oklab,var(--color-zinc-700)50%,transparent)}}.hover\:bg-zinc-800:hover{background-color:var(--color-zinc-800)}.hover\:text-amber-300:hover{color:var(--color-amber-300)}.hover\:text-amber-800:hover{color:var(--color-amber-800)}.hover\:text-bambu-gray:hover{color:var(--color-bambu-gray)}.hover\:text-bambu-green:hover{color:var(--color-bambu-green)}.hover\:text-bambu-green-light:hover{color:var(--color-bambu-green-light)}.hover\:text-bambu-green\/70:hover{color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:text-bambu-green\/70:hover{color:color-mix(in oklab,var(--color-bambu-green)70%,transparent)}}.hover\:text-bambu-green\/80:hover{color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:text-bambu-green\/80:hover{color:color-mix(in oklab,var(--color-bambu-green)80%,transparent)}}.hover\:text-blue-300:hover{color:var(--color-blue-300)}.hover\:text-blue-600:hover{color:var(--color-blue-600)}.hover\:text-gray-600:hover{color:var(--color-gray-600)}.hover\:text-gray-900:hover{color:var(--color-gray-900)}.hover\:text-orange-300:hover{color:var(--color-orange-300)}.hover\:text-red-200:hover{color:var(--color-red-200)}.hover\:text-red-300:hover{color:var(--color-red-300)}.hover\:text-red-400:hover{color:var(--color-red-400)}.hover\:text-white:hover{color:var(--color-white)}.hover\:text-white\/70:hover{color:#ffffffb3}@supports (color:color-mix(in lab,red,red)){.hover\:text-white\/70:hover{color:color-mix(in oklab,var(--color-white)70%,transparent)}}.hover\:text-white\/80:hover{color:#fffc}@supports (color:color-mix(in lab,red,red)){.hover\:text-white\/80:hover{color:color-mix(in oklab,var(--color-white)80%,transparent)}}.hover\:text-yellow-400:hover{color:var(--color-yellow-400)}.hover\:text-zinc-200:hover{color:var(--color-zinc-200)}.hover\:text-zinc-300:hover{color:var(--color-zinc-300)}.hover\:underline:hover{text-decoration-line:underline}.hover\:opacity-70:hover{opacity:.7}.hover\:opacity-80:hover{opacity:.8}.hover\:shadow-lg:hover{--tw-shadow:0 10px 15px -3px var(--tw-shadow-color,#0000001a),0 4px 6px -4px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.hover\:shadow-xl:hover{--tw-shadow:0 20px 25px -5px var(--tw-shadow-color,#0000001a),0 8px 10px -6px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.hover\:shadow-bambu-green\/5:hover{--tw-shadow-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:shadow-bambu-green\/5:hover{--tw-shadow-color:color-mix(in oklab,color-mix(in oklab,var(--color-bambu-green)5%,transparent)var(--tw-shadow-alpha),transparent)}}.hover\:shadow-bambu-green\/30:hover{--tw-shadow-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.hover\:shadow-bambu-green\/30:hover{--tw-shadow-color:color-mix(in oklab,color-mix(in oklab,var(--color-bambu-green)30%,transparent)var(--tw-shadow-alpha),transparent)}}}.focus\:border-amber-500\/50:focus{border-color:#f99c0080}@supports (color:color-mix(in lab,red,red)){.focus\:border-amber-500\/50:focus{border-color:color-mix(in oklab,var(--color-amber-500)50%,transparent)}}.focus\:border-bambu-green:focus{border-color:var(--color-bambu-green)}.focus\:border-red-500:focus{border-color:var(--color-red-500)}.focus\:border-transparent:focus{border-color:#0000}.focus\:ring-1:focus{--tw-ring-shadow:var(--tw-ring-inset,)0 0 0 calc(1px + var(--tw-ring-offset-width))var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.focus\:ring-2:focus{--tw-ring-shadow:var(--tw-ring-inset,)0 0 0 calc(2px + var(--tw-ring-offset-width))var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.focus\:ring-bambu-gray:focus{--tw-ring-color:var(--color-bambu-gray)}.focus\:ring-bambu-green:focus,.focus\:ring-bambu-green\/50:focus{--tw-ring-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.focus\:ring-bambu-green\/50:focus{--tw-ring-color:color-mix(in oklab,var(--color-bambu-green)50%,transparent)}}.focus\:ring-blue-500:focus{--tw-ring-color:var(--color-blue-500)}.focus\:ring-red-500:focus{--tw-ring-color:var(--color-red-500)}.focus\:ring-offset-0:focus{--tw-ring-offset-width:0px;--tw-ring-offset-shadow:var(--tw-ring-inset,)0 0 0 var(--tw-ring-offset-width)var(--tw-ring-offset-color)}.focus\:ring-offset-2:focus{--tw-ring-offset-width:2px;--tw-ring-offset-shadow:var(--tw-ring-inset,)0 0 0 var(--tw-ring-offset-width)var(--tw-ring-offset-color)}.focus\:ring-offset-bambu-dark:focus{--tw-ring-offset-color:var(--color-bambu-dark)}.focus\:ring-offset-bambu-dark-secondary:focus{--tw-ring-offset-color:var(--color-bambu-dark-secondary)}.focus\:outline-none:focus{--tw-outline-style:none;outline-style:none}.active\:scale-95:active{--tw-scale-x:95%;--tw-scale-y:95%;--tw-scale-z:95%;scale:var(--tw-scale-x)var(--tw-scale-y)}.active\:cursor-grabbing:active{cursor:grabbing}.disabled\:cursor-not-allowed:disabled{cursor:not-allowed}.disabled\:opacity-30:disabled{opacity:.3}.disabled\:opacity-40:disabled{opacity:.4}.disabled\:opacity-50:disabled{opacity:.5}@media(hover:hover){.disabled\:hover\:bg-bambu-green:disabled:hover{background-color:var(--color-bambu-green)}}@media not all and (min-width:640px){.max-\[640px\]\:hidden{display:none}.max-\[640px\]\:w-full{width:100%}.max-\[640px\]\:grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.max-\[640px\]\:flex-col{flex-direction:column}.max-\[640px\]\:flex-wrap{flex-wrap:wrap}.max-\[640px\]\:items-center{align-items:center}.max-\[640px\]\:items-start{align-items:flex-start}}@media not all and (min-width:550px){.max-\[550px\]\:order-1{order:1}.max-\[550px\]\:order-2{order:2}.max-\[550px\]\:order-3{order:3}.max-\[550px\]\:order-4{order:4}.max-\[550px\]\:mt-1{margin-top:calc(var(--spacing)*1)}.max-\[550px\]\:w-full{width:100%}.max-\[550px\]\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.max-\[550px\]\:flex-col{flex-direction:column}.max-\[550px\]\:flex-wrap{flex-wrap:wrap}.max-\[550px\]\:items-center{align-items:center}.max-\[550px\]\:items-start{align-items:flex-start}.max-\[550px\]\:justify-end{justify-content:flex-end}.max-\[550px\]\:gap-1\.5{gap:calc(var(--spacing)*1.5)}.max-\[550px\]\:gap-3{gap:calc(var(--spacing)*3)}.max-\[550px\]\:self-start{align-self:flex-start}}@media(min-width:40rem){.sm\:col-span-1{grid-column:span 1/span 1}.sm\:mt-0{margin-top:calc(var(--spacing)*0)}.sm\:mt-2{margin-top:calc(var(--spacing)*2)}.sm\:mt-3{margin-top:calc(var(--spacing)*3)}.sm\:mr-1{margin-right:calc(var(--spacing)*1)}.sm\:mb-4{margin-bottom:calc(var(--spacing)*4)}.sm\:ml-auto{margin-left:auto}.sm\:block{display:block}.sm\:flex{display:flex}.sm\:grid{display:grid}.sm\:hidden{display:none}.sm\:inline{display:inline}.sm\:h-2{height:calc(var(--spacing)*2)}.sm\:h-3{height:calc(var(--spacing)*3)}.sm\:h-3\.5{height:calc(var(--spacing)*3.5)}.sm\:h-4{height:calc(var(--spacing)*4)}.sm\:h-5{height:calc(var(--spacing)*5)}.sm\:h-6{height:calc(var(--spacing)*6)}.sm\:h-10{height:calc(var(--spacing)*10)}.sm\:h-14{height:calc(var(--spacing)*14)}.sm\:w-3{width:calc(var(--spacing)*3)}.sm\:w-3\.5{width:calc(var(--spacing)*3.5)}.sm\:w-4{width:calc(var(--spacing)*4)}.sm\:w-5{width:calc(var(--spacing)*5)}.sm\:w-6{width:calc(var(--spacing)*6)}.sm\:w-10{width:calc(var(--spacing)*10)}.sm\:w-14{width:calc(var(--spacing)*14)}.sm\:w-16{width:calc(var(--spacing)*16)}.sm\:w-40{width:calc(var(--spacing)*40)}.sm\:w-auto{width:auto}.sm\:max-w-none{max-width:none}.sm\:max-w-xs{max-width:var(--container-xs)}.sm\:flex-1{flex:1}.sm\:flex-none{flex:none}.sm\:cursor-default{cursor:default}.sm\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.sm\:grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.sm\:grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}.sm\:flex-row{flex-direction:row}.sm\:items-center{align-items:center}.sm\:justify-between{justify-content:space-between}.sm\:gap-1{gap:calc(var(--spacing)*1)}.sm\:gap-1\.5{gap:calc(var(--spacing)*1.5)}.sm\:gap-2{gap:calc(var(--spacing)*2)}.sm\:gap-3{gap:calc(var(--spacing)*3)}.sm\:gap-4{gap:calc(var(--spacing)*4)}.sm\:gap-6{gap:calc(var(--spacing)*6)}:where(.sm\:space-y-3>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*3)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*3)*calc(1 - var(--tw-space-y-reverse)))}:where(.sm\:space-y-8>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*8)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*8)*calc(1 - var(--tw-space-y-reverse)))}.sm\:border-bambu-dark-tertiary{border-color:var(--color-bambu-dark-tertiary)}.sm\:p-1\.5{padding:calc(var(--spacing)*1.5)}.sm\:p-2{padding:calc(var(--spacing)*2)}.sm\:p-3{padding:calc(var(--spacing)*3)}.sm\:p-4{padding:calc(var(--spacing)*4)}.sm\:px-2{padding-inline:calc(var(--spacing)*2)}.sm\:px-3{padding-inline:calc(var(--spacing)*3)}.sm\:text-2xl{font-size:var(--text-2xl);line-height:var(--tw-leading,var(--text-2xl--line-height))}.sm\:text-base{font-size:var(--text-base);line-height:var(--tw-leading,var(--text-base--line-height))}.sm\:text-lg{font-size:var(--text-lg);line-height:var(--tw-leading,var(--text-lg--line-height))}.sm\:text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.sm\:text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}}@media(min-width:48rem){.md\:top-\[2px\]{top:2px}.md\:left-\[2px\]{left:2px}.md\:mx-0{margin-inline:calc(var(--spacing)*0)}.md\:block{display:block}.md\:inline{display:inline}.md\:h-4{height:calc(var(--spacing)*4)}.md\:h-5{height:calc(var(--spacing)*5)}.md\:min-h-0{min-height:calc(var(--spacing)*0)}.md\:w-4{width:calc(var(--spacing)*4)}.md\:w-9{width:calc(var(--spacing)*9)}.md\:min-w-\[200px\]{min-width:200px}.md\:flex-1{flex:1}.md\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.md\:grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.md\:grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}.md\:grid-cols-5{grid-template-columns:repeat(5,minmax(0,1fr))}.md\:flex-row{flex-direction:row}.md\:flex-wrap{flex-wrap:wrap}.md\:items-center{align-items:center}.md\:gap-4{gap:calc(var(--spacing)*4)}.md\:p-6{padding:calc(var(--spacing)*6)}.md\:p-8{padding:calc(var(--spacing)*8)}.md\:px-0{padding-inline:calc(var(--spacing)*0)}.md\:py-2{padding-block:calc(var(--spacing)*2)}.md\:pb-0{padding-bottom:calc(var(--spacing)*0)}}@media(min-width:64rem){.lg\:static{position:static}.lg\:col-span-2{grid-column:span 2/span 2}.lg\:col-span-3{grid-column:span 3/span 3}.lg\:flex{display:flex}.lg\:hidden{display:none}.lg\:h-\[calc\(100vh-64px\)\]{height:calc(100vh - 64px)}.lg\:w-1\/3{width:33.3333%}.lg\:w-2\/3{width:66.6667%}.lg\:w-80{width:calc(var(--spacing)*80)}.lg\:w-\[480px\]{width:480px}.lg\:max-w-md{max-width:var(--container-md)}.lg\:max-w-sm{max-width:var(--container-sm)}.lg\:max-w-xl{max-width:var(--container-xl)}.lg\:flex-shrink-0{flex-shrink:0}.lg\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.lg\:grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.lg\:grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}.lg\:grid-cols-5{grid-template-columns:repeat(5,minmax(0,1fr))}.lg\:flex-row{flex-direction:row}.lg\:gap-4{gap:calc(var(--spacing)*4)}.lg\:gap-6{gap:calc(var(--spacing)*6)}.lg\:gap-8{gap:calc(var(--spacing)*8)}.lg\:overflow-y-auto{overflow-y:auto}.lg\:p-8{padding:calc(var(--spacing)*8)}}@media(min-width:80rem){.xl\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.xl\:grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.xl\:grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}.xl\:grid-cols-5{grid-template-columns:repeat(5,minmax(0,1fr))}.xl\:grid-cols-6{grid-template-columns:repeat(6,minmax(0,1fr))}}@media(min-width:96rem){.\32xl\:grid-cols-6{grid-template-columns:repeat(6,minmax(0,1fr))}}.dark\:border-amber-700:where(.dark,.dark *){border-color:var(--color-amber-700)}.dark\:border-amber-800:where(.dark,.dark *){border-color:var(--color-amber-800)}.dark\:border-bambu-dark-tertiary:where(.dark,.dark *),.dark\:border-bambu-dark-tertiary\/50:where(.dark,.dark *){border-color:var(--color-bambu-dark-tertiary)}@supports (color:color-mix(in lab,red,red)){.dark\:border-bambu-dark-tertiary\/50:where(.dark,.dark *){border-color:color-mix(in oklab,var(--color-bambu-dark-tertiary)50%,transparent)}}.dark\:border-bambu-green\/40:where(.dark,.dark *){border-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.dark\:border-bambu-green\/40:where(.dark,.dark *){border-color:color-mix(in oklab,var(--color-bambu-green)40%,transparent)}}.dark\:border-gray-600:where(.dark,.dark *){border-color:var(--color-gray-600)}.dark\:border-gray-700:where(.dark,.dark *){border-color:var(--color-gray-700)}.dark\:border-red-500\/30:where(.dark,.dark *){border-color:#fb2c364d}@supports (color:color-mix(in lab,red,red)){.dark\:border-red-500\/30:where(.dark,.dark *){border-color:color-mix(in oklab,var(--color-red-500)30%,transparent)}}.dark\:border-red-500\/40:where(.dark,.dark *){border-color:#fb2c3666}@supports (color:color-mix(in lab,red,red)){.dark\:border-red-500\/40:where(.dark,.dark *){border-color:color-mix(in oklab,var(--color-red-500)40%,transparent)}}.dark\:bg-amber-500\/10:where(.dark,.dark *){background-color:#f99c001a}@supports (color:color-mix(in lab,red,red)){.dark\:bg-amber-500\/10:where(.dark,.dark *){background-color:color-mix(in oklab,var(--color-amber-500)10%,transparent)}}.dark\:bg-amber-900\/20:where(.dark,.dark *){background-color:#7b330633}@supports (color:color-mix(in lab,red,red)){.dark\:bg-amber-900\/20:where(.dark,.dark *){background-color:color-mix(in oklab,var(--color-amber-900)20%,transparent)}}.dark\:bg-bambu-dark:where(.dark,.dark *){background-color:var(--color-bambu-dark)}.dark\:bg-bambu-dark-secondary:where(.dark,.dark *){background-color:var(--color-bambu-dark-secondary)}.dark\:bg-bambu-green\/20:where(.dark,.dark *){background-color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.dark\:bg-bambu-green\/20:where(.dark,.dark *){background-color:color-mix(in oklab,var(--color-bambu-green)20%,transparent)}}.dark\:bg-black\/80:where(.dark,.dark *){background-color:#000c}@supports (color:color-mix(in lab,red,red)){.dark\:bg-black\/80:where(.dark,.dark *){background-color:color-mix(in oklab,var(--color-black)80%,transparent)}}.dark\:bg-blue-500\/10:where(.dark,.dark *){background-color:#3080ff1a}@supports (color:color-mix(in lab,red,red)){.dark\:bg-blue-500\/10:where(.dark,.dark *){background-color:color-mix(in oklab,var(--color-blue-500)10%,transparent)}}.dark\:bg-blue-500\/20:where(.dark,.dark *){background-color:#3080ff33}@supports (color:color-mix(in lab,red,red)){.dark\:bg-blue-500\/20:where(.dark,.dark *){background-color:color-mix(in oklab,var(--color-blue-500)20%,transparent)}}.dark\:bg-blue-900\/20:where(.dark,.dark *){background-color:#1c398e33}@supports (color:color-mix(in lab,red,red)){.dark\:bg-blue-900\/20:where(.dark,.dark *){background-color:color-mix(in oklab,var(--color-blue-900)20%,transparent)}}.dark\:bg-gray-700:where(.dark,.dark *){background-color:var(--color-gray-700)}.dark\:bg-gray-800:where(.dark,.dark *){background-color:var(--color-gray-800)}.dark\:bg-gray-900:where(.dark,.dark *){background-color:var(--color-gray-900)}.dark\:bg-red-500\/10:where(.dark,.dark *){background-color:#fb2c361a}@supports (color:color-mix(in lab,red,red)){.dark\:bg-red-500\/10:where(.dark,.dark *){background-color:color-mix(in oklab,var(--color-red-500)10%,transparent)}}.dark\:bg-red-500\/20:where(.dark,.dark *){background-color:#fb2c3633}@supports (color:color-mix(in lab,red,red)){.dark\:bg-red-500\/20:where(.dark,.dark *){background-color:color-mix(in oklab,var(--color-red-500)20%,transparent)}}.dark\:text-amber-200:where(.dark,.dark *){color:var(--color-amber-200)}.dark\:text-amber-300:where(.dark,.dark *){color:var(--color-amber-300)}.dark\:text-amber-400:where(.dark,.dark *){color:var(--color-amber-400)}.dark\:text-bambu-gray:where(.dark,.dark *),.dark\:text-bambu-gray\/30:where(.dark,.dark *){color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.dark\:text-bambu-gray\/30:where(.dark,.dark *){color:color-mix(in oklab,var(--color-bambu-gray)30%,transparent)}}.dark\:text-bambu-gray\/50:where(.dark,.dark *){color:var(--color-bambu-gray)}@supports (color:color-mix(in lab,red,red)){.dark\:text-bambu-gray\/50:where(.dark,.dark *){color:color-mix(in oklab,var(--color-bambu-gray)50%,transparent)}}.dark\:text-bambu-green:where(.dark,.dark *),.dark\:text-bambu-green\/60:where(.dark,.dark *){color:var(--color-bambu-green)}@supports (color:color-mix(in lab,red,red)){.dark\:text-bambu-green\/60:where(.dark,.dark *){color:color-mix(in oklab,var(--color-bambu-green)60%,transparent)}}.dark\:text-blue-200:where(.dark,.dark *){color:var(--color-blue-200)}.dark\:text-blue-200\/80:where(.dark,.dark *){color:#bedbffcc}@supports (color:color-mix(in lab,red,red)){.dark\:text-blue-200\/80:where(.dark,.dark *){color:color-mix(in oklab,var(--color-blue-200)80%,transparent)}}.dark\:text-blue-300:where(.dark,.dark *){color:var(--color-blue-300)}.dark\:text-blue-300\/60:where(.dark,.dark *){color:#90c5ff99}@supports (color:color-mix(in lab,red,red)){.dark\:text-blue-300\/60:where(.dark,.dark *){color:color-mix(in oklab,var(--color-blue-300)60%,transparent)}}.dark\:text-blue-400:where(.dark,.dark *){color:var(--color-blue-400)}.dark\:text-gray-300:where(.dark,.dark *){color:var(--color-gray-300)}.dark\:text-gray-400:where(.dark,.dark *){color:var(--color-gray-400)}.dark\:text-orange-200:where(.dark,.dark *){color:var(--color-orange-200)}.dark\:text-orange-400:where(.dark,.dark *){color:var(--color-orange-400)}.dark\:text-red-400:where(.dark,.dark *){color:var(--color-red-400)}.dark\:text-red-400\/70:where(.dark,.dark *){color:#ff6568b3}@supports (color:color-mix(in lab,red,red)){.dark\:text-red-400\/70:where(.dark,.dark *){color:color-mix(in oklab,var(--color-red-400)70%,transparent)}}.dark\:text-white:where(.dark,.dark *){color:var(--color-white)}.dark\:text-yellow-200:where(.dark,.dark *){color:var(--color-yellow-200)}.dark\:text-yellow-200\/70:where(.dark,.dark *){color:#fff085b3}@supports (color:color-mix(in lab,red,red)){.dark\:text-yellow-200\/70:where(.dark,.dark *){color:color-mix(in oklab,var(--color-yellow-200)70%,transparent)}}@media(hover:hover){.dark\:hover\:border-gray-500:where(.dark,.dark *):hover{border-color:var(--color-gray-500)}.dark\:hover\:bg-bambu-dark-tertiary:where(.dark,.dark *):hover{background-color:var(--color-bambu-dark-tertiary)}.dark\:hover\:bg-bambu-dark\/50:where(.dark,.dark *):hover{background-color:var(--color-bambu-dark)}@supports (color:color-mix(in lab,red,red)){.dark\:hover\:bg-bambu-dark\/50:where(.dark,.dark *):hover{background-color:color-mix(in oklab,var(--color-bambu-dark)50%,transparent)}}.dark\:hover\:bg-gray-600:where(.dark,.dark *):hover{background-color:var(--color-gray-600)}.dark\:hover\:bg-red-500\/30:where(.dark,.dark *):hover{background-color:#fb2c364d}@supports (color:color-mix(in lab,red,red)){.dark\:hover\:bg-red-500\/30:where(.dark,.dark *):hover{background-color:color-mix(in oklab,var(--color-red-500)30%,transparent)}}.dark\:hover\:text-amber-200:where(.dark,.dark *):hover{color:var(--color-amber-200)}.dark\:hover\:text-gray-300:where(.dark,.dark *):hover{color:var(--color-gray-300)}.dark\:hover\:text-white:where(.dark,.dark *):hover{color:var(--color-white)}}.\[\&\:\:-webkit-inner-spin-button\]\:appearance-none::-webkit-inner-spin-button{appearance:none}.\[\&\:\:-webkit-outer-spin-button\]\:appearance-none::-webkit-outer-spin-button{appearance:none}.\[\&\:\:-webkit-slider-thumb\]\:h-3::-webkit-slider-thumb{height:calc(var(--spacing)*3)}.\[\&\:\:-webkit-slider-thumb\]\:w-3::-webkit-slider-thumb{width:calc(var(--spacing)*3)}.\[\&\:\:-webkit-slider-thumb\]\:cursor-pointer::-webkit-slider-thumb{cursor:pointer}.\[\&\:\:-webkit-slider-thumb\]\:appearance-none::-webkit-slider-thumb{appearance:none}.\[\&\:\:-webkit-slider-thumb\]\:rounded-full::-webkit-slider-thumb{border-radius:3.40282e38px}.\[\&\:\:-webkit-slider-thumb\]\:bg-bambu-green::-webkit-slider-thumb{background-color:var(--color-bambu-green)}}:root{--accent:#00ae42;--accent-light:#00c64d;--accent-dark:#009438;--status-ok:#22c55e;--status-error:#ef4444;--status-warning:#f59e0b;--bg-primary:#f5f5f5;--bg-secondary:#fff;--bg-tertiary:#e5e5e5;--text-primary:#1a1a1a;--text-secondary:#4a4a4a;--text-muted:#6b6b6b;--text-tertiary:gray;--border-color:#d4d4d4;--card-shadow:0 2px 8px #00000014;--glow-color:transparent;font-synthesis:none;text-rendering:optimizeLegibility;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-family:Inter,system-ui,sans-serif;font-weight:400;line-height:1.5}.dark{--bg-primary:#1a1a1a;--bg-secondary:#2d2d2d;--bg-tertiary:#3d3d3d;--text-primary:#fff;--text-secondary:#a0a0a0;--text-muted:gray;--text-tertiary:#4a4a4a;--border-color:#3d3d3d;--card-shadow:0 4px 16px #0006}.bg-warm{--bg-primary:#faf8f5;--bg-secondary:#fffefa;--bg-tertiary:#e8e4dd;--text-primary:#2d2a26;--text-secondary:#5c5750;--text-muted:#7a756c;--text-tertiary:#9a9590;--border-color:#d8d4cc}.bg-cool{--bg-primary:#f0f4f8;--bg-secondary:#fff;--bg-tertiary:#dce4ec;--text-primary:#1a2530;--text-secondary:#4a5568;--text-muted:#6b7a8a;--text-tertiary:#8a9aaa;--border-color:#c8d4e0}.dark.bg-neutral{--bg-primary:#1a1a1a;--bg-secondary:#2d2d2d;--bg-tertiary:#3d3d3d;--text-primary:#fff;--text-secondary:#a0a0a0;--text-muted:gray;--text-tertiary:#4a4a4a;--border-color:#3d3d3d}.dark.bg-warm{--bg-primary:#1c1a18;--bg-secondary:#2e2a26;--bg-tertiary:#3e3a36;--text-primary:#f5f0ea;--text-secondary:#b0a898;--text-muted:#8a8278;--text-tertiary:#5a5248;--border-color:#3e3a36}.dark.bg-cool{--bg-primary:#181c20;--bg-secondary:#262c32;--bg-tertiary:#363e46;--text-primary:#f0f4f8;--text-secondary:#98a8b8;--text-muted:#788898;--text-tertiary:#4a5a6a;--border-color:#363e46}.dark.bg-oled{--bg-primary:#000;--bg-secondary:#141414;--bg-tertiary:#1f1f1f;--text-primary:#fff;--text-secondary:#a0a0a0;--text-muted:#707070;--text-tertiary:#404040;--border-color:#2a2a2a}.dark.bg-slate{--bg-primary:#0f172a;--bg-secondary:#1e293b;--bg-tertiary:#334155;--text-primary:#f1f5f9;--text-secondary:#94a3b8;--text-muted:#64748b;--text-tertiary:#475569;--border-color:#334155}.dark.bg-forest{--bg-primary:#121a16;--bg-secondary:#1c2a22;--bg-tertiary:#2a3d30;--text-primary:#e8f5ec;--text-secondary:#8aa894;--text-muted:#6a8874;--text-tertiary:#4a6854;--border-color:#2a3d30}.printer-control-buttons-container{container-type:inline-size}@container (max-width:220px){.printer-control-buttons{flex-direction:column;align-items:stretch}.printer-control-buttons>button{width:100%}}.style-glow{--card-shadow:0 2px 8px #00000014,0 0 25px var(--accent)}@supports (color:color-mix(in lab,red,red)){.style-glow{--card-shadow:0 2px 8px #00000014,0 0 25px color-mix(in srgb,var(--accent)12%,transparent)}}.dark.style-glow{--card-shadow:0 4px 20px #00000080,0 0 40px var(--accent)}@supports (color:color-mix(in lab,red,red)){.dark.style-glow{--card-shadow:0 4px 20px #00000080,0 0 40px color-mix(in srgb,var(--accent)15%,transparent)}}.style-vibrant{--card-shadow:0 8px 30px #00000026,0 2px 8px #0000001a}.dark.style-vibrant{--card-shadow:0 10px 40px #0009,0 4px 12px #0006}.accent-green{--accent:#00ae42;--accent-light:#00c64d;--accent-dark:#009438}.accent-teal{--accent:#14b8a6;--accent-light:#2dd4bf;--accent-dark:#0d9488}.accent-blue{--accent:#3b82f6;--accent-light:#60a5fa;--accent-dark:#2563eb}.accent-orange{--accent:#f97316;--accent-light:#fb923c;--accent-dark:#ea580c}.accent-purple{--accent:#8b5cf6;--accent-light:#a78bfa;--accent-dark:#7c3aed}.accent-red{--accent:#ef4444;--accent-light:#f87171;--accent-dark:#dc2626}body{background-color:var(--bg-primary);color:var(--text-primary);min-height:100vh;margin:0;transition:background-color .2s,color .2s}#root{min-height:100vh}.text-white{color:var(--text-primary)}.bg-bambu-dark,.bg-bambu-dark-secondary,.bg-bambu-dark-tertiary,.border-bambu-dark-tertiary{transition:background-color .2s,border-color .2s}@keyframes slide-in{0%{opacity:0;transform:translate(100%)}to{opacity:1;transform:translate(0)}}.animate-slide-in{animation:.2s ease-out slide-in}.icon-theme{opacity:.5}.dark .icon-theme{filter:invert();opacity:.4}.icon-green{filter:invert(48%)sepia(89%)saturate(459%)hue-rotate(93deg)brightness(95%)contrast(92%);opacity:1}.icon-heating{filter:invert(50%)sepia()saturate(1000%)hue-rotate(360deg)brightness()contrast();opacity:1}.dark .jogpad-theme{filter:brightness(.35)contrast(1.2)}.ams-empty-slot{background:repeating-linear-gradient(45deg,#444,#444 2px,#222 2px 4px)}.dark .ams-empty-slot{background:repeating-linear-gradient(45deg,#555,#555 2px,#333 2px 4px)}.touch-manipulation{touch-action:manipulation}.safe-area-bottom{padding-bottom:env(safe-area-inset-bottom,0)}.safe-area-top{padding-top:env(safe-area-inset-top,0)}.scrollbar-hide{-ms-overflow-style:none;scrollbar-width:none}.scrollbar-hide::-webkit-scrollbar{display:none}@keyframes slide-in-left{0%{transform:translate(-100%)}to{transform:translate(0)}}.animate-slide-in-left{animation:.3s ease-out slide-in-left}.card-shadow{box-shadow:var(--card-shadow)}.calendar-scroll{scrollbar-width:thin;scrollbar-color:var(--text-muted)transparent}@supports (color:color-mix(in lab,red,red)){.calendar-scroll{scrollbar-color:color-mix(in srgb,var(--text-muted)60%,transparent)transparent}}.calendar-scroll::-webkit-scrollbar{width:8px}.calendar-scroll::-webkit-scrollbar-track{background:0 0}.calendar-scroll::-webkit-scrollbar-thumb{background-color:var(--text-muted)}@supports (color:color-mix(in lab,red,red)){.calendar-scroll::-webkit-scrollbar-thumb{background-color:color-mix(in srgb,var(--text-muted)60%,transparent)}}.calendar-scroll::-webkit-scrollbar-thumb{border:2px solid var(--bg-secondary);border-radius:999px}@supports (color:color-mix(in lab,red,red)){.calendar-scroll::-webkit-scrollbar-thumb{border:2px solid color-mix(in srgb,var(--bg-secondary)70%,transparent)}}.calendar-scroll::-webkit-scrollbar-thumb:hover{background-color:var(--text-muted)}@supports (color:color-mix(in lab,red,red)){.calendar-scroll::-webkit-scrollbar-thumb:hover{background-color:color-mix(in srgb,var(--text-muted)80%,transparent)}}@property --tw-translate-x{syntax:"*";inherits:false;initial-value:0}@property --tw-translate-y{syntax:"*";inherits:false;initial-value:0}@property --tw-translate-z{syntax:"*";inherits:false;initial-value:0}@property --tw-scale-x{syntax:"*";inherits:false;initial-value:1}@property --tw-scale-y{syntax:"*";inherits:false;initial-value:1}@property --tw-scale-z{syntax:"*";inherits:false;initial-value:1}@property --tw-rotate-x{syntax:"*";inherits:false}@property --tw-rotate-y{syntax:"*";inherits:false}@property --tw-rotate-z{syntax:"*";inherits:false}@property --tw-skew-x{syntax:"*";inherits:false}@property --tw-skew-y{syntax:"*";inherits:false}@property --tw-space-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-divide-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-gradient-position{syntax:"*";inherits:false}@property --tw-gradient-from{syntax:"";inherits:false;initial-value:#0000}@property --tw-gradient-via{syntax:"";inherits:false;initial-value:#0000}@property --tw-gradient-to{syntax:"";inherits:false;initial-value:#0000}@property --tw-gradient-stops{syntax:"*";inherits:false}@property --tw-gradient-via-stops{syntax:"*";inherits:false}@property --tw-gradient-from-position{syntax:"";inherits:false;initial-value:0%}@property --tw-gradient-via-position{syntax:"";inherits:false;initial-value:50%}@property --tw-gradient-to-position{syntax:"";inherits:false;initial-value:100%}@property --tw-leading{syntax:"*";inherits:false}@property --tw-font-weight{syntax:"*";inherits:false}@property --tw-tracking{syntax:"*";inherits:false}@property --tw-ordinal{syntax:"*";inherits:false}@property --tw-slashed-zero{syntax:"*";inherits:false}@property --tw-numeric-figure{syntax:"*";inherits:false}@property --tw-numeric-spacing{syntax:"*";inherits:false}@property --tw-numeric-fraction{syntax:"*";inherits:false}@property --tw-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:"*";inherits:false}@property --tw-shadow-alpha{syntax:"";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:"*";inherits:false}@property --tw-inset-shadow-alpha{syntax:"";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:"*";inherits:false}@property --tw-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:"*";inherits:false}@property --tw-inset-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:"*";inherits:false}@property --tw-ring-offset-width{syntax:"";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:"*";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-outline-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-blur{syntax:"*";inherits:false}@property --tw-brightness{syntax:"*";inherits:false}@property --tw-contrast{syntax:"*";inherits:false}@property --tw-grayscale{syntax:"*";inherits:false}@property --tw-hue-rotate{syntax:"*";inherits:false}@property --tw-invert{syntax:"*";inherits:false}@property --tw-opacity{syntax:"*";inherits:false}@property --tw-saturate{syntax:"*";inherits:false}@property --tw-sepia{syntax:"*";inherits:false}@property --tw-drop-shadow{syntax:"*";inherits:false}@property --tw-drop-shadow-color{syntax:"*";inherits:false}@property --tw-drop-shadow-alpha{syntax:"";inherits:false;initial-value:100%}@property --tw-drop-shadow-size{syntax:"*";inherits:false}@property --tw-backdrop-blur{syntax:"*";inherits:false}@property --tw-backdrop-brightness{syntax:"*";inherits:false}@property --tw-backdrop-contrast{syntax:"*";inherits:false}@property --tw-backdrop-grayscale{syntax:"*";inherits:false}@property --tw-backdrop-hue-rotate{syntax:"*";inherits:false}@property --tw-backdrop-invert{syntax:"*";inherits:false}@property --tw-backdrop-opacity{syntax:"*";inherits:false}@property --tw-backdrop-saturate{syntax:"*";inherits:false}@property --tw-backdrop-sepia{syntax:"*";inherits:false}@property --tw-duration{syntax:"*";inherits:false}@property --tw-ease{syntax:"*";inherits:false}@property --tw-content{syntax:"*";inherits:false;initial-value:""}@keyframes spin{to{transform:rotate(360deg)}}@keyframes ping{75%,to{opacity:0;transform:scale(2)}}@keyframes pulse{50%{opacity:.5}}@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-translate-x:0;--tw-translate-y:0;--tw-translate-z:0;--tw-scale-x:1;--tw-scale-y:1;--tw-scale-z:1;--tw-rotate-x:initial;--tw-rotate-y:initial;--tw-rotate-z:initial;--tw-skew-x:initial;--tw-skew-y:initial;--tw-space-y-reverse:0;--tw-divide-y-reverse:0;--tw-border-style:solid;--tw-gradient-position:initial;--tw-gradient-from:#0000;--tw-gradient-via:#0000;--tw-gradient-to:#0000;--tw-gradient-stops:initial;--tw-gradient-via-stops:initial;--tw-gradient-from-position:0%;--tw-gradient-via-position:50%;--tw-gradient-to-position:100%;--tw-leading:initial;--tw-font-weight:initial;--tw-tracking:initial;--tw-ordinal:initial;--tw-slashed-zero:initial;--tw-numeric-figure:initial;--tw-numeric-spacing:initial;--tw-numeric-fraction:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-outline-style:solid;--tw-blur:initial;--tw-brightness:initial;--tw-contrast:initial;--tw-grayscale:initial;--tw-hue-rotate:initial;--tw-invert:initial;--tw-opacity:initial;--tw-saturate:initial;--tw-sepia:initial;--tw-drop-shadow:initial;--tw-drop-shadow-color:initial;--tw-drop-shadow-alpha:100%;--tw-drop-shadow-size:initial;--tw-backdrop-blur:initial;--tw-backdrop-brightness:initial;--tw-backdrop-contrast:initial;--tw-backdrop-grayscale:initial;--tw-backdrop-hue-rotate:initial;--tw-backdrop-invert:initial;--tw-backdrop-opacity:initial;--tw-backdrop-saturate:initial;--tw-backdrop-sepia:initial;--tw-duration:initial;--tw-ease:initial;--tw-content:""}}}.hg-theme-default{background-color:#ececec;border-radius:5px;box-sizing:border-box;font-family:HelveticaNeue-Light,Helvetica Neue Light,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;overflow:hidden;padding:5px;touch-action:manipulation;-webkit-user-select:none;-moz-user-select:none;user-select:none;width:100%}.hg-theme-default .hg-button span,.hg-theme-default .hg-button span svg{pointer-events:none}.hg-theme-default button.hg-button{border-width:0;font-size:inherit}.hg-theme-default .hg-button{display:inline-block;flex-grow:1}.hg-theme-default .hg-row{display:flex}.hg-theme-default .hg-row:not(:last-child){margin-bottom:5px}.hg-theme-default .hg-row .hg-button-container,.hg-theme-default .hg-row .hg-button:not(:last-child){margin-right:5px}.hg-theme-default .hg-row>div:last-child{margin-right:0}.hg-theme-default .hg-row .hg-button-container{display:flex}.hg-theme-default .hg-button{align-items:center;background:#fff;border-bottom:1px solid #b5b5b5;border-radius:5px;box-shadow:0 0 3px -1px #0000004d;box-sizing:border-box;cursor:pointer;display:flex;height:40px;justify-content:center;padding:5px;-webkit-tap-highlight-color:rgba(0,0,0,0)}.hg-theme-default .hg-button.hg-standardBtn{width:20px}.hg-theme-default .hg-button.hg-activeButton{background:#efefef}.hg-theme-default.hg-layout-numeric .hg-button{align-items:center;display:flex;height:60px;justify-content:center;width:33.3%}.hg-theme-default .hg-button.hg-button-numpadadd,.hg-theme-default .hg-button.hg-button-numpadenter{height:85px}.hg-theme-default .hg-button.hg-button-numpad0{width:105px}.hg-theme-default .hg-button.hg-button-com{max-width:85px}.hg-theme-default .hg-button.hg-standardBtn.hg-button-at{max-width:45px}.hg-theme-default .hg-button.hg-selectedButton{background:#05194687;color:#fff}.hg-theme-default .hg-button.hg-standardBtn[data-skbtn=".com"]{max-width:82px}.hg-theme-default .hg-button.hg-standardBtn[data-skbtn="@"]{max-width:60px}.hg-candidate-box{background:#ececec;border-bottom:2px solid #b5b5b5;border-radius:5px;display:inline-flex;margin-top:-10px;position:absolute;transform:translateY(-100%);-webkit-user-select:none;-moz-user-select:none;user-select:none}ul.hg-candidate-box-list{display:flex;flex:1;list-style:none;margin:0;padding:0}li.hg-candidate-box-list-item{align-items:center;display:flex;height:40px;justify-content:center;width:40px}li.hg-candidate-box-list-item:hover{background:#00000008;cursor:pointer}li.hg-candidate-box-list-item:active{background:#0000001a}.hg-candidate-box-prev:before{content:"◄"}.hg-candidate-box-next:before{content:"►"}.hg-candidate-box-next,.hg-candidate-box-prev{align-items:center;color:#969696;cursor:pointer;display:flex;padding:0 10px}.hg-candidate-box-next{border-bottom-right-radius:5px;border-top-right-radius:5px}.hg-candidate-box-prev{border-bottom-left-radius:5px;border-top-left-radius:5px}.hg-candidate-box-btn-active{color:#444}.simple-keyboard.vkb-theme{background:#1a1a1a;border-top:1px solid #333;padding:8px 4px;font-family:inherit}.simple-keyboard.vkb-theme .hg-row{display:flex!important;flex-direction:row!important;flex-wrap:nowrap!important;gap:4px;margin-bottom:4px}.simple-keyboard.vkb-theme .hg-row:last-child{margin-bottom:0}.simple-keyboard.vkb-theme .hg-button{display:inline-flex!important;align-items:center;justify-content:center;flex-grow:1;flex-shrink:1;flex-basis:auto;background:#2d2d2d;color:#e0e0e0;border:none;border-radius:6px;height:44px;font-size:16px;font-weight:500;box-shadow:0 1px 2px #0000004d;transition:background .1s;cursor:pointer;padding:0 2px;min-width:0}.simple-keyboard.vkb-theme .hg-button:active{background:#00ae42;color:#fff}.simple-keyboard.vkb-theme .hg-button-bksp,.simple-keyboard.vkb-theme .hg-button-shift,.simple-keyboard.vkb-theme .hg-button-lock{background:#3a3a3a;color:#aaa;flex-grow:1.5}.simple-keyboard.vkb-theme .hg-button-close{background:#3a3a3a;color:#aaa;flex-grow:2;font-weight:600}.simple-keyboard.vkb-theme .hg-button-close:active{background:#555}.simple-keyboard.vkb-theme .hg-button-space{flex-grow:7}.simple-keyboard.vkb-theme .hg-activeButton{background:#00ae42;color:#fff} diff --git a/static/index.html b/static/index.html index 87730af5b..d652bff98 100644 --- a/static/index.html +++ b/static/index.html @@ -23,8 +23,8 @@ - - + +