diff --git a/CHANGELOG.md b/CHANGELOG.md index d47c71ff2..2ad41b7de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ All notable changes to Bambuddy will be documented in this file. - **Generated thumbnails are lit, so one model no longer looks like the next (#2816, requested by @NaegeliJ, contributed by @sadontsev in #2861)** — Both renderers that draw a model themselves — the File Manager's STL/3MF thumbnails and the plate cards — handed matplotlib a mesh with no light source, and without one every triangle is filled with the identical green whichever way it faces. The result was a flat silhouette, so two models of similar outline were the same picture. The mesh is now shaded from a fixed light whose angle is pinned to the camera angle rather than chosen freely: the two are a pair, and a light aimed at the far side of the model gives both visible faces the same brightness and no contrast at all. Lighting then exposed two faults a flat render had hidden. A face wound the wrong way shades as though it faced away, so an STL with inconsistent winding came out patchy like camouflage; winding is now repaired before the render — outward rather than merely consistent, and only for the meshes that need it, since the check is milliseconds where the repair is seconds. And a mesh whose facets are all zero-area or collinear — stub or truncated STLs, 3MFs with an empty triangle list — would have failed outright once lit, so those are detected and still render flat instead of counting as a failure in a folder-wide batch. Both renderers share one copy of the light, the camera and the repair, so a plate card and a library thumbnail of the same model cannot drift apart. Passing the faces as an array rather than a list of lists also cut the collection build on an 82k-face mesh from ~0.19s to ~0.007s, which speeds up the unlit path too. ### Fixed +- **A wood-filled spool was named as plain PLA on the slot it was assigned to** — A spool's subtype is half of what it is called: "PLA" and "PLA Wood" are different filaments, and the AMS slot's hover card built the assigned-spool line out of brand, material and colour name with the subtype left out. A roll of Bambu PLA Wood Classic Birch in an H2C's A4 was therefore announced as "Bambu Lab PLA - Classic Birch". Everything else named it correctly at the same moment — the RFID read, the inventory row, the slot's own profile line, which is built from the spool's slicer preset rather than reassembled, and Bambu Studio — so the one wrong line read like a bad tag read rather than a display fault. It was not only the render: the card's `assignedSpool` prop had no subtype field at all, and the six places the printer card fills it in (regular AMS, AMS-HT and external spool, each in both Spoolman and internal-inventory mode) never passed one, so the value could not reach the component. The field is required now rather than optional, which is what stops the next call site from quietly omitting it — that omission is the whole of this bug. Three more surfaces were rebuilding the name the same way and are fixed with it: the SpoolBuddy AMS slot panel in both inventory modes, and the write-tag confirmation. Every other place a spool is named — the assign dialogs, the inventory cards, the forecast rows, the label picker — already included the subtype, so these four were the outliers. This is the display-side half of #2902, which stopped the backend reducing a filled or foamed filament onto its base material; the card was doing the same thing to the same spools, one layer further out. - **The bundled chamber-preheat table was unreadable to the code that reads it** — every lookup of the per-filament chamber map happens after the keys are upper-cased, but an install that had never opened the setting got the bundled table back exactly as declared, with its lowercase `default` row. The scheduler then looked for `DEFAULT`, found nothing, and used a hardcoded 0 for any filament without a row of its own. It reported the right number only because that bundled default is 0 — raising it would have silently changed nothing for everyone who had not customised the map. Both paths out of the parser now honour the one contract it documents. - **The archives API never reported which plate was printed (#2796, contributed by @sgiffhorn)** — `archive_to_response()` builds the archives response field by field and had no line for `plate_id`, so `GET /archives/`, the detail endpoint, search, PATCH and the project archive list all answered `plate_id: null` — for archives whose column was populated as well. `ArchiveResponse.plate_id` defaults to `None`, so Pydantic filled the null in without complaint and nothing ever raised. The column has been written since #2603 and is backfilled from the queue on startup, so the plate was recorded all along and simply could not be read back out; on the reporting instance 181 of 257 rows carry one. Archive cards now name the plate again — but only when it is not the first one. The queue records a plate for single-plate files too, because the print dialog auto-selects the only plate there is, so labelling every archive that has a `plate_id` would have put "Plate 1" on most cards in the grid and taken room from the truncated print name. A multi-plate archive printed from its first plate still identifies itself through the plate carousel, which has always gated on whether the source 3MF holds more than one plate. - **The first AMS sync after enabling Spoolman from Settings failed on every slot (#2903, diagnosed by @ojimpo)** — Spoolman rejects a spool whose `extra` dict carries a key it has not been told about, answering HTTP 400 `Unknown extra field tag.`. Bambuddy stores the tray UUID in `extra.tag`, so that key has to be registered before the first spool is created — and registration only ever ran from three hand-maintained lists that fire when the integration is *set up*: the Connect button, application startup, and two inline blocks in the inventory routes. Enabling Spoolman from the Settings page reaches none of them, so "Sync AMS Data" reported `Synced 0 spools with 3 errors` with vendor and filament creation succeeding and only spool creation rejected. Restarting Bambuddy cleared it, which made the failure look like a connectivity problem. The Connect button would also have fixed it, but it is not on screen by then: saving the settings initialises the Spoolman client as a side effect of syncing locations, the status endpoint reads any live client as "connected", and the UI shows the Connect button only while disconnected — so the one registration path reachable from the interface hides itself exactly when it is needed. Registration now travels with the write instead of the feature: every spool write that carries an `extra` dict registers the keys it is about to send, once per client, before it sends them. That covers all five places Bambuddy writes a tag — AMS sync, linking and unlinking a tag from a spool, and both inventory edit paths — and it closes the class rather than the instance, since a write that carries a key is now a write that registers it. `bambu_color_name` is the cautionary case: it never made it into the Connect or startup lists at all, and worked only because two call sites remembered to register it by hand. Registration stays best-effort — if it fails, the write is still attempted and reports exactly what it reported before, and the failure is not cached, so a Spoolman that was merely restarting is retried on the next write. diff --git a/frontend/src/__tests__/components/FilamentHoverCard.test.tsx b/frontend/src/__tests__/components/FilamentHoverCard.test.tsx index a63d78927..7877be9fd 100644 --- a/frontend/src/__tests__/components/FilamentHoverCard.test.tsx +++ b/frontend/src/__tests__/components/FilamentHoverCard.test.tsx @@ -205,6 +205,7 @@ describe('FilamentHoverCard', () => { assignedSpool: { id: 1, material: 'PLA', + subtype: null, brand: 'Devil Design', color_name: 'Black', }, @@ -280,6 +281,7 @@ describe('FilamentHoverCard', () => { const inventorySpool = { id: 42, material: 'PLA', + subtype: null, brand: 'eSun', color_name: 'Black', }; @@ -420,7 +422,7 @@ describe('FilamentHoverCard', () => { @@ -607,7 +609,7 @@ describe('FilamentHoverCard colour name (#2875)', () => { data={{ ...whiteMatte, colorName: 'Jade White' }} inventory={{ isAssigned: true, - assignedSpool: { id: 17, material: 'PLA', brand: 'Bambu Lab', color_name: 'Matte Ivory White' }, + assignedSpool: { id: 17, material: 'PLA', subtype: null, brand: 'Bambu Lab', color_name: 'Matte Ivory White' }, }} >
trigger
@@ -626,7 +628,7 @@ describe('FilamentHoverCard colour name (#2875)', () => { data={whiteMatte} inventory={{ isAssigned: true, - assignedSpool: { id: 17, material: 'PLA', brand: 'Bambu Lab', color_name: 'A06-D0' }, + assignedSpool: { id: 17, material: 'PLA', subtype: null, brand: 'Bambu Lab', color_name: 'A06-D0' }, }} >
trigger
@@ -646,7 +648,7 @@ describe('FilamentHoverCard colour name (#2875)', () => { data={whiteMatte} inventory={{ isAssigned: true, - assignedSpool: { id: 17, material: 'PLA', brand: 'Bambu Lab', color_name: colorName }, + assignedSpool: { id: 17, material: 'PLA', subtype: null, brand: 'Bambu Lab', color_name: colorName }, }} >
trigger
@@ -664,7 +666,7 @@ describe('FilamentHoverCard colour name (#2875)', () => { data={whiteMatte} inventory={{ isAssigned: true, - assignedSpool: { id: 17, material: 'PLA', brand: 'Bambu Lab', color_name: null }, + assignedSpool: { id: 17, material: 'PLA', subtype: null, brand: 'Bambu Lab', color_name: null }, }} >
trigger
@@ -674,3 +676,58 @@ describe('FilamentHoverCard colour name (#2875)', () => { await waitFor(() => expect(screen.getByText('Ivory White')).toBeInTheDocument()); }); }); + +// A spool's subtype is part of its name. Dropping it made a wood-filled roll +// read as plain PLA on the slot card, which is the display-side version of +// the mistake #2902 fixed on the backend -- and the printer, the inventory +// page and Studio all named it correctly at the same time, so the card was +// the only thing saying otherwise. +describe('FilamentHoverCard assigned spool name', () => { + beforeEach(() => { + vi.useFakeTimers({ shouldAdvanceTime: true }); + __resetColorCatalogForTests(); + }); + + function showAssigned(assignedSpool: { + id: number; + material: string; + subtype: string | null; + brand: string | null; + color_name: string | null; + }) { + renderWithHover( + +
trigger
+
+ ); + vi.advanceTimersByTime(100); + } + + it('names a filled filament by its subtype, not by its base material', async () => { + showAssigned({ + id: 77, + material: 'PLA', + subtype: 'Wood', + brand: 'Bambu Lab', + color_name: 'Classic Birch', + }); + + await waitFor(() => + expect(screen.getByText('Bambu Lab PLA Wood - Classic Birch')).toBeInTheDocument() + ); + }); + + it('omits the subtype entirely for a spool that has none', async () => { + showAssigned({ + id: 78, + material: 'PLA', + subtype: null, + brand: 'Bambu Lab', + color_name: 'Jade White', + }); + + await waitFor(() => + expect(screen.getByText('Bambu Lab PLA - Jade White')).toBeInTheDocument() + ); + }); +}); diff --git a/frontend/src/components/FilamentHoverCard.tsx b/frontend/src/components/FilamentHoverCard.tsx index 78fea1160..623fa7b4d 100644 --- a/frontend/src/components/FilamentHoverCard.tsx +++ b/frontend/src/components/FilamentHoverCard.tsx @@ -33,7 +33,10 @@ interface SpoolmanConfig { interface InventoryConfig { onAssignSpool?: () => void; onUnassignSpool?: () => void; - assignedSpool?: { id: number; material: string; brand: string | null; color_name: string | null; remainingWeightGrams?: number | null } | null; + // `subtype` is part of the spool's name, not decoration: "PLA" and "PLA Wood" + // are different filaments, and a card that prints only the material tells the + // user their wood-filled roll is plain PLA (the display-side half of #2902). + assignedSpool?: { id: number; material: string; subtype: string | null; brand: string | null; color_name: string | null; remainingWeightGrams?: number | null } | null; isAssigned?: boolean; } @@ -401,6 +404,7 @@ export function FilamentHoverCard({ data, children, disabled, className = '', sp

{inventory.assignedSpool.brand ? `${inventory.assignedSpool.brand} ` : ''} {inventory.assignedSpool.material} + {inventory.assignedSpool.subtype ? ` ${inventory.assignedSpool.subtype}` : ''} {inventory.assignedSpool.color_name ? ` - ${inventory.assignedSpool.color_name}` : ''}

#{inventory.assignedSpool.id} diff --git a/frontend/src/pages/PrintersPage.tsx b/frontend/src/pages/PrintersPage.tsx index a62d6d1b1..036e581f6 100644 --- a/frontend/src/pages/PrintersPage.tsx +++ b/frontend/src/pages/PrintersPage.tsx @@ -5573,6 +5573,7 @@ function PrinterCard({ assignedSpool: spoolmanSpool ? { id: spoolmanSpool.id, material: spoolmanSpool.material, + subtype: spoolmanSpool.subtype, brand: spoolmanSpool.brand ?? null, color_name: spoolmanSpool.color_name ?? null, remainingWeightGrams: spoolmanSpool.label_weight @@ -5600,6 +5601,7 @@ function PrinterCard({ assignedSpool: assignment?.spool ? { id: assignment.spool.id, material: assignment.spool.material, + subtype: assignment.spool.subtype, brand: assignment.spool.brand, color_name: assignment.spool.color_name, remainingWeightGrams: Math.max(0, Math.round(assignment.spool.label_weight - assignment.spool.weight_used)), @@ -5961,6 +5963,7 @@ function PrinterCard({ assignedSpool: spoolmanSpool ? { id: spoolmanSpool.id, material: spoolmanSpool.material, + subtype: spoolmanSpool.subtype, brand: spoolmanSpool.brand ?? null, color_name: spoolmanSpool.color_name ?? null, remainingWeightGrams: spoolmanSpool.label_weight @@ -5988,6 +5991,7 @@ function PrinterCard({ assignedSpool: assignment?.spool ? { id: assignment.spool.id, material: assignment.spool.material, + subtype: assignment.spool.subtype, brand: assignment.spool.brand, color_name: assignment.spool.color_name, remainingWeightGrams: Math.max(0, Math.round(assignment.spool.label_weight - assignment.spool.weight_used)), @@ -6234,6 +6238,7 @@ function PrinterCard({ assignedSpool: spoolmanSpool ? { id: spoolmanSpool.id, material: spoolmanSpool.material, + subtype: spoolmanSpool.subtype, brand: spoolmanSpool.brand ?? null, color_name: spoolmanSpool.color_name ?? null, remainingWeightGrams: spoolmanSpool.label_weight @@ -6261,6 +6266,7 @@ function PrinterCard({ assignedSpool: assignment?.spool ? { id: assignment.spool.id, material: assignment.spool.material, + subtype: assignment.spool.subtype, brand: assignment.spool.brand, color_name: assignment.spool.color_name, remainingWeightGrams: Math.max(0, Math.round(assignment.spool.label_weight - assignment.spool.weight_used)), diff --git a/frontend/src/pages/spoolbuddy/SpoolBuddyAmsPage.tsx b/frontend/src/pages/spoolbuddy/SpoolBuddyAmsPage.tsx index 37be6c565..782da7b33 100644 --- a/frontend/src/pages/spoolbuddy/SpoolBuddyAmsPage.tsx +++ b/frontend/src/pages/spoolbuddy/SpoolBuddyAmsPage.tsx @@ -756,6 +756,7 @@ export function SpoolBuddyAmsPage() { )} {assignment.spool.brand ? `${assignment.spool.brand} ` : ''}{assignment.spool.material} + {assignment.spool.subtype ? ` ${assignment.spool.subtype}` : ''} {assignment.spool.color_name ? ` - ${assignment.spool.color_name}` : ''} #{assignment.spool.id} @@ -789,6 +790,7 @@ export function SpoolBuddyAmsPage() { )} {spoolmanAssignedSpool.brand ? `${spoolmanAssignedSpool.brand} ` : ''}{spoolmanAssignedSpool.material} + {spoolmanAssignedSpool.subtype ? ` ${spoolmanAssignedSpool.subtype}` : ''} {spoolmanAssignedSpool.color_name ? ` - ${spoolmanAssignedSpool.color_name}` : ''} diff --git a/frontend/src/pages/spoolbuddy/SpoolBuddyWriteTagPage.tsx b/frontend/src/pages/spoolbuddy/SpoolBuddyWriteTagPage.tsx index 20caf3e24..07bc85628 100644 --- a/frontend/src/pages/spoolbuddy/SpoolBuddyWriteTagPage.tsx +++ b/frontend/src/pages/spoolbuddy/SpoolBuddyWriteTagPage.tsx @@ -1030,6 +1030,7 @@ function NfcStatusPanel({ writeStatus, writeMessage, selectedSpool, tagOnReader, {selectedSpool && (

{selectedSpool.brand ? `${selectedSpool.brand} ` : ''}{selectedSpool.material} + {selectedSpool.subtype ? ` ${selectedSpool.subtype}` : ''} {selectedSpool.color_name ? ` - ${selectedSpool.color_name}` : ''}

)} diff --git a/static/assets/index-e8_8xCtK.js b/static/assets/index-B6R8pq98.js similarity index 98% rename from static/assets/index-e8_8xCtK.js rename to static/assets/index-B6R8pq98.js index aa9b8827b..6ec753473 100644 --- a/static/assets/index-e8_8xCtK.js +++ b/static/assets/index-B6R8pq98.js @@ -4168,7 +4168,7 @@ void main() { `,children:j}),(0,G.jsx)(`div`,{className:` absolute top-1.5 right-1.5 px-1.5 py-0.5 rounded text-[9px] font-bold uppercase tracking-wider ${e.vendor===`Bambu Lab`?`bg-black/60 text-white`:`bg-black/50 text-white/90`} - `,children:e.vendor===`Bambu Lab`?`BBL`:`GEN`})]}),(0,G.jsxs)(`div`,{className:`p-3 space-y-2.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:c(`ams.profile`)}),(0,G.jsx)(`span`,{className:`text-xs text-white font-semibold truncate max-w-[120px]`,children:e.profile})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:c(`ams.kFactor`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-green font-mono font-bold`,children:e.kFactor})]}),(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium flex items-center gap-1`,children:[(0,G.jsx)(Zs,{className:`w-3 h-3`}),c(`ams.fill`)]}),(0,G.jsxs)(`span`,{className:`text-xs text-white font-semibold flex items-center gap-1`,children:[(0,G.jsx)(`span`,{children:e.fillLevel===null?`—`:`${e.fillLevel}%`}),M!==null&&e.fillLevel!==null&&(0,G.jsxs)(`span`,{className:`text-[9px] text-bambu-gray font-normal`,children:[`• `,M,`g`]})]})]}),(0,G.jsx)(`div`,{className:`h-1.5 bg-black/40 rounded-full overflow-hidden`,children:e.fillLevel===null?(0,G.jsx)(`div`,{className:`h-full w-full bg-bambu-gray/30 rounded-full`}):(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all duration-300`,style:{width:`${e.fillLevel}%`,backgroundColor:k(e.fillLevel)}})})]}),i?.enabled&&(0,G.jsxs)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:c(`spoolman.spoolId`)}),e.trayUuid?(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),w()},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-white transition-colors`,title:`Copy spool UUID`,children:[(0,G.jsxs)(`span`,{className:`font-mono text-[10px] truncate max-w-[80px]`,children:[e.trayUuid.slice(0,8),`...`]}),g?(0,G.jsx)(ds,{className:`w-3 h-3 text-bambu-green`}):(0,G.jsx)(Bs,{className:`w-3 h-3`})]}):(0,G.jsx)(`span`,{className:`text-[10px] text-bambu-gray`,children:`—`})]}),i.linkedSpoolId&&(0,G.jsx)(G.Fragment,{children:(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),O(),l(`/inventory?spool=${i.linkedSpoolId}`)},className:`w-full flex items-center justify-start gap-1.5 px-2 py-1.5 text-xs font-medium rounded transition-colors bg-bambu-green/20 hover:bg-bambu-green/40 text-bambu-green`,title:c(`inventory.openInInventory`),children:[(0,G.jsx)(Sl,{className:`w-3.5 h-3.5`}),c(`inventory.openInInventory`)]})})]}),a&&(0,G.jsx)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary space-y-2`,children:a.assignedSpool?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(Sl,{className:`w-3 h-3 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:c(`inventory.assigned`)})]}),(0,G.jsxs)(`div`,{className:`flex items-baseline gap-1.5 min-w-0 mb-1`,children:[(0,G.jsxs)(`p`,{className:`text-xs text-white truncate`,children:[a.assignedSpool.brand?`${a.assignedSpool.brand} `:``,a.assignedSpool.material,a.assignedSpool.color_name?` - ${a.assignedSpool.color_name}`:``]}),(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-bambu-gray shrink-0`,children:[`#`,a.assignedSpool.id]})]}),(!i?.linkedSpoolId||a.assignedSpool.id!==i.linkedSpoolId)&&(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),O(),l(`/inventory?spool=${a.assignedSpool.id}`)},className:`w-full flex items-center justify-start gap-1.5 px-2 py-1.5 text-xs font-medium rounded transition-colors bg-bambu-green/20 hover:bg-bambu-green/40 text-bambu-green`,title:c(`inventory.openInInventory`),children:[(0,G.jsx)(Sl,{className:`w-3.5 h-3.5`}),c(`inventory.openInInventory`)]}),a.onUnassignSpool&&(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),O(),a.onUnassignSpool?.()},className:`w-full flex items-center justify-start gap-1.5 px-2 py-1.5 text-xs font-medium rounded transition-colors bg-red-100 dark:bg-red-500/20 hover:bg-red-200 dark:hover:bg-red-500/40 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(zu,{className:`w-3.5 h-3.5`}),c(`inventory.unassignSpool`)]})]}):a.onAssignSpool?(0,G.jsxs)(`button`,{onClick:a.isAssigned?void 0:e=>{e.stopPropagation(),O(),a.onAssignSpool?.()},disabled:!!a.isAssigned,className:`w-full flex items-center justify-start gap-1.5 px-2 py-1.5 text-xs font-medium rounded transition-colors bg-bambu-blue/20 text-bambu-blue ${a.isAssigned?`opacity-50 cursor-not-allowed`:`hover:bg-bambu-blue/40`}`,children:[(0,G.jsx)(Sl,{className:`w-3.5 h-3.5`}),c(`inventory.assignSpool`)]}):null}),o?.enabled&&(0,G.jsx)(`div`,{className:`${i?.enabled&&e.trayUuid?``:`pt-2 mt-2 border-t border-bambu-dark-tertiary`}`,children:(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),O(),o.onConfigure?.()},className:`w-full flex items-center justify-start gap-1.5 px-2 py-1.5 text-xs font-medium rounded transition-colors bg-bambu-blue/20 hover:bg-bambu-blue/40 text-bambu-blue`,title:c(`ams.configureSlot`),children:[(0,G.jsx)(tu,{className:`w-3.5 h-3.5`}),c(`ams.configure`)]})}),s&&(0,G.jsx)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary space-y-1`,children:s})]})]}),(0,G.jsx)(`div`,{className:` + `,children:e.vendor===`Bambu Lab`?`BBL`:`GEN`})]}),(0,G.jsxs)(`div`,{className:`p-3 space-y-2.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:c(`ams.profile`)}),(0,G.jsx)(`span`,{className:`text-xs text-white font-semibold truncate max-w-[120px]`,children:e.profile})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:c(`ams.kFactor`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-green font-mono font-bold`,children:e.kFactor})]}),(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium flex items-center gap-1`,children:[(0,G.jsx)(Zs,{className:`w-3 h-3`}),c(`ams.fill`)]}),(0,G.jsxs)(`span`,{className:`text-xs text-white font-semibold flex items-center gap-1`,children:[(0,G.jsx)(`span`,{children:e.fillLevel===null?`—`:`${e.fillLevel}%`}),M!==null&&e.fillLevel!==null&&(0,G.jsxs)(`span`,{className:`text-[9px] text-bambu-gray font-normal`,children:[`• `,M,`g`]})]})]}),(0,G.jsx)(`div`,{className:`h-1.5 bg-black/40 rounded-full overflow-hidden`,children:e.fillLevel===null?(0,G.jsx)(`div`,{className:`h-full w-full bg-bambu-gray/30 rounded-full`}):(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all duration-300`,style:{width:`${e.fillLevel}%`,backgroundColor:k(e.fillLevel)}})})]}),i?.enabled&&(0,G.jsxs)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:c(`spoolman.spoolId`)}),e.trayUuid?(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),w()},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-white transition-colors`,title:`Copy spool UUID`,children:[(0,G.jsxs)(`span`,{className:`font-mono text-[10px] truncate max-w-[80px]`,children:[e.trayUuid.slice(0,8),`...`]}),g?(0,G.jsx)(ds,{className:`w-3 h-3 text-bambu-green`}):(0,G.jsx)(Bs,{className:`w-3 h-3`})]}):(0,G.jsx)(`span`,{className:`text-[10px] text-bambu-gray`,children:`—`})]}),i.linkedSpoolId&&(0,G.jsx)(G.Fragment,{children:(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),O(),l(`/inventory?spool=${i.linkedSpoolId}`)},className:`w-full flex items-center justify-start gap-1.5 px-2 py-1.5 text-xs font-medium rounded transition-colors bg-bambu-green/20 hover:bg-bambu-green/40 text-bambu-green`,title:c(`inventory.openInInventory`),children:[(0,G.jsx)(Sl,{className:`w-3.5 h-3.5`}),c(`inventory.openInInventory`)]})})]}),a&&(0,G.jsx)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary space-y-2`,children:a.assignedSpool?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(Sl,{className:`w-3 h-3 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:c(`inventory.assigned`)})]}),(0,G.jsxs)(`div`,{className:`flex items-baseline gap-1.5 min-w-0 mb-1`,children:[(0,G.jsxs)(`p`,{className:`text-xs text-white truncate`,children:[a.assignedSpool.brand?`${a.assignedSpool.brand} `:``,a.assignedSpool.material,a.assignedSpool.subtype?` ${a.assignedSpool.subtype}`:``,a.assignedSpool.color_name?` - ${a.assignedSpool.color_name}`:``]}),(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-bambu-gray shrink-0`,children:[`#`,a.assignedSpool.id]})]}),(!i?.linkedSpoolId||a.assignedSpool.id!==i.linkedSpoolId)&&(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),O(),l(`/inventory?spool=${a.assignedSpool.id}`)},className:`w-full flex items-center justify-start gap-1.5 px-2 py-1.5 text-xs font-medium rounded transition-colors bg-bambu-green/20 hover:bg-bambu-green/40 text-bambu-green`,title:c(`inventory.openInInventory`),children:[(0,G.jsx)(Sl,{className:`w-3.5 h-3.5`}),c(`inventory.openInInventory`)]}),a.onUnassignSpool&&(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),O(),a.onUnassignSpool?.()},className:`w-full flex items-center justify-start gap-1.5 px-2 py-1.5 text-xs font-medium rounded transition-colors bg-red-100 dark:bg-red-500/20 hover:bg-red-200 dark:hover:bg-red-500/40 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(zu,{className:`w-3.5 h-3.5`}),c(`inventory.unassignSpool`)]})]}):a.onAssignSpool?(0,G.jsxs)(`button`,{onClick:a.isAssigned?void 0:e=>{e.stopPropagation(),O(),a.onAssignSpool?.()},disabled:!!a.isAssigned,className:`w-full flex items-center justify-start gap-1.5 px-2 py-1.5 text-xs font-medium rounded transition-colors bg-bambu-blue/20 text-bambu-blue ${a.isAssigned?`opacity-50 cursor-not-allowed`:`hover:bg-bambu-blue/40`}`,children:[(0,G.jsx)(Sl,{className:`w-3.5 h-3.5`}),c(`inventory.assignSpool`)]}):null}),o?.enabled&&(0,G.jsx)(`div`,{className:`${i?.enabled&&e.trayUuid?``:`pt-2 mt-2 border-t border-bambu-dark-tertiary`}`,children:(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),O(),o.onConfigure?.()},className:`w-full flex items-center justify-start gap-1.5 px-2 py-1.5 text-xs font-medium rounded transition-colors bg-bambu-blue/20 hover:bg-bambu-blue/40 text-bambu-blue`,title:c(`ams.configureSlot`),children:[(0,G.jsx)(tu,{className:`w-3.5 h-3.5`}),c(`ams.configure`)]})}),s&&(0,G.jsx)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary space-y-1`,children:s})]})]}),(0,G.jsx)(`div`,{className:` absolute left-1/2 -translate-x-1/2 w-0 h-0 border-l-[6px] border-l-transparent border-r-[6px] border-r-transparent @@ -4210,7 +4210,7 @@ void main() { `,title:z(`printers:control`)?F(n?`printers.resume`:`printers.pause`):F(`printers.permission.noControl`),children:[n?(0,G.jsx)(Ml,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}):(0,G.jsx)(El,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),F(n?`printers.resume`:`printers.pause`)]})})(),(()=>{let e=!r||i||!z(`printers:control`);return(0,G.jsxs)(`button`,{onClick:()=>Te(!0),disabled:e,className:` ${s} ${e?a:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 hover:bg-red-500/30`} - `,title:z(`printers:control`)?F(`printers.stop`):F(`printers.permission.noControl`),children:[(0,G.jsx)(yu,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),F(`printers.stop`)]})})()]})]})]})})(),(En?.length>0||W.vt_tray.length>0)&&r===`expanded`&&(()=>{let t=En.filter(e=>e.tray.length>1),n=En.filter(e=>e.tray.length===1),r=En.length>0&&W.vt_tray.length>0,g=!(r&&xe),_=e.nozzle_count===2||W?.temperatures?.nozzle_2!==void 0,v=AW[i]??1,y=e=>`${Math.round(e*v*1e3)/1e3}rem`,b=`3.5rem`,x={minWidth:b},S={minWidth:b,maxWidth:y(7.25)},C=e=>({gridTemplateColumns:`repeat(${e}, minmax(${b}, 1fr))`}),w=(W.state===`RUNNING`||W.state===`PAUSE`)&&Array.isArray(W.ams_mapping)?W.ams_mapping:[],T=e=>{let t=Math.max(1,e),n=`calc(${t} * ${b} + ${Math.max(0,t-1)} * 0.25rem + 1rem)`;return{flex:`1 1 ${n}`,minWidth:n}};return(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] uppercase tracking-wider text-bambu-gray font-medium`,children:F(`printers.filaments`)}),(0,G.jsx)(lke,{state:W.ams_filament_backup,onClick:()=>be(!0)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`}),r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(uke,{hidden:xe,onClick:Ce}),(0,G.jsx)(`div`,{className:`w-3 h-[2px] bg-bambu-dark-tertiary`})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[t.map(t=>{let n=pW(t.id,xn,wn,Cn);return(0,G.jsxs)(`div`,{style:T(4),className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex w-full min-h-7 items-center justify-between gap-2 rounded-lg bg-bambu-dark-secondary px-2 py-1`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,G.jsx)(OW,{ams:t,printerId:e.id,label:fp(t.id,t.tray.length),amsLabels:pn,canEdit:z(`printers:update`),onSaved:mn,children:(0,G.jsx)(`span`,{className:`block truncate text-[length:var(--pc-t10,10px)] text-white font-medium cursor-default select-none`,children:pn?.[t.id]||fp(t.id,t.tray.length)})}),n?.kind===`inlet`?(0,G.jsx)(fW,{inlet:n.inlet,title:F(`printers.amsSwitchInletTooltip`,{inlet:n.inlet,side:lp[n.inlet]})}):_&&n?.kind===`nozzle`?(0,G.jsx)(dW,{side:n.side}):null]}),(t.humidity!=null||t.temp!=null)&&(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[t.humidity!=null&&(0,G.jsx)(vW,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>Nt({amsId:t.id,amsLabel:fp(t.id,t.tray.length),mode:`humidity`}),compact:!0}),t.temp!=null&&(0,G.jsx)(`div`,{className:`mr-1`,children:(0,G.jsx)(yW,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>Nt({amsId:t.id,amsLabel:fp(t.id,t.tray.length),mode:`temperature`}),compact:!0})}),(W.supports_drying||W.drying_screen_only)&&(t.module_type===`n3f`||t.module_type===`n3s`)&&z(`printers:control`)&&(0,G.jsx)(`button`,{disabled:W.drying_screen_only||!!(t.dry_sf_reason?.length&&t.dry_time===0),onClick:e=>{t.dry_time>0?sr.mutate(t.id):Ze===t.id?Qe(null):yt(t,e.currentTarget)},className:`ml-1 flex items-center gap-0.5 px-1 py-0.5 rounded text-[length:var(--pc-t9,9px)] transition-colors ${t.dry_time>0?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:W.drying_screen_only||t.dry_sf_reason?.length?`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark/80`}`,title:W.drying_screen_only?F(`printers.drying.screenOnly`):t.dry_time>0?F(`printers.drying.stop`):t.dry_sf_reason?.length?F(QOe(t.dry_sf_reason)):F(`printers.drying.start`),children:(0,G.jsx)(mc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]})]}),t.dry_time>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-amber-50 dark:bg-amber-500/10 px-2 py-1 text-[length:var(--pc-t9,9px)]`,children:[(0,G.jsx)(mc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-amber-600 dark:text-amber-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400 font-medium`,children:F(`printers.drying.active`)}),t.dry_filament&&(0,G.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70`,children:t.dry_target_temp==null?t.dry_filament:F(`printers.drying.targetSummary`,{filament:t.dry_filament,temp:t.dry_target_temp})}),(0,G.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70`,children:F(`printers.drying.timeRemaining`,{time:t.dry_time>=60?`${Math.floor(t.dry_time/60)}h ${t.dry_time%60}m`:`${t.dry_time}m`})}),!W.drying_screen_only&&(0,G.jsx)(`button`,{onClick:()=>sr.mutate(t.id),disabled:sr.isPending,className:`ml-auto text-amber-700 dark:text-amber-400 hover:text-amber-900 dark:hover:text-amber-300 transition-colors disabled:opacity-50`,title:F(`printers.drying.stop`),children:(0,G.jsx)(td,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]}),(0,G.jsx)(`div`,{className:`grid w-full gap-1`,style:C(4),children:[0,1,2,3].map(n=>{let r=t.tray[n]||t.tray.find(e=>e.id===n),i=r?.tray_type&&r.remain>=0,a=!r?.tray_type,g=bW(r),_=t.id*4+n,v=An===_,y=jn!==null&&jn===_,b=Mn!==null&&Mn===_,S=r?.tray_info_idx?cn?.[r.tray_info_idx]:null,C=ln?.[_],T=(r?.tray_uuid||r?.tag_uid||Ap(e.serial_number,t.id,n))?.toUpperCase(),E=T?s?.[T]:void 0,D=Dp(E),O=o&&!m?p?.find(r=>r.printer_id===e.id&&r.ams_id===t.id&&r.tray_id===n):void 0,k=O?f?.find(e=>e.id===O.spoolman_spool_id):void 0,A=k&&(k.label_weight??0)>0?Math.round(Math.max(0,(k.label_weight??0)-k.weight_used)/(k.label_weight??1)*100):null,j=u?.(e.id,t.id,n),M=(()=>{let e=j?.spool;return e&&e.label_weight>0&&e.weight_used!=null?Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100):null})(),N=M===0&&i&&r.remain>0?null:M,P=D??A??N??(i?r.remain:null),I=D!==null||A!==null?`spoolman`:N===null?i?`ams`:void 0:`inventory`,L=r?.tray_type?{vendor:Bp(r)?`Bambu Lab`:`Generic`,profile:C?.preset_name||(k?[k.brand,k.slicer_filament_name?.split(`@`)[0].trim()||k.material].filter(Boolean).join(` `).trim():null)||j?.spool?.slicer_filament_name||S?.name||r.tray_sub_brands||r.tray_type,colorName:Sf(r.tray_color||``,r.tray_sub_brands),colorHex:r.tray_color||null,kFactor:lW(r.k),fillLevel:P,trayUuid:r.tray_uuid||null,tagUid:r.tag_uid||null,fillSource:I}:null,R=Ir?.amsId===t.id&&Ir?.slotId===n,B=w.indexOf(_),V=B>=0?`P${B+1}`:null,ee=(0,G.jsxs)(`div`,{className:`relative w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${a?`opacity-50`:``} ${y?`ring-2 ring-amber-400 ring-offset-1 ring-offset-bambu-dark animate-pulse`:b?`ring-2 ring-red-500/60 ring-offset-1 ring-offset-bambu-dark`:v?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[y&&(0,G.jsx)(`span`,{"aria-label":F(`printers.expectedSlot.ariaLabel`,{n:n+1}),title:F(`printers.expectedSlot.title`),className:`absolute top-0.5 left-0.5 px-1 py-px text-[length:var(--pc-t8,8px)] font-bold text-bambu-dark bg-amber-400 rounded pointer-events-none leading-none`,children:`↓`}),V&&(0,G.jsx)(`span`,{"aria-label":F(`printers.activeJobSlot.ariaLabel`,{n:B+1}),title:F(`printers.activeJobSlot.title`,{n:B+1}),className:`absolute top-0.5 right-0.5 px-1 py-px text-[length:var(--pc-t8,8px)] font-bold text-bambu-dark bg-bambu-green rounded pointer-events-none leading-none`,children:V}),(0,G.jsx)(oW,{trayColor:r?.tray_color,trayType:r?.tray_type,isEmpty:a,emptyKind:g,slotNumber:n+1}),(0,G.jsx)(`div`,{className:`text-[length:var(--pc-t9,9px)] text-white font-bold truncate`,children:r?.tray_type||F(g===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,G.jsx)(uW,{k:L?r?.k:null,reserve:Dn}),(0,G.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:P!==null&&P>=0&&!a&&r&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${P}%`,backgroundColor:Ep(P)}})})]});return(0,G.jsxs)(`div`,{className:`relative group w-full`,style:x,children:[R&&(0,G.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-tertiary/80 rounded flex items-center justify-center z-20`,children:(0,G.jsx)(Vl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] text-bambu-green animate-spin`})}),L?(0,G.jsx)(GH,{data:L,actions:_i({amsId:t.id,slotId:n,loadTrayId:t.id*4+n,isRefreshing:R}),spoolman:{enabled:o,linkedSpoolId:O?.spoolman_spool_id??(T?s?.[T]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!O&&!j?()=>{let r=(L.trayUuid||L.tagUid||Ap(e.serial_number,t.id,n)).toUpperCase();Lt({tagUid:L.tagUid||r,trayUuid:L.trayUuid||``,printerId:e.id,amsId:t.id,trayId:n})}:void 0,onUnlinkSpool:E?.id?()=>rr.mutate(E.id):void 0},inventory:(()=>{if(o){if(m)return;let i=O,a=k;return{assignedSpool:a?{id:a.id,material:a.material,brand:a.brand??null,color_name:a.color_name??null,remainingWeightGrams:a.label_weight?Math.max(0,Math.round(a.label_weight-a.weight_used)):void 0}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:n,trayInfo:{type:r?.tray_type||L.profile,material:r?.tray_type??void 0,profile:L.profile,color:L.colorHex||``,location:`${fp(t.id,t.tray.length)} Slot ${n+1}`}}),onUnassignSpool:a&&!Bp(r)?()=>h?.(a.id):void 0,isAssigned:!!i||Bp(r)}}let i=u?.(e.id,t.id,n);return{assignedSpool:i?.spool?{id:i.spool.id,material:i.spool.material,brand:i.spool.brand,color_name:i.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(i.spool.label_weight-i.spool.weight_used))}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:n,trayInfo:{type:r?.tray_type||L.profile,material:r?.tray_type??void 0,profile:L.profile,color:L.colorHex||``,location:`${fp(t.id,t.tray.length)} Slot ${n+1}`}}),onUnassignSpool:i&&!Bp(r)?()=>d?.(e.id,t.id,n):void 0,isAssigned:!!i||Bp(r)}})(),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:t.id,trayId:n,trayCount:t.tray.length,trayType:r?.tray_type||void 0,trayColor:r?.tray_color||void 0,traySubBrands:r?.tray_sub_brands||void 0,trayInfoIdx:r?.tray_info_idx||void 0,extruderId:dp(t.id,r?.id??0,xn,wn),caliIdx:r?.cali_idx,savedPresetId:C?.preset_id})},children:ee}):(0,G.jsx)(KH,{kind:g??void 0,actions:_i({amsId:t.id,slotId:n,loadTrayId:t.id*4+n,isRefreshing:R}),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:t.id,trayId:n,trayCount:t.tray.length,extruderId:dp(t.id,r?.id??0,xn,wn)})},onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:n,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`${fp(t.id,t.tray.length)} Slot ${n+1}`}}),children:ee})]},n)})})]},t.id)}),n.map(t=>{let n=pW(t.id,xn,wn,Cn),r=t.tray[0],i=r?.tray_type&&r.remain>=0,g=!r?.tray_type,v=bW(r),x=Tp(t.id,r?.id??0,!1),C=An===x,T=jn!==null&&jn===x,E=Mn!==null&&Mn===x,D=r?.tray_info_idx?cn?.[r.tray_info_idx]:null,O=ln?.[x],k=r?.id??0,A=(r?.tray_uuid||r?.tag_uid||Ap(e.serial_number,t.id,k))?.toUpperCase(),j=A?s?.[A]:void 0,M=Dp(j),N=u?.(e.id,t.id,k),P=(()=>{let e=N?.spool;return e&&e.label_weight>0&&e.weight_used!=null?Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100):null})(),I=P===0&&i&&r.remain>0?null:P,L=o&&!m?p?.find(n=>n.printer_id===e.id&&n.ams_id===t.id&&n.tray_id===k):void 0,R=L?f?.find(e=>e.id===L.spoolman_spool_id):void 0,B=R&&(R.label_weight??0)>0?Math.round(Math.max(0,(R.label_weight??0)-R.weight_used)/(R.label_weight??1)*100):null,V=M??B??I??(i?r.remain:null),ee=M!==null||B!==null?`spoolman`:I===null?i?`ams`:void 0:`inventory`,te=r?.tray_type?{vendor:Bp(r)?`Bambu Lab`:`Generic`,profile:O?.preset_name||(R?[R.brand,R.slicer_filament_name?.split(`@`)[0].trim()||R.material].filter(Boolean).join(` `).trim():null)||N?.spool?.slicer_filament_name||D?.name||r.tray_sub_brands||r.tray_type,colorName:Sf(r.tray_color||``,r.tray_sub_brands),colorHex:r.tray_color||null,kFactor:lW(r.k),fillLevel:V,trayUuid:r.tray_uuid||null,tagUid:r.tag_uid||null,fillSource:ee}:null,ne=Ir?.amsId===t.id&&Ir?.slotId===k,re=w.indexOf(x),ie=re>=0?`P${re+1}`:null,ae=(0,G.jsxs)(`div`,{className:`relative w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${g?`opacity-50`:``} ${T?`ring-2 ring-amber-400 ring-offset-1 ring-offset-bambu-dark animate-pulse`:E?`ring-2 ring-red-500/60 ring-offset-1 ring-offset-bambu-dark`:C?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[T&&(0,G.jsx)(`span`,{"aria-label":F(`printers.expectedSlot.ariaLabel`,{n:1}),title:F(`printers.expectedSlot.title`),className:`absolute top-0.5 left-0.5 px-1 py-px text-[length:var(--pc-t8,8px)] font-bold text-bambu-dark bg-amber-400 rounded pointer-events-none leading-none`,children:`↓`}),ie&&(0,G.jsx)(`span`,{"aria-label":F(`printers.activeJobSlot.ariaLabel`,{n:re+1}),title:F(`printers.activeJobSlot.title`,{n:re+1}),className:`absolute top-0.5 right-0.5 px-1 py-px text-[length:var(--pc-t8,8px)] font-bold text-bambu-dark bg-bambu-green rounded pointer-events-none leading-none`,children:ie}),(0,G.jsx)(oW,{trayColor:r?.tray_color,trayType:r?.tray_type,isEmpty:g,emptyKind:v,slotNumber:1}),(0,G.jsx)(`div`,{className:`text-[length:var(--pc-t9,9px)] text-white font-bold truncate`,children:r?.tray_type||F(v===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,G.jsx)(uW,{k:te?r?.k:null,reserve:Dn}),(0,G.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:V!==null&&V>=0&&!g&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${V}%`,backgroundColor:Ep(V)}})})]}),oe=y(11);return(0,G.jsxs)(`div`,{style:{flex:`1 1 ${oe}`,minWidth:oe,maxWidth:`calc(4 * ${b} + 3 * 0.25rem + 1rem)`},className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex w-full min-h-7 items-center gap-1.5 rounded-lg bg-bambu-dark-secondary px-2 py-1`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,G.jsx)(OW,{ams:t,printerId:e.id,label:fp(t.id,t.tray.length),amsLabels:pn,canEdit:z(`printers:update`),onSaved:mn,children:(0,G.jsx)(`span`,{className:`block truncate text-[length:var(--pc-t10,10px)] text-white font-medium cursor-default select-none`,children:pn?.[t.id]||fp(t.id,t.tray.length)})}),n?.kind===`inlet`?(0,G.jsx)(fW,{inlet:n.inlet,title:F(`printers.amsSwitchInletTooltip`,{inlet:n.inlet,side:lp[n.inlet]})}):_&&n?.kind===`nozzle`?(0,G.jsx)(dW,{side:n.side}):null]}),(W.supports_drying||W.drying_screen_only)&&(t.module_type===`n3f`||t.module_type===`n3s`)&&z(`printers:control`)&&(0,G.jsx)(`div`,{className:`relative ml-auto`,children:(0,G.jsx)(`button`,{disabled:W.drying_screen_only,onClick:e=>{t.dry_time>0?sr.mutate(t.id):Ze===t.id?Qe(null):yt(t,e.currentTarget)},className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[length:var(--pc-t9,9px)] transition-colors ${t.dry_time>0?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:W.drying_screen_only?`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark/80`}`,title:W.drying_screen_only?F(`printers.drying.screenOnly`):t.dry_time>0?F(`printers.drying.stop`):F(`printers.drying.start`),children:(0,G.jsx)(mc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})})]}),t.dry_time>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 overflow-hidden whitespace-nowrap rounded-lg bg-amber-50 dark:bg-amber-500/10 px-2 py-1 text-[length:var(--pc-t9,9px)]`,children:[(0,G.jsx)(mc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-amber-600 dark:text-amber-400 shrink-0`}),t.dry_filament&&(0,G.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70 text-[length:var(--pc-t8,8px)] truncate`,children:t.dry_target_temp==null?t.dry_filament:F(`printers.drying.targetSummary`,{filament:t.dry_filament,temp:t.dry_target_temp})}),(0,G.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70 text-[length:var(--pc-t8,8px)] truncate`,children:t.dry_time>=60?`${Math.floor(t.dry_time/60)}h ${t.dry_time%60}m`:`${t.dry_time}m`}),!W.drying_screen_only&&(0,G.jsx)(`button`,{onClick:()=>sr.mutate(t.id),disabled:sr.isPending,className:`ml-auto text-amber-700 dark:text-amber-400 hover:text-amber-900 dark:hover:text-amber-300 transition-colors disabled:opacity-50 shrink-0`,title:F(`printers.drying.stop`),children:(0,G.jsx)(td,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-1.5 max-[550px]:flex-col max-[550px]:items-start`,children:[(0,G.jsxs)(`div`,{className:`relative group flex-1`,style:S,children:[ne&&(0,G.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-tertiary/80 rounded flex items-center justify-center z-20`,children:(0,G.jsx)(Vl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] text-bambu-green animate-spin`})}),te?(0,G.jsx)(GH,{data:te,actions:_i({amsId:t.id,slotId:k,loadTrayId:t.id*4+k,isRefreshing:ne}),spoolman:{enabled:o,linkedSpoolId:L?.spoolman_spool_id??(A?s?.[A]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!L&&!N?()=>{let n=(te.trayUuid||te.tagUid||Ap(e.serial_number,t.id,k)).toUpperCase();Lt({tagUid:te.tagUid||n,trayUuid:te.trayUuid||``,printerId:e.id,amsId:t.id,trayId:k})}:void 0,onUnlinkSpool:j?.id?()=>rr.mutate(j.id):void 0},inventory:(()=>{if(o){if(m)return;let n=L,i=R;return{assignedSpool:i?{id:i.id,material:i.material,brand:i.brand??null,color_name:i.color_name??null,remainingWeightGrams:i.label_weight?Math.max(0,Math.round(i.label_weight-i.weight_used)):void 0}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:k,trayInfo:{type:r?.tray_type||te.profile,material:r?.tray_type??void 0,profile:te.profile,color:te.colorHex||``,location:fp(t.id,t.tray.length)}}),onUnassignSpool:i&&!Bp(r)?()=>h?.(i.id):void 0,isAssigned:!!n||Bp(r)}}let n=u?.(e.id,t.id,k);return{assignedSpool:n?.spool?{id:n.spool.id,material:n.spool.material,brand:n.spool.brand,color_name:n.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(n.spool.label_weight-n.spool.weight_used))}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:k,trayInfo:{type:r?.tray_type||te.profile,material:r?.tray_type??void 0,profile:te.profile,color:te.colorHex||``,location:fp(t.id,t.tray.length)}}),onUnassignSpool:n&&!Bp(r)?()=>d?.(e.id,t.id,k):void 0,isAssigned:!!n||Bp(r)}})(),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:t.id,trayId:k,trayCount:t.tray.length,trayType:r?.tray_type||void 0,trayColor:r?.tray_color||void 0,traySubBrands:r?.tray_sub_brands||void 0,trayInfoIdx:r?.tray_info_idx||void 0,extruderId:dp(t.id,r?.id??0,xn,wn),caliIdx:r?.cali_idx,savedPresetId:O?.preset_id})},children:ae}):(0,G.jsx)(KH,{kind:v??void 0,actions:_i({amsId:t.id,slotId:k,loadTrayId:t.id*4+k,isRefreshing:ne}),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:t.id,trayId:k,trayCount:t.tray.length,extruderId:dp(t.id,r?.id??0,xn,wn)})},onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:k,trayInfo:{type:``,material:void 0,profile:``,color:``,location:fp(t.id,t.tray.length)}}),children:ae})]}),(t.humidity!=null||t.temp!=null)&&(0,G.jsxs)(`div`,{className:`flex flex-col justify-center gap-1 shrink-0 max-[550px]:w-full`,children:[t.temp!=null&&(0,G.jsx)(yW,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>Nt({amsId:t.id,amsLabel:fp(t.id,t.tray.length),mode:`temperature`}),compact:!0}),t.humidity!=null&&(0,G.jsx)(vW,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>Nt({amsId:t.id,amsLabel:fp(t.id,t.tray.length),mode:`humidity`}),compact:!0})]})]})]},t.id)}),W.vt_tray.length>0&&g&&(0,G.jsxs)(`div`,{style:T(W.vt_tray.length),className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,G.jsx)(`div`,{className:`flex w-full min-h-7 items-center gap-1.5 rounded-lg bg-bambu-dark-secondary px-2 py-1`,children:(0,G.jsx)(`span`,{className:`block min-w-0 flex-1 truncate text-[length:var(--pc-t10,10px)] text-white font-medium`,children:F(`printers.external`)})}),(0,G.jsx)(`div`,{className:`grid w-full gap-1`,style:C(W.vt_tray.length>1?2:1),children:[...W.vt_tray].sort((e,t)=>(e.id??254)-(t.id??254)).map(t=>{let n=t.id??254,r=_&&An===254?n===254&&W.active_extruder===1||n===255&&W.active_extruder===0:An===n,i=n-254,a=_?F(n===254?`printers.extL`:`printers.extR`):``,g=t.tray_info_idx?cn?.[t.tray_info_idx]:null,v=ln?.[1020+i],y=(t.tray_uuid||t.tag_uid||Ap(e.serial_number,255,i))?.toUpperCase(),b=y?s?.[y]:void 0,S=Dp(b),C=u?.(e.id,255,i),w=(()=>{let e=C?.spool;return e&&e.label_weight>0&&e.weight_used!=null?Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100):null})(),T=t.tray_type&&t.remain>=0,E=w===0&&T&&t.remain>0?null:w,D=o&&!m?p?.find(t=>t.printer_id===e.id&&t.ams_id===255&&t.tray_id===i):void 0,O=D?f?.find(e=>e.id===D.spoolman_spool_id):void 0,k=O&&(O.label_weight??0)>0?Math.round(Math.max(0,(O.label_weight??0)-O.weight_used)/(O.label_weight??1)*100):null,A=S??k??E??(T?t.remain:null),j=S!==null||k!==null?`spoolman`:E===null?T?`ams`:void 0:`inventory`,M={vendor:Bp(t)?`Bambu Lab`:`Generic`,profile:v?.preset_name||(O?[O.brand,O.slicer_filament_name?.split(`@`)[0].trim()||O.material].filter(Boolean).join(` `).trim():null)||C?.spool?.slicer_filament_name||g?.name||t.tray_sub_brands||t.tray_type||`Unknown`,colorName:Sf(t.tray_color||``,t.tray_sub_brands),colorHex:t.tray_color||null,kFactor:lW(t.k),fillLevel:A,trayUuid:t.tray_uuid||null,tagUid:t.tag_uid||null,fillSource:j},N=!t.tray_type,P=bW(t),I=(0,G.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${N?`opacity-50`:``} ${r?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[(0,G.jsx)(oW,{trayColor:t.tray_color,trayType:t.tray_type,isEmpty:N,emptyKind:P,slotNumber:_?n===254?`L`:`R`:i+1}),(0,G.jsx)(`div`,{className:`text-[length:var(--pc-t9,9px)] font-bold truncate ${N?`text-white/40`:`text-white`}`,children:t.tray_type||F(`ams.slotEmpty`)}),(0,G.jsx)(uW,{k:N?null:t.k,reserve:Dn}),(0,G.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:A!==null&&A>=0&&!N&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${A}%`,backgroundColor:Ep(A)}})})]});return(0,G.jsx)(`div`,{className:`relative group w-full`,style:x,children:N?(0,G.jsx)(KH,{kind:P??void 0,actions:_i({amsId:255,slotId:i,loadTrayId:n,includeRfid:!1}),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:255,trayId:i,trayCount:1,extruderId:_?+(n===254):void 0})},onAssignSpool:()=>zt({printerId:e.id,amsId:255,trayId:i,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`External Slot ${i+1}`}}),children:I}):(0,G.jsx)(GH,{data:M,actions:_i({amsId:255,slotId:i,loadTrayId:n,includeRfid:!1}),spoolman:{enabled:o,linkedSpoolId:D?.spoolman_spool_id??(y?s?.[y]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!D&&!C?()=>{let t=(M.trayUuid||M.tagUid||Ap(e.serial_number,255,i)).toUpperCase();Lt({tagUid:M.tagUid||t,trayUuid:M.trayUuid||``,printerId:e.id,amsId:255,trayId:i})}:void 0,onUnlinkSpool:b?.id?()=>rr.mutate(b.id):void 0},inventory:(()=>{if(o){if(m)return;let n=D,r=O;return{assignedSpool:r?{id:r.id,material:r.material,brand:r.brand??null,color_name:r.color_name??null,remainingWeightGrams:r.label_weight?Math.max(0,Math.round(r.label_weight-r.weight_used)):void 0}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:255,trayId:i,trayInfo:{type:t.tray_type||M.profile,material:t.tray_type??void 0,profile:M.profile,color:M.colorHex||``,location:a||F(`printers.external`)}}),onUnassignSpool:r&&!Bp(t)?()=>h?.(r.id):void 0,isAssigned:!!n||Bp(t)}}let n=u?.(e.id,255,i);return{assignedSpool:n?.spool?{id:n.spool.id,material:n.spool.material,brand:n.spool.brand,color_name:n.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(n.spool.label_weight-n.spool.weight_used))}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:255,trayId:i,trayInfo:{type:t.tray_type||M.profile,material:t.tray_type??void 0,profile:M.profile,color:M.colorHex||``,location:a||F(`printers.external`)}}),onUnassignSpool:n&&!Bp(t)?()=>d?.(e.id,255,i):void 0,isAssigned:!!n||Bp(t)}})(),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:255,trayId:i,trayCount:1,trayType:t.tray_type||void 0,trayColor:t.tray_color||void 0,traySubBrands:t.tray_sub_brands||void 0,trayInfoIdx:t.tray_info_idx||void 0,extruderId:_?+(n===254):void 0,caliIdx:t.cali_idx,savedPresetId:v?.preset_id})},children:I})},n)})})]})]})]})})()]}),e.is_active!==!1&&!W?.connected&&r===`expanded`&&qn&&gr,r===`expanded`&&(0,G.jsxs)(`div`,{className:`mt-auto`,children:[Fn&&(0,G.jsxs)(`div`,{className:`pt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] uppercase tracking-wider text-bambu-gray font-medium`,children:F(`printers.power`,`Power`)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 rounded-[10px] bg-bambu-dark p-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 pl-1`,children:[(0,G.jsx)(rd,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm text-white truncate`,children:Fn.name}),(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray text-[length:var(--pc-t10,10px)] font-medium flex-shrink-0`,title:F(`smartPlugs.power`),children:Ln?.energy?.power!==null&&Ln?.energy?.power!==void 0?`${Math.round(Ln.energy.power)}W`:`--`})]}),(0,G.jsx)(`div`,{className:`flex-1`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`button`,{onClick:()=>ur.mutate(!Fn.auto_off),disabled:ur.isPending||Fn.auto_off_executed||!z(`smart_plugs:control`),title:z(`smart_plugs:control`)?Fn.auto_off_executed?F(`printers.autoOffExecuted`):F(`printers.autoOffAfterPrint`):F(`printers.permission.noSmartPlugControl`),className:`flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg text-xs font-bold transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${z(`smart_plugs:control`)?Fn.auto_off||Fn.auto_off_executed?`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary/80`:`bg-bambu-dark-tertiary/50 text-bambu-gray/50`}`,children:(0,G.jsx)(As,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`button`,{onClick:()=>{Ln?.state===`ON`?fe(!0):ue(!0)},disabled:lr.isPending||!z(`smart_plugs:control`),className:`flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg text-xs transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${z(`smart_plugs:control`)?Ln?.state===`ON`?`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary/80`:`bg-bambu-dark-tertiary/50 text-bambu-gray/50`}`,title:z(`smart_plugs:control`)?Ln?.state===`ON`?`Turn off`:`Turn on`:F(`printers.permission.noSmartPlugControl`),children:(0,G.jsx)(rd,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})})]})]}),In&&In.length>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,G.jsx)(zc,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] text-blue-600 dark:text-blue-400 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`HA:`}),(0,G.jsx)(`div`,{className:`h-[2px] w-5 bg-bambu-dark-tertiary/50`}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:In.map(e=>{let t=e.ha_entity_id?.startsWith(`script.`);return(0,G.jsxs)(`button`,{onClick:()=>{t?dr.mutate({id:e.id,action:`on`}):me(e)},disabled:dr.isPending,title:`${t?`Run`:`Toggle`} ${e.ha_entity_id}`,className:`px-2 py-0.5 text-xs bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 hover:bg-blue-500/30 rounded transition-colors flex items-center gap-1`,children:[(0,G.jsx)(Ml,{className:`w-[var(--pc-i25,0.625rem)] h-[var(--pc-i25,0.625rem)]`}),e.name]},e.id)})})]})]}),(0,G.jsx)(lce,{printerId:e.id}),(0,G.jsxs)(`div`,{className:`pt-4`,children:[(0,G.jsx)(`div`,{className:`mb-3 h-[2px] bg-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[vi,(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[(0,G.jsxs)(`div`,{className:`flex items-center flex-shrink-0`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>hi(_),disabled:!W?.connected||!z(`camera:view`),title:z(`camera:view`)?F(_===`embedded`?`printers.openCameraOverlay`:`printers.openCameraWindow`):F(`printers.permission.noCamera`),className:`${mi} !rounded-r-none`,children:(0,G.jsx)(Wu,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();At({x:t.left,y:t.bottom+4})},disabled:!W?.connected||!z(`camera:view`),title:z(`camera:view`)?F(`settings.cameraViewMode`):F(`printers.permission.noCamera`),"aria-label":F(`settings.cameraViewMode`),className:`!h-8 !min-h-8 !w-6 !px-0 !py-0 !rounded-l-none border-l border-bambu-dark`,children:(0,G.jsx)(fs,{className:`w-3 h-3`})})]}),kt&&(0,G.jsx)(_T,{x:kt.x,y:kt.y,items:gi,onClose:()=>At(null)}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>se(!0),disabled:!z(`printers:files`),title:z(`printers:files`)?F(`printers.browseFiles`):F(`printers.permission.noFiles`),className:mi,children:(0,G.jsx)(Nc,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>Ue(!0),disabled:!z(`library:upload`)||!z(`queue:create`),title:z(`library:upload`)?z(`queue:create`)?F(`common.print`):F(`fileManager.noPermissionAddToQueue`):F(`fileManager.noPermissionUpload`),className:`!h-8 !min-h-8 !px-2 !py-0 !bg-bambu-green hover:!bg-bambu-green/80 !text-white`,children:[(0,G.jsx)(Ll,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`common.print`)]})]})]})]})]}),(0,G.jsx)(bke,{printerId:e.id,dryingActive:En.some(e=>(e.dry_time??0)>0),timeFormat:g})]}),oe&&(0,G.jsx)(Use,{printerId:e.id,printerName:e.name,onClose:()=>se(!1)}),He&&(0,G.jsx)(IU,{folderId:null,onClose:()=>Ue(!1),onUploadComplete:()=>{},autoUpload:!0,accept:`.gcode,.3mf`,validateFile:e=>{let t=e.name.toLowerCase();if(!t.endsWith(`.gcode`)&&!t.includes(`.gcode.`))return F(`printers.dropNotPrintable`,`Only .gcode and .gcode.3mf files can be printed`)},onFileUploaded:t=>{let n=t.metadata?.sliced_for_model,r=DW(e.model);if(n&&r&&n.toLowerCase()!==r.toLowerCase())return Z.deleteLibraryFile(t.id).catch(()=>{}),F(`printers.incompatibleFile`,`This file was sliced for {{slicedFor}}, but this printer is a {{printerModel}}`,{slicedFor:n,printerModel:r});Xe({id:t.id,filename:t.filename})}}),Ye&&(0,G.jsx)(iW,{mode:`create`,libraryFileId:Ye.id,archiveName:Ye.filename,initialSelectedPrinterIds:[e.id],onClose:()=>Xe(null),onSuccess:()=>Xe(null),cleanupLibraryAfterDispatch:!0}),H&&(0,G.jsx)(ice,{printerId:e.id,printerName:e.name,onClose:()=>ce(!1)}),Ke&&(0,G.jsx)(Wp,{printerId:e.id,printerName:e.name,onClose:()=>qe(!1)}),We&&(0,G.jsx)(GOe,{printer:e,status:W,totalPrintHours:n?.total_print_hours,onClose:Je}),Wt&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:()=>Zr(),children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-w-lg w-full`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[Wt.needs_calibration?(0,G.jsx)(Yl,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-blue-500`}):Wt.is_empty?(0,G.jsx)(bs,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-green-500`}):(0,G.jsx)(Es,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-yellow-500`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:`Build Plate Check`}),Wt.reference_count!==void 0&&Wt.max_references&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[Wt.reference_count,`/`,Wt.max_references,` refs`]})]}),(0,G.jsx)(`button`,{onClick:()=>Zr(),className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(td,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)]`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[Wt.needs_calibration?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`p-3 rounded-lg bg-blue-100 dark:bg-blue-500/20 border border-blue-300 dark:border-blue-500/50`,children:[(0,G.jsx)(`p`,{className:`font-medium text-blue-700 dark:text-blue-400`,children:F(`printers.plateDetection.calibrationRequired`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,dangerouslySetInnerHTML:{__html:F(`printers.plateDetection.calibrationInstructions`)}})]}),(0,G.jsxs)(`div`,{className:`text-sm text-bambu-gray space-y-2`,children:[(0,G.jsx)(`p`,{children:F(`printers.plateDetection.calibrationDescription`)}),(0,G.jsx)(`p`,{dangerouslySetInnerHTML:{__html:F(`printers.plateDetection.calibrationTip`)}})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`p-3 rounded-lg ${Wt.is_empty?`bg-green-100 dark:bg-green-500/20 border border-green-300 dark:border-green-500/50`:`bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-300 dark:border-yellow-500/50`}`,children:[(0,G.jsx)(`p`,{className:`font-medium ${Wt.is_empty?`text-green-700 dark:text-green-400`:`text-yellow-700 dark:text-yellow-400`}`,children:Wt.is_empty?F(`printers.plateDetection.plateEmpty`):F(`printers.plateDetection.objectsDetected`)}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:[F(`printers.plateDetection.confidence`),`: `,Math.round(Wt.confidence*100),`% | `,F(`printers.plateDetection.difference`),`: `,Wt.difference_percent.toFixed(1),`%`]})]}),Wt.debug_image_url&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:F(`printers.plateDetection.analysisPreview`)}),(0,G.jsx)(`img`,{src:Wt.debug_image_url,alt:F(`printers.plateDetection.analysisPreview`),className:`w-full rounded-lg border border-bambu-dark-tertiary`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:F(`printers.plateDetection.analysisLegend`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:Wt.message})]}),Wr&&Wr.references.length>0&&(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white shrink-0`,children:F(`printers.plateDetection.savedReferences`,{count:Wr.references.length,max:Wr.max_references})}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-5 gap-2`,children:Wr.references.map(t=>(0,G.jsxs)(`div`,{className:`relative group`,children:[(0,G.jsx)(`img`,{src:Z.getPlateReferenceThumbnailUrl(e.id,t.index),alt:t.label||`Reference ${t.index+1}`,className:`w-full aspect-video object-cover rounded border border-bambu-dark-tertiary`}),(0,G.jsx)(`button`,{onClick:()=>ei(t.index),className:`absolute top-1 right-1 p-0.5 bg-red-500/80 rounded can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity`,title:F(`printers.plateDetection.deleteReference`),children:(0,G.jsx)(td,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-white`})}),Kr?.index===t.index?(0,G.jsx)(`input`,{type:`text`,value:Kr.label,onChange:e=>qr({...Kr,label:e.target.value}),onBlur:()=>$r(t.index,Kr.label),onKeyDown:e=>{e.key===`Enter`&&$r(t.index,Kr.label),e.key===`Escape`&&qr(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:F(`printers.plateDetection.labelPlaceholder`)}):(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1 truncate cursor-pointer hover:text-white`,onClick:()=>qr({index:t.index,label:t.label}),title:t.label?F(`printers.plateDetection.clickToEdit`,{label:t.label}):F(`printers.plateDetection.clickToAddLabel`),children:t.label||(0,G.jsx)(`span`,{className:`italic opacity-50`,children:F(`printers.noLabel`)})}),(0,G.jsx)(`p`,{className:`text-[length:var(--pc-t10,10px)] text-bambu-gray/60`,children:t.timestamp?Xf(t.timestamp)?.toLocaleDateString()??``:``})]},t.index))})]}),!Wt.needs_calibration&&(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white shrink-0`,children:F(`printers.roi.title`)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),Xt?(0,G.jsxs)(`div`,{className:`flex gap-1`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>Zt(null),disabled:Qt,children:F(`common.cancel`)}),(0,G.jsx)(Q,{size:`sm`,onClick:ti,disabled:Qt,children:Qt?(0,G.jsx)(Y,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] animate-spin`}):F(`common.save`)})]}):(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>Zt(Wt.roi||{x:.15,y:.35,w:.7,h:.55}),children:[(0,G.jsx)(kl,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] mr-1`}),F(`common.edit`)]})]}),Xt?(0,G.jsxs)(`div`,{className:`space-y-3 bg-bambu-dark-tertiary/50 p-3 rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:F(`printers.roi.xStart`)}),(0,G.jsx)(`input`,{type:`range`,min:`0`,max:`0.9`,step:`0.01`,value:Xt.x,onChange:e=>Zt({...Xt,x:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Xt.x*100),`%`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:F(`printers.roi.yStart`)}),(0,G.jsx)(`input`,{type:`range`,min:`0`,max:`0.9`,step:`0.01`,value:Xt.y,onChange:e=>Zt({...Xt,y:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Xt.y*100),`%`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:F(`printers.width`)}),(0,G.jsx)(`input`,{type:`range`,min:`0.1`,max:`1`,step:`0.01`,value:Xt.w,onChange:e=>Zt({...Xt,w:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Xt.w*100),`%`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:F(`printers.height`)}),(0,G.jsx)(`input`,{type:`range`,min:`0.1`,max:`1`,step:`0.01`,value:Xt.h,onChange:e=>Zt({...Xt,h:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Xt.h*100),`%`]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:F(`printers.roi.instruction`)})]}):(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[`Current: X=`,Math.round((Wt.roi?.x||.15)*100),`%, Y=`,Math.round((Wt.roi?.y||.35)*100),`%, W=`,Math.round((Wt.roi?.w||.7)*100),`%, H=`,Math.round((Wt.roi?.h||.55)*100),`%`]})]})]}),(0,G.jsx)(`div`,{className:`flex justify-end gap-2 p-4`,children:Wt.needs_calibration?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>Zr(),children:F(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>Qr(),disabled:Jt,children:Jt?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] mr-2 animate-spin`}),`Calibrating...`]}):`Calibrate Empty Plate`})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>Qr(),disabled:Jt,children:Jt?`Adding...`:`Add Reference (${Wr?.references.length||0}/${Wr?.max_references||5})`}),(0,G.jsx)(Q,{onClick:()=>Zr(),children:`Close`})]})})]})}),le&&Fn&&(0,G.jsx)(ef,{title:F(`printers.confirm.powerOnTitle`),message:F(`printers.confirm.powerOnMessage`,{name:e.name}),confirmText:F(`printers.confirm.powerOnButton`),variant:`default`,onConfirm:()=>{lr.mutate(`on`),ue(!1)},onCancel:()=>ue(!1)}),jr&&(0,G.jsx)(ef,{title:F(`printers.maintenance.confirmMidPrintTitle`),message:F(`printers.maintenance.confirmMidPrintMessage`,{name:e.name}),confirmText:F(`printers.maintenance.menuEnter`),variant:`danger`,onConfirm:()=>{Ar.mutate(!1),Mr(!1)},onCancel:()=>Mr(!1)}),de&&Fn&&(0,G.jsx)(ef,{title:F(`printers.confirm.powerOffTitle`),message:W?.state===`RUNNING`?F(`printers.confirm.powerOffWarning`,{name:e.name}):F(`printers.confirm.powerOffMessage`,{name:e.name}),confirmText:F(`printers.confirm.powerOffButton`),variant:`danger`,onConfirm:()=>{lr.mutate(`off`),fe(!1)},onCancel:()=>fe(!1)}),pe&&(0,G.jsx)(ef,{title:F(`printers.confirm.haToggleTitle`,{name:pe.name}),message:W?.state===`RUNNING`?F(`printers.confirm.haToggleWarning`,{name:e.name,entity:pe.ha_entity_id||pe.name}):F(`printers.confirm.haToggleMessage`,{entity:pe.ha_entity_id||pe.name}),confirmText:F(`printers.confirm.haToggleButton`),variant:W?.state===`RUNNING`?`danger`:`default`,onConfirm:()=>{dr.mutate({id:pe.id,action:`toggle`}),me(null)},onCancel:()=>me(null)}),we&&(0,G.jsx)(ef,{title:F(`printers.confirm.stopTitle`),message:F(`printers.confirm.stopMessage`,{name:e.name}),confirmText:F(`printers.confirm.stopButton`),variant:`danger`,onConfirm:()=>{fr.mutate(),Te(!1)},onCancel:()=>Te(!1)}),Ee&&(0,G.jsx)(ef,{title:F(`printers.confirm.pauseTitle`),message:F(`printers.confirm.pauseMessage`,{name:e.name}),confirmText:F(`printers.confirm.pauseButton`),variant:`default`,onConfirm:()=>{pr.mutate(),De(!1)},onCancel:()=>De(!1)}),Re&&(0,G.jsx)(ef,{title:F(`printers.confirm.resumeTitle`),message:F(`printers.confirm.resumeMessage`,{name:e.name}),confirmText:F(`printers.confirm.resumeButton`),variant:`default`,onConfirm:()=>{mr.mutate(),ze(!1)},onCancel:()=>ze(!1)}),(0,G.jsx)(cT,{printerId:e.id,isOpen:Be,onClose:()=>Ve(!1)}),he&&(0,G.jsx)(jee,{printerName:e.name,errors:W?.hms_errors||[],onClose:()=>ge(!1),printerId:e.id,hasPermission:z,runoutGuidance:Pn}),_e&&(0,G.jsx)(ace,{printerName:e.name,detection:N,lastError:P,onClose:()=>ve(!1)}),ye&&W&&(0,G.jsx)(iOe,{isOpen:ye,state:W.ams_filament_backup,amsUnits:W.ams,amsExtruderMap:W.ams_extruder_map,isDualNozzle:e.nozzle_count===2||W?.temperatures?.nozzle_2!==void 0,canToggle:z(`printers:control`),pending:cr.isPending,onToggle:e=>cr.mutate(e),onClose:()=>be(!1)}),Mt&&(0,G.jsx)(eOe,{isOpen:!!Mt,onClose:()=>Nt(null),printerId:e.id,printerName:e.name,amsId:Mt.amsId,amsLabel:Mt.amsLabel,initialMode:Mt.mode,thresholds:a}),Pt&&(0,G.jsx)(oOe,{isOpen:!!Pt,onClose:()=>Ft(null),printerId:e.id,printerName:e.name,initialKind:Pt.initialKind,availableKinds:Pt.availableKinds}),It&&(0,G.jsx)(qH,{isOpen:!!It,onClose:()=>Lt(null),tagUid:It.tagUid,trayUuid:It.trayUuid,printerId:It.printerId,amsId:It.amsId,trayId:It.trayId}),Rt&&(0,G.jsx)(YH,{isOpen:!!Rt,onClose:()=>zt(null),printerId:Rt.printerId,amsId:Rt.amsId,trayId:Rt.trayId,trayInfo:Rt.trayInfo,spoolmanEnabled:!!o}),Bt&&(0,G.jsx)(PU,{isOpen:!!Bt,onClose:()=>Vt(null),printerId:e.id,slotInfo:Bt,printerModel:DW(e.model)||void 0,nozzleDiameter:zp(W,Bt.amsId),onSuccess:()=>{I.invalidateQueries({queryKey:[`slotPresets`,e.id]}),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})}}),ie&&(0,G.jsx)(Cke,{printer:e,onClose:()=>ae(!1)}),Ht&&nn&&(0,G.jsx)(Ske,{printer:e,firmwareInfo:nn,onClose:()=>Ut(!1)}),Ze!==null&&ht&&(()=>{let e=$e===`n3s`?85:65,t=e+10;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-[100]`,"data-testid":`drying-popover-backdrop`,onMouseDown:()=>{xt.current=bt.current!==null&&document.activeElement===bt.current},onClick:()=>{if(xt.current){xt.current=!1;return}Qe(null)}}),(0,G.jsxs)(`div`,{className:`fixed z-[101] flex flex-col w-[240px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl overflow-hidden`,style:{left:ht.left,...ht.placement===`above`?{bottom:`calc(100dvh - ${ht.anchorY}px)`,maxHeight:`${ht.anchorY-8}px`}:{top:ht.top,maxHeight:`calc(100dvh - ${ht.top}px - 8px)`}},onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`shrink-0 flex items-center justify-center gap-2 px-3 py-2.5`,children:[(0,G.jsx)(mc,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium text-center`,children:F(`printers.drying.start`)})]}),(0,G.jsx)(`div`,{className:`shrink-0 h-px bg-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`px-3 py-2.5 space-y-2.5 overflow-y-auto min-h-0`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-[length:var(--pc-t10,10px)] text-white/70 font-medium mb-1 block`,children:F(`printers.filaments`)}),(0,G.jsx)(xW,{value:tt,options:Object.keys(S).map(e=>({value:e,label:e})),onChange:e=>{nt(e);let t=S[e];t&&(it(t[$e===`n3s`?`n3s`:`n3f`]),ot($e===`n3s`?t.n3s_hours:t.n3f_hours))},fullWidth:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsx)(`label`,{className:`text-[length:var(--pc-t10,10px)] text-white/70 font-medium`,children:F(`printers.drying.temperature`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:45,max:e,value:rt,onChange:t=>it(Math.min(e,Math.max(45,Number(t.target.value)||45))),className:`w-12 px-1 py-0.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-[length:var(--pc-t11,11px)] text-center focus:outline-none focus:border-bambu-green [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] text-bambu-gray`,children:`°C`})]})]}),(0,G.jsx)(`input`,{type:`range`,min:35,max:t,value:rt,onChange:t=>it(Math.min(e,Math.max(45,Number(t.target.value)))),className:`w-full h-1 accent-bambu-green cursor-pointer`}),(0,G.jsxs)(`div`,{className:`flex justify-between text-[length:var(--pc-t9,9px)] text-bambu-gray/50 mt-0.5`,children:[(0,G.jsx)(`span`,{children:`45°C`}),(0,G.jsxs)(`span`,{children:[e,`°C`]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsx)(`label`,{className:`text-[length:var(--pc-t10,10px)] text-white/70 font-medium`,children:F(`printers.drying.duration`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:1,max:24,value:at,onChange:e=>ot(Math.min(24,Math.max(1,Number(e.target.value)||1))),className:`w-10 px-1 py-0.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-[length:var(--pc-t11,11px)] text-center focus:outline-none focus:border-bambu-green [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] text-bambu-gray`,children:F(`printers.drying.hours`)})]})]}),(0,G.jsx)(`input`,{type:`range`,min:1,max:24,value:at,onChange:e=>ot(Number(e.target.value)),className:`w-full h-1 accent-bambu-green cursor-pointer`}),(0,G.jsxs)(`div`,{className:`flex justify-between text-[length:var(--pc-t9,9px)] text-bambu-gray/50 mt-0.5`,children:[(0,G.jsx)(`span`,{children:`1h`}),(0,G.jsx)(`span`,{children:`24h`})]})]}),(()=>{let e=((Ze===null?void 0:En.find(e=>e.id===Ze))?.tray??[]).some(e=>e.state===11),t=st&&!e;return(0,G.jsx)(`button`,{type:`button`,onClick:()=>ct(e=>!e),"aria-pressed":t,disabled:e,title:e?F(`printers.drying.rotateUnavailableReason`):void 0,className:`h-8 w-full rounded-lg border px-2 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${t?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary disabled:hover:bg-bambu-dark`}`,children:F(`printers.drying.rotateTray`)})})(),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-[10px] text-white/70 font-medium mb-1 block`,children:F(`printers.drying.startMode`)}),(0,G.jsx)(`div`,{className:`grid grid-cols-3 gap-1`,children:[`now`,`delay`,`at_time`].map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>ut(e),className:`py-1 rounded-lg border text-[10px] font-medium transition-colors ${lt===e?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:F(e===`now`?`printers.drying.modeNow`:e===`delay`?`printers.drying.modeDelay`:`printers.drying.modeAtTime`)},e))}),lt===`delay`&&(0,G.jsx)(`div`,{className:`mt-1.5 grid grid-cols-4 gap-1`,children:YOe.map(e=>(0,G.jsx)(`button`,{type:`button`,"aria-pressed":dt===e,onClick:()=>ft(e),className:`py-1 rounded-lg border text-[10px] font-medium transition-colors ${dt===e?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:ap(e/60)},e))}),lt===`at_time`&&(0,G.jsx)(`input`,{ref:bt,type:`datetime-local`,"data-testid":`drying-start-at`,value:pt,onChange:e=>mt(e.target.value),className:`mt-1.5 w-full px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-[11px] focus:outline-none focus:border-bambu-green [color-scheme:dark]`})]})]}),(0,G.jsx)(`div`,{className:`shrink-0 h-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`shrink-0 px-3 pt-2.5 pb-3`,children:(0,G.jsx)(`button`,{onClick:()=>{if(Ze!==null){let e=(En.find(e=>e.id===Ze)?.tray??[]).some(e=>e.state===11),t=st&&!e;if(lt===`now`)ir.mutate({amsId:Ze,temp:rt,duration:at,filament:tt,rotateTray:t});else{let e=Cee(lt,dt,pt);e&&ar.mutate({amsId:Ze,temp:rt,duration:at,filament:tt,rotateTray:t,startAfter:e})}}},disabled:ir.isPending||ar.isPending||lt===`at_time`&&!pt,"data-testid":`drying-start-confirm`,className:`w-full py-1.5 bg-bambu-green hover:bg-bambu-green/80 text-white text-xs font-medium rounded-lg transition-colors disabled:opacity-50`,children:lt===`now`?ir.isPending?F(`printers.drying.startingDrying`):F(`printers.drying.start`):F(`printers.drying.schedule`)})})]}),(0,G.jsx)(`div`,{className:`fixed z-[102] w-2.5 h-2.5 rotate-45 bg-bambu-dark-secondary border-bambu-dark-tertiary pointer-events-none`,style:{left:ht.left+ht.arrowLeft-5,top:ht.anchorY-5,...ht.placement===`above`?{borderRightWidth:1,borderBottomWidth:1}:{borderLeftWidth:1,borderTopWidth:1}}})]})})()]})}function xke({onClose:e,onAdd:t,existingSerials:n}){let{t:r}=U(),[i,a]=(0,y.useState)({name:``,serial_number:``,ip_address:``,access_code:``,model:``,location:``,auto_archive:!0}),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)([]),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(!1),[g,_]=(0,y.useState)([]),[v,b]=(0,y.useState)(``),[x,S]=(0,y.useState)(``),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)({scanned:0,total:0}),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(null);(0,y.useEffect)(()=>{_d.getInfo().then(e=>{h(e.is_docker),e.subnets.length>0&&(_(e.subnets),b(e.subnets[0]))}).catch(()=>{});try{let e=localStorage.getItem(`bambuddy.discovery.customSubnet`);e&&S(e)}catch{}},[]);let N=c.filter(e=>!n.includes(e.serial)),P=async e=>{e.preventDefault(),A(!0);try{let e=await Z.diagnoseConnection({ip_address:i.ip_address.trim(),serial_number:i.serial_number.trim()||void 0,access_code:i.access_code||void 0});if(e.checks.some(e=>e.status===`fail`)){M(e);return}}catch{}finally{A(!1)}t(i)},F=async()=>{d(``),l([]),s(!0),p(!1),E({scanned:0,total:0});let e=C?x.trim():v,t=m||C;if(t&&C)try{localStorage.setItem(`bambuddy.discovery.customSubnet`,e)}catch{}try{if(t){await _d.startSubnetScan(e);let t=setInterval(async()=>{try{let e=await _d.getScanStatus();E({scanned:e.scanned,total:e.total}),l(await _d.getDiscoveredPrinters()),e.running||(clearInterval(t),s(!1),p(!0))}catch(e){console.error(`Failed to get scan status:`,e)}},500)}else{await _d.startDiscovery(10);let e=setInterval(async()=>{try{l(await _d.getDiscoveredPrinters())}catch(e){console.error(`Failed to get discovered printers:`,e)}},1e3);setTimeout(async()=>{clearInterval(e);try{await _d.stopDiscovery()}catch{}s(!1),p(!0);try{l(await _d.getDiscoveredPrinters())}catch(e){console.error(`Failed to get final discovered printers:`,e)}},1e4)}}catch(e){console.error(`Failed to start discovery:`,e),d(e instanceof Error?e.message:r(`printers.discovery.failedToStart`)),s(!1),p(!0)}},I=e=>{let t=e.serial.startsWith(`unknown-`)?``:e.serial;a({...i,name:e.name||``,serial_number:t,ip_address:e.ip_address,model:DW(e.model)}),l([])};return(0,y.useEffect)(()=>()=>{_d.stopDiscovery().catch(()=>{}),_d.stopSubnetScan().catch(()=>{})},[]),(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-start sm:items-center justify-center z-50 p-4 overflow-y-auto`,onClick:e,children:(0,G.jsx)(Pd,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Id,{children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold mb-4`,children:r(`printers.addPrinter`)}),(0,G.jsxs)(`div`,{className:`mb-4 pb-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`mb-3`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.discovery.subnetToScan`)}),g.length>0?(0,G.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 text-sm`,value:C?`__custom__`:v,onChange:e=>{e.target.value===`__custom__`?w(!0):(w(!1),b(e.target.value))},disabled:o,children:[g.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e)),(0,G.jsx)(`option`,{value:`__custom__`,children:r(`printers.discovery.customSubnetOption`)})]}):(0,G.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:v,onChange:e=>b(e.target.value),placeholder:`192.168.1.0/24`,disabled:o}),C&&(0,G.jsx)(`input`,{type:`text`,"aria-label":r(`printers.discovery.customSubnetLabel`),className:`mt-2 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:x,onChange:e=>S(e.target.value),placeholder:`10.1.1.0/24`,disabled:o}),(0,G.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:r(m?`printers.discovery.dockerNote`:`printers.discovery.customSubnetNote`)})]}),(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:F,disabled:o,className:`w-full`,children:o?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(m||C)&&T.total>0?r(`printers.discovery.scanProgress`,{scanned:T.scanned,total:T.total}):r(`printers.discovery.scanning`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Zl,{className:`w-4 h-4`}),r(m||C?`printers.discovery.scanSubnet`:`printers.discovery.discoverNetwork`)]})}),u&&(0,G.jsx)(`div`,{className:`mt-2 text-sm text-red-700 dark:text-red-400`,children:u}),N.length>0&&(0,G.jsx)(`div`,{className:`mt-3 space-y-2 max-h-40 overflow-y-auto`,children:N.map(e=>(0,G.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:()=>I(e),children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`font-medium text-white text-sm truncate`,children:e.name||e.serial}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[DW(e.model)||r(`printers.discovery.unknown`),` • `,e.ip_address,e.serial.startsWith(`unknown-`)&&(0,G.jsxs)(`span`,{className:`text-yellow-500`,children:[` • `,r(`printers.discovery.serialRequired`)]})]})]}),(0,G.jsx)(fs,{className:`w-4 h-4 text-bambu-gray -rotate-90 flex-shrink-0 ml-2`})]},e.serial))}),o&&(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray text-center`,children:r(m||C?`printers.discovery.scanningSubnet`:`printers.discovery.scanningNetwork`)}),f&&!o&&c.length===0&&(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray text-center`,children:r(m||C?`printers.discovery.noPrintersFoundSubnet`:`printers.discovery.noPrintersFoundNetwork`)}),f&&!o&&c.length>0&&N.length===0&&(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray text-center`,children:r(`printers.discovery.allConfigured`)})]}),(0,G.jsxs)(`form`,{onSubmit:P,className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.name`)}),(0,G.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:i.name,onChange:e=>a({...i,name:e.target.value}),placeholder:r(`printers.modal.myPrinter`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.ipAddress`)}),(0,G.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:i.ip_address,onChange:e=>a({...i,ip_address:e.target.value}),placeholder:`192.168.1.100 or printer.local`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.serialNumber`)}),(0,G.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:i.serial_number,onChange:e=>a({...i,serial_number:e.target.value}),placeholder:`01P00A000000000`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.accessCode`)}),(0,G.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:i.access_code,onChange:e=>a({...i,access_code:e.target.value}),placeholder:r(`printers.modal.fromPrinterSettings`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.modal.modelOptional`)}),(0,G.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:i.model||``,onChange:e=>a({...i,model:e.target.value}),children:[(0,G.jsx)(`option`,{value:``,children:r(`printers.modal.selectModel`)}),(0,G.jsxs)(`optgroup`,{label:`A1 Series`,children:[(0,G.jsx)(`option`,{value:`A1`,children:`A1`}),(0,G.jsx)(`option`,{value:`A1 Mini`,children:`A1 Mini`})]}),(0,G.jsx)(`optgroup`,{label:`A2 Series`,children:(0,G.jsx)(`option`,{value:`A2L`,children:`A2L`})}),(0,G.jsxs)(`optgroup`,{label:`H2 Series`,children:[(0,G.jsx)(`option`,{value:`H2C`,children:`H2C`}),(0,G.jsx)(`option`,{value:`H2D`,children:`H2D`}),(0,G.jsx)(`option`,{value:`H2D Pro`,children:`H2D Pro`}),(0,G.jsx)(`option`,{value:`H2S`,children:`H2S`})]}),(0,G.jsxs)(`optgroup`,{label:`P Series`,children:[(0,G.jsx)(`option`,{value:`P1P`,children:`P1P`}),(0,G.jsx)(`option`,{value:`P1S`,children:`P1S`}),(0,G.jsx)(`option`,{value:`P2S`,children:`P2S`})]}),(0,G.jsxs)(`optgroup`,{label:`X1 Series`,children:[(0,G.jsx)(`option`,{value:`X1`,children:`X1`}),(0,G.jsx)(`option`,{value:`X1C`,children:`X1 Carbon`}),(0,G.jsx)(`option`,{value:`X1E`,children:`X1E`})]}),(0,G.jsx)(`optgroup`,{label:`X2 Series`,children:(0,G.jsx)(`option`,{value:`X2D`,children:`X2D`})})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.modal.locationGroup`)}),(0,G.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:i.location||``,onChange:e=>a({...i,location:e.target.value}),placeholder:r(`printers.modal.locationPlaceholder`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`printers.locationHelp`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`auto_archive`,checked:i.auto_archive,onChange:e=>a({...i,auto_archive:e.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`label`,{htmlFor:`auto_archive`,className:`text-sm text-bambu-gray`,children:r(`printers.modal.autoArchiveLabel`)})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>O(!0),disabled:!i.ip_address.trim(),className:`w-full flex items-center justify-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white disabled:opacity-40 disabled:cursor-not-allowed border border-bambu-dark-tertiary rounded-lg transition-colors`,children:[(0,G.jsx)(xu,{className:`w-4 h-4`}),r(`diagnostic.runButton`)]}),j?(0,G.jsxs)(`div`,{className:`rounded-lg bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 p-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Iu,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-amber-600 dark:text-amber-400`}),(0,G.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-300`,children:r(`printers.addPreflight.warning`)})]}),(0,G.jsx)(Up,{result:j}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>M(null),className:`flex-1`,children:r(`printers.addPreflight.back`)}),(0,G.jsx)(Q,{type:`button`,onClick:()=>t(i),className:`flex-1`,children:r(`printers.addPreflight.saveAnyway`)})]})]}):(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:e,className:`flex-1`,children:r(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:k,className:`flex-1`,children:r(k?`printers.addPreflight.checking`:`printers.addPrinter`)})]})]})]})})}),D&&(0,G.jsx)(Wp,{connection:{ip_address:i.ip_address.trim(),serial_number:i.serial_number.trim()||void 0,access_code:i.access_code||void 0},printerName:i.name||null,onClose:()=>O(!1)})]})}function Ske({printer:e,firmwareInfo:t,onClose:n}){let{t:r}=U(),i=co(),{showToast:a}=Hd(),{hasPermission:o}=Od(),s=o(`firmware:update`),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(t.update_available?t.latest_version:null),{data:g,isLoading:_}=K({queryKey:[`firmwarePrepare`,e.id,m],queryFn:()=>xd.prepareUpload(e.id,m??void 0),staleTime:3e4,enabled:!!m&&s&&!u}),v=q({mutationFn:()=>xd.startUpload(e.id,m??void 0),onSuccess:()=>{d(!0);let t=setInterval(async()=>{try{let n=await xd.getUploadStatus(e.id);l(n),(n.status===`complete`||n.status===`error`)&&(clearInterval(t),p(null),d(!1),n.status===`complete`&&(a(r(`printers.firmwareModal.uploadedToast`),`success`),i.invalidateQueries({queryKey:[`firmwareUpdate`,e.id]})))}catch{}},2e3);p(t)},onError:e=>{a(r(`printers.firmwareModal.uploadFailed`,{error:e.message}),`error`),d(!1)}});return(0,y.useEffect)(()=>()=>{f&&clearInterval(f)},[f]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,G.jsx)(Pd,{className:`w-full max-w-md mx-4`,children:(0,G.jsxs)(Id,{children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full ${t.update_available?`bg-orange-100 dark:bg-orange-500/20`:`bg-status-ok/20`}`,children:t.update_available?(0,G.jsx)(Ys,{className:`w-5 h-5 text-orange-600 dark:text-orange-400`}):(0,G.jsx)(bs,{className:`w-5 h-5 text-status-ok`})}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:t.update_available?r(`printers.firmwareModal.title`):r(`printers.firmwareModal.titleUpToDate`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e.name})]})]}),(()=>{let e=m?t.available_versions?.find(e=>e.version===m):null,n=m??t.latest_version,i=e?.release_notes??t.release_notes,a=!!n&&n!==t.current_version;return(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3 mb-4`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between items-center text-sm`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:r(`printers.firmwareModal.currentVersion`)}),(0,G.jsx)(`span`,{className:`font-mono ${a?`text-white`:`text-status-ok`}`,children:t.current_version||r(`common.unknown`)})]}),a&&(0,G.jsxs)(`div`,{className:`flex justify-between items-center text-sm mt-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:r(`printers.firmwareModal.latestVersion`)}),(0,G.jsx)(`span`,{className:`text-orange-700 dark:text-orange-400 font-mono`,children:n})]}),i&&(0,G.jsxs)(`details`,{className:`mt-3 text-sm`,open:!a,children:[(0,G.jsx)(`summary`,{className:`cursor-pointer hover:underline ${a?`text-orange-700 dark:text-orange-400`:`text-status-ok`}`,children:r(`printers.firmwareModal.releaseNotes`)}),(0,G.jsx)(`div`,{className:`mt-2 text-bambu-gray text-xs max-h-40 overflow-y-auto whitespace-pre-wrap`,children:i})]},n??`none`)]})})(),t.available_versions&&t.available_versions.length>0&&!u&&c?.status!==`complete`&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mb-2`,children:r(`printers.firmwareModal.availableVersions`)}),(0,G.jsx)(`div`,{className:`max-h-56 overflow-y-auto border border-bambu-dark-tertiary rounded-lg divide-y divide-bambu-dark-tertiary`,children:t.available_versions.map(e=>{let n=t.current_version===e.version,i=m===e.version,a=t.current_version?hee(e.version,t.current_version):0,o=r(n?`printers.firmwareModal.currentBadge`:a>0?`printers.firmwareModal.newerBadge`:`printers.firmwareModal.olderBadge`),c=n?`text-bambu-gray`:a>0?`text-orange-700 dark:text-orange-400`:`text-blue-700 dark:text-blue-400`;return(0,G.jsxs)(`button`,{type:`button`,disabled:!e.file_available||!s||n,onClick:()=>h(e.version),className:`w-full text-left px-3 py-2 text-sm flex items-center justify-between gap-2 transition-colors ${i?`bg-orange-50 dark:bg-orange-500/10`:`hover:bg-bambu-dark`} ${!e.file_available||!s||n?`opacity-60 cursor-not-allowed`:`cursor-pointer`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(`span`,{className:`font-mono text-white`,children:e.version}),(0,G.jsx)(`span`,{className:`text-xs ${c}`,children:o})]}),(0,G.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full ${n?`bg-blue-50 dark:bg-blue-500/15 text-blue-700 dark:text-blue-400 border border-blue-300 dark:border-blue-500/30`:e.file_available?`bg-bambu-green/15 text-bambu-green border border-bambu-green/30`:`bg-bambu-gray/10 text-bambu-gray border border-bambu-gray/30`}`,children:n?r(`printers.firmwareModal.installed`):e.file_available?r(`printers.firmwareModal.usable`):r(`printers.firmwareModal.unavailable`)})]},e.version)})})]}),m?_?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm mb-4`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`printers.firmwareModal.checkingPrereqs`)]}):g&&!u&&!c?(0,G.jsx)(`div`,{className:`mb-4`,children:g.can_proceed?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-green text-sm`,children:[(0,G.jsx)(Xo,{className:`w-4 h-4`}),r(`printers.firmwareModal.sdCardReady`)]}):(0,G.jsx)(`div`,{className:`space-y-1`,children:g.errors.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400 text-sm`,children:[(0,G.jsx)(vs,{className:`w-4 h-4 flex-shrink-0`}),e]},t))})}):null:null,(u||c)&&c&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-sm mb-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray capitalize`,children:c.status}),(0,G.jsxs)(`span`,{className:`text-white`,children:[c.progress,`%`]})]}),(0,G.jsx)(`div`,{className:`w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,G.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}%`}})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c.message}),c.error&&(0,G.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:c.error})]}),c?.status===`complete`&&(0,G.jsxs)(`div`,{className:`bg-bambu-green/10 border border-bambu-green/30 rounded-lg p-3 mb-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-green font-medium mb-2`,children:r(`printers.firmwareModal.uploadedSuccess`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`printers.firmwareModal.applyInstructions`)}),(0,G.jsxs)(`ol`,{className:`text-xs text-bambu-gray mt-1 list-decimal list-inside space-y-1`,children:[(0,G.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step1`)}}),(0,G.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step2`)}}),(0,G.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step3`)}}),(0,G.jsx)(`li`,{children:r(`printers.firmwareModal.step4`)})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:n,children:c?.status===`complete`?r(`printers.firmwareModal.done`):r(`common.cancel`)}),g?.can_proceed&&!u&&c?.status!==`complete`&&s&&(0,G.jsx)(Q,{onClick:()=>{l(null),v.mutate()},disabled:v.isPending,children:v.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-2`}),r(`printers.firmwareModal.starting`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ys,{className:`w-4 h-4 mr-2`}),r(`printers.firmwareModal.uploadFirmware`)]})})]})]})})})}function Cke({printer:e,onClose:t}){let{t:n}=U(),r=co(),{showToast:i}=Hd(),[a,o]=(0,y.useState)({name:e.name,ip_address:e.ip_address,access_code:``,model:e.model||``,location:e.location||``,auto_archive:e.auto_archive,is_active:e.is_active}),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(null),d=q({mutationFn:t=>Z.updatePrinter(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`printers`]}),r.invalidateQueries({queryKey:[`printerStatus`,e.id]}),t()},onError:e=>i(e.message||n(`printers.toast.failedToUpdate`),`error`)});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let f=()=>{let e={name:a.name,ip_address:a.ip_address,model:a.model||void 0,location:a.location||void 0,auto_archive:a.auto_archive,is_active:a.is_active};a.access_code&&(e.access_code=a.access_code),d.mutate(e)};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-start sm:items-center justify-center z-50 p-4 overflow-y-auto`,onClick:t,children:(0,G.jsx)(Pd,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Id,{children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold mb-4`,children:n(`printers.editPrinter`)}),(0,G.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault(),c(!0);try{let t=await Z.diagnoseConnection({ip_address:a.ip_address.trim(),serial_number:e.serial_number,access_code:a.access_code||void 0});if(t.checks.some(e=>e.status===`fail`)){u(t);return}}catch{}finally{c(!1)}f()},className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.name`)}),(0,G.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:e=>o({...a,name:e.target.value}),placeholder:n(`printers.modal.myPrinter`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.ipAddress`)}),(0,G.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:e=>o({...a,ip_address:e.target.value}),placeholder:`192.168.1.100 or printer.local`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.serialNumber`)}),(0,G.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:e.serial_number}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`printers.serialCannotBeChanged`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.accessCode`)}),(0,G.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:a.access_code,onChange:e=>o({...a,access_code:e.target.value}),placeholder:n(`printers.accessCodePlaceholder`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.model`)}),(0,G.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:e=>o({...a,model:e.target.value}),children:[(0,G.jsx)(`option`,{value:``,children:n(`printers.modal.selectModel`)}),(0,G.jsxs)(`optgroup`,{label:`A1 Series`,children:[(0,G.jsx)(`option`,{value:`A1`,children:`A1`}),(0,G.jsx)(`option`,{value:`A1 Mini`,children:`A1 Mini`})]}),(0,G.jsx)(`optgroup`,{label:`A2 Series`,children:(0,G.jsx)(`option`,{value:`A2L`,children:`A2L`})}),(0,G.jsxs)(`optgroup`,{label:`H2 Series`,children:[(0,G.jsx)(`option`,{value:`H2C`,children:`H2C`}),(0,G.jsx)(`option`,{value:`H2D`,children:`H2D`}),(0,G.jsx)(`option`,{value:`H2D Pro`,children:`H2D Pro`}),(0,G.jsx)(`option`,{value:`H2S`,children:`H2S`})]}),(0,G.jsxs)(`optgroup`,{label:`P Series`,children:[(0,G.jsx)(`option`,{value:`P1P`,children:`P1P`}),(0,G.jsx)(`option`,{value:`P1S`,children:`P1S`}),(0,G.jsx)(`option`,{value:`P2S`,children:`P2S`})]}),(0,G.jsxs)(`optgroup`,{label:`X1 Series`,children:[(0,G.jsx)(`option`,{value:`X1`,children:`X1`}),(0,G.jsx)(`option`,{value:`X1C`,children:`X1 Carbon`}),(0,G.jsx)(`option`,{value:`X1E`,children:`X1E`})]}),(0,G.jsx)(`optgroup`,{label:`X2 Series`,children:(0,G.jsx)(`option`,{value:`X2D`,children:`X2D`})})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Location / Group`}),(0,G.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:e=>o({...a,location:e.target.value}),placeholder:n(`printers.modal.locationPlaceholder`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`printers.locationHelp`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`edit_auto_archive`,checked:a.auto_archive,onChange:e=>o({...a,auto_archive:e.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`label`,{htmlFor:`edit_auto_archive`,className:`text-sm text-bambu-gray`,children:n(`printers.modal.autoArchiveLabel`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`edit_maintenance_mode`,checked:!a.is_active,onChange:e=>o({...a,is_active:!e.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-amber-400 focus:ring-amber-400`}),(0,G.jsxs)(`label`,{htmlFor:`edit_maintenance_mode`,className:`text-sm text-bambu-gray flex items-center gap-1.5`,children:[(0,G.jsx)(ed,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400`}),n(`printers.maintenance.editFieldLabel`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1 ml-6`,children:n(`printers.maintenance.editFieldHelp`)})]}),l?(0,G.jsxs)(`div`,{className:`rounded-lg bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 p-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Iu,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-amber-600 dark:text-amber-400`}),(0,G.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-300`,children:n(`printers.addPreflight.warning`)})]}),(0,G.jsx)(Up,{result:l}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>u(null),className:`flex-1`,children:n(`printers.addPreflight.back`)}),(0,G.jsx)(Q,{type:`button`,onClick:f,className:`flex-1`,disabled:d.isPending,children:n(`printers.addPreflight.saveAnyway`)})]})]}):(0,G.jsxs)(`div`,{className:`flex gap-3 pt-4`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,className:`flex-1`,disabled:d.isPending||s,children:s?n(`printers.addPreflight.checking`):d.isPending?n(`common.saving`):n(`printers.modal.saveChanges`)})]})]})]})})})}function wke(e){let{data:t}=K({queryKey:[`printerStatus`,e],queryFn:()=>Z.getPrinterStatus(e),refetchInterval:3e4});return!t?.connected}function Tke({printer:e,plug:t,onPowerOn:n,isPowering:r}){let i=wke(e.id),{data:a}=K({queryKey:[`smartPlugStatus`,t.id],queryFn:()=>Z.getSmartPlugStatus(t.id),refetchInterval:1e4});return i?(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 hover:bg-gray-100 dark:hover:bg-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white truncate`,children:e.name}),a&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded ${a.state===`ON`?`bg-bambu-green/20 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`}`,children:a.state||`?`})]}),(0,G.jsxs)(`button`,{onClick:()=>n(t.id),disabled:r||a?.state===`ON`,className:`px-2 py-1 text-xs rounded transition-colors flex items-center gap-1 ${a?.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:[(0,G.jsx)(Il,{className:`w-3 h-3`}),r?`...`:`On`]})]}):null}function Eke(){let{t:e}=U(),{resolvedMode:t,darkAccent:n,lightAccent:r}=jd(),i={green:`bg-green-500 text-white hover:bg-green-400 border-green-400/60`,teal:`bg-teal-500 text-white hover:bg-teal-400 border-teal-400/60`,blue:`bg-blue-500 text-white hover:bg-blue-400 border-blue-400/60`,orange:`bg-orange-500 text-white hover:bg-orange-400 border-orange-400/60`,purple:`bg-purple-500 text-white hover:bg-purple-400 border-purple-400/60`,red:`bg-red-500 text-white hover:bg-red-400 border-red-400/60`}[t===`dark`?n:r],[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(()=>localStorage.getItem(`hideDisconnectedPrinters`)===`true`),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(()=>localStorage.getItem(`printerSortBy`)||`name`),[h,g]=(0,y.useState)(()=>localStorage.getItem(`printerSortAsc`)!==`false`),[_,v]=(0,y.useState)(()=>{let e=localStorage.getItem(`printerCardSize`);return e?parseInt(e,10):2}),[b,x]=(0,y.useState)(()=>localStorage.getItem(`printerPageView`)===`camwall`?`camwall`:`cards`),[S,C]=(0,y.useState)(()=>{let e=parseInt(localStorage.getItem(`camWallMaxLive`)||``,10);return Number.isFinite(e)&&e>0?e:4}),[w,T]=(0,y.useState)(()=>{let e=parseInt(localStorage.getItem(`camWallSnapshotSec`)||``,10);return Number.isFinite(e)&&e>0?e:8}),[E,D]=(0,y.useState)(()=>{let e=localStorage.getItem(`camWallStatusMode`);return e===`off`||e===`compact`||e===`full`?e:`full`}),O=_===1?`compact`:`expanded`,[k,A]=(0,y.useState)(null),j=(0,y.useCallback)(e=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{let t=document.getElementById(`printer-card-${e}`);if(!t)return;let n=document.querySelector(`header`)?.getBoundingClientRect().height??56,r=t.getBoundingClientRect().top+window.scrollY-n-16;window.scrollTo({top:Math.max(0,r),behavior:`smooth`})})})},[]),M=(0,y.useCallback)(e=>{A(e),v(2),localStorage.setItem(`printerCardSize`,`2`),j(e)},[j]),N=(0,y.useCallback)(()=>{let e=k;A(null),v(1),localStorage.setItem(`printerCardSize`,`1`),e!=null&&j(e)},[k,j]),[P,F]=(0,y.useState)(``),[I,L]=(0,y.useState)(()=>{let e=localStorage.getItem(`printerStatusFilter`);return $Oe(e)?e:`all`}),[R,z]=(0,y.useState)(()=>localStorage.getItem(`printerLocationFilter`)||`all`),[B,V]=(0,y.useState)(0),[ee,te]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`printerCollapsedSections`);return e?JSON.parse(e):{}}catch{return{}}}),ne=co(),{showToast:re}=Hd(),{hasPermission:ie}=Od(),[ae,oe]=(0,y.useState)(()=>yee()),[se,H]=(0,y.useState)(()=>{let e=localStorage.getItem(`openEmbeddedCameras`);if(e)try{let t=JSON.parse(e);return new Map(t.map(e=>[e.id,e]))}catch{return new Map}return new Map});(0,y.useEffect)(()=>{let e=Array.from(se.values());e.length>0?localStorage.setItem(`openEmbeddedCameras`,JSON.stringify(e)):localStorage.removeItem(`openEmbeddedCameras`)},[se]);let{data:ce,isLoading:le}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:ue}=K({queryKey:[`ui-preferences`],queryFn:Z.getUiPreferences}),de=(0,y.useMemo)(()=>wm(ue?.nozzle_temp_presets,bm,0,320),[ue?.nozzle_temp_presets]),fe=(0,y.useMemo)(()=>wm(ue?.bed_temp_presets,xm,0,140),[ue?.bed_temp_presets]),pe=(0,y.useMemo)(()=>wm(ue?.chamber_temp_presets,Sm,0,65),[ue?.chamber_temp_presets]),me=(0,y.useMemo)(()=>wm(ue?.fan_speed_presets,Cm,0,100),[ue?.fan_speed_presets]),he=(0,y.useMemo)(()=>{if(ue?.drying_presets)try{let e=JSON.parse(ue.drying_presets);if(typeof e==`object`&&e&&Object.keys(e).length>0)return{...kW,...e}}catch{}return kW},[ue?.drying_presets]),ge=ae??(ue?.camera_view_mode===`embedded`?`embedded`:`window`),_e=(0,y.useCallback)(e=>{bee(e),oe(e),ie(`settings:update`)&&Z.updateSettings({camera_view_mode:e}).then(()=>ne.invalidateQueries({queryKey:[`ui-preferences`]})).catch(e=>console.warn(`Could not save camera view mode as the default:`,e))},[ie,ne]),{data:ve}=K({queryKey:[`smart-plugs`],queryFn:Z.getSmartPlugs}),{data:ye}=K({queryKey:[`maintenanceOverview`],queryFn:Z.getMaintenanceOverview,staleTime:60*1e3}),{data:be}=K({queryKey:[`obico-printer-status`],queryFn:Z.getObicoPrinterStatus,refetchInterval:1e4}),xe=(0,y.useCallback)(e=>be?.enabled===!0&&(be.monitored_printers===null||be.monitored_printers.includes(e)),[be]),{data:Se}=K({queryKey:[`spoolman-status`],queryFn:Z.getSpoolmanStatus,staleTime:60*1e3}),Ce=Se?.enabled&&Se?.connected,{data:we}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,enabled:!!Ce,staleTime:60*1e3}),Te=we?.spoolman_sync_mode,{data:Ee}=K({queryKey:[`unlinked-spools`],queryFn:Z.getUnlinkedSpools,enabled:!!Ce,staleTime:30*1e3}),De=Ee&&Ee.length>0,{data:Oe}=K({queryKey:[`linked-spools`],queryFn:Z.getLinkedSpools,enabled:!!Ce,staleTime:30*1e3}),ke=Oe?.linked,{data:Ae}=K({queryKey:[`spool-assignments`],queryFn:()=>Z.getAssignments(),enabled:ie(`inventory:view_assignments`),staleTime:30*1e3}),je=q({mutationFn:({printerId:e,amsId:t,trayId:n})=>Z.unassignSpool(e,t,n),onSuccess:()=>{ne.invalidateQueries({queryKey:[`spool-assignments`]})}}),{data:Me,isLoading:Ne}=K({queryKey:[`spoolman-inventory-spools`],queryFn:()=>Z.getSpoolmanInventorySpools(!1),enabled:!!Ce,staleTime:30*1e3}),{data:Pe,isLoading:Fe}=K({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:!!Ce,staleTime:30*1e3}),Ie=q({mutationFn:e=>Z.unassignSpoolmanSlot(e),onSuccess:()=>{ne.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),ne.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})}}),Le=(e,t,n)=>Ae?.find(r=>r.printer_id===e&&r.ams_id===Number(t)&&r.tray_id===Number(n)),Re=ye?.reduce((e,t)=>(e[t.printer_id]={due_count:t.due_count,warning_count:t.warning_count,total_print_hours:t.total_print_hours},e),{})||{},ze=ve?.reduce((e,t)=>(t.printer_id&&(e[t.printer_id]=t),e),{})||{},Be=q({mutationFn:Z.createPrinter,onSuccess:()=>{ne.invalidateQueries({queryKey:[`printers`]}),ne.invalidateQueries({queryKey:[`maintenanceOverview`]}),o(!1)},onError:t=>{if(t instanceof od&&t.code===`printer_connection_failed`){re(e(`printers.toast.connectionFailedNotAdded`),`error`);return}re(t.message||e(`printers.toast.failedToAdd`),`error`)}}),Ve=q({mutationFn:e=>Z.controlSmartPlug(e,`on`),onSuccess:()=>{ne.invalidateQueries({queryKey:[`smart-plugs`]}),f(null)},onError:()=>{f(null)}}),[He,Ue]=(0,y.useState)(new Set),[We,Ge]=(0,y.useState)(!1),[Ke,qe]=(0,y.useState)(null),[Je,Ye]=(0,y.useState)(!1),Xe=We||He.size>0,Ze=(0,y.useCallback)(e=>{Ue(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Qe=(0,y.useCallback)(()=>{Ue(new Set),Ge(!1)},[]);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&Xe&&Qe()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Xe,Qe]);let $e=(0,y.useCallback)(async t=>{Ye(!0);let n=Array.from(He).filter(e=>{let n=ne.getQueryData([`printerStatus`,e]);if(t===`clearPlate`)return!!n?.awaiting_plate_clear;if(!n?.connected)return!1;switch(t){case`stop`:return n.state===`RUNNING`||n.state===`PAUSE`;case`pause`:return n.state===`RUNNING`;case`resume`:return n.state===`PAUSE`;case`clearHMS`:return n.hms_errors&&km(n.hms_errors).length>0;default:return!1}});if(n.length===0){re(e(`printers.bulk.noneApplicable`),`error`),Ye(!1),qe(null);return}let r={stop:Z.stopPrint,pause:Z.pausePrint,resume:Z.resumePrint,clearPlate:Z.clearPlate,clearHMS:Z.clearHMSErrors}[t],i=await Promise.allSettled(n.map(e=>r(e))),a=i.filter(e=>e.status===`fulfilled`).length,o=i.filter(e=>e.status===`rejected`).length;o===0?re(e(`printers.bulk.success`,{action:e(`printers.bulk.actions.${t}`),count:a})):re(e(`printers.bulk.partial`,{succeeded:a,failed:o}),`error`),n.forEach(e=>{ne.invalidateQueries({queryKey:[`printerStatus`,e]})}),Ye(!1),qe(null)},[He,ne,re,e]),et=(0,y.useCallback)(e=>{e===`stop`||e===`pause`||e===`clearPlate`?qe(e):$e(e)},[$e]),tt=()=>{let e=!s;c(e),localStorage.setItem(`hideDisconnectedPrinters`,String(e))},nt=e=>{m(e),localStorage.setItem(`printerSortBy`,e)},rt=e=>{L(e),localStorage.setItem(`printerStatusFilter`,e)},it=e=>{z(e),localStorage.setItem(`printerLocationFilter`,e)},at=()=>{let e=!h;g(e),localStorage.setItem(`printerSortAsc`,String(e))},ot=()=>{switch(_){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`}},st=[`S`,`M`,`L`,`XL`];(0,y.useEffect)(()=>ne.getQueryCache().subscribe(e=>{e.type===`updated`&&Array.isArray(e.query.queryKey)&&e.query.queryKey[0]===`printerStatus`&&V(e=>e+1)}),[ne]);let ct=(0,y.useMemo)(()=>{if(!ce)return[];let e=ce;if(P.trim()){let t=P.trim().toLowerCase();e=e.filter(e=>e.name.toLowerCase().includes(t)||(e.model||``).toLowerCase().includes(t)||(e.location||``).toLowerCase().includes(t)||(e.serial_number||``).toLowerCase().includes(t))}return R!==`all`&&(e=e.filter(e=>(e.location||``)===R)),I!==`all`&&(e=e.filter(e=>{let t=ne.getQueryData([`printerStatus`,e.id]);if(!t?.connected)return I===`offline`;let n=t.hms_errors?km(t.hms_errors):[];switch(I){case`printing`:return t.state===`RUNNING`;case`paused`:return t.state===`PAUSE`;case`finished`:return t.state===`FINISH`;case`error`:return t.state===`FAILED`||n.length>0;case`idle`:return t.state!==`RUNNING`&&t.state!==`PAUSE`&&t.state!==`FINISH`&&t.state!==`FAILED`&&n.length===0;case`offline`:return!1;default:return!0}})),e},[ce,P,I,R,ne,B]),lt=(0,y.useMemo)(()=>ce?[...new Set(ce.map(e=>e.location||``).filter(Boolean))].sort():[],[ce]);(0,y.useEffect)(()=>{!ce||R===`all`||lt.includes(R)||(z(`all`),localStorage.setItem(`printerLocationFilter`,`all`))},[ce,lt,R]);let ut=(0,y.useMemo)(()=>{let e=[...ct];switch(p){case`name`:e.sort((e,t)=>e.name.localeCompare(t.name));break;case`model`:e.sort((e,t)=>(e.model||``).localeCompare(t.model||``));break;case`location`:e.sort((e,t)=>{let n=e.location||``,r=t.location||``;return!n&&r?1:n&&!r?-1:n.localeCompare(r)||e.name.localeCompare(t.name)});break;case`status`:e.sort((e,t)=>{let n=ne.getQueryData([`printerStatus`,e.id]),r=ne.getQueryData([`printerStatus`,t.id]),i=e=>e?.connected?(e.hms_errors?km(e.hms_errors):[]).length>0?0:e.state===`RUNNING`?1:2:3;return i(n)-i(r)});break;case`eta`:e.sort((e,t)=>{let n=ne.getQueryData([`printerStatus`,e.id]),r=ne.getQueryData([`printerStatus`,t.id]),i=e=>e?.connected?e.state===`RUNNING`&&e.remaining_time!=null&&e.remaining_time>0?0:e.state===`RUNNING`?1:2:3,a=i(n),o=i(r);if(a!==o)return a-o;if(a===0){let e=(n.remaining_time??0)-(r.remaining_time??0);if(e!==0)return e}return e.name.localeCompare(t.name)});break}return h||e.reverse(),e},[ct,p,h,ne]),dt=(0,y.useCallback)(()=>{Ue(new Set(ut.map(e=>e.id))),Ge(!0)},[ut]),ft=(0,y.useCallback)(e=>{Ue(t=>{let n=new Set(t);return ut.forEach(t=>{EW(ne.getQueryData([`printerStatus`,t.id]))===e&&n.add(t.id)}),n}),Ge(!0)},[ut,ne]),pt=(0,y.useCallback)(e=>{Ue(t=>{let n=new Set(t);return ut.filter(t=>(t.location||``)===e).forEach(e=>n.add(e.id)),n}),Ge(!0)},[ut]),mt=(0,y.useCallback)(e=>{Ue(t=>{let n=new Set(t);return ut.filter(t=>(t.model||`Unknown`)===e).forEach(e=>n.add(e.id)),n}),Ge(!0)},[ut]),ht=(0,y.useCallback)(e=>{te(t=>{let n={...t,[e]:!t[e]};try{localStorage.setItem(`printerCollapsedSections`,JSON.stringify(n))}catch{}return n})},[]),gt=(0,y.useMemo)(()=>{if(p===`name`||p===`eta`)return null;let e={};return p===`location`?ut.forEach(t=>{let n=t.location||`Ungrouped`;e[n]||(e[n]=[]),e[n].push(t)}):p===`model`?ut.forEach(t=>{let n=t.model||`Unknown`;e[n]||(e[n]=[]),e[n].push(t)}):p===`status`&&ut.forEach(t=>{let n=EW(ne.getQueryData([`printerStatus`,t.id]));e[n]||(e[n]=[]),e[n].push(t)}),e},[p,ut,ne,B]),_t=(0,y.useRef)(null),vt=(0,y.useRef)(null),yt=(0,y.useRef)(0),[bt,xt]=(0,y.useState)(!1),St=(0,y.useCallback)(()=>{let e=_t.current;if(!e)return;let t=vt.current?.offsetWidth;t&&(yt.current=t);let n=yt.current>0&&e.clientWidthe===n?e:n)},[]),Ct=Object.keys(ze).length;(0,y.useLayoutEffect)(()=>{St();let e=_t.current;if(!e)return;if(typeof ResizeObserver>`u`)return window.addEventListener(`resize`,St),()=>window.removeEventListener(`resize`,St);let t=new ResizeObserver(()=>St());return t.observe(e),window.addEventListener(`resize`,St),()=>{t.disconnect(),window.removeEventListener(`resize`,St)}},[St,ce?.length,lt.length,s,Ct]);let wt=(t=!1)=>(0,G.jsxs)(G.Fragment,{children:[ce&&ce.length>0&&(0,G.jsx)(xW,{value:I,onChange:rt,fullWidth:t,options:cW.map(t=>({value:t.value,label:e(t.labelKey)}))}),ce&&ce.length>0&<.length>0&&(0,G.jsx)(xW,{value:R,onChange:it,fullWidth:t,options:[{value:`all`,label:e(`printers.filter.allLocations`)},...lt.map(e=>({value:e,label:e}))]}),(0,G.jsx)(`button`,{type:`button`,onClick:tt,"aria-pressed":s,className:`h-8 px-2 rounded-lg border text-sm font-medium transition-colors ${t?`w-full`:``} ${s?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:e(`printers.hideOffline`)})]}),Tt=(t=!1)=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1 ${t?`w-full`:``}`,children:[(0,G.jsx)(xW,{value:p,onChange:nt,fullWidth:t,options:[{value:`name`,label:e(`printers.sort.name`)},{value:`status`,label:e(`printers.sort.status`)},{value:`model`,label:e(`printers.sort.model`)},{value:`location`,label:e(`printers.sort.location`)},{value:`eta`,label:e(`printers.sort.eta`)}]}),(0,G.jsx)(`button`,{onClick:at,className:`h-8 shrink-0 px-2 rounded-lg border bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center justify-center`,title:e(h?`printers.sort.descending`:`printers.sort.ascending`),children:h?(0,G.jsx)(Ho,{className:`w-4 h-4 text-white`}):(0,G.jsx)(Io,{className:`w-4 h-4 text-white`})})]}),(0,G.jsxs)(`div`,{className:`flex h-8 items-center bg-bambu-dark rounded-lg border border-bambu-dark-tertiary ${t?`w-full`:``}`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{x(`cards`),localStorage.setItem(`printerPageView`,`cards`)},className:`flex h-full items-center gap-1 rounded-l-lg px-2 text-xs font-medium transition-colors ${t?`flex-1 justify-center`:``} ${b===`cards`?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,title:e(`printers.pageView.cards`),"aria-pressed":b===`cards`,children:[(0,G.jsx)(Jc,{className:`w-3.5 h-3.5`}),t&&(0,G.jsx)(`span`,{children:e(`printers.pageView.cards`)})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{x(`camwall`),localStorage.setItem(`printerPageView`,`camwall`)},className:`flex h-full items-center gap-1 rounded-r-lg px-2 text-xs font-medium transition-colors ${t?`flex-1 justify-center`:``} ${b===`camwall`?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,title:e(`printers.pageView.camWall`),"aria-pressed":b===`camwall`,disabled:!ie(`camera:view`),children:[(0,G.jsx)(ml,{className:`w-3.5 h-3.5`}),t&&(0,G.jsx)(`span`,{children:e(`printers.pageView.camWall`)})]})]}),b===`camwall`&&ie(`camera:view`)&&(0,G.jsxs)(Ai,{to:`/camwall`,className:`flex h-8 items-center gap-1 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark px-2 text-xs font-medium text-white transition-colors hover:bg-bambu-dark-tertiary ${t?`w-full justify-center`:``}`,title:e(`printers.pageView.openCamWallPage`),children:[(0,G.jsx)(nc,{className:`w-3.5 h-3.5`}),t&&(0,G.jsx)(`span`,{children:e(`printers.pageView.openCamWallPage`)})]}),(0,G.jsx)(`div`,{className:`flex h-8 items-center bg-bambu-dark rounded-lg border border-bambu-dark-tertiary ${b===`camwall`?`opacity-40 pointer-events-none`:``} ${t?`w-full`:``}`,children:st.map((n,r)=>{let i=r+1,a=_===i;return(0,G.jsx)(`button`,{onClick:()=>{A(null),v(i),localStorage.setItem(`printerCardSize`,String(i))},className:`h-full px-2 text-xs font-medium transition-colors ${t?`flex-1`:``} ${r===0?`rounded-l-lg`:``} ${r===st.length-1?`rounded-r-lg`:``} ${a?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,title:e(n===`S`?`printers.cardSize.small`:n===`M`?`printers.cardSize.medium`:n===`L`?`printers.cardSize.large`:`printers.cardSize.extraLarge`),children:n},n)})})]}),Et=(t=!1)=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`button`,{onClick:()=>{Xe?Qe():Ge(!0)},className:`h-8 px-2 rounded-lg border transition-colors ${t?`w-full justify-center gap-1.5 text-sm font-medium flex items-center`:``} ${Xe?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,title:e(`printers.bulk.select`),disabled:!ie(`printers:control`),children:[(0,G.jsx)(_u,{className:`w-4 h-4`}),t&&(0,G.jsx)(`span`,{children:e(`printers.bulk.select`)})]}),s&&Object.keys(ze).length>0&&(0,G.jsxs)(`div`,{className:`relative ${t?`w-full`:``}`,children:[(0,G.jsxs)(`button`,{onClick:()=>u(!l),className:`h-8 flex items-center gap-1.5 px-2 text-sm rounded-lg border transition-colors ${t?`w-full justify-between bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary hover:text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(Il,{className:`w-4 h-4`}),e(`printers.powerOn`)]}),(0,G.jsx)(fs,{className:`w-3 h-3 transition-transform ${l?`rotate-180`:``}`})]}),l&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>u(!1)}),(0,G.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:[(0,G.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:e(`printers.offlinePrintersWithPlugs`)}),ce?.filter(e=>ze[e.id]).map(e=>(0,G.jsx)(Tke,{printer:e,plug:ze[e.id],onPowerOn:e=>{f(e),Ve.mutate(e)},isPowering:d===ze[e.id]?.id},e.id)),ce?.filter(e=>ze[e.id]).length===0&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:`No printers with smart plugs`})]})]})]}),(0,G.jsxs)(Q,{onClick:()=>o(!0),disabled:!ie(`printers:create`),title:ie(`printers:create`)?void 0:e(`printers.permission.noAdd`),className:`!h-8 !min-h-8 px-2 py-0 ${t?`w-full`:``}`,children:[(0,G.jsx)(Pl,{className:`w-4 h-4`}),e(`printers.addPrinter`)]})]});return(0,G.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,G.jsxs)(`div`,{className:`space-y-3 mb-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(Ll,{className:`w-7 h-7 text-bambu-green`}),e(`printers.title`)]}),(0,G.jsx)(pke,{printers:ce})]}),(0,G.jsxs)(`div`,{ref:_t,className:`relative flex items-center gap-2`,children:[ce&&ce.length>0&&(0,G.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,G.jsx)(Zl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50`}),(0,G.jsx)(`input`,{type:`search`,name:`printer-search`,autoComplete:`off`,"data-1p-ignore":!0,"data-lpignore":`true`,value:P,onChange:e=>F(e.target.value),placeholder:e(`printers.search`),"aria-label":e(`printers.search`),className:`w-full h-8 pl-9 pr-8 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`}),P&&(0,G.jsx)(`button`,{type:`button`,"aria-label":e(`common.clear`),onClick:()=>F(``),className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,G.jsx)(td,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{ref:vt,"aria-hidden":bt,inert:bt,className:`${bt?`absolute -left-[9999px] top-0 flex w-max pointer-events-none opacity-0`:`flex`} ml-auto items-center justify-end gap-2 flex-nowrap [&>*]:shrink-0`,children:[(0,G.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:wt()}),(0,G.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:Tt()}),(0,G.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:Et()})]}),bt&&(0,G.jsxs)(`div`,{className:`ml-auto flex items-center justify-end gap-1`,children:[(0,G.jsx)(SW,{label:e(`printers.toolbar.filters`,`Filters`),icon:(0,G.jsx)(Cc,{className:`w-4 h-4`}),children:(0,G.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:wt(!0)})}),(0,G.jsx)(SW,{label:e(`printers.toolbar.view`,`View`),icon:(0,G.jsx)(du,{className:`w-4 h-4`}),children:(0,G.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:Tt(!0)})}),(0,G.jsx)(SW,{label:e(`printers.toolbar.actions`,`Actions`),icon:(0,G.jsx)($s,{className:`w-4 h-4`}),children:(0,G.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:Et(!0)})})]})]})]}),le?(0,G.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`common.loading`)}):ce?.length===0?(0,G.jsx)(Pd,{children:(0,G.jsxs)(Id,{className:`text-center py-12`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`printers.noPrintersConfigured`)}),(0,G.jsxs)(Q,{onClick:()=>o(!0),disabled:!ie(`printers:create`),title:ie(`printers:create`)?void 0:e(`printers.permission.noAdd`),children:[(0,G.jsx)(Pl,{className:`w-4 h-4`}),e(`printers.addPrinter`)]})]})}):ut.length===0&&(P.trim()||I!==`all`||R!==`all`)?(0,G.jsx)(Pd,{children:(0,G.jsx)(Id,{className:`text-center py-12`,children:(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`printers.noSearchResults`)})})}):b===`camwall`?(0,G.jsx)(gT,{printers:ut,maxLive:S,snapshotIntervalSec:w,onTileClick:(e,t)=>{ge===`embedded`?H(n=>new Map(n).set(e,{id:e,name:t})):fm(e)},statusMode:E,onChangeMaxLive:e=>{C(e),localStorage.setItem(`camWallMaxLive`,String(e))},onChangeSnapshotIntervalSec:e=>{T(e),localStorage.setItem(`camWallSnapshotSec`,String(e))},onChangeStatusMode:e=>{D(e),localStorage.setItem(`camWallStatusMode`,e)}}):gt?(0,G.jsx)(`div`,{className:`space-y-6`,children:(()=>{let e=p===`status`?hke.filter(e=>gt[e]?.length>0):Object.keys(gt);return h?e:[...e].reverse()})().map(t=>{let n=gt[t],r=`${p}:${t}`,i=!ee[r],a=p===`status`&&TW[t]?.dot||`bg-bambu-green`,o=p===`status`?e(TW[t]?.labelKey||t):t;return(0,G.jsx)(qp,{open:i,onToggle:()=>ht(r),summaryClassName:`py-1`,summary:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${a}`}),o,(0,G.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n.length,`)`]}),Xe&&(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),p===`location`?pt(t===`Ungrouped`?``:t):p===`status`?ft(t):p===`model`&&mt(t)},className:`text-xs text-bambu-green hover:text-bambu-green-light transition-colors ml-1`,children:e(`printers.bulk.selectAll`)})]}),children:(0,G.jsx)(`div`,{className:`grid gap-4 ${_>=3?`gap-6`:``} ${ot()}`,children:n.map(e=>(0,G.jsx)(jW,{printer:e,hideIfDisconnected:s,maintenanceInfo:Re[e.id],viewMode:O,cardSize:_,amsThresholds:ue?{humidityGood:Number(ue.ams_humidity_good)||40,humidityFair:Number(ue.ams_humidity_fair)||60,tempGood:Number(ue.ams_temp_good)||28,tempFair:Number(ue.ams_temp_fair)||35}:void 0,spoolmanEnabled:Ce,hasUnlinkedSpools:De,linkedSpools:ke,spoolmanUrl:Se?.url,spoolmanSyncMode:Te,onGetAssignment:Le,onUnassignSpool:(e,t,n)=>je.mutate({printerId:e,amsId:t,trayId:n}),spoolmanSpools:Me,spoolmanSlotAssignments:Pe,spoolmanLoading:Ne||Fe,onUnassignSpoolmanSpool:e=>Ie.mutate(e),timeFormat:ue?.time_format||`system`,cameraViewMode:ge,onOpenEmbeddedCamera:(e,t)=>H(n=>new Map(n).set(e,{id:e,name:t})),onSelectCameraViewMode:_e,checkPrinterFirmware:ue?.check_printer_firmware!==!1,dryingPresets:he,nozzleTempPresets:de,bedTempPresets:fe,chamberTempPresets:pe,fanSpeedPresets:me,requirePlateClear:ue?.require_plate_clear===!0,selectionMode:Xe,isSelected:He.has(e.id),onToggleSelect:Ze,onOpenCompactCard:M,aiDetectionEnabled:xe(e.id),aiDetection:be?.enabled?be.per_printer[String(e.id)]:void 0,aiLastError:be?.last_error??null},e.id))})},t)})}):(0,G.jsx)(`div`,{className:`grid gap-4 ${_>=3?`gap-6`:``} ${ot()}`,children:ut.map(e=>(0,G.jsx)(jW,{printer:e,hideIfDisconnected:s,maintenanceInfo:Re[e.id],viewMode:O,cardSize:_,spoolmanEnabled:Ce,hasUnlinkedSpools:De,linkedSpools:ke,spoolmanUrl:Se?.url,spoolmanSyncMode:Te,onGetAssignment:Le,onUnassignSpool:(e,t,n)=>je.mutate({printerId:e,amsId:t,trayId:n}),spoolmanSpools:Me,spoolmanSlotAssignments:Pe,spoolmanLoading:Ne||Fe,onUnassignSpoolmanSpool:e=>Ie.mutate(e),amsThresholds:ue?{humidityGood:Number(ue.ams_humidity_good)||40,humidityFair:Number(ue.ams_humidity_fair)||60,tempGood:Number(ue.ams_temp_good)||28,tempFair:Number(ue.ams_temp_fair)||35}:void 0,timeFormat:ue?.time_format||`system`,cameraViewMode:ge,onOpenEmbeddedCamera:(e,t)=>H(n=>new Map(n).set(e,{id:e,name:t})),onSelectCameraViewMode:_e,checkPrinterFirmware:ue?.check_printer_firmware!==!1,dryingPresets:he,nozzleTempPresets:de,bedTempPresets:fe,chamberTempPresets:pe,fanSpeedPresets:me,requirePlateClear:ue?.require_plate_clear===!0,selectionMode:Xe,isSelected:He.has(e.id),onToggleSelect:Ze,onOpenCompactCard:M,aiDetectionEnabled:xe(e.id),aiDetection:be?.enabled?be.per_printer[String(e.id)]:void 0,aiLastError:be?.last_error??null},e.id))}),_===2&&k!=null&&(0,G.jsxs)(`button`,{type:`button`,onClick:N,className:`fixed bottom-5 left-1/2 z-40 inline-flex -translate-x-1/2 items-center gap-2 rounded-full border px-4 py-2 text-sm font-medium shadow-xl transition-colors ${i}`,title:e(`common.back`,`Back`),children:[(0,G.jsx)(Lo,{className:`w-4 h-4`}),e(`common.back`,`Back`)]}),a&&(0,G.jsx)(xke,{onClose:()=>o(!1),onAdd:e=>Be.mutate(e),existingSerials:ce?.map(e=>e.serial_number)||[]}),Xe&&ce&&(0,G.jsx)(Nee,{selectedIds:He,printers:ce,onClose:Qe,onSelectAll:dt,onSelectByLocation:pt,onSelectByState:ft,onAction:et,actionPending:Je}),Ke===`stop`&&(0,G.jsx)(ef,{title:e(`printers.bulk.confirm.stopTitle`,{count:He.size}),message:e(`printers.bulk.confirm.stopMessage`,{count:He.size}),confirmText:e(`printers.bulk.confirm.stopButton`),variant:`danger`,isLoading:Je,onConfirm:()=>$e(`stop`),onCancel:()=>qe(null)}),Ke===`pause`&&(0,G.jsx)(ef,{title:e(`printers.bulk.confirm.pauseTitle`,{count:He.size}),message:e(`printers.bulk.confirm.pauseMessage`,{count:He.size}),confirmText:e(`printers.bulk.confirm.pauseButton`),isLoading:Je,onConfirm:()=>$e(`pause`),onCancel:()=>qe(null)}),Ke===`clearPlate`&&(0,G.jsx)(ef,{title:e(`printers.bulk.confirm.clearPlateTitle`,{count:He.size}),message:e(`printers.bulk.confirm.clearPlateMessage`,{count:He.size}),confirmText:e(`printers.bulk.confirm.clearPlateButton`),isLoading:Je,onConfirm:()=>$e(`clearPlate`),onCancel:()=>qe(null)}),Array.from(se.values()).map((e,t)=>(0,G.jsx)(Zse,{printerId:e.id,printerName:e.name,viewerIndex:t,onClose:()=>H(t=>{let n=new Map(t);return n.delete(e.id),n})},e.id))]})}function Dke({title:e,message:t,subtitle:n,closeText:r,variant:i=`error`,onClose:a}){let{t:o}=U(),s=r??o(`common.close`);return(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&a()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[a]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-[120]`,onClick:a,children:(0,G.jsx)(Pd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Id,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-dark ${i===`warning`?`text-yellow-600 dark:text-yellow-400`:`text-red-600 dark:text-red-400`}`,children:(0,G.jsx)(Iu,{className:`w-6 h-6`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-1`,children:e}),n&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2 truncate`,children:n}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm whitespace-pre-line break-words`,children:t})]})]}),(0,G.jsx)(`div`,{className:`flex mt-6`,children:(0,G.jsx)(Q,{onClick:a,className:`flex-1`,children:s})})]})})})}var MW=(0,y.createContext)(null),Oke=1500,kke=1e3,NW=e=>`slice-job-${e}`;function PW(e){try{return decodeURIComponent(e)}catch{return e}}function Ake(e){let t=Math.max(0,Math.floor(e));if(t<60)return`${t}s`;let n=Math.floor(t/60),r=t%60;return n<60?`${n}m ${r}s`:`${Math.floor(n/60)}h ${n%60}m`}function jke({children:e}){let{t}=U(),{showToast:n,showPersistentToast:r,dismissToast:i}=Hd(),a=co(),[o,s]=(0,y.useState)([]),[c,l]=(0,y.useState)(null),u=(0,y.useRef)([]);u.current=o;let d=(0,y.useRef)(new Map),f=(0,y.useRef)(new Map),p=(0,y.useRef)(new Map),m=(0,y.useRef)(new Set),h=(0,y.useCallback)(e=>{let n=d.current.get(e.id);if(n==null)return;let i=(Date.now()-n)/1e3,a=f.current.get(e.id)??`pending`,o=Ake(i),s=p.current.get(e.id)??null,c=s&&s.stage&&s.total_percent>0;if(a===`running`&&c){let n=PW(e.sourceName),i=s.stage,a=Math.min(100,Math.max(0,Math.round(s.total_percent))),c=typeof s.multi_plate_index==`number`&&typeof s.multi_plate_count==`number`&&s.multi_plate_count>1?t(`slice.runningWithProgressMultiPlate`,`Plate {{plateIndex}} of {{plateCount}} • {{name}} — {{stage}} ({{percent}}%) — {{elapsed}}`,{plateIndex:s.multi_plate_index,plateCount:s.multi_plate_count,name:n,stage:i,percent:a,elapsed:o}):t(`slice.runningWithProgress`,`{{name}} — {{stage}} ({{percent}}%) — {{elapsed}}`,{name:n,stage:i,percent:a,elapsed:o});r(NW(e.id),c,`loading`);return}let l=a===`pending`?`slice.queuedToast`:`slice.runningToast`,u=a===`pending`?`Queued: {{name}} — {{elapsed}}`:`Slicing {{name}} — {{elapsed}}`;r(NW(e.id),t(l,u,{name:PW(e.sourceName),elapsed:o}),`loading`)},[r,t]),g=(0,y.useCallback)((e,t,n)=>{s(r=>r.some(t=>t.id===e)?r:[...r,{id:e,kind:t,sourceName:n}]),m.current.delete(e),d.current.set(e,Date.now()),f.current.set(e,`pending`),p.current.set(e,null),h({id:e,kind:t,sourceName:n})},[h]),_=(0,y.useCallback)((e,r)=>{m.current.has(e.id)||(m.current.add(e.id),s(t=>t.filter(t=>t.id!==e.id)),d.current.delete(e.id),f.current.delete(e.id),p.current.delete(e.id),i(NW(e.id)),r.status===`completed`?(n(t(`slice.completedToast`,`Sliced {{name}}`,{name:PW(e.sourceName)}),`success`),r.result&&`external_write_fallback`in r.result&&r.result.external_write_fallback&&n(t(`slice.externalWriteFallbackToast`,`Saved to the internal library: the external folder could not be written to`),`warning`)):r.status===`failed`&&l({name:PW(e.sourceName),detail:r.error_detail||t(`slice.failed`)}),a.invalidateQueries({queryKey:[`library-files`]}),a.invalidateQueries({queryKey:[`archives`]}))},[i,a,n,t]);return(0,y.useEffect)(()=>{if(o.length===0)return;let e=!1,t=!1,n=setInterval(async()=>{if(!(e||t)){t=!0;try{let t=[...u.current];for(let n of t)try{let t=await Z.getSliceJob(n.id);if(e)return;f.current.set(n.id,t.status),t.progress&&p.current.set(n.id,t.progress),(t.status===`completed`||t.status===`failed`)&&_(n,t)}catch{}}finally{t=!1}}},Oke);return()=>{e=!0,clearInterval(n)}},[o.length,_]),(0,y.useEffect)(()=>{if(o.length===0)return;let e=setInterval(()=>{for(let e of u.current)h(e)},kke);return()=>clearInterval(e)},[o.length,h]),(0,G.jsxs)(MW.Provider,{value:{trackJob:g,activeJobs:o},children:[e,c&&(0,G.jsx)(Dke,{title:t(`slice.failedTitle`),subtitle:c.name,message:c.detail,onClose:()=>l(null)})]})}function FW(){let e=(0,y.useContext)(MW);if(!e)throw Error(`useSliceJobTracker must be used inside SliceJobTrackerProvider`);return e}var IW=1024;function Mke(){let[e,t]=(0,y.useState)(()=>typeof window<`u`?window.innerWidth>=IW:!1);return(0,y.useEffect)(()=>{let e=window.matchMedia(`(min-width: ${IW}px)`),n=e=>{t(e.matches)};return t(e.matches),e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}function LW({plates:e,onSelect:t,onClose:n}){let{t:r}=U();return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,onClick:n,children:(0,G.jsxs)(`div`,{className:`w-full max-w-3xl max-h-[85vh] flex flex-col rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary/60`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex-shrink-0 flex items-start justify-between gap-3 px-4 pt-4 pb-3 border-b border-bambu-dark-tertiary/40`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:r(`archives.platePicker.title`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`archives.platePicker.hint`)})]}),(0,G.jsx)(`button`,{onClick:n,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors`,"aria-label":r(`common.close`,`Close`),children:(0,G.jsx)(td,{className:`w-5 h-5`})})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:(0,G.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:e.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>t(e.index),className:`flex items-center gap-2 p-2 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray transition-colors text-left`,children:[e.has_thumbnail&&e.thumbnail_url!=null?(0,G.jsx)(`img`,{src:pd(e.thumbnail_url),alt:`Plate ${e.index}`,className:`w-12 h-12 rounded object-cover bg-bambu-dark-tertiary flex-shrink-0`}):(0,G.jsx)(`div`,{className:`w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center flex-shrink-0`,children:(0,G.jsx)(qc,{className:`w-5 h-5 text-bambu-gray`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:e.name?`${r(`archives.platePicker.plateLabel`,{index:e.index})} — ${e.name}`:r(`archives.platePicker.plateLabel`,{index:e.index})}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[e.objects.length>0?e.objects.slice(0,3).join(`, `)+(e.objects.length>3?`…`:``):e.object_count!=null&&e.object_count>0?r(`archives.platePicker.objectCount`,{count:e.object_count}):`${e.filaments.length} filament${e.filaments.length===1?``:`s`}`,e.print_time_seconds==null?``:` • ${np(e.print_time_seconds)}`]})]})]},e.index))})})]})})}var RW=e=>typeof e==`object`&&!!e&&`enumKey`in e,zW=`enum:`;function BW(e){if(typeof e==`number`)return e;if(typeof e==`boolean`)return+!!e;if(typeof e!=`string`)return;let t=Number.parseFloat(e);return Number.isFinite(t)?t:void 0}function VW(e){if(typeof e==`boolean`)return e;if(typeof e==`number`)return e!==0;if(e===`1`||e===`true`)return!0;if(e===`0`||e===`false`)return!1}function Nke(e,t){return{get:n=>{let r=e[n];if((r===void 0||r===``)&&(r=t[n]?.default),Array.isArray(r)&&(r=r[0]),typeof r==`boolean`||typeof r==`number`||typeof r==`string`)return r},has:e=>e in t}}var Pke=[`->`,`||`,`&&`,`==`,`!=`,`<=`,`>=`,`(`,`)`,`,`,`<`,`>`,`!`];function Fke(e){let t=[],n=0;for(;n0||W.vt_tray.length>0)&&r===`expanded`&&(()=>{let t=En.filter(e=>e.tray.length>1),n=En.filter(e=>e.tray.length===1),r=En.length>0&&W.vt_tray.length>0,g=!(r&&xe),_=e.nozzle_count===2||W?.temperatures?.nozzle_2!==void 0,v=AW[i]??1,y=e=>`${Math.round(e*v*1e3)/1e3}rem`,b=`3.5rem`,x={minWidth:b},S={minWidth:b,maxWidth:y(7.25)},C=e=>({gridTemplateColumns:`repeat(${e}, minmax(${b}, 1fr))`}),w=(W.state===`RUNNING`||W.state===`PAUSE`)&&Array.isArray(W.ams_mapping)?W.ams_mapping:[],T=e=>{let t=Math.max(1,e),n=`calc(${t} * ${b} + ${Math.max(0,t-1)} * 0.25rem + 1rem)`;return{flex:`1 1 ${n}`,minWidth:n}};return(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] uppercase tracking-wider text-bambu-gray font-medium`,children:F(`printers.filaments`)}),(0,G.jsx)(lke,{state:W.ams_filament_backup,onClick:()=>be(!0)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`}),r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(uke,{hidden:xe,onClick:Ce}),(0,G.jsx)(`div`,{className:`w-3 h-[2px] bg-bambu-dark-tertiary`})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[t.map(t=>{let n=pW(t.id,xn,wn,Cn);return(0,G.jsxs)(`div`,{style:T(4),className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex w-full min-h-7 items-center justify-between gap-2 rounded-lg bg-bambu-dark-secondary px-2 py-1`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,G.jsx)(OW,{ams:t,printerId:e.id,label:fp(t.id,t.tray.length),amsLabels:pn,canEdit:z(`printers:update`),onSaved:mn,children:(0,G.jsx)(`span`,{className:`block truncate text-[length:var(--pc-t10,10px)] text-white font-medium cursor-default select-none`,children:pn?.[t.id]||fp(t.id,t.tray.length)})}),n?.kind===`inlet`?(0,G.jsx)(fW,{inlet:n.inlet,title:F(`printers.amsSwitchInletTooltip`,{inlet:n.inlet,side:lp[n.inlet]})}):_&&n?.kind===`nozzle`?(0,G.jsx)(dW,{side:n.side}):null]}),(t.humidity!=null||t.temp!=null)&&(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[t.humidity!=null&&(0,G.jsx)(vW,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>Nt({amsId:t.id,amsLabel:fp(t.id,t.tray.length),mode:`humidity`}),compact:!0}),t.temp!=null&&(0,G.jsx)(`div`,{className:`mr-1`,children:(0,G.jsx)(yW,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>Nt({amsId:t.id,amsLabel:fp(t.id,t.tray.length),mode:`temperature`}),compact:!0})}),(W.supports_drying||W.drying_screen_only)&&(t.module_type===`n3f`||t.module_type===`n3s`)&&z(`printers:control`)&&(0,G.jsx)(`button`,{disabled:W.drying_screen_only||!!(t.dry_sf_reason?.length&&t.dry_time===0),onClick:e=>{t.dry_time>0?sr.mutate(t.id):Ze===t.id?Qe(null):yt(t,e.currentTarget)},className:`ml-1 flex items-center gap-0.5 px-1 py-0.5 rounded text-[length:var(--pc-t9,9px)] transition-colors ${t.dry_time>0?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:W.drying_screen_only||t.dry_sf_reason?.length?`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark/80`}`,title:W.drying_screen_only?F(`printers.drying.screenOnly`):t.dry_time>0?F(`printers.drying.stop`):t.dry_sf_reason?.length?F(QOe(t.dry_sf_reason)):F(`printers.drying.start`),children:(0,G.jsx)(mc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]})]}),t.dry_time>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-amber-50 dark:bg-amber-500/10 px-2 py-1 text-[length:var(--pc-t9,9px)]`,children:[(0,G.jsx)(mc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-amber-600 dark:text-amber-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400 font-medium`,children:F(`printers.drying.active`)}),t.dry_filament&&(0,G.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70`,children:t.dry_target_temp==null?t.dry_filament:F(`printers.drying.targetSummary`,{filament:t.dry_filament,temp:t.dry_target_temp})}),(0,G.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70`,children:F(`printers.drying.timeRemaining`,{time:t.dry_time>=60?`${Math.floor(t.dry_time/60)}h ${t.dry_time%60}m`:`${t.dry_time}m`})}),!W.drying_screen_only&&(0,G.jsx)(`button`,{onClick:()=>sr.mutate(t.id),disabled:sr.isPending,className:`ml-auto text-amber-700 dark:text-amber-400 hover:text-amber-900 dark:hover:text-amber-300 transition-colors disabled:opacity-50`,title:F(`printers.drying.stop`),children:(0,G.jsx)(td,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]}),(0,G.jsx)(`div`,{className:`grid w-full gap-1`,style:C(4),children:[0,1,2,3].map(n=>{let r=t.tray[n]||t.tray.find(e=>e.id===n),i=r?.tray_type&&r.remain>=0,a=!r?.tray_type,g=bW(r),_=t.id*4+n,v=An===_,y=jn!==null&&jn===_,b=Mn!==null&&Mn===_,S=r?.tray_info_idx?cn?.[r.tray_info_idx]:null,C=ln?.[_],T=(r?.tray_uuid||r?.tag_uid||Ap(e.serial_number,t.id,n))?.toUpperCase(),E=T?s?.[T]:void 0,D=Dp(E),O=o&&!m?p?.find(r=>r.printer_id===e.id&&r.ams_id===t.id&&r.tray_id===n):void 0,k=O?f?.find(e=>e.id===O.spoolman_spool_id):void 0,A=k&&(k.label_weight??0)>0?Math.round(Math.max(0,(k.label_weight??0)-k.weight_used)/(k.label_weight??1)*100):null,j=u?.(e.id,t.id,n),M=(()=>{let e=j?.spool;return e&&e.label_weight>0&&e.weight_used!=null?Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100):null})(),N=M===0&&i&&r.remain>0?null:M,P=D??A??N??(i?r.remain:null),I=D!==null||A!==null?`spoolman`:N===null?i?`ams`:void 0:`inventory`,L=r?.tray_type?{vendor:Bp(r)?`Bambu Lab`:`Generic`,profile:C?.preset_name||(k?[k.brand,k.slicer_filament_name?.split(`@`)[0].trim()||k.material].filter(Boolean).join(` `).trim():null)||j?.spool?.slicer_filament_name||S?.name||r.tray_sub_brands||r.tray_type,colorName:Sf(r.tray_color||``,r.tray_sub_brands),colorHex:r.tray_color||null,kFactor:lW(r.k),fillLevel:P,trayUuid:r.tray_uuid||null,tagUid:r.tag_uid||null,fillSource:I}:null,R=Ir?.amsId===t.id&&Ir?.slotId===n,B=w.indexOf(_),V=B>=0?`P${B+1}`:null,ee=(0,G.jsxs)(`div`,{className:`relative w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${a?`opacity-50`:``} ${y?`ring-2 ring-amber-400 ring-offset-1 ring-offset-bambu-dark animate-pulse`:b?`ring-2 ring-red-500/60 ring-offset-1 ring-offset-bambu-dark`:v?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[y&&(0,G.jsx)(`span`,{"aria-label":F(`printers.expectedSlot.ariaLabel`,{n:n+1}),title:F(`printers.expectedSlot.title`),className:`absolute top-0.5 left-0.5 px-1 py-px text-[length:var(--pc-t8,8px)] font-bold text-bambu-dark bg-amber-400 rounded pointer-events-none leading-none`,children:`↓`}),V&&(0,G.jsx)(`span`,{"aria-label":F(`printers.activeJobSlot.ariaLabel`,{n:B+1}),title:F(`printers.activeJobSlot.title`,{n:B+1}),className:`absolute top-0.5 right-0.5 px-1 py-px text-[length:var(--pc-t8,8px)] font-bold text-bambu-dark bg-bambu-green rounded pointer-events-none leading-none`,children:V}),(0,G.jsx)(oW,{trayColor:r?.tray_color,trayType:r?.tray_type,isEmpty:a,emptyKind:g,slotNumber:n+1}),(0,G.jsx)(`div`,{className:`text-[length:var(--pc-t9,9px)] text-white font-bold truncate`,children:r?.tray_type||F(g===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,G.jsx)(uW,{k:L?r?.k:null,reserve:Dn}),(0,G.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:P!==null&&P>=0&&!a&&r&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${P}%`,backgroundColor:Ep(P)}})})]});return(0,G.jsxs)(`div`,{className:`relative group w-full`,style:x,children:[R&&(0,G.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-tertiary/80 rounded flex items-center justify-center z-20`,children:(0,G.jsx)(Vl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] text-bambu-green animate-spin`})}),L?(0,G.jsx)(GH,{data:L,actions:_i({amsId:t.id,slotId:n,loadTrayId:t.id*4+n,isRefreshing:R}),spoolman:{enabled:o,linkedSpoolId:O?.spoolman_spool_id??(T?s?.[T]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!O&&!j?()=>{let r=(L.trayUuid||L.tagUid||Ap(e.serial_number,t.id,n)).toUpperCase();Lt({tagUid:L.tagUid||r,trayUuid:L.trayUuid||``,printerId:e.id,amsId:t.id,trayId:n})}:void 0,onUnlinkSpool:E?.id?()=>rr.mutate(E.id):void 0},inventory:(()=>{if(o){if(m)return;let i=O,a=k;return{assignedSpool:a?{id:a.id,material:a.material,subtype:a.subtype,brand:a.brand??null,color_name:a.color_name??null,remainingWeightGrams:a.label_weight?Math.max(0,Math.round(a.label_weight-a.weight_used)):void 0}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:n,trayInfo:{type:r?.tray_type||L.profile,material:r?.tray_type??void 0,profile:L.profile,color:L.colorHex||``,location:`${fp(t.id,t.tray.length)} Slot ${n+1}`}}),onUnassignSpool:a&&!Bp(r)?()=>h?.(a.id):void 0,isAssigned:!!i||Bp(r)}}let i=u?.(e.id,t.id,n);return{assignedSpool:i?.spool?{id:i.spool.id,material:i.spool.material,subtype:i.spool.subtype,brand:i.spool.brand,color_name:i.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(i.spool.label_weight-i.spool.weight_used))}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:n,trayInfo:{type:r?.tray_type||L.profile,material:r?.tray_type??void 0,profile:L.profile,color:L.colorHex||``,location:`${fp(t.id,t.tray.length)} Slot ${n+1}`}}),onUnassignSpool:i&&!Bp(r)?()=>d?.(e.id,t.id,n):void 0,isAssigned:!!i||Bp(r)}})(),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:t.id,trayId:n,trayCount:t.tray.length,trayType:r?.tray_type||void 0,trayColor:r?.tray_color||void 0,traySubBrands:r?.tray_sub_brands||void 0,trayInfoIdx:r?.tray_info_idx||void 0,extruderId:dp(t.id,r?.id??0,xn,wn),caliIdx:r?.cali_idx,savedPresetId:C?.preset_id})},children:ee}):(0,G.jsx)(KH,{kind:g??void 0,actions:_i({amsId:t.id,slotId:n,loadTrayId:t.id*4+n,isRefreshing:R}),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:t.id,trayId:n,trayCount:t.tray.length,extruderId:dp(t.id,r?.id??0,xn,wn)})},onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:n,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`${fp(t.id,t.tray.length)} Slot ${n+1}`}}),children:ee})]},n)})})]},t.id)}),n.map(t=>{let n=pW(t.id,xn,wn,Cn),r=t.tray[0],i=r?.tray_type&&r.remain>=0,g=!r?.tray_type,v=bW(r),x=Tp(t.id,r?.id??0,!1),C=An===x,T=jn!==null&&jn===x,E=Mn!==null&&Mn===x,D=r?.tray_info_idx?cn?.[r.tray_info_idx]:null,O=ln?.[x],k=r?.id??0,A=(r?.tray_uuid||r?.tag_uid||Ap(e.serial_number,t.id,k))?.toUpperCase(),j=A?s?.[A]:void 0,M=Dp(j),N=u?.(e.id,t.id,k),P=(()=>{let e=N?.spool;return e&&e.label_weight>0&&e.weight_used!=null?Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100):null})(),I=P===0&&i&&r.remain>0?null:P,L=o&&!m?p?.find(n=>n.printer_id===e.id&&n.ams_id===t.id&&n.tray_id===k):void 0,R=L?f?.find(e=>e.id===L.spoolman_spool_id):void 0,B=R&&(R.label_weight??0)>0?Math.round(Math.max(0,(R.label_weight??0)-R.weight_used)/(R.label_weight??1)*100):null,V=M??B??I??(i?r.remain:null),ee=M!==null||B!==null?`spoolman`:I===null?i?`ams`:void 0:`inventory`,te=r?.tray_type?{vendor:Bp(r)?`Bambu Lab`:`Generic`,profile:O?.preset_name||(R?[R.brand,R.slicer_filament_name?.split(`@`)[0].trim()||R.material].filter(Boolean).join(` `).trim():null)||N?.spool?.slicer_filament_name||D?.name||r.tray_sub_brands||r.tray_type,colorName:Sf(r.tray_color||``,r.tray_sub_brands),colorHex:r.tray_color||null,kFactor:lW(r.k),fillLevel:V,trayUuid:r.tray_uuid||null,tagUid:r.tag_uid||null,fillSource:ee}:null,ne=Ir?.amsId===t.id&&Ir?.slotId===k,re=w.indexOf(x),ie=re>=0?`P${re+1}`:null,ae=(0,G.jsxs)(`div`,{className:`relative w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${g?`opacity-50`:``} ${T?`ring-2 ring-amber-400 ring-offset-1 ring-offset-bambu-dark animate-pulse`:E?`ring-2 ring-red-500/60 ring-offset-1 ring-offset-bambu-dark`:C?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[T&&(0,G.jsx)(`span`,{"aria-label":F(`printers.expectedSlot.ariaLabel`,{n:1}),title:F(`printers.expectedSlot.title`),className:`absolute top-0.5 left-0.5 px-1 py-px text-[length:var(--pc-t8,8px)] font-bold text-bambu-dark bg-amber-400 rounded pointer-events-none leading-none`,children:`↓`}),ie&&(0,G.jsx)(`span`,{"aria-label":F(`printers.activeJobSlot.ariaLabel`,{n:re+1}),title:F(`printers.activeJobSlot.title`,{n:re+1}),className:`absolute top-0.5 right-0.5 px-1 py-px text-[length:var(--pc-t8,8px)] font-bold text-bambu-dark bg-bambu-green rounded pointer-events-none leading-none`,children:ie}),(0,G.jsx)(oW,{trayColor:r?.tray_color,trayType:r?.tray_type,isEmpty:g,emptyKind:v,slotNumber:1}),(0,G.jsx)(`div`,{className:`text-[length:var(--pc-t9,9px)] text-white font-bold truncate`,children:r?.tray_type||F(v===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,G.jsx)(uW,{k:te?r?.k:null,reserve:Dn}),(0,G.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:V!==null&&V>=0&&!g&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${V}%`,backgroundColor:Ep(V)}})})]}),oe=y(11);return(0,G.jsxs)(`div`,{style:{flex:`1 1 ${oe}`,minWidth:oe,maxWidth:`calc(4 * ${b} + 3 * 0.25rem + 1rem)`},className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex w-full min-h-7 items-center gap-1.5 rounded-lg bg-bambu-dark-secondary px-2 py-1`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,G.jsx)(OW,{ams:t,printerId:e.id,label:fp(t.id,t.tray.length),amsLabels:pn,canEdit:z(`printers:update`),onSaved:mn,children:(0,G.jsx)(`span`,{className:`block truncate text-[length:var(--pc-t10,10px)] text-white font-medium cursor-default select-none`,children:pn?.[t.id]||fp(t.id,t.tray.length)})}),n?.kind===`inlet`?(0,G.jsx)(fW,{inlet:n.inlet,title:F(`printers.amsSwitchInletTooltip`,{inlet:n.inlet,side:lp[n.inlet]})}):_&&n?.kind===`nozzle`?(0,G.jsx)(dW,{side:n.side}):null]}),(W.supports_drying||W.drying_screen_only)&&(t.module_type===`n3f`||t.module_type===`n3s`)&&z(`printers:control`)&&(0,G.jsx)(`div`,{className:`relative ml-auto`,children:(0,G.jsx)(`button`,{disabled:W.drying_screen_only,onClick:e=>{t.dry_time>0?sr.mutate(t.id):Ze===t.id?Qe(null):yt(t,e.currentTarget)},className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[length:var(--pc-t9,9px)] transition-colors ${t.dry_time>0?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:W.drying_screen_only?`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark/80`}`,title:W.drying_screen_only?F(`printers.drying.screenOnly`):t.dry_time>0?F(`printers.drying.stop`):F(`printers.drying.start`),children:(0,G.jsx)(mc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})})]}),t.dry_time>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 overflow-hidden whitespace-nowrap rounded-lg bg-amber-50 dark:bg-amber-500/10 px-2 py-1 text-[length:var(--pc-t9,9px)]`,children:[(0,G.jsx)(mc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-amber-600 dark:text-amber-400 shrink-0`}),t.dry_filament&&(0,G.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70 text-[length:var(--pc-t8,8px)] truncate`,children:t.dry_target_temp==null?t.dry_filament:F(`printers.drying.targetSummary`,{filament:t.dry_filament,temp:t.dry_target_temp})}),(0,G.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70 text-[length:var(--pc-t8,8px)] truncate`,children:t.dry_time>=60?`${Math.floor(t.dry_time/60)}h ${t.dry_time%60}m`:`${t.dry_time}m`}),!W.drying_screen_only&&(0,G.jsx)(`button`,{onClick:()=>sr.mutate(t.id),disabled:sr.isPending,className:`ml-auto text-amber-700 dark:text-amber-400 hover:text-amber-900 dark:hover:text-amber-300 transition-colors disabled:opacity-50 shrink-0`,title:F(`printers.drying.stop`),children:(0,G.jsx)(td,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-1.5 max-[550px]:flex-col max-[550px]:items-start`,children:[(0,G.jsxs)(`div`,{className:`relative group flex-1`,style:S,children:[ne&&(0,G.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-tertiary/80 rounded flex items-center justify-center z-20`,children:(0,G.jsx)(Vl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] text-bambu-green animate-spin`})}),te?(0,G.jsx)(GH,{data:te,actions:_i({amsId:t.id,slotId:k,loadTrayId:t.id*4+k,isRefreshing:ne}),spoolman:{enabled:o,linkedSpoolId:L?.spoolman_spool_id??(A?s?.[A]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!L&&!N?()=>{let n=(te.trayUuid||te.tagUid||Ap(e.serial_number,t.id,k)).toUpperCase();Lt({tagUid:te.tagUid||n,trayUuid:te.trayUuid||``,printerId:e.id,amsId:t.id,trayId:k})}:void 0,onUnlinkSpool:j?.id?()=>rr.mutate(j.id):void 0},inventory:(()=>{if(o){if(m)return;let n=L,i=R;return{assignedSpool:i?{id:i.id,material:i.material,subtype:i.subtype,brand:i.brand??null,color_name:i.color_name??null,remainingWeightGrams:i.label_weight?Math.max(0,Math.round(i.label_weight-i.weight_used)):void 0}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:k,trayInfo:{type:r?.tray_type||te.profile,material:r?.tray_type??void 0,profile:te.profile,color:te.colorHex||``,location:fp(t.id,t.tray.length)}}),onUnassignSpool:i&&!Bp(r)?()=>h?.(i.id):void 0,isAssigned:!!n||Bp(r)}}let n=u?.(e.id,t.id,k);return{assignedSpool:n?.spool?{id:n.spool.id,material:n.spool.material,subtype:n.spool.subtype,brand:n.spool.brand,color_name:n.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(n.spool.label_weight-n.spool.weight_used))}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:k,trayInfo:{type:r?.tray_type||te.profile,material:r?.tray_type??void 0,profile:te.profile,color:te.colorHex||``,location:fp(t.id,t.tray.length)}}),onUnassignSpool:n&&!Bp(r)?()=>d?.(e.id,t.id,k):void 0,isAssigned:!!n||Bp(r)}})(),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:t.id,trayId:k,trayCount:t.tray.length,trayType:r?.tray_type||void 0,trayColor:r?.tray_color||void 0,traySubBrands:r?.tray_sub_brands||void 0,trayInfoIdx:r?.tray_info_idx||void 0,extruderId:dp(t.id,r?.id??0,xn,wn),caliIdx:r?.cali_idx,savedPresetId:O?.preset_id})},children:ae}):(0,G.jsx)(KH,{kind:v??void 0,actions:_i({amsId:t.id,slotId:k,loadTrayId:t.id*4+k,isRefreshing:ne}),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:t.id,trayId:k,trayCount:t.tray.length,extruderId:dp(t.id,r?.id??0,xn,wn)})},onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:k,trayInfo:{type:``,material:void 0,profile:``,color:``,location:fp(t.id,t.tray.length)}}),children:ae})]}),(t.humidity!=null||t.temp!=null)&&(0,G.jsxs)(`div`,{className:`flex flex-col justify-center gap-1 shrink-0 max-[550px]:w-full`,children:[t.temp!=null&&(0,G.jsx)(yW,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>Nt({amsId:t.id,amsLabel:fp(t.id,t.tray.length),mode:`temperature`}),compact:!0}),t.humidity!=null&&(0,G.jsx)(vW,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>Nt({amsId:t.id,amsLabel:fp(t.id,t.tray.length),mode:`humidity`}),compact:!0})]})]})]},t.id)}),W.vt_tray.length>0&&g&&(0,G.jsxs)(`div`,{style:T(W.vt_tray.length),className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,G.jsx)(`div`,{className:`flex w-full min-h-7 items-center gap-1.5 rounded-lg bg-bambu-dark-secondary px-2 py-1`,children:(0,G.jsx)(`span`,{className:`block min-w-0 flex-1 truncate text-[length:var(--pc-t10,10px)] text-white font-medium`,children:F(`printers.external`)})}),(0,G.jsx)(`div`,{className:`grid w-full gap-1`,style:C(W.vt_tray.length>1?2:1),children:[...W.vt_tray].sort((e,t)=>(e.id??254)-(t.id??254)).map(t=>{let n=t.id??254,r=_&&An===254?n===254&&W.active_extruder===1||n===255&&W.active_extruder===0:An===n,i=n-254,a=_?F(n===254?`printers.extL`:`printers.extR`):``,g=t.tray_info_idx?cn?.[t.tray_info_idx]:null,v=ln?.[1020+i],y=(t.tray_uuid||t.tag_uid||Ap(e.serial_number,255,i))?.toUpperCase(),b=y?s?.[y]:void 0,S=Dp(b),C=u?.(e.id,255,i),w=(()=>{let e=C?.spool;return e&&e.label_weight>0&&e.weight_used!=null?Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100):null})(),T=t.tray_type&&t.remain>=0,E=w===0&&T&&t.remain>0?null:w,D=o&&!m?p?.find(t=>t.printer_id===e.id&&t.ams_id===255&&t.tray_id===i):void 0,O=D?f?.find(e=>e.id===D.spoolman_spool_id):void 0,k=O&&(O.label_weight??0)>0?Math.round(Math.max(0,(O.label_weight??0)-O.weight_used)/(O.label_weight??1)*100):null,A=S??k??E??(T?t.remain:null),j=S!==null||k!==null?`spoolman`:E===null?T?`ams`:void 0:`inventory`,M={vendor:Bp(t)?`Bambu Lab`:`Generic`,profile:v?.preset_name||(O?[O.brand,O.slicer_filament_name?.split(`@`)[0].trim()||O.material].filter(Boolean).join(` `).trim():null)||C?.spool?.slicer_filament_name||g?.name||t.tray_sub_brands||t.tray_type||`Unknown`,colorName:Sf(t.tray_color||``,t.tray_sub_brands),colorHex:t.tray_color||null,kFactor:lW(t.k),fillLevel:A,trayUuid:t.tray_uuid||null,tagUid:t.tag_uid||null,fillSource:j},N=!t.tray_type,P=bW(t),I=(0,G.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${N?`opacity-50`:``} ${r?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[(0,G.jsx)(oW,{trayColor:t.tray_color,trayType:t.tray_type,isEmpty:N,emptyKind:P,slotNumber:_?n===254?`L`:`R`:i+1}),(0,G.jsx)(`div`,{className:`text-[length:var(--pc-t9,9px)] font-bold truncate ${N?`text-white/40`:`text-white`}`,children:t.tray_type||F(`ams.slotEmpty`)}),(0,G.jsx)(uW,{k:N?null:t.k,reserve:Dn}),(0,G.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:A!==null&&A>=0&&!N&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${A}%`,backgroundColor:Ep(A)}})})]});return(0,G.jsx)(`div`,{className:`relative group w-full`,style:x,children:N?(0,G.jsx)(KH,{kind:P??void 0,actions:_i({amsId:255,slotId:i,loadTrayId:n,includeRfid:!1}),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:255,trayId:i,trayCount:1,extruderId:_?+(n===254):void 0})},onAssignSpool:()=>zt({printerId:e.id,amsId:255,trayId:i,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`External Slot ${i+1}`}}),children:I}):(0,G.jsx)(GH,{data:M,actions:_i({amsId:255,slotId:i,loadTrayId:n,includeRfid:!1}),spoolman:{enabled:o,linkedSpoolId:D?.spoolman_spool_id??(y?s?.[y]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!D&&!C?()=>{let t=(M.trayUuid||M.tagUid||Ap(e.serial_number,255,i)).toUpperCase();Lt({tagUid:M.tagUid||t,trayUuid:M.trayUuid||``,printerId:e.id,amsId:255,trayId:i})}:void 0,onUnlinkSpool:b?.id?()=>rr.mutate(b.id):void 0},inventory:(()=>{if(o){if(m)return;let n=D,r=O;return{assignedSpool:r?{id:r.id,material:r.material,subtype:r.subtype,brand:r.brand??null,color_name:r.color_name??null,remainingWeightGrams:r.label_weight?Math.max(0,Math.round(r.label_weight-r.weight_used)):void 0}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:255,trayId:i,trayInfo:{type:t.tray_type||M.profile,material:t.tray_type??void 0,profile:M.profile,color:M.colorHex||``,location:a||F(`printers.external`)}}),onUnassignSpool:r&&!Bp(t)?()=>h?.(r.id):void 0,isAssigned:!!n||Bp(t)}}let n=u?.(e.id,255,i);return{assignedSpool:n?.spool?{id:n.spool.id,material:n.spool.material,subtype:n.spool.subtype,brand:n.spool.brand,color_name:n.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(n.spool.label_weight-n.spool.weight_used))}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:255,trayId:i,trayInfo:{type:t.tray_type||M.profile,material:t.tray_type??void 0,profile:M.profile,color:M.colorHex||``,location:a||F(`printers.external`)}}),onUnassignSpool:n&&!Bp(t)?()=>d?.(e.id,255,i):void 0,isAssigned:!!n||Bp(t)}})(),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:255,trayId:i,trayCount:1,trayType:t.tray_type||void 0,trayColor:t.tray_color||void 0,traySubBrands:t.tray_sub_brands||void 0,trayInfoIdx:t.tray_info_idx||void 0,extruderId:_?+(n===254):void 0,caliIdx:t.cali_idx,savedPresetId:v?.preset_id})},children:I})},n)})})]})]})]})})()]}),e.is_active!==!1&&!W?.connected&&r===`expanded`&&qn&&gr,r===`expanded`&&(0,G.jsxs)(`div`,{className:`mt-auto`,children:[Fn&&(0,G.jsxs)(`div`,{className:`pt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] uppercase tracking-wider text-bambu-gray font-medium`,children:F(`printers.power`,`Power`)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 rounded-[10px] bg-bambu-dark p-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 pl-1`,children:[(0,G.jsx)(rd,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm text-white truncate`,children:Fn.name}),(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray text-[length:var(--pc-t10,10px)] font-medium flex-shrink-0`,title:F(`smartPlugs.power`),children:Ln?.energy?.power!==null&&Ln?.energy?.power!==void 0?`${Math.round(Ln.energy.power)}W`:`--`})]}),(0,G.jsx)(`div`,{className:`flex-1`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`button`,{onClick:()=>ur.mutate(!Fn.auto_off),disabled:ur.isPending||Fn.auto_off_executed||!z(`smart_plugs:control`),title:z(`smart_plugs:control`)?Fn.auto_off_executed?F(`printers.autoOffExecuted`):F(`printers.autoOffAfterPrint`):F(`printers.permission.noSmartPlugControl`),className:`flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg text-xs font-bold transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${z(`smart_plugs:control`)?Fn.auto_off||Fn.auto_off_executed?`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary/80`:`bg-bambu-dark-tertiary/50 text-bambu-gray/50`}`,children:(0,G.jsx)(As,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`button`,{onClick:()=>{Ln?.state===`ON`?fe(!0):ue(!0)},disabled:lr.isPending||!z(`smart_plugs:control`),className:`flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg text-xs transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${z(`smart_plugs:control`)?Ln?.state===`ON`?`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary/80`:`bg-bambu-dark-tertiary/50 text-bambu-gray/50`}`,title:z(`smart_plugs:control`)?Ln?.state===`ON`?`Turn off`:`Turn on`:F(`printers.permission.noSmartPlugControl`),children:(0,G.jsx)(rd,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})})]})]}),In&&In.length>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,G.jsx)(zc,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] text-blue-600 dark:text-blue-400 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`HA:`}),(0,G.jsx)(`div`,{className:`h-[2px] w-5 bg-bambu-dark-tertiary/50`}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:In.map(e=>{let t=e.ha_entity_id?.startsWith(`script.`);return(0,G.jsxs)(`button`,{onClick:()=>{t?dr.mutate({id:e.id,action:`on`}):me(e)},disabled:dr.isPending,title:`${t?`Run`:`Toggle`} ${e.ha_entity_id}`,className:`px-2 py-0.5 text-xs bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 hover:bg-blue-500/30 rounded transition-colors flex items-center gap-1`,children:[(0,G.jsx)(Ml,{className:`w-[var(--pc-i25,0.625rem)] h-[var(--pc-i25,0.625rem)]`}),e.name]},e.id)})})]})]}),(0,G.jsx)(lce,{printerId:e.id}),(0,G.jsxs)(`div`,{className:`pt-4`,children:[(0,G.jsx)(`div`,{className:`mb-3 h-[2px] bg-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[vi,(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[(0,G.jsxs)(`div`,{className:`flex items-center flex-shrink-0`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>hi(_),disabled:!W?.connected||!z(`camera:view`),title:z(`camera:view`)?F(_===`embedded`?`printers.openCameraOverlay`:`printers.openCameraWindow`):F(`printers.permission.noCamera`),className:`${mi} !rounded-r-none`,children:(0,G.jsx)(Wu,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();At({x:t.left,y:t.bottom+4})},disabled:!W?.connected||!z(`camera:view`),title:z(`camera:view`)?F(`settings.cameraViewMode`):F(`printers.permission.noCamera`),"aria-label":F(`settings.cameraViewMode`),className:`!h-8 !min-h-8 !w-6 !px-0 !py-0 !rounded-l-none border-l border-bambu-dark`,children:(0,G.jsx)(fs,{className:`w-3 h-3`})})]}),kt&&(0,G.jsx)(_T,{x:kt.x,y:kt.y,items:gi,onClose:()=>At(null)}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>se(!0),disabled:!z(`printers:files`),title:z(`printers:files`)?F(`printers.browseFiles`):F(`printers.permission.noFiles`),className:mi,children:(0,G.jsx)(Nc,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>Ue(!0),disabled:!z(`library:upload`)||!z(`queue:create`),title:z(`library:upload`)?z(`queue:create`)?F(`common.print`):F(`fileManager.noPermissionAddToQueue`):F(`fileManager.noPermissionUpload`),className:`!h-8 !min-h-8 !px-2 !py-0 !bg-bambu-green hover:!bg-bambu-green/80 !text-white`,children:[(0,G.jsx)(Ll,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`common.print`)]})]})]})]})]}),(0,G.jsx)(bke,{printerId:e.id,dryingActive:En.some(e=>(e.dry_time??0)>0),timeFormat:g})]}),oe&&(0,G.jsx)(Use,{printerId:e.id,printerName:e.name,onClose:()=>se(!1)}),He&&(0,G.jsx)(IU,{folderId:null,onClose:()=>Ue(!1),onUploadComplete:()=>{},autoUpload:!0,accept:`.gcode,.3mf`,validateFile:e=>{let t=e.name.toLowerCase();if(!t.endsWith(`.gcode`)&&!t.includes(`.gcode.`))return F(`printers.dropNotPrintable`,`Only .gcode and .gcode.3mf files can be printed`)},onFileUploaded:t=>{let n=t.metadata?.sliced_for_model,r=DW(e.model);if(n&&r&&n.toLowerCase()!==r.toLowerCase())return Z.deleteLibraryFile(t.id).catch(()=>{}),F(`printers.incompatibleFile`,`This file was sliced for {{slicedFor}}, but this printer is a {{printerModel}}`,{slicedFor:n,printerModel:r});Xe({id:t.id,filename:t.filename})}}),Ye&&(0,G.jsx)(iW,{mode:`create`,libraryFileId:Ye.id,archiveName:Ye.filename,initialSelectedPrinterIds:[e.id],onClose:()=>Xe(null),onSuccess:()=>Xe(null),cleanupLibraryAfterDispatch:!0}),H&&(0,G.jsx)(ice,{printerId:e.id,printerName:e.name,onClose:()=>ce(!1)}),Ke&&(0,G.jsx)(Wp,{printerId:e.id,printerName:e.name,onClose:()=>qe(!1)}),We&&(0,G.jsx)(GOe,{printer:e,status:W,totalPrintHours:n?.total_print_hours,onClose:Je}),Wt&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:()=>Zr(),children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-w-lg w-full`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[Wt.needs_calibration?(0,G.jsx)(Yl,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-blue-500`}):Wt.is_empty?(0,G.jsx)(bs,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-green-500`}):(0,G.jsx)(Es,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-yellow-500`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:`Build Plate Check`}),Wt.reference_count!==void 0&&Wt.max_references&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[Wt.reference_count,`/`,Wt.max_references,` refs`]})]}),(0,G.jsx)(`button`,{onClick:()=>Zr(),className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(td,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)]`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[Wt.needs_calibration?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`p-3 rounded-lg bg-blue-100 dark:bg-blue-500/20 border border-blue-300 dark:border-blue-500/50`,children:[(0,G.jsx)(`p`,{className:`font-medium text-blue-700 dark:text-blue-400`,children:F(`printers.plateDetection.calibrationRequired`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,dangerouslySetInnerHTML:{__html:F(`printers.plateDetection.calibrationInstructions`)}})]}),(0,G.jsxs)(`div`,{className:`text-sm text-bambu-gray space-y-2`,children:[(0,G.jsx)(`p`,{children:F(`printers.plateDetection.calibrationDescription`)}),(0,G.jsx)(`p`,{dangerouslySetInnerHTML:{__html:F(`printers.plateDetection.calibrationTip`)}})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`p-3 rounded-lg ${Wt.is_empty?`bg-green-100 dark:bg-green-500/20 border border-green-300 dark:border-green-500/50`:`bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-300 dark:border-yellow-500/50`}`,children:[(0,G.jsx)(`p`,{className:`font-medium ${Wt.is_empty?`text-green-700 dark:text-green-400`:`text-yellow-700 dark:text-yellow-400`}`,children:Wt.is_empty?F(`printers.plateDetection.plateEmpty`):F(`printers.plateDetection.objectsDetected`)}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:[F(`printers.plateDetection.confidence`),`: `,Math.round(Wt.confidence*100),`% | `,F(`printers.plateDetection.difference`),`: `,Wt.difference_percent.toFixed(1),`%`]})]}),Wt.debug_image_url&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:F(`printers.plateDetection.analysisPreview`)}),(0,G.jsx)(`img`,{src:Wt.debug_image_url,alt:F(`printers.plateDetection.analysisPreview`),className:`w-full rounded-lg border border-bambu-dark-tertiary`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:F(`printers.plateDetection.analysisLegend`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:Wt.message})]}),Wr&&Wr.references.length>0&&(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white shrink-0`,children:F(`printers.plateDetection.savedReferences`,{count:Wr.references.length,max:Wr.max_references})}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-5 gap-2`,children:Wr.references.map(t=>(0,G.jsxs)(`div`,{className:`relative group`,children:[(0,G.jsx)(`img`,{src:Z.getPlateReferenceThumbnailUrl(e.id,t.index),alt:t.label||`Reference ${t.index+1}`,className:`w-full aspect-video object-cover rounded border border-bambu-dark-tertiary`}),(0,G.jsx)(`button`,{onClick:()=>ei(t.index),className:`absolute top-1 right-1 p-0.5 bg-red-500/80 rounded can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity`,title:F(`printers.plateDetection.deleteReference`),children:(0,G.jsx)(td,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-white`})}),Kr?.index===t.index?(0,G.jsx)(`input`,{type:`text`,value:Kr.label,onChange:e=>qr({...Kr,label:e.target.value}),onBlur:()=>$r(t.index,Kr.label),onKeyDown:e=>{e.key===`Enter`&&$r(t.index,Kr.label),e.key===`Escape`&&qr(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:F(`printers.plateDetection.labelPlaceholder`)}):(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1 truncate cursor-pointer hover:text-white`,onClick:()=>qr({index:t.index,label:t.label}),title:t.label?F(`printers.plateDetection.clickToEdit`,{label:t.label}):F(`printers.plateDetection.clickToAddLabel`),children:t.label||(0,G.jsx)(`span`,{className:`italic opacity-50`,children:F(`printers.noLabel`)})}),(0,G.jsx)(`p`,{className:`text-[length:var(--pc-t10,10px)] text-bambu-gray/60`,children:t.timestamp?Xf(t.timestamp)?.toLocaleDateString()??``:``})]},t.index))})]}),!Wt.needs_calibration&&(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white shrink-0`,children:F(`printers.roi.title`)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),Xt?(0,G.jsxs)(`div`,{className:`flex gap-1`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>Zt(null),disabled:Qt,children:F(`common.cancel`)}),(0,G.jsx)(Q,{size:`sm`,onClick:ti,disabled:Qt,children:Qt?(0,G.jsx)(Y,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] animate-spin`}):F(`common.save`)})]}):(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>Zt(Wt.roi||{x:.15,y:.35,w:.7,h:.55}),children:[(0,G.jsx)(kl,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] mr-1`}),F(`common.edit`)]})]}),Xt?(0,G.jsxs)(`div`,{className:`space-y-3 bg-bambu-dark-tertiary/50 p-3 rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:F(`printers.roi.xStart`)}),(0,G.jsx)(`input`,{type:`range`,min:`0`,max:`0.9`,step:`0.01`,value:Xt.x,onChange:e=>Zt({...Xt,x:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Xt.x*100),`%`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:F(`printers.roi.yStart`)}),(0,G.jsx)(`input`,{type:`range`,min:`0`,max:`0.9`,step:`0.01`,value:Xt.y,onChange:e=>Zt({...Xt,y:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Xt.y*100),`%`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:F(`printers.width`)}),(0,G.jsx)(`input`,{type:`range`,min:`0.1`,max:`1`,step:`0.01`,value:Xt.w,onChange:e=>Zt({...Xt,w:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Xt.w*100),`%`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:F(`printers.height`)}),(0,G.jsx)(`input`,{type:`range`,min:`0.1`,max:`1`,step:`0.01`,value:Xt.h,onChange:e=>Zt({...Xt,h:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Xt.h*100),`%`]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:F(`printers.roi.instruction`)})]}):(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[`Current: X=`,Math.round((Wt.roi?.x||.15)*100),`%, Y=`,Math.round((Wt.roi?.y||.35)*100),`%, W=`,Math.round((Wt.roi?.w||.7)*100),`%, H=`,Math.round((Wt.roi?.h||.55)*100),`%`]})]})]}),(0,G.jsx)(`div`,{className:`flex justify-end gap-2 p-4`,children:Wt.needs_calibration?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>Zr(),children:F(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>Qr(),disabled:Jt,children:Jt?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] mr-2 animate-spin`}),`Calibrating...`]}):`Calibrate Empty Plate`})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>Qr(),disabled:Jt,children:Jt?`Adding...`:`Add Reference (${Wr?.references.length||0}/${Wr?.max_references||5})`}),(0,G.jsx)(Q,{onClick:()=>Zr(),children:`Close`})]})})]})}),le&&Fn&&(0,G.jsx)(ef,{title:F(`printers.confirm.powerOnTitle`),message:F(`printers.confirm.powerOnMessage`,{name:e.name}),confirmText:F(`printers.confirm.powerOnButton`),variant:`default`,onConfirm:()=>{lr.mutate(`on`),ue(!1)},onCancel:()=>ue(!1)}),jr&&(0,G.jsx)(ef,{title:F(`printers.maintenance.confirmMidPrintTitle`),message:F(`printers.maintenance.confirmMidPrintMessage`,{name:e.name}),confirmText:F(`printers.maintenance.menuEnter`),variant:`danger`,onConfirm:()=>{Ar.mutate(!1),Mr(!1)},onCancel:()=>Mr(!1)}),de&&Fn&&(0,G.jsx)(ef,{title:F(`printers.confirm.powerOffTitle`),message:W?.state===`RUNNING`?F(`printers.confirm.powerOffWarning`,{name:e.name}):F(`printers.confirm.powerOffMessage`,{name:e.name}),confirmText:F(`printers.confirm.powerOffButton`),variant:`danger`,onConfirm:()=>{lr.mutate(`off`),fe(!1)},onCancel:()=>fe(!1)}),pe&&(0,G.jsx)(ef,{title:F(`printers.confirm.haToggleTitle`,{name:pe.name}),message:W?.state===`RUNNING`?F(`printers.confirm.haToggleWarning`,{name:e.name,entity:pe.ha_entity_id||pe.name}):F(`printers.confirm.haToggleMessage`,{entity:pe.ha_entity_id||pe.name}),confirmText:F(`printers.confirm.haToggleButton`),variant:W?.state===`RUNNING`?`danger`:`default`,onConfirm:()=>{dr.mutate({id:pe.id,action:`toggle`}),me(null)},onCancel:()=>me(null)}),we&&(0,G.jsx)(ef,{title:F(`printers.confirm.stopTitle`),message:F(`printers.confirm.stopMessage`,{name:e.name}),confirmText:F(`printers.confirm.stopButton`),variant:`danger`,onConfirm:()=>{fr.mutate(),Te(!1)},onCancel:()=>Te(!1)}),Ee&&(0,G.jsx)(ef,{title:F(`printers.confirm.pauseTitle`),message:F(`printers.confirm.pauseMessage`,{name:e.name}),confirmText:F(`printers.confirm.pauseButton`),variant:`default`,onConfirm:()=>{pr.mutate(),De(!1)},onCancel:()=>De(!1)}),Re&&(0,G.jsx)(ef,{title:F(`printers.confirm.resumeTitle`),message:F(`printers.confirm.resumeMessage`,{name:e.name}),confirmText:F(`printers.confirm.resumeButton`),variant:`default`,onConfirm:()=>{mr.mutate(),ze(!1)},onCancel:()=>ze(!1)}),(0,G.jsx)(cT,{printerId:e.id,isOpen:Be,onClose:()=>Ve(!1)}),he&&(0,G.jsx)(jee,{printerName:e.name,errors:W?.hms_errors||[],onClose:()=>ge(!1),printerId:e.id,hasPermission:z,runoutGuidance:Pn}),_e&&(0,G.jsx)(ace,{printerName:e.name,detection:N,lastError:P,onClose:()=>ve(!1)}),ye&&W&&(0,G.jsx)(iOe,{isOpen:ye,state:W.ams_filament_backup,amsUnits:W.ams,amsExtruderMap:W.ams_extruder_map,isDualNozzle:e.nozzle_count===2||W?.temperatures?.nozzle_2!==void 0,canToggle:z(`printers:control`),pending:cr.isPending,onToggle:e=>cr.mutate(e),onClose:()=>be(!1)}),Mt&&(0,G.jsx)(eOe,{isOpen:!!Mt,onClose:()=>Nt(null),printerId:e.id,printerName:e.name,amsId:Mt.amsId,amsLabel:Mt.amsLabel,initialMode:Mt.mode,thresholds:a}),Pt&&(0,G.jsx)(oOe,{isOpen:!!Pt,onClose:()=>Ft(null),printerId:e.id,printerName:e.name,initialKind:Pt.initialKind,availableKinds:Pt.availableKinds}),It&&(0,G.jsx)(qH,{isOpen:!!It,onClose:()=>Lt(null),tagUid:It.tagUid,trayUuid:It.trayUuid,printerId:It.printerId,amsId:It.amsId,trayId:It.trayId}),Rt&&(0,G.jsx)(YH,{isOpen:!!Rt,onClose:()=>zt(null),printerId:Rt.printerId,amsId:Rt.amsId,trayId:Rt.trayId,trayInfo:Rt.trayInfo,spoolmanEnabled:!!o}),Bt&&(0,G.jsx)(PU,{isOpen:!!Bt,onClose:()=>Vt(null),printerId:e.id,slotInfo:Bt,printerModel:DW(e.model)||void 0,nozzleDiameter:zp(W,Bt.amsId),onSuccess:()=>{I.invalidateQueries({queryKey:[`slotPresets`,e.id]}),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})}}),ie&&(0,G.jsx)(Cke,{printer:e,onClose:()=>ae(!1)}),Ht&&nn&&(0,G.jsx)(Ske,{printer:e,firmwareInfo:nn,onClose:()=>Ut(!1)}),Ze!==null&&ht&&(()=>{let e=$e===`n3s`?85:65,t=e+10;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-[100]`,"data-testid":`drying-popover-backdrop`,onMouseDown:()=>{xt.current=bt.current!==null&&document.activeElement===bt.current},onClick:()=>{if(xt.current){xt.current=!1;return}Qe(null)}}),(0,G.jsxs)(`div`,{className:`fixed z-[101] flex flex-col w-[240px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl overflow-hidden`,style:{left:ht.left,...ht.placement===`above`?{bottom:`calc(100dvh - ${ht.anchorY}px)`,maxHeight:`${ht.anchorY-8}px`}:{top:ht.top,maxHeight:`calc(100dvh - ${ht.top}px - 8px)`}},onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`shrink-0 flex items-center justify-center gap-2 px-3 py-2.5`,children:[(0,G.jsx)(mc,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium text-center`,children:F(`printers.drying.start`)})]}),(0,G.jsx)(`div`,{className:`shrink-0 h-px bg-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`px-3 py-2.5 space-y-2.5 overflow-y-auto min-h-0`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-[length:var(--pc-t10,10px)] text-white/70 font-medium mb-1 block`,children:F(`printers.filaments`)}),(0,G.jsx)(xW,{value:tt,options:Object.keys(S).map(e=>({value:e,label:e})),onChange:e=>{nt(e);let t=S[e];t&&(it(t[$e===`n3s`?`n3s`:`n3f`]),ot($e===`n3s`?t.n3s_hours:t.n3f_hours))},fullWidth:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsx)(`label`,{className:`text-[length:var(--pc-t10,10px)] text-white/70 font-medium`,children:F(`printers.drying.temperature`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:45,max:e,value:rt,onChange:t=>it(Math.min(e,Math.max(45,Number(t.target.value)||45))),className:`w-12 px-1 py-0.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-[length:var(--pc-t11,11px)] text-center focus:outline-none focus:border-bambu-green [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] text-bambu-gray`,children:`°C`})]})]}),(0,G.jsx)(`input`,{type:`range`,min:35,max:t,value:rt,onChange:t=>it(Math.min(e,Math.max(45,Number(t.target.value)))),className:`w-full h-1 accent-bambu-green cursor-pointer`}),(0,G.jsxs)(`div`,{className:`flex justify-between text-[length:var(--pc-t9,9px)] text-bambu-gray/50 mt-0.5`,children:[(0,G.jsx)(`span`,{children:`45°C`}),(0,G.jsxs)(`span`,{children:[e,`°C`]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsx)(`label`,{className:`text-[length:var(--pc-t10,10px)] text-white/70 font-medium`,children:F(`printers.drying.duration`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:1,max:24,value:at,onChange:e=>ot(Math.min(24,Math.max(1,Number(e.target.value)||1))),className:`w-10 px-1 py-0.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-[length:var(--pc-t11,11px)] text-center focus:outline-none focus:border-bambu-green [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] text-bambu-gray`,children:F(`printers.drying.hours`)})]})]}),(0,G.jsx)(`input`,{type:`range`,min:1,max:24,value:at,onChange:e=>ot(Number(e.target.value)),className:`w-full h-1 accent-bambu-green cursor-pointer`}),(0,G.jsxs)(`div`,{className:`flex justify-between text-[length:var(--pc-t9,9px)] text-bambu-gray/50 mt-0.5`,children:[(0,G.jsx)(`span`,{children:`1h`}),(0,G.jsx)(`span`,{children:`24h`})]})]}),(()=>{let e=((Ze===null?void 0:En.find(e=>e.id===Ze))?.tray??[]).some(e=>e.state===11),t=st&&!e;return(0,G.jsx)(`button`,{type:`button`,onClick:()=>ct(e=>!e),"aria-pressed":t,disabled:e,title:e?F(`printers.drying.rotateUnavailableReason`):void 0,className:`h-8 w-full rounded-lg border px-2 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${t?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary disabled:hover:bg-bambu-dark`}`,children:F(`printers.drying.rotateTray`)})})(),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-[10px] text-white/70 font-medium mb-1 block`,children:F(`printers.drying.startMode`)}),(0,G.jsx)(`div`,{className:`grid grid-cols-3 gap-1`,children:[`now`,`delay`,`at_time`].map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>ut(e),className:`py-1 rounded-lg border text-[10px] font-medium transition-colors ${lt===e?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:F(e===`now`?`printers.drying.modeNow`:e===`delay`?`printers.drying.modeDelay`:`printers.drying.modeAtTime`)},e))}),lt===`delay`&&(0,G.jsx)(`div`,{className:`mt-1.5 grid grid-cols-4 gap-1`,children:YOe.map(e=>(0,G.jsx)(`button`,{type:`button`,"aria-pressed":dt===e,onClick:()=>ft(e),className:`py-1 rounded-lg border text-[10px] font-medium transition-colors ${dt===e?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:ap(e/60)},e))}),lt===`at_time`&&(0,G.jsx)(`input`,{ref:bt,type:`datetime-local`,"data-testid":`drying-start-at`,value:pt,onChange:e=>mt(e.target.value),className:`mt-1.5 w-full px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-[11px] focus:outline-none focus:border-bambu-green [color-scheme:dark]`})]})]}),(0,G.jsx)(`div`,{className:`shrink-0 h-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`shrink-0 px-3 pt-2.5 pb-3`,children:(0,G.jsx)(`button`,{onClick:()=>{if(Ze!==null){let e=(En.find(e=>e.id===Ze)?.tray??[]).some(e=>e.state===11),t=st&&!e;if(lt===`now`)ir.mutate({amsId:Ze,temp:rt,duration:at,filament:tt,rotateTray:t});else{let e=Cee(lt,dt,pt);e&&ar.mutate({amsId:Ze,temp:rt,duration:at,filament:tt,rotateTray:t,startAfter:e})}}},disabled:ir.isPending||ar.isPending||lt===`at_time`&&!pt,"data-testid":`drying-start-confirm`,className:`w-full py-1.5 bg-bambu-green hover:bg-bambu-green/80 text-white text-xs font-medium rounded-lg transition-colors disabled:opacity-50`,children:lt===`now`?ir.isPending?F(`printers.drying.startingDrying`):F(`printers.drying.start`):F(`printers.drying.schedule`)})})]}),(0,G.jsx)(`div`,{className:`fixed z-[102] w-2.5 h-2.5 rotate-45 bg-bambu-dark-secondary border-bambu-dark-tertiary pointer-events-none`,style:{left:ht.left+ht.arrowLeft-5,top:ht.anchorY-5,...ht.placement===`above`?{borderRightWidth:1,borderBottomWidth:1}:{borderLeftWidth:1,borderTopWidth:1}}})]})})()]})}function xke({onClose:e,onAdd:t,existingSerials:n}){let{t:r}=U(),[i,a]=(0,y.useState)({name:``,serial_number:``,ip_address:``,access_code:``,model:``,location:``,auto_archive:!0}),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)([]),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(!1),[g,_]=(0,y.useState)([]),[v,b]=(0,y.useState)(``),[x,S]=(0,y.useState)(``),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)({scanned:0,total:0}),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(null);(0,y.useEffect)(()=>{_d.getInfo().then(e=>{h(e.is_docker),e.subnets.length>0&&(_(e.subnets),b(e.subnets[0]))}).catch(()=>{});try{let e=localStorage.getItem(`bambuddy.discovery.customSubnet`);e&&S(e)}catch{}},[]);let N=c.filter(e=>!n.includes(e.serial)),P=async e=>{e.preventDefault(),A(!0);try{let e=await Z.diagnoseConnection({ip_address:i.ip_address.trim(),serial_number:i.serial_number.trim()||void 0,access_code:i.access_code||void 0});if(e.checks.some(e=>e.status===`fail`)){M(e);return}}catch{}finally{A(!1)}t(i)},F=async()=>{d(``),l([]),s(!0),p(!1),E({scanned:0,total:0});let e=C?x.trim():v,t=m||C;if(t&&C)try{localStorage.setItem(`bambuddy.discovery.customSubnet`,e)}catch{}try{if(t){await _d.startSubnetScan(e);let t=setInterval(async()=>{try{let e=await _d.getScanStatus();E({scanned:e.scanned,total:e.total}),l(await _d.getDiscoveredPrinters()),e.running||(clearInterval(t),s(!1),p(!0))}catch(e){console.error(`Failed to get scan status:`,e)}},500)}else{await _d.startDiscovery(10);let e=setInterval(async()=>{try{l(await _d.getDiscoveredPrinters())}catch(e){console.error(`Failed to get discovered printers:`,e)}},1e3);setTimeout(async()=>{clearInterval(e);try{await _d.stopDiscovery()}catch{}s(!1),p(!0);try{l(await _d.getDiscoveredPrinters())}catch(e){console.error(`Failed to get final discovered printers:`,e)}},1e4)}}catch(e){console.error(`Failed to start discovery:`,e),d(e instanceof Error?e.message:r(`printers.discovery.failedToStart`)),s(!1),p(!0)}},I=e=>{let t=e.serial.startsWith(`unknown-`)?``:e.serial;a({...i,name:e.name||``,serial_number:t,ip_address:e.ip_address,model:DW(e.model)}),l([])};return(0,y.useEffect)(()=>()=>{_d.stopDiscovery().catch(()=>{}),_d.stopSubnetScan().catch(()=>{})},[]),(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-start sm:items-center justify-center z-50 p-4 overflow-y-auto`,onClick:e,children:(0,G.jsx)(Pd,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Id,{children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold mb-4`,children:r(`printers.addPrinter`)}),(0,G.jsxs)(`div`,{className:`mb-4 pb-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`mb-3`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.discovery.subnetToScan`)}),g.length>0?(0,G.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 text-sm`,value:C?`__custom__`:v,onChange:e=>{e.target.value===`__custom__`?w(!0):(w(!1),b(e.target.value))},disabled:o,children:[g.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e)),(0,G.jsx)(`option`,{value:`__custom__`,children:r(`printers.discovery.customSubnetOption`)})]}):(0,G.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:v,onChange:e=>b(e.target.value),placeholder:`192.168.1.0/24`,disabled:o}),C&&(0,G.jsx)(`input`,{type:`text`,"aria-label":r(`printers.discovery.customSubnetLabel`),className:`mt-2 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:x,onChange:e=>S(e.target.value),placeholder:`10.1.1.0/24`,disabled:o}),(0,G.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:r(m?`printers.discovery.dockerNote`:`printers.discovery.customSubnetNote`)})]}),(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:F,disabled:o,className:`w-full`,children:o?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(m||C)&&T.total>0?r(`printers.discovery.scanProgress`,{scanned:T.scanned,total:T.total}):r(`printers.discovery.scanning`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Zl,{className:`w-4 h-4`}),r(m||C?`printers.discovery.scanSubnet`:`printers.discovery.discoverNetwork`)]})}),u&&(0,G.jsx)(`div`,{className:`mt-2 text-sm text-red-700 dark:text-red-400`,children:u}),N.length>0&&(0,G.jsx)(`div`,{className:`mt-3 space-y-2 max-h-40 overflow-y-auto`,children:N.map(e=>(0,G.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:()=>I(e),children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`font-medium text-white text-sm truncate`,children:e.name||e.serial}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[DW(e.model)||r(`printers.discovery.unknown`),` • `,e.ip_address,e.serial.startsWith(`unknown-`)&&(0,G.jsxs)(`span`,{className:`text-yellow-500`,children:[` • `,r(`printers.discovery.serialRequired`)]})]})]}),(0,G.jsx)(fs,{className:`w-4 h-4 text-bambu-gray -rotate-90 flex-shrink-0 ml-2`})]},e.serial))}),o&&(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray text-center`,children:r(m||C?`printers.discovery.scanningSubnet`:`printers.discovery.scanningNetwork`)}),f&&!o&&c.length===0&&(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray text-center`,children:r(m||C?`printers.discovery.noPrintersFoundSubnet`:`printers.discovery.noPrintersFoundNetwork`)}),f&&!o&&c.length>0&&N.length===0&&(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray text-center`,children:r(`printers.discovery.allConfigured`)})]}),(0,G.jsxs)(`form`,{onSubmit:P,className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.name`)}),(0,G.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:i.name,onChange:e=>a({...i,name:e.target.value}),placeholder:r(`printers.modal.myPrinter`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.ipAddress`)}),(0,G.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:i.ip_address,onChange:e=>a({...i,ip_address:e.target.value}),placeholder:`192.168.1.100 or printer.local`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.serialNumber`)}),(0,G.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:i.serial_number,onChange:e=>a({...i,serial_number:e.target.value}),placeholder:`01P00A000000000`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.accessCode`)}),(0,G.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:i.access_code,onChange:e=>a({...i,access_code:e.target.value}),placeholder:r(`printers.modal.fromPrinterSettings`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.modal.modelOptional`)}),(0,G.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:i.model||``,onChange:e=>a({...i,model:e.target.value}),children:[(0,G.jsx)(`option`,{value:``,children:r(`printers.modal.selectModel`)}),(0,G.jsxs)(`optgroup`,{label:`A1 Series`,children:[(0,G.jsx)(`option`,{value:`A1`,children:`A1`}),(0,G.jsx)(`option`,{value:`A1 Mini`,children:`A1 Mini`})]}),(0,G.jsx)(`optgroup`,{label:`A2 Series`,children:(0,G.jsx)(`option`,{value:`A2L`,children:`A2L`})}),(0,G.jsxs)(`optgroup`,{label:`H2 Series`,children:[(0,G.jsx)(`option`,{value:`H2C`,children:`H2C`}),(0,G.jsx)(`option`,{value:`H2D`,children:`H2D`}),(0,G.jsx)(`option`,{value:`H2D Pro`,children:`H2D Pro`}),(0,G.jsx)(`option`,{value:`H2S`,children:`H2S`})]}),(0,G.jsxs)(`optgroup`,{label:`P Series`,children:[(0,G.jsx)(`option`,{value:`P1P`,children:`P1P`}),(0,G.jsx)(`option`,{value:`P1S`,children:`P1S`}),(0,G.jsx)(`option`,{value:`P2S`,children:`P2S`})]}),(0,G.jsxs)(`optgroup`,{label:`X1 Series`,children:[(0,G.jsx)(`option`,{value:`X1`,children:`X1`}),(0,G.jsx)(`option`,{value:`X1C`,children:`X1 Carbon`}),(0,G.jsx)(`option`,{value:`X1E`,children:`X1E`})]}),(0,G.jsx)(`optgroup`,{label:`X2 Series`,children:(0,G.jsx)(`option`,{value:`X2D`,children:`X2D`})})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.modal.locationGroup`)}),(0,G.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:i.location||``,onChange:e=>a({...i,location:e.target.value}),placeholder:r(`printers.modal.locationPlaceholder`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`printers.locationHelp`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`auto_archive`,checked:i.auto_archive,onChange:e=>a({...i,auto_archive:e.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`label`,{htmlFor:`auto_archive`,className:`text-sm text-bambu-gray`,children:r(`printers.modal.autoArchiveLabel`)})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>O(!0),disabled:!i.ip_address.trim(),className:`w-full flex items-center justify-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white disabled:opacity-40 disabled:cursor-not-allowed border border-bambu-dark-tertiary rounded-lg transition-colors`,children:[(0,G.jsx)(xu,{className:`w-4 h-4`}),r(`diagnostic.runButton`)]}),j?(0,G.jsxs)(`div`,{className:`rounded-lg bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 p-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Iu,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-amber-600 dark:text-amber-400`}),(0,G.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-300`,children:r(`printers.addPreflight.warning`)})]}),(0,G.jsx)(Up,{result:j}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>M(null),className:`flex-1`,children:r(`printers.addPreflight.back`)}),(0,G.jsx)(Q,{type:`button`,onClick:()=>t(i),className:`flex-1`,children:r(`printers.addPreflight.saveAnyway`)})]})]}):(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:e,className:`flex-1`,children:r(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:k,className:`flex-1`,children:r(k?`printers.addPreflight.checking`:`printers.addPrinter`)})]})]})]})})}),D&&(0,G.jsx)(Wp,{connection:{ip_address:i.ip_address.trim(),serial_number:i.serial_number.trim()||void 0,access_code:i.access_code||void 0},printerName:i.name||null,onClose:()=>O(!1)})]})}function Ske({printer:e,firmwareInfo:t,onClose:n}){let{t:r}=U(),i=co(),{showToast:a}=Hd(),{hasPermission:o}=Od(),s=o(`firmware:update`),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(t.update_available?t.latest_version:null),{data:g,isLoading:_}=K({queryKey:[`firmwarePrepare`,e.id,m],queryFn:()=>xd.prepareUpload(e.id,m??void 0),staleTime:3e4,enabled:!!m&&s&&!u}),v=q({mutationFn:()=>xd.startUpload(e.id,m??void 0),onSuccess:()=>{d(!0);let t=setInterval(async()=>{try{let n=await xd.getUploadStatus(e.id);l(n),(n.status===`complete`||n.status===`error`)&&(clearInterval(t),p(null),d(!1),n.status===`complete`&&(a(r(`printers.firmwareModal.uploadedToast`),`success`),i.invalidateQueries({queryKey:[`firmwareUpdate`,e.id]})))}catch{}},2e3);p(t)},onError:e=>{a(r(`printers.firmwareModal.uploadFailed`,{error:e.message}),`error`),d(!1)}});return(0,y.useEffect)(()=>()=>{f&&clearInterval(f)},[f]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,G.jsx)(Pd,{className:`w-full max-w-md mx-4`,children:(0,G.jsxs)(Id,{children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full ${t.update_available?`bg-orange-100 dark:bg-orange-500/20`:`bg-status-ok/20`}`,children:t.update_available?(0,G.jsx)(Ys,{className:`w-5 h-5 text-orange-600 dark:text-orange-400`}):(0,G.jsx)(bs,{className:`w-5 h-5 text-status-ok`})}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:t.update_available?r(`printers.firmwareModal.title`):r(`printers.firmwareModal.titleUpToDate`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e.name})]})]}),(()=>{let e=m?t.available_versions?.find(e=>e.version===m):null,n=m??t.latest_version,i=e?.release_notes??t.release_notes,a=!!n&&n!==t.current_version;return(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3 mb-4`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between items-center text-sm`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:r(`printers.firmwareModal.currentVersion`)}),(0,G.jsx)(`span`,{className:`font-mono ${a?`text-white`:`text-status-ok`}`,children:t.current_version||r(`common.unknown`)})]}),a&&(0,G.jsxs)(`div`,{className:`flex justify-between items-center text-sm mt-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:r(`printers.firmwareModal.latestVersion`)}),(0,G.jsx)(`span`,{className:`text-orange-700 dark:text-orange-400 font-mono`,children:n})]}),i&&(0,G.jsxs)(`details`,{className:`mt-3 text-sm`,open:!a,children:[(0,G.jsx)(`summary`,{className:`cursor-pointer hover:underline ${a?`text-orange-700 dark:text-orange-400`:`text-status-ok`}`,children:r(`printers.firmwareModal.releaseNotes`)}),(0,G.jsx)(`div`,{className:`mt-2 text-bambu-gray text-xs max-h-40 overflow-y-auto whitespace-pre-wrap`,children:i})]},n??`none`)]})})(),t.available_versions&&t.available_versions.length>0&&!u&&c?.status!==`complete`&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mb-2`,children:r(`printers.firmwareModal.availableVersions`)}),(0,G.jsx)(`div`,{className:`max-h-56 overflow-y-auto border border-bambu-dark-tertiary rounded-lg divide-y divide-bambu-dark-tertiary`,children:t.available_versions.map(e=>{let n=t.current_version===e.version,i=m===e.version,a=t.current_version?hee(e.version,t.current_version):0,o=r(n?`printers.firmwareModal.currentBadge`:a>0?`printers.firmwareModal.newerBadge`:`printers.firmwareModal.olderBadge`),c=n?`text-bambu-gray`:a>0?`text-orange-700 dark:text-orange-400`:`text-blue-700 dark:text-blue-400`;return(0,G.jsxs)(`button`,{type:`button`,disabled:!e.file_available||!s||n,onClick:()=>h(e.version),className:`w-full text-left px-3 py-2 text-sm flex items-center justify-between gap-2 transition-colors ${i?`bg-orange-50 dark:bg-orange-500/10`:`hover:bg-bambu-dark`} ${!e.file_available||!s||n?`opacity-60 cursor-not-allowed`:`cursor-pointer`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(`span`,{className:`font-mono text-white`,children:e.version}),(0,G.jsx)(`span`,{className:`text-xs ${c}`,children:o})]}),(0,G.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full ${n?`bg-blue-50 dark:bg-blue-500/15 text-blue-700 dark:text-blue-400 border border-blue-300 dark:border-blue-500/30`:e.file_available?`bg-bambu-green/15 text-bambu-green border border-bambu-green/30`:`bg-bambu-gray/10 text-bambu-gray border border-bambu-gray/30`}`,children:n?r(`printers.firmwareModal.installed`):e.file_available?r(`printers.firmwareModal.usable`):r(`printers.firmwareModal.unavailable`)})]},e.version)})})]}),m?_?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm mb-4`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`printers.firmwareModal.checkingPrereqs`)]}):g&&!u&&!c?(0,G.jsx)(`div`,{className:`mb-4`,children:g.can_proceed?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-green text-sm`,children:[(0,G.jsx)(Xo,{className:`w-4 h-4`}),r(`printers.firmwareModal.sdCardReady`)]}):(0,G.jsx)(`div`,{className:`space-y-1`,children:g.errors.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400 text-sm`,children:[(0,G.jsx)(vs,{className:`w-4 h-4 flex-shrink-0`}),e]},t))})}):null:null,(u||c)&&c&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-sm mb-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray capitalize`,children:c.status}),(0,G.jsxs)(`span`,{className:`text-white`,children:[c.progress,`%`]})]}),(0,G.jsx)(`div`,{className:`w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,G.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}%`}})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c.message}),c.error&&(0,G.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:c.error})]}),c?.status===`complete`&&(0,G.jsxs)(`div`,{className:`bg-bambu-green/10 border border-bambu-green/30 rounded-lg p-3 mb-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-green font-medium mb-2`,children:r(`printers.firmwareModal.uploadedSuccess`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`printers.firmwareModal.applyInstructions`)}),(0,G.jsxs)(`ol`,{className:`text-xs text-bambu-gray mt-1 list-decimal list-inside space-y-1`,children:[(0,G.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step1`)}}),(0,G.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step2`)}}),(0,G.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step3`)}}),(0,G.jsx)(`li`,{children:r(`printers.firmwareModal.step4`)})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:n,children:c?.status===`complete`?r(`printers.firmwareModal.done`):r(`common.cancel`)}),g?.can_proceed&&!u&&c?.status!==`complete`&&s&&(0,G.jsx)(Q,{onClick:()=>{l(null),v.mutate()},disabled:v.isPending,children:v.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-2`}),r(`printers.firmwareModal.starting`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ys,{className:`w-4 h-4 mr-2`}),r(`printers.firmwareModal.uploadFirmware`)]})})]})]})})})}function Cke({printer:e,onClose:t}){let{t:n}=U(),r=co(),{showToast:i}=Hd(),[a,o]=(0,y.useState)({name:e.name,ip_address:e.ip_address,access_code:``,model:e.model||``,location:e.location||``,auto_archive:e.auto_archive,is_active:e.is_active}),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(null),d=q({mutationFn:t=>Z.updatePrinter(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`printers`]}),r.invalidateQueries({queryKey:[`printerStatus`,e.id]}),t()},onError:e=>i(e.message||n(`printers.toast.failedToUpdate`),`error`)});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let f=()=>{let e={name:a.name,ip_address:a.ip_address,model:a.model||void 0,location:a.location||void 0,auto_archive:a.auto_archive,is_active:a.is_active};a.access_code&&(e.access_code=a.access_code),d.mutate(e)};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-start sm:items-center justify-center z-50 p-4 overflow-y-auto`,onClick:t,children:(0,G.jsx)(Pd,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Id,{children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold mb-4`,children:n(`printers.editPrinter`)}),(0,G.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault(),c(!0);try{let t=await Z.diagnoseConnection({ip_address:a.ip_address.trim(),serial_number:e.serial_number,access_code:a.access_code||void 0});if(t.checks.some(e=>e.status===`fail`)){u(t);return}}catch{}finally{c(!1)}f()},className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.name`)}),(0,G.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:e=>o({...a,name:e.target.value}),placeholder:n(`printers.modal.myPrinter`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.ipAddress`)}),(0,G.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:e=>o({...a,ip_address:e.target.value}),placeholder:`192.168.1.100 or printer.local`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.serialNumber`)}),(0,G.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:e.serial_number}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`printers.serialCannotBeChanged`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.accessCode`)}),(0,G.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:a.access_code,onChange:e=>o({...a,access_code:e.target.value}),placeholder:n(`printers.accessCodePlaceholder`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.model`)}),(0,G.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:e=>o({...a,model:e.target.value}),children:[(0,G.jsx)(`option`,{value:``,children:n(`printers.modal.selectModel`)}),(0,G.jsxs)(`optgroup`,{label:`A1 Series`,children:[(0,G.jsx)(`option`,{value:`A1`,children:`A1`}),(0,G.jsx)(`option`,{value:`A1 Mini`,children:`A1 Mini`})]}),(0,G.jsx)(`optgroup`,{label:`A2 Series`,children:(0,G.jsx)(`option`,{value:`A2L`,children:`A2L`})}),(0,G.jsxs)(`optgroup`,{label:`H2 Series`,children:[(0,G.jsx)(`option`,{value:`H2C`,children:`H2C`}),(0,G.jsx)(`option`,{value:`H2D`,children:`H2D`}),(0,G.jsx)(`option`,{value:`H2D Pro`,children:`H2D Pro`}),(0,G.jsx)(`option`,{value:`H2S`,children:`H2S`})]}),(0,G.jsxs)(`optgroup`,{label:`P Series`,children:[(0,G.jsx)(`option`,{value:`P1P`,children:`P1P`}),(0,G.jsx)(`option`,{value:`P1S`,children:`P1S`}),(0,G.jsx)(`option`,{value:`P2S`,children:`P2S`})]}),(0,G.jsxs)(`optgroup`,{label:`X1 Series`,children:[(0,G.jsx)(`option`,{value:`X1`,children:`X1`}),(0,G.jsx)(`option`,{value:`X1C`,children:`X1 Carbon`}),(0,G.jsx)(`option`,{value:`X1E`,children:`X1E`})]}),(0,G.jsx)(`optgroup`,{label:`X2 Series`,children:(0,G.jsx)(`option`,{value:`X2D`,children:`X2D`})})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Location / Group`}),(0,G.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:e=>o({...a,location:e.target.value}),placeholder:n(`printers.modal.locationPlaceholder`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`printers.locationHelp`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`edit_auto_archive`,checked:a.auto_archive,onChange:e=>o({...a,auto_archive:e.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`label`,{htmlFor:`edit_auto_archive`,className:`text-sm text-bambu-gray`,children:n(`printers.modal.autoArchiveLabel`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`edit_maintenance_mode`,checked:!a.is_active,onChange:e=>o({...a,is_active:!e.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-amber-400 focus:ring-amber-400`}),(0,G.jsxs)(`label`,{htmlFor:`edit_maintenance_mode`,className:`text-sm text-bambu-gray flex items-center gap-1.5`,children:[(0,G.jsx)(ed,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400`}),n(`printers.maintenance.editFieldLabel`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1 ml-6`,children:n(`printers.maintenance.editFieldHelp`)})]}),l?(0,G.jsxs)(`div`,{className:`rounded-lg bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 p-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Iu,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-amber-600 dark:text-amber-400`}),(0,G.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-300`,children:n(`printers.addPreflight.warning`)})]}),(0,G.jsx)(Up,{result:l}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>u(null),className:`flex-1`,children:n(`printers.addPreflight.back`)}),(0,G.jsx)(Q,{type:`button`,onClick:f,className:`flex-1`,disabled:d.isPending,children:n(`printers.addPreflight.saveAnyway`)})]})]}):(0,G.jsxs)(`div`,{className:`flex gap-3 pt-4`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,className:`flex-1`,disabled:d.isPending||s,children:s?n(`printers.addPreflight.checking`):d.isPending?n(`common.saving`):n(`printers.modal.saveChanges`)})]})]})]})})})}function wke(e){let{data:t}=K({queryKey:[`printerStatus`,e],queryFn:()=>Z.getPrinterStatus(e),refetchInterval:3e4});return!t?.connected}function Tke({printer:e,plug:t,onPowerOn:n,isPowering:r}){let i=wke(e.id),{data:a}=K({queryKey:[`smartPlugStatus`,t.id],queryFn:()=>Z.getSmartPlugStatus(t.id),refetchInterval:1e4});return i?(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 hover:bg-gray-100 dark:hover:bg-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white truncate`,children:e.name}),a&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded ${a.state===`ON`?`bg-bambu-green/20 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`}`,children:a.state||`?`})]}),(0,G.jsxs)(`button`,{onClick:()=>n(t.id),disabled:r||a?.state===`ON`,className:`px-2 py-1 text-xs rounded transition-colors flex items-center gap-1 ${a?.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:[(0,G.jsx)(Il,{className:`w-3 h-3`}),r?`...`:`On`]})]}):null}function Eke(){let{t:e}=U(),{resolvedMode:t,darkAccent:n,lightAccent:r}=jd(),i={green:`bg-green-500 text-white hover:bg-green-400 border-green-400/60`,teal:`bg-teal-500 text-white hover:bg-teal-400 border-teal-400/60`,blue:`bg-blue-500 text-white hover:bg-blue-400 border-blue-400/60`,orange:`bg-orange-500 text-white hover:bg-orange-400 border-orange-400/60`,purple:`bg-purple-500 text-white hover:bg-purple-400 border-purple-400/60`,red:`bg-red-500 text-white hover:bg-red-400 border-red-400/60`}[t===`dark`?n:r],[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(()=>localStorage.getItem(`hideDisconnectedPrinters`)===`true`),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(()=>localStorage.getItem(`printerSortBy`)||`name`),[h,g]=(0,y.useState)(()=>localStorage.getItem(`printerSortAsc`)!==`false`),[_,v]=(0,y.useState)(()=>{let e=localStorage.getItem(`printerCardSize`);return e?parseInt(e,10):2}),[b,x]=(0,y.useState)(()=>localStorage.getItem(`printerPageView`)===`camwall`?`camwall`:`cards`),[S,C]=(0,y.useState)(()=>{let e=parseInt(localStorage.getItem(`camWallMaxLive`)||``,10);return Number.isFinite(e)&&e>0?e:4}),[w,T]=(0,y.useState)(()=>{let e=parseInt(localStorage.getItem(`camWallSnapshotSec`)||``,10);return Number.isFinite(e)&&e>0?e:8}),[E,D]=(0,y.useState)(()=>{let e=localStorage.getItem(`camWallStatusMode`);return e===`off`||e===`compact`||e===`full`?e:`full`}),O=_===1?`compact`:`expanded`,[k,A]=(0,y.useState)(null),j=(0,y.useCallback)(e=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{let t=document.getElementById(`printer-card-${e}`);if(!t)return;let n=document.querySelector(`header`)?.getBoundingClientRect().height??56,r=t.getBoundingClientRect().top+window.scrollY-n-16;window.scrollTo({top:Math.max(0,r),behavior:`smooth`})})})},[]),M=(0,y.useCallback)(e=>{A(e),v(2),localStorage.setItem(`printerCardSize`,`2`),j(e)},[j]),N=(0,y.useCallback)(()=>{let e=k;A(null),v(1),localStorage.setItem(`printerCardSize`,`1`),e!=null&&j(e)},[k,j]),[P,F]=(0,y.useState)(``),[I,L]=(0,y.useState)(()=>{let e=localStorage.getItem(`printerStatusFilter`);return $Oe(e)?e:`all`}),[R,z]=(0,y.useState)(()=>localStorage.getItem(`printerLocationFilter`)||`all`),[B,V]=(0,y.useState)(0),[ee,te]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`printerCollapsedSections`);return e?JSON.parse(e):{}}catch{return{}}}),ne=co(),{showToast:re}=Hd(),{hasPermission:ie}=Od(),[ae,oe]=(0,y.useState)(()=>yee()),[se,H]=(0,y.useState)(()=>{let e=localStorage.getItem(`openEmbeddedCameras`);if(e)try{let t=JSON.parse(e);return new Map(t.map(e=>[e.id,e]))}catch{return new Map}return new Map});(0,y.useEffect)(()=>{let e=Array.from(se.values());e.length>0?localStorage.setItem(`openEmbeddedCameras`,JSON.stringify(e)):localStorage.removeItem(`openEmbeddedCameras`)},[se]);let{data:ce,isLoading:le}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:ue}=K({queryKey:[`ui-preferences`],queryFn:Z.getUiPreferences}),de=(0,y.useMemo)(()=>wm(ue?.nozzle_temp_presets,bm,0,320),[ue?.nozzle_temp_presets]),fe=(0,y.useMemo)(()=>wm(ue?.bed_temp_presets,xm,0,140),[ue?.bed_temp_presets]),pe=(0,y.useMemo)(()=>wm(ue?.chamber_temp_presets,Sm,0,65),[ue?.chamber_temp_presets]),me=(0,y.useMemo)(()=>wm(ue?.fan_speed_presets,Cm,0,100),[ue?.fan_speed_presets]),he=(0,y.useMemo)(()=>{if(ue?.drying_presets)try{let e=JSON.parse(ue.drying_presets);if(typeof e==`object`&&e&&Object.keys(e).length>0)return{...kW,...e}}catch{}return kW},[ue?.drying_presets]),ge=ae??(ue?.camera_view_mode===`embedded`?`embedded`:`window`),_e=(0,y.useCallback)(e=>{bee(e),oe(e),ie(`settings:update`)&&Z.updateSettings({camera_view_mode:e}).then(()=>ne.invalidateQueries({queryKey:[`ui-preferences`]})).catch(e=>console.warn(`Could not save camera view mode as the default:`,e))},[ie,ne]),{data:ve}=K({queryKey:[`smart-plugs`],queryFn:Z.getSmartPlugs}),{data:ye}=K({queryKey:[`maintenanceOverview`],queryFn:Z.getMaintenanceOverview,staleTime:60*1e3}),{data:be}=K({queryKey:[`obico-printer-status`],queryFn:Z.getObicoPrinterStatus,refetchInterval:1e4}),xe=(0,y.useCallback)(e=>be?.enabled===!0&&(be.monitored_printers===null||be.monitored_printers.includes(e)),[be]),{data:Se}=K({queryKey:[`spoolman-status`],queryFn:Z.getSpoolmanStatus,staleTime:60*1e3}),Ce=Se?.enabled&&Se?.connected,{data:we}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,enabled:!!Ce,staleTime:60*1e3}),Te=we?.spoolman_sync_mode,{data:Ee}=K({queryKey:[`unlinked-spools`],queryFn:Z.getUnlinkedSpools,enabled:!!Ce,staleTime:30*1e3}),De=Ee&&Ee.length>0,{data:Oe}=K({queryKey:[`linked-spools`],queryFn:Z.getLinkedSpools,enabled:!!Ce,staleTime:30*1e3}),ke=Oe?.linked,{data:Ae}=K({queryKey:[`spool-assignments`],queryFn:()=>Z.getAssignments(),enabled:ie(`inventory:view_assignments`),staleTime:30*1e3}),je=q({mutationFn:({printerId:e,amsId:t,trayId:n})=>Z.unassignSpool(e,t,n),onSuccess:()=>{ne.invalidateQueries({queryKey:[`spool-assignments`]})}}),{data:Me,isLoading:Ne}=K({queryKey:[`spoolman-inventory-spools`],queryFn:()=>Z.getSpoolmanInventorySpools(!1),enabled:!!Ce,staleTime:30*1e3}),{data:Pe,isLoading:Fe}=K({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:!!Ce,staleTime:30*1e3}),Ie=q({mutationFn:e=>Z.unassignSpoolmanSlot(e),onSuccess:()=>{ne.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),ne.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})}}),Le=(e,t,n)=>Ae?.find(r=>r.printer_id===e&&r.ams_id===Number(t)&&r.tray_id===Number(n)),Re=ye?.reduce((e,t)=>(e[t.printer_id]={due_count:t.due_count,warning_count:t.warning_count,total_print_hours:t.total_print_hours},e),{})||{},ze=ve?.reduce((e,t)=>(t.printer_id&&(e[t.printer_id]=t),e),{})||{},Be=q({mutationFn:Z.createPrinter,onSuccess:()=>{ne.invalidateQueries({queryKey:[`printers`]}),ne.invalidateQueries({queryKey:[`maintenanceOverview`]}),o(!1)},onError:t=>{if(t instanceof od&&t.code===`printer_connection_failed`){re(e(`printers.toast.connectionFailedNotAdded`),`error`);return}re(t.message||e(`printers.toast.failedToAdd`),`error`)}}),Ve=q({mutationFn:e=>Z.controlSmartPlug(e,`on`),onSuccess:()=>{ne.invalidateQueries({queryKey:[`smart-plugs`]}),f(null)},onError:()=>{f(null)}}),[He,Ue]=(0,y.useState)(new Set),[We,Ge]=(0,y.useState)(!1),[Ke,qe]=(0,y.useState)(null),[Je,Ye]=(0,y.useState)(!1),Xe=We||He.size>0,Ze=(0,y.useCallback)(e=>{Ue(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Qe=(0,y.useCallback)(()=>{Ue(new Set),Ge(!1)},[]);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&Xe&&Qe()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Xe,Qe]);let $e=(0,y.useCallback)(async t=>{Ye(!0);let n=Array.from(He).filter(e=>{let n=ne.getQueryData([`printerStatus`,e]);if(t===`clearPlate`)return!!n?.awaiting_plate_clear;if(!n?.connected)return!1;switch(t){case`stop`:return n.state===`RUNNING`||n.state===`PAUSE`;case`pause`:return n.state===`RUNNING`;case`resume`:return n.state===`PAUSE`;case`clearHMS`:return n.hms_errors&&km(n.hms_errors).length>0;default:return!1}});if(n.length===0){re(e(`printers.bulk.noneApplicable`),`error`),Ye(!1),qe(null);return}let r={stop:Z.stopPrint,pause:Z.pausePrint,resume:Z.resumePrint,clearPlate:Z.clearPlate,clearHMS:Z.clearHMSErrors}[t],i=await Promise.allSettled(n.map(e=>r(e))),a=i.filter(e=>e.status===`fulfilled`).length,o=i.filter(e=>e.status===`rejected`).length;o===0?re(e(`printers.bulk.success`,{action:e(`printers.bulk.actions.${t}`),count:a})):re(e(`printers.bulk.partial`,{succeeded:a,failed:o}),`error`),n.forEach(e=>{ne.invalidateQueries({queryKey:[`printerStatus`,e]})}),Ye(!1),qe(null)},[He,ne,re,e]),et=(0,y.useCallback)(e=>{e===`stop`||e===`pause`||e===`clearPlate`?qe(e):$e(e)},[$e]),tt=()=>{let e=!s;c(e),localStorage.setItem(`hideDisconnectedPrinters`,String(e))},nt=e=>{m(e),localStorage.setItem(`printerSortBy`,e)},rt=e=>{L(e),localStorage.setItem(`printerStatusFilter`,e)},it=e=>{z(e),localStorage.setItem(`printerLocationFilter`,e)},at=()=>{let e=!h;g(e),localStorage.setItem(`printerSortAsc`,String(e))},ot=()=>{switch(_){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`}},st=[`S`,`M`,`L`,`XL`];(0,y.useEffect)(()=>ne.getQueryCache().subscribe(e=>{e.type===`updated`&&Array.isArray(e.query.queryKey)&&e.query.queryKey[0]===`printerStatus`&&V(e=>e+1)}),[ne]);let ct=(0,y.useMemo)(()=>{if(!ce)return[];let e=ce;if(P.trim()){let t=P.trim().toLowerCase();e=e.filter(e=>e.name.toLowerCase().includes(t)||(e.model||``).toLowerCase().includes(t)||(e.location||``).toLowerCase().includes(t)||(e.serial_number||``).toLowerCase().includes(t))}return R!==`all`&&(e=e.filter(e=>(e.location||``)===R)),I!==`all`&&(e=e.filter(e=>{let t=ne.getQueryData([`printerStatus`,e.id]);if(!t?.connected)return I===`offline`;let n=t.hms_errors?km(t.hms_errors):[];switch(I){case`printing`:return t.state===`RUNNING`;case`paused`:return t.state===`PAUSE`;case`finished`:return t.state===`FINISH`;case`error`:return t.state===`FAILED`||n.length>0;case`idle`:return t.state!==`RUNNING`&&t.state!==`PAUSE`&&t.state!==`FINISH`&&t.state!==`FAILED`&&n.length===0;case`offline`:return!1;default:return!0}})),e},[ce,P,I,R,ne,B]),lt=(0,y.useMemo)(()=>ce?[...new Set(ce.map(e=>e.location||``).filter(Boolean))].sort():[],[ce]);(0,y.useEffect)(()=>{!ce||R===`all`||lt.includes(R)||(z(`all`),localStorage.setItem(`printerLocationFilter`,`all`))},[ce,lt,R]);let ut=(0,y.useMemo)(()=>{let e=[...ct];switch(p){case`name`:e.sort((e,t)=>e.name.localeCompare(t.name));break;case`model`:e.sort((e,t)=>(e.model||``).localeCompare(t.model||``));break;case`location`:e.sort((e,t)=>{let n=e.location||``,r=t.location||``;return!n&&r?1:n&&!r?-1:n.localeCompare(r)||e.name.localeCompare(t.name)});break;case`status`:e.sort((e,t)=>{let n=ne.getQueryData([`printerStatus`,e.id]),r=ne.getQueryData([`printerStatus`,t.id]),i=e=>e?.connected?(e.hms_errors?km(e.hms_errors):[]).length>0?0:e.state===`RUNNING`?1:2:3;return i(n)-i(r)});break;case`eta`:e.sort((e,t)=>{let n=ne.getQueryData([`printerStatus`,e.id]),r=ne.getQueryData([`printerStatus`,t.id]),i=e=>e?.connected?e.state===`RUNNING`&&e.remaining_time!=null&&e.remaining_time>0?0:e.state===`RUNNING`?1:2:3,a=i(n),o=i(r);if(a!==o)return a-o;if(a===0){let e=(n.remaining_time??0)-(r.remaining_time??0);if(e!==0)return e}return e.name.localeCompare(t.name)});break}return h||e.reverse(),e},[ct,p,h,ne]),dt=(0,y.useCallback)(()=>{Ue(new Set(ut.map(e=>e.id))),Ge(!0)},[ut]),ft=(0,y.useCallback)(e=>{Ue(t=>{let n=new Set(t);return ut.forEach(t=>{EW(ne.getQueryData([`printerStatus`,t.id]))===e&&n.add(t.id)}),n}),Ge(!0)},[ut,ne]),pt=(0,y.useCallback)(e=>{Ue(t=>{let n=new Set(t);return ut.filter(t=>(t.location||``)===e).forEach(e=>n.add(e.id)),n}),Ge(!0)},[ut]),mt=(0,y.useCallback)(e=>{Ue(t=>{let n=new Set(t);return ut.filter(t=>(t.model||`Unknown`)===e).forEach(e=>n.add(e.id)),n}),Ge(!0)},[ut]),ht=(0,y.useCallback)(e=>{te(t=>{let n={...t,[e]:!t[e]};try{localStorage.setItem(`printerCollapsedSections`,JSON.stringify(n))}catch{}return n})},[]),gt=(0,y.useMemo)(()=>{if(p===`name`||p===`eta`)return null;let e={};return p===`location`?ut.forEach(t=>{let n=t.location||`Ungrouped`;e[n]||(e[n]=[]),e[n].push(t)}):p===`model`?ut.forEach(t=>{let n=t.model||`Unknown`;e[n]||(e[n]=[]),e[n].push(t)}):p===`status`&&ut.forEach(t=>{let n=EW(ne.getQueryData([`printerStatus`,t.id]));e[n]||(e[n]=[]),e[n].push(t)}),e},[p,ut,ne,B]),_t=(0,y.useRef)(null),vt=(0,y.useRef)(null),yt=(0,y.useRef)(0),[bt,xt]=(0,y.useState)(!1),St=(0,y.useCallback)(()=>{let e=_t.current;if(!e)return;let t=vt.current?.offsetWidth;t&&(yt.current=t);let n=yt.current>0&&e.clientWidthe===n?e:n)},[]),Ct=Object.keys(ze).length;(0,y.useLayoutEffect)(()=>{St();let e=_t.current;if(!e)return;if(typeof ResizeObserver>`u`)return window.addEventListener(`resize`,St),()=>window.removeEventListener(`resize`,St);let t=new ResizeObserver(()=>St());return t.observe(e),window.addEventListener(`resize`,St),()=>{t.disconnect(),window.removeEventListener(`resize`,St)}},[St,ce?.length,lt.length,s,Ct]);let wt=(t=!1)=>(0,G.jsxs)(G.Fragment,{children:[ce&&ce.length>0&&(0,G.jsx)(xW,{value:I,onChange:rt,fullWidth:t,options:cW.map(t=>({value:t.value,label:e(t.labelKey)}))}),ce&&ce.length>0&<.length>0&&(0,G.jsx)(xW,{value:R,onChange:it,fullWidth:t,options:[{value:`all`,label:e(`printers.filter.allLocations`)},...lt.map(e=>({value:e,label:e}))]}),(0,G.jsx)(`button`,{type:`button`,onClick:tt,"aria-pressed":s,className:`h-8 px-2 rounded-lg border text-sm font-medium transition-colors ${t?`w-full`:``} ${s?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:e(`printers.hideOffline`)})]}),Tt=(t=!1)=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1 ${t?`w-full`:``}`,children:[(0,G.jsx)(xW,{value:p,onChange:nt,fullWidth:t,options:[{value:`name`,label:e(`printers.sort.name`)},{value:`status`,label:e(`printers.sort.status`)},{value:`model`,label:e(`printers.sort.model`)},{value:`location`,label:e(`printers.sort.location`)},{value:`eta`,label:e(`printers.sort.eta`)}]}),(0,G.jsx)(`button`,{onClick:at,className:`h-8 shrink-0 px-2 rounded-lg border bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center justify-center`,title:e(h?`printers.sort.descending`:`printers.sort.ascending`),children:h?(0,G.jsx)(Ho,{className:`w-4 h-4 text-white`}):(0,G.jsx)(Io,{className:`w-4 h-4 text-white`})})]}),(0,G.jsxs)(`div`,{className:`flex h-8 items-center bg-bambu-dark rounded-lg border border-bambu-dark-tertiary ${t?`w-full`:``}`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{x(`cards`),localStorage.setItem(`printerPageView`,`cards`)},className:`flex h-full items-center gap-1 rounded-l-lg px-2 text-xs font-medium transition-colors ${t?`flex-1 justify-center`:``} ${b===`cards`?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,title:e(`printers.pageView.cards`),"aria-pressed":b===`cards`,children:[(0,G.jsx)(Jc,{className:`w-3.5 h-3.5`}),t&&(0,G.jsx)(`span`,{children:e(`printers.pageView.cards`)})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{x(`camwall`),localStorage.setItem(`printerPageView`,`camwall`)},className:`flex h-full items-center gap-1 rounded-r-lg px-2 text-xs font-medium transition-colors ${t?`flex-1 justify-center`:``} ${b===`camwall`?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,title:e(`printers.pageView.camWall`),"aria-pressed":b===`camwall`,disabled:!ie(`camera:view`),children:[(0,G.jsx)(ml,{className:`w-3.5 h-3.5`}),t&&(0,G.jsx)(`span`,{children:e(`printers.pageView.camWall`)})]})]}),b===`camwall`&&ie(`camera:view`)&&(0,G.jsxs)(Ai,{to:`/camwall`,className:`flex h-8 items-center gap-1 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark px-2 text-xs font-medium text-white transition-colors hover:bg-bambu-dark-tertiary ${t?`w-full justify-center`:``}`,title:e(`printers.pageView.openCamWallPage`),children:[(0,G.jsx)(nc,{className:`w-3.5 h-3.5`}),t&&(0,G.jsx)(`span`,{children:e(`printers.pageView.openCamWallPage`)})]}),(0,G.jsx)(`div`,{className:`flex h-8 items-center bg-bambu-dark rounded-lg border border-bambu-dark-tertiary ${b===`camwall`?`opacity-40 pointer-events-none`:``} ${t?`w-full`:``}`,children:st.map((n,r)=>{let i=r+1,a=_===i;return(0,G.jsx)(`button`,{onClick:()=>{A(null),v(i),localStorage.setItem(`printerCardSize`,String(i))},className:`h-full px-2 text-xs font-medium transition-colors ${t?`flex-1`:``} ${r===0?`rounded-l-lg`:``} ${r===st.length-1?`rounded-r-lg`:``} ${a?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,title:e(n===`S`?`printers.cardSize.small`:n===`M`?`printers.cardSize.medium`:n===`L`?`printers.cardSize.large`:`printers.cardSize.extraLarge`),children:n},n)})})]}),Et=(t=!1)=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`button`,{onClick:()=>{Xe?Qe():Ge(!0)},className:`h-8 px-2 rounded-lg border transition-colors ${t?`w-full justify-center gap-1.5 text-sm font-medium flex items-center`:``} ${Xe?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,title:e(`printers.bulk.select`),disabled:!ie(`printers:control`),children:[(0,G.jsx)(_u,{className:`w-4 h-4`}),t&&(0,G.jsx)(`span`,{children:e(`printers.bulk.select`)})]}),s&&Object.keys(ze).length>0&&(0,G.jsxs)(`div`,{className:`relative ${t?`w-full`:``}`,children:[(0,G.jsxs)(`button`,{onClick:()=>u(!l),className:`h-8 flex items-center gap-1.5 px-2 text-sm rounded-lg border transition-colors ${t?`w-full justify-between bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary hover:text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(Il,{className:`w-4 h-4`}),e(`printers.powerOn`)]}),(0,G.jsx)(fs,{className:`w-3 h-3 transition-transform ${l?`rotate-180`:``}`})]}),l&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>u(!1)}),(0,G.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:[(0,G.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:e(`printers.offlinePrintersWithPlugs`)}),ce?.filter(e=>ze[e.id]).map(e=>(0,G.jsx)(Tke,{printer:e,plug:ze[e.id],onPowerOn:e=>{f(e),Ve.mutate(e)},isPowering:d===ze[e.id]?.id},e.id)),ce?.filter(e=>ze[e.id]).length===0&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:`No printers with smart plugs`})]})]})]}),(0,G.jsxs)(Q,{onClick:()=>o(!0),disabled:!ie(`printers:create`),title:ie(`printers:create`)?void 0:e(`printers.permission.noAdd`),className:`!h-8 !min-h-8 px-2 py-0 ${t?`w-full`:``}`,children:[(0,G.jsx)(Pl,{className:`w-4 h-4`}),e(`printers.addPrinter`)]})]});return(0,G.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,G.jsxs)(`div`,{className:`space-y-3 mb-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(Ll,{className:`w-7 h-7 text-bambu-green`}),e(`printers.title`)]}),(0,G.jsx)(pke,{printers:ce})]}),(0,G.jsxs)(`div`,{ref:_t,className:`relative flex items-center gap-2`,children:[ce&&ce.length>0&&(0,G.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,G.jsx)(Zl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50`}),(0,G.jsx)(`input`,{type:`search`,name:`printer-search`,autoComplete:`off`,"data-1p-ignore":!0,"data-lpignore":`true`,value:P,onChange:e=>F(e.target.value),placeholder:e(`printers.search`),"aria-label":e(`printers.search`),className:`w-full h-8 pl-9 pr-8 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`}),P&&(0,G.jsx)(`button`,{type:`button`,"aria-label":e(`common.clear`),onClick:()=>F(``),className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,G.jsx)(td,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{ref:vt,"aria-hidden":bt,inert:bt,className:`${bt?`absolute -left-[9999px] top-0 flex w-max pointer-events-none opacity-0`:`flex`} ml-auto items-center justify-end gap-2 flex-nowrap [&>*]:shrink-0`,children:[(0,G.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:wt()}),(0,G.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:Tt()}),(0,G.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:Et()})]}),bt&&(0,G.jsxs)(`div`,{className:`ml-auto flex items-center justify-end gap-1`,children:[(0,G.jsx)(SW,{label:e(`printers.toolbar.filters`,`Filters`),icon:(0,G.jsx)(Cc,{className:`w-4 h-4`}),children:(0,G.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:wt(!0)})}),(0,G.jsx)(SW,{label:e(`printers.toolbar.view`,`View`),icon:(0,G.jsx)(du,{className:`w-4 h-4`}),children:(0,G.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:Tt(!0)})}),(0,G.jsx)(SW,{label:e(`printers.toolbar.actions`,`Actions`),icon:(0,G.jsx)($s,{className:`w-4 h-4`}),children:(0,G.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:Et(!0)})})]})]})]}),le?(0,G.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`common.loading`)}):ce?.length===0?(0,G.jsx)(Pd,{children:(0,G.jsxs)(Id,{className:`text-center py-12`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`printers.noPrintersConfigured`)}),(0,G.jsxs)(Q,{onClick:()=>o(!0),disabled:!ie(`printers:create`),title:ie(`printers:create`)?void 0:e(`printers.permission.noAdd`),children:[(0,G.jsx)(Pl,{className:`w-4 h-4`}),e(`printers.addPrinter`)]})]})}):ut.length===0&&(P.trim()||I!==`all`||R!==`all`)?(0,G.jsx)(Pd,{children:(0,G.jsx)(Id,{className:`text-center py-12`,children:(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`printers.noSearchResults`)})})}):b===`camwall`?(0,G.jsx)(gT,{printers:ut,maxLive:S,snapshotIntervalSec:w,onTileClick:(e,t)=>{ge===`embedded`?H(n=>new Map(n).set(e,{id:e,name:t})):fm(e)},statusMode:E,onChangeMaxLive:e=>{C(e),localStorage.setItem(`camWallMaxLive`,String(e))},onChangeSnapshotIntervalSec:e=>{T(e),localStorage.setItem(`camWallSnapshotSec`,String(e))},onChangeStatusMode:e=>{D(e),localStorage.setItem(`camWallStatusMode`,e)}}):gt?(0,G.jsx)(`div`,{className:`space-y-6`,children:(()=>{let e=p===`status`?hke.filter(e=>gt[e]?.length>0):Object.keys(gt);return h?e:[...e].reverse()})().map(t=>{let n=gt[t],r=`${p}:${t}`,i=!ee[r],a=p===`status`&&TW[t]?.dot||`bg-bambu-green`,o=p===`status`?e(TW[t]?.labelKey||t):t;return(0,G.jsx)(qp,{open:i,onToggle:()=>ht(r),summaryClassName:`py-1`,summary:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${a}`}),o,(0,G.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n.length,`)`]}),Xe&&(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),p===`location`?pt(t===`Ungrouped`?``:t):p===`status`?ft(t):p===`model`&&mt(t)},className:`text-xs text-bambu-green hover:text-bambu-green-light transition-colors ml-1`,children:e(`printers.bulk.selectAll`)})]}),children:(0,G.jsx)(`div`,{className:`grid gap-4 ${_>=3?`gap-6`:``} ${ot()}`,children:n.map(e=>(0,G.jsx)(jW,{printer:e,hideIfDisconnected:s,maintenanceInfo:Re[e.id],viewMode:O,cardSize:_,amsThresholds:ue?{humidityGood:Number(ue.ams_humidity_good)||40,humidityFair:Number(ue.ams_humidity_fair)||60,tempGood:Number(ue.ams_temp_good)||28,tempFair:Number(ue.ams_temp_fair)||35}:void 0,spoolmanEnabled:Ce,hasUnlinkedSpools:De,linkedSpools:ke,spoolmanUrl:Se?.url,spoolmanSyncMode:Te,onGetAssignment:Le,onUnassignSpool:(e,t,n)=>je.mutate({printerId:e,amsId:t,trayId:n}),spoolmanSpools:Me,spoolmanSlotAssignments:Pe,spoolmanLoading:Ne||Fe,onUnassignSpoolmanSpool:e=>Ie.mutate(e),timeFormat:ue?.time_format||`system`,cameraViewMode:ge,onOpenEmbeddedCamera:(e,t)=>H(n=>new Map(n).set(e,{id:e,name:t})),onSelectCameraViewMode:_e,checkPrinterFirmware:ue?.check_printer_firmware!==!1,dryingPresets:he,nozzleTempPresets:de,bedTempPresets:fe,chamberTempPresets:pe,fanSpeedPresets:me,requirePlateClear:ue?.require_plate_clear===!0,selectionMode:Xe,isSelected:He.has(e.id),onToggleSelect:Ze,onOpenCompactCard:M,aiDetectionEnabled:xe(e.id),aiDetection:be?.enabled?be.per_printer[String(e.id)]:void 0,aiLastError:be?.last_error??null},e.id))})},t)})}):(0,G.jsx)(`div`,{className:`grid gap-4 ${_>=3?`gap-6`:``} ${ot()}`,children:ut.map(e=>(0,G.jsx)(jW,{printer:e,hideIfDisconnected:s,maintenanceInfo:Re[e.id],viewMode:O,cardSize:_,spoolmanEnabled:Ce,hasUnlinkedSpools:De,linkedSpools:ke,spoolmanUrl:Se?.url,spoolmanSyncMode:Te,onGetAssignment:Le,onUnassignSpool:(e,t,n)=>je.mutate({printerId:e,amsId:t,trayId:n}),spoolmanSpools:Me,spoolmanSlotAssignments:Pe,spoolmanLoading:Ne||Fe,onUnassignSpoolmanSpool:e=>Ie.mutate(e),amsThresholds:ue?{humidityGood:Number(ue.ams_humidity_good)||40,humidityFair:Number(ue.ams_humidity_fair)||60,tempGood:Number(ue.ams_temp_good)||28,tempFair:Number(ue.ams_temp_fair)||35}:void 0,timeFormat:ue?.time_format||`system`,cameraViewMode:ge,onOpenEmbeddedCamera:(e,t)=>H(n=>new Map(n).set(e,{id:e,name:t})),onSelectCameraViewMode:_e,checkPrinterFirmware:ue?.check_printer_firmware!==!1,dryingPresets:he,nozzleTempPresets:de,bedTempPresets:fe,chamberTempPresets:pe,fanSpeedPresets:me,requirePlateClear:ue?.require_plate_clear===!0,selectionMode:Xe,isSelected:He.has(e.id),onToggleSelect:Ze,onOpenCompactCard:M,aiDetectionEnabled:xe(e.id),aiDetection:be?.enabled?be.per_printer[String(e.id)]:void 0,aiLastError:be?.last_error??null},e.id))}),_===2&&k!=null&&(0,G.jsxs)(`button`,{type:`button`,onClick:N,className:`fixed bottom-5 left-1/2 z-40 inline-flex -translate-x-1/2 items-center gap-2 rounded-full border px-4 py-2 text-sm font-medium shadow-xl transition-colors ${i}`,title:e(`common.back`,`Back`),children:[(0,G.jsx)(Lo,{className:`w-4 h-4`}),e(`common.back`,`Back`)]}),a&&(0,G.jsx)(xke,{onClose:()=>o(!1),onAdd:e=>Be.mutate(e),existingSerials:ce?.map(e=>e.serial_number)||[]}),Xe&&ce&&(0,G.jsx)(Nee,{selectedIds:He,printers:ce,onClose:Qe,onSelectAll:dt,onSelectByLocation:pt,onSelectByState:ft,onAction:et,actionPending:Je}),Ke===`stop`&&(0,G.jsx)(ef,{title:e(`printers.bulk.confirm.stopTitle`,{count:He.size}),message:e(`printers.bulk.confirm.stopMessage`,{count:He.size}),confirmText:e(`printers.bulk.confirm.stopButton`),variant:`danger`,isLoading:Je,onConfirm:()=>$e(`stop`),onCancel:()=>qe(null)}),Ke===`pause`&&(0,G.jsx)(ef,{title:e(`printers.bulk.confirm.pauseTitle`,{count:He.size}),message:e(`printers.bulk.confirm.pauseMessage`,{count:He.size}),confirmText:e(`printers.bulk.confirm.pauseButton`),isLoading:Je,onConfirm:()=>$e(`pause`),onCancel:()=>qe(null)}),Ke===`clearPlate`&&(0,G.jsx)(ef,{title:e(`printers.bulk.confirm.clearPlateTitle`,{count:He.size}),message:e(`printers.bulk.confirm.clearPlateMessage`,{count:He.size}),confirmText:e(`printers.bulk.confirm.clearPlateButton`),isLoading:Je,onConfirm:()=>$e(`clearPlate`),onCancel:()=>qe(null)}),Array.from(se.values()).map((e,t)=>(0,G.jsx)(Zse,{printerId:e.id,printerName:e.name,viewerIndex:t,onClose:()=>H(t=>{let n=new Map(t);return n.delete(e.id),n})},e.id))]})}function Dke({title:e,message:t,subtitle:n,closeText:r,variant:i=`error`,onClose:a}){let{t:o}=U(),s=r??o(`common.close`);return(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&a()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[a]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-[120]`,onClick:a,children:(0,G.jsx)(Pd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Id,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-dark ${i===`warning`?`text-yellow-600 dark:text-yellow-400`:`text-red-600 dark:text-red-400`}`,children:(0,G.jsx)(Iu,{className:`w-6 h-6`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-1`,children:e}),n&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2 truncate`,children:n}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm whitespace-pre-line break-words`,children:t})]})]}),(0,G.jsx)(`div`,{className:`flex mt-6`,children:(0,G.jsx)(Q,{onClick:a,className:`flex-1`,children:s})})]})})})}var MW=(0,y.createContext)(null),Oke=1500,kke=1e3,NW=e=>`slice-job-${e}`;function PW(e){try{return decodeURIComponent(e)}catch{return e}}function Ake(e){let t=Math.max(0,Math.floor(e));if(t<60)return`${t}s`;let n=Math.floor(t/60),r=t%60;return n<60?`${n}m ${r}s`:`${Math.floor(n/60)}h ${n%60}m`}function jke({children:e}){let{t}=U(),{showToast:n,showPersistentToast:r,dismissToast:i}=Hd(),a=co(),[o,s]=(0,y.useState)([]),[c,l]=(0,y.useState)(null),u=(0,y.useRef)([]);u.current=o;let d=(0,y.useRef)(new Map),f=(0,y.useRef)(new Map),p=(0,y.useRef)(new Map),m=(0,y.useRef)(new Set),h=(0,y.useCallback)(e=>{let n=d.current.get(e.id);if(n==null)return;let i=(Date.now()-n)/1e3,a=f.current.get(e.id)??`pending`,o=Ake(i),s=p.current.get(e.id)??null,c=s&&s.stage&&s.total_percent>0;if(a===`running`&&c){let n=PW(e.sourceName),i=s.stage,a=Math.min(100,Math.max(0,Math.round(s.total_percent))),c=typeof s.multi_plate_index==`number`&&typeof s.multi_plate_count==`number`&&s.multi_plate_count>1?t(`slice.runningWithProgressMultiPlate`,`Plate {{plateIndex}} of {{plateCount}} • {{name}} — {{stage}} ({{percent}}%) — {{elapsed}}`,{plateIndex:s.multi_plate_index,plateCount:s.multi_plate_count,name:n,stage:i,percent:a,elapsed:o}):t(`slice.runningWithProgress`,`{{name}} — {{stage}} ({{percent}}%) — {{elapsed}}`,{name:n,stage:i,percent:a,elapsed:o});r(NW(e.id),c,`loading`);return}let l=a===`pending`?`slice.queuedToast`:`slice.runningToast`,u=a===`pending`?`Queued: {{name}} — {{elapsed}}`:`Slicing {{name}} — {{elapsed}}`;r(NW(e.id),t(l,u,{name:PW(e.sourceName),elapsed:o}),`loading`)},[r,t]),g=(0,y.useCallback)((e,t,n)=>{s(r=>r.some(t=>t.id===e)?r:[...r,{id:e,kind:t,sourceName:n}]),m.current.delete(e),d.current.set(e,Date.now()),f.current.set(e,`pending`),p.current.set(e,null),h({id:e,kind:t,sourceName:n})},[h]),_=(0,y.useCallback)((e,r)=>{m.current.has(e.id)||(m.current.add(e.id),s(t=>t.filter(t=>t.id!==e.id)),d.current.delete(e.id),f.current.delete(e.id),p.current.delete(e.id),i(NW(e.id)),r.status===`completed`?(n(t(`slice.completedToast`,`Sliced {{name}}`,{name:PW(e.sourceName)}),`success`),r.result&&`external_write_fallback`in r.result&&r.result.external_write_fallback&&n(t(`slice.externalWriteFallbackToast`,`Saved to the internal library: the external folder could not be written to`),`warning`)):r.status===`failed`&&l({name:PW(e.sourceName),detail:r.error_detail||t(`slice.failed`)}),a.invalidateQueries({queryKey:[`library-files`]}),a.invalidateQueries({queryKey:[`archives`]}))},[i,a,n,t]);return(0,y.useEffect)(()=>{if(o.length===0)return;let e=!1,t=!1,n=setInterval(async()=>{if(!(e||t)){t=!0;try{let t=[...u.current];for(let n of t)try{let t=await Z.getSliceJob(n.id);if(e)return;f.current.set(n.id,t.status),t.progress&&p.current.set(n.id,t.progress),(t.status===`completed`||t.status===`failed`)&&_(n,t)}catch{}}finally{t=!1}}},Oke);return()=>{e=!0,clearInterval(n)}},[o.length,_]),(0,y.useEffect)(()=>{if(o.length===0)return;let e=setInterval(()=>{for(let e of u.current)h(e)},kke);return()=>clearInterval(e)},[o.length,h]),(0,G.jsxs)(MW.Provider,{value:{trackJob:g,activeJobs:o},children:[e,c&&(0,G.jsx)(Dke,{title:t(`slice.failedTitle`),subtitle:c.name,message:c.detail,onClose:()=>l(null)})]})}function FW(){let e=(0,y.useContext)(MW);if(!e)throw Error(`useSliceJobTracker must be used inside SliceJobTrackerProvider`);return e}var IW=1024;function Mke(){let[e,t]=(0,y.useState)(()=>typeof window<`u`?window.innerWidth>=IW:!1);return(0,y.useEffect)(()=>{let e=window.matchMedia(`(min-width: ${IW}px)`),n=e=>{t(e.matches)};return t(e.matches),e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}function LW({plates:e,onSelect:t,onClose:n}){let{t:r}=U();return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,onClick:n,children:(0,G.jsxs)(`div`,{className:`w-full max-w-3xl max-h-[85vh] flex flex-col rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary/60`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex-shrink-0 flex items-start justify-between gap-3 px-4 pt-4 pb-3 border-b border-bambu-dark-tertiary/40`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:r(`archives.platePicker.title`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`archives.platePicker.hint`)})]}),(0,G.jsx)(`button`,{onClick:n,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors`,"aria-label":r(`common.close`,`Close`),children:(0,G.jsx)(td,{className:`w-5 h-5`})})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:(0,G.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:e.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>t(e.index),className:`flex items-center gap-2 p-2 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray transition-colors text-left`,children:[e.has_thumbnail&&e.thumbnail_url!=null?(0,G.jsx)(`img`,{src:pd(e.thumbnail_url),alt:`Plate ${e.index}`,className:`w-12 h-12 rounded object-cover bg-bambu-dark-tertiary flex-shrink-0`}):(0,G.jsx)(`div`,{className:`w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center flex-shrink-0`,children:(0,G.jsx)(qc,{className:`w-5 h-5 text-bambu-gray`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:e.name?`${r(`archives.platePicker.plateLabel`,{index:e.index})} — ${e.name}`:r(`archives.platePicker.plateLabel`,{index:e.index})}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[e.objects.length>0?e.objects.slice(0,3).join(`, `)+(e.objects.length>3?`…`:``):e.object_count!=null&&e.object_count>0?r(`archives.platePicker.objectCount`,{count:e.object_count}):`${e.filaments.length} filament${e.filaments.length===1?``:`s`}`,e.print_time_seconds==null?``:` • ${np(e.print_time_seconds)}`]})]})]},e.index))})})]})})}var RW=e=>typeof e==`object`&&!!e&&`enumKey`in e,zW=`enum:`;function BW(e){if(typeof e==`number`)return e;if(typeof e==`boolean`)return+!!e;if(typeof e!=`string`)return;let t=Number.parseFloat(e);return Number.isFinite(t)?t:void 0}function VW(e){if(typeof e==`boolean`)return e;if(typeof e==`number`)return e!==0;if(e===`1`||e===`true`)return!0;if(e===`0`||e===`false`)return!1}function Nke(e,t){return{get:n=>{let r=e[n];if((r===void 0||r===``)&&(r=t[n]?.default),Array.isArray(r)&&(r=r[0]),typeof r==`boolean`||typeof r==`number`||typeof r==`string`)return r},has:e=>e in t}}var Pke=[`->`,`||`,`&&`,`==`,`!=`,`<=`,`>=`,`(`,`)`,`,`,`<`,`>`,`!`];function Fke(e){let t=[],n=0;for(;ne.startsWith(t,n));if(a){t.push({kind:`op`,value:a}),n+=a.length;continue}let o=/^[A-Za-z_][A-Za-z0-9_]*(::[A-Za-z_][A-Za-z0-9_]*)*/.exec(e.slice(n));if(o){t.push({kind:`id`,value:o[0]}),n+=o[0].length;continue}return}return t}var Ike=new Set([`opt_bool`,`opt_int`,`opt_float`,`opt_float_nullable`,`opt_int_nullable`,`opt_bool_nullable`,`opt_enum`,`opt_string`,`option`,`has`]),Lke=class e{tokens=[];pos=0;cfg;locals;schema;resolving;memo;constructor(e,t,n,r,i){this.cfg=e,this.locals=t,this.schema=n,this.resolving=r,this.memo=i}evaluate(e){let t=Fke(e);if(!t||t.length===0)return;this.tokens=t,this.pos=0;let n=this.parseOr();if(this.pos===this.tokens.length)return n}peek(){return this.tokens[this.pos]}eatOp(e){let t=this.peek();return t&&t.kind===`op`&&t.value===e?(this.pos+=1,!0):!1}parseOr(){let e=this.parseAnd();for(;this.eatOp(`||`);){let t=this.parseAnd(),n=VW(e),r=VW(t);e=n===!0||r===!0?!0:n===void 0||r===void 0?void 0:n||r}return e}parseAnd(){let e=this.parseComparison();for(;this.eatOp(`&&`);){let t=this.parseComparison(),n=VW(e),r=VW(t);e=n===!1||r===!1?!1:n===void 0||r===void 0?void 0:n&&r}return e}parseComparison(){let e=this.parseUnary();for(let t of[`==`,`!=`,`<=`,`>=`,`<`,`>`])if(this.eatOp(t))return Rke(e,this.parseUnary(),t,this.schema);return e}parseUnary(){if(this.eatOp(`!`)){let e=VW(this.parseUnary());return e===void 0?void 0:!e}return this.parsePrimary()}parsePrimary(){let e=this.peek();if(!e)return;if(e.kind===`num`||e.kind===`str`)return this.pos+=1,e.value;if(e.kind===`op`&&e.value===`(`){this.pos+=1;let e=this.parseOr();return this.eatOp(`)`)?e:void 0}if(e.kind!==`id`)return;if(this.pos+=1,e.value===`true`)return!0;if(e.value===`false`)return!1;if(e.value===`config`)return this.parseConfigAccess();let t=this.locals[e.value];return t===void 0?`${zW}${e.value}`:this.resolveLocal(e.value,t)}parseConfigAccess(){if(!this.eatOp(`->`))return;let e=this.peek();if(!e||e.kind!==`id`||!Ike.has(e.value))return;if(this.pos+=1,this.eatOp(`<`)){let e=1;for(;e>0;){let t=this.peek();if(!t)return;this.pos+=1,t.kind===`op`&&t.value===`<`&&(e+=1),t.kind===`op`&&t.value===`>`&&--e}}if(!this.eatOp(`(`))return;let t=this.peek();if(!t||t.kind!==`str`)return;this.pos+=1;let n=t.value;for(;this.eatOp(`,`);){let e=0;for(;;){let t=this.peek();if(!t)return;if(t.kind===`op`&&t.value===`(`&&(e+=1),t.kind===`op`&&t.value===`)`){if(e===0)break;--e}if(t.kind===`op`&&t.value===`,`&&e===0)break;this.pos+=1}}if(!this.eatOp(`)`))return;if(this.eatOp(`->`)){let e=this.peek();if(!e||e.kind!==`id`)return;this.pos+=1}if(e.value===`has`)return this.cfg.has(n);let r=this.cfg.get(n);return this.schema[n]?.enum_values?{enumKey:n,value:typeof r==`string`?r:void 0}:r}resolveLocal(t,n){let r=this.memo.get(t);if(r!==void 0||this.memo.has(t))return r;if(this.resolving.has(t))return;this.resolving.add(t);let i=new e(this.cfg,this.locals,this.schema,this.resolving,this.memo).evaluate(n);return this.resolving.delete(t),this.memo.set(t,i),i}};function Rke(e,t,n,r){let i=typeof e==`string`&&e.startsWith(zW)?e:typeof t==`string`&&t.startsWith(zW)?t:void 0;if(i!==void 0){if(n!==`==`&&n!==`!=`)return;let a=i===e?t:e;if(!RW(a))return;let o=r[a.enumKey]?.enum_values;if(!o||a.value===void 0)return;let s=zke(i.slice(5)).filter(e=>o.includes(e));if(s.length!==1)return;let c=s[0]===a.value;return n===`==`?c:!c}let a=RW(e)?e.value:e,o=RW(t)?t.value:t;if(n===`==`||n===`!=`){if(a===void 0||o===void 0)return;let e=typeof a==`string`||typeof o==`string`?String(a)===String(o):BW(a)===BW(o);return n===`==`?e:!e}let s=BW(a),c=BW(o);if(!(s===void 0||c===void 0)){if(n===`<`)return s`)return s>c;if(n===`>=`)return s>=c}}function zke(e){let t=e.includes(`::`)?e.slice(e.lastIndexOf(`::`)+2):e,n=[t,/^[a-z]+([A-Z].*)$/.exec(t)?.[1]].filter(e=>!!e),r=new Set;for(let e of n){let t=e.replace(/([a-z0-9])([A-Z])/g,`$1_$2`).toLowerCase();r.add(t),r.add(t.replace(/_/g,` `)),r.add(t.replace(/_/g,``))}return[...r]}function Bke(e,t,n){let r=Nke(e,t),i=new Map,a=new Set;for(let e of n.rules){let o=Vke(e.enable_if);if(o&&VW(new Lke(r,n.locals,t,new Set,i).evaluate(o))===!1)for(let t of e.fields)a.add(t)}return a}function Vke(e){let t=0;for(let n=0;nHke.has(e.type);function HW(e){if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(typeof e!=`string`)return;let t=Number.parseFloat(e);return Number.isFinite(t)?t:void 0}function Wke(e){let t=e.sidetext;if(!(!t||t.includes(`->`)||t.includes(`::`)))return t}function UW(e,t){let n=t===void 0?e.default:t;return n===void 0?``:Array.isArray(n)?n.map(String).join(`, `):typeof n==`boolean`?n?`1`:`0`:String(n)}function WW(e,t){if(Uke(e))return(Array.isArray(t)?t.map(String):String(t).split(`,`)).map(e=>e.trim()).filter(e=>e!==``);if(e.type===`coBool`)return typeof t==`boolean`?t?`1`:`0`:t===`1`||t===`true`||t===1?`1`:`0`;let n=String(t).trim();return e.type===`coPercent`?n.endsWith(`%`)?n:`${n}%`:n}function Gke(e,t){let n={};for(let[r,i]of Object.entries(e)){let e=t[r];e&&(n[r]=WW(e,i))}return n}function GW(e,t,n){if(t===void 0||t===``)return!1;let r=t=>{let n=WW(e,Array.isArray(t)?t.map(String).join(`, `):t);return Array.isArray(n)?n.join(`, `):n},i=r(t),a=n===void 0?e.default:n;return a===void 0?i!==``:i!==r(a)}var Kke=new Set([`support_filament`,`support_interface_filament`,`outer_wall_filament_id`,`inner_wall_filament_id`,`top_surface_filament_id`,`bottom_surface_filament_id`,`internal_solid_filament_id`,`sparse_infill_filament_id`]),qke=[`simple`,`advanced`,`expert`],KW={simple:0,advanced:1,expert:2,develop:3};function Jke({values:e,onChange:t,disabled:n=!1,sourceOverrides:r=[],sourceSelected:i,onToggleSource:a,filamentChoices:o,presetValues:s,presetValuesResolved:c=!0,presetValuesReason:l}){let{t:u}=U(),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(`simple`),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(``);(0,y.useEffect)(()=>{let e=!1;return Promise.all([Pt(()=>import(`./process-schema-CzfeynAH.js`),[]),Pt(()=>import(`./process-ui-tree-BWrKRLV6.js`),[]),Pt(()=>import(`./process-toggle-rules-DDBax3G5.js`),[])]).then(([t,n,r])=>{e||f({schema:t.default??t,tree:n.default??n,toggles:r.default??r})}),()=>{e=!0}},[]);let b=(0,y.useMemo)(()=>d?Bke(e,d.schema,d.toggles):new Set,[d,e]),x=(0,y.useMemo)(()=>new Map(r.map(e=>[e.key,e])),[r]),S=(0,y.useMemo)(()=>d?r.filter(e=>!d.schema[e.key]):[],[d,r]),C=e=>{if(!d)return;let n={};for(let[t,r]of Object.entries(e))d.schema[t]&&GW(d.schema[t],r,s?.[t])&&(n[t]=r);t(e,Gke(n,d.schema))},w=(t,n)=>{let r={...e};n===void 0?delete r[t]:r[t]=n,C(r)},T=(0,y.useMemo)(()=>{if(!d)return[];let e=e=>e.toLowerCase().replace(/[_\s]+/g,` `).trim(),t=e(_),n=e=>KW[d.schema[e]?.mode??`expert`]<=KW[p],r=(n,r,i)=>{if(!t)return!0;let a=d.schema[n];return[n,a?.label??``,a?.tooltip??``,r,i].some(n=>e(n).includes(t))};return d.tree.map(e=>({...e,groups:e.groups.map(t=>({...t,options:t.options.filter(i=>n(i)&&r(i,t.group,e.page))})).filter(e=>e.options.length>0)})).filter(e=>e.groups.length>0)},[d,p,_]),E=(0,y.useMemo)(()=>T.length===0||_.trim()?null:T.find(e=>e.page===h)??T[0],[T,h,_]),D=(0,y.useMemo)(()=>d?Object.keys(e).filter(t=>d.schema[t]&&GW(d.schema[t],e[t],s?.[t])).length:0,[d,e,s]);if(!d)return(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-8 text-sm text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),u(`slicerSettings.loading`,`Loading slicer settings...`)]});let O=E?[E]:T;return(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex overflow-hidden rounded border border-bambu-dark-tertiary`,children:qke.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>m(e),disabled:n,className:`px-2.5 py-1 text-xs capitalize transition-colors ${p===e?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:u(`slicerSettings.mode.${e}`,e)},e))}),(0,G.jsxs)(`div`,{className:`relative flex-1 min-w-[10rem]`,children:[(0,G.jsx)(Zl,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`search`,value:_,onChange:e=>v(e.target.value),disabled:n,placeholder:u(`slicerSettings.searchPlaceholder`,`Search settings`),className:`w-full rounded border border-bambu-dark-tertiary bg-bambu-dark pl-7 pr-2 py-1 text-xs text-white placeholder:text-bambu-gray/60 focus:border-bambu-green focus:outline-none disabled:opacity-40`})]}),D>0&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>C({}),disabled:n,className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-white`,children:[(0,G.jsx)(Ul,{className:`w-3 h-3`}),u(`slicerSettings.resetAll`,`Reset {{count}}`,{count:D})]})]}),!c&&(0,G.jsx)(`p`,{className:`rounded border border-amber-300 bg-amber-50 px-2 py-1 text-[0.7rem] text-amber-800 dark:border-amber-700/40 dark:bg-amber-900/20 dark:text-amber-200`,children:l===`sidecar_outdated`?u(`slicerSettings.presetValuesOutdatedSidecar`,`Showing slicer defaults: your slicer sidecar is older than this feature and can't report a preset's values. Update the sidecar image to see them. Anything you don't change still uses the preset.`):l===`not_configured`?u(`slicerSettings.presetValuesNotConfigured`,`Showing slicer defaults: no slicer sidecar is configured, so a preset's values can't be read. Anything you don't change still uses the preset.`):l===`sidecar_unavailable`?u(`slicerSettings.presetValuesSidecarUnavailable`,`Showing slicer defaults: the slicer sidecar did not answer, so a preset's values can't be read. Anything you don't change still uses the preset.`):u(`slicerSettings.presetValuesUnavailable`,`Showing slicer defaults: the picked preset's own values could not be read. Anything you don't change still uses the preset.`)}),!_.trim()&&(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:T.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>g(e.page),disabled:n,className:`px-2 py-1 text-xs rounded transition-colors ${E?.page===e.page?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`}`,children:e.page},e.page))}),O.length===0?(0,G.jsx)(`p`,{className:`py-6 text-center text-xs text-bambu-gray`,children:u(`slicerSettings.noMatches`,`No settings match this search.`)}):(0,G.jsxs)(`div`,{className:`flex flex-col gap-4 max-h-[22rem] lg:max-h-[58vh] overflow-y-auto pr-1`,children:[O.map(t=>(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[_.trim()&&(0,G.jsx)(`p`,{className:`text-[0.7rem] uppercase tracking-wide text-bambu-gray/70`,children:t.page}),t.groups.map(r=>(0,G.jsxs)(`fieldset`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`legend`,{className:`mb-1 text-xs font-medium text-white`,children:r.group}),r.options.map(t=>(0,G.jsx)(Yke,{optionKey:t,option:d.schema[t],value:e[t],onChange:e=>w(t,e),disabled:n||b.has(t),disabledBySlicer:b.has(t),source:x.get(t),sourceOn:i?.has(t)??!1,onToggleSource:a,filamentChoices:Kke.has(t)?o:void 0,presetValue:s?.[t]},t))]},`${t.page}:${r.group}`))]},t.page)),S.length>0&&!_.trim()&&(0,G.jsxs)(`fieldset`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`legend`,{className:`mb-1 text-xs font-medium text-white`,children:u(`slicerSettings.otherFromFile`,`Other settings from this file`)}),S.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-xs cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:i?.has(e.key)??!1,disabled:n||!a,onChange:t=>a?.(e.key,t.target.checked),className:`shrink-0 cursor-pointer disabled:opacity-40`}),(0,G.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[(0,G.jsx)(`span`,{className:`font-mono text-bambu-gray`,children:e.key}),(0,G.jsx)(`span`,{className:`ml-1.5 text-white`,children:qW(e.value)})]}),(e.printer_coupled||e.preset_defining)&&(0,G.jsx)(`span`,{className:`shrink-0 rounded bg-amber-100 px-1 py-0.5 text-[10px] text-amber-700 dark:bg-amber-500/20 dark:text-amber-400`,children:e.printer_coupled?u(`slicerSettings.fromFilePrinterCoupled`,`designer's printer`):u(`slicerSettings.fromFileOverridesPreset`,`overrides preset`)})]},e.key))]})]})]})}function Yke({optionKey:e,option:t,value:n,onChange:r,disabled:i,disabledBySlicer:a,source:o,sourceOn:s=!1,onToggleSource:c,filamentChoices:l,presetValue:u}){let{t:d}=U(),f=GW(t,n,u),p=Wke(t),m=n===void 0?s&&o?qW(o.value):UW(t,u):String(n);return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 group`,title:t.tooltip,children:[(0,G.jsxs)(`label`,{htmlFor:`slicer-opt-${e}`,className:`flex min-w-0 flex-1 items-center gap-1 text-xs ${a?`text-bambu-gray/40`:`text-bambu-gray`}`,children:[(0,G.jsx)(`span`,{className:`truncate`,title:t.label||e,children:t.label||e}),f&&(0,G.jsx)(`span`,{className:`shrink-0 text-bambu-green`,"aria-hidden":`true`,children:`•`}),o&&(0,G.jsx)(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[10px] ${o.printer_coupled||o.preset_defining?`bg-amber-100 text-amber-700 dark:bg-amber-500/20 dark:text-amber-400`:`bg-bambu-green/15 text-bambu-green`}`,title:o.printer_coupled?d(`slicerSettings.fromFilePrinterCoupledHint`,`Tuned for the printer this file was designed for -- may be wrong or out of range on yours.`):o.preset_defining?d(`slicerSettings.fromFileOverridesPresetHint`,`The file sets this to {{value}} where the preset you picked uses {{preset}}. Tick it only if the file should win.`,{value:qW(o.value),preset:UW(t,u)}):d(`slicerSettings.fromFileHint`,`The designer changed this in the source file. Its value is {{value}}.`,{value:qW(o.value)}),children:o.printer_coupled?d(`slicerSettings.fromFilePrinterCoupled`,`designer's printer`):o.preset_defining?d(`slicerSettings.fromFileOverridesPreset`,`overrides preset`):d(`slicerSettings.fromFile`,`from file`)})]}),(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`flex w-3 shrink-0 justify-center`,children:o&&c&&(0,G.jsx)(`input`,{type:`checkbox`,checked:s,disabled:i,onChange:t=>c(e,t.target.checked),"aria-label":d(`slicerSettings.useFromFile`,`Use the source file's value for {{option}}`,{option:t.label||e}),title:d(`slicerSettings.useFromFile`,`Use the source file's value for {{option}}`,{option:t.label||e}),className:`w-3 h-3 cursor-pointer disabled:opacity-40`})}),(0,G.jsx)(`div`,{className:`w-40`,children:(0,G.jsx)(Xke,{id:`slicer-opt-${e}`,option:t,current:m,onChange:r,disabled:i,filamentChoices:l})}),(0,G.jsx)(`span`,{className:`w-16 shrink-0 whitespace-nowrap text-[0.65rem] text-bambu-gray/60`,children:p??``}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>r(void 0),disabled:i||!f,"aria-label":d(`slicerSettings.resetOption`,`Reset to default`),className:`p-0.5 transition-opacity ${f?`text-bambu-gray hover:text-white`:`opacity-0 pointer-events-none`}`,children:(0,G.jsx)(Ul,{className:`w-3 h-3`})})]})]})}function qW(e){return Array.isArray(e)?e.map(e=>String(e)).join(`, `):e==null?``:String(e)}function Xke({id:e,option:t,current:n,onChange:r,disabled:i,filamentChoices:a}){let{t:o}=U(),s=`w-full rounded border border-bambu-dark-tertiary bg-bambu-dark px-1.5 py-0.5 text-xs text-white focus:border-bambu-green focus:outline-none disabled:opacity-40`;if(a&&a.length>0){let t=a.find(e=>String(e.index)===n);return(0,G.jsxs)(`div`,{className:`relative w-full`,children:[(0,G.jsxs)(`select`,{id:e,value:n,onChange:e=>r(e.target.value),disabled:i,className:`${s} w-full cursor-pointer appearance-none pr-5`,title:t?.label,children:[(0,G.jsx)(`option`,{value:`0`,children:o(`slicerSettings.filamentDefault`,`Default`)}),a.map(e=>(0,G.jsxs)(`option`,{value:String(e.index),children:[e.index,`: `,e.label]},e.index))]}),(0,G.jsx)(fs,{className:`pointer-events-none absolute right-1.5 top-1/2 h-3 w-3 -translate-y-1/2 text-bambu-gray`})]})}return t.type===`coBool`?(0,G.jsx)(`input`,{id:e,type:`checkbox`,checked:n===`1`||n===`true`,onChange:e=>r(e.target.checked),disabled:i,className:`w-3.5 h-3.5 cursor-pointer disabled:opacity-40`}):t.type===`coEnum`&&t.enum_values?(0,G.jsxs)(`div`,{className:`relative w-full`,children:[(0,G.jsx)(`select`,{id:e,value:n,onChange:e=>r(e.target.value),disabled:i,className:`${s} w-full cursor-pointer appearance-none pr-5`,children:t.enum_values.map((e,n)=>(0,G.jsx)(`option`,{value:e,children:t.enum_labels?.[n]??e},e))}),(0,G.jsx)(fs,{className:`pointer-events-none absolute right-1.5 top-1/2 h-3 w-3 -translate-y-1/2 text-bambu-gray`})]}):t.type===`coInt`||t.type===`coFloat`||t.type===`coPercent`?(0,G.jsx)(`input`,{id:e,type:`number`,value:n.replace(`%`,``),min:HW(t.min),max:HW(t.max),step:t.type===`coInt`?1:`any`,onChange:e=>r(e.target.value),disabled:i,className:s}):(0,G.jsx)(`input`,{id:e,type:`text`,value:n,onChange:e=>r(e.target.value),disabled:i,className:s})}var JW=[`local`,`orca_cloud`,`cloud`,`standard`],Zke={local:1.75,orca_cloud:1.5,cloud:1,standard:.5};function YW(e,t){for(let n of JW){let r=e[n][t];if(r.length>0)return{source:r[0].source,id:r[0].id}}return null}function XW(e,t,n){return t?e[t.source][n].find(e=>e.id===t.id)??null:null}function ZW(e,t,n){if(!n)return null;for(let r of JW){let i=e[r][t].find(e=>e.name===n);if(i)return{source:i.source,id:i.id}}return null}function Qke(e,t,n,r){let i=ZW(e,`process`,r);if(i){let r=XW(e,i,`process`);if(r&&iU(r,`process`,t,n)!==`mismatch`)return i}for(let r of[`match`,`unknown`])for(let i of JW)for(let a of e[i].process)if(iU(a,`process`,t,n)===r)return{source:a.source,id:a.id};return YW(e,`process`)}function $ke(e,t,n,r){let i=t.type.trim().toUpperCase(),a=cp(t.color),o=null,s=null;for(let c of JW)for(let l of e[c].filament){let e=0,u=(l.filament_type??``).trim().toUpperCase(),d=cp(l.filament_colour??``);i&&u&&i===u&&(e+=10),a&&d&&(d===a?e+=5:_p(l.filament_colour??``,t.color)&&(e+=2)),e+=Zke[c];let f={source:l.source,id:l.id};iU(l,`filament`,n,r)===`mismatch`?(s==null||e>s.score)&&(s={ref:f,score:e}):(o==null||e>o.score)&&(o={ref:f,score:e})}return o==null?s==null?YW(e,`filament`):s.ref:o.ref}function QW(e){return e?`${e.source}:${e.id}`:``}function eAe(e){if(!e)return null;let t=e.indexOf(`:`);if(t<0)return null;let n=e.slice(0,t),r=e.slice(t+1);return n!==`orca_cloud`&&n!==`cloud`&&n!==`local`&&n!==`standard`?null:{source:n,id:r}}function tAe({requestId:e,sourceName:t}){let{t:n}=U(),{showPersistentToast:r,dismissToast:i}=Hd(),[a,o]=(0,y.useState)(0),[s,c]=(0,y.useState)(null),l=t;try{l=decodeURIComponent(t)}catch{}(0,y.useEffect)(()=>{let e=Date.now(),t=setInterval(()=>o(Math.floor((Date.now()-e)/1e3)),1e3);return()=>clearInterval(t)},[]),(0,y.useEffect)(()=>{let t=!1,n=setInterval(async()=>{if(t)return;let n=await Z.getPreviewSliceProgress(e);!t&&n&&c(n)},1e3);return()=>{t=!0,clearInterval(n)}},[e]);let u=`slice-preview-${e}`;(0,y.useEffect)(()=>{let e=s&&s.stage&&s.total_percent>0,t=nAe(a);return e?r(u,n(`slice.previewWithProgress`,`Analyzing {{name}} — {{stage}} ({{percent}}%) — {{elapsed}}`,{name:l,stage:s.stage,percent:Math.min(100,Math.max(0,Math.round(s.total_percent))),elapsed:t}),`loading`):r(u,n(`slice.previewToast`,{name:l,elapsed:t}),`loading`),()=>{i(u)}},[a,s,l,r,i,n,u]);let d=s?.stage,f=s?.total_percent,p=d&&typeof f==`number`&&f>0?`${d} (${Math.min(100,Math.max(0,Math.round(f)))}%)`:n(`slice.analyzingPlateFilaments`);return(0,G.jsxs)(`div`,{className:`flex flex-col gap-1 text-bambu-gray text-sm py-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),p,(0,G.jsxs)(`span`,{className:`text-xs tabular-nums`,children:[a,`s`]})]}),a>=5&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray/70 pl-6`,children:n(`slice.analyzingPlateFilamentsHint`,`Running a preview slice to discover which AMS slots this plate uses. Cached after — re-opening is instant.`)})]})}function nAe(e){let t=Math.max(0,Math.floor(e));if(t<60)return`${t}s`;let n=Math.floor(t/60),r=t%60;return n<60?`${n}m ${r}s`:`${Math.floor(n/60)}h ${n%60}m`}function $W({source:e,onClose:t}){let{t:n}=U(),{trackJob:r}=FW(),i=co(),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)([]),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(new Set),[O,k]=(0,y.useState)({}),[A,j]=(0,y.useState)({}),[M,N]=(0,y.useState)(!1),P=Mke(),F=P||M,I=K({queryKey:[`slicer-pipelines`],queryFn:()=>Z.listSlicerPipelines(),staleTime:6e4}),[L,R]=(0,y.useState)(!1),[z,B]=(0,y.useState)(``),{showToast:V}=Hd(),ee=q({mutationFn:e=>Z.createSlicerPipeline(e),onSuccess:()=>{i.invalidateQueries({queryKey:[`slicer-pipelines`]}),V(n(`slice.pipelines.toast.saved`,`Pipeline saved`),`success`),R(!1),B(``)},onError:e=>{V(e.message||n(`slice.pipelines.toast.saveFailed`,`Save failed`),`error`)}}),te=K({queryKey:[`slicePlates`,e.kind,e.id],queryFn:async()=>e.kind===`libraryFile`?Z.getLibraryFilePlates(e.id):Z.getArchivePlates(e.id),staleTime:6e4}),ne=!!te.data?.is_multi_plate&&(te.data?.plates?.length??0)>1,re=ne&&p==null,ie=p??1,ae=(0,y.useMemo)(()=>{let t=typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2)}`;return`${e.kind}-${e.id}-p${ie}-${t}`},[e.kind,e.id,ie]),oe=K({queryKey:[`sliceFilamentReqs`,e.kind,e.id,ie],queryFn:async()=>e.kind===`libraryFile`?Z.getLibraryFileFilamentRequirements(e.id,ie,ae,!0):Z.getArchiveFilamentRequirements(e.id,ie,ae,!0),enabled:!re,staleTime:6e4}),se=(0,y.useMemo)(()=>{let e=oe.data?.filaments??[],t=e.length>0?e:[{slot_id:1,type:``,color:``,used_grams:0,used_meters:0}];return h?t.map(e=>({...e,used_in_plate:!0})):t},[h,oe.data]),H=K({queryKey:[`slicerPresets`],queryFn:()=>Z.getSlicerPresets(),staleTime:6e4,enabled:!te.isLoading&&!re}),[ce,le]=(0,y.useState)(!1),ue=async()=>{if(!ce){le(!0);try{let e=await Z.getSlicerPresets({refresh:!0});i.setQueryData([`slicerPresets`],e)}catch{i.invalidateQueries({queryKey:[`slicerPresets`]})}finally{le(!1)}}},de=K({queryKey:[`slicerPrinterModels`],queryFn:Z.getSlicerPrinterModels,staleTime:1/0}),fe=(0,y.useMemo)(()=>!H.data||!a?null:XW(H.data,a,`printer`)?.name??null,[H.data,a]),pe=(0,y.useMemo)(()=>QH(de.data??{}),[de.data]),me=K({queryKey:[`slicer-preset-values`,s?.source,s?.id],queryFn:()=>Z.getSlicerPresetValues(s),enabled:s!=null,staleTime:5*6e4}),he=me.data?.values,ge=me.data?.resolved??me.isLoading,_e=me.data?.reason??(me.isError?`sidecar_unavailable`:void 0),ve=(0,y.useMemo)(()=>{let e=H.data;return se.map((t,r)=>{let i=l[r]??null,a=e&&i?XW(e,i,`filament`):null;return{index:r+1,label:a?.name||t.type||n(`slice.filamentSlotUnset`,`not set`),color:t.color||void 0}})},[se,l,H.data,n]),ye=te.data?.embedded_printer??null,be=(0,y.useMemo)(()=>te.data?.design_overrides??[],[te.data]),xe=te.data?.embedded_process??null,Se=(0,y.useMemo)(()=>{if(!ye||!xe||!fe)return!1;let e=e=>e.replace(/^#\s*/,``).trim().toLowerCase();return e(fe)===e(ye)},[ye,xe,fe]);(0,y.useEffect)(()=>{Se||x(!1)},[Se]),(0,y.useEffect)(()=>{D(new Set(be.filter(e=>!e.printer_coupled&&!e.preset_defining).map(e=>e.key)))},[be]),(0,y.useEffect)(()=>{let e=H.data;e&&(a??o(ZW(e,`printer`,ye)??YW(e,`printer`)))},[H.data,ye]),(0,y.useEffect)(()=>{let e=H.data;e&&c(t=>{if(t){let n=XW(e,t,`process`);if(n&&iU(n,`process`,fe,pe)!==`mismatch`)return t}return Qke(e,fe,pe,xe)})},[H.data,fe,pe,xe]),(0,y.useEffect)(()=>{let e=H.data;e&&u(t=>se.map((n,r)=>{let i=t[r]??null;if(i){let t=XW(e,i,`filament`);if(t&&iU(t,`filament`,fe,pe)!==`mismatch`)return i}return $ke(e,{type:n.type,color:n.color},fe,pe)}))},[H.data,se,fe,pe]);let Ce=q({mutationFn:async t=>{let n=we(t);return e.kind===`libraryFile`?Z.sliceLibraryFile(e.id,n):Z.sliceArchive(e.id,n)},onSuccess:n=>{r(n.job_id,e.kind,e.filename),t()},onError:e=>{f(e instanceof Error?e.message:String(e))}});function we(e){if(!a||!s||l.length===0||l.some(e=>e==null))throw Error(n(`slice.allPresetsRequired`));return{printer_preset:a,process_preset:s,filament_preset:l[0],filament_presets:l,...e==null?{}:{plate:e},..._==null?{}:{bed_type:_},...b&&Se?{use_embedded_settings:!0}:{},...!b&&E.size>0?{design_overrides:[...E]}:{},...!b&&Object.keys(O).length>0?{process_overrides:A}:{},...S?{auto_orient:!0}:{},...w?{auto_arrange:!0}:{}}}let Te=a!=null&&s!=null&&oe.isSuccess&&l.length>0&&l.every(e=>e!=null),Ee=Ce.isPending,De=te.data?.plates?.length??0,Oe=ne&&De>1&&!re;return re&&te.data?(0,G.jsx)(LW,{plates:te.data.plates,onSelect:e=>m(e),onClose:t}):(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,onClick:()=>{Ee||t()},children:(0,G.jsxs)(`div`,{className:`w-full max-w-xl lg:max-w-5xl max-h-[85vh] flex flex-col rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary/60`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex-shrink-0 flex items-start justify-between gap-3 px-4 pt-4 pb-3 border-b border-bambu-dark-tertiary/40`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`h3`,{className:`text-white font-medium flex items-center gap-2`,children:[(0,G.jsx)(Ls,{className:`w-4 h-4`}),n(`slice.title`)]}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1 truncate`,title:e.filename,children:[e.filename,p==null?``:` • ${n(`archives.platePicker.plateLabel`,{index:p})}`]})]}),(0,G.jsx)(`button`,{onClick:t,disabled:Ee,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors disabled:opacity-50`,"aria-label":n(`common.close`),children:(0,G.jsx)(td,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[(te.isLoading||H.isLoading)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),n(`slice.loadingPresets`)]}),H.isError&&(0,G.jsx)(`div`,{className:`text-sm text-red-700 dark:text-red-400`,role:`alert`,children:n(`slice.presetsLoadFailed`,`Failed to load presets. Open Settings → Profiles to import them, or sign in to Bambu Cloud.`)}),H.data&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,G.jsx)(eG,{status:H.data.cloud_status,cloudName:`bambu`}),(0,G.jsx)(eG,{status:H.data.orca_cloud_status,cloudName:`orca`})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:ue,disabled:ce||Ee,className:`flex-shrink-0 inline-flex items-center gap-1 px-2 py-1 rounded-md text-xs text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary/40 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,title:n(`slice.refreshPresetsTitle`),"aria-label":n(`slice.refreshPresets`),children:[(0,G.jsx)(Vl,{className:`w-3.5 h-3.5 ${ce?`animate-spin`:``}`}),n(`slice.refreshPresets`)]})]}),(0,G.jsxs)(`div`,{className:`lg:grid lg:grid-cols-[minmax(0,20rem)_minmax(0,1fr)] lg:gap-5 lg:items-start`,children:[(0,G.jsxs)(`div`,{className:`space-y-4 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-2 py-1.5 rounded-md bg-bambu-dark/40 border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`span`,{className:`text-xs font-medium text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(Ls,{className:`w-3.5 h-3.5`}),` `,n(`slice.pipelines.label`,`Pipeline`)]}),(0,G.jsxs)(`select`,{value:``,disabled:Ee||(I.data?.pipelines.length??0)===0,onChange:e=>{let t=parseInt(e.target.value,10);if(Number.isNaN(t))return;let r=I.data?.pipelines.find(e=>e.id===t);r&&(o(r.printer_preset),c(r.process_preset),v(r.bed_type),u(e=>{let t=e.length>0?[...e]:r.filament_presets.map(()=>null);for(let e=0;e(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),L?(0,G.jsxs)(`div`,{className:`flex items-center gap-1 flex-1 min-w-[16ch]`,children:[(0,G.jsx)(`input`,{autoFocus:!0,value:z,onChange:e=>B(e.target.value),placeholder:n(`slice.pipelines.namePlaceholder`,`Pipeline name`),"aria-label":n(`slice.pipelines.nameAria`,`New pipeline name`),className:`flex-1 text-xs px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{let e=z.trim();if(!e||!a||!s)return;let t=l.filter(e=>e!==null);t.length!==0&&ee.mutate({name:e,printer_preset:a,process_preset:s,filament_presets:t,bed_type:_})},disabled:ee.isPending||!z.trim(),className:`text-xs px-2 py-1 bg-bambu-green hover:bg-bambu-green/80 text-white rounded disabled:opacity-50`,children:ee.isPending?(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin`}):n(`common.save`,`Save`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{R(!1),B(``)},className:`text-xs px-2 py-1 text-bambu-gray hover:text-white`,children:n(`common.cancel`,`Cancel`)})]}):(0,G.jsx)(`button`,{type:`button`,onClick:()=>{B(``),R(!0)},disabled:Ee||!a||!s||l.length===0||l.some(e=>e===null),className:`text-xs px-2 py-1 bg-bambu-green/20 hover:bg-bambu-green/30 text-bambu-green border border-bambu-green/40 rounded disabled:opacity-50 disabled:cursor-not-allowed`,title:n(`slice.pipelines.saveTitle`,`Save the current four-slot selection as a reusable pipeline`),children:n(`slice.pipelines.saveButton`,`Save as pipeline`)})]}),(0,G.jsx)(tG,{label:n(`slice.printer`),slot:`printer`,data:H.data,value:a,onChange:o,disabled:Ee||b}),Se&&(0,G.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-bambu-gray cursor-pointer select-none`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:b,onChange:e=>x(e.target.checked),disabled:Ee,className:`mt-0.5 cursor-pointer`}),(0,G.jsxs)(`span`,{children:[n(`slice.useEmbedded`),(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:n(`slice.useEmbeddedHint`)})]})]}),(0,G.jsx)(tG,{label:n(`slice.process`),slot:`process`,data:H.data,value:s,onChange:c,disabled:Ee||b,selectedPrinterName:fe,compatIndex:pe}),(0,G.jsx)(iAe,{value:_,onChange:v,disabled:Ee||b}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-bambu-gray cursor-pointer select-none`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:S,onChange:e=>C(e.target.checked),disabled:Ee,className:`mt-0.5 cursor-pointer`}),(0,G.jsxs)(`span`,{children:[n(`slice.autoOrient`),(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:n(`slice.autoOrientHint`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-bambu-gray cursor-pointer select-none`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:w,onChange:e=>T(e.target.checked),disabled:Ee,className:`mt-0.5 cursor-pointer`}),(0,G.jsxs)(`span`,{children:[n(`slice.autoArrange`),(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:n(`slice.autoArrangeHint`)})]})]})]}),oe.isLoading?(0,G.jsx)(tAe,{requestId:ae,sourceName:e.filename}):se.map((e,t)=>{let r=e.used_in_plate!==!1,i=se.length>1?n(`slice.filamentSlot`,{index:t+1,type:e.type}):n(`slice.filament`);return(0,G.jsx)(tG,{label:r?i:`${i} ${n(`slice.notUsedByPlate`)}`,slot:`filament`,data:H.data,value:l[t]??null,onChange:e=>u(n=>{let r=n.length===se.length?[...n]:se.map((e,t)=>n[t]??null);return r[t]=e,r}),disabled:Ee||!r||b,swatchColor:se.length>1?e.color:void 0,selectedPrinterName:fe,compatIndex:pe},`filament-${t}`)})]}),(0,G.jsx)(`div`,{className:`mt-4 lg:mt-0 min-w-0`,children:(0,G.jsxs)(`div`,{className:`rounded border border-bambu-dark-tertiary p-3 ${b?`opacity-60`:``}`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>N(e=>!e),"aria-expanded":F,disabled:P,className:`flex w-full items-center justify-between gap-2 text-left lg:cursor-default`,children:[(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[n(`slice.processSettings`,`Process settings`),(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:b?n(`slice.processSettingsEmbedded`,`Not used while "Use the file's built-in settings" is on -- the file's own settings drive this slice.`):n(`slice.processSettingsHint`,`Adjust the picked preset for this slice. Anything you don't touch stays as the preset defines it.`)})]}),(0,G.jsx)(`span`,{className:`shrink-0 text-xs text-bambu-gray`,children:b?n(`slice.processSettingsInactive`,`Inactive`):Object.keys(A).length>0?n(`slice.processSettingsChanged`,`{{count}} changed`,{count:Object.keys(A).length}):n(`slice.processSettingsUnchanged`,`Preset defaults`)})]}),F&&(0,G.jsx)(`div`,{className:`mt-3 border-t border-bambu-dark-tertiary pt-3`,children:(0,G.jsx)(Jke,{values:O,onChange:(e,t)=>{k(e),j(t)},disabled:Ee||b,filamentChoices:ve,presetValues:he,presetValuesResolved:ge,presetValuesReason:_e,sourceOverrides:be,sourceSelected:E,onToggleSource:(e,t)=>D(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})})})]})})]})]}),d&&(0,G.jsx)(`div`,{className:`text-sm text-red-700 dark:text-red-400 bg-red-900/20 border border-red-900/40 rounded p-2`,role:`alert`,children:d})]}),(0,G.jsxs)(`div`,{className:`flex-shrink-0 flex justify-end gap-2 px-4 py-3 border-t border-bambu-dark-tertiary/40`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:t,disabled:Ee,className:`px-3 py-1.5 text-sm rounded-md border border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray transition-colors disabled:opacity-50`,children:n(`common.cancel`)}),Oe&&(0,G.jsxs)(`label`,{className:`flex items-center gap-2 mr-auto text-sm text-bambu-gray cursor-pointer select-none`,title:n(`slice.actionAllTitle`,{count:De}),children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),disabled:Ee,className:`cursor-pointer`}),n(`slice.allPlatesToggle`,{count:De})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{f(null);let e=h?0:p;Ce.mutate(e)},disabled:!Te||Ee,className:`px-3 py-1.5 text-sm rounded-md bg-bambu-green hover:bg-bambu-green/90 text-bambu-dark font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2`,children:Ee?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),n(`slice.enqueuing`)]}):h?n(`slice.actionAll`,{count:De}):n(`slice.action`)})]})]})})}function eG({status:e,cloudName:t=`bambu`}){let{t:n}=U();if(e===`ok`||e===`not_authenticated`)return null;let r=t===`orca`?{expired:{key:`slice.orcaCloud.expired`,fallback:`Orca Cloud session expired — sign in again to refresh your Orca presets.`},unreachable:{key:`slice.orcaCloud.unreachable`,fallback:`Orca Cloud is unreachable right now. Other presets still work.`}}:{expired:{key:`slice.cloud.expired`,fallback:`Bambu Cloud session expired — sign in again to refresh your cloud presets.`},unreachable:{key:`slice.cloud.unreachable`,fallback:`Bambu Cloud is unreachable right now. Local and standard presets still work.`}},{tone:i,icon:a}={expired:{tone:`border-amber-300 dark:border-amber-700/40 bg-amber-50 dark:bg-amber-900/20 text-amber-800 dark:text-amber-200`,icon:js},unreachable:{tone:`border-bambu-dark-tertiary/40 bg-bambu-dark text-bambu-gray`,icon:js}}[e],{key:o,fallback:s}=r[e];return(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-xs rounded-md border p-2 ${i}`,role:`status`,children:[(0,G.jsx)(a,{className:`w-4 h-4 flex-shrink-0 mt-0.5`}),(0,G.jsx)(`span`,{children:n(o,s)})]})}var rAe=[{value:`Cool Plate`,labelKey:`slice.bedType.coolPlate`,fallback:`Cool Plate`},{value:`Cool Plate (SuperTack)`,labelKey:`slice.bedType.coolPlateSuperTack`,fallback:`Cool Plate SuperTack`},{value:`Engineering Plate`,labelKey:`slice.bedType.engineering`,fallback:`Engineering Plate`},{value:`High Temp Plate`,labelKey:`slice.bedType.highTemp`,fallback:`High Temp Plate`},{value:`Textured PEI Plate`,labelKey:`slice.bedType.texturedPEI`,fallback:`Textured PEI Plate`},{value:`Smooth PEI Plate`,labelKey:`slice.bedType.smoothPEI`,fallback:`Smooth PEI Plate`}];function iAe({value:e,onChange:t,disabled:n}){let{t:r}=U();return(0,G.jsxs)(`label`,{className:`block`,children:[(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:r(`slice.bedType.label`)}),(0,G.jsxs)(`select`,{value:e??``,onChange:e=>t(e.target.value===``?null:e.target.value),disabled:n,className:`w-full px-3 py-2 rounded-md bg-bambu-dark border border-bambu-dark-tertiary text-white text-sm focus:outline-none focus:border-bambu-gray disabled:opacity-50`,children:[(0,G.jsx)(`option`,{value:``,children:r(`slice.bedType.auto`)}),rAe.map(e=>(0,G.jsx)(`option`,{value:e.value,children:r(e.labelKey,e.fallback)},e.value))]})]})}function tG({label:e,slot:t,data:n,value:r,onChange:i,disabled:a,swatchColor:o,selectedPrinterName:s,compatIndex:c}){let{t:l}=U(),[u,d]=(0,y.useState)(!1),f=(0,y.useId)(),{sections:p,otherEntries:m}=(0,y.useMemo)(()=>{let e=[{key:`local`,label:`slice.tier.local`,fallback:`Imported`},{key:`orca_cloud`,label:`slice.tier.orcaCloud`,fallback:`Orca Cloud`},{key:`cloud`,label:`slice.tier.cloud`,fallback:`Bambu Cloud`},{key:`standard`,label:`slice.tier.standard`,fallback:`Standard`}],r=t!==`printer`,i=[],a=[];for(let{key:o,label:u,fallback:d}of e){let e=n[o][t];if(!r){e.length>0&&i.push({tierLabel:l(u,d),entries:e});continue}let f=[];for(let n of e)iU(n,t,s??null,c??cOe)===`mismatch`?a.push(n):f.push(n);f.length>0&&i.push({tierLabel:l(u,d),entries:f})}return{sections:i,otherEntries:a}},[n,t,l,s,c]),h=QW(r),g=(0,y.useMemo)(()=>u?m:m.filter(e=>`${e.source}:${e.id}`===h),[u,m,h]),_=m.length-g.length,v=p.reduce((e,t)=>e+t.entries.length,0)+g.length;return(0,G.jsxs)(`div`,{className:`block`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray mb-1`,children:[o&&(0,G.jsx)(`span`,{className:`inline-block w-3 h-3 rounded-full border border-bambu-dark-tertiary`,style:{backgroundColor:o||`transparent`},"aria-hidden":!0}),(0,G.jsx)(`label`,{htmlFor:f,children:e}),(_>0||u)&&(0,G.jsxs)(`span`,{className:`ml-auto flex items-center gap-1.5 font-normal`,children:[_>0&&(0,G.jsx)(`span`,{className:`text-bambu-gray/60`,children:l(`slice.presetsHidden`,`{{count}} hidden`,{count:_})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>d(e=>!e),disabled:a,className:`text-bambu-green hover:underline disabled:opacity-50 disabled:no-underline`,children:u?l(`slice.showFewerPresets`,`Show fewer`):l(`slice.showAllPresets`,`Show all`)})]})]}),(0,G.jsxs)(`select`,{id:f,value:QW(r),onChange:e=>i(eAe(e.target.value)),disabled:a||v===0,className:`w-full px-3 py-2 rounded-md bg-bambu-dark border border-bambu-dark-tertiary text-white text-sm focus:outline-none focus:border-bambu-gray disabled:opacity-50`,children:[(0,G.jsx)(`option`,{value:``,children:l(v===0?`slice.noPresetsForSlot`:`slice.selectPreset`)}),p.map(e=>(0,G.jsx)(`optgroup`,{label:e.tierLabel,children:e.entries.map(e=>(0,G.jsx)(`option`,{value:`${e.source}:${e.id}`,children:e.name},`${e.source}:${e.id}`))},e.tierLabel)),g.length>0&&(0,G.jsx)(`optgroup`,{label:l(`slice.otherPrinters`),children:g.map(e=>(0,G.jsx)(`option`,{value:`${e.source}:${e.id}`,children:e.name},`${e.source}:${e.id}`))})]})]})}function nG({source:e,onClose:t}){let{t:n}=U(),r=co(),{showToast:i}=Hd(),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(1),{trackJob:d}=FW(),{data:f,isLoading:p}=K({queryKey:[`slicer-pipelines`],queryFn:()=>Z.listSlicerPipelines()}),{data:m}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),{data:h}=K({queryKey:[`app-settings`],queryFn:()=>Z.getSettings()}),g=h?.pipeline_max_copies??50,_={kind:e.kind,id:e.id},v=q({mutationFn:e=>Z.checkPipelineEligibility(e,_)}),b=q({mutationFn:({pipelineId:e,force:t})=>Z.runPipeline(e,_,t,l),onSuccess:a=>{r.invalidateQueries({queryKey:[`slicer-pipelines`]}),r.invalidateQueries({queryKey:[`pipeline-runs`]}),a.slice_job_id&&d(a.slice_job_id,e.kind,e.filename),i(n(`library.runWithPipeline.toast.started`,`Pipeline run started`),`success`),t()},onError:e=>{i(e.message||n(`library.runWithPipeline.toast.failed`,`Could not start run`),`error`)}}),x=f?.pipelines??[],S=(m??[]).reduce((e,t)=>(e[t.id]=t,e),{});return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/60 flex items-center justify-center p-4`,onClick:t,role:`dialog`,"aria-modal":`true`,"aria-label":n(`library.runWithPipeline.modalTitle`,`Run with pipeline`),children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl w-full max-w-md max-h-[80vh] flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`h3`,{className:`text-sm font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Ml,{className:`w-4 h-4 text-bambu-green`}),a&&s?n(`library.runWithPipeline.confirmTitle`,`Confirm run`):n(`library.runWithPipeline.modalTitle`,`Run with pipeline`)]}),(0,G.jsx)(`button`,{type:`button`,onClick:t,"aria-label":n(`common.close`,`Close`),className:`text-bambu-gray hover:text-white`,children:(0,G.jsx)(td,{className:`w-4 h-4`})})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-3`,children:a&&s?(0,G.jsx)(oAe,{pipeline:a,report:s,source:e,onBack:()=>{o(null),c(null)},onConfirm:()=>{a&&b.mutate({pipelineId:a.id,force:!0})},running:b.isPending}):(0,G.jsx)(aAe,{source:e,pipelines:x,printerById:S,loading:p||v.isPending,onPick:async e=>{if(!(e.target_printer_id||e.target_kind===`printer_class`&&e.target_model_class)){i(n(`library.runWithPipeline.noTargetMessage`,`This pipeline has no target printer set. Open it in Settings to pick one.`),`error`);return}o(e);try{let t=await v.mutateAsync(e.id);c(t),t.ok&&b.mutate({pipelineId:e.id,force:!1})}catch{o(null)}},copies:l,maxCopies:g,onCopiesChange:u})})]})})}function aAe({source:e,pipelines:t,printerById:n,loading:r,onPick:i,copies:a,maxCopies:o,onCopiesChange:s}){let{t:c}=U();return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[c(`library.runWithPipeline.sourceHint`,`Source`),`:`,` `,(0,G.jsx)(`span`,{className:`text-white`,children:e.filename})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`label`,{className:`text-xs text-bambu-gray`,htmlFor:`run-pipeline-copies`,children:[c(`library.runWithPipeline.copies`,`Copies`),`:`]}),(0,G.jsx)(`input`,{id:`run-pipeline-copies`,type:`number`,min:1,max:o,value:a,onChange:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||s(Math.max(1,Math.min(o,t)))},"aria-label":c(`library.runWithPipeline.copies`,`Copies`),className:`w-20 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:c(`library.runWithPipeline.copiesHint`,`max {{n}}`,{n:o})})]}),r&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),c(`library.runWithPipeline.loading`,`Loading…`)]}),!r&&t.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:c(`library.runWithPipeline.empty`,`No pipelines saved yet. Open the Slice dialog and click "Save as pipeline" to create one.`)}),!r&&t.length>0&&(0,G.jsx)(`ul`,{className:`space-y-1.5`,"aria-label":c(`library.runWithPipeline.pipelineListAria`,`Available pipelines`),children:t.map(e=>{let t=e.target_kind===`printer_class`,r=e.target_printer_id?n[e.target_printer_id]?.name:null,a=t&&e.target_model_class?c(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}):null;return(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(e),disabled:!(e.target_printer_id||t&&e.target_model_class),className:`w-full text-left px-3 py-2 rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 hover:bg-bambu-dark-tertiary disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ls,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(Ll,{className:`w-3 h-3`}),a?(0,G.jsx)(`span`,{children:a}):r?(0,G.jsx)(`span`,{children:r}):(0,G.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:c(`library.runWithPipeline.noTarget`,`No target printer set`)})]})]})},e.id)})})]})}function oAe({pipeline:e,report:t,source:n,onBack:r,onConfirm:i,running:a}){let{t:o}=U();return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[(0,G.jsxs)(`p`,{children:[o(`library.runWithPipeline.confirmIntro`,`Pre-flight found issues with this run`),`:`]}),(0,G.jsxs)(`p`,{className:`mt-1`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[o(`library.runWithPipeline.sourceHint`,`Source`),`: `]}),(0,G.jsx)(`span`,{className:`text-white`,children:n.filename})]}),(0,G.jsxs)(`p`,{children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[o(`library.runWithPipeline.pipelineHint`,`Pipeline`),`: `]}),(0,G.jsx)(`span`,{className:`text-white`,children:e.name})]}),t.target_printer_name&&(0,G.jsxs)(`p`,{children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[o(`library.runWithPipeline.targetHint`,`Target`),`: `]}),(0,G.jsx)(`span`,{className:`text-white`,children:t.target_printer_name})]})]}),(0,G.jsx)(`ul`,{className:`space-y-1.5`,children:t.issues.map((e,t)=>(0,G.jsxs)(`li`,{className:`flex items-start gap-2 text-xs`,children:[(0,G.jsx)(Iu,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:(0,G.jsx)(sAe,{issue:e})})]},t))}),(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:r,disabled:a,className:`px-3 py-1.5 text-xs text-bambu-gray hover:text-white`,children:o(`common.back`,`Back`)}),(0,G.jsxs)(`button`,{type:`button`,onClick:i,disabled:a,className:`px-3 py-1.5 text-xs bg-amber-500 hover:bg-amber-600 text-white rounded disabled:opacity-50 flex items-center gap-1`,children:[a?(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin`}):(0,G.jsx)(Ml,{className:`w-3 h-3`}),o(`library.runWithPipeline.runAnyway`,`Run anyway`)]})]})]})}function sAe({issue:e}){let{t}=U();switch(e.kind){case`printer_not_set`:return(0,G.jsx)(G.Fragment,{children:t(`library.runWithPipeline.issue.printerNotSet`,`No target printer set on this pipeline.`)});case`printer_not_found`:return(0,G.jsx)(G.Fragment,{children:t(`library.runWithPipeline.issue.printerNotFound`,`Target printer no longer exists.`)});case`printer_disabled`:return(0,G.jsx)(G.Fragment,{children:t(`library.runWithPipeline.issue.printerDisabled`,`Target printer is disabled.`)});case`printer_offline`:return(0,G.jsx)(G.Fragment,{children:t(`library.runWithPipeline.issue.printerOffline`,`Target printer is offline.`)});case`filament_type_mismatch`:return(0,G.jsx)(G.Fragment,{children:t(`library.runWithPipeline.issue.filamentType`,`Filament slot {{slot}}: expected {{expected}}, AMS has {{actual}}`,{slot:(e.slot_index??0)+1,expected:e.expected??`?`,actual:e.actual??`?`})});case`filament_color_mismatch`:return(0,G.jsx)(G.Fragment,{children:t(`library.runWithPipeline.issue.filamentColor`,`Filament slot {{slot}}: colour differs (expected {{expected}}, AMS has {{actual}})`,{slot:(e.slot_index??0)+1,expected:e.expected??`?`,actual:e.actual??`?`})});case`ams_slot_missing`:return(0,G.jsx)(G.Fragment,{children:t(`library.runWithPipeline.issue.amsSlotMissing`,`AMS slot {{slot}} not available on this printer`,{slot:(e.slot_index??0)+1})});case`filament_unverified`:return(0,G.jsx)(G.Fragment,{children:t(`library.runWithPipeline.issue.filamentUnverified`,`Filament slot {{slot}} comes from a cloud / standard preset and could not be statically verified.`,{slot:(e.slot_index??0)+1})});default:return(0,G.jsx)(G.Fragment,{children:e.kind})}}function rG(e,t){return e??t??`bambu_studio`}var iG=[`3mf`,`stl`,`step`,`stp`],aG=[`3mf`,`stl`];function cAe(e){let t=(e||``).toLowerCase();return iG.includes(t)}function oG(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)?!1:iG.some(e=>t.endsWith(`.${e}`))}function sG(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)?!1:aG.some(e=>t.endsWith(`.${e}`))}function lAe(){let e=navigator.userAgent.toLowerCase(),t=navigator.platform?.toLowerCase()||``;return e.includes(`win`)||t.includes(`win`)?`windows`:e.includes(`mac`)||t.includes(`mac`)?`macos`:e.includes(`linux`)||t.includes(`linux`)?`linux`:`unknown`}function cG(e,t=`bambu_studio`){let n,r=encodeURIComponent(e);n=t===`orcaslicer`?`orcaslicer://open?file=${r}`:lAe()===`macos`?`bambustudioopen://${r}`:`bambustudio://open?file=${r}`;let i=document.createElement(`a`);i.href=n,i.style.display=`none`,document.body.appendChild(i),i.click(),document.body.removeChild(i)}function uAe(e){let t=(e||``).toLowerCase();return aG.includes(t)}var dAe=[[`projects`],[`project`],[`project-archives`],[`project-timeline`],[`project-file-progress`]];function fAe(e){return Promise.all(dAe.map(t=>e.invalidateQueries({queryKey:[...t]})))}function lG(e){return Promise.all([e.invalidateQueries({queryKey:[`archives`]}),fAe(e)])}function pAe(e,t){if(t===void 0)return e;let n=new Set([t]),r=!0;for(;r;){r=!1;for(let t of e)t.parent_id!==null&&n.has(t.parent_id)&&!n.has(t.id)&&(n.add(t.id),r=!0)}return e.filter(e=>!n.has(e.id))}function uG(e,t){return e.filter(e=>e.status!==`archived`||e.id===t)}function dG({onFiles:e,onRejected:t,extensions:n,disabled:r=!1}){let[i,a]=(0,y.useState)(!1),o=(0,y.useRef)(e),s=(0,y.useRef)(t),c=(0,y.useRef)(n);(0,y.useEffect)(()=>{o.current=e},[e]),(0,y.useEffect)(()=>{s.current=t},[t]),(0,y.useEffect)(()=>{c.current=n},[n]);let l=(0,y.useCallback)(e=>{r||(e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&a(!0))},[r]),u=(0,y.useCallback)(e=>{r||(e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&a(!0))},[r]),d=(0,y.useCallback)(e=>{if(r)return;e.preventDefault();let t=e.currentTarget,n=e.relatedTarget;(!n||!t.contains(n))&&a(!1)},[r]),f=(0,y.useCallback)(e=>{if(r)return;e.preventDefault(),a(!1);let t=Array.from(e.dataTransfer.files);if(t.length===0)return;let n=c.current,i=n&&n.length>0?t.filter(e=>n.some(t=>e.name.toLowerCase().endsWith(t))):t;i.length>0?o.current(i):s.current?.()},[r]);return(0,y.useEffect)(()=>{if(!i)return;let e=()=>a(!1),t=t=>{t.key===`Escape`&&e()};return document.addEventListener(`drop`,e),document.addEventListener(`dragend`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`drop`,e),document.removeEventListener(`dragend`,e),document.removeEventListener(`keydown`,t)}},[i]),{isDraggingOver:i,dragHandlers:{onDragOver:l,onDragEnter:u,onDragLeave:d,onDrop:f}}}function mAe({onClose:e,initialFiles:t}){let{t:n}=U(),r=co(),{showToast:i}=Hd(),a=(0,y.useRef)(null),[o,s]=(0,y.useState)(()=>t?.filter(e=>e.name.endsWith(`.3mf`)).map(e=>({file:e,status:`pending`}))||[]),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(null);(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]);let f=q({mutationFn:e=>Z.uploadArchivesBulk(e),onSuccess:e=>{d(e),r.invalidateQueries({queryKey:[`archives`]}),r.invalidateQueries({queryKey:[`archiveStats`]}),s(t=>t.map(t=>{let n=e.results.find(e=>e.filename===t.file.name),r=e.errors.find(e=>e.filename===t.file.name);return n?{...t,status:`success`,archiveId:n.id}:r?{...t,status:`error`,error:r.error}:t})),e.failed===0?i(`${e.uploaded} file${e.uploaded===1?``:`s`} uploaded`):e.uploaded===0?i(`Failed to upload ${e.failed} file${e.failed===1?``:`s`}`,`error`):i(`${e.uploaded} uploaded, ${e.failed} failed`,`warning`)},onError:()=>{s(e=>e.map(e=>({...e,status:`error`,error:`Upload failed`}))),i(`Upload failed`,`error`)}}),p=(0,y.useCallback)(e=>{e.preventDefault(),l(!0)},[]),m=(0,y.useCallback)(e=>{e.preventDefault(),l(!1)},[]),h=(0,y.useCallback)(e=>{e.preventDefault(),l(!1);let t=Array.from(e.dataTransfer.files).filter(e=>e.name.endsWith(`.3mf`));t.length>0&&s(e=>[...e,...t.map(e=>({file:e,status:`pending`}))])},[]),g=(0,y.useCallback)(e=>{let t=Array.from(e.target.files||[]).filter(e=>e.name.endsWith(`.3mf`));t.length>0&&s(e=>[...e,...t.map(e=>({file:e,status:`pending`}))]),a.current&&(a.current.value=``)},[]),_=(0,y.useCallback)(e=>{s(t=>t.filter((t,n)=>n!==e))},[]),v=()=>{if(o.length===0)return;let e=o.filter(e=>e.status===`pending`);e.length!==0&&(s(e=>e.map(e=>e.status===`pending`?{...e,status:`uploading`}:e)),f.mutate(e.map(e=>e.file)))},b=o.filter(e=>e.status===`pending`).length,x=f.isPending;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,G.jsx)(Pd,{className:`w-full max-w-2xl max-h-[90vh] flex flex-col`,children:(0,G.jsxs)(Id,{className:`p-0 flex flex-col h-full`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:n(`uploadModal.title`)}),(0,G.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(td,{className:`w-5 h-5`})})]}),(0,G.jsx)(`div`,{className:`p-4`,children:(0,G.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:p,onDragLeave:m,onDrop:h,children:[(0,G.jsx)(Bu,{className:`w-12 h-12 mx-auto mb-4 text-bambu-gray`}),(0,G.jsx)(`p`,{className:`text-white mb-2`,children:n(`uploadModal.dragDrop`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm mb-4`,children:n(`uploadModal.or`)}),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>a.current?.click(),disabled:x,children:n(`uploadModal.browseFiles`)}),(0,G.jsx)(`input`,{ref:a,type:`file`,accept:`.3mf`,multiple:!0,className:`hidden`,onChange:g})]})}),(0,G.jsx)(`div`,{className:`px-4 pb-4`,children:(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`uploadModal.extractionInfo`)})}),o.length>0&&(0,G.jsx)(`div`,{className:`px-4 pb-4 max-h-60 overflow-y-auto`,children:(0,G.jsx)(`div`,{className:`space-y-2`,children:o.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(fc,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`flex-1 text-white text-sm truncate`,children:e.file.name}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[(e.file.size/(1024*1024)).toFixed(1),` MB`]}),e.status===`pending`&&(0,G.jsx)(`button`,{onClick:()=>_(t),className:`text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,disabled:x,children:(0,G.jsx)(td,{className:`w-4 h-4`})}),e.status===`uploading`&&(0,G.jsx)(Y,{className:`w-4 h-4 text-bambu-green animate-spin`}),e.status===`success`&&(0,G.jsx)(bs,{className:`w-4 h-4 text-bambu-green`}),e.status===`error`&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs text-red-700 dark:text-red-400`,children:e.error}),(0,G.jsx)(vs,{className:`w-4 h-4 text-red-600 dark:text-red-400`})]})]},`${e.file.name}-${t}`))})}),u&&(0,G.jsx)(`div`,{className:`px-4 pb-4`,children:(0,G.jsx)(`div`,{className:`p-3 bg-bambu-dark rounded-lg`,children:(0,G.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,G.jsx)(`span`,{className:`text-bambu-green`,children:u.uploaded}),` `,n(`uploadModal.uploaded`),u.failed>0&&(0,G.jsxs)(G.Fragment,{children:[`, `,(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:u.failed}),` `,n(`uploadModal.failed`)]})]})})}),(0,G.jsxs)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,className:`flex-1`,children:n(u?`common.close`:`common.cancel`)}),!u&&(0,G.jsx)(Q,{onClick:v,disabled:b===0||x,className:`flex-1`,children:x?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),n(`uploadModal.uploading`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Bu,{className:`w-4 h-4`}),n(`uploadModal.upload`),` `,b>0&&`(${b})`]})})]})]})})})}var hAe=365;function gAe({onClose:e,initialDays:t}){let{t:n}=U(),r=co(),{showToast:i}=Hd(),[a,o]=(0,y.useState)(t??hAe),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(a);(0,y.useEffect)(()=>{let e=window.setTimeout(()=>u(a),300);return()=>window.clearTimeout(e)},[a]);let d=K({queryKey:[`archive-purge-preview`,l,s],queryFn:()=>Z.previewArchivePurge(l,s),enabled:l>=1}),f=q({mutationFn:()=>Z.executeArchivePurge(a,s),onSuccess:t=>{i(n(`archivePurge.toast.success`,{count:t.deleted}),`success`),r.invalidateQueries({queryKey:[`archives`]}),r.invalidateQueries({queryKey:[`archive-stats`]}),e()},onError:e=>i(e.message||n(`archivePurge.toast.failed`),`error`)});(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!f.isPending&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,f.isPending]);let p=d.data,m=p?.count??0,h=p?.total_bytes??0,g=m>0&&!f.isPending;return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg shadow-xl max-w-lg w-full`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,G.jsx)(Nu,{className:`w-5 h-5`}),n(`archivePurge.title`)]}),(0,G.jsx)(`button`,{onClick:e,className:`text-gray-400 hover:text-gray-600 dark:hover:text-gray-200`,"aria-label":n(`common.close`),disabled:f.isPending,children:(0,G.jsx)(td,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:n(`archivePurge.description`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`archive-purge-days`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:n(`archivePurge.ageLabel`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`input`,{id:`archive-purge-days`,type:`number`,min:1,max:3650,value:a,onChange:e=>o(Math.max(1,Math.min(3650,parseInt(e.target.value||`0`,10)||0))),className:`w-24 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,G.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:n(`archivePurge.days`)})]})]}),(0,G.jsxs)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/30 p-3`,children:[(0,G.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-gray-600 dark:text-gray-300 mb-2`,children:n(`archivePurge.effectsTitle`)}),(0,G.jsxs)(`ul`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1 list-disc pl-4`,children:[(0,G.jsx)(`li`,{children:n(`archivePurge.effect1`)}),(0,G.jsx)(`li`,{children:n(`archivePurge.effect2`)}),(0,G.jsx)(`li`,{children:n(`archivePurge.effect3`)}),(0,G.jsx)(`li`,{children:n(`archivePurge.effect4`)})]})]}),(0,G.jsx)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 p-3`,children:d.isLoading||d.isFetching?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),` `,n(`archivePurge.previewLoading`)]}):d.isError?(0,G.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:d.error?.message??n(`archivePurge.previewFailed`)}):(0,G.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:n(`archivePurge.previewSummary`,{count:m,size:Bd(h)})}),p?.sample_filenames&&p.sample_filenames.length>0&&(0,G.jsxs)(`ul`,{className:`mt-2 text-xs text-gray-600 dark:text-gray-400 space-y-0.5 list-disc pl-4`,children:[p.sample_filenames.map(e=>(0,G.jsx)(`li`,{className:`truncate`,children:e},e)),m>p.sample_filenames.length&&(0,G.jsx)(`li`,{className:`list-none italic text-gray-500`,children:n(`archivePurge.andMore`,{count:m-p.sample_filenames.length})})]})]})}),(0,G.jsxs)(`label`,{className:`flex gap-2 items-start rounded border border-gray-200 dark:border-gray-700 px-3 py-2 cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800/50`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked),disabled:f.isPending,className:`mt-0.5 shrink-0`}),(0,G.jsxs)(`span`,{className:`text-xs text-gray-700 dark:text-gray-300`,children:[(0,G.jsx)(`span`,{className:`font-medium block mb-0.5`,children:n(`archivePurge.purgeStatsLabel`)}),(0,G.jsx)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:n(`archivePurge.purgeStatsHint`)})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 items-start text-xs text-amber-700 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 rounded px-3 py-2`,children:[(0,G.jsx)(Iu,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:n(`archivePurge.warning`)})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,disabled:f.isPending,children:n(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,disabled:!g,onClick:()=>f.mutate(),children:f.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-1`}),n(`archivePurge.purging`)]}):n(`archivePurge.confirmCta`,{count:m})})]})]})})}function _Ae(e){if(!e||e<=0)return`—`;let t=Math.floor(e/3600),n=Math.floor(e%3600/60);return t>0?`${t}h ${n}m`:`${n}m`}function vAe(e){if(!e)return`—`;let t=Xf(e);return t?t.toLocaleString():`—`}function fG({archiveId:e}){let{t}=U(),{data:n,isLoading:r}=K({queryKey:[`archive-runs`,e],queryFn:()=>Z.getArchiveRuns(e)});if(r)return(0,G.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,G.jsx)(Y,{className:`w-5 h-5 text-bambu-gray animate-spin`})});let i=n?.items||[];return i.length===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:t(`archives.runLog.empty`)}):(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`th`,{className:`text-left py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.date`)}),(0,G.jsx)(`th`,{className:`text-left py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.status`)}),(0,G.jsx)(`th`,{className:`text-right py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.duration`)}),(0,G.jsx)(`th`,{className:`text-right py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.filament`)}),(0,G.jsx)(`th`,{className:`text-right py-1.5 font-medium`,children:t(`archives.runLog.col.cost`)})]})}),(0,G.jsx)(`tbody`,{children:i.map(e=>{let n=e.status===`completed`?`text-bambu-green`:e.status===`failed`?`text-red-700 dark:text-red-400`:`text-bambu-gray`;return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/40 last:border-0`,children:[(0,G.jsx)(`td`,{className:`py-1.5 pr-2 text-bambu-gray-light`,children:vAe(e.started_at||e.created_at)}),(0,G.jsxs)(`td`,{className:`py-1.5 pr-2 font-medium ${n}`,children:[t(`archives.runLog.status.${e.status}`,{defaultValue:e.status}),e.failure_reason&&(0,G.jsx)(`span`,{className:`block text-[10px] text-bambu-gray font-normal`,children:t(`editArchive.failureReasons.${e.failure_reason}`,{defaultValue:e.failure_reason})})]}),(0,G.jsx)(`td`,{className:`py-1.5 pr-2 text-right text-bambu-gray-light`,children:_Ae(e.duration_seconds)}),(0,G.jsx)(`td`,{className:`py-1.5 pr-2 text-right text-bambu-gray-light`,children:e.filament_used_grams==null?`—`:`${e.filament_used_grams.toFixed(1)} g`}),(0,G.jsx)(`td`,{className:`py-1.5 text-right text-bambu-gray-light`,children:e.cost==null?`—`:e.cost.toFixed(2)})]},e.id)})})]})})}var pG=[`adhesionFailure`,`spaghettiDetached`,`layerShift`,`cloggedNozzle`,`filamentRunout`,`warping`,`stringing`,`underExtrusion`,`powerFailure`,`userCancelled`,`other`],yAe=[`completed`,`failed`,`aborted`,`printing`],mG=1e5;function hG({archive:e,onClose:t,existingTags:n=[]}){let{t:r}=U();(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let i=co(),[a,o]=(0,y.useState)(e.print_name||``),[s,c]=(0,y.useState)(e.printer_id),[l,u]=(0,y.useState)(e.project_id??null),[d,f]=(0,y.useState)(e.notes||``),[p,m]=(0,y.useState)(e.tags||``),[h,g]=(0,y.useState)(()=>{let t=e.failure_reason||``;return t?pG.includes(t)?t:pG.find(e=>r(`editArchive.failureReasons.${e}`)===t)||``:``}),[_,v]=(0,y.useState)(e.status),[b,x]=(0,y.useState)(e.quantity??1),[S,C]=(0,y.useState)(e.filament_used_grams==null?``:String(e.filament_used_grams)),[w,T]=(0,y.useState)(e.photos||[]),[E,D]=(0,y.useState)(e.external_url||``),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(!1),M=(0,y.useRef)(null),N=(0,y.useRef)(null),P=(0,y.useRef)(null),{data:F}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:I}=K({queryKey:[`projects`],queryFn:()=>Z.getProjects(),select:e=>[...e].sort((e,t)=>e.name.localeCompare(t.name))}),L=(0,y.useMemo)(()=>uG(I??[],e.project_id),[I,e.project_id]),{data:R}=K({queryKey:[`tags`],queryFn:Z.getTags,enabled:n.length===0}),z=n.length>0?n:R?.map(e=>e.name)||[],B=p.split(`,`).map(e=>e.trim()).filter(Boolean),V=p.includes(`,`)?p.substring(p.lastIndexOf(`,`)+1).trim().toLowerCase():p.trim().toLowerCase(),ee=z.filter(e=>!B.includes(e)&&(V===``||e.toLowerCase().includes(V))),te=e=>{let t;t=V&&!z.includes(V)?p.includes(`,`)?p.substring(0,p.lastIndexOf(`,`)).split(`,`).map(e=>e.trim()).filter(Boolean):[]:B,t.includes(e)||m([...t,e].join(`, `)),P.current!==null&&clearTimeout(P.current),M.current?.focus()},ne=e=>{m(B.filter(t=>t!==e).join(`, `))},re=q({mutationFn:t=>Z.updateArchive(e.id,t),onSuccess:()=>{lG(i),i.invalidateQueries({queryKey:[`archive-runs`,e.id]}),t()}}),ie=async t=>{let n=t.target.files?.[0];if(n){k(!0);try{T((await Z.uploadArchivePhoto(e.id,n)).photos),i.invalidateQueries({queryKey:[`archives`]})}catch(e){console.error(`Failed to upload photo:`,e)}finally{k(!1),N.current&&(N.current.value=``)}}},ae=async t=>{try{T((await Z.deleteArchivePhoto(e.id,t)).photos||[]),i.invalidateQueries({queryKey:[`archives`]})}catch(e){console.error(`Failed to delete photo:`,e)}};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`editArchive.title`)}),(0,G.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(td,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let n={print_name:a||void 0,printer_id:s,project_id:l,notes:d||void 0,tags:p||void 0,quantity:b,external_url:E||null};_!==e.status&&(n.status=_);let r=S.trim(),i=r===``?null:Number(r),o=i!==null&&!Number.isFinite(i),c=i===null?null:Math.min(Math.max(i,0),mG),u=e.filament_used_grams??null;!o&&c!==u&&(n.filament_used_grams=c),_===`failed`||_===`aborted`?n.failure_reason=h||void 0:(e.status===`failed`||e.status===`aborted`)&&(n.failure_reason=null),re.mutate(n)},className:`p-6 space-y-4 overflow-y-auto flex-1`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`archives.runLog.title`)}),(0,G.jsx)(fG,{archiveId:e.id})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.name`)}),(0,G.jsx)(`input`,{type:`text`,value:a,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`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.printer`)}),(0,G.jsxs)(`select`,{value:s??``,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:[(0,G.jsx)(`option`,{value:``,children:r(`editArchive.noPrinter`)}),F?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(gc,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.project`)]}),(0,G.jsxs)(`select`,{value:l??``,onChange:e=>u(e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:``,children:r(`editArchive.noProject`)}),L.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(Pc,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.itemsPrinted`)]}),(0,G.jsx)(`input`,{type:`number`,min:1,value:b,onChange:e=>x(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`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`editArchive.itemsPrintedHelp`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,htmlFor:`archive-filament-grams`,children:[(0,G.jsx)(Yu,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.filamentUsed`)]}),(0,G.jsx)(`input`,{id:`archive-filament-grams`,type:`text`,inputMode:`decimal`,value:S,onChange:e=>{let t=e.target.value.replace(`,`,`.`);(t===``||/^\d*\.?\d*$/.test(t))&&C(t)},onBlur:()=>C(e=>{let t=Number(e);return e===``||!Number.isFinite(t)?``:String(Math.min(t,mG))}),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.filamentUsedPlaceholder`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`editArchive.filamentUsedHelp`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.notes`)}),(0,G.jsx)(`textarea`,{value:d,onChange:e=>f(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`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(Xc,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.externalLink`)]}),(0,G.jsx)(`input`,{type:`url`,value:E,onChange:e=>D(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,placeholder:`https://printables.com/model/...`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`editArchive.externalLinkHelp`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.tags`)}),B.length>0&&(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:B.map(e=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 bg-bambu-dark-tertiary rounded text-sm text-white`,children:[(0,G.jsx)(Tu,{className:`w-3 h-3`}),e,(0,G.jsx)(`button`,{type:`button`,onClick:()=>ne(e),className:`ml-0.5 text-bambu-gray hover:text-white`,children:(0,G.jsx)(td,{className:`w-3 h-3`})})]},e))}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{ref:M,type:`text`,value:p,onChange:e=>m(e.target.value),onFocus:()=>{P.current!==null&&clearTimeout(P.current),j(!0)},onBlur:()=>{P.current=window.setTimeout(()=>j(!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:B.length>0?r(`editArchive.addMoreTags`):r(`editArchive.tagsPlaceholder`)}),A&&ee.length>0&&(0,G.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:[(0,G.jsxs)(`div`,{className:`p-2 text-xs text-bambu-gray border-b border-bambu-dark-tertiary`,children:[V?r(`editArchive.matchingTags`,{query:V}):r(`editArchive.existingTags`),` `,r(`editArchive.clickToAdd`)]}),(0,G.jsx)(`div`,{className:`p-2 flex flex-wrap gap-1.5`,children:ee.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>te(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))})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.status`)}),(0,G.jsx)(`select`,{value:_,onChange:e=>{v(e.target.value),e.target.value===`completed`&&g(``)},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:yAe.map(e=>(0,G.jsx)(`option`,{value:e,children:r(`editArchive.statuses.${e}`)},e))})]}),(_===`failed`||_===`aborted`)&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`failure-reason-select`,className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.failureReason`)}),(0,G.jsxs)(`select`,{id:`failure-reason-select`,value:h,onChange:e=>g(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:``,children:r(`editArchive.selectReason`)}),pG.map(e=>(0,G.jsx)(`option`,{value:e,children:r(`editArchive.failureReasons.${e}`)},e))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(as,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.photos`)]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-2`,children:[w.map(t=>(0,G.jsxs)(`div`,{className:`relative group`,children:[(0,G.jsx)(`img`,{src:Z.getArchivePhotoUrl(e.id,t),alt:r(`editArchive.printResult`),className:`w-20 h-20 object-cover rounded-lg border border-bambu-dark-tertiary`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>ae(t),className:`absolute -top-1 -right-1 p-1 bg-red-500 rounded-full can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity`,children:(0,G.jsx)(Nu,{className:`w-3 h-3 text-white`})})]},t)),(0,G.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:[(0,G.jsx)(`input`,{ref:N,type:`file`,accept:`image/jpeg,image/png,image/webp`,onChange:ie,className:`hidden`,disabled:O}),O?(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,G.jsx)(Pl,{className:`w-6 h-6 text-bambu-gray`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`editArchive.photosHelp`)})]}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:r(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:re.isPending,className:`flex-1`,children:[(0,G.jsx)(Kl,{className:`w-4 h-4`}),re.isPending?r(`common.saving`):r(`common.save`)]})]})]})]})})}function gG({archiveId:e,archiveName:t,onClose:n}){let{t:r}=U();return(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-2xl max-h-[85vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(Rc,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,title:t||``,children:r(`archives.runLog.modalTitle`,{name:t||r(`archives.runLog.modalTitleFallback`)})})]}),(0,G.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:r(`common.close`),children:(0,G.jsx)(td,{className:`w-5 h-5`})})]}),(0,G.jsx)(`div`,{className:`p-6 overflow-y-auto flex-1`,children:(0,G.jsx)(fG,{archiveId:e})})]})})}function _G({isOpen:e,onClose:t,columns:n,defaultColumns:r,onSave:i}){let{t:a}=U(),[o,s]=(0,y.useState)(n),[c,l]=(0,y.useState)(null),u=(0,y.useRef)(null);if((0,y.useEffect)(()=>{e&&s(n.map(e=>({...e})))},[e,n]),(0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),!e)return null;let d=e=>{s(t=>t.map((t,n)=>n===e?{...t,visible:!t.visible}:t))},f=(e,t)=>{t<0||t>=o.length||s(n=>{let r=[...n],[i]=r.splice(e,1);return r.splice(t,0,i),r})},p=(e,t)=>{u.current=t,l(t),e.dataTransfer.effectAllowed=`move`},m=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=u.current;n!==null&&n!==t&&(f(n,t),u.current=t,l(t))},h=e=>{e.preventDefault()},g=()=>{u.current=null,l(null)},_=()=>{s(r.map(e=>({...e})))},v=()=>{i(o),t()},b=o.filter(e=>e.visible).length;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,G.jsx)(Pd,{className:`w-full max-w-md max-h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Id,{className:`p-6 flex flex-col min-h-0`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:a(`inventory.configureColumns`)}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:[a(`inventory.configureColumnsDesc`),(0,G.jsxs)(`span`,{className:`ml-2 text-bambu-gray/60`,children:[`(`,b,` `,a(`inventory.of`),` `,o.length,` `,a(`inventory.visible`),`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-1 overflow-y-auto flex-1 min-h-0 pr-1`,children:o.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-lg border transition-colors ${c===t?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-tertiary/50`} ${e.visible?``:`opacity-50`}`,draggable:!0,onDragStart:e=>p(e,t),onDragOver:e=>m(e,t),onDrop:h,onDragEnd:g,children:[(0,G.jsx)(`div`,{className:`cursor-grab text-bambu-gray/50 hover:text-bambu-gray`,children:(0,G.jsx)(Ac,{className:`w-4 h-4`})}),(0,G.jsx)(`span`,{className:`flex-1 font-medium text-sm text-white`,children:e.label}),(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,G.jsx)(`button`,{onClick:()=>f(t,t-1),disabled:t===0,className:`p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed`,title:a(`inventory.moveUp`),children:(0,G.jsx)(hs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>f(t,t+1),disabled:t===o.length-1,className:`p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed`,title:a(`inventory.moveDown`),children:(0,G.jsx)(fs,{className:`w-4 h-4`})})]}),(0,G.jsx)(`button`,{onClick:()=>d(t),className:`p-1.5 rounded transition-colors ${e.visible?`text-bambu-green hover:bg-bambu-green/10`:`text-bambu-gray/50 hover:bg-bambu-dark-secondary`}`,title:e.visible?a(`inventory.hideColumn`):a(`inventory.showColumn`),children:e.visible?(0,G.jsx)(ic,{className:`w-4 h-4`}):(0,G.jsx)(rc,{className:`w-4 h-4`})})]},e.id))}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:_,className:`mr-auto`,children:[(0,G.jsx)(Ul,{className:`w-4 h-4`}),a(`inventory.reset`)]}),(0,G.jsx)(Q,{variant:`secondary`,onClick:t,children:a(`inventory.cancel`)}),(0,G.jsx)(Q,{onClick:v,children:a(`inventory.applyChanges`)})]})]})})})}function bAe({selectedIds:e,existingTags:t,onClose:n}){let r=co(),{showToast:i}=Hd(),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(new Set),[l,u]=(0,y.useState)(`add`);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let d=q({mutationFn:async()=>{let t=Array.from(s),n=0;for(let r of e)try{let e=await Z.getArchive(r),i=e.tags?e.tags.split(`,`).map(e=>e.trim()).filter(Boolean):[],a;a=l===`add`?[...new Set([...i,...t])]:i.filter(e=>!s.has(e)),await Z.updateArchive(r,{tags:a.join(`, `)}),n++}catch(e){throw console.error(`Failed to update archive ${r}:`,e),Error(`Failed on archive ${r}: ${e instanceof Error?e.message:`Unknown error`}`)}return{count:n,mode:l,tags:t}},onSuccess:({count:e,mode:t,tags:a})=>{r.invalidateQueries({queryKey:[`archives`]}),i(`${t===`add`?`Added`:`Removed`} ${a.length} tag${a.length===1?``:`s`} ${t===`add`?`to`:`from`} ${e} archive${e===1?``:`s`}`),n()},onError:e=>{i(e.message||`Failed to update tags`,`error`)}}),f=e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},p=()=>{a.trim()&&!s.has(a.trim())&&(c(e=>new Set([...e,a.trim()])),o(``))};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,G.jsx)(Pd,{className:`w-full max-w-md`,children:(0,G.jsxs)(Id,{className:`p-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Tu,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:l===`add`?`Add Tags`:`Remove Tags`})]}),(0,G.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(td,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[l===`add`?`Add`:`Remove`,` tags for `,e.length,` selected archive`,e.length===1?``:`s`]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{size:`sm`,variant:l===`add`?`primary`:`secondary`,onClick:()=>u(`add`),children:`Add Tags`}),(0,G.jsx)(Q,{size:`sm`,variant:l===`remove`?`primary`:`secondary`,onClick:()=>u(`remove`),children:`Remove Tags`})]}),l===`add`&&(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.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:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),p())}}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:p,disabled:!a.trim(),children:(0,G.jsx)(Pl,{className:`w-4 h-4`})})]}),t.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:`Existing tags:`}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t.map(e=>(0,G.jsx)(`button`,{onClick:()=>f(e),className:`px-2 py-1 rounded text-sm transition-colors ${s.has(e)?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray-light hover:bg-bambu-dark`}`,children:e},e))})]}),s.size>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:[`Tags to `,l===`add`?`add`:`remove`,`:`]}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Array.from(s).map(e=>(0,G.jsxs)(`span`,{className:`px-2 py-1 rounded text-sm flex items-center gap-1 ${l===`add`?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`}`,children:[e,(0,G.jsx)(`button`,{onClick:()=>f(e),className:`hover:opacity-70`,children:(0,G.jsx)(td,{className:`w-3 h-3`})})]},e))})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:n,className:`flex-1`,children:`Cancel`}),(0,G.jsx)(Q,{onClick:()=>d.mutate(),disabled:s.size===0||d.isPending,className:`flex-1`,children:d.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),`Processing...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Tu,{className:`w-4 h-4`}),l===`add`?`Add Tags`:`Remove Tags`]})})]})]})})})}function xAe({selectedIds:e,onClose:t}){let{t:n}=U(),r=co(),{showToast:i}=Hd(),[a,o]=(0,y.useState)(``),{data:s,isLoading:c}=K({queryKey:[`projects`],queryFn:()=>Z.getProjects()}),l=(0,y.useMemo)(()=>s?uG([...s].sort((e,t)=>e.name.localeCompare(t.name))):void 0,[s]),u=a.trim().toLowerCase(),d=u?l?.filter(e=>e.name.toLowerCase().includes(u)):l,f=(l?.length??0)>5;(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let p=()=>lG(r),m=q({mutationFn:async t=>(await Z.addArchivesToProject(t,e),t),onSuccess:n=>{let r=s?.find(e=>e.id===n);p(),i(`Added ${e.length} archive${e.length===1?``:`s`} to "${r?.name}"`),t()},onError:()=>{i(`Failed to assign project`,`error`)}}),h=q({mutationFn:async()=>{for(let t of e)await Z.updateArchive(t,{project_id:null});return e.length},onSuccess:e=>{p(),i(`Removed ${e} archive${e===1?``:`s`} from project`),t()},onError:()=>{i(`Failed to remove from project`,`error`)}}),g=m.isPending||h.isPending;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,G.jsx)(Pd,{className:`w-full max-w-md max-h-[80vh] flex flex-col`,children:(0,G.jsxs)(Id,{className:`p-0 flex flex-col min-h-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(gc,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:`Assign to Project`})]}),(0,G.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,disabled:g,children:(0,G.jsx)(td,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-3 overflow-y-auto min-h-0`,children:[(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`Assign `,e.length,` selected archive`,e.length===1?``:`s`,` to a project`]}),c?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin text-bambu-gray`})}):(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`button`,{onClick:()=>h.mutate(),disabled:g,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:[(0,G.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-red-500/20 flex items-center justify-center shrink-0`,children:(0,G.jsx)(Es,{className:`w-4 h-4 text-red-600 dark:text-red-400`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:`Remove from project`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray truncate`,children:`Clear project assignment`})]}),h.isPending&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin text-bambu-gray shrink-0`})]}),l&&l.length>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 py-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`or assign to`}),(0,G.jsx)(`div`,{className:`flex-1 h-px bg-bambu-dark-tertiary`})]}),f&&(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Zl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:n(`archives.menu.searchProjects`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray text-sm focus:border-bambu-green focus:outline-none`})]}),d?.map(e=>(0,G.jsxs)(`button`,{onClick:()=>m.mutate(e.id),disabled:g,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:[(0,G.jsx)(`div`,{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0`,style:{backgroundColor:e.color?`${e.color}20`:`rgb(var(--bambu-green) / 0.2)`},children:(0,G.jsx)(gc,{className:`w-4 h-4`,style:{color:e.color||`rgb(var(--bambu-green))`}})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.name}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray truncate`,children:[e.archive_count,` archive`,e.archive_count===1?``:`s`,e.status&&` • ${e.status}`]})]}),m.isPending&&m.variables===e.id&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin text-bambu-gray shrink-0`})]},e.id)),(!l||l.length===0)&&(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-4`,children:`No projects yet. Create one from the Projects page.`}),l&&l.length>0&&d?.length===0&&(0,G.jsx)(`p`,{className:`text-center text-bambu-gray text-sm py-4`,children:`—`})]})]}),(0,G.jsx)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary shrink-0`,children:(0,G.jsx)(Q,{variant:`secondary`,onClick:t,className:`flex-1`,disabled:g,children:`Cancel`})})]})})})}function SAe(e,t){return new Date(e,t+1,0).getDate()}function CAe(e,t){return new Date(e,t,1).getDay()}var wAe=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],TAe=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function EAe({archives:e,onArchiveClick:t,highlightedArchiveId:n}){let r=new Date,[i,a]=(0,y.useState)(r.getMonth()),[o,s]=(0,y.useState)(r.getFullYear()),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(null),f=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=Xf(e.completed_at||e.created_at)||new Date,r=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,`0`)}-${String(n.getDate()).padStart(2,`0`)}`,i=t.get(r)||[];i.push(e),t.set(r,i)}),t},[e]),p=SAe(o,i),m=CAe(o,i),h=()=>{i===0?(a(11),s(o-1)):a(i-1)},g=()=>{i===11?(a(0),s(o+1)):a(i+1)},_=()=>{a(r.getMonth()),s(r.getFullYear())},v=[];for(let e=0;e{e!==c&&d(null),l(e)};return(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsx)(`button`,{onClick:h,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,G.jsx)(ms,{className:`w-5 h-5 text-bambu-gray`})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[wAe[i],` `,o]}),(0,G.jsx)(`button`,{onClick:_,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`})]}),(0,G.jsx)(`button`,{onClick:g,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,G.jsx)(ps,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-7 gap-1 mb-1`,children:TAe.map(e=>(0,G.jsx)(`div`,{className:`text-center text-xs text-bambu-gray py-2`,children:e},e))}),(0,G.jsx)(`div`,{className:`grid grid-cols-7 gap-1`,children:v.map((e,t)=>{if(e===null)return(0,G.jsx)(`div`,{className:`aspect-square`},`empty-${t}`);let n=`${o}-${String(i+1).padStart(2,`0`)}-${String(e).padStart(2,`0`)}`,a=f.get(n)||[],s=a.length>0,l=e===r.getDate()&&i===r.getMonth()&&o===r.getFullYear(),u=n===c,d=a.filter(e=>e.status===`completed`).length,p=a.filter(e=>e.status===`failed`).length;return(0,G.jsxs)(`button`,{onClick:()=>x(u?null:n),className:`aspect-square rounded-lg p-1 flex flex-col items-center justify-center transition-colors relative ${u?`bg-bambu-green text-white`:l?`bg-bambu-green/20 text-white ring-2 ring-bambu-green`:s?`bg-bambu-dark-tertiary hover:bg-bambu-dark-tertiary/70 text-white`:`hover:bg-bambu-dark-tertiary/50 text-bambu-gray`}`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium ${l&&!u?`text-bambu-green`:``}`,children:e}),s&&(0,G.jsxs)(`div`,{className:`absolute bottom-1 left-1/2 -translate-x-1/2 flex items-center gap-1`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full ${p>0&&d===0?`bg-red-400`:p>0?`bg-yellow-400`:`bg-green-400`}`}),(0,G.jsx)(`span`,{className:`text-xs font-medium`,children:a.length})]})]},e)})}),(0,G.jsx)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-4 text-center`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-2xl font-bold text-white`,children:e.filter(e=>{let t=Xf(e.completed_at||e.created_at)||new Date;return t.getMonth()===i&&t.getFullYear()===o}).length}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Prints this month`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-2xl font-bold text-green-700 dark:text-green-400`,children:e.filter(e=>{let t=Xf(e.completed_at||e.created_at)||new Date;return t.getMonth()===i&&t.getFullYear()===o&&e.status===`completed`}).length}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Successful`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-2xl font-bold text-red-700 dark:text-red-400`,children:e.filter(e=>{let t=Xf(e.completed_at||e.created_at)||new Date;return t.getMonth()===i&&t.getFullYear()===o&&e.status===`failed`}).length}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Failed`})]})]})})]}),(0,G.jsx)(`div`,{className:`lg:w-80 bg-bambu-dark rounded-xl p-4`,children:c?(0,G.jsxs)(G.Fragment,{children:[(0,G.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`})}),b.length>0?(0,G.jsx)(`div`,{className:`calendar-scroll space-y-2 max-h-96 overflow-y-auto`,children:b.map(e=>{let r=e.id===u||e.id===n;return(0,G.jsxs)(`button`,{onClick:()=>{d(e.id),t?.(e)},className:`w-full flex items-center gap-3 p-2 rounded-lg transition-colors text-left ${r?``:`hover:bg-bambu-dark-tertiary`}`,style:r?{outline:`4px solid #facc15`,outlineOffset:`2px`}:void 0,children:[e.thumbnail_path?(0,G.jsx)(`img`,{src:Z.getArchiveThumbnail(e.id),alt:``,className:`w-12 h-12 rounded object-cover`}):(0,G.jsx)(`div`,{className:`w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`3MF`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.print_name||e.filename}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,G.jsx)(`span`,{className:e.status===`failed`?`text-red-700 dark:text-red-400`:`text-green-700 dark:text-green-400`,children:e.status===`failed`?`Failed`:`Completed`}),e.filament_color&&(0,G.jsx)(`div`,{className:`flex gap-0.5`,children:e.filament_color.split(`,`).map((e,t)=>(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:e}},t))})]})]})]},e.id)})}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:`No prints on this day`})]}):(0,G.jsx)(`div`,{className:`text-center py-8`,children:(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:`Select a day to see prints`})})})]})}function vG({archiveId:e,archiveName:t,onClose:n}){let r=Z.getArchiveQRCodeUrl(e,300);return(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-sm`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:`QR Code`}),(0,G.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(td,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-6 flex flex-col items-center`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 text-center truncate max-w-full`,children:t}),(0,G.jsx)(`div`,{className:`bg-white p-4 rounded-lg mb-4`,children:(0,G.jsx)(`img`,{src:r,alt:`QR Code`,className:`w-64 h-64`})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4 text-center`,children:`Scan to open this archive`}),(0,G.jsxs)(Q,{onClick:()=>{let e=document.createElement(`a`);e.href=r,e.download=`${t}_qrcode.png`,e.click()},className:`w-full`,children:[(0,G.jsx)(Ys,{className:`w-4 h-4`}),`Download QR Code`]})]})]})})}function yG({archiveId:e,archiveName:t,photos:n,onClose:r,onDelete:i}){let[a,o]=(0,y.useState)(0),[s,c]=(0,y.useState)(!1);if((0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r(),e.key===`ArrowLeft`&&o(e=>Math.max(0,e-1)),e.key===`ArrowRight`&&o(e=>Math.min(n.length-1,e+1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,n.length]),(0,y.useEffect)(()=>{a>=n.length&&o(Math.max(0,n.length-1))},[n.length,a]),n.length===0)return r(),null;let l=n[a],u=Z.getArchivePhotoUrl(e,l);return(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:r,children:[(0,G.jsxs)(`div`,{className:`relative w-full h-full flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 bg-black/50`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`Photo `,a+1,` of `,n.length]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{let e=document.createElement(`a`);e.href=u,e.download=`${t}_photo_${a+1}.jpg`,e.click()},children:[(0,G.jsx)(Ys,{className:`w-4 h-4`}),`Download`]}),i&&(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{i&&c(!0)},className:`text-red-400 hover:text-red-300`,children:(0,G.jsx)(Nu,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:r,className:`p-2 text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(td,{className:`w-6 h-6`})})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-h-0 flex items-center justify-center p-4 relative overflow-hidden`,children:[a>0&&(0,G.jsx)(`button`,{onClick:()=>o(e=>e-1),className:`absolute left-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors`,children:(0,G.jsx)(ms,{className:`w-8 h-8 text-white`})}),(0,G.jsx)(`img`,{src:u,alt:`Photo ${a+1}`,className:`max-w-full max-h-full object-contain rounded-lg`,style:{maxHeight:`calc(100vh - 200px)`}}),ao(e=>e+1),className:`absolute right-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors`,children:(0,G.jsx)(ps,{className:`w-8 h-8 text-white`})})]}),n.length>1&&(0,G.jsx)(`div`,{className:`flex justify-center gap-2 p-4 bg-black/50`,children:n.map((t,n)=>(0,G.jsx)(`button`,{onClick:()=>o(n),className:`w-16 h-16 rounded-lg overflow-hidden border-2 transition-colors ${n===a?`border-bambu-green`:`border-transparent hover:border-bambu-gray`}`,children:(0,G.jsx)(`img`,{src:Z.getArchivePhotoUrl(e,t),alt:`Thumbnail ${n+1}`,className:`w-full h-full object-cover`})},t))})]}),s&&(0,G.jsx)(ef,{title:`Delete Photo`,message:`Delete this photo? This cannot be undone.`,confirmText:`Delete`,variant:`danger`,onConfirm:()=>{i?.(l),c(!1)},onCancel:()=>c(!1)})]})}function bG(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n`u`?null:WG(BigInt.prototype.toString),zG=typeof Symbol>`u`?null:WG(Symbol.prototype.toString),BG=WG(Object.prototype.hasOwnProperty),VG=WG(Object.prototype.toString),HG=WG(RegExp.prototype.test),UG=BAe(TypeError);function WG(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return DG(e,t,n)}}function BAe(e){return function(){return OG(e,[...arguments])}}function GG(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:NG;if(SG&&SG(e,null),!MG(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(MAe(t)||(t[r]=e),i=e)}e[i]=!0}return e}function VAe(e){for(let t=0;t/g),JAe=wG(/\${[\w\W]*/g),YAe=wG(/^data-[\-\w.\u00B7-\uFFFF]+$/),XAe=wG(/^aria-[\-\w]+$/),rK=wG(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),ZAe=wG(/^(?:\w+script|data):/i),QAe=wG(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),$Ae=wG(/^html$/i),eje=wG(/^[a-z][.\w]*(-[.\w]+)+$/i),iK=wG(/<[/\w!]/g),aK=wG(/<[/\w]/g),tje=wG(/<\/no(script|embed|frames)/i),nje=wG(/\/>/i),oK={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},rje=function(){return typeof window>`u`?null:window},ije=function(e,t){if(typeof e!=`object`||typeof e.createPolicy!=`function`)return null;let n=null,r=`data-tt-policy-suffix`;t&&t.hasAttribute(r)&&(n=t.getAttribute(r));let i=`dompurify`+(n?`#`+n:``);try{return e.createPolicy(i,{createHTML(e){return e},createScriptURL(e){return e}})}catch{return console.warn(`TrustedTypes policy `+i+` could not be created.`),null}},sK=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},cK=function(e,t,n,r){return BG(e,t)&&MG(e[t])?GG(r.base?KG(r.base):{},e[t],r.transform):n};function lK(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:rje(),t=e=>lK(e);if(t.version=`3.4.13`,t.removed=[],!e||!e.document||e.document.nodeType!==oK.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,i=r.currentScript;e.DocumentFragment;let a=e.HTMLTemplateElement,o=e.Node,s=e.Element,c=e.NodeFilter;e.NamedNodeMap===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;let l=e.DOMParser,u=e.trustedTypes,d=s.prototype,f=qG(d,`cloneNode`),p=qG(d,`remove`),m=qG(d,`nextSibling`),h=qG(d,`childNodes`),g=qG(d,`parentNode`),_=qG(d,`shadowRoot`),v=qG(d,`attributes`),y=o&&o.prototype?qG(o.prototype,`nodeType`):null,b=o&&o.prototype?qG(o.prototype,`nodeName`):null,x=o&&o.prototype?qG(o.prototype,`ownerDocument`):null;if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let S,C=``,w,T=!1,E=0,D=function(){if(E>0)throw UG(`A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.`)},O=function(e){D(),E++;try{return S.createHTML(e)}finally{E--}},k=function(e){D(),E++;try{return S.createScriptURL(e)}finally{E--}},A=function(){return T||=(w=ije(u,i),!0),w},j=n,M=j.implementation,N=j.createNodeIterator,P=j.createDocumentFragment,F=j.getElementsByTagName,I=r.importNode,L=sK();t.isSupported=typeof xG==`function`&&typeof g==`function`&&M&&M.createHTMLDocument!==void 0;let R=KAe,z=qAe,B=JAe,V=YAe,ee=XAe,te=ZAe,ne=QAe,re=eje,ie=rK,ae=null,oe=GG({},[...JG,...YG,...XG,...ZG,...QG]),se=null,H=GG({},[...$G,...eK,...tK,...nK]),ce=Object.seal(TG(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}})),le=null,ue=null,de=Object.seal(TG(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),fe=!0,pe=!0,me=!1,he=!0,ge=!1,_e=!0,ve=!1,ye=!1,be=null,xe=null,Se=!1,Ce=!1,we=!1,Te=!1,Ee=!0,De=!1,Oe=`user-content-`,ke=!0,Ae=!1,je={},Me=null,Ne=GG({},`annotation-xml.audio.colgroup.desc.foreignobject.head.iframe.math.mi.mn.mo.ms.mtext.noembed.noframes.noscript.plaintext.script.selectedcontent.style.svg.template.thead.title.video.xmp`.split(`.`)),Pe=null,Fe=GG({},[`audio`,`video`,`img`,`source`,`image`,`track`]),Ie=null,Le=GG({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),Re=`http://www.w3.org/1998/Math/MathML`,ze=`http://www.w3.org/2000/svg`,Be=`http://www.w3.org/1999/xhtml`,Ve=Be,He=!1,Ue=null,We=GG({},[Re,ze,Be],PG),Ge=CG([`mi`,`mo`,`mn`,`ms`,`mtext`]),Ke=GG({},Ge),qe=CG([`annotation-xml`]),Je=GG({},qe),Ye=GG({},[`title`,`style`,`font`,`a`,`script`]),Xe=null,Ze=[`application/xhtml+xml`,`text/html`],Qe=null,$e=null,et=n.createElement(`form`),U=function(e){return e instanceof RegExp||e instanceof Function},tt=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if($e&&$e===e)return;(!e||typeof e!=`object`)&&(e={}),e=KG(e),Xe=Ze.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,Qe=Xe===`application/xhtml+xml`?PG:NG,ae=cK(e,`ALLOWED_TAGS`,oe,{transform:Qe}),se=cK(e,`ALLOWED_ATTR`,H,{transform:Qe}),Ue=cK(e,`ALLOWED_NAMESPACES`,We,{transform:PG}),Ie=cK(e,`ADD_URI_SAFE_ATTR`,Le,{transform:Qe,base:Le}),Pe=cK(e,`ADD_DATA_URI_TAGS`,Fe,{transform:Qe,base:Fe}),Me=cK(e,`FORBID_CONTENTS`,Ne,{transform:Qe}),le=cK(e,`FORBID_TAGS`,KG({}),{transform:Qe}),ue=cK(e,`FORBID_ATTR`,KG({}),{transform:Qe}),je=BG(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?KG(e.USE_PROFILES):e.USE_PROFILES:!1,fe=e.ALLOW_ARIA_ATTR!==!1,pe=e.ALLOW_DATA_ATTR!==!1,me=e.ALLOW_UNKNOWN_PROTOCOLS||!1,he=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,ge=e.SAFE_FOR_TEMPLATES||!1,_e=e.SAFE_FOR_XML!==!1,ve=e.WHOLE_DOCUMENT||!1,Ce=e.RETURN_DOM||!1,we=e.RETURN_DOM_FRAGMENT||!1,Te=e.RETURN_TRUSTED_TYPE||!1,Se=e.FORCE_BODY||!1,Ee=e.SANITIZE_DOM!==!1,De=e.SANITIZE_NAMED_PROPS||!1,ke=e.KEEP_CONTENT!==!1,Ae=e.IN_PLACE||!1,ie=UAe(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:rK,Ve=typeof e.NAMESPACE==`string`?e.NAMESPACE:Be,Ke=BG(e,`MATHML_TEXT_INTEGRATION_POINTS`)&&e.MATHML_TEXT_INTEGRATION_POINTS&&typeof e.MATHML_TEXT_INTEGRATION_POINTS==`object`?KG(e.MATHML_TEXT_INTEGRATION_POINTS):GG({},Ge),Je=BG(e,`HTML_INTEGRATION_POINTS`)&&e.HTML_INTEGRATION_POINTS&&typeof e.HTML_INTEGRATION_POINTS==`object`?KG(e.HTML_INTEGRATION_POINTS):GG({},qe);let t=BG(e,`CUSTOM_ELEMENT_HANDLING`)&&e.CUSTOM_ELEMENT_HANDLING&&typeof e.CUSTOM_ELEMENT_HANDLING==`object`?KG(e.CUSTOM_ELEMENT_HANDLING):TG(null);if(ce=TG(null),BG(t,`tagNameCheck`)&&U(t.tagNameCheck)&&(ce.tagNameCheck=t.tagNameCheck),BG(t,`attributeNameCheck`)&&U(t.attributeNameCheck)&&(ce.attributeNameCheck=t.attributeNameCheck),BG(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(ce.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),wG(ce),ge&&(pe=!1),we&&(Ce=!0),je&&(ae=GG({},QG),se=TG(null),je.html===!0&&(GG(ae,JG),GG(se,$G)),je.svg===!0&&(GG(ae,YG),GG(se,eK),GG(se,nK)),je.svgFilters===!0&&(GG(ae,XG),GG(se,eK),GG(se,nK)),je.mathMl===!0&&(GG(ae,ZG),GG(se,tK),GG(se,nK))),de.tagCheck=null,de.attributeCheck=null,BG(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?de.tagCheck=e.ADD_TAGS:MG(e.ADD_TAGS)&&(ae===oe&&(ae=KG(ae)),GG(ae,e.ADD_TAGS,Qe))),BG(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?de.attributeCheck=e.ADD_ATTR:MG(e.ADD_ATTR)&&(se===H&&(se=KG(se)),GG(se,e.ADD_ATTR,Qe))),BG(e,`ADD_URI_SAFE_ATTR`)&&MG(e.ADD_URI_SAFE_ATTR)&&GG(Ie,e.ADD_URI_SAFE_ATTR,Qe),BG(e,`FORBID_CONTENTS`)&&MG(e.FORBID_CONTENTS)&&(Me===Ne&&(Me=KG(Me)),GG(Me,e.FORBID_CONTENTS,Qe)),BG(e,`ADD_FORBID_CONTENTS`)&&MG(e.ADD_FORBID_CONTENTS)&&(Me===Ne&&(Me=KG(Me)),GG(Me,e.ADD_FORBID_CONTENTS,Qe)),ke&&(ae[`#text`]=!0),ve&&GG(ae,[`html`,`head`,`body`]),ae.table&&(GG(ae,[`tbody`]),delete le.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw UG(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw UG(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=S;S=e.TRUSTED_TYPES_POLICY;try{C=O(``)}catch(e){throw S=t,e}}else e.TRUSTED_TYPES_POLICY===null?(S=void 0,C=``):(S===void 0&&(S=A()),S&&typeof C==`string`&&(C=O(``)));CG&&CG(e),$e=e},nt=GG({},[...YG,...XG,...WAe]),rt=GG({},[...ZG,...GAe]),it=function(e,t,n){return t.namespaceURI===Be?e===`svg`:t.namespaceURI===Re?e===`svg`&&(n===`annotation-xml`||Ke[n]):!!nt[e]},at=function(e,t,n){return t.namespaceURI===Be?e===`math`:t.namespaceURI===ze?e===`math`&&Je[n]:!!rt[e]},ot=function(e,t,n){return t.namespaceURI===ze&&!Je[n]||t.namespaceURI===Re&&!Ke[n]?!1:!rt[e]&&(Ye[e]||!nt[e])},st=function(e){let t=g(e);(!t||!t.tagName)&&(t={namespaceURI:Ve,tagName:`template`});let n=NG(e.tagName),r=NG(t.tagName);return Ue[e.namespaceURI]?e.namespaceURI===ze?it(n,t,r):e.namespaceURI===Re?at(n,t,r):e.namespaceURI===Be?ot(n,t,r):!!(Xe===`application/xhtml+xml`&&Ue[e.namespaceURI]):!1},ct=function(e){jG(t.removed,{element:e});try{g(e).removeChild(e)}catch{if(p(e),!g(e))throw UG(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},lt=function(e){ft(e);let t=h(e);if(t){let e=[];kG(t,t=>{jG(e,t)}),kG(e,e=>{try{p(e)}catch{}})}let n=v(e);if(n)for(let t=n.length-1;t>=0;--t){let r=n[t],i=r&&r.name;if(typeof i==`string`)try{e.removeAttribute(i)}catch{}}},ut=function(e,n){try{jG(t.removed,{attribute:n.getAttributeNode(e),from:n})}catch{jG(t.removed,{attribute:null,from:n})}if(n.removeAttribute(e),e===`is`)if(Ce||we)try{ct(n)}catch{}else try{n.setAttribute(e,``)}catch{}},dt=function(e){let t=v(e);if(t)for(let n=t.length-1;n>=0;--n){let r=t[n],i=r&&r.name;if(!(typeof i!=`string`||se[Qe(i)]))try{e.removeAttribute(i)}catch{}}},ft=function(e){let t=[e];for(;t.length>0;){let e=t.pop();(y?y(e):e.nodeType)===oK.element&&dt(e);let n=h(e);if(n)for(let e=n.length-1;e>=0;--e)t.push(n[e])}},pt=function(e){if(!_e)return;let t=[e];for(;t.length>0;){let e=t.pop(),n=y?y(e):e.nodeType;if(n===oK.processingInstruction||n===oK.comment&&HG(aK,e.data)){try{p(e)}catch{}continue}if(n===oK.element){let t=e,n=Qe(b?b(e):e.nodeName);try{t.hasAttribute&&t.hasAttribute(`patchsrc`)&&t.removeAttribute(`patchsrc`),t.hasAttribute&&t.hasAttribute(`for`)&&n!==`label`&&n!==`output`&&t.removeAttribute(`for`)}catch{}}let r=h(e);if(r)for(let e=r.length-1;e>=0;--e)t.push(r[e])}},mt=function(e){let t=null,r=null;if(Se)e=``+e;else{let t=FG(e,/^[\r\n\t ]+/);r=t&&t[0]}Xe===`application/xhtml+xml`&&Ve===Be&&(e=``+e+``);let i=S?O(e):e;if(Ve===Be)try{t=new l().parseFromString(i,Xe)}catch{}if(!t||!t.documentElement){t=M.createDocument(Ve,`template`,null);try{t.documentElement.innerHTML=He?C:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),Ve===Be?F.call(t,ve?`html`:`body`)[0]:ve?t.documentElement:a},ht=function(e){let t=x?x(e):e.ownerDocument;return N.call(t||e,e,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},gt=function(e){return e=IG(e,R,` `),e=IG(e,z,` `),e=IG(e,B,` `),e},_t=function(e){e.normalize();let t=x?x(e):e.ownerDocument,n=N.call(t||e,e,c.SHOW_TEXT|c.SHOW_COMMENT|c.SHOW_CDATA_SECTION|c.SHOW_PROCESSING_INSTRUCTION,null),r=n.nextNode();for(;r;)r.data=gt(r.data),r=n.nextNode();let i=e.querySelectorAll?.call(e,`template`);i&&kG(i,e=>{yt(e.content)&&_t(e.content)})},vt=function(e){let t=b?b(e):null;return typeof t!=`string`||Qe(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==v(e)||typeof e.removeAttribute!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==y(e)||e.childNodes!==h(e)},yt=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return y(e)===oK.documentFragment}catch{return!1}},bt=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return typeof y(e)==`number`}catch{return!1}};function xt(e,n,r){e.length!==0&&kG(e,e=>{e.call(t,n,r,$e)})}let St=function(e,t){return!!(_e&&e.hasChildNodes()&&!bt(e.firstElementChild)&&HG(iK,e.textContent)&&HG(iK,e.innerHTML)||_e&&e.namespaceURI===Be&&t===`style`&&bt(e.firstElementChild)||e.nodeType===oK.processingInstruction||_e&&e.nodeType===oK.comment&&HG(aK,e.data))},Ct=function(e,t,n){if(!le[t]&&Ot(t)&&(ce.tagNameCheck instanceof RegExp&&HG(ce.tagNameCheck,t)||ce.tagNameCheck instanceof Function&&ce.tagNameCheck(t)))return!1;if(ke&&!Me[t]){let t=g(e),r=h(e);if(r&&t){let i=r.length;for(let a=i-1;a>=0;--a){let i=e===n?f(r[a],!0):r[a];t.insertBefore(i,m(e))}}}return ct(e),!0},wt=function(e,t,n,r){return e.length===0?t:t===n||t===r?KG(t):t},Tt=function(e,n){if(xt(L.beforeSanitizeElements,e,null),e!==n&&g(e)===null)return Ae&&ft(e),!0;if(vt(e))return ct(e),!0;let r=Qe(b?b(e):e.nodeName);if(ae=wt(L.uponSanitizeElement,ae,oe,be),xt(L.uponSanitizeElement,e,{tagName:r,allowedTags:ae}),e!==n&&g(e)===null)return Ae&&ft(e),!0;if(St(e,r))return ct(e),!0;if(le[r]||!(de.tagCheck instanceof Function&&de.tagCheck(r))&&!ae[r]){let t=Ct(e,r,n);return t===!1&&xt(L.afterSanitizeElements,e,null),t}if((y?y(e):e.nodeType)===oK.element&&!st(e)||(r===`noscript`||r===`noembed`||r===`noframes`)&&HG(tje,e.innerHTML))return ct(e),!0;if(ge&&e.nodeType===oK.text){let n=gt(e.textContent);e.textContent!==n&&(jG(t.removed,{element:e.cloneNode()}),e.textContent=n)}return xt(L.afterSanitizeElements,e,null),!1},Et=function(e,t,r){if(ue[t]||_e&&t===`patchsrc`||_e&&t===`for`&&e!==`label`&&e!==`output`||Ee&&(t===`id`||t===`name`)&&(r in n||r in et))return!1;let i=se[t]||de.attributeCheck instanceof Function&&de.attributeCheck(t,e);if(!(pe&&HG(V,t))&&!(fe&&HG(ee,t))){if(!i){if(!(Ot(e)&&(ce.tagNameCheck instanceof RegExp&&HG(ce.tagNameCheck,e)||ce.tagNameCheck instanceof Function&&ce.tagNameCheck(e))&&(ce.attributeNameCheck instanceof RegExp&&HG(ce.attributeNameCheck,t)||ce.attributeNameCheck instanceof Function&&ce.attributeNameCheck(t,e))||t===`is`&&ce.allowCustomizedBuiltInElements&&(ce.tagNameCheck instanceof RegExp&&HG(ce.tagNameCheck,r)||ce.tagNameCheck instanceof Function&&ce.tagNameCheck(r))))return!1}else if(!Ie[t]&&!HG(ie,IG(r,ne,``))&&!((t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&LG(r,`data:`)===0&&Pe[e])&&!(me&&!HG(te,IG(r,ne,``)))&&r)return!1}return!0},Dt=GG({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),Ot=function(e){return!Dt[NG(e)]&&HG(re,e)},kt=function(e,t,n,r){if(S&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return O(r);case`TrustedScriptURL`:return k(r)}return r},At=function(e,n,r,i){try{r?e.setAttributeNS(r,n,i):e.setAttribute(n,i),vt(e)?ct(e):AG(t.removed)}catch{ut(n,e)}},jt=function(e){xt(L.beforeSanitizeAttributes,e,null);let t=e.attributes;if(!t||vt(e))return;se=wt(L.uponSanitizeAttribute,se,H,xe);let n={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:se,forceKeepAttr:void 0},r=t.length,i=Qe(e.nodeName);for(;r--;){let a=t[r],o=a.name,s=a.namespaceURI,c=a.value,l=Qe(o),u=c,d=o===`value`?u:LAe(u);if(n.attrName=l,n.attrValue=d,n.keepAttr=!0,n.forceKeepAttr=void 0,xt(L.uponSanitizeAttribute,e,n),d=n.attrValue,De&&(l===`id`||l===`name`)&&LG(d,Oe)!==0&&(ut(o,e),d=Oe+d),_e&&HG(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,d)){ut(o,e);continue}if(l===`attributename`&&FG(d,`href`)){ut(o,e);continue}if(!n.forceKeepAttr){if(!n.keepAttr){ut(o,e);continue}if(!he&&HG(nje,d)){ut(o,e);continue}if(ge&&(d=gt(d)),!Et(i,l,d)){ut(o,e);continue}d=kt(i,l,s,d),d!==u&&At(e,o,s,d)}}xt(L.afterSanitizeAttributes,e,null)},Mt=function(e){let t=null,n=ht(e);for(xt(L.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(xt(L.uponSanitizeShadowNode,t,null),Tt(t,e),jt(t),yt(t.content)&&Mt(t.content),(y?y(t):t.nodeType)===oK.element){let e=_(t);yt(e)&&(Nt(e),Mt(e))}xt(L.afterSanitizeShadowDOM,e,null)},Nt=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){Mt(e.shadow);continue}let n=e.node,r=(y?y(n):n.nodeType)===oK.element,i=h(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=b?b(n):null;if(typeof e==`string`&&Qe(e)===`template`){let e=n.content;yt(e)&&t.push({node:e,shadow:null})}}if(r){let e=_(n);yt(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return t.sanitize=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,a=null,o=null,s=null;if(He=!e,He&&(e=``),typeof e!=`string`&&!bt(e)&&(e=HAe(e),typeof e!=`string`))throw UG(`dirty is not a string, aborting`);if(!t.isSupported)return e;ye?(ae=be,se=xe):tt(n),(L.uponSanitizeElement.length>0||L.uponSanitizeAttribute.length>0)&&(ae=KG(ae)),L.uponSanitizeAttribute.length>0&&(se=KG(se)),t.removed=[];let c=Ae&&typeof e!=`string`&&bt(e);if(c){pt(e);let t=b?b(e):e.nodeName;if(typeof t==`string`){let n=Qe(t);if(!ae[n]||le[n])throw lt(e),UG(`root node is forbidden and cannot be sanitized in-place`)}if(vt(e))throw lt(e),UG(`root node is clobbered and cannot be sanitized in-place`);try{Nt(e)}catch(t){throw lt(e),t}}else if(bt(e))i=mt(``),a=i.ownerDocument.importNode(e,!0),a.nodeType===oK.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),Nt(a);else{if(!Ce&&!ge&&!ve&&e.indexOf(`<`)===-1)return S&&Te?O(e):e;if(i=mt(e),!i)return Ce?null:Te?C:``}i&&Se&&ct(i.firstChild);let l=c?e:i;try{let e=ht(l);for(;o=e.nextNode();)Tt(o,l),jt(o),yt(o.content)&&Mt(o.content)}catch(n){throw c&&(lt(e),kG(t.removed,e=>{e.element&&ft(e.element)})),n}if(c)return kG(t.removed,e=>{e.element&&ft(e.element)}),ge&&_t(e),e;if(Ce){if(ge&&_t(i),we)for(s=P.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(se.shadowroot||se.shadowrootmode)&&(s=I.call(r,s,!0)),s}let u=ve?i.outerHTML:i.innerHTML;return ve&&ae[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&HG($Ae,i.ownerDocument.doctype.name)&&(u=` `+u),ge&&(u=gt(u)),S&&Te?O(u):u},t.setConfig=function(){tt(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{}),ye=!0,be=ae,xe=se},t.clearConfig=function(){$e=null,ye=!1,be=null,xe=null,S=w,C=``},t.isValidAttribute=function(e,t,n){return $e||tt({}),Et(Qe(e),Qe(t),n)},t.addHook=function(e,t){typeof t==`function`&&BG(L,e)&&jG(L[e],t)},t.removeHook=function(e,t){if(BG(L,e)){if(t!==void 0){let n=FAe(L[e],t);return n===-1?void 0:IAe(L[e],n,1)[0]}return AG(L[e])}},t.removeHooks=function(e){BG(L,e)&&(L[e]=[])},t.removeAllHooks=function(){L=sK()},t}var uK=lK();function dK(e){this.content=e}dK.prototype={constructor:dK,find:function(e){for(var t=0;t>1}},dK.from=function(e){if(e instanceof dK)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new dK(t)};function fK(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let i=e.child(r),a=t.child(r);if(i==a){n+=i.nodeSize;continue}if(!i.sameMarkup(a))return n;if(i.isText&&i.text!=a.text){for(let e=0;i.text[e]==a.text[e];e++)n++;return n}if(i.content.size||a.content.size){let e=fK(i.content,a.content,n+1);if(e!=null)return e}n+=i.nodeSize}}function pK(e,t,n,r){for(let i=e.childCount,a=t.childCount;;){if(i==0||a==0)return i==a?null:{a:n,b:r};let o=e.child(--i),s=t.child(--a),c=o.nodeSize;if(o==s){n-=c,r-=c;continue}if(!o.sameMarkup(s))return{a:n,b:r};if(o.isText&&o.text!=s.text){let e=0,t=Math.min(o.text.length,s.text.length);for(;ee&&n(s,r+o,i||null,a)!==!1&&s.content.size){let i=o+1;s.nodesBetween(Math.max(0,e-i),Math.min(s.content.size,t-i),n,r+i)}o=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i=``,a=!0;return this.nodesBetween(e,t,(o,s)=>{let c=o.isText?o.text.slice(Math.max(e,s)-s,t-s):o.isLeaf?r?typeof r==`function`?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):``:``;o.isBlock&&(o.isLeaf&&c||o.isTextblock)&&n&&(a?a=!1:i+=n),i+=c},0),i}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,i=this.content.slice(),a=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),a=1);at)for(let e=0,a=0;at&&((an)&&(o=o.isText?o.cut(Math.max(0,t-a),Math.min(o.text.length,n-a)):o.cut(Math.max(0,t-a-1),Math.min(o.content.size,n-a-1))),r.push(o),i+=o.nodeSize),a=s}return new e(r,i)}cutByIndex(t,n){return t==n?e.empty:t==0&&n==this.content.length?this:new e(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let i=this.content.slice(),a=this.size+n.nodeSize-r.nodeSize;return i[t]=n,new e(i,a)}addToStart(t){return new e([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new e(this.content.concat(t),this.size+t.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=this.child(t),i=n+r.nodeSize;if(i>=e)return i==e?gK(t+1,i):gK(t,n);n=i}}toString(){return`<`+this.toStringInner()+`>`}toStringInner(){return this.content.join(`, `)}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(t,n){if(!n)return e.empty;if(!Array.isArray(n))throw RangeError(`Invalid input for Fragment.fromJSON`);return new e(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return e.empty;let n,r=0;for(let e=0;ethis.type.rank&&(t||=e.slice(0,r),t.push(this),n=!0),t&&t.push(i)}return t||=e.slice(),n||t.push(this),t}removeFromSet(e){for(let t=0;te.type.rank-t.type.rank),n}};vK.none=[];var yK=class extends Error{},bK=class e{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=SK(this.content,t+this.openStart,n);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(xK(this.content,t+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(t,n){if(!n)return e.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!=`number`||typeof i!=`number`)throw RangeError(`Invalid input for Slice.fromJSON`);return new e(mK.fromJSON(t,n.content),r,i)}static maxOpen(t,n=!0){let r=0,i=0;for(let e=t.firstChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.firstChild)r++;for(let e=t.lastChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.lastChild)i++;return new e(t,r,i)}};bK.empty=new bK(mK.empty,0,0);function xK(e,t,n){let{index:r,offset:i}=e.findIndex(t),a=e.maybeChild(r),{index:o,offset:s}=e.findIndex(n);if(i==t||a.isText){if(s!=n&&!e.child(o).isText)throw RangeError(`Removing non-flat range`);return e.cut(0,t).append(e.cut(n))}if(r!=o)throw RangeError(`Removing non-flat range`);return e.replaceChild(r,a.copy(xK(a.content,t-i-1,n-i-1)))}function SK(e,t,n,r){let{index:i,offset:a}=e.findIndex(t),o=e.maybeChild(i);if(a==t||o.isText)return r&&!r.canReplace(i,i,n)?null:e.cut(0,t).append(n).append(e.cut(t));let s=SK(o.content,t-a-1,n,o);return s&&e.replaceChild(i,o.copy(s))}function aje(e,t,n){if(n.openStart>e.depth)throw new yK(`Inserted content deeper than insertion position`);if(e.depth-n.openStart!=t.depth-n.openEnd)throw new yK(`Inconsistent open depths`);return CK(e,t,n,0)}function CK(e,t,n,r){let i=e.index(r),a=e.node(r);if(i==t.index(r)&&r=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function DK(e,t,n,r){let i=(t||e).node(n),a=0,o=t?t.index(n):i.childCount;e&&(a=e.index(n),e.depth>n?a++:e.textOffset&&(EK(e.nodeAfter,r),a++));for(let e=a;ei&&TK(e,t,i+1),o=r.depth>i&&TK(n,r,i+1),s=[];return DK(null,e,i,s),a&&o&&t.index(i)==n.index(i)?(wK(a,o),EK(OK(a,kK(e,t,n,r,i+1)),s)):(a&&EK(OK(a,AK(e,t,i+1)),s),DK(t,n,i,s),o&&EK(OK(o,AK(n,r,i+1)),s)),DK(r,null,i,s),new mK(s)}function AK(e,t,n){let r=[];return DK(null,e,n,r),e.depth>n&&EK(OK(TK(e,t,n+1),AK(e,t,n+1)),r),DK(t,null,n,r),new mK(r)}function oje(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(mK.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}var jK=class e{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.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 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 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,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let t=0;t0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new NK(this,e,n);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<=t.content.size))throw RangeError(`Position `+n+` out of range`);let r=[],i=0,a=n;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(a),o=a-n;if(r.push(e,t,i+n),!o||(e=e.child(t),e.isText))break;a=o-1,i+=n+1}return new e(n,r,a)}static resolveCached(t,n){let r=MK.get(t);if(r)for(let e=0;ee&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}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()+`)`),FK(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error(`Called contentMatchAt on a node with invalid content`);return t}canReplace(e,t,n=mK.empty,r=0,i=n.childCount){let a=this.contentMatchAt(e).matchFragment(n,r,i),o=a&&a.matchFragment(this.content,t);if(!o||!o.validEnd)return!1;for(let e=r;ee.type.name)}`);this.content.forEach(e=>e.check())}toJSON(){let e={type:this.type.name};for(let t 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(e=>e.toJSON())),e}static fromJSON(e,t){if(!t)throw RangeError(`Invalid input for Node.fromJSON`);let n;if(t.marks){if(!Array.isArray(t.marks))throw RangeError(`Invalid mark data for Node.fromJSON`);n=t.marks.map(e.markFromJSON)}if(t.type==`text`){if(typeof t.text!=`string`)throw RangeError(`Invalid text node in JSON`);return e.text(t.text,n)}let r=mK.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}};PK.prototype.text=void 0;var uje=class e extends PK{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError(`Empty text nodes are not allowed`);this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):FK(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new e(this.type,this.attrs,t,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function FK(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+`(`+t+`)`;return t}var IK=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new dje(t,n);if(r.next==null)return e.empty;let i=LK(r);r.next&&r.err(`Unexpected trailing text`);let a=vje(_je(i));return yje(a,r),a}matchType(e){for(let t=0;te.createAndFill()));for(let e=0;e=this.next.length)throw RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let r=0;r{let r=n+(t.validEnd?`*`:` `)+` `;for(let n=0;n`+e.indexOf(t.next[n].next);return r}).join(` @@ -4432,5 +4432,5 @@ ${t.slice(l+2)}`,d+=1;else break}t.push({indent:l,number:parseInt(s,10),content: In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}()}function a(e,t){if(e){if(typeof e==`string`)return o(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,t):void 0}}function o(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n`u`||`remove`in Element.prototype||(Element.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)}),typeof self<`u`&&`document`in self&&((!(`classList`in document.createElement(`_`))||document.createElementNS&&!(`classList`in document.createElementNS(`http://www.w3.org/2000/svg`,`g`)))&&function(e){if(`Element`in e){var t=`classList`,n=`prototype`,r=e.Element[n],i=Object,a=String[n].trim||function(){return this.replace(/^\s+|\s+$/g,``)},o=Array[n].indexOf||function(e){for(var t=0,n=this.length;t2&&arguments[2]!==void 0&&arguments[2]?Object.assign({},this.getDefaultDiplay(),t):t||this.getDefaultDiplay())[e]||e}},{key:`getUpdatedInput`,value:function(e,t,n){var r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:n,i=arguments.length>4&&arguments[4]!==void 0&&arguments[4],a=this.getOptions(),o=[n,r,i],s=t;return(e===`{bksp}`||e===`{backspace}`)&&s.length>0?s=this.removeAt.apply(this,[s].concat(o)):(e===`{delete}`||e===`{forwarddelete}`)&&s.length>0?s=this.removeForwardsAt.apply(this,[s].concat(o)):e===`{space}`?s=this.addStringAt.apply(this,[s,` `].concat(o)):e!==`{tab}`||typeof a.tabCharOnTab==`boolean`&&!1===a.tabCharOnTab?e!==`{enter}`&&e!==`{numpadenter}`||!a.newLineOnEnter?e.includes(`numpad`)&&Number.isInteger(Number(e[e.length-2]))?s=this.addStringAt.apply(this,[s,e[e.length-2]].concat(o)):e===`{numpaddivide}`?s=this.addStringAt.apply(this,[s,`/`].concat(o)):e===`{numpadmultiply}`?s=this.addStringAt.apply(this,[s,`*`].concat(o)):e===`{numpadsubtract}`?s=this.addStringAt.apply(this,[s,`-`].concat(o)):e===`{numpadadd}`?s=this.addStringAt.apply(this,[s,`+`].concat(o)):e===`{numpaddecimal}`?s=this.addStringAt.apply(this,[s,`.`].concat(o)):e===`{`||e===`}`?s=this.addStringAt.apply(this,[s,e].concat(o)):e.includes(`{`)||e.includes(`}`)||(s=this.addStringAt.apply(this,[s,e].concat(o))):s=this.addStringAt.apply(this,[s,` `].concat(o)):s=this.addStringAt.apply(this,[s,` `].concat(o)),a.debug&&console.log(`Input will be: `+s),s}},{key:`updateCaretPos`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0&&arguments[1],n=this.updateCaretPosAction(e,t);this.dispatch((function(e){e.setCaretPosition(n)}))}},{key:`updateCaretPosAction`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0&&arguments[1],n=this.getOptions(),r=this.getCaretPosition();return r!=null&&(t?r>0&&(r-=e):r+=e),n.debug&&console.log(`Caret at:`,r),r}},{key:`addStringAt`,value:function(e,t){var n,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:e.length,i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:e.length,a=arguments.length>4&&arguments[4]!==void 0&&arguments[4];return r||r===0?(n=[e.slice(0,r),t,e.slice(i)].join(``),this.isMaxLengthReached()||a&&this.updateCaretPos(t.length)):n=e+t,n}},{key:`removeAt`,value:function(e){var t,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:e.length,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:e.length,i=arguments.length>3&&arguments[3]!==void 0&&arguments[3];if(n===0&&r===0)return e;if(n===r){var a=/([\uD800-\uDBFF][\uDC00-\uDFFF])/g;n&&n>=0?e.substring(n-2,n).match(a)?(t=e.substr(0,n-2)+e.substr(n),i&&this.updateCaretPos(2,!0)):(t=e.substr(0,n-1)+e.substr(n),i&&this.updateCaretPos(1,!0)):e.slice(-2).match(a)?(t=e.slice(0,-2),i&&this.updateCaretPos(2,!0)):(t=e.slice(0,-1),i&&this.updateCaretPos(1,!0))}else t=e.slice(0,n)+e.slice(r),i&&this.dispatch((function(e){e.setCaretPosition(n)}));return t}},{key:`removeForwardsAt`,value:function(e){var t,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:e.length,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:e.length,i=arguments.length>3&&arguments[3]!==void 0&&arguments[3];return e!=null&&e.length&&n!==null?(n===r?t=e.substring(n,n+2).match(/([\uD800-\uDBFF][\uDC00-\uDFFF])/g)?e.substr(0,n)+e.substr(n+2):e.substr(0,n)+e.substr(n+1):(t=e.slice(0,n)+e.slice(r),i&&this.dispatch((function(e){e.setCaretPosition(n)}))),t):e}},{key:`handleMaxLength`,value:function(e,t){var n=this.getOptions(),r=n.maxLength,i=e[n.inputName||`default`],a=t.length-1>=r;if(t.length<=i.length)return!1;if(Number.isInteger(r))return n.debug&&console.log(`maxLength (num) reached:`,a),a?(this.maxLengthReached=!0,!0):(this.maxLengthReached=!1,!1);if(s(r)===`object`){var o=t.length-1>=r[n.inputName||`default`];return n.debug&&console.log(`maxLength (obj) reached:`,o),o?(this.maxLengthReached=!0,!0):(this.maxLengthReached=!1,!1)}}},{key:`isMaxLengthReached`,value:function(){return!!this.maxLengthReached}},{key:`isTouchDevice`,value:function(){return`ontouchstart`in window||navigator.maxTouchPoints}},{key:`pointerEventsSupported`,value:function(){return!!window.PointerEvent}},{key:`camelCase`,value:function(e){return e?e.toLowerCase().trim().split(/[.\-_\s]/g).reduce((function(e,t){return t.length?e+t[0].toUpperCase()+t.slice(1):e})):``}},{key:`chunkArray`,value:function(e,t){return i(Array(Math.ceil(e.length/t))).map((function(n,r){return e.slice(t*r,t+t*r)}))}},{key:`escapeRegex`,value:function(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,`\\$&`)}},{key:`getRtlOffset`,value:function(e,t){var n=e,r=t.indexOf(`‫`);return r=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw TypeError(`Invalid attempt to iterate non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var o,s=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){c=!0,o=e},f:function(){try{s||n.return==null||n.return()}finally{if(c)throw o}}}}(Object.getOwnPropertyNames(e.prototype));try{for(r.s();!(n=r.n()).done;){var i=n.value;i===`constructor`||i===`bindMethods`||(t[i]=t[i].bind(t))}}catch(e){r.e(e)}finally{r.f()}}}],t&&c(e.prototype,t),n&&c(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}();l(d,`noop`,(function(){}));var f=d;function p(e){return p=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},p(e)}function m(e,t){for(var n=0;n1?t?.toLowerCase():t}},{key:`keyCodeToKey`,value:function(e){return{8:`Backspace`,9:`Tab`,13:`Enter`,16:`Shift`,17:`Ctrl`,18:`Alt`,19:`Pause`,20:`CapsLock`,27:`Esc`,32:`Space`,33:`PageUp`,34:`PageDown`,35:`End`,36:`Home`,37:`ArrowLeft`,38:`ArrowUp`,39:`ArrowRight`,40:`ArrowDown`,45:`Insert`,46:`Delete`,48:`0`,49:`1`,50:`2`,51:`3`,52:`4`,53:`5`,54:`6`,55:`7`,56:`8`,57:`9`,65:`A`,66:`B`,67:`C`,68:`D`,69:`E`,70:`F`,71:`G`,72:`H`,73:`I`,74:`J`,75:`K`,76:`L`,77:`M`,78:`N`,79:`O`,80:`P`,81:`Q`,82:`R`,83:`S`,84:`T`,85:`U`,86:`V`,87:`W`,88:`X`,89:`Y`,90:`Z`,91:`Meta`,96:`Numpad0`,97:`Numpad1`,98:`Numpad2`,99:`Numpad3`,100:`Numpad4`,101:`Numpad5`,102:`Numpad6`,103:`Numpad7`,104:`Numpad8`,105:`Numpad9`,106:`NumpadMultiply`,107:`NumpadAdd`,109:`NumpadSubtract`,110:`NumpadDecimal`,111:`NumpadDivide`,112:`F1`,113:`F2`,114:`F3`,115:`F4`,116:`F5`,117:`F6`,118:`F7`,119:`F8`,120:`F9`,121:`F10`,122:`F11`,123:`F12`,144:`NumLock`,145:`ScrollLock`,186:`;`,187:`=`,188:`,`,189:`-`,190:`.`,191:`/`,192:"`",219:`[`,220:`\\`,221:`]`,222:`'`}[e]||``}}],t&&m(e.prototype,t),n&&m(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}();function v(e){return v=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},v(e)}function y(e,t){for(var n=0;n0&&arguments[0]!==void 0?arguments[0]:r())},c.appendChild(t)}));var l=a>0,u=document.createElement(`div`);u.classList.add(`hg-candidate-box-prev`),l&&u.classList.add(`hg-candidate-box-btn-active`);var d=function(){l&&n.renderPage({candidateListPages:r,targetElement:i,pageIndex:a-1,nbPages:o,onItemSelected:s})};this.options.useTouchEvents?u.ontouchstart=d:u.onclick=d,this.candidateBoxElement.appendChild(u),this.candidateBoxElement.appendChild(c);var f=ae.length)&&(t=e.length);for(var n=0,r=Array(t);n1&&arguments[1]!==void 0?arguments[1]:e;this.caretPosition=e,this.caretPositionEnd=t}},{key:`getInputCandidates`,value:function(e){var t=this,n=this.options,r=n.layoutCandidates,i=n.layoutCandidatesCaseSensitiveMatch;if(!r||T(r)!==`object`)return{};var a=Object.keys(r).filter((function(n){var r=e.substring(0,t.getCaretPositionEnd()||0)||e,a=RegExp(`${t.utilities.escapeRegex(n)}\$`,i?`g`:`gi`);return!!C(r.matchAll(a)).length}));if(a.length>1){var o=a.sort((function(e,t){return t.length-e.length}))[0];return{candidateKey:o,candidateValue:r[o]}}if(a.length){var s=a[0];return{candidateKey:s,candidateValue:r[s]}}return{}}},{key:`showCandidatesBox`,value:function(e,t,n){var r=this;this.candidateBox&&this.candidateBox.show({candidateValue:t,targetElement:n,onSelect:function(t,n){var i=r.options,a=i.layoutCandidatesCaseSensitiveMatch,o=i.disableCandidateNormalization,s=i.enableLayoutCandidatesKeyPress,c=t;o||(c=t.normalize(`NFD`)),typeof r.options.beforeInputUpdate==`function`&&r.options.beforeInputUpdate(r);var l=r.getInput(r.options.inputName,!0),u=r.getCaretPositionEnd()||0,d=l.substring(0,u||0)||l,f=RegExp(`${r.utilities.escapeRegex(e)}\$`,a?`g`:`gi`),p=d.replace(f,c),m=l.replace(d,p),h=p.length-d.length,g=(u||l.length)+h;g<0&&(g=0),r.setInput(m,r.options.inputName,!0),r.setCaretPosition(g),s&&typeof r.options.onKeyPress==`function`&&r.options.onKeyPress(t,n),typeof r.options.onChange==`function`&&r.options.onChange(r.getInput(r.options.inputName,!0),n),typeof r.options.onChangeAll==`function`&&r.options.onChangeAll(r.getAllInputs(),n)}})}},{key:`handleButtonClicked`,value:function(e,t){var n=this.options,r=n.inputName,i=r===void 0?this.defaultName:r,a=n.debug;if(e!==`{//}`){this.input[i]||(this.input[i]=``),typeof this.options.beforeInputUpdate==`function`&&this.options.beforeInputUpdate(this);var o=this.utilities.getUpdatedInput(e,this.input[i],this.caretPosition,this.caretPositionEnd);if(this.utilities.isStandardButton(e)&&this.activeInputElement&&this.input[i]&&this.input[i]===o&&this.caretPosition===0&&this.caretPositionEnd===o.length)return this.setInput(``,this.options.inputName,!0),this.setCaretPosition(0),this.activeInputElement.value=``,this.activeInputElement.setSelectionRange(0,0),void this.handleButtonClicked(e,t);if(typeof this.options.onKeyPress==`function`&&this.options.onKeyPress(e,t),this.input[i]!==o&&(!this.options.inputPattern||this.options.inputPattern&&this.inputPatternIsValid(o))){if(this.options.maxLength&&this.utilities.handleMaxLength(this.input,o))return;var s=this.utilities.getUpdatedInput(e,this.input[i],this.caretPosition,this.caretPositionEnd,!0);if(this.setInput(s,this.options.inputName,!0),a&&console.log(`Input changed:`,this.getAllInputs()),this.options.debug&&console.log(`Caret at: `,this.getCaretPosition(),this.getCaretPositionEnd(),`(${this.keyboardDOMClass})`,t?.type),this.options.syncInstanceInputs&&this.syncInstanceInputs(),typeof this.options.onChange==`function`&&this.options.onChange(this.getInput(this.options.inputName,!0),t),typeof this.options.onChangeAll==`function`&&this.options.onChangeAll(this.getAllInputs(),t),t!=null&&t.target&&this.options.enableLayoutCandidates){var c,l=this.getInputCandidates(o),u=l.candidateKey,d=l.candidateValue;u&&d?this.showCandidatesBox(u,d,this.keyboardDOM):(c=this.candidateBox)==null||c.destroy()}}this.caretPositionEnd&&this.caretPosition!==this.caretPositionEnd&&(this.setCaretPosition(this.caretPositionEnd,this.caretPositionEnd),this.activeInputElement&&this.activeInputElement.setSelectionRange(this.caretPositionEnd,this.caretPositionEnd),this.options.debug&&console.log(`Caret position aligned`,this.caretPosition)),a&&console.log(`Key pressed:`,e)}}},{key:`getMouseHold`,value:function(){return this.isMouseHold}},{key:`setMouseHold`,value:function(e){this.options.syncInstanceInputs?this.dispatch((function(t){t.isMouseHold=e})):this.isMouseHold=e}},{key:`handleButtonMouseDown`,value:function(e,t){var n=this;t&&(this.options.preventMouseDownDefault&&t.preventDefault(),this.options.stopMouseDownPropagation&&t.stopPropagation(),t.target.classList.add(this.activeButtonClass)),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdTimeout&&clearTimeout(this.holdTimeout),this.setMouseHold(!0),this.options.disableButtonHold||(this.holdTimeout=window.setTimeout((function(){(n.getMouseHold()&&(!e.includes(`{`)&&!e.includes(`}`)||e===`{delete}`||e===`{backspace}`||e===`{bksp}`||e===`{space}`||e===`{tab}`)||e===`{arrowright}`||e===`{arrowleft}`||e===`{arrowup}`||e===`{arrowdown}`)&&(n.options.debug&&console.log(`Button held:`,e),n.handleButtonHold(e)),clearTimeout(n.holdTimeout)}),500))}},{key:`handleButtonMouseUp`,value:function(e,t){var n=this;t&&(this.options.preventMouseUpDefault&&t.preventDefault&&t.preventDefault(),this.options.stopMouseUpPropagation&&t.stopPropagation&&t.stopPropagation(),!(t.target===this.keyboardDOM||t.target&&this.keyboardDOM.contains(t.target)||this.candidateBox&&this.candidateBox.candidateBoxElement&&(t.target===this.candidateBox.candidateBoxElement||t.target&&this.candidateBox.candidateBoxElement.contains(t.target)))&&this.candidateBox&&this.candidateBox.destroy()),this.recurseButtons((function(e){e.classList.remove(n.activeButtonClass)})),this.setMouseHold(!1),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),e&&typeof this.options.onKeyReleased==`function`&&this.options.onKeyReleased(e,t)}},{key:`handleKeyboardContainerMouseDown`,value:function(e){this.options.preventMouseDownDefault&&e.preventDefault()}},{key:`handleButtonHold`,value:function(e){var t=this;this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdInteractionTimeout=window.setTimeout((function(){t.getMouseHold()?(t.handleButtonClicked(e),t.handleButtonHold(e)):clearTimeout(t.holdInteractionTimeout)}),100)}},{key:`syncInstanceInputs`,value:function(){var e=this;this.dispatch((function(t){t.replaceInput(e.input),t.setCaretPosition(e.caretPosition,e.caretPositionEnd)}))}},{key:`clearInput`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName;this.input[e]=``,this.setCaretPosition(0),this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:`getInput`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName,t=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return this.options.syncInstanceInputs&&!t&&this.syncInstanceInputs(),this.options.rtl?`‫`+this.input[e].replace(`‫`,``).replace(`‬`,``)+`‬`:this.input[e]}},{key:`getAllInputs`,value:function(){var e=this,t={};return Object.keys(this.input).forEach((function(n){t[n]=e.getInput(n,!0)})),t}},{key:`setInput`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.options.inputName||this.defaultName,n=arguments.length>2?arguments[2]:void 0;this.input[t]=e,!n&&this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:`replaceInput`,value:function(e){this.input=e}},{key:`setOptions`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=this.changedOptions(e);this.options=Object.assign(this.options,e),t.length&&(this.options.debug&&console.log(`changedOptions`,t),this.onSetOptions(t),this.render())}},{key:`changedOptions`,value:function(e){var t=this;return Object.keys(e).filter((function(n){return JSON.stringify(e[n])!==JSON.stringify(t.options[n])}))}},{key:`onSetOptions`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];e.includes(`layoutName`)&&this.candidateBox&&this.candidateBox.destroy(),(e.includes(`layoutCandidatesPageSize`)||e.includes(`layoutCandidates`))&&this.candidateBox&&(this.candidateBox.destroy(),this.candidateBox=new S({utilities:this.utilities,options:this.options}))}},{key:`resetRows`,value:function(){this.keyboardRowsDOM&&this.keyboardRowsDOM.remove(),this.keyboardDOM.className=this.keyboardDOMClass,this.keyboardDOM.setAttribute(`data-skInstance`,this.currentInstanceName),this.buttonElements={}}},{key:`dispatch`,value:function(e){if(!window.SimpleKeyboardInstances)throw console.warn(`SimpleKeyboardInstances is not defined. Dispatch cannot be called.`),Error(`INSTANCES_VAR_ERROR`);return Object.keys(window.SimpleKeyboardInstances).forEach((function(t){e(window.SimpleKeyboardInstances[t],t)}))}},{key:`addButtonTheme`,value:function(e,t){var n=this;t&&e&&(e.split(` `).forEach((function(r){t.split(` `).forEach((function(t){n.options.buttonTheme||(n.options.buttonTheme=[]);var i=!1;n.options.buttonTheme.map((function(e){if(e!=null&&e.class.split(` `).includes(t)){i=!0;var n=e.buttons.split(` `);n.includes(r)||(i=!0,n.push(r),e.buttons=n.join(` `))}return e})),i||n.options.buttonTheme.push({class:t,buttons:e})}))})),this.render())}},{key:`removeButtonTheme`,value:function(e,t){var n=this;if(!e&&!t)return this.options.buttonTheme=[],void this.render();e&&Array.isArray(this.options.buttonTheme)&&this.options.buttonTheme.length&&(e.split(` `).forEach((function(e){var r;(r=n.options)==null||(r=r.buttonTheme)==null||r.map((function(r,i){if(r&&t&&t.includes(r.class)||!t){var a,o=r?.buttons.split(` `).filter((function(t){return t!==e}));r&&o!=null&&o.length?r.buttons=o.join(` `):((a=n.options.buttonTheme)==null||a.splice(i,1),r=null)}return r}))})),this.render())}},{key:`getButtonElement`,value:function(e){var t,n=this.buttonElements[e];return n&&(t=n.length>1?n:n[0]),t}},{key:`inputPatternIsValid`,value:function(e){var t,n=this.options.inputPattern;if((t=n instanceof RegExp?n:n[this.options.inputName||this.defaultName])&&e){var r=t.test(e);return this.options.debug&&console.log(`inputPattern ("${t}"): ${r?`passed`:`did not pass!`}`),r}return!0}},{key:`setEventListeners`,value:function(){if(this.isFirstKeyboardInstance||!this.allKeyboardInstances){this.options.debug&&console.log(`Caret handling started (${this.keyboardDOMClass})`);var e=this.options.physicalKeyboardHighlightPreventDefault,t=e!==void 0&&e;document.addEventListener(`keyup`,this.handleKeyUp,t),document.addEventListener(`keydown`,this.handleKeyDown,t),document.addEventListener(`mouseup`,this.handleMouseUp),document.addEventListener(`touchend`,this.handleTouchEnd),this.options.updateCaretOnSelectionChange&&document.addEventListener(`selectionchange`,this.handleSelectionChange),document.addEventListener(`select`,this.handleSelect)}}},{key:`handleKeyUp`,value:function(e){this.caretEventHandler(e),this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyUp(e)}},{key:`handleKeyDown`,value:function(e){this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyDown(e)}},{key:`handleMouseUp`,value:function(e){this.caretEventHandler(e)}},{key:`handleTouchEnd`,value:function(e){this.caretEventHandler(e)}},{key:`handleSelect`,value:function(e){this.caretEventHandler(e)}},{key:`handleSelectionChange`,value:function(e){navigator.userAgent.includes(`Firefox`)||this.caretEventHandler(e)}},{key:`caretEventHandler`,value:function(e){var t,n=this;e.target.tagName&&(t=e.target.tagName.toLowerCase()),this.dispatch((function(r){var i=e.target===r.keyboardDOM||e.target&&r.keyboardDOM.contains(e.target);if(n.options.syncInstanceInputs&&Array.isArray(e.path)&&(i=e.path.some((function(e){var t;return e==null||(t=e.hasAttribute)==null?void 0:t.call(e,`data-skInstance`)}))),(t===`textarea`||t===`input`&&[`text`,`search`,`url`,`tel`,`password`].includes(e.target.type))&&!r.options.disableCaretPositioning){var a=e.target.selectionStart,o=e.target.selectionEnd;r.options.rtl&&(a=r.utilities.getRtlOffset(a,r.getInput()),o=r.utilities.getRtlOffset(o,r.getInput())),r.setCaretPosition(a,o),r.activeInputElement=e.target,r.options.debug&&console.log(`Caret at: `,r.getCaretPosition(),r.getCaretPositionEnd(),e&&e.target.tagName.toLowerCase(),`(${r.keyboardDOMClass})`,e?.type)}else !r.options.disableCaretPositioning&&i||e?.type===`selectionchange`||(r.setCaretPosition(null),r.activeInputElement=null,r.options.debug&&console.log(`Caret position reset due to "${e?.type}" event`,e))}))}},{key:`recurseButtons`,value:function(e){var t=this;e&&Object.keys(this.buttonElements).forEach((function(n){return t.buttonElements[n].forEach(e)}))}},{key:`destroy`,value:function(){this.options.debug&&console.log(`Destroying simple-keyboard instance: ${this.currentInstanceName}`);var e=this.options.physicalKeyboardHighlightPreventDefault,t=e!==void 0&&e;document.removeEventListener(`keyup`,this.handleKeyUp,t),document.removeEventListener(`keydown`,this.handleKeyDown,t),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`touchend`,this.handleTouchEnd),document.removeEventListener(`select`,this.handleSelect),this.options.updateCaretOnSelectionChange&&document.removeEventListener(`selectionchange`,this.handleSelectionChange),document.onpointerup=null,document.ontouchend=null,document.ontouchcancel=null,document.onmouseup=null,this.recurseButtons((function(e){e&&=(e.onpointerdown=null,e.onpointerup=null,e.onpointercancel=null,e.ontouchstart=null,e.ontouchend=null,e.ontouchcancel=null,e.onclick=null,e.onmousedown=null,e.onmouseup=null,e.remove(),null)})),this.keyboardDOM.onpointerdown=null,this.keyboardDOM.ontouchstart=null,this.keyboardDOM.onmousedown=null,this.resetRows(),this.candidateBox&&=(this.candidateBox.destroy(),null),this.activeInputElement=null,this.keyboardDOM.removeAttribute(`data-skInstance`),this.keyboardDOM.innerHTML=``,window.SimpleKeyboardInstances[this.currentInstanceName]=null,delete window.SimpleKeyboardInstances[this.currentInstanceName],this.initialized=!1}},{key:`getButtonThemeClasses`,value:function(e){var t=this.options.buttonTheme,n=[];return Array.isArray(t)&&t.forEach((function(t){if(t&&t.class&&typeof t.class==`string`&&t.buttons&&typeof t.buttons==`string`){var r=t.class.split(` `);t.buttons.split(` `).includes(e)&&(n=[].concat(C(n),C(r)))}else console.warn(`Incorrect "buttonTheme". Please check the documentation.`,t)})),n}},{key:`setDOMButtonAttributes`,value:function(e,t){var n=this.options.buttonAttributes;Array.isArray(n)&&n.forEach((function(n){n.attribute&&typeof n.attribute==`string`&&n.value&&typeof n.value==`string`?n.buttons&&typeof n.buttons==`string`?n.buttons.split(` `).includes(e)&&t(n.attribute,n.value):t(n.attribute,n.value):console.warn(`Incorrect "buttonAttributes". Please check the documentation.`,n)}))}},{key:`onTouchDeviceDetected`,value:function(){this.processAutoTouchEvents(),this.disableContextualWindow()}},{key:`disableContextualWindow`,value:function(){window.oncontextmenu=function(e){var t;if((t=e.target.classList)!=null&&t.contains(`hg-button`))return e.preventDefault(),e.stopPropagation(),!1}}},{key:`processAutoTouchEvents`,value:function(){this.options.autoUseTouchEvents&&(this.options.useTouchEvents=!0,this.options.debug&&console.log(`autoUseTouchEvents: Touch device detected, useTouchEvents enabled.`))}},{key:`onInit`,value:function(){this.options.debug&&console.log(`${this.keyboardDOMClass} Initialized`),this.setEventListeners(),typeof this.options.onInit==`function`&&this.options.onInit(this)}},{key:`beforeFirstRender`,value:function(){this.utilities.isTouchDevice()&&this.onTouchDeviceDetected(),typeof this.options.beforeFirstRender==`function`&&this.options.beforeFirstRender(this),this.isFirstKeyboardInstance&&this.utilities.pointerEventsSupported()&&!this.options.useTouchEvents&&!this.options.useMouseEvents&&this.options.debug&&console.log(`Using PointerEvents as it is supported by this browser`),this.options.useTouchEvents&&this.options.debug&&console.log(`useTouchEvents has been enabled. Only touch events will be used.`)}},{key:`beforeRender`,value:function(){typeof this.options.beforeRender==`function`&&this.options.beforeRender(this)}},{key:`onRender`,value:function(){typeof this.options.onRender==`function`&&this.options.onRender(this)}},{key:`onModulesLoaded`,value:function(){typeof this.options.onModulesLoaded==`function`&&this.options.onModulesLoaded(this)}},{key:`loadModules`,value:function(){var e=this;Array.isArray(this.options.modules)&&(this.options.modules.forEach((function(t){var n=e.utilities.isConstructor(t)?new t(e):t(e);n.init&&n.init(e)})),this.keyboardPluginClasses=`modules-loaded`,this.render(),this.onModulesLoaded())}},{key:`getModuleProp`,value:function(e,t){return!!this.modules[e]&&this.modules[e][t]}},{key:`getModulesList`,value:function(){return Object.keys(this.modules)}},{key:`parseRowDOMContainers`,value:function(e,t,n,r){var i=this,a=Array.from(e.children),o=0;return a.length&&n.forEach((function(n,s){var c=r[s];if(!(c&&c>n))return!1;var l=n-o,u=c-o,d=document.createElement(`div`);d.className+=`hg-button-container`;var f=`${i.options.layoutName}-r${t}c${s}`;d.setAttribute(`data-skUID`,f);var p=a.splice(l,u-l+1);o+=u-l,p.forEach((function(e){return d.appendChild(e)})),a.splice(l,0,d),e.innerHTML=``,a.forEach((function(t){return e.appendChild(t)})),i.options.debug&&console.log(`rowDOMContainer`,p,l,u,o+1)})),e}},{key:`render`,value:function(){var e=this;this.resetRows(),this.initialized||this.beforeFirstRender(),this.beforeRender();var t=`hg-layout-${this.options.layoutName}`,n=this.options.layout||{default:["` 1 2 3 4 5 6 7 8 9 0 - = {bksp}",`{tab} q w e r t y u i o p [ ] \\`,`{lock} a s d f g h j k l ; ' {enter}`,`{shift} z x c v b n m , . / {shift}`,`.com @ {space}`],shift:[`~ ! @ # $ % ^ & * ( ) _ + {bksp}`,`{tab} Q W E R T Y U I O P { } |`,`{lock} A S D F G H J K L : " {enter}`,`{shift} Z X C V B N M < > ? {shift}`,`.com @ {space}`]},r=this.options.useTouchEvents||!1,i=r?`hg-touch-events`:``,a=this.options.useMouseEvents||!1,o=this.options.disableRowButtonContainers;this.keyboardDOM.className=this.getKeyboardClassString(this.options.theme,t,this.keyboardPluginClasses,i),this.keyboardDOM.setAttribute(`data-skInstance`,this.currentInstanceName),this.keyboardRowsDOM=document.createElement(`div`),this.keyboardRowsDOM.className=`hg-rows`,n[this.options.layoutName||this.defaultName].forEach((function(t,n){var i=t.split(` `);e.options.excludeFromLayout&&e.options.excludeFromLayout[e.options.layoutName||e.defaultName]&&(i=i.filter((function(t){return e.options.excludeFromLayout&&!e.options.excludeFromLayout[e.options.layoutName||e.defaultName].includes(t)})));var s=document.createElement(`div`);s.className+=`hg-row`;var c=[],l=[];i.forEach((function(t,i){var u,d=!o&&typeof t==`string`&&t.length>1&&t.indexOf(`[`)===0,f=!o&&typeof t==`string`&&t.length>1&&t.indexOf(`]`)===t.length-1;d&&(c.push(i),t=t.replace(/\[/g,``)),f&&(l.push(i),t=t.replace(/\]/g,``));var p=e.utilities.getButtonClass(t),m=e.utilities.getButtonDisplayName(t,e.options.display,e.options.mergeDisplay),h=e.options.useButtonTag?`button`:`div`,g=document.createElement(h);g.className+=`hg-button ${p}`,(u=g.classList).add.apply(u,C(e.getButtonThemeClasses(t))),e.setDOMButtonAttributes(t,(function(e,t){g.setAttribute(e,t)})),e.activeButtonClass=`hg-activeButton`,!e.utilities.pointerEventsSupported()||r||a?r?(g.ontouchstart=function(n){e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.ontouchend=function(n){e.handleButtonMouseUp(t,n)},g.ontouchcancel=function(n){e.handleButtonMouseUp(t,n)}):(g.onclick=function(n){e.setMouseHold(!1),typeof e.options.onKeyReleased==`function`||e.options.useMouseEvents&&e.options.clickOnMouseDown||e.handleButtonClicked(t,n)},g.onmousedown=function(n){(typeof e.options.onKeyReleased==`function`||e.options.useMouseEvents&&e.options.clickOnMouseDown)&&!e.isMouseHold&&e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.onmouseup=function(n){e.handleButtonMouseUp(t,n)}):(g.onpointerdown=function(n){e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.onpointerup=function(n){e.handleButtonMouseUp(t,n)},g.onpointercancel=function(n){e.handleButtonMouseUp(t,n)}),g.setAttribute(`data-skBtn`,t);var _=`${e.options.layoutName}-r${n}b${i}`;g.setAttribute(`data-skBtnUID`,_);var v=document.createElement(`span`);v.innerHTML=m,g.appendChild(v),e.buttonElements[t]||(e.buttonElements[t]=[]),e.buttonElements[t].push(g),s.appendChild(g)})),s=e.parseRowDOMContainers(s,n,c,l),e.keyboardRowsDOM.appendChild(s)})),this.keyboardDOM.appendChild(this.keyboardRowsDOM),this.onRender(),this.initialized||(this.initialized=!0,!this.utilities.pointerEventsSupported()||r||a?r?(document.ontouchend=function(t){return e.handleButtonMouseUp(void 0,t)},document.ontouchcancel=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.ontouchstart=function(t){return e.handleKeyboardContainerMouseDown(t)}):r||(document.onmouseup=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.onmousedown=function(t){return e.handleKeyboardContainerMouseDown(t)}):(document.onpointerup=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.onpointerdown=function(t){return e.handleKeyboardContainerMouseDown(t)}),this.onInit())}}],t&&D(e.prototype,t),n&&D(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}(),j=A;return r}()},442:function(t){t.exports=e}},n={};function r(e){var i=n[e];if(i!==void 0)return i.exports;var a=n[e]={exports:{}};return t[e].call(a.exports,a,a.exports,r),a.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){typeof Symbol<`u`&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return function(){r.r(i),r.d(i,{KeyboardReact:function(){return u},default:function(){return d}}),r(981);var e=r(442),t=r(548),n=r.n(t);function a(e){return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function s(e){for(var t=1;t{e?.(t)},[t,e]);let d=(0,y.useCallback)(e=>{if(a.current)return;let t=e.target;if(!t.closest(`[data-vkb="false"]`)){if(t instanceof HTMLInputElement){if(!_1e.has(t.type))return}else if(!(t instanceof HTMLTextAreaElement))return;c.current=t,n(!0),s(`default`),l.current?.setInput?.(c.current.value),setTimeout(()=>{(t.closest(`.bg-zinc-800, .rounded-lg, [data-vkb-group]`)??t).scrollIntoView({behavior:`smooth`,block:`nearest`})},100)}},[]),f=(0,y.useCallback)(()=>{setTimeout(()=>{let e=document.activeElement;e&&(u.current?.contains(e)||e===c.current)||(n(!1),c.current=null)},150)},[]);(0,y.useEffect)(()=>(document.addEventListener(`focusin`,d),document.addEventListener(`focusout`,f),()=>{document.removeEventListener(`focusin`,d),document.removeEventListener(`focusout`,f)}),[d,f]);let p=(0,y.useCallback)(()=>{a.current=!0,i(!0),c.current?.blur(),c.current=null,setTimeout(()=>{n(!1),i(!1),a.current=!1},400)},[]),m=(0,y.useCallback)(e=>{let t=c.current;if(t){if(e===`{shift}`){s(e=>e==="default"?`shift`:`default`);return}if(e===`{lock}`){s(e=>e==="default"?`shift`:`default`);return}if(e===`{close}`){p();return}e===`{bksp}`?W9(t,t.value.slice(0,-1)):e===`{space}`?W9(t,t.value+` `):(W9(t,t.value+e),o===`shift`&&s(`default`)),t.focus(),l.current?.setInput?.(t.value)}},[o,p]);return t?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-[9998] bg-transparent`,onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),r||p()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation(),r||p()},onClick:e=>{e.preventDefault(),e.stopPropagation()}}),!r&&(0,G.jsx)(`div`,{ref:u,className:`relative z-[9999] shrink-0`,onMouseDown:e=>e.preventDefault(),onTouchStart:e=>{e.target.closest(`.hg-button`)||e.preventDefault()},children:(0,G.jsx)(g1e,{keyboardRef:e=>{l.current=e},layoutName:o,onKeyPress:m,theme:`simple-keyboard vkb-theme`,layout:{default:[`1 2 3 4 5 6 7 8 9 0 {bksp}`,`q w e r t y u i o p`,`{lock} a s d f g h j k l`,`{shift} z x c v b n m . @`,`{space} {close}`],shift:[`! @ # $ % ^ & * ( ) {bksp}`,`Q W E R T Y U I O P`,`{lock} A S D F G H J K L`,`{shift} Z X C V B N M , _`,`{space} {close}`]},display:{"{bksp}":`⌫`,"{close}":`✕ Close`,"{shift}":`⇧`,"{lock}":`⇪`,"{space}":` `}})})]}):null}function y1e(){Of();let[e,t]=(0,y.useState)(null),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(100),{i18n:o}=U(),s=or(),c=rr(),l=p1e(),{setViewportSuppressed:u}=Hd();(0,y.useEffect)(()=>(u(!0),()=>u(!1)),[u]);let{data:d}=K({queryKey:[`settings`],queryFn:Z.getSettings});(0,y.useEffect)(()=>{d?.language&&d.language!==o.language&&o.changeLanguage(d.language)},[d?.language,o]);let{data:f=[]}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Cd.getDevices(),refetchInterval:3e4}),p=f[0],m=l.deviceOnline||!!p?.online,h=(0,y.useMemo)(()=>({...l,deviceOnline:m}),[l,m]),g=(0,y.useRef)(!1);(0,y.useEffect)(()=>{p&&!g.current&&(a(p.display_brightness),g.current=!0)},[p]),(0,y.useEffect)(()=>{let e=document.documentElement,t=e.classList.contains(`dark`);return e.classList.add(`dark`),()=>{t||e.classList.remove(`dark`)}},[]);let{data:_}=K({queryKey:[`spoolbuddy-update-check`,p?.device_id],queryFn:()=>p?Cd.checkDaemonUpdate(p.device_id):Promise.resolve(null),enabled:!!p,refetchInterval:300*1e3,staleTime:0}),v=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!m){let e=`SpoolBuddy device disconnected`;r({type:`warning`,message:e}),v.current=e}else if(_?.update_available&&_.latest_version){let e=`Update available: v${_.latest_version}`;r({type:`info`,message:e}),v.current=e}else v.current&&=(r(null),null)},[m,_?.update_available,_?.latest_version]);let b=!!(l.matchedSpool||l.unknownTagUid||l.unknownTrayUuid),x=(0,y.useRef)(!1);(0,y.useEffect)(()=>{b&&!x.current&&c.pathname!==`/spoolbuddy`&&s(`/spoolbuddy`),x.current=b},[b,c.pathname,s]);let{data:S=[]}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),C=Co({queries:S.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id),refetchInterval:1e4,select:e=>({connected:e?.connected})}))}),w=(0,y.useMemo)(()=>S.filter((e,t)=>C[t]?.data?.connected),[S,C]),T=(0,y.useRef)(null),E=(0,y.useRef)(!1),D=(0,y.useRef)(null),O=(0,y.useCallback)(e=>{T.current={x:e.touches[0].clientX,y:e.touches[0].clientY},E.current=!1},[]),k=(0,y.useCallback)(n=>{if(!T.current)return;let r=n.changedTouches[0].clientX-T.current.x,i=n.changedTouches[0].clientY-T.current.y,a=T.current.y;if(T.current=null,E.current=!1,i>=50&&Math.abs(i)>Math.abs(r)&&a<120){N(!0);return}if(w.length<2||Math.abs(r)<50||Math.abs(i)>Math.abs(r))return;let o=w.findIndex(t=>t.id===e);t(w[r<0?(o+1)%w.length:(o-1+w.length)%w.length].id)},[w,e,t]);(0,y.useEffect)(()=>{let e=D.current;if(!e)return;let t=e=>{if(!T.current)return;let t=Math.abs(e.touches[0].clientX-T.current.x),n=Math.abs(e.touches[0].clientY-T.current.y);if(E.current){e.preventDefault();return}t>10&&t>n&&(E.current=!0,e.preventDefault())};return e.addEventListener(`touchmove`,t,{passive:!1}),()=>e.removeEventListener(`touchmove`,t)},[]);let[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(!1);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{ref:D,"data-spoolbuddy-kiosk":!0,className:`w-screen h-screen bg-bambu-dark text-white flex flex-col overflow-hidden`,style:{...i<100?{filter:`brightness(${i/100})`}:void 0,overscrollBehaviorX:`none`},onTouchStart:O,onTouchEnd:k,children:[(0,G.jsx)(`button`,{onClick:()=>N(!0),className:`w-full h-1.5 bg-bambu-dark-secondary flex justify-center items-center shrink-0 touch-none`,"aria-label":`Open quick menu`,children:(0,G.jsx)(`div`,{className:`w-8 h-0.5 rounded-full bg-zinc-600`})}),(0,G.jsx)(o1e,{selectedPrinterId:e,onPrinterChange:t,deviceOnline:m}),(0,G.jsx)(`main`,{className:`flex-1 overflow-y-auto`,children:(0,G.jsx)(Ir,{context:{selectedPrinterId:e,setSelectedPrinterId:t,sbState:h,setAlert:r,displayBrightness:i,setDisplayBrightness:a}})}),!A&&(0,G.jsx)(l1e,{alert:n}),!A&&(0,G.jsx)(c1e,{}),(0,G.jsx)(v1e,{onVisibilityChange:j})]}),(0,G.jsx)(u1e,{isOpen:M,onClose:()=>N(!1),deviceId:p?.device_id??null,deviceOnline:m})]})}function G9({color:e,isEmpty:t,size:n=32}){return t?(0,G.jsx)(`div`,{className:`rounded-full border-2 border-dashed border-zinc-500 flex items-center justify-center`,style:{width:n,height:n},children:(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-zinc-600`})}):(0,G.jsxs)(`svg`,{width:n,height:n,viewBox:`0 0 32 32`,children:[(0,G.jsx)(`circle`,{cx:`16`,cy:`16`,r:`14`,fill:e,stroke:`white`,strokeWidth:`1.5`,strokeOpacity:`0.7`}),(0,G.jsx)(`circle`,{cx:`16`,cy:`16`,r:`11`,fill:e,style:{filter:`brightness(0.85)`}})]})}var b1e=`spoolbuddy-default-core-weight`;function x1e(){try{let e=localStorage.getItem(b1e);if(e){let t=parseInt(e,10);if(t>=0&&t<=500)return t}}catch{}return 250}function S1e({spool:e,scaleWeight:t,onClose:n,onSyncWeight:r,onAssignToAms:i,isAssigned:a,onUnassignFromAms:o}){let{t:s}=U(),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(!1),f=wf(e.rgba),p=e.core_weight&&e.core_weight>0?e.core_weight:x1e(),m=t===null?null:Math.round(Math.max(0,t)),h=m===null?null:Math.round(Math.max(0,m-p)),g=Math.round(e.label_weight||1e3),_=h===null?null:Math.min(100,Math.round(h/g*100)),v=_===null?`#808080`:_>50?`#22c55e`:_>20?`#eab308`:`#ef4444`,b=Math.max(0,(e.label_weight||0)-(e.weight_used||0))+p,x=m===null?null:m-b,S=x===null?null:Math.abs(x)<=50,C=async()=>{if(t!==null){l(!0);try{await Cd.updateSpoolWeight(e.id,Math.round(t)),d(!0),r?.(),setTimeout(()=>d(!1),3e3)}catch(e){console.error(`Failed to sync weight:`,e)}finally{l(!1)}}};return(0,G.jsxs)(`div`,{className:`flex flex-col items-center space-y-4 max-w-md`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-5`,children:[(0,G.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,G.jsx)(G9,{color:f,isEmpty:!1,size:100}),_!==null&&(0,G.jsxs)(`div`,{className:`absolute -bottom-2 -right-2 px-2 py-0.5 rounded-full text-xs font-bold text-white shadow-lg`,style:{backgroundColor:v},children:[_,`%`]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:e.color_name||`Unknown color`}),(0,G.jsxs)(`span`,{className:`text-xs font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,G.jsxs)(`p`,{className:`text-sm text-zinc-400`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]}),h!==null&&(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-3xl font-bold font-mono text-zinc-100`,children:[h,`g`]}),(0,G.jsxs)(`span`,{className:`text-sm text-zinc-500`,children:[`/ `,g,`g`]})]}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mt-0.5`,children:s(`spoolbuddy.spool.remaining`,`Remaining`)}),(0,G.jsx)(`div`,{className:`mt-2 max-w-xs`,children:(0,G.jsx)(`div`,{className:`h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500`,style:{width:`${_}%`,backgroundColor:v}})})})]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-2 text-sm bg-zinc-800 rounded-lg p-4 w-full`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.dashboard.grossWeight`,`Gross weight`)}),(0,G.jsx)(`span`,{className:`font-mono text-zinc-300`,children:m===null?`—`:`${m}g`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.spool.coreWeight`,`Core`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[p,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.dashboard.spoolSize`,`Spool size`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[g,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.spool.scaleWeight`,`Scale`)}),m===null?(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`—`}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 font-mono ${S?`text-green-500`:`text-yellow-500`}`,children:[m,`g`,S?(0,G.jsx)(ds,{className:`w-3.5 h-3.5`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Iu,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`button`,{onClick:C,className:`p-1 hover:bg-green-500/20 rounded transition-colors text-green-500`,title:s(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`),children:(0,G.jsx)(Vl,{className:`w-4 h-4`})})]})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.dashboard.tagId`,`Tag`)}),(0,G.jsx)(`span`,{className:`font-mono text-xs text-zinc-400 truncate max-w-[120px]`,title:e.tag_uid||``,children:e.tag_uid?e.tag_uid.slice(-8):`—`})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[i&&(0,G.jsx)(`button`,{onClick:a?void 0:i,disabled:!!a,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px] disabled:opacity-50 disabled:cursor-not-allowed`,children:s(`spoolbuddy.modal.assignToAms`,`Assign to AMS`)}),o&&(0,G.jsxs)(`button`,{onClick:o,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-red-600/20 text-red-400 hover:bg-red-600/30 transition-colors min-h-[44px]`,children:[(0,G.jsx)(zu,{className:`w-4 h-4 inline mr-1`}),s(`inventory.unassignSpool`)]}),(0,G.jsx)(`button`,{onClick:C,disabled:t===null||c,className:`px-5 py-2.5 rounded-lg text-sm font-medium transition-colors min-h-[44px] ${u?`bg-green-600/20 text-green-400`:i?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600 disabled:opacity-40 disabled:cursor-not-allowed`:`bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed`}`,children:c?`...`:u?s(`spoolbuddy.dashboard.weightSynced`,`Synced!`):s(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`)}),n&&(0,G.jsx)(`button`,{onClick:n,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:s(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function C1e({tagUid:e,scaleWeight:t,coreWeight:n,onLinkSpool:r,onAddToInventory:i,onClose:a}){let{t:o}=U(),s=n??x1e(),c=t===null?null:Math.round(Math.max(0,t)),l=c===null?null:Math.round(Math.max(0,c-s));return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-5`,children:[(0,G.jsx)(`div`,{className:`w-20 h-20 rounded-2xl bg-green-500/15 flex items-center justify-center`,children:(0,G.jsx)(`svg`,{className:`w-10 h-10 text-green-500`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z`})})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:o(`spoolbuddy.dashboard.newTag`,`New Tag Detected`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-500 font-mono mt-1`,children:e})]}),c!==null&&(0,G.jsxs)(`div`,{className:`text-sm text-zinc-400`,children:[(0,G.jsxs)(`span`,{className:`font-mono font-semibold`,children:[c,`g`]}),` `,o(`spoolbuddy.dashboard.onScale`,`on scale`),l!==null&&l>0&&(0,G.jsxs)(`span`,{className:`text-zinc-500`,children:[` • ~`,l,`g filament`]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2 justify-center`,children:[i&&(0,G.jsx)(`button`,{onClick:i,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:o(`spoolbuddy.modal.addToInventory`,`Add to Inventory`)}),r&&(0,G.jsxs)(`button`,{onClick:r,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4 inline-block mr-1.5 -mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1`})}),o(`inventory.assignSpool`,`Assign Spool`)]}),a&&(0,G.jsx)(`button`,{onClick:a,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:o(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function w1e(e){return e?`#${e.slice(0,6)}`:`#808080`}function T1e(e){return!e.tray_type||e.tray_type===``}function E1e(e){if(e.tray_type)return null;if(e.exists===!0)return`reset`;if(e.exists===!1)return`physical`;let t=e.state??null;return t===9||t===10?`physical`:`reset`}function D1e(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function O1e({className:e}){return(0,G.jsx)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,G.jsx)(`path`,{d:`M17.8131 0.00538C18.4463 -0.15091 20.3648 3.14642 20.8264 3.84781C25.4187 10.816 35.3089 26.9368 35.9383 34.8694C37.4182 53.5822 11.882 61.3357 2.53721 45.3789C-1.73471 38.0791 0.016 32.2049 3.178 25.0232C6.99221 16.3662 12.6411 7.90372 17.8131 0.00538ZM18.3738 7.24807L17.5881 7.48441C14.4452 12.9431 10.917 18.2341 8.19369 23.9368C4.6808 31.29 1.18317 38.5479 7.69403 45.5657C17.3058 55.9228 34.9847 46.8808 31.4604 32.8681C29.2558 24.0969 22.4207 15.2913 18.3776 7.24807H18.3738Z`,fill:`#C3C2C1`})})}function k1e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 35 53`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`path`,{d:`M17.3165 0.0038C17.932 -0.14959 19.7971 3.08645 20.2458 3.77481C24.7103 10.6135 34.3251 26.4346 34.937 34.2198C36.3757 52.5848 11.5505 60.1942 2.46584 44.534C-1.68714 37.3735 0.0148 31.6085 3.08879 24.5603C6.79681 16.0605 12.2884 7.75907 17.3165 0.0038ZM17.8615 7.11561L17.0977 7.34755C14.0423 12.7048 10.6124 17.8974 7.96483 23.4941C4.54975 30.7107 1.14949 37.8337 7.47908 44.721C16.8233 54.8856 34.01 46.0117 30.5838 32.2595C28.4405 23.6512 21.7957 15.0093 17.8652 7.11561H17.8615Z`,fill:`#C3C2C1`}),(0,G.jsx)(`path`,{d:`M5.03547 30.112C9.64453 30.4936 11.632 35.7985 16.4154 35.791C19.6339 35.7873 20.2161 33.2283 22.3853 31.6197C31.6776 24.7286 33.5835 37.4894 27.9881 44.4254C18.1878 56.5653 -1.16063 44.6013 5.03917 30.1158L5.03547 30.112Z`,fill:`#1F8FEB`})]})}function A1e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`path`,{d:`M17.9625 4.48059L4.77216 26.3154L2.08228 40.2175L10.0224 50.8414H23.1594L33.3246 42.1693V30.2455L17.9625 4.48059Z`,fill:`#1F8FEB`}),(0,G.jsx)(`path`,{d:`M17.7948 0.00538C18.4273 -0.15091 20.3438 3.14642 20.8048 3.84781C25.3921 10.816 35.2715 26.9368 35.9001 34.8694C37.3784 53.5822 11.8702 61.3357 2.53562 45.3789C-1.73163 38.0829 0.0134 32.2087 3.1757 25.027C6.98574 16.3662 12.6284 7.90372 17.7948 0.00538ZM18.3549 7.24807L17.57 7.48441C14.4306 12.9431 10.9063 18.2341 8.1859 23.9368C4.67686 31.29 1.18305 38.5479 7.68679 45.5657C17.2881 55.9228 34.9476 46.8808 31.4271 32.8681C29.2249 24.0969 22.3974 15.2913 18.3587 7.24807H18.3549Z`,fill:`#C3C2C1`})]})}function j1e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`}),(0,G.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2.5`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function M1e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`rect`,{x:`4.5`,y:`8`,width:`3`,height:`4.5`,fill:`#d4a017`,rx:`0.5`}),(0,G.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#d4a017`}),(0,G.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function N1e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`rect`,{x:`4.5`,y:`3`,width:`3`,height:`9.5`,fill:`#c62828`,rx:`0.5`}),(0,G.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#c62828`}),(0,G.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function P1e({humidity:e,goodThreshold:t=40,fairThreshold:n=60}){let r,i;return e<=t?(r=`#22a352`,i=O1e):e<=n?(r=`#d4a017`,i=k1e):(r=`#c62828`,i=A1e),(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,G.jsx)(i,{className:`w-3 h-3.5`}),(0,G.jsxs)(`span`,{className:`font-medium tabular-nums text-xs`,style:{color:r},children:[e,`%`]})]})}function F1e({temp:e,goodThreshold:t=28,fairThreshold:n=35}){let r,i;return e<=t?(r=`#22a352`,i=j1e):e<=n?(r=`#d4a017`,i=M1e):(r=`#c62828`,i=N1e),(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,G.jsx)(i,{className:`w-3 h-3.5`}),(0,G.jsxs)(`span`,{className:`font-medium tabular-nums text-xs`,style:{color:r},children:[e,`°C`]})]})}function K9({side:e}){return(0,G.jsx)(`span`,{className:`inline-flex items-center justify-center w-4 h-4 text-[9px] font-bold rounded`,style:{backgroundColor:`#1a4d2e`,color:`#00ae42`},children:e})}function I1e({tray:e,slotIndex:t,isActive:n,fillOverride:r,spoolmanFill:i,onClick:a}){let o=T1e(e),s=E1e(e),c=w1e(e.tray_color),l=e.remain!==null&&e.remain!==void 0&&e.remain>=0?e.remain:null,u=i??(r===0&&l!==null&&l>0?null:r)??l;return(0,G.jsxs)(`div`,{className:`relative flex flex-col items-center p-2.5 rounded-lg transition-all ${n?`ring-2 ring-bambu-green`:``} ${a?`cursor-pointer hover:bg-white/5`:``}`,onClick:a,title:a?`AMS Slot ${t+1}`:void 0,children:[(0,G.jsxs)(`div`,{className:`relative w-16 h-16 mb-1`,children:[o?(0,G.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-full bg-gray-600`})}):(0,G.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:c}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:c,style:{filter:`brightness(0.85)`}}),(0,G.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]}),n&&(0,G.jsx)(`div`,{className:`absolute -bottom-1 left-1/2 -translate-x-1/2 w-2.5 h-2.5 bg-bambu-green rounded-full`})]}),(0,G.jsx)(`span`,{className:`text-sm text-white/70 truncate max-w-full`,title:s===`reset`?`Spool loaded — slot not configured`:void 0,children:o?s===`reset`?`?`:`Empty`:e.tray_type||`Unknown`}),!o&&u!==null&&u>=0&&(0,G.jsx)(`div`,{className:`w-full h-1 bg-bambu-dark-tertiary rounded-full overflow-hidden mt-1`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${u}%`,backgroundColor:Ep(u)}})}),(0,G.jsx)(`span`,{className:`absolute top-1 right-1 text-xs text-white/30`,children:t+1})]})}function L1e({unit:e,activeSlot:t,onConfigureSlot:n,isDualNozzle:r,nozzleSide:i,thresholds:a,fillOverrides:o,spoolmanFillOverrides:s}){let c=e.tray||[],l=e.is_ams_ht,u=l?1:4;return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-white font-medium text-base`,children:D1e(e.id)}),r&&i&&(0,G.jsx)(K9,{side:i})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.temp!=null&&(0,G.jsx)(F1e,{temp:e.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair}),e.humidity!=null&&(0,G.jsx)(P1e,{humidity:e.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair})]})]}),(0,G.jsx)(`div`,{className:`grid ${l?`grid-cols-1 max-w-[100px] mx-auto`:`grid-cols-4`} gap-2`,children:Array.from({length:u}).map((r,i)=>{let a=c[i]||{id:i,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null};return(0,G.jsx)(I1e,{tray:a,slotIndex:i,isActive:t===i,fillOverride:o?.[`${e.id}-${i}`]??null,spoolmanFill:s?.[`${e.id}-${i}`]??null,onClick:n?()=>n(e.id,i,T1e(a)?null:a):void 0},i)})})]})}function q9(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function J9(e){return!e.tray_type||e.tray_type===``}function R1e(e){return e?`#${e.slice(0,6)}`:`#808080`}var Y9=e=>(e??``).trim().toUpperCase();function z1e(e,t){let n=Y9(e),r=Y9(t);return!n||!r?`none`:n===r?`exact`:r.includes(n)||n.includes(r)?`partial`:`none`}function B1e(e,t){let n=Y9(e),r=Y9(t);return!n||!r?!1:n===r}function V1e({isOpen:e,onClose:t,spool:n,printerId:r,spoolmanMode:i=!1}){let{t:a}=U(),o=co(),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null);(0,y.useEffect)(()=>{e&&(c(null),u(null),f(!1),m(null),g(null))},[e]);let _=(0,y.useCallback)(e=>{e.key===`Escape`&&t()},[t]);(0,y.useEffect)(()=>(e&&document.addEventListener(`keydown`,_),()=>document.removeEventListener(`keydown`,_)),[e,_]);let{data:v}=K({queryKey:[`printerStatus`,r],queryFn:()=>Z.getPrinterStatus(r),enabled:e&&r!==null,refetchInterval:5e3}),{data:b}=K({queryKey:[`printer`,r],queryFn:()=>Z.getPrinter(r),enabled:e&&r!==null}),{data:x}=K({queryKey:[`settings`],queryFn:()=>Z.getSettings(),enabled:e,staleTime:300*1e3}),{data:S}=K({queryKey:[`spool-assignments`,r],queryFn:()=>Z.getAssignments(r),enabled:e&&r!==null,staleTime:30*1e3}),{data:C=[]}=K({queryKey:[`spoolman-slot-assignments`,r],queryFn:()=>Z.getSpoolmanSlotAssignments(r??void 0),enabled:e&&!!i&&r!==null,staleTime:30*1e3}),w=i?C.find(e=>e.spoolman_spool_id===n.id):void 0,T=(0,y.useMemo)(()=>{let e={};if(!S)return e;for(let t of S){let n=t.spool;if(n&&n.label_weight>0&&n.weight_used!=null){let r=Math.round(Math.max(0,n.label_weight-n.weight_used)/n.label_weight*100);e[`${t.ams_id}-${t.tray_id}`]=r}}return e},[S]),E=x?{humidityGood:Number(x.ams_humidity_good)||40,humidityFair:Number(x.ams_humidity_fair)||60,tempGood:Number(x.ams_temp_good)||28,tempFair:Number(x.ams_temp_fair)||35}:void 0,D=v?.connected??!1,O=(0,y.useMemo)(()=>v?.ams??[],[v?.ams]),k=(0,y.useMemo)(()=>O.filter(e=>!e.is_ams_ht),[O]),A=(0,y.useMemo)(()=>O.filter(e=>e.is_ams_ht),[O]),j=(0,y.useMemo)(()=>[...v?.vt_tray??[]].sort((e,t)=>(e.id??254)-(t.id??254)),[v?.vt_tray]),M=b?.nozzle_count===2||v?.temperatures?.nozzle_2!==void 0,N=(0,y.useRef)({});(0,y.useEffect)(()=>{v?.ams_extruder_map&&Object.keys(v.ams_extruder_map).length>0&&(N.current=v.ams_extruder_map)},[v?.ams_extruder_map]);let P=v?.ams_extruder_map&&Object.keys(v.ams_extruder_map).length>0?v.ams_extruder_map:N.current,F=v?.fila_switch?.installed===!0,I=(0,y.useCallback)(e=>{if(!M)return null;let t=P[String(e)];return t===void 0?F?null:(e>=128?e-128:e)===1?`L`:`R`:t===1?`L`:`R`},[M,P,F]),L=q({mutationFn:async({amsId:e,trayId:t})=>{if(!r)throw Error(`No printer selected`);return i?await Z.assignSpoolmanSlot({spoolman_spool_id:n.id,printer_id:r,ams_id:e,tray_id:t}):await Z.assignSpool({spool_id:n.id,printer_id:r,ams_id:e,tray_id:t})},onSuccess:e=>{u(`success`);let n=e&&`pending_config`in e&&e.pending_config;c(n?a(`spoolbuddy.modal.assignPendingInsert`,`Assigned. Slot will configure when you insert the spool.`):a(`spoolbuddy.modal.assignSuccess`,`Assigned!`)),o.invalidateQueries({queryKey:[`slotPresets`]}),o.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),o.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),setTimeout(()=>t(),n?2500:1500)},onError:e=>{u(`error`),c(e instanceof Error?e.message:a(`spoolbuddy.modal.assignError`,`Failed to assign spool.`))}}),R=L.isPending,z=(0,y.useCallback)((e,t)=>{if(e===254||e===255){let n=e===254?254:254+t;return j.find(e=>(e.id??254)===n)||null}return O.find(t=>t.id===e)?.tray?.find(e=>e.id===t)||null},[O,j]),B=(0,y.useCallback)((e,t)=>e<=3?`${q9(e)} ${a(`ams.slot`,`Slot`)} ${t+1}`:e>=128&&e<=135?q9(e):e===254?a(`printers.extL`,`Ext-L`):M?a(`printers.extR`,`Ext-R`):a(`printers.ext`,`Ext`),[a,M]),V=(0,y.useCallback)((e,t)=>{u(`info`),c(a(`spoolbuddy.modal.assigning`,`Configuring slot...`)),L.mutate({amsId:e,trayId:t})},[L,a]),ee=(0,y.useCallback)((e,t)=>{if(!R){if(!x?.disable_filament_warnings){let r=z(e,t);if(r&&!J9(r)){let i=r.tray_sub_brands||r.tray_type||``,a=z1e(n.material,i),o=n.slicer_filament_name||n.slicer_filament,s=r.tray_type||``,c=B1e(o,s);if(a!==`exact`){let r;r=a===`none`&&!c?`material_profile`:a===`partial`&&!c?`partial_profile`:a===`none`?`material`:`partial`;let l=B(e,t);g({amsId:e,trayId:t}),m({type:r,spoolMaterial:n.material||``,trayMaterial:i||``,spoolProfile:o||void 0,trayProfile:s||void 0,location:l}),f(!0);return}}}V(e,t)}},[R,x?.disable_filament_warnings,n,z,B,V]),te=(0,y.useCallback)(()=>{h&&(f(!1),m(null),V(h.amsId,h.trayId),g(null))},[h,V]),ne=(0,y.useMemo)(()=>{let e=[];for(let t of A){let n=t.tray?.[0]||{id:0,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},r=T[`${t.id}-0`]??null,i=n.remain!=null&&n.remain>=0?n.remain:null,a=r===0&&i!==null&&i>0?null:r;e.push({key:`ht-${t.id}`,label:q9(t.id),amsId:t.id,trayId:0,tray:n,isEmpty:J9(n),nozzleSide:I(t.id),effectiveFill:a??i})}for(let t of j){let n=t.id??254,r=n-254,i=T[`255-${r}`]??null,o=t.remain!=null&&t.remain>=0?t.remain:null,s=i===0&&o!==null&&o>0?null:i;e.push({key:`ext-${n}`,label:M?n===254?a(`printers.extL`,`Ext-L`):a(`printers.extR`,`Ext-R`):a(`printers.ext`,`Ext`),amsId:255,trayId:r,tray:t,isEmpty:J9(t),nozzleSide:M?n===254?`L`:`R`:null,effectiveFill:s??o})}return e},[A,j,M,a,I,T]);return e?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`fixed inset-0 z-[60] bg-bambu-dark flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-zinc-800 shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,G.jsx)(`div`,{className:`w-7 h-7 rounded-full shrink-0`,style:Tf(n.rgba)}),(0,G.jsx)(`div`,{className:`min-w-0`,children:(0,G.jsxs)(`h2`,{className:`text-sm font-semibold text-zinc-100 truncate`,children:[a(`spoolbuddy.modal.assignToAmsTitle`,`Assign to AMS`),(0,G.jsxs)(`span`,{className:`font-normal text-zinc-500 ml-2`,children:[n.color_name||`Unknown`,` • `,n.brand,` `,n.material,n.subtype&&` ${n.subtype}`]}),(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 ml-2 shrink-0`,children:[`#`,n.id]})]})})]}),(0,G.jsx)(`button`,{onClick:t,disabled:R,className:`p-2 rounded-lg text-zinc-500 hover:text-zinc-300 hover:bg-zinc-800 transition-colors shrink-0 disabled:opacity-50`,children:(0,G.jsx)(td,{className:`w-5 h-5`})})]}),s&&(0,G.jsxs)(`div`,{className:`mx-5 mt-3 p-3 rounded-lg flex items-center gap-3 border shrink-0 ${l===`info`?`bg-blue-500/10 border-blue-500/40`:l===`success`?`bg-green-500/10 border-green-500/40`:`bg-red-500/10 border-red-500/40`}`,children:[l===`info`&&(0,G.jsx)(Y,{className:`w-4 h-4 text-blue-400 animate-spin shrink-0`}),l===`success`&&(0,G.jsx)(bs,{className:`w-4 h-4 text-green-400 shrink-0`}),l===`error`&&(0,G.jsx)(Es,{className:`w-4 h-4 text-red-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm ${l===`info`?`text-blue-300`:l===`success`?`text-green-300`:`text-red-300`}`,children:s})]}),(0,G.jsx)(`div`,{className:`flex-1 flex flex-col gap-3 p-4 min-h-0 overflow-y-auto`,children:!D&&r?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`text-center text-white/50`,children:(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:a(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)})})}):O.length===0&&j.length===0?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,G.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,G.jsx)(qc,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:a(`spoolbuddy.ams.noData`,`No AMS detected`)}),(0,G.jsx)(`p`,{className:`text-sm`,children:a(`spoolbuddy.ams.connectAms`,`Connect an AMS to see filament slots`)})]})}):(0,G.jsxs)(G.Fragment,{children:[k.length>0&&(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3 flex-1 min-h-0`,children:k.map(e=>(0,G.jsx)(L1e,{unit:e,activeSlot:w?.ams_id===e.id?w.tray_id??null:null,onConfigureSlot:(t,n)=>ee(e.id,n),isDualNozzle:M,nozzleSide:I(e.id),thresholds:E,fillOverrides:T},e.id))}),ne.length>0&&(0,G.jsx)(`div`,{className:`flex gap-2 shrink-0`,children:ne.map(({key:e,label:t,amsId:n,trayId:r,tray:i,isEmpty:a,nozzleSide:o,effectiveFill:s})=>{let c=R1e(i.tray_color);return(0,G.jsxs)(`div`,{onClick:()=>ee(n,r),className:`bg-bambu-dark-secondary rounded-lg px-3 py-2 cursor-pointer hover:bg-bambu-dark-secondary/80 transition-all flex items-center gap-2 ${w&&w.ams_id===n&&w.tray_id===r?`ring-2 ring-bambu-green`:``} ${R?`opacity-50 pointer-events-none`:``}`,children:[(0,G.jsx)(`div`,{className:`relative w-10 h-10 shrink-0`,children:a?(0,G.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-gray-600`})}):(0,G.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:c}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:c,style:{filter:`brightness(0.85)`}}),(0,G.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]})}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`text-xs text-white/50 font-medium`,children:t}),o&&(0,G.jsx)(K9,{side:o})]}),(0,G.jsx)(`div`,{className:`text-sm text-white/80 truncate`,children:a?`Empty`:i.tray_type||`?`})]}),!a&&s!=null&&s>=0&&(0,G.jsx)(`div`,{className:`w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden shrink-0 flex flex-col-reverse`,children:(0,G.jsx)(`div`,{className:`w-full rounded-full`,style:{height:`${s}%`,backgroundColor:Ep(s)}})})]},e)})})]})}),(0,G.jsx)(`div`,{className:`flex justify-end gap-3 px-5 py-3 border-t border-zinc-800 shrink-0`,children:(0,G.jsx)(`button`,{onClick:t,disabled:R,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-800 text-zinc-300 hover:bg-zinc-700 transition-colors min-h-[44px] disabled:opacity-50`,children:l===`success`?a(`spoolbuddy.dashboard.close`,`Close`):a(`spoolbuddy.modal.cancel`,`Cancel`)})})]}),d&&p&&(()=>{let e=``;return p.type===`material`?e=a(`inventory.assignMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location}):p.type===`partial`?e=a(`inventory.assignPartialMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location}):p.type===`material_profile`?e=`${a(`inventory.assignMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location})}\n\n${a(`inventory.assignProfileMismatchMessage`,{spoolProfile:p.spoolProfile||a(`common.unknown`),trayProfile:p.trayProfile||a(`common.unknown`),location:p.location})}`:p.type===`partial_profile`&&(e=`${a(`inventory.assignPartialMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location})}\n\n${a(`inventory.assignProfileMismatchMessage`,{spoolProfile:p.spoolProfile||a(`common.unknown`),trayProfile:p.trayProfile||a(`common.unknown`),location:p.location})}`),e=`${e}\n\n${a(`inventory.assignReconfigureNote`)}`,(0,G.jsx)(ef,{title:a(`inventory.assignMismatchTitle`),message:e,confirmText:a(`inventory.assignMismatchConfirm`),variant:`warning`,isLoading:L.isPending,onConfirm:te,onCancel:()=>{L.isPending||(f(!1),g(null),m(null))}})})()]}):null}function H1e({isOpen:e,onClose:t,tagId:n,untaggedSpools:r,onLink:i}){let{t:a}=U(),[o,s]=(0,y.useState)(null),c=(0,y.useCallback)(()=>{s(null),t()},[t]),l=(0,y.useCallback)(e=>{e.key===`Escape`&&c()},[c]);return(0,y.useEffect)(()=>(e&&(document.addEventListener(`keydown`,l),document.body.style.overflow=`hidden`),()=>{document.removeEventListener(`keydown`,l),document.body.style.overflow=``}),[e,l]),e?(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 animate-fade-in`,onClick:c,children:(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-xl shadow-2xl w-full max-w-lg mx-4 animate-slide-up`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b border-zinc-700`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-base font-semibold text-zinc-100`,children:a(`spoolbuddy.dashboard.linkTagTitle`,`Link Tag to Spool`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-500 font-mono`,children:n})]}),(0,G.jsx)(`button`,{onClick:c,className:`p-2 rounded-lg text-zinc-500 hover:text-zinc-300 hover:bg-zinc-700 transition-colors`,children:(0,G.jsx)(td,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`px-5 py-4 space-y-3 max-h-[400px] overflow-y-auto`,children:[(0,G.jsx)(`p`,{className:`text-sm text-zinc-400`,children:a(`spoolbuddy.dashboard.selectSpool`,`Select a spool to link this tag to:`)}),r.length===0?(0,G.jsx)(`div`,{className:`text-center py-8 text-zinc-500`,children:a(`spoolbuddy.dashboard.noUntagged`,`No spools without tags found`)}):(0,G.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(e),className:`w-full flex items-center gap-3 p-3 rounded-lg border-2 transition-all text-left ${o?.id===e.id?`border-green-500 bg-green-500/10`:`border-zinc-700 hover:border-green-500/50 hover:bg-zinc-700/50`}`,children:[(0,G.jsx)(G9,{color:wf(e.rgba),isEmpty:!1,size:40}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`font-medium text-zinc-100 truncate`,children:e.color_name||`Unknown color`}),(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,G.jsxs)(`div`,{className:`text-sm text-zinc-400 truncate`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]})]}),(0,G.jsxs)(`div`,{className:`text-sm font-mono text-zinc-500`,children:[Math.max(0,e.label_weight-e.weight_used),`g`]})]},e.id))})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 px-5 py-4 border-t border-zinc-700`,children:[(0,G.jsx)(`button`,{onClick:c,className:`px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:a(`common.cancel`,`Cancel`)}),(0,G.jsx)(`button`,{onClick:()=>{o&&(i(o),s(null))},disabled:!o,className:`px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors min-h-[44px]`,children:a(`spoolbuddy.dashboard.linkTag`,`Link Tag`)})]})]})}):null}function U1e(e){return e?e.replace(/[^0-9a-f]/gi,``).toUpperCase():``}function W1e(e,t){let n=U1e(e),r=U1e(t);return!n||!r?!1:n===r?!0:n.endsWith(r)||r.endsWith(n)}var G1e=[`#00AE42`,`#FF6B35`,`#3B82F6`,`#EF4444`,`#A855F7`,`#FBBF24`,`#14B8A6`,`#EC4899`,`#F97316`,`#22C55E`];function K1e(){let{t:e}=U(),[t,n]=(0,y.useState)(0);(0,y.useEffect)(()=>{let e=setInterval(()=>{n(e=>(e+1)%G1e.length)},5e3);return()=>clearInterval(e)},[]);let r=G1e[t];return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,G.jsxs)(`div`,{className:`relative mb-6 flex items-center justify-center`,style:{width:160,height:160},children:[(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:[0,1].map(e=>(0,G.jsx)(`div`,{className:`absolute rounded-full border spoolbuddy-optimized-ping`,style:{width:80,height:80,borderColor:`${r}4D`,transition:`border-color 140ms linear`,animationDelay:`${e*.8}s`}},e))}),(0,G.jsxs)(`div`,{className:`relative overflow-hidden rounded-full`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 rounded-full opacity-30 spoolbuddy-spool-glow`,style:{background:`radial-gradient(circle, ${r} 0%, transparent 70%)`}}),(0,G.jsx)(`div`,{className:`relative`,style:{transition:`opacity 140ms linear`},children:(0,G.jsx)(G9,{color:r,isEmpty:!1,size:100})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xl font-medium text-zinc-300`,children:e(`spoolbuddy.dashboard.readyToScan`,`Ready to scan`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-500`,children:e(`spoolbuddy.dashboard.idleMessage`,`Place a spool on the scale to identify it`)})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex items-center gap-2 text-sm text-zinc-600`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z`})}),(0,G.jsx)(`span`,{children:e(`spoolbuddy.dashboard.nfcHint`,`NFC tag will be read automatically`)})]})]})}function q1e(){let{t:e}=U();return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,G.jsx)(`div`,{className:`relative mb-6 flex items-center justify-center`,style:{width:160,height:160},children:(0,G.jsx)(`div`,{className:`w-24 h-24 rounded-full bg-zinc-800 flex items-center justify-center`,children:(0,G.jsx)(`svg`,{className:`w-12 h-12 text-zinc-600`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,d:`M18.364 5.636a9 9 0 010 12.728m0 0l-12.728-12.728m12.728 12.728L5.636 5.636m12.728 0a9 9 0 00-12.728 0m0 12.728a9 9 0 010-12.728`})})})}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-lg font-medium text-zinc-500`,children:e(`spoolbuddy.status.deviceOffline`,`Device Offline`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-600`,children:e(`spoolbuddy.status.connectDisplay`,`Connect the SpoolBuddy display to scan spools`)})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex items-center gap-2 text-xs text-zinc-600`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M8.111 16.404a5.5 5.5 0 017.778 0M12 20h.01m-7.08-7.071c3.904-3.905 10.236-3.905 14.14 0M1.394 9.393c5.857-5.857 15.355-5.857 21.213 0`})}),(0,G.jsx)(`span`,{children:e(`spoolbuddy.status.waitingConnection`,`Waiting for device connection...`)})]})]})}function J1e(){let{sbState:e,selectedPrinterId:t}=lr(),{t:n}=U(),{showToast:r}=Hd(),{data:i}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,staleTime:300*1e3}),a=i?.spoolman_enabled===`true`&&!!i?.spoolman_url,{data:o=[],refetch:s}=K({queryKey:a?[`spoolman-inventory-spools`]:[`inventory-spools`],queryFn:()=>a?Z.getSpoolmanInventorySpools(!1):Z.getSpools(!1),enabled:i!==void 0}),{data:c=[]}=K({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:a,staleTime:3*1e3,refetchInterval:3*1e3,refetchIntervalInBackground:!1}),{data:l=[]}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),u=Co({queries:l.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id),refetchInterval:1e4,select:e=>({connected:e?.connected,awaiting_plate_clear:e?.awaiting_plate_clear===!0})}))}),d=l.map((e,t)=>({printer:e,pending:u[t]?.data?.awaiting_plate_clear===!0})).filter(e=>e.pending),f=co(),p=q({mutationFn:e=>Z.clearPlate(e),onSuccess:(e,t)=>{f.setQueryData([`printerStatus`,t],e=>e&&{...e,awaiting_plate_clear:!1}),r(n(`spoolbuddy.dashboard.plateClearedToast`,`Plate marked as cleared`),`success`)},onError:()=>{r(n(`spoolbuddy.dashboard.plateClearFailed`,`Could not mark plate as cleared`),`error`)}}),m=q({mutationFn:e=>Z.unassignSpoolmanSlot(e),onSuccess:()=>{f.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),f.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},onError:()=>r(n(`inventory.unassignFailed`,`Failed to unassign spool`),`error`)}),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(null),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(null),M=e.matchedSpool?.tag_uid??e.unknownTagUid??null,N=e.weight,P=e.weightStable,F=(0,y.useRef)(null);N===null?F.current=null:(F.current===null||Math.abs(N-F.current)>=3||P)&&(F.current=N);let I=F.current,L=(0,y.useMemo)(()=>{if(e.matchedSpool?.id){let t=o.find(t=>t.id===e.matchedSpool?.id);if(t)return t}return h&&(o.find(e=>W1e(e.tag_uid,h))||A)||null},[h,e.matchedSpool,o,A]),R=(0,y.useMemo)(()=>{if(L&&!A)return L;let t=e.matchedSpool;return t?{id:t.id,tag_uid:t.tag_uid,material:t.material,subtype:t.subtype,color_name:t.color_name,rgba:t.rgba,brand:t.brand,label_weight:t.label_weight,core_weight:t.core_weight,weight_used:t.weight_used}:null},[L,A,e.matchedSpool]),z=a&&R!=null?c.some(e=>e.spoolman_spool_id===R.id):!1,B=(0,y.useMemo)(()=>a?o.filter(e=>!e.tag_uid&&!e.tray_uuid&&!e.archived_at):o.filter(e=>!e.tag_uid&&!e.archived_at),[o,a]);(0,y.useEffect)(()=>{if(M){let e=b===M;(h!==null&&h!==M||!e&&h!==M)&&(g(M),v(null),x(null),j(null)),!e&&N!==null&&P&&v(Math.round(Math.max(0,N)))}else b&&(g(null),x(null),v(null),j(null))},[M,N,P,h,b]);let V=()=>{x(h)},ee=async t=>{if(h)try{if(a){let i=e.unknownTagUid||void 0,a=!e.unknownTagUid&&e.unknownTrayUuid?e.unknownTrayUuid:void 0;if(!i&&!a){r(n(`spoolman.linkFailed`),`error`);return}let o=await Z.linkTagToSpoolmanSpool(t.id,{tray_uuid:a,tag_uid:i});if(!o){r(n(`spoolman.linkFailed`),`error`);return}let{id:s,material:c,subtype:l,color_name:u,rgba:d,brand:f,label_weight:p,core_weight:m,weight_used:h}=o;j({id:s,material:c,subtype:l,color_name:u,rgba:d,brand:f,label_weight:p,core_weight:m,weight_used:h}),r(n(`spoolman.linkSuccess`),`success`)}else await Z.linkTagToSpool(t.id,{tag_uid:h,tag_type:`generic`,data_origin:`nfc_link`});s()}catch(e){console.error(`Failed to link tag:`,e),r(n(`spoolman.linkFailed`),`error`)}finally{C(!1)}},te=async()=>{if(h){k(!0);try{let t=ne??_;if(a){let n=await Z.createSpoolmanInventorySpool({material:`PLA`,subtype:null,color_name:null,rgba:null,extra_colors:null,effect_type:null,brand:null,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,nozzle_temp_min:null,nozzle_temp_max:null,note:null,added_full:null,last_used:null,encode_time:null,tag_uid:null,tray_uuid:null,data_origin:null,tag_type:null,cost_per_kg:null,last_scale_weight:t===null?null:Math.round(t),last_weighed_at:t===null?null:new Date().toISOString(),category:null,low_stock_threshold_pct:null});await Z.linkTagToSpoolmanSpool(n.id,{tag_uid:e.unknownTagUid||void 0,tray_uuid:!e.unknownTagUid&&e.unknownTrayUuid?e.unknownTrayUuid:void 0})}else await Z.createSpool({material:`PLA`,subtype:null,color_name:null,rgba:null,extra_colors:null,effect_type:null,brand:null,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,nozzle_temp_min:null,nozzle_temp_max:null,note:null,added_full:null,last_used:null,encode_time:null,tag_uid:h,tray_uuid:null,data_origin:`spoolbuddy`,tag_type:`generic`,cost_per_kg:null,last_scale_weight:t===null?null:Math.round(t),last_weighed_at:t===null?null:new Date().toISOString(),category:null,low_stock_threshold_pct:null})}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`Failed to quick-add spool:`,t),r(t||n(`spoolbuddy.errors.quickAddFailed`,`Failed to add spool`),`error`)}finally{D(!1),k(!1),s()}}},ne=N!==null&&(M===h||M===null&&h!==null)?N:null,re=o.length,ie=new Set(o.map(e=>e.material)).size,ae=new Set(o.filter(e=>e.brand).map(e=>e.brand)).size;return(0,G.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-6 px-4 py-1.5 bg-zinc-800/50 rounded-xl border border-zinc-700/50 mb-3 shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:re}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.inventory.spools`,`Spools`)})]}),(0,G.jsx)(`div`,{className:`w-px h-5 bg-zinc-700`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:ie}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.material`,`Materials`)})]}),(0,G.jsx)(`div`,{className:`w-px h-5 bg-zinc-700`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:ae}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.brand`,`Brands`)})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex gap-4 min-h-0`,children:[(0,G.jsxs)(`div`,{className:`w-5/12 flex flex-col min-h-0`,children:[(0,G.jsxs)(`div`,{className:`border border-dashed border-zinc-700/50 rounded-xl p-4`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-3`,children:n(`spoolbuddy.dashboard.device`,`Device`)}),(0,G.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full ${e.deviceOnline?`bg-green-500`:`bg-red-500`}`}),(0,G.jsx)(`span`,{className:`text-base text-zinc-400`,children:e.deviceOnline?n(`spoolbuddy.status.online`,`Online`):n(`spoolbuddy.status.offline`,`Disconnected`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-zinc-800/50 rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4 ${e.deviceOnline?`text-green-500`:`text-zinc-500`}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M3 6l3 1m0 0l-3 9a5.002 5.002 0 006.001 0M6 7l3 9M6 7l6-2m6 2l3-1m-3 1l-3 9a5.002 5.002 0 006.001 0M18 7l3 9m-3-9l-6-2m0-2v2m0 16V5m0 16H9m3 0h3`})}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.scaleWeight`,`Scale`)})]}),(0,G.jsx)(`span`,{className:`text-lg font-mono font-semibold text-zinc-100`,children:I===null?`—`:`${Math.abs(I)<=20?0:Math.round(Math.max(0,I))}g`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-zinc-800/50 rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4 ${e.deviceOnline?`text-green-500`:`text-zinc-500`}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z`})}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:`NFC`})]}),(0,G.jsx)(`span`,{className:`text-sm font-medium ${M?`text-green-500`:`text-zinc-500`}`,children:M?n(`spoolbuddy.dashboard.tagDetected`,`Tag detected`):n(`spoolbuddy.dashboard.noTag`,`No tag`)})]})]})]}),l.length>0&&(0,G.jsxs)(`div`,{className:`mt-3 border border-dashed border-zinc-700/50 rounded-xl p-4`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-2.5`,children:n(`spoolbuddy.dashboard.printers`,`Printers`)}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2 overflow-hidden`,children:l.map((e,t)=>{let n=u[t]?.data?.connected??!1;return(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2.5 py-1 bg-zinc-800/50 rounded-lg`,title:`${e.name} — ${n?`Online`:`Offline`}`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${n?`bg-green-500`:`bg-zinc-600`}`}),(0,G.jsx)(`span`,{className:`text-xs text-zinc-400 truncate max-w-[100px]`,children:e.name})]},e.id)})}),d.length>0&&(0,G.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,"data-testid":`plate-clear-section`,"aria-label":n(`spoolbuddy.dashboard.plateReadyLabel`,`Plates ready to clear`),children:d.map(({printer:e})=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>p.mutate(e.id),disabled:p.isPending,"data-testid":`plate-clear-button-${e.id}`,title:n(`spoolbuddy.dashboard.plateReady`,`Plate ready: {{name}}`,{name:e.name}),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-amber-500/10 hover:bg-amber-500/20 active:bg-amber-500/30 border border-amber-500/30 text-amber-200 transition-colors disabled:opacity-60 disabled:cursor-wait`,children:[(0,G.jsxs)(`svg`,{className:`w-3 h-3 shrink-0`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,G.jsx)(`path`,{d:`M12 9v4`}),(0,G.jsx)(`path`,{d:`M12 17h.01`}),(0,G.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`})]}),(0,G.jsx)(`span`,{className:`text-xs truncate max-w-[100px]`,children:e.name}),(0,G.jsx)(`span`,{className:`text-xs opacity-70`,"aria-hidden":`true`,children:`·`}),(0,G.jsx)(`span`,{className:`text-xs font-medium`,children:n(`spoolbuddy.dashboard.plateClearAction`,`Clear`)})]},e.id))})]})]}),(0,G.jsx)(`div`,{className:`w-7/12 min-h-0`,children:(0,G.jsxs)(`div`,{className:`border border-dashed border-zinc-700/50 rounded-xl p-6 h-full flex flex-col`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-4 shrink-0`,children:n(`spoolbuddy.dashboard.currentSpool`,`Current Spool`)}),(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:e.deviceOnline?(L||e.matchedSpool)&&h&&b!==h?(0,G.jsx)(S1e,{spool:(()=>{let t=L??e.matchedSpool;return{id:t.id,tag_uid:h,material:t.material,subtype:t.subtype,color_name:t.color_name,rgba:t.rgba,brand:t.brand,label_weight:t.label_weight,core_weight:t.core_weight,weight_used:t.weight_used}})(),scaleWeight:ne??_,onSyncWeight:()=>s(),onAssignToAms:()=>T(!0),isAssigned:z,onUnassignFromAms:z&&L?.id!=null?()=>m.mutate(L.id):void 0,onClose:V}):M&&h&&!L&&!e.matchedSpool&&b!==h?(0,G.jsx)(C1e,{tagUid:h,scaleWeight:ne??_,onLinkSpool:B.length>0?()=>C(!0):void 0,onAddToInventory:()=>D(!0),onClose:V}):(0,G.jsx)(K1e,{}):(0,G.jsx)(q1e,{})})]})})]}),R&&!A&&h&&(0,G.jsx)(V1e,{isOpen:w,onClose:()=>T(!1),spool:R,printerId:t,spoolmanMode:a}),h&&(0,G.jsx)(H1e,{isOpen:S,onClose:()=>C(!1),tagId:h,untaggedSpools:B,onLink:ee}),E&&h&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,children:(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-2xl p-6 mx-4 max-w-sm w-full border border-zinc-700`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100 mb-3`,children:n(`spoolbuddy.modal.addToInventory`,`Add to Inventory`)}),(0,G.jsxs)(`div`,{className:`flex gap-2.5 p-3 bg-amber-500/10 border border-amber-500/20 rounded-lg mb-4`,children:[(0,G.jsx)(`svg`,{className:`w-5 h-5 text-amber-500 shrink-0 mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z`})}),(0,G.jsx)(`p`,{className:`text-sm text-amber-200/80`,children:n(`spoolbuddy.modal.quickAddHint`,`For best results, add the spool in the Bambuddy web interface first (with material, color, brand), then use "Assign Spool" here to assign the NFC tag.`)})]}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-400 mb-1`,children:n(`spoolbuddy.modal.quickAddDesc`,`This will create a basic PLA spool entry with this NFC tag. You can edit the details later in Bambuddy.`)}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 font-mono mb-5`,children:h}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(`button`,{onClick:()=>D(!1),className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:n(`common.cancel`,`Cancel`)}),(0,G.jsx)(`button`,{onClick:te,disabled:O,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-50 transition-colors min-h-[44px]`,children:O?n(`common.saving`,`Saving...`):n(`spoolbuddy.modal.addAnyway`,`Add Anyway`)})]})]})})]})}function Y1e(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function X1e(e){return e?{O1D:`H2D`,O1E:`H2D Pro`,O2D:`H2D Pro`,O1C:`H2C`,O1C2:`H2C`,O1S:`H2S`,"BL-P001":`X1C`,"BL-P002":`X1`,"BL-P003":`X1E`,N6:`X2D`,N9:`A2L`,C11:`P1S`,C12:`P1P`,C13:`P2S`,N2S:`A1`,N1:`A1 Mini`,X1C:`X1C`,X1:`X1`,X1E:`X1E`,X2D:`X2D`,P1S:`P1S`,P1P:`P1P`,P2S:`P2S`,A1:`A1`,"A1 Mini":`A1 Mini`,A2L:`A2L`,H2D:`H2D`,"H2D Pro":`H2D Pro`,H2C:`H2C`,H2S:`H2S`}[e]||e:``}function X9(e){return!e.tray_type||e.tray_type===``}function Z1e(e){return e?`#${e.slice(0,6)}`:`#808080`}function Q1e(){let{selectedPrinterId:e,setAlert:t}=lr(),{t:n}=U(),r=co(),{showToast:i}=Hd(),{data:a}=K({queryKey:[`printerStatus`,e],queryFn:()=>Z.getPrinterStatus(e),enabled:e!==null,staleTime:30*1e3}),{data:o}=K({queryKey:[`printer`,e],queryFn:()=>Z.getPrinter(e),enabled:e!==null,staleTime:60*1e3}),{data:s}=K({queryKey:[`slotPresets`,e],queryFn:()=>Z.getSlotPresets(e),enabled:e!==null,staleTime:120*1e3}),{data:c}=K({queryKey:[`settings`],queryFn:()=>Z.getSettings(),staleTime:300*1e3}),{data:l}=K({queryKey:[`spoolman-status`],queryFn:Z.getSpoolmanStatus,staleTime:60*1e3}),u=l?.enabled&&l?.connected,{data:d}=K({queryKey:[`linked-spools`],queryFn:Z.getLinkedSpools,enabled:!!u,staleTime:30*1e3}),f=d?.linked,{data:p=[]}=K({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:!!u,staleTime:30*1e3}),{data:m=[]}=K({queryKey:[`spoolman-inventory-spools`],queryFn:()=>Z.getSpoolmanInventorySpools(!1),enabled:!!u,staleTime:30*1e3}),{data:h}=K({queryKey:[`spool-assignments`,e],queryFn:()=>Z.getAssignments(e),enabled:e!==null,staleTime:30*1e3}),g=(0,y.useMemo)(()=>{let e={};if(!h)return e;for(let t of h){let n=t.spool;if(n&&n.label_weight>0&&n.weight_used!=null){let r=Math.round(Math.max(0,n.label_weight-n.weight_used)/n.label_weight*100);e[`${t.ams_id}-${t.tray_id}`]=r}}return e},[h]),_=o?.serial_number??``,v=(0,y.useCallback)((t,n,r)=>{if(e!==null&&p.length&&m.length){let r=p.find(r=>r.printer_id===e&&r.ams_id===t&&r.tray_id===n);if(r){let e=m.find(e=>e.id===r.spoolman_spool_id);if(e&&(e.label_weight??0)>0)return Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100)}}if(f&&_){let e=(r?.tray_uuid||r?.tag_uid||Ap(_,t,n))?.toUpperCase(),i=Dp(e?f[e]:void 0);if(i!==null)return i}return null},[f,_,e,p,m]),b=a?.connected??!1,x=(0,y.useRef)({});(0,y.useEffect)(()=>{e&&a?.ams&&a.ams.length>0&&(x.current[e]=a.ams)},[a?.ams,e]);let S=(0,y.useMemo)(()=>{let t=a?.ams;return t&&t.length>0?t:(e?x.current[e]:null)??[]},[a?.ams,e]),C=(0,y.useMemo)(()=>S.filter(e=>!e.is_ams_ht),[S]),w=(0,y.useMemo)(()=>S.filter(e=>e.is_ams_ht),[S]),T=(0,y.useMemo)(()=>{let e={};if(!f||!_)return e;for(let t of C)for(let n=0;n<(t.tray?.length??0);n++){let r=t.tray[n],i=v(t.id,n,X9(r)?null:r);i!==null&&(e[`${t.id}-${n}`]=i)}return e},[f,_,C,v]),E=(0,y.useRef)(void 0),D=a?.tray_now;D!==void 0&&D!==255?E.current=D:D===255&&(E.current=void 0);let O=D!==void 0&&D!==255?D:E.current,k=o?.nozzle_count===2||a?.temperatures?.nozzle_2!==void 0,A=(0,y.useMemo)(()=>[...a?.vt_tray??[]].sort((e,t)=>(e.id??254)-(t.id??254)),[a?.vt_tray]),j=c?{humidityGood:Number(c.ams_humidity_good)||40,humidityFair:Number(c.ams_humidity_fair)||60,tempGood:Number(c.ams_temp_good)||28,tempFair:Number(c.ams_temp_fair)||35}:void 0,M=(0,y.useRef)({});(0,y.useEffect)(()=>{a?.ams_extruder_map&&Object.keys(a.ams_extruder_map).length>0&&(M.current=a.ams_extruder_map)},[a?.ams_extruder_map]);let N=a?.ams_extruder_map&&Object.keys(a.ams_extruder_map).length>0?a.ams_extruder_map:M.current,P=(0,y.useCallback)(e=>{if(!k)return null;let t=N[String(e)],n=e>=128?e-128:e;return(t===void 0?n:t)===1?`L`:`R`},[k,N]),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(null),[z,B]=(0,y.useState)(null),[V,ee]=(0,y.useState)(null),te=(0,y.useCallback)((e,t)=>h?.find(n=>n.ams_id===Number(e)&&n.tray_id===Number(t)),[h]),ne=(0,y.useCallback)((e,t,n)=>{if(!f||!_)return;let r=(n?.tray_uuid||n?.tag_uid||Ap(_,e,t))?.toUpperCase();return r?f[r]:void 0},[f,_]),re=q({mutationFn:({printerId:e,amsId:t,trayId:n})=>Z.unassignSpool(e,t,n),onSuccess:()=>{r.invalidateQueries({queryKey:[`spool-assignments`,e]}),r.invalidateQueries({queryKey:[`spool-assignments`]}),i(n(`inventory.unassignSuccess`,`Spool unassigned`),`success`),R(null)}}),ie=q({mutationFn:e=>Z.unlinkSpool(e),onSuccess:e=>{i(n(`spoolman.unlinkSuccess`)||e?.message,`success`),r.invalidateQueries({queryKey:[`linked-spools`]}),r.invalidateQueries({queryKey:[`unlinked-spools`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),r.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),R(null)},onError:e=>{i(e.message||n(`spoolman.unlinkFailed`),`error`)}}),ae=q({mutationFn:e=>Z.unassignSpoolmanSlot(e),onSuccess:()=>{i(n(`inventory.unassignSuccess`,`Spool unassigned`),`success`),r.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),r.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),r.invalidateQueries({queryKey:[`unlinked-spools`]}),r.invalidateQueries({queryKey:[`linked-spools`]}),R(null)},onError:e=>{i(e.message||n(`inventory.assignFailed`,`Failed to unassign spool`),`error`)}}),oe=(0,y.useCallback)(e=>O===void 0?null:e<=3&&Math.floor(O/4)===e?O%4:e>=128&&e<=135&&O===Tp(e,0,!1)?0:null,[O]),se=(0,y.useCallback)((e,t,n)=>{let r=Tp(e,t,!1),i=s?.[r],a=N[String(e)],o=e>=128?e-128:e,c=a===void 0?o:a;R({amsId:e,trayId:t,trayCount:n&&e>=128?1:4,tray:n,trayType:n?.tray_type||void 0,trayColor:n?.tray_color||void 0,traySubBrands:n?.tray_sub_brands||void 0,trayInfoIdx:n?.tray_info_idx||void 0,extruderId:k?c:void 0,caliIdx:n?.cali_idx,savedPresetId:i?.preset_id,location:`${Y1e(e)} Slot ${t+1}`})},[s,N,k]),H=(0,y.useCallback)(e=>{let t=e.id??254,n=t-254,r=s?.[1020+n];R({amsId:255,trayId:n,trayCount:1,tray:X9(e)?null:e,trayType:e.tray_type||void 0,trayColor:e.tray_color||void 0,traySubBrands:e.tray_sub_brands||void 0,trayInfoIdx:e.tray_info_idx||void 0,extruderId:k?+(t===254):void 0,caliIdx:e.cali_idx,savedPresetId:r?.preset_id,location:k?t===254?`Ext-L`:`Ext-R`:`External`})},[s,k]),ce=(0,y.useCallback)(()=>{if(!L)return;let{tray:e,location:t,...n}=L;R(null),I(n)},[L]),le=(0,y.useCallback)(()=>{if(!L||!e)return;let{amsId:t,trayId:n,trayType:r,trayColor:i,location:a}=L;R(null),B({printerId:e,amsId:t,trayId:n,trayInfo:{type:r||``,material:r,color:i?.slice(0,6)||``,location:a}})},[L,e]),ue=(0,y.useCallback)(()=>{if(!L||!e)return;let{amsId:t,trayId:n,tray:r}=L,i=(r?.tray_uuid||r?.tag_uid||Ap(_,t,n))?.toUpperCase()||``;R(null),ee({tagUid:r?.tag_uid||i,trayUuid:r?.tray_uuid||``,printerId:e,amsId:t,trayId:n})},[L,e,_]),de=(0,y.useCallback)(()=>{if(!L||!e)return;let{amsId:t,trayId:n}=L;re.mutate({printerId:e,amsId:t,trayId:n})},[L,e,re]);(0,y.useEffect)(()=>{if(!b&&e){t({type:`warning`,message:n(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)});return}for(let e of S){let n=e.tray||[];for(let r=0;r=0&&i.remain<15&&i.tray_type){let n=e.id===254||e.id===255,a=!n&&e.id>=128,o=wp(e.id,r,a,n);t({type:`warning`,message:`Low Filament: ${i.tray_type} (${o}) - ${i.remain}% remaining`});return}}}t(null)},[S,b,e,t,n]);let fe=(0,y.useMemo)(()=>{let e=[];for(let t of w){let n=t.tray?.[0]||{id:0,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},r=v(t.id,0,X9(n)?null:n),i=g[`${t.id}-0`]??null,a=n.remain!=null&&n.remain>=0?n.remain:null,o=i===0&&a!==null&&a>0?null:i;e.push({key:`ht-${t.id}`,label:Y1e(t.id),tray:n,isEmpty:X9(n),isActive:oe(t.id)===0,temp:t.temp,humidity:t.humidity,nozzleSide:P(t.id),effectiveFill:r??o??a,onClick:()=>se(t.id,0,X9(n)?null:n)})}for(let t of A){let r=t.id??254,i=k&&O===254?r===254&&a?.active_extruder===1||r===255&&a?.active_extruder===0:O===r,o=r-254,s=v(255,o,X9(t)?null:t),c=g[`255-${o}`]??null,l=t.remain!=null&&t.remain>=0?t.remain:null,u=c===0&&l!==null&&l>0?null:c;e.push({key:`ext-${r}`,label:k?r===254?n(`printers.extL`,`Ext-L`):n(`printers.extR`,`Ext-R`):n(`printers.ext`,`Ext`),tray:t,isEmpty:X9(t),isActive:i,nozzleSide:null,effectiveFill:s??u??l,onClick:()=>H(t)})}return e},[w,A,k,O,a?.active_extruder,n,oe,P,se,H,g,v]);return(0,G.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,G.jsx)(`div`,{className:`flex-1 min-h-0`,children:e?b?S.length===0&&A.length===0?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,G.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,G.jsx)(qc,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.noData`,`No AMS detected`)}),(0,G.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.ams.connectAms`,`Connect an AMS to see filament slots`)})]})}):(0,G.jsxs)(`div`,{className:`flex flex-col gap-3 h-full`,children:[(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:C.map(e=>(0,G.jsx)(L1e,{unit:e,activeSlot:oe(e.id),onConfigureSlot:se,isDualNozzle:k,nozzleSide:P(e.id),thresholds:j,fillOverrides:g,spoolmanFillOverrides:T},e.id))}),fe.length>0&&(0,G.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-3`,children:fe.map(({key:e,label:t,tray:n,isEmpty:r,isActive:i,temp:a,humidity:o,nozzleSide:s,effectiveFill:c,onClick:l})=>{let u=Z1e(n.tray_color);return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg px-3 py-2 cursor-pointer hover:bg-bambu-dark-secondary/80 transition-all flex items-center gap-3 ${i?`ring-2 ring-bambu-green`:``}`,onClick:l,children:[(0,G.jsxs)(`div`,{className:`relative w-10 h-10 flex-shrink-0`,children:[r?(0,G.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-gray-600`})}):(0,G.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:u}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:u,style:{filter:`brightness(0.85)`}}),(0,G.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]}),i&&(0,G.jsx)(`div`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1.5 h-1.5 bg-bambu-green rounded-full`})]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`text-xs text-white/50 font-medium truncate`,children:t}),s&&(0,G.jsx)(K9,{side:s})]}),(0,G.jsx)(`div`,{className:`text-sm text-white/80 truncate`,children:r?`Empty`:n.tray_type||`?`}),(a!=null||o!=null)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[a!=null&&(0,G.jsx)(F1e,{temp:a,goodThreshold:j?.tempGood,fairThreshold:j?.tempFair}),o!=null&&(0,G.jsx)(P1e,{humidity:o,goodThreshold:j?.humidityGood,fairThreshold:j?.humidityFair})]})]}),!r&&c!=null&&c>=0&&(0,G.jsx)(`div`,{className:`w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0 flex flex-col-reverse`,children:(0,G.jsx)(`div`,{className:`w-full rounded-full`,style:{height:`${c}%`,backgroundColor:Ep(c)}})})]},e)})})]}):(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,G.jsx)(`div`,{className:`text-center text-white/50`,children:(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)})})}):(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,G.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.noPrinter`,`No printer selected`)}),(0,G.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.ams.selectPrinter`,`Select a printer from the top bar`)})]})})}),F&&e&&(0,G.jsx)(PU,{isOpen:!!F,onClose:()=>I(null),printerId:e,slotInfo:F,printerModel:X1e(o?.model??null)||void 0,nozzleDiameter:zp(a,F.amsId),fullScreen:!0,onSuccess:()=>{r.invalidateQueries({queryKey:[`slotPresets`,e]}),r.invalidateQueries({queryKey:[`printerStatus`,e]})}}),L&&e&&(()=>{let t=te(L.amsId,L.trayId),r=ne(L.amsId,L.trayId,L.tray),i=u?p.find(t=>t.printer_id===e&&t.ams_id===L.amsId&&t.tray_id===L.trayId):void 0,a=i?m.find(e=>e.id===i.spoolman_spool_id)??null:null;return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:()=>R(null)}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-sm mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[L.trayColor&&(0,G.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:{backgroundColor:`#${L.trayColor.slice(0,6)}`}}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:L.location}),L.traySubBrands&&(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,L.traySubBrands,`)`]})]}),(0,G.jsx)(`button`,{onClick:()=>R(null),className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(td,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-2`,children:[!u&&t?.spool&&(0,G.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`inventory.assignedSpool`,`Assigned spool`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.spool.rgba&&(0,G.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:Tf(t.spool.rgba)}),(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[t.spool.brand?`${t.spool.brand} `:``,t.spool.material,t.spool.color_name?` - ${t.spool.color_name}`:``]}),(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0 ml-auto`,children:[`#`,t.spool.id]})]})]}),u&&r&&!a&&(0,G.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`spoolman.linkedSpool`,`Linked spool`)}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[`Spoolman #`,r.id,r.remaining_weight==null?``:` (${Math.round(r.remaining_weight)}g)`]})})]}),u&&a&&(0,G.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`inventory.assignedSpool`,`Assigned spool`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a.rgba&&(0,G.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:Tf(a.rgba)}),(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[a.brand?`${a.brand} `:``,a.material,a.color_name?` - ${a.color_name}`:``]})]})]}),(0,G.jsxs)(`button`,{onClick:ce,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-blue transition-colors text-left`,children:[(0,G.jsx)(tu,{className:`w-5 h-5 text-bambu-blue flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:n(`configureAmsSlot.title`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.configureDesc`,`Set filament preset, K-profile, and color`)})]})]}),!u&&(Bp(L?.tray)?null:t?(0,G.jsxs)(`button`,{onClick:de,disabled:re.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left`,children:[(0,G.jsx)(zu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`,`Unassign`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unassignDesc`,`Remove inventory spool from this slot`)})]})]}):(0,G.jsxs)(`button`,{onClick:le,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors text-left`,children:[(0,G.jsx)(Sl,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.assignSpool`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.assignDesc`,`Track a spool from your inventory`)})]})]})),u&&(r?.id?(0,G.jsxs)(`button`,{onClick:()=>ie.mutate(r.id),disabled:ie.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left active:opacity-50`,children:[(0,G.jsx)(zu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unlinkDesc`,`Remove Spoolman link from this slot`)})]})]}):a?(0,G.jsxs)(`button`,{onClick:()=>ae.mutate(a.id),disabled:ae.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left active:opacity-50`,children:[(0,G.jsx)(zu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unassignDesc`,`Remove inventory spool from this slot`)})]})]}):(0,G.jsxs)(`button`,{onClick:ue,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors text-left`,children:[(0,G.jsx)(Yc,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.assignSpool`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.linkDesc`,`Link a Spoolman spool to this slot`)})]})]}))]})]})]})})(),z&&(0,G.jsx)(YH,{isOpen:!!z,onClose:()=>{B(null),r.invalidateQueries({queryKey:[`spool-assignments`,e]}),r.invalidateQueries({queryKey:[`spool-assignments`]})},printerId:z.printerId,amsId:z.amsId,trayId:z.trayId,trayInfo:z.trayInfo,spoolmanEnabled:!!u}),V&&(0,G.jsx)(qH,{isOpen:!!V,onClose:()=>ee(null),tagUid:V.tagUid,trayUuid:V.trayUuid,printerId:V.printerId,amsId:V.amsId,trayId:V.trayId})]})}function $1e({type:e,deviceId:t,onClose:n}){let{t:r}=U(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)(!1);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!i&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i,n]);let f=(0,y.useCallback)(async()=>{a(!0),s(``),l(``),d(!0);try{s(r(`spoolbuddy.diagnostic.queuing`,`Queuing diagnostic on device... -`)),await Cd.queueDiagnostics(t,e);let n=null,i=0;for(;i<60&&!n;){await new Promise(e=>setTimeout(e,500));try{n=await Cd.getDiagnosticResult(t,e);break}catch{i++,i%4==0&&s(e=>e+`.`)}}if(!n)throw Error(`Diagnostic timed out - device did not report results`);s(n.output),n.success||l(`Exit code: ${n.exit_code}`)}catch(e){l(e instanceof Error?e.message:`Unknown error`),s(``)}finally{a(!1)}},[e,t,r]);return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 animate-fade-in`,onClick:n,children:(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg shadow-xl w-full max-w-2xl mx-4 max-h-[80vh] flex flex-col animate-slide-up`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex justify-between items-center p-4 border-b border-zinc-700`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e===`scale`?r(`spoolbuddy.diagnostic.scaleTitle`,`Scale Diagnostic`):e===`read_tag`?r(`spoolbuddy.diagnostic.readTagTitle`,`Read Tag Diagnostic`):r(`spoolbuddy.diagnostic.nfcTitle`,`NFC Reader Diagnostic`)}),(0,G.jsx)(`button`,{onClick:n,className:`text-zinc-400 hover:text-white transition-colors`,"aria-label":`Close`,children:(0,G.jsx)(td,{size:20})})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-auto p-4 bg-black/50 font-mono text-sm`,children:i?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-green-400`,children:[(0,G.jsx)(`div`,{className:`animate-spin w-4 h-4 border-2 border-green-400 border-t-transparent rounded-full`}),(0,G.jsx)(`span`,{children:r(`spoolbuddy.diagnostic.running`,`Running diagnostic on device...`)})]}):o?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`text-green-400 whitespace-pre-wrap break-words`,children:o}),c&&(0,G.jsxs)(`div`,{className:`text-red-400 mt-2`,children:[`❌ `,c]})]}):u?(0,G.jsx)(`div`,{children:c?(0,G.jsxs)(`div`,{className:`text-red-400`,children:[`ERROR: `,c]}):(0,G.jsx)(`span`,{className:`text-green-400`,children:r(`spoolbuddy.diagnostic.completed`,`Diagnostic completed successfully.`)})}):(0,G.jsxs)(`div`,{className:`text-zinc-500`,children:[r(`spoolbuddy.diagnostic.clickStart`,`Click "Run Diagnostic" to start the hardware diagnostic on`),` `,t,`.`]})}),(0,G.jsxs)(`div`,{className:`flex gap-2 p-4 border-t border-zinc-700 bg-zinc-800`,children:[(0,G.jsx)(`button`,{onClick:f,disabled:i,className:`flex-1 flex items-center justify-center gap-2 bg-green-600 hover:bg-green-700 disabled:bg-gray-600 disabled:cursor-not-allowed px-4 py-2 rounded font-semibold text-white transition-colors`,children:i?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`animate-spin w-4 h-4 border-2 border-white border-t-transparent rounded-full`}),r(`spoolbuddy.diagnostic.runningBtn`,`Running...`)]}):u?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Wl,{size:16}),r(`spoolbuddy.diagnostic.runAgain`,`Run Again`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ml,{size:16}),r(`spoolbuddy.diagnostic.runBtn`,`Run Diagnostic`)]})}),(0,G.jsx)(`button`,{onClick:n,className:`px-4 py-2 rounded bg-zinc-700 hover:bg-zinc-600 text-white font-semibold transition-colors`,children:r(`spoolbuddy.diagnostic.close`,`Close`)})]})]})})}function e0e(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m`:`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`}function t0e(e){if(!e)return`-`;let t=Xf(e);return t?t.toLocaleDateString(void 0,{month:`short`,day:`numeric`})+` `+t.toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`}):`-`}var n0e=[{label:`Off`,value:0},{label:`1m`,value:60},{label:`2m`,value:120},{label:`5m`,value:300},{label:`10m`,value:600},{label:`30m`,value:1800}];function r0e({device:e}){let{t}=U(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(null);return(0,y.useEffect)(()=>{!i&&e.backend_url&&a(e.backend_url)},[e.backend_url,i]),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.nfcReader`,`NFC Reader`)}),(0,G.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.type`,`Type`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:e.nfc_reader_type||`N/A`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.connection`,`Connection`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:e.nfc_connection||`N/A`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.status.status`,`Status`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full ${e.nfc_ok?`bg-green-500`:e.nfc_reader_type?`bg-red-500`:`bg-zinc-600`}`}),(0,G.jsx)(`span`,{className:e.nfc_ok?`text-green-400`:e.nfc_reader_type?`text-red-400`:`text-zinc-500`,children:e.nfc_ok?t(`spoolbuddy.status.nfcReady`,`Ready`):e.nfc_reader_type?t(`common.error`,`Error`):t(`spoolbuddy.settings.notConnected`,`N/A`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.deviceInfo`,`Device Info`)}),(0,G.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.hostname`,`Host`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 truncate ml-2`,children:e.hostname})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`IP`}),(0,G.jsx)(`span`,{className:`text-zinc-300`,children:e.ip_address})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.uptime`,`Uptime`)}),(0,G.jsx)(`span`,{className:`text-zinc-300`,children:e0e(e.uptime_s)})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`ID`}),(0,G.jsx)(`span`,{className:`text-zinc-400 font-mono truncate ml-2`,children:e.device_id})]})]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 space-y-2`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300`,children:t(`spoolbuddy.settings.systemConfig`,`Backend & Auth`)}),(0,G.jsx)(`input`,{value:i,onChange:e=>a(e.target.value),placeholder:`http://192.168.1.100:5000`,className:`w-full px-2 py-1.5 rounded bg-zinc-900 border border-zinc-700 text-zinc-100 text-xs`}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`password`,value:o,onChange:e=>s(e.target.value),placeholder:t(`spoolbuddy.settings.apiTokenPlaceholder`,`API token`),className:`flex-1 px-2 py-1.5 rounded bg-zinc-900 border border-zinc-700 text-zinc-100 text-xs`}),(0,G.jsx)(`button`,{onClick:async()=>{if(!i.trim()){d({type:`error`,text:t(`spoolbuddy.settings.systemFieldsRequired`,`Backend URL is required.`)});return}l(!0),d(null);try{await Cd.updateSystemConfig(e.device_id,i.trim(),o.trim()||void 0),d({type:`ok`,text:t(`spoolbuddy.settings.systemQueued`,`Config queued.`)})}catch(e){d({type:`error`,text:e instanceof Error?e.message:t(`common.error`,`Error`)})}finally{l(!1)}},disabled:c,className:`px-3 py-1.5 rounded bg-green-700 hover:bg-green-600 disabled:bg-zinc-700 text-xs font-medium text-zinc-100`,children:t(`spoolbuddy.settings.saveConfig`,`Save`)})]}),u&&(0,G.jsx)(`div`,{className:`text-xs ${u.type===`ok`?`text-green-400`:`text-red-400`}`,children:u.text})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 flex flex-col gap-2`,children:[(0,G.jsxs)(`button`,{onClick:()=>r(`nfc`),className:`flex-1 bg-blue-700 hover:bg-blue-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,G.jsx)(Ju,{className:`w-4 h-4 text-blue-300 shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium text-blue-100`,children:t(`spoolbuddy.settings.nfcDiagnostic`,`NFC Diagnostic`)})]}),(0,G.jsxs)(`button`,{onClick:()=>r(`scale`),className:`flex-1 bg-yellow-700 hover:bg-yellow-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,G.jsx)(rd,{className:`w-4 h-4 text-yellow-300 shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium text-yellow-100`,children:t(`spoolbuddy.settings.scaleDiagnostic`,`Scale Diagnostic`)})]}),(0,G.jsxs)(`button`,{onClick:()=>r(`read_tag`),className:`flex-1 bg-emerald-700 hover:bg-emerald-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,G.jsx)(dc,{className:`w-4 h-4 text-emerald-300 shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium text-emerald-100`,children:t(`spoolbuddy.settings.readTagDiagnostic`,`Read Tag`)})]})]})]}),n&&e&&(0,G.jsx)($1e,{type:n,deviceId:e.device_id,onClose:()=>r(null)})]})}function i0e({device:e,onBrightnessChange:t}){let{t:n}=U(),[r,i]=(0,y.useState)(e.display_brightness),[a,o]=(0,y.useState)(e.display_blank_timeout),[s,c]=(0,y.useState)(!1),l=(0,y.useRef)(void 0),u=(0,y.useRef)(void 0);(0,y.useEffect)(()=>{i(e.display_brightness),o(e.display_blank_timeout)},[e.display_brightness,e.display_blank_timeout]);let d=(0,y.useCallback)(()=>{c(!0),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>c(!1),1500)},[]),f=(0,y.useCallback)((t,n)=>{l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{Cd.updateDisplay(e.device_id,t,n).then(()=>d()).catch(e=>console.error(`Failed to update display:`,e))},300)},[e.device_id,d]),p=e=>{i(e),t(e),f(e,a)},m=e=>{o(e),f(r,e)};return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300`,children:n(`spoolbuddy.settings.brightness`,`Brightness`)}),s&&(0,G.jsxs)(`span`,{className:`text-xs text-green-400 flex items-center gap-1 animate-pulse`,children:[(0,G.jsx)(`svg`,{className:`w-3 h-3`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:3,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}),n(`spoolbuddy.settings.saved`,`Saved`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4 text-zinc-500 flex-shrink-0`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z`})}),(0,G.jsx)(`input`,{type:`range`,min:0,max:100,value:r,onChange:e=>p(parseInt(e.target.value)),className:`flex-1 h-2 bg-zinc-700 rounded-lg appearance-none cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-sm font-mono text-zinc-400 w-10 text-right`,children:[r,`%`]})]}),!e.has_backlight&&(0,G.jsx)(`p`,{className:`text-xs text-zinc-600 mt-2`,children:n(`spoolbuddy.settings.noBacklight`,`No DSI backlight detected. Brightness control requires a DSI display.`)})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1`,children:n(`spoolbuddy.settings.screenBlank`,`Screen Blank Timeout`)}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mb-3`,children:n(`spoolbuddy.settings.screenBlankDesc`,`Screen turns off after inactivity. Touch to wake.`)}),(0,G.jsx)(`div`,{className:`grid grid-cols-3 gap-2`,children:n0e.map(e=>(0,G.jsx)(`button`,{onClick:()=>m(e.value),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors min-h-[40px] ${a===e.value?`bg-green-600 text-white`:`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`}`,children:e.label},e.value))})]}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-600 text-center`,children:n(`spoolbuddy.settings.displayNote`,`Brightness is applied as a software filter.`)})]})}function a0e({step:e,labels:t}){return(0,G.jsxs)(`div`,{className:`flex flex-col items-center w-16 shrink-0 pt-1`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center w-7 h-7 rounded-full text-xs font-bold ${e===`tare`?`bg-green-600 text-white`:`bg-green-600/20 text-green-400`}`,children:e===`weight`?(0,G.jsx)(`svg`,{className:`w-3.5 h-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:3,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}):`1`}),(0,G.jsx)(`span`,{className:`text-[10px] mt-0.5 ${e===`tare`?`text-green-400 font-medium`:`text-green-400/60`}`,children:t.tare}),(0,G.jsx)(`div`,{className:`w-px h-5 my-1 ${e===`weight`?`bg-green-600/40`:`bg-zinc-700`}`}),(0,G.jsx)(`div`,{className:`flex items-center justify-center w-7 h-7 rounded-full text-xs font-bold ${e===`weight`?`bg-green-600 text-white`:`bg-zinc-700 text-zinc-500`}`,children:`2`}),(0,G.jsx)(`span`,{className:`text-[10px] mt-0.5 ${e===`weight`?`text-green-400 font-medium`:`text-zinc-600`}`,children:t.weight})]})}function o0e({device:e,weight:t,weightStable:n,rawAdc:r}){let{t:i}=U(),a=co(),[o,s]=(0,y.useState)(`idle`),[c,l]=(0,y.useState)(`500`),[u,d]=(0,y.useState)(null),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),v=(0,y.useRef)(null);(0,y.useEffect)(()=>()=>{v.current&&clearTimeout(v.current)},[]);let b=(0,y.useCallback)(e=>{v.current&&clearTimeout(v.current),v.current=setTimeout(()=>h(null),e)},[]);(0,y.useEffect)(()=>{if(!g)return;let e=()=>Date.now()-g.startedAtMs,t=setInterval(()=>{a.invalidateQueries({queryKey:[`spoolbuddy-devices`]})},1e3),n=setTimeout(()=>{_(null),h({type:`error`,msg:i(`spoolbuddy.settings.tareTimedOut`,`Tare timed out — is the SpoolBuddy daemon running?`)}),b(5e3)},Math.max(0,15e3-e()));return()=>{clearInterval(t),clearTimeout(n)}},[g,a,i,b]),(0,y.useEffect)(()=>{g&&(e?.last_calibrated_at??null)!==g.snapshot&&(_(null),h({type:`ok`,msg:i(`spoolbuddy.settings.tareComplete`,`Tare complete!`)}),b(3e3))},[e?.last_calibrated_at,g,i,b]);let x=e=>{e===`backspace`?l(e=>e.slice(0,-1)||``):e===`.`&&!c.includes(`.`)?l(e=>e+`.`):e>=`0`&&e<=`9`&&l(t=>t===`0`?e:t+e)};return o===`idle`?(0,G.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,G.jsx)(`span`,{className:`text-lg font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`})]}),(0,G.jsxs)(`div`,{className:`text-xs text-zinc-500 text-right`,children:[(0,G.jsxs)(`span`,{children:[i(`spoolbuddy.settings.tareOffset`,`Tare`),`: `,e.tare_offset]}),(0,G.jsx)(`span`,{className:`mx-1.5`,children:`·`}),(0,G.jsxs)(`span`,{children:[i(`spoolbuddy.settings.calFactor`,`Factor`),`: `,e.calibration_factor.toFixed(2)]})]})]}),e.last_calibrated_at&&(0,G.jsxs)(`div`,{className:`text-xs text-zinc-600 mt-1`,children:[i(`spoolbuddy.settings.lastCalibrated`,`Last calibrated`),`: `,t0e(e.last_calibrated_at)]})]}),m&&(0,G.jsx)(`div`,{className:`rounded-lg px-3 py-2 mb-3 text-sm ${m.type===`ok`?`bg-green-900/30 text-green-300 border border-green-800`:`bg-red-900/30 text-red-300 border border-red-800`}`,children:m.msg}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`button`,{onClick:async()=>{p(!0),h(null),v.current&&=(clearTimeout(v.current),null);let t=e?.last_calibrated_at??null;try{await Cd.tare(e.device_id),h({type:`ok`,msg:i(`spoolbuddy.settings.tareSet`,`Tare command sent. Waiting for device...`)}),_({snapshot:t,startedAtMs:Date.now()})}catch{h({type:`error`,msg:i(`spoolbuddy.settings.tareFailed`,`Failed to send tare command`)}),b(5e3)}finally{p(!1)}},disabled:f,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-200 hover:bg-zinc-600 disabled:opacity-40 transition-colors min-h-[44px] flex items-center justify-center gap-2`,children:[f&&(0,G.jsxs)(`svg`,{className:`w-4 h-4 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,G.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,G.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),i(`spoolbuddy.weight.tare`,`Tare`)]}),(0,G.jsx)(`button`,{onClick:()=>{s(`tare`),h(null)},className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:i(`spoolbuddy.weight.calibrate`,`Calibrate`)})]})]}):(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(a0e,{step:o,labels:{tare:i(`spoolbuddy.weight.tare`,`Tare`),weight:i(`spoolbuddy.settings.knownWeight`,`Known weight`)}}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 bg-zinc-800 rounded-lg px-3 py-1.5 mb-1.5`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,G.jsx)(`span`,{className:`text-sm font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`}),(0,G.jsx)(`span`,{className:`text-xs ml-auto ${n?`text-green-400`:`text-amber-400`}`,children:n?i(`spoolbuddy.settings.stable`,`Stable`):i(`spoolbuddy.settings.settling`,`Settling...`)})]}),m&&(0,G.jsx)(`div`,{className:`rounded-lg px-3 py-1.5 mb-1.5 text-xs ${m.type===`ok`?`bg-green-900/30 text-green-300 border border-green-800`:`bg-red-900/30 text-red-300 border border-red-800`}`,children:m.msg}),o===`tare`?(0,G.jsx)(`p`,{className:`text-sm text-zinc-300 mb-3`,children:i(`spoolbuddy.settings.calStep1`,`Remove all items from the scale and press Set Zero.`)}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-zinc-400 shrink-0`,children:i(`spoolbuddy.settings.knownWeight`,`Known weight`)}),(0,G.jsxs)(`div`,{className:`flex-1 bg-zinc-900 border border-zinc-600 rounded px-3 py-1 text-right text-lg font-mono text-zinc-100`,children:[c||`0`,(0,G.jsx)(`span`,{className:`text-zinc-500 ml-1`,children:`g`})]})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-4 gap-1 mb-1.5`,children:[`7`,`8`,`9`,`backspace`,`4`,`5`,`6`,`.`,`1`,`2`,`3`,`0`].map(e=>(0,G.jsx)(`button`,{onClick:()=>x(e),className:`rounded text-lg font-medium transition-colors h-[48px] active:scale-95 ${e===`backspace`?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`:`bg-zinc-800 text-zinc-100 hover:bg-zinc-700 border border-zinc-700`}`,children:e===`backspace`?`⌫`:e},e))})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`button`,{onClick:()=>{s(`idle`),h(null)},className:`flex-1 px-4 py-2 rounded-lg text-sm bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors h-[40px]`,children:i(`common.cancel`,`Cancel`)}),(0,G.jsxs)(`button`,{onClick:async()=>{if(o===`tare`){p(!0),h(null);try{d(r),await Cd.tare(e.device_id),h({type:`ok`,msg:i(`spoolbuddy.settings.zeroSet`,`Zero point set. Place known weight on scale.`)}),s(`weight`)}catch{h({type:`error`,msg:i(`spoolbuddy.settings.tareFailed`,`Failed to send tare command`)})}finally{p(!1)}}else if(o===`weight`){let t=parseFloat(c);if(r===null||!t||t<=0)return;p(!0),h(null);try{await Cd.setCalibrationFactor(e.device_id,t,r,u??void 0),h({type:`ok`,msg:i(`spoolbuddy.settings.calibrationDone`,`Calibration complete!`)}),b(3e3),s(`idle`)}catch{h({type:`error`,msg:i(`spoolbuddy.settings.calibrationFailed`,`Calibration failed`)}),b(5e3)}finally{p(!1)}}},disabled:f,className:`flex-1 px-4 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors h-[40px] flex items-center justify-center gap-2`,children:[f&&(0,G.jsxs)(`svg`,{className:`w-4 h-4 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,G.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,G.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),o===`tare`?i(`spoolbuddy.settings.setZero`,`Set Zero`):i(`spoolbuddy.settings.calibrateNow`,`Calibrate`)]})]})]})]})}function s0e({device:e}){let{t}=U(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(null),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),u=e.update_status===`pending`||e.update_status===`updating`;(0,y.useEffect)(()=>{u&&n===`applying`&&r(null)},[u,n]),(0,y.useEffect)(()=>{let e=()=>{u&&setTimeout(()=>window.location.reload(),1e3)};return window.addEventListener(`spoolbuddy-online`,e),()=>window.removeEventListener(`spoolbuddy-online`,e)},[u]);let{data:d,refetch:f}=K({queryKey:[`spoolbuddy-update-check`,e.device_id],queryFn:()=>Cd.checkDaemonUpdate(e.device_id),staleTime:0}),{data:p}=K({queryKey:[`spoolbuddy-ssh-key`],queryFn:()=>Cd.getSSHPublicKey(),enabled:o,staleTime:1/0}),m=async()=>{r(`checking`),a(null);try{await f()}finally{r(null)}},h=async()=>{r(`applying`),a(null);try{await Cd.triggerUpdate(e.device_id)}catch(e){a(e instanceof Error?e.message:`Failed to trigger update`),r(null)}},g=n!=null||u,_=()=>{p?.public_key&&(navigator.clipboard.writeText(p.public_key),l(!0),setTimeout(()=>l(!1),2e3))},v=e.firmware_version||(d?.current_version&&d.current_version!==`0.0.0`?d.current_version:null);return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between items-center text-sm`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.currentVersion`,`Current Version`)}),(0,G.jsx)(`span`,{className:`text-zinc-200 font-mono`,children:v||(0,G.jsx)(`span`,{className:`text-zinc-500 italic text-xs`,children:t(`spoolbuddy.settings.versionPending`,`Waiting for daemon...`)})})]}),g?(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`svg`,{className:`w-4 h-4 animate-spin text-green-400 flex-shrink-0`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,G.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,G.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),(0,G.jsx)(`span`,{className:`text-green-300 text-xs`,children:n===`checking`?t(`spoolbuddy.settings.checking`,`Checking for updates...`):e.update_message||t(`spoolbuddy.settings.updateWaiting`,`Updating...`)})]}):e.update_status===`error`?(0,G.jsx)(`p`,{className:`text-xs text-red-300`,children:e.update_message||t(`spoolbuddy.settings.updateFailed`,`Update failed`)}):i?(0,G.jsx)(`p`,{className:`text-xs text-red-300`,children:i}):d?.update_available?(0,G.jsxs)(`p`,{className:`text-xs text-green-300`,children:[t(`spoolbuddy.settings.updateAvailable`,`Update available`),`: `,v,` → `,d.latest_version]}):null,!g&&(d?.update_available?(0,G.jsx)(`button`,{onClick:h,disabled:!e.online,className:`w-full px-3 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors`,children:e.online?t(`spoolbuddy.settings.applyUpdate`,`Apply Update`):t(`spoolbuddy.settings.deviceOffline`,`Device Offline`)}):(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`button`,{onClick:m,className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors`,children:t(`spoolbuddy.settings.checkUpdates`,`Check for Updates`)}),(0,G.jsx)(`button`,{onClick:h,disabled:!e.online,className:`px-3 py-2 rounded-lg text-xs font-medium bg-zinc-700 text-zinc-400 hover:bg-zinc-600 hover:text-zinc-200 disabled:opacity-40 transition-colors`,children:t(`spoolbuddy.settings.forceUpdate`,`Force Update`)})]}))]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsxs)(`button`,{onClick:()=>s(!o),className:`w-full flex justify-between items-center text-xs`,children:[(0,G.jsx)(`span`,{className:`font-medium text-zinc-400`,children:t(`spoolbuddy.settings.sshSetup`,`SSH Setup`)}),(0,G.jsx)(`svg`,{className:`w-3 h-3 text-zinc-500 transition-transform ${o?`rotate-180`:``}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 9l-7 7-7-7`})})]}),o&&(0,G.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-zinc-500`,children:t(`spoolbuddy.settings.sshDescription`,`SSH key is deployed automatically. For manual setup, add this key to ~/.ssh/authorized_keys on the device.`)}),p?.public_key?(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`pre`,{className:`bg-zinc-900 rounded p-2 text-[10px] text-zinc-400 font-mono break-all whitespace-pre-wrap`,children:p.public_key}),(0,G.jsx)(`button`,{onClick:_,className:`absolute top-1 right-1 px-1.5 py-0.5 rounded text-[10px] bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors`,children:c?t(`common.copied`,`Copied!`):t(`common.copy`,`Copy`)})]}):(0,G.jsx)(`span`,{className:`text-[10px] text-zinc-500 italic`,children:t(`spoolbuddy.settings.sshKeyLoading`,`Loading...`)})]})]})]})}function c0e({percent:e,color:t}){return(0,G.jsx)(`div`,{className:`w-full h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all ${t}`,style:{width:`${Math.min(100,Math.max(0,e))}%`}})})}function l0e(e){let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h ${r}m`:n>0?`${n}h ${r}m`:`${r}m`}function u0e({device:e}){let{t}=U(),n=e.system_stats;if(!n)return(0,G.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,G.jsx)(`p`,{className:`text-sm text-zinc-500`,children:t(`spoolbuddy.settings.systemStatsWaiting`,`Waiting for system stats...`)})});let r=n.memory,i=n.disk,a=(n.cpu_temp_c??0)>=80?`text-red-400`:(n.cpu_temp_c??0)>=65?`text-amber-400`:`text-green-400`,o=(r?.percent??0)>=90?`bg-red-500`:(r?.percent??0)>=70?`bg-amber-500`:`bg-green-500`,s=(i?.percent??0)>=90?`bg-red-500`:(i?.percent??0)>=70?`bg-amber-500`:`bg-green-500`;return(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:`CPU`}),(0,G.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.cores`,`Cores`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.cpu_count??`-`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.loadAvg`,`Load Avg`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.load_avg?n.load_avg.join(` / `):`-`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.temp`,`Temp`)}),(0,G.jsx)(`span`,{className:`font-mono font-medium ${a}`,children:n.cpu_temp_c==null?`-`:`${n.cpu_temp_c}\u00B0C`})]})]})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.memory`,`Memory`)}),r?(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(c0e,{percent:r.percent??0,color:o}),(0,G.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.used`,`Used`)}),(0,G.jsxs)(`span`,{className:`text-zinc-300 font-mono`,children:[r.used_mb,` / `,r.total_mb,` MB`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.available`,`Free`)}),(0,G.jsxs)(`span`,{className:`text-zinc-300 font-mono`,children:[r.available_mb,` MB`]})]})]})]}):(0,G.jsx)(`span`,{className:`text-xs text-zinc-500`,children:`-`})]})]}),(0,G.jsx)(`div`,{className:`bg-zinc-800 rounded-lg px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 shrink-0`,children:t(`spoolbuddy.settings.disk`,`Disk`)}),i?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`flex-1`,children:(0,G.jsx)(c0e,{percent:i.percent??0,color:s})}),(0,G.jsxs)(`span`,{className:`text-xs text-zinc-300 font-mono shrink-0`,children:[i.used_gb,` / `,i.total_gb,` GB`]})]}):(0,G.jsx)(`span`,{className:`text-xs text-zinc-500`,children:`-`})]})}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1.5`,children:t(`spoolbuddy.settings.osInfo`,`OS`)}),(0,G.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[n.os?.os&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.distro`,`Distro`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 truncate ml-2`,children:n.os.os})]}),n.os?.kernel&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.kernel`,`Kernel`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono truncate ml-2`,children:n.os.kernel})]}),n.os?.arch&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.arch`,`Arch`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.os.arch})]})]})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1.5`,children:t(`spoolbuddy.settings.runtime`,`Runtime`)}),(0,G.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[n.os?.python&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`Python`}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.os.python})]}),n.system_uptime_s!=null&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.systemUptime`,`Uptime`)}),(0,G.jsx)(`span`,{className:`text-zinc-300`,children:l0e(n.system_uptime_s)})]})]})]})]})]})}function d0e(){let{sbState:e,setDisplayBrightness:t}=lr(),{t:n}=U(),[r,i]=(0,y.useState)(`device`),{data:a=[]}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Cd.getDevices(),refetchInterval:1e4}),o=e.deviceId?a.find(t=>t.device_id===e.deviceId)??a[0]:a[0],s=[{id:`device`,label:n(`spoolbuddy.settings.tabDevice`,`Device`)},{id:`display`,label:n(`spoolbuddy.settings.tabDisplay`,`Display`)},{id:`scale`,label:n(`spoolbuddy.settings.tabScale`,`Scale`)},{id:`updates`,label:n(`spoolbuddy.settings.tabUpdates`,`Updates`)},{id:`system`,label:n(`spoolbuddy.settings.tabSystem`,`System`)}];return(0,G.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,G.jsx)(`h1`,{className:`text-xl font-semibold text-zinc-100 mb-3`,children:n(`spoolbuddy.nav.settings`,`Settings`)}),(0,G.jsx)(`div`,{className:`flex gap-1 bg-zinc-800/50 rounded-lg p-1 mb-4`,children:s.map(e=>(0,G.jsx)(`button`,{onClick:()=>i(e.id),className:`flex-1 px-2 py-2 rounded-md text-sm font-medium transition-colors min-h-[36px] ${r===e.id?`bg-zinc-700 text-zinc-100`:`text-zinc-500 hover:text-zinc-300`}`,children:e.label},e.id))}),(0,G.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:o?(0,G.jsxs)(G.Fragment,{children:[r===`device`&&(0,G.jsx)(r0e,{device:o}),r===`display`&&(0,G.jsx)(i0e,{device:o,onBrightnessChange:t}),r===`scale`&&(0,G.jsx)(o0e,{device:o,weight:e.weight,weightStable:e.weightStable,rawAdc:e.rawAdc}),r===`updates`&&(0,G.jsx)(s0e,{device:o}),r===`system`&&(0,G.jsx)(u0e,{device:o})]}):(0,G.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,G.jsx)(`div`,{className:`text-center text-zinc-500`,children:(0,G.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.settings.noDevice`,`No SpoolBuddy device found`)})})})})]})}function f0e({device:e,weight:t,weightStable:n,rawAdc:r}){let{t:i}=U(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(`idle`),[l,u]=(0,y.useState)(`500`),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(!1),h=e=>{e===`backspace`?u(e=>e.slice(0,-1)||``):e===`.`&&!l.includes(`.`)?u(e=>e+`.`):e>=`0`&&e<=`9`&&u(t=>t===`0`?e:t+e)};return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-zinc-400`,children:i(`spoolbuddy.settings.currentWeight`,`Current weight`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,G.jsx)(`span`,{className:`text-lg font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 mt-3 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:i(`spoolbuddy.settings.tareOffset`,`Tare offset`)}),(0,G.jsx)(`span`,{className:`text-zinc-400 font-mono`,children:e.tare_offset})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:i(`spoolbuddy.settings.calFactor`,`Cal. factor`)}),(0,G.jsx)(`span`,{className:`text-zinc-400 font-mono`,children:e.calibration_factor.toFixed(2)})]})]})]}),s===`idle`?(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`button`,{onClick:async()=>{m(!0);try{await Cd.tare(e.device_id)}catch(e){console.error(`Failed to tare:`,e)}finally{m(!1)}},disabled:p,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-200 hover:bg-zinc-600 disabled:opacity-40 transition-colors min-h-[44px]`,children:p?`...`:i(`spoolbuddy.weight.tare`,`Tare`)}),(0,G.jsx)(`button`,{onClick:()=>{c(`tare`)},className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:i(`spoolbuddy.weight.calibrate`,`Calibrate`)})]}):(0,G.jsxs)(`div`,{className:`bg-zinc-800 border border-zinc-700 rounded-lg p-3 space-y-2`,children:[(0,G.jsx)(`div`,{className:`text-sm font-medium text-zinc-200`,children:s===`tare`?i(`spoolbuddy.settings.calStep1`,`Step 1: Remove all items from the scale`):i(`spoolbuddy.settings.calStep2`,`Step 2: Place known weight on scale`)}),s===`weight`&&(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs text-zinc-400`,children:i(`spoolbuddy.settings.knownWeight`,`Known weight (g)`)}),(0,G.jsxs)(`div`,{className:`flex-1 bg-zinc-900 border border-zinc-600 rounded px-3 py-1.5 text-right text-base font-mono text-zinc-100`,children:[l||`0`,(0,G.jsx)(`span`,{className:`text-zinc-500 ml-1`,children:`g`})]})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-4 gap-1`,children:[`7`,`8`,`9`,`backspace`,`4`,`5`,`6`,`.`,`1`,`2`,`3`,`0`].map(e=>(0,G.jsx)(`button`,{onClick:()=>h(e),className:`py-2 rounded text-sm font-medium transition-colors min-h-[36px] ${e===`backspace`?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`:`bg-zinc-800 text-zinc-100 hover:bg-zinc-700 border border-zinc-700`}`,children:e===`backspace`?`⌫`:e},e))})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`button`,{onClick:()=>c(`idle`),className:`flex-1 px-4 py-2 rounded-lg text-sm bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[40px]`,children:i(`common.cancel`,`Cancel`)}),(0,G.jsx)(`button`,{onClick:async()=>{if(s===`tare`){o(!0);try{f(r),await Cd.tare(e.device_id),c(`weight`)}catch(e){console.error(`Failed to tare:`,e)}finally{o(!1)}}else if(s===`weight`){let t=parseFloat(l);if(r===null||!t||t<=0)return;o(!0);try{await Cd.setCalibrationFactor(e.device_id,t,r,d??void 0),c(`idle`)}catch(e){console.error(`Failed to calibrate:`,e)}finally{o(!1)}}},disabled:a,className:`flex-1 px-4 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors min-h-[40px]`,children:a?`...`:s===`tare`?i(`spoolbuddy.settings.setZero`,`Set Zero`):i(`spoolbuddy.settings.calibrateNow`,`Calibrate`)})]})]})]})}function p0e(){let{sbState:e}=lr(),{t}=U(),n=or(),{data:r=[]}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Cd.getDevices(),refetchInterval:1e4}),i=e.deviceId?r.find(t=>t.device_id===e.deviceId)??r[0]:r[0];return(0,G.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,G.jsx)(`button`,{onClick:()=>n(`/spoolbuddy/settings`),className:`p-1.5 rounded-lg text-zinc-400 hover:text-zinc-200 hover:bg-zinc-800 transition-colors`,children:(0,G.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 19l-7-7 7-7`})})}),(0,G.jsx)(`h1`,{className:`text-xl font-semibold text-zinc-100`,children:t(`spoolbuddy.settings.scaleCalibration`,`Scale Calibration`)})]}),(0,G.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:i?(0,G.jsx)(f0e,{device:i,weight:e.weight,weightStable:e.weightStable,rawAdc:e.rawAdc}):(0,G.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,G.jsx)(`div`,{className:`text-center text-zinc-500`,children:(0,G.jsx)(`p`,{className:`text-sm`,children:t(`spoolbuddy.settings.noDevice`,`No SpoolBuddy device found`)})})})})]})}var m0e=[`PLA`,`PETG`,`ABS`,`ASA`,`TPU`,`PA`,`PC`,`PVA`,`HIPS`];function h0e(){let{t:e}=U(),{showToast:t}=Hd(),{sbState:n}=lr(),[r,i]=(0,y.useState)(`existing`),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`idle`),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(null),{data:b}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,staleTime:300*1e3}),x=b!==void 0,S=b?.spoolman_enabled===`true`&&!!b?.spoolman_url,{data:C=[],refetch:w}=K({queryKey:[S?`spoolman-inventory-spools`:`inventory-spools`,`write-tag`],queryFn:()=>S?Z.getSpoolmanInventorySpools(!1):Z.getSpools(!1),refetchInterval:1e4,enabled:x}),{data:T=[]}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Cd.getDevices(),refetchInterval:5e3}),{data:E}=K({queryKey:[`settings`],queryFn:Z.getSettings}),D=T[0],O=n.deviceOnline,k=Af(E?.currency||`USD`),A=(0,y.useMemo)(()=>{let e;if(r===`existing`)e=C.filter(e=>!e.tag_uid&&!e.archived_at);else if(r===`replace`)e=C.filter(e=>(e.tag_uid||e.tray_uuid)&&!e.archived_at);else return[];if(s){let t=s.toLowerCase();e=e.filter(e=>e.material?.toLowerCase().includes(t)||e.color_name?.toLowerCase().includes(t)||e.brand?.toLowerCase().includes(t)||e.subtype?.toLowerCase().includes(t))}return e},[C,r,s]),j=(0,y.useCallback)(e=>{let t=e.detail;(t.sak??t.data?.sak)===0&&(g(!0),v(t.tag_uid??t.data?.tag_uid??null))},[]),M=(0,y.useCallback)(e=>{let t=e.detail;g(!0),v(t.tag_uid??t.data?.tag_uid??null)},[]),N=(0,y.useCallback)(()=>{g(!1),v(null)},[]),P=(0,y.useCallback)(t=>{let n=t.detail;(n.spool_id===a?.id||n.data?.spool_id===a?.id)&&(u(`success`),f(e(`spoolbuddy.writeTag.writeSuccess`,`Tag written successfully!`)),w(),setTimeout(()=>{u(`idle`),o(null),f(``)},5e3))},[a,e,w]),F=(0,y.useCallback)(t=>{let n=t.detail;(n.spool_id===a?.id||n.data?.spool_id===a?.id)&&(u(`error`),f(n.message??n.data?.message??e(`spoolbuddy.writeTag.writeFailed`,`Write failed`)))},[a,e]);(0,y.useEffect)(()=>(window.addEventListener(`spoolbuddy-unknown-tag`,j),window.addEventListener(`spoolbuddy-tag-matched`,M),window.addEventListener(`spoolbuddy-tag-removed`,N),window.addEventListener(`spoolbuddy-tag-written`,P),window.addEventListener(`spoolbuddy-tag-write-failed`,F),()=>{window.removeEventListener(`spoolbuddy-unknown-tag`,j),window.removeEventListener(`spoolbuddy-tag-matched`,M),window.removeEventListener(`spoolbuddy-tag-removed`,N),window.removeEventListener(`spoolbuddy-tag-written`,P),window.removeEventListener(`spoolbuddy-tag-write-failed`,F)}),[j,M,N,P,F]),(0,y.useEffect)(()=>{o(null),u(`idle`),f(``),c(``)},[r]);let I=async()=>{if(!(!a||!D)){u(`writing`),f(e(`spoolbuddy.writeTag.waiting`,`Waiting for SpoolBuddy...`));try{let e=await Cd.writeTag(D.device_id,a.id);if(e?.warnings?.length)for(let n of e.warnings)t(n,`warning`)}catch{u(`error`),f(e(`spoolbuddy.writeTag.queueFailed`,`Failed to queue write command`))}}},L=async()=>{if(D){try{await Cd.cancelWrite(D.device_id)}catch{}u(`idle`),f(``)}},R=async()=>{if(!(!a||!g0e(a))){m(!0),u(`idle`),f(``);try{S?await Z.linkTagToSpoolmanSpool(a.id,{tag_uid:``,tray_uuid:``}):await Z.linkTagToSpool(a.id,{tag_uid:``,tray_uuid:``,data_origin:`manual`}),await w(),o(null),u(`success`),f(e(`spoolbuddy.writeTag.untagSuccess`,`Tag removed from spool`)),setTimeout(()=>{u(`idle`),f(``)},2500)}catch{u(`error`),f(e(`spoolbuddy.writeTag.untagFailed`,`Failed to remove tag from spool`))}finally{m(!1)}}},z=(0,y.useCallback)(e=>{o(e),u(`idle`),f(``),w()},[w]),B=a&&O&&l!==`writing`&&l!==`success`;return(0,G.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,G.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary shrink-0`,children:[{key:`existing`,label:e(`spoolbuddy.writeTag.tabExisting`,`Existing Spool`)},{key:`new`,label:e(`spoolbuddy.writeTag.tabNew`,`New Spool`)},{key:`replace`,label:e(`spoolbuddy.writeTag.tabReplace`,`Replace Tag`)}].map(e=>(0,G.jsx)(`button`,{onClick:()=>i(e.key),className:`flex-1 py-3 text-sm font-medium transition-colors ${r===e.key?`text-bambu-green border-b-2 border-bambu-green bg-bambu-dark`:`text-zinc-400 hover:text-zinc-200 hover:bg-bambu-dark-tertiary`}`,children:e.label},e.key))}),(0,G.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,G.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden border-r border-bambu-dark-tertiary`,children:r===`new`?(0,G.jsx)(v0e,{currencySymbol:k,onCreated:z,selectedSpool:a,spoolmanMode:S,t:e}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`p-3 shrink-0`,children:(0,G.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:e(`spoolbuddy.writeTag.searchPlaceholder`,`Search by material, color, brand...`),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 pb-3 space-y-2`,children:A.length===0?(0,G.jsx)(`div`,{className:`text-center text-zinc-500 py-8 text-sm`,children:r===`existing`?e(`spoolbuddy.writeTag.noUntaggedSpools`,`No spools without tags`):e(`spoolbuddy.writeTag.noTaggedSpools`,`No spools with tags`)}):A.map(e=>(0,G.jsx)(_0e,{spool:e,selected:a?.id===e.id,showTag:r===`replace`,onClick:()=>{o(e),u(`idle`),f(``)}},e.id))})]})}),(0,G.jsx)(`div`,{className:`w-[340px] flex flex-col items-center justify-center p-6 shrink-0`,children:(0,G.jsx)(y0e,{writeStatus:l,writeMessage:d,selectedSpool:a,tagOnReader:h,tagUid:_,deviceOnline:O,canWrite:!!B,isReplace:r===`replace`,canUntag:r===`replace`&&!!a&&g0e(a),untagging:p,onWrite:I,onUntag:R,onCancel:L,onRetry:()=>{u(`idle`),f(``)},t:e})})]})]})}function g0e(e){return!!(e.tag_uid||e.tray_uuid)}function _0e({spool:e,selected:t,showTag:n,onClick:r}){let i=Math.max(0,e.label_weight-e.weight_used),a=e.label_weight>0?Math.round(i/e.label_weight*100):0;return(0,G.jsxs)(`button`,{onClick:r,className:`w-full flex items-center gap-3 p-3 rounded-lg text-left transition-colors ${t?`bg-bambu-green/15 border border-bambu-green/50`:`bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-transparent`}`,children:[(0,G.jsx)(`div`,{className:`w-8 h-8 rounded-full shrink-0 border border-white/10`,style:e.rgba?Tf(e.rgba):{backgroundColor:`#666`}}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-sm font-medium text-white truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-zinc-400`,children:[e.color_name&&(0,G.jsx)(`span`,{children:e.color_name}),(0,G.jsxs)(`span`,{children:[i,`g / `,e.label_weight,`g (`,a,`%)`]})]}),n&&e.tag_uid&&(0,G.jsx)(`div`,{className:`text-xs text-zinc-500 mt-0.5 font-mono`,children:e.tag_uid})]}),t&&(0,G.jsx)(`svg`,{className:`w-5 h-5 text-bambu-green shrink-0`,fill:`currentColor`,viewBox:`0 0 20 20`,children:(0,G.jsx)(`path`,{fillRule:`evenodd`,d:`M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z`,clipRule:`evenodd`})})]})}function v0e({currencySymbol:e,onCreated:t,selectedSpool:n,spoolmanMode:r,t:i}){let{data:a=[]}=K({queryKey:[r?`spoolman-inventory-spools`:`inventory-spools`,`write-tag-form`],queryFn:()=>r?Z.getSpoolmanInventorySpools(!0):Z.getSpools(!0)}),{data:o}=K({queryKey:[`settings`],queryFn:Z.getSettings}),[s,c]=(0,y.useState)(`simple`),[l,u]=(0,y.useState)(`filament`),[d,f]=(0,y.useState)(v9),[p,m]=(0,y.useState)({}),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)([]),[A,j]=(0,y.useState)([]),[M,N]=(0,y.useState)([]),[P,F]=(0,y.useState)([]),[I,L]=(0,y.useState)([]),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)([]),[ee,te]=(0,y.useState)([]),[ne,re]=(0,y.useState)(new Set),[ie,ae]=(0,y.useState)(new Set);(0,y.useEffect)(()=>{V(vU())},[]),(0,y.useEffect)(()=>{let e=!1;return(async()=>{if(s===`full`){D(!0);try{let[t,n]=await Promise.allSettled([(async()=>(await Z.getCloudStatus()).is_authenticated?{connected:!0,presets:await Z.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await Z.orcaCloudStatus()).connected?{connected:!0,presets:(await Z.orcaCloudListProfiles()).filament}:{connected:!1,presets:[]})()]);if(e)return;let r=t.status===`fulfilled`&&t.value.connected,i=n.status===`fulfilled`&&n.value.connected,a=t.status===`fulfilled`?t.value.presets:[],o=n.status===`fulfilled`?n.value.presets:[];T(r||i),k([...a,...o])}catch{e||T(!1)}finally{e||D(!1)}Z.getSpoolCatalog().then(t=>{e||F(t)}).catch(()=>void 0),Z.getColorCatalog().then(t=>{e||L(t)}).catch(()=>void 0),Z.getLocalPresets().then(t=>{e||j(t.filament)}).catch(()=>void 0),Z.getBuiltinFilaments().then(t=>{e||N(t)}).catch(()=>void 0);try{let t=await Z.getPrinters(),n=await Promise.all(t.map(e=>Z.getPrinterStatus(e.id).catch(()=>null))),r=[];for(let e=0;e{e=!0}},[s]),(0,y.useEffect)(()=>{ee.length>0&&ae(new Set(ee.map(e=>String(e.printer.id))))},[ee]);let oe=(0,y.useMemo)(()=>mU(O,new Set,A,M),[O,A,M]),se=(0,y.useMemo)(()=>hU(d.slicer_filament,oe),[d.slicer_filament,oe]),H=(0,y.useMemo)(()=>{let e=pU(O,A),t=I.map(e=>e.manufacturer?.trim()).filter(e=>!!e);return Array.from(new Set([...e,...t])).sort((e,t)=>e.localeCompare(t))},[O,A,I]),ce=(0,y.useMemo)(()=>{let e=I.map(e=>e.material?.trim()).filter(e=>!!e);return Array.from(new Set([...aU,...e])).sort((e,t)=>e.localeCompare(t))},[I]),le=(0,y.useMemo)(()=>{let e=[];for(let t of I){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of O){let n=fU(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of A){let n=fU(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[O,I,A]),ue=(0,y.useMemo)(()=>{let e=new Map;for(let t of le){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[le]),de=(0,y.useMemo)(()=>{let e=new Map;for(let t of le){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[le]),fe=(0,y.useMemo)(()=>gU(H,d.brand),[H,d.brand]),pe=(0,y.useMemo)(()=>gU(ce,d.material),[ce,d.material]),me=(0,y.useMemo)(()=>_U(fe,d.material,de),[fe,d.material,de]),he=(0,y.useMemo)(()=>_U(pe,d.brand,ue),[pe,d.brand,ue]),ge=(e,t)=>{f(n=>({...n,[e]:t})),p[e]&&m(t=>({...t,[e]:void 0}))},_e=e=>{V(t=>yU(e,t))},ve=async e=>{let t=r?Z.saveSpoolmanKProfiles:Z.saveSpoolKProfiles;if(ne.size===0){try{await t(e,[])}catch{}return}let n=[];for(let e of ne){let[t,r,i]=e.split(`:`),a=parseInt(t),o=parseInt(r),s=i===`null`?0:parseInt(i),c=ee.find(e=>e.printer.id===a);if(c){let e=c.calibrations.find(e=>e.cali_idx===o);e&&n.push({printer_id:a,extruder:s,nozzle_diameter:e.nozzle_diameter||`0.4`,k_value:e.k_value,name:e.name||null,cali_idx:e.cali_idx,setting_id:e.setting_id||null})}}n.length>0&&await t(e,n)},ye=async()=>{C(null);let e=WQe(d,s===`simple`?!0:h);if(!e.isValid){m(e.errors),u(`filament`);return}let n=se?.displayName||R||null,a={material:d.material,subtype:d.subtype||null,brand:d.brand||null,color_name:d.color_name||null,rgba:d.rgba||null,extra_colors:d.extra_colors||null,effect_type:d.effect_type||null,label_weight:d.label_weight,core_weight:d.core_weight,core_weight_catalog_id:d.core_weight_catalog_id,weight_used:d.weight_used,slicer_filament:d.slicer_filament||null,slicer_filament_name:n,nozzle_temp_min:null,nozzle_temp_max:null,note:d.note||null,cost_per_kg:d.cost_per_kg,added_full:null,last_used:null,encode_time:null,tag_uid:null,tray_uuid:null,data_origin:null,tag_type:null,last_scale_weight:null,last_weighed_at:null,category:d.category.trim()||null,low_stock_threshold_pct:d.low_stock_threshold_pct};x(!0);try{if(_>1){let e=r?await Z.bulkCreateSpoolmanInventorySpools(a,_):await Z.bulkCreateSpools(a,_),n=r&&e&&typeof e==`object`&&`created`in e?e.created:e;for(let e of n)await ve(e.id);n.length>0&&t(n[0])}else{let e=r?await Z.createSpoolmanInventorySpool(a):await Z.createSpool(a);await ve(e.id),t(e)}}catch{C(i(`spoolbuddy.writeTag.createFailed`,`Failed to create spool`))}finally{x(!1)}},be=`#${(d.rgba||`808080FF`).slice(0,6)}`;return(0,G.jsxs)(`div`,{className:`p-3 space-y-3 overflow-y-auto h-full`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-sm text-zinc-200`,children:i(`spoolbuddy.writeTag.viewMode`,`View`)}),(0,G.jsxs)(`div`,{className:`flex rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>c(`simple`),className:`px-3 py-1.5 text-xs font-medium ${s===`simple`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:i(`spoolbuddy.writeTag.simpleView`,`Simple`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>c(`full`),className:`px-3 py-1.5 text-xs font-medium ${s===`full`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:i(`spoolbuddy.writeTag.fullView`,`Full`)})]})]}),s===`simple`?n?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full p-6 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:n.rgba?Tf(n.rgba):{backgroundColor:`#666`}}),(0,G.jsxs)(`p`,{className:`text-white font-medium`,children:[n.brand?`${n.brand} `:``,n.material]}),n.color_name&&(0,G.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:n.color_name}),(0,G.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[n.label_weight,`g`]}),(0,G.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:i(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]}):(0,G.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.material`,`Material`)}),(0,G.jsx)(`select`,{value:d.material,onChange:e=>ge(`material`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,children:m0e.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))})]}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.colorName`,`Color Name`)}),(0,G.jsx)(`input`,{type:`text`,value:d.color_name,onChange:e=>ge(`color_name`,e.target.value),placeholder:`Jade White`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.color`,`Color`)}),(0,G.jsx)(`input`,{type:`color`,value:be,onChange:e=>ge(`rgba`,e.target.value.replace(`#`,``).toUpperCase()+`FF`),className:`w-10 h-9 bg-transparent border border-bambu-dark-tertiary rounded cursor-pointer`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.brand`,`Brand`)}),(0,G.jsx)(`input`,{type:`text`,value:d.brand,onChange:e=>ge(`brand`,e.target.value),placeholder:`Polymaker`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.weight`,`Weight (g)`)}),(0,G.jsx)(`input`,{type:`number`,value:d.label_weight,onChange:e=>ge(`label_weight`,parseInt(e.target.value)||0),min:0,max:1e4,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`})]}),(0,G.jsx)(`button`,{onClick:ye,disabled:b||!d.material,className:`w-full py-2.5 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:b?i(`spoolbuddy.writeTag.creating`,`Creating...`):i(`spoolbuddy.writeTag.createSpool`,`Create Spool`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-sm text-zinc-200`,children:i(`inventory.quickAdd`,`Quick Add`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${h?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(`span`,{className:`inline-block h-4.5 w-4.5 rounded-full bg-white transition-transform ${h?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{className:`flex border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsx)(`button`,{onClick:()=>u(`filament`),className:`flex-1 py-2.5 text-sm font-medium ${l===`filament`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:i(`inventory.filamentInfoTab`,`Filament`)}),!h&&(0,G.jsx)(`button`,{onClick:()=>u(`pa-profile`),className:`flex-1 py-2.5 text-sm font-medium ${l===`pa-profile`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:i(`inventory.paProfileTab`,`PA Profile`)})]}),(0,G.jsx)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-3`,children:l===`filament`?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(KQe,{formData:d,updateField:ge,cloudAuthenticated:w,loadingCloudPresets:E,presetInputValue:R,setPresetInputValue:z,selectedPresetOption:se,filamentOptions:oe,availableBrands:fe,availableMaterials:pe,suggestedBrands:me,suggestedMaterials:he,quickAdd:h,detailsRequired:!h,quantity:_,onQuantityChange:v,errors:p}),(0,G.jsx)(JQe,{formData:d,updateField:ge,recentColors:B,onColorUsed:_e,catalogColors:I}),(0,G.jsx)(XQe,{formData:d,updateField:ge,spoolCatalog:P,currencySymbol:e,availableCategories:Array.from(new Set(a.map(e=>e.category?.trim()).filter(e=>!!e))).sort((e,t)=>e.localeCompare(t)),globalLowStockThreshold:o?.low_stock_threshold??20})]}):(0,G.jsx)(QQe,{formData:d,updateField:ge,printersWithCalibrations:ee,selectedProfiles:ne,setSelectedProfiles:re,expandedPrinters:ie,setExpandedPrinters:ae})})]}),S&&(0,G.jsx)(`div`,{className:`text-sm text-red-400 bg-red-900/20 border border-red-900/40 rounded-lg px-3 py-2`,children:S}),s===`full`&&(0,G.jsx)(`button`,{onClick:ye,disabled:b,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:b?i(`spoolbuddy.writeTag.creating`,`Creating...`):i(`spoolbuddy.writeTag.createSpool`,`Create Spool`)}),s===`full`&&n&&(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-4 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:n.rgba?Tf(n.rgba):{backgroundColor:`#666`}}),(0,G.jsxs)(`p`,{className:`text-white font-medium`,children:[n.brand?`${n.brand} `:``,n.material]}),n.color_name&&(0,G.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:n.color_name}),(0,G.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[n.label_weight,`g`]}),(0,G.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:i(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]})]})}function y0e({writeStatus:e,writeMessage:t,selectedSpool:n,tagOnReader:r,tagUid:i,deviceOnline:a,canWrite:o,isReplace:s,canUntag:c,untagging:l,onWrite:u,onUntag:d,onCancel:f,onRetry:p,t:m}){if(e===`success`)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,G.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-green-500/20 flex items-center justify-center`,children:(0,G.jsx)(`svg`,{className:`w-8 h-8 text-green-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M5 13l4 4L19 7`})})}),(0,G.jsx)(`p`,{className:`text-green-400 font-medium`,children:t}),n&&(0,G.jsxs)(`p`,{className:`text-zinc-400 text-sm`,children:[n.brand?`${n.brand} `:``,n.material,n.color_name?` - ${n.color_name}`:``]})]});if(e===`error`)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,G.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,G.jsx)(`svg`,{className:`w-8 h-8 text-red-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})}),(0,G.jsx)(`p`,{className:`text-red-400 font-medium`,children:t}),(0,G.jsx)(`button`,{onClick:p,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-white text-sm rounded transition-colors`,children:m(`spoolbuddy.writeTag.tryAgain`,`Try Again`)})]});if(e===`writing`)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,G.jsxs)(`div`,{className:`relative w-16 h-16`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-bambu-green/30 animate-ping`}),(0,G.jsx)(`div`,{className:`absolute inset-2 rounded-full border-2 border-bambu-green/50 animate-pulse`}),(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,G.jsx)(Z9,{className:`w-8 h-8 text-bambu-green`})})]}),(0,G.jsx)(`p`,{className:`text-bambu-green font-medium`,children:m(`spoolbuddy.writeTag.writing`,`Writing tag...`)}),(0,G.jsx)(`p`,{className:`text-zinc-500 text-xs`,children:t}),(0,G.jsx)(`button`,{onClick:f,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-zinc-400 text-sm rounded transition-colors`,children:m(`spoolbuddy.writeTag.cancel`,`Cancel`)})]});if(!a)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,G.jsx)(Z9,{className:`w-12 h-12 text-zinc-600`}),(0,G.jsx)(`p`,{className:`text-zinc-500 text-sm`,children:m(`spoolbuddy.writeTag.deviceOffline`,`SpoolBuddy is offline`)})]});if(!n)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,G.jsx)(Z9,{className:`w-12 h-12 text-zinc-600`}),(0,G.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:m(`spoolbuddy.writeTag.selectSpool`,`Select a spool, then place a blank NTAG on the reader`)})]});let h=n.rgba?Tf(n.rgba):{backgroundColor:`#666`};return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4 w-full`,children:[(0,G.jsx)(`div`,{className:`relative w-16 h-16`,children:r?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`absolute inset-0 rounded-full bg-bambu-green/10`}),(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,G.jsx)(Z9,{className:`w-8 h-8 text-bambu-green`})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-zinc-600 animate-pulse`}),(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,G.jsx)(Z9,{className:`w-8 h-8 text-zinc-500`})})]})}),r?(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(`p`,{className:`text-bambu-green text-sm font-medium`,children:m(`spoolbuddy.writeTag.tagReady`,`Tag detected — ready to write`)}),i&&(0,G.jsx)(`p`,{className:`text-zinc-500 text-xs font-mono`,children:i})]}):(0,G.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:m(`spoolbuddy.writeTag.placeTag`,`Place an NTAG on the reader`)}),(0,G.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-3 space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-8 h-8 rounded-full border border-white/10 shrink-0`,style:h}),(0,G.jsxs)(`div`,{className:`text-left min-w-0`,children:[(0,G.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[n.brand?`${n.brand} `:``,n.material]}),n.color_name&&(0,G.jsx)(`p`,{className:`text-zinc-400 text-xs`,children:n.color_name})]})]}),(0,G.jsxs)(`div`,{className:`text-xs text-zinc-500`,children:[n.label_weight,`g`]})]}),s&&n.tag_uid&&(0,G.jsx)(`p`,{className:`text-yellow-500/80 text-xs`,children:m(`spoolbuddy.writeTag.replaceWarning`,`Old tag will be unlinked. New tag will replace it.`)}),(0,G.jsx)(`button`,{onClick:u,disabled:!o,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-40 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors text-sm`,children:s?m(`spoolbuddy.writeTag.replaceTag`,`Replace Tag`):m(`spoolbuddy.writeTag.writeTag`,`Write Tag`)}),s&&c&&(0,G.jsx)(`button`,{onClick:d,disabled:l,className:`w-full py-2.5 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary disabled:opacity-40 disabled:cursor-not-allowed text-zinc-200 rounded-lg transition-colors text-sm`,children:l?m(`spoolbuddy.writeTag.untagging`,`Removing tag...`):m(`spoolbuddy.writeTag.untagSpool`,`Untag Selected Spool`)})]})}function Z9({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,children:[(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0`}),(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z`})]})}var b0e=`spoolbuddy-default-core-weight`;function x0e(){try{let e=localStorage.getItem(b0e);if(e){let t=parseInt(e,10);if(t>=0&&t<=500)return t}}catch{}return 250}function S0e({spool:e,liveScaleWeight:t,persistedGrossWeight:n,onClose:r,onSyncWeight:i,onAssignToAms:a,isAssigned:o,onUnassignFromAms:s,className:c}){let{t:l}=U(),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),{data:g}=K({queryKey:[`spool-k-profiles`,e.id],queryFn:()=>Z.getSpoolKProfiles(e.id),enabled:!e.k_profiles||e.k_profiles.length===0,staleTime:300*1e3}),_=e.k_profiles&&e.k_profiles.length>0?e.k_profiles:g,v=wf(e.rgba),b=e.core_weight&&e.core_weight>0?e.core_weight:x0e(),x=t===null?null:Math.round(Math.max(0,t)),S=m??(n===void 0?x:n===null?null:Math.round(Math.max(0,n))),C=Math.round(Math.max(0,(e.label_weight||0)-(e.weight_used||0))),w=x!==null&&x>=10?Math.round(Math.max(0,x-b)):C,T=Math.round(e.label_weight||1e3),E=T>0?Math.min(100,Math.round(w/T*100)):null,D=E===null?`#808080`:E>50?`#22c55e`:E>20?`#eab308`:`#ef4444`,O=Math.max(0,(e.label_weight||0)-(e.weight_used||0))+b,k=x===null?null:x-O,A=k===null?null:Math.abs(k)<=50,j=S??Math.round(O),M=e.nozzle_temp_min!=null&&e.nozzle_temp_max!=null?`${e.nozzle_temp_min}-${e.nozzle_temp_max}\u00B0C`:null,N=e.slicer_filament_name||e.slicer_filament||null,P=e.note?.trim()||null,F=_&&_.length>0?Array.from(new Set(_.map(e=>e.k_value.toFixed(3)))).join(`, `):null,I=async()=>{if(t===null)return;let n=Math.round(Math.max(0,t));d(!0);try{await Cd.updateSpoolWeight(e.id,n),h(n),p(!0),i?.(),setTimeout(()=>p(!1),3e3)}catch(e){console.error(`Failed to sync weight:`,e)}finally{d(!1)}};return(0,G.jsxs)(`div`,{className:`flex flex-col items-center space-y-4 max-w-md ${c??``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-5`,children:[(0,G.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,G.jsx)(G9,{color:v,isEmpty:!1,size:100}),E!==null&&(0,G.jsxs)(`div`,{className:`absolute -bottom-2 -right-2 px-2 py-0.5 rounded-full text-xs font-bold text-white shadow-lg`,style:{backgroundColor:D},children:[E,`%`]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:e.color_name||`Unknown color`}),(0,G.jsxs)(`span`,{className:`text-xs font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,G.jsxs)(`p`,{className:`text-sm text-zinc-400`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]}),(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-3xl font-bold font-mono text-zinc-100`,children:[w,`g`]}),(0,G.jsxs)(`span`,{className:`text-sm text-zinc-500`,children:[`/ `,T,`g`]})]}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mt-0.5`,children:l(`spoolbuddy.spool.remaining`,`Remaining`)}),(0,G.jsx)(`div`,{className:`mt-2 max-w-xs`,children:(0,G.jsx)(`div`,{className:`h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500`,style:{width:`${E??0}%`,backgroundColor:D}})})})]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-2 text-sm bg-zinc-800 rounded-lg p-4 w-full`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.grossWeight`,`Gross weight`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[j,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.spool.coreWeight`,`Core`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[b,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.spoolSize`,`Spool size`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[T,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.spool.scaleWeight`,`Scale`)}),x===null?(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`—`}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 font-mono ${A?`text-green-500`:`text-yellow-500`}`,children:[x,`g`,A?(0,G.jsx)(ds,{className:`w-3.5 h-3.5`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Iu,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`button`,{onClick:I,className:`p-1 hover:bg-green-500/20 rounded transition-colors text-green-500`,title:l(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`),children:(0,G.jsx)(Vl,{className:`w-4 h-4`})})]})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.tagId`,`Tag`)}),(0,G.jsx)(`span`,{className:`font-mono text-xs text-zinc-400 truncate max-w-[120px]`,title:e.tag_uid||``,children:e.tag_uid?e.tag_uid.slice(-8):`—`})]}),M&&(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.inventory.nozzleTemp`,`Nozzle`)}),(0,G.jsx)(`span`,{className:`font-mono text-zinc-300`,children:M})]}),e.cost_per_kg!=null&&e.cost_per_kg>0&&(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.inventory.costPerKg`,`Cost/kg`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[e.cost_per_kg.toFixed(2),`/kg`]})]}),F&&(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.inventory.kProfiles`,`K-Profile`)}),(0,G.jsx)(`span`,{className:`font-mono text-zinc-300 truncate max-w-[220px] text-right`,title:F,children:F})]}),N&&(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mb-1`,children:l(`spoolbuddy.inventory.slicerFilament`,`Slicer Filament`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-300 whitespace-pre-wrap break-words`,children:N})]}),P&&(0,G.jsxs)(`div`,{className:`col-span-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mb-1`,children:l(`spoolbuddy.inventory.note`,`Note`)}),(0,G.jsx)(`p`,{className:`text-sm leading-5 text-zinc-300 whitespace-pre-wrap break-words max-h-[3.75rem] overflow-y-auto pr-1`,children:P})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[a&&(0,G.jsx)(`button`,{onClick:o?void 0:a,disabled:!!o,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px] disabled:opacity-50 disabled:cursor-not-allowed`,children:l(`spoolbuddy.modal.assignToAms`,`Assign to AMS`)}),s&&(0,G.jsxs)(`button`,{onClick:s,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-red-600/20 text-red-400 hover:bg-red-600/30 transition-colors min-h-[44px]`,children:[(0,G.jsx)(zu,{className:`w-4 h-4 inline mr-1`}),l(`inventory.unassignSpool`)]}),(0,G.jsx)(`button`,{onClick:I,disabled:t===null||u,className:`px-5 py-2.5 rounded-lg text-sm font-medium transition-colors min-h-[44px] ${f?`bg-green-600/20 text-green-400`:a?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600 disabled:opacity-40 disabled:cursor-not-allowed`:`bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed`}`,children:u?`...`:f?l(`spoolbuddy.dashboard.weightSynced`,`Synced!`):l(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`)}),r&&(0,G.jsx)(`button`,{onClick:r,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:l(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function C0e(e){return wf(e.rgba)}function w0e(e){return Math.max(0,e.label_weight-e.weight_used)}function T0e(e){return e.label_weight<=0?0:Math.max(0,Math.min(100,(e.label_weight-e.weight_used)/e.label_weight*100))}function E0e(e){let t=[e.material];return e.subtype&&t.push(e.subtype),t.join(` `)}function D0e(e){let t=e.ams_id===254||e.ams_id===255,n=!t&&e.ams_id>=128;return wp(e.ams_id,e.tray_id,n,t)}function O0e({color:e,size:t=56}){return(0,G.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 56 56`,children:[(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:e}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:e,style:{filter:`brightness(0.85)`}}),(0,G.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]})}function k0e(){let{sbState:e,selectedPrinterId:t}=lr(),{t:n}=U(),{showToast:r}=Hd(),i=co(),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`all`),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(!1),{data:p}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,staleTime:300*1e3}),m=p?.spoolman_enabled===`true`&&!!p?.spoolman_url,{data:h=[],isLoading:g,refetch:_}=K({queryKey:m?[`spoolman-inventory-spools`]:[`inventory-spools`],queryFn:()=>m?Z.getSpoolmanInventorySpools(!1):Z.getSpools(!1),enabled:p!==void 0,refetchInterval:3e4}),{data:v=[]}=K({queryKey:[`spool-assignments`],queryFn:()=>Z.getAssignments(),refetchInterval:3e4,enabled:!m}),{data:b=[]}=K({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Z.getSpoolmanSlotAssignments(),refetchInterval:3e4,enabled:m}),x=q({mutationFn:e=>Z.unassignSpoolmanSlot(e),onSuccess:()=>{i.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),i.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},onError:()=>r(n(`inventory.unassignFailed`,`Failed to unassign spool`),`error`)}),S=(0,y.useMemo)(()=>{if(m){let e={};return b.forEach(t=>{e[t.spoolman_spool_id]={ams_id:t.ams_id,tray_id:t.tray_id}}),e}let e={};return v.forEach(t=>{e[t.spool_id]={ams_id:t.ams_id,tray_id:t.tray_id,printer_name:t.printer_name}}),e},[m,v,b]),C=(0,y.useMemo)(()=>h.filter(e=>!e.archived_at),[h]),w=(0,y.useMemo)(()=>new Set(Object.keys(S).map(Number)),[S]),T=(0,y.useMemo)(()=>C.filter(e=>w.has(e.id)).length,[C,w]),E=(0,y.useMemo)(()=>{let e=new Set;return C.forEach(t=>e.add(t.material)),Array.from(e).sort()},[C]),D=(0,y.useMemo)(()=>{let e=C;return s===`in_ams`?e=e.filter(e=>w.has(e.id)):s!==`all`&&(e=e.filter(e=>e.material===s)),e=JH(e,a.trim()),[...e].sort((e,t)=>{let n=+!w.has(e.id),r=+!w.has(t.id);return n===r?new Date(t.updated_at).getTime()-new Date(e.updated_at).getTime():n-r})},[C,s,a,w]);return(0,G.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`px-3 pt-3 pb-2 space-y-2.5`,children:[(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Zl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-white/40`}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:n(`spoolbuddy.inventory.searchPlaceholder`,`Search spools...`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-white/30 focus:outline-none focus:border-bambu-green`}),a&&(0,G.jsx)(`button`,{onClick:()=>o(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-white/40 hover:text-white/60`,children:(0,G.jsx)(td,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-1.5 overflow-x-auto no-scrollbar`,children:[(0,G.jsx)(Q9,{active:s===`all`,onClick:()=>c(`all`),label:`${n(`spoolbuddy.inventory.all`,`All`)} (${C.length})`,green:!0}),T>0&&(0,G.jsx)(Q9,{active:s===`in_ams`,onClick:()=>c(`in_ams`),label:`${n(`spoolbuddy.inventory.inAms`,`In AMS`)} (${T})`}),E.map(e=>(0,G.jsx)(Q9,{active:s===e,onClick:()=>c(s===e?`all`:e),label:e},e))]})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 pb-3`,children:g?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(`div`,{className:`w-8 h-8 border-2 border-bambu-green border-t-transparent rounded-full animate-spin`})}):D.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-white/30`,children:[(0,G.jsx)(Sl,{className:`w-12 h-12 mb-3`}),(0,G.jsx)(`p`,{className:`text-sm`,children:a||s!==`all`?n(`spoolbuddy.inventory.noResults`,`No spools match your filters`):n(`spoolbuddy.inventory.empty`,`No spools in inventory`)})]}):(0,G.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(130px,1fr))] gap-2`,children:D.map(e=>(0,G.jsx)(A0e,{spool:e,assignment:S[e.id],onClick:()=>u(e.id)},e.id))})}),l!=null&&(()=>{let n=h.find(e=>e.id===l);return n?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(j0e,{spool:n,assignment:S[n.id],sbState:e,onSyncWeight:()=>{_()},onAssignToAms:()=>f(!0),onUnassignFromAms:m&&S[n.id]?()=>x.mutate(n.id):void 0,onClose:()=>{u(null),f(!1)}}),(0,G.jsx)(V1e,{isOpen:d,onClose:()=>f(!1),spool:n,printerId:t,spoolmanMode:m})]}):null})()]})}function Q9({active:e,onClick:t,label:n,green:r}){return(0,G.jsx)(`button`,{onClick:t,className:`px-4 py-1.5 rounded-full text-sm font-medium border whitespace-nowrap shrink-0 transition-colors ${e?r?`bg-bambu-green/20 text-bambu-green border-bambu-green/50`:`bg-white/10 text-white border-white/20`:`bg-transparent text-white/40 border-bambu-dark-tertiary hover:text-white/60`}`,children:n})}function A0e({spool:e,assignment:t,onClick:n}){let r=C0e(e),i=T0e(e),a=w0e(e),o=Cf(e.color_name,e.rgba);return(0,G.jsxs)(`button`,{onClick:n,className:`bg-bambu-dark-secondary rounded-xl p-3 flex flex-col items-center text-center gap-1.5 border border-transparent hover:border-bambu-green/50 transition-colors`,children:[(0,G.jsx)(O0e,{color:r,size:56}),(0,G.jsx)(`p`,{className:`text-xs font-semibold text-white leading-tight truncate w-full`,children:E0e(e)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 max-w-full`,children:[(0,G.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full shrink-0 border border-white/10`,style:Tf(e.rgba)}),(0,G.jsx)(`span`,{className:`text-[11px] text-white/50 truncate`,children:o||`-`})]}),(0,G.jsxs)(`div`,{className:`w-full space-y-0.5`,children:[(0,G.jsx)(`div`,{className:`h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full ${i>50?`bg-bambu-green`:i>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(i,100)}%`}})}),(0,G.jsxs)(`p`,{className:`text-[11px] text-white/40`,children:[Math.round(a),`g (`,Math.round(i),`%)`]})]}),t&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded text-[10px] font-bold bg-bambu-green/20 text-bambu-green`,children:D0e(t)})]})}function j0e({spool:e,assignment:t,sbState:n,onSyncWeight:r,onAssignToAms:i,onUnassignFromAms:a,onClose:o}){let s=n.deviceOnline&&n.weight!==null?Math.round(n.weight):null,c=e.last_scale_weight==null?null:Math.round(e.last_scale_weight);return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/70 flex items-center justify-center p-4`,onClick:o,children:(0,G.jsx)(`div`,{className:`w-full max-w-md bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-2xl p-4 overflow-y-auto max-h-[90vh]`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[t&&(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,G.jsx)(`span`,{className:`px-2.5 py-1 rounded-md text-xs font-bold bg-bambu-green/20 text-bambu-green`,children:D0e(t)}),t.printer_name&&(0,G.jsx)(`span`,{className:`text-xs text-zinc-400`,children:t.printer_name})]}),(0,G.jsx)(`div`,{className:`flex justify-center`,children:(0,G.jsx)(S0e,{spool:e,liveScaleWeight:s,persistedGrossWeight:c,onSyncWeight:r,onAssignToAms:i,isAssigned:!!t,onUnassignFromAms:a,onClose:o,className:`max-w-md`})})]})})})}var M0e=class extends y.Component{state={error:null,errorInfo:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){this.setState({errorInfo:t}),console.error(`React crash:`,e,t)}render(){return this.state.error?(0,G.jsxs)(`div`,{style:{padding:24,color:`#ef4444`,backgroundColor:`#18181b`,minHeight:`100vh`,fontFamily:`monospace`},children:[(0,G.jsx)(`h1`,{style:{fontSize:20,marginBottom:12},children:`UI Crash`}),(0,G.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,fontSize:14},children:this.state.error.message}),(0,G.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,fontSize:12,color:`#a1a1aa`,marginTop:12},children:this.state.error.stack}),(0,G.jsx)(`button`,{onClick:()=>{this.setState({error:null,errorInfo:null})},style:{marginTop:16,padding:`8px 16px`,backgroundColor:`#3b82f6`,color:`#fff`,border:`none`,borderRadius:8,cursor:`pointer`},children:`Retry`})]}):this.props.children}},N0e=new ao({defaultOptions:{queries:{staleTime:1e3*60,retry:1}}});function P0e(){return rQe(),null}function F0e({children:e}){return $$e(),i1e(),(0,G.jsx)(G.Fragment,{children:e})}function I0e({children:e}){let{authEnabled:t,loading:n,user:r}=Od(),i=rr();return n?(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):t&&!r?(0,G.jsx)(Fr,{to:`/login`,replace:!0,state:{from:i}}):(0,G.jsx)(G.Fragment,{children:e})}function $9({permission:e,children:t}){let{authEnabled:n,loading:r,user:i,hasPermission:a}=Od(),o=rr();return r?(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):n?i?a(e)?(0,G.jsx)(G.Fragment,{children:t}):(0,G.jsx)(Fr,{to:`/`,replace:!0}):(0,G.jsx)(Fr,{to:`/login`,replace:!0,state:{from:o}}):(0,G.jsx)(G.Fragment,{children:t})}function L0e({children:e}){let{authEnabled:t,loading:n}=Od();return n?(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):t?(0,G.jsx)(Fr,{to:`/login`,replace:!0}):(0,G.jsx)(G.Fragment,{children:e})}function R0e(){return(0,G.jsx)(M0e,{children:(0,G.jsx)(Qd,{children:(0,G.jsx)(lo,{client:N0e,children:(0,G.jsx)(Dd,{children:(0,G.jsx)(Ad,{children:(0,G.jsx)(a1e,{children:(0,G.jsxs)(jke,{children:[(0,G.jsx)(P0e,{}),(0,G.jsx)(Oi,{children:(0,G.jsxs)(zr,{children:[(0,G.jsx)(Lr,{path:`/setup`,element:(0,G.jsx)(L0e,{children:(0,G.jsx)(Y$e,{})})}),(0,G.jsx)(Lr,{path:`/login`,element:(0,G.jsx)(J$e,{})}),(0,G.jsx)(Lr,{path:`/camera/:printerId`,element:(0,G.jsx)(sQe,{})}),(0,G.jsx)(Lr,{path:`/overlay/:printerId`,element:(0,G.jsx)(CQe,{})}),(0,G.jsx)(Lr,{path:`/camwall`,element:(0,G.jsx)(_Qe,{})}),(0,G.jsxs)(Lr,{element:(0,G.jsx)(I0e,{children:(0,G.jsx)(F0e,{children:(0,G.jsx)(y1e,{})})}),children:[(0,G.jsx)(Lr,{path:`spoolbuddy`,element:(0,G.jsx)(J1e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/ams`,element:(0,G.jsx)(Q1e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/write-tag`,element:(0,G.jsx)(h0e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/inventory`,element:(0,G.jsx)(k0e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/settings`,element:(0,G.jsx)(d0e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/calibration`,element:(0,G.jsx)(p0e,{})})]}),(0,G.jsxs)(Lr,{element:(0,G.jsx)(I0e,{children:(0,G.jsx)(F0e,{children:(0,G.jsx)(mee,{})})}),children:[(0,G.jsx)(Lr,{index:!0,element:(0,G.jsx)(Eke,{})}),(0,G.jsx)(Lr,{path:`archives`,element:(0,G.jsx)(wze,{})}),(0,G.jsx)(Lr,{path:`queue`,element:(0,G.jsx)(jVe,{})}),(0,G.jsx)(Lr,{path:`pipelines/runs`,element:(0,G.jsx)(Fr,{to:`/queue?tab=pipelines`,replace:!0})}),(0,G.jsx)(Lr,{path:`stats`,element:(0,G.jsx)(XVe,{})}),(0,G.jsx)(Lr,{path:`profiles`,element:(0,G.jsx)(rWe,{})}),(0,G.jsx)(Lr,{path:`finance`,element:(0,G.jsx)($9,{permission:`cost_centers:read_own`,children:(0,G.jsx)(IUe,{})})}),(0,G.jsx)(Lr,{path:`maintenance`,element:(0,G.jsx)(cWe,{})}),(0,G.jsx)(Lr,{path:`projects`,element:(0,G.jsx)(dWe,{})}),(0,G.jsx)(Lr,{path:`projects/:id`,element:(0,G.jsx)(hWe,{})}),(0,G.jsx)(Lr,{path:`inventory`,element:(0,G.jsx)(T$e,{})}),(0,G.jsx)(Lr,{path:`files`,element:(0,G.jsx)(QZe,{})}),(0,G.jsx)(Lr,{path:`files/trash`,element:(0,G.jsx)(tQe,{})}),(0,G.jsx)(Lr,{path:`makerworld`,element:(0,G.jsx)($9,{permission:`makerworld:view`,children:(0,G.jsx)(L$e,{})})}),(0,G.jsx)(Lr,{path:`settings`,element:(0,G.jsx)($9,{permission:`settings:read`,children:(0,G.jsx)(MUe,{})})}),(0,G.jsx)(Lr,{path:`groups/new`,element:(0,G.jsx)($9,{permission:`groups:create`,children:(0,G.jsx)(TQe,{})})}),(0,G.jsx)(Lr,{path:`groups/:id/edit`,element:(0,G.jsx)($9,{permission:`groups:update`,children:(0,G.jsx)(TQe,{})})}),(0,G.jsx)(Lr,{path:`users`,element:(0,G.jsx)(Fr,{to:`/settings?tab=users`,replace:!0})}),(0,G.jsx)(Lr,{path:`groups`,element:(0,G.jsx)(Fr,{to:`/settings?tab=users`,replace:!0})}),(0,G.jsx)(Lr,{path:`system`,element:(0,G.jsx)(U$e,{})}),(0,G.jsx)(Lr,{path:`notifications`,element:(0,G.jsx)(X$e,{})}),(0,G.jsx)(Lr,{path:`gcode-viewer`,element:(0,G.jsx)(Z$e,{})}),(0,G.jsx)(Lr,{path:`external/:id`,element:(0,G.jsx)(wQe,{})}),(0,G.jsx)(Lr,{path:`camera-tokens`,element:(0,G.jsx)(Fr,{to:`/settings?tab=apikeys#card-camera-tokens`,replace:!0})})]})]})})]})})})})})})})}(0,b.createRoot)(document.getElementById(`root`)).render((0,G.jsx)(y.StrictMode,{children:(0,G.jsx)(R0e,{})})); \ No newline at end of file +In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}()}function w(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n1&&arguments[1]!==void 0?arguments[1]:e;this.caretPosition=e,this.caretPositionEnd=t}},{key:`getInputCandidates`,value:function(e){var t=this,n=this.options,r=n.layoutCandidates,i=n.layoutCandidatesCaseSensitiveMatch;if(!r||T(r)!==`object`)return{};var a=Object.keys(r).filter((function(n){var r=e.substring(0,t.getCaretPositionEnd()||0)||e,a=RegExp(`${t.utilities.escapeRegex(n)}\$`,i?`g`:`gi`);return!!C(r.matchAll(a)).length}));if(a.length>1){var o=a.sort((function(e,t){return t.length-e.length}))[0];return{candidateKey:o,candidateValue:r[o]}}if(a.length){var s=a[0];return{candidateKey:s,candidateValue:r[s]}}return{}}},{key:`showCandidatesBox`,value:function(e,t,n){var r=this;this.candidateBox&&this.candidateBox.show({candidateValue:t,targetElement:n,onSelect:function(t,n){var i=r.options,a=i.layoutCandidatesCaseSensitiveMatch,o=i.disableCandidateNormalization,s=i.enableLayoutCandidatesKeyPress,c=t;o||(c=t.normalize(`NFD`)),typeof r.options.beforeInputUpdate==`function`&&r.options.beforeInputUpdate(r);var l=r.getInput(r.options.inputName,!0),u=r.getCaretPositionEnd()||0,d=l.substring(0,u||0)||l,f=RegExp(`${r.utilities.escapeRegex(e)}\$`,a?`g`:`gi`),p=d.replace(f,c),m=l.replace(d,p),h=p.length-d.length,g=(u||l.length)+h;g<0&&(g=0),r.setInput(m,r.options.inputName,!0),r.setCaretPosition(g),s&&typeof r.options.onKeyPress==`function`&&r.options.onKeyPress(t,n),typeof r.options.onChange==`function`&&r.options.onChange(r.getInput(r.options.inputName,!0),n),typeof r.options.onChangeAll==`function`&&r.options.onChangeAll(r.getAllInputs(),n)}})}},{key:`handleButtonClicked`,value:function(e,t){var n=this.options,r=n.inputName,i=r===void 0?this.defaultName:r,a=n.debug;if(e!==`{//}`){this.input[i]||(this.input[i]=``),typeof this.options.beforeInputUpdate==`function`&&this.options.beforeInputUpdate(this);var o=this.utilities.getUpdatedInput(e,this.input[i],this.caretPosition,this.caretPositionEnd);if(this.utilities.isStandardButton(e)&&this.activeInputElement&&this.input[i]&&this.input[i]===o&&this.caretPosition===0&&this.caretPositionEnd===o.length)return this.setInput(``,this.options.inputName,!0),this.setCaretPosition(0),this.activeInputElement.value=``,this.activeInputElement.setSelectionRange(0,0),void this.handleButtonClicked(e,t);if(typeof this.options.onKeyPress==`function`&&this.options.onKeyPress(e,t),this.input[i]!==o&&(!this.options.inputPattern||this.options.inputPattern&&this.inputPatternIsValid(o))){if(this.options.maxLength&&this.utilities.handleMaxLength(this.input,o))return;var s=this.utilities.getUpdatedInput(e,this.input[i],this.caretPosition,this.caretPositionEnd,!0);if(this.setInput(s,this.options.inputName,!0),a&&console.log(`Input changed:`,this.getAllInputs()),this.options.debug&&console.log(`Caret at: `,this.getCaretPosition(),this.getCaretPositionEnd(),`(${this.keyboardDOMClass})`,t?.type),this.options.syncInstanceInputs&&this.syncInstanceInputs(),typeof this.options.onChange==`function`&&this.options.onChange(this.getInput(this.options.inputName,!0),t),typeof this.options.onChangeAll==`function`&&this.options.onChangeAll(this.getAllInputs(),t),t!=null&&t.target&&this.options.enableLayoutCandidates){var c,l=this.getInputCandidates(o),u=l.candidateKey,d=l.candidateValue;u&&d?this.showCandidatesBox(u,d,this.keyboardDOM):(c=this.candidateBox)==null||c.destroy()}}this.caretPositionEnd&&this.caretPosition!==this.caretPositionEnd&&(this.setCaretPosition(this.caretPositionEnd,this.caretPositionEnd),this.activeInputElement&&this.activeInputElement.setSelectionRange(this.caretPositionEnd,this.caretPositionEnd),this.options.debug&&console.log(`Caret position aligned`,this.caretPosition)),a&&console.log(`Key pressed:`,e)}}},{key:`getMouseHold`,value:function(){return this.isMouseHold}},{key:`setMouseHold`,value:function(e){this.options.syncInstanceInputs?this.dispatch((function(t){t.isMouseHold=e})):this.isMouseHold=e}},{key:`handleButtonMouseDown`,value:function(e,t){var n=this;t&&(this.options.preventMouseDownDefault&&t.preventDefault(),this.options.stopMouseDownPropagation&&t.stopPropagation(),t.target.classList.add(this.activeButtonClass)),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdTimeout&&clearTimeout(this.holdTimeout),this.setMouseHold(!0),this.options.disableButtonHold||(this.holdTimeout=window.setTimeout((function(){(n.getMouseHold()&&(!e.includes(`{`)&&!e.includes(`}`)||e===`{delete}`||e===`{backspace}`||e===`{bksp}`||e===`{space}`||e===`{tab}`)||e===`{arrowright}`||e===`{arrowleft}`||e===`{arrowup}`||e===`{arrowdown}`)&&(n.options.debug&&console.log(`Button held:`,e),n.handleButtonHold(e)),clearTimeout(n.holdTimeout)}),500))}},{key:`handleButtonMouseUp`,value:function(e,t){var n=this;t&&(this.options.preventMouseUpDefault&&t.preventDefault&&t.preventDefault(),this.options.stopMouseUpPropagation&&t.stopPropagation&&t.stopPropagation(),!(t.target===this.keyboardDOM||t.target&&this.keyboardDOM.contains(t.target)||this.candidateBox&&this.candidateBox.candidateBoxElement&&(t.target===this.candidateBox.candidateBoxElement||t.target&&this.candidateBox.candidateBoxElement.contains(t.target)))&&this.candidateBox&&this.candidateBox.destroy()),this.recurseButtons((function(e){e.classList.remove(n.activeButtonClass)})),this.setMouseHold(!1),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),e&&typeof this.options.onKeyReleased==`function`&&this.options.onKeyReleased(e,t)}},{key:`handleKeyboardContainerMouseDown`,value:function(e){this.options.preventMouseDownDefault&&e.preventDefault()}},{key:`handleButtonHold`,value:function(e){var t=this;this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdInteractionTimeout=window.setTimeout((function(){t.getMouseHold()?(t.handleButtonClicked(e),t.handleButtonHold(e)):clearTimeout(t.holdInteractionTimeout)}),100)}},{key:`syncInstanceInputs`,value:function(){var e=this;this.dispatch((function(t){t.replaceInput(e.input),t.setCaretPosition(e.caretPosition,e.caretPositionEnd)}))}},{key:`clearInput`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName;this.input[e]=``,this.setCaretPosition(0),this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:`getInput`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName,t=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return this.options.syncInstanceInputs&&!t&&this.syncInstanceInputs(),this.options.rtl?`‫`+this.input[e].replace(`‫`,``).replace(`‬`,``)+`‬`:this.input[e]}},{key:`getAllInputs`,value:function(){var e=this,t={};return Object.keys(this.input).forEach((function(n){t[n]=e.getInput(n,!0)})),t}},{key:`setInput`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.options.inputName||this.defaultName,n=arguments.length>2?arguments[2]:void 0;this.input[t]=e,!n&&this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:`replaceInput`,value:function(e){this.input=e}},{key:`setOptions`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=this.changedOptions(e);this.options=Object.assign(this.options,e),t.length&&(this.options.debug&&console.log(`changedOptions`,t),this.onSetOptions(t),this.render())}},{key:`changedOptions`,value:function(e){var t=this;return Object.keys(e).filter((function(n){return JSON.stringify(e[n])!==JSON.stringify(t.options[n])}))}},{key:`onSetOptions`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];e.includes(`layoutName`)&&this.candidateBox&&this.candidateBox.destroy(),(e.includes(`layoutCandidatesPageSize`)||e.includes(`layoutCandidates`))&&this.candidateBox&&(this.candidateBox.destroy(),this.candidateBox=new S({utilities:this.utilities,options:this.options}))}},{key:`resetRows`,value:function(){this.keyboardRowsDOM&&this.keyboardRowsDOM.remove(),this.keyboardDOM.className=this.keyboardDOMClass,this.keyboardDOM.setAttribute(`data-skInstance`,this.currentInstanceName),this.buttonElements={}}},{key:`dispatch`,value:function(e){if(!window.SimpleKeyboardInstances)throw console.warn(`SimpleKeyboardInstances is not defined. Dispatch cannot be called.`),Error(`INSTANCES_VAR_ERROR`);return Object.keys(window.SimpleKeyboardInstances).forEach((function(t){e(window.SimpleKeyboardInstances[t],t)}))}},{key:`addButtonTheme`,value:function(e,t){var n=this;t&&e&&(e.split(` `).forEach((function(r){t.split(` `).forEach((function(t){n.options.buttonTheme||(n.options.buttonTheme=[]);var i=!1;n.options.buttonTheme.map((function(e){if(e!=null&&e.class.split(` `).includes(t)){i=!0;var n=e.buttons.split(` `);n.includes(r)||(i=!0,n.push(r),e.buttons=n.join(` `))}return e})),i||n.options.buttonTheme.push({class:t,buttons:e})}))})),this.render())}},{key:`removeButtonTheme`,value:function(e,t){var n=this;if(!e&&!t)return this.options.buttonTheme=[],void this.render();e&&Array.isArray(this.options.buttonTheme)&&this.options.buttonTheme.length&&(e.split(` `).forEach((function(e){var r;(r=n.options)==null||(r=r.buttonTheme)==null||r.map((function(r,i){if(r&&t&&t.includes(r.class)||!t){var a,o=r?.buttons.split(` `).filter((function(t){return t!==e}));r&&o!=null&&o.length?r.buttons=o.join(` `):((a=n.options.buttonTheme)==null||a.splice(i,1),r=null)}return r}))})),this.render())}},{key:`getButtonElement`,value:function(e){var t,n=this.buttonElements[e];return n&&(t=n.length>1?n:n[0]),t}},{key:`inputPatternIsValid`,value:function(e){var t,n=this.options.inputPattern;if((t=n instanceof RegExp?n:n[this.options.inputName||this.defaultName])&&e){var r=t.test(e);return this.options.debug&&console.log(`inputPattern ("${t}"): ${r?`passed`:`did not pass!`}`),r}return!0}},{key:`setEventListeners`,value:function(){if(this.isFirstKeyboardInstance||!this.allKeyboardInstances){this.options.debug&&console.log(`Caret handling started (${this.keyboardDOMClass})`);var e=this.options.physicalKeyboardHighlightPreventDefault,t=e!==void 0&&e;document.addEventListener(`keyup`,this.handleKeyUp,t),document.addEventListener(`keydown`,this.handleKeyDown,t),document.addEventListener(`mouseup`,this.handleMouseUp),document.addEventListener(`touchend`,this.handleTouchEnd),this.options.updateCaretOnSelectionChange&&document.addEventListener(`selectionchange`,this.handleSelectionChange),document.addEventListener(`select`,this.handleSelect)}}},{key:`handleKeyUp`,value:function(e){this.caretEventHandler(e),this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyUp(e)}},{key:`handleKeyDown`,value:function(e){this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyDown(e)}},{key:`handleMouseUp`,value:function(e){this.caretEventHandler(e)}},{key:`handleTouchEnd`,value:function(e){this.caretEventHandler(e)}},{key:`handleSelect`,value:function(e){this.caretEventHandler(e)}},{key:`handleSelectionChange`,value:function(e){navigator.userAgent.includes(`Firefox`)||this.caretEventHandler(e)}},{key:`caretEventHandler`,value:function(e){var t,n=this;e.target.tagName&&(t=e.target.tagName.toLowerCase()),this.dispatch((function(r){var i=e.target===r.keyboardDOM||e.target&&r.keyboardDOM.contains(e.target);if(n.options.syncInstanceInputs&&Array.isArray(e.path)&&(i=e.path.some((function(e){var t;return e==null||(t=e.hasAttribute)==null?void 0:t.call(e,`data-skInstance`)}))),(t===`textarea`||t===`input`&&[`text`,`search`,`url`,`tel`,`password`].includes(e.target.type))&&!r.options.disableCaretPositioning){var a=e.target.selectionStart,o=e.target.selectionEnd;r.options.rtl&&(a=r.utilities.getRtlOffset(a,r.getInput()),o=r.utilities.getRtlOffset(o,r.getInput())),r.setCaretPosition(a,o),r.activeInputElement=e.target,r.options.debug&&console.log(`Caret at: `,r.getCaretPosition(),r.getCaretPositionEnd(),e&&e.target.tagName.toLowerCase(),`(${r.keyboardDOMClass})`,e?.type)}else !r.options.disableCaretPositioning&&i||e?.type===`selectionchange`||(r.setCaretPosition(null),r.activeInputElement=null,r.options.debug&&console.log(`Caret position reset due to "${e?.type}" event`,e))}))}},{key:`recurseButtons`,value:function(e){var t=this;e&&Object.keys(this.buttonElements).forEach((function(n){return t.buttonElements[n].forEach(e)}))}},{key:`destroy`,value:function(){this.options.debug&&console.log(`Destroying simple-keyboard instance: ${this.currentInstanceName}`);var e=this.options.physicalKeyboardHighlightPreventDefault,t=e!==void 0&&e;document.removeEventListener(`keyup`,this.handleKeyUp,t),document.removeEventListener(`keydown`,this.handleKeyDown,t),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`touchend`,this.handleTouchEnd),document.removeEventListener(`select`,this.handleSelect),this.options.updateCaretOnSelectionChange&&document.removeEventListener(`selectionchange`,this.handleSelectionChange),document.onpointerup=null,document.ontouchend=null,document.ontouchcancel=null,document.onmouseup=null,this.recurseButtons((function(e){e&&=(e.onpointerdown=null,e.onpointerup=null,e.onpointercancel=null,e.ontouchstart=null,e.ontouchend=null,e.ontouchcancel=null,e.onclick=null,e.onmousedown=null,e.onmouseup=null,e.remove(),null)})),this.keyboardDOM.onpointerdown=null,this.keyboardDOM.ontouchstart=null,this.keyboardDOM.onmousedown=null,this.resetRows(),this.candidateBox&&=(this.candidateBox.destroy(),null),this.activeInputElement=null,this.keyboardDOM.removeAttribute(`data-skInstance`),this.keyboardDOM.innerHTML=``,window.SimpleKeyboardInstances[this.currentInstanceName]=null,delete window.SimpleKeyboardInstances[this.currentInstanceName],this.initialized=!1}},{key:`getButtonThemeClasses`,value:function(e){var t=this.options.buttonTheme,n=[];return Array.isArray(t)&&t.forEach((function(t){if(t&&t.class&&typeof t.class==`string`&&t.buttons&&typeof t.buttons==`string`){var r=t.class.split(` `);t.buttons.split(` `).includes(e)&&(n=[].concat(C(n),C(r)))}else console.warn(`Incorrect "buttonTheme". Please check the documentation.`,t)})),n}},{key:`setDOMButtonAttributes`,value:function(e,t){var n=this.options.buttonAttributes;Array.isArray(n)&&n.forEach((function(n){n.attribute&&typeof n.attribute==`string`&&n.value&&typeof n.value==`string`?n.buttons&&typeof n.buttons==`string`?n.buttons.split(` `).includes(e)&&t(n.attribute,n.value):t(n.attribute,n.value):console.warn(`Incorrect "buttonAttributes". Please check the documentation.`,n)}))}},{key:`onTouchDeviceDetected`,value:function(){this.processAutoTouchEvents(),this.disableContextualWindow()}},{key:`disableContextualWindow`,value:function(){window.oncontextmenu=function(e){var t;if((t=e.target.classList)!=null&&t.contains(`hg-button`))return e.preventDefault(),e.stopPropagation(),!1}}},{key:`processAutoTouchEvents`,value:function(){this.options.autoUseTouchEvents&&(this.options.useTouchEvents=!0,this.options.debug&&console.log(`autoUseTouchEvents: Touch device detected, useTouchEvents enabled.`))}},{key:`onInit`,value:function(){this.options.debug&&console.log(`${this.keyboardDOMClass} Initialized`),this.setEventListeners(),typeof this.options.onInit==`function`&&this.options.onInit(this)}},{key:`beforeFirstRender`,value:function(){this.utilities.isTouchDevice()&&this.onTouchDeviceDetected(),typeof this.options.beforeFirstRender==`function`&&this.options.beforeFirstRender(this),this.isFirstKeyboardInstance&&this.utilities.pointerEventsSupported()&&!this.options.useTouchEvents&&!this.options.useMouseEvents&&this.options.debug&&console.log(`Using PointerEvents as it is supported by this browser`),this.options.useTouchEvents&&this.options.debug&&console.log(`useTouchEvents has been enabled. Only touch events will be used.`)}},{key:`beforeRender`,value:function(){typeof this.options.beforeRender==`function`&&this.options.beforeRender(this)}},{key:`onRender`,value:function(){typeof this.options.onRender==`function`&&this.options.onRender(this)}},{key:`onModulesLoaded`,value:function(){typeof this.options.onModulesLoaded==`function`&&this.options.onModulesLoaded(this)}},{key:`loadModules`,value:function(){var e=this;Array.isArray(this.options.modules)&&(this.options.modules.forEach((function(t){var n=e.utilities.isConstructor(t)?new t(e):t(e);n.init&&n.init(e)})),this.keyboardPluginClasses=`modules-loaded`,this.render(),this.onModulesLoaded())}},{key:`getModuleProp`,value:function(e,t){return!!this.modules[e]&&this.modules[e][t]}},{key:`getModulesList`,value:function(){return Object.keys(this.modules)}},{key:`parseRowDOMContainers`,value:function(e,t,n,r){var i=this,a=Array.from(e.children),o=0;return a.length&&n.forEach((function(n,s){var c=r[s];if(!(c&&c>n))return!1;var l=n-o,u=c-o,d=document.createElement(`div`);d.className+=`hg-button-container`;var f=`${i.options.layoutName}-r${t}c${s}`;d.setAttribute(`data-skUID`,f);var p=a.splice(l,u-l+1);o+=u-l,p.forEach((function(e){return d.appendChild(e)})),a.splice(l,0,d),e.innerHTML=``,a.forEach((function(t){return e.appendChild(t)})),i.options.debug&&console.log(`rowDOMContainer`,p,l,u,o+1)})),e}},{key:`render`,value:function(){var e=this;this.resetRows(),this.initialized||this.beforeFirstRender(),this.beforeRender();var t=`hg-layout-${this.options.layoutName}`,n=this.options.layout||{default:["` 1 2 3 4 5 6 7 8 9 0 - = {bksp}",`{tab} q w e r t y u i o p [ ] \\`,`{lock} a s d f g h j k l ; ' {enter}`,`{shift} z x c v b n m , . / {shift}`,`.com @ {space}`],shift:[`~ ! @ # $ % ^ & * ( ) _ + {bksp}`,`{tab} Q W E R T Y U I O P { } |`,`{lock} A S D F G H J K L : " {enter}`,`{shift} Z X C V B N M < > ? {shift}`,`.com @ {space}`]},r=this.options.useTouchEvents||!1,i=r?`hg-touch-events`:``,a=this.options.useMouseEvents||!1,o=this.options.disableRowButtonContainers;this.keyboardDOM.className=this.getKeyboardClassString(this.options.theme,t,this.keyboardPluginClasses,i),this.keyboardDOM.setAttribute(`data-skInstance`,this.currentInstanceName),this.keyboardRowsDOM=document.createElement(`div`),this.keyboardRowsDOM.className=`hg-rows`,n[this.options.layoutName||this.defaultName].forEach((function(t,n){var i=t.split(` `);e.options.excludeFromLayout&&e.options.excludeFromLayout[e.options.layoutName||e.defaultName]&&(i=i.filter((function(t){return e.options.excludeFromLayout&&!e.options.excludeFromLayout[e.options.layoutName||e.defaultName].includes(t)})));var s=document.createElement(`div`);s.className+=`hg-row`;var c=[],l=[];i.forEach((function(t,i){var u,d=!o&&typeof t==`string`&&t.length>1&&t.indexOf(`[`)===0,f=!o&&typeof t==`string`&&t.length>1&&t.indexOf(`]`)===t.length-1;d&&(c.push(i),t=t.replace(/\[/g,``)),f&&(l.push(i),t=t.replace(/\]/g,``));var p=e.utilities.getButtonClass(t),m=e.utilities.getButtonDisplayName(t,e.options.display,e.options.mergeDisplay),h=e.options.useButtonTag?`button`:`div`,g=document.createElement(h);g.className+=`hg-button ${p}`,(u=g.classList).add.apply(u,C(e.getButtonThemeClasses(t))),e.setDOMButtonAttributes(t,(function(e,t){g.setAttribute(e,t)})),e.activeButtonClass=`hg-activeButton`,!e.utilities.pointerEventsSupported()||r||a?r?(g.ontouchstart=function(n){e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.ontouchend=function(n){e.handleButtonMouseUp(t,n)},g.ontouchcancel=function(n){e.handleButtonMouseUp(t,n)}):(g.onclick=function(n){e.setMouseHold(!1),typeof e.options.onKeyReleased==`function`||e.options.useMouseEvents&&e.options.clickOnMouseDown||e.handleButtonClicked(t,n)},g.onmousedown=function(n){(typeof e.options.onKeyReleased==`function`||e.options.useMouseEvents&&e.options.clickOnMouseDown)&&!e.isMouseHold&&e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.onmouseup=function(n){e.handleButtonMouseUp(t,n)}):(g.onpointerdown=function(n){e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.onpointerup=function(n){e.handleButtonMouseUp(t,n)},g.onpointercancel=function(n){e.handleButtonMouseUp(t,n)}),g.setAttribute(`data-skBtn`,t);var _=`${e.options.layoutName}-r${n}b${i}`;g.setAttribute(`data-skBtnUID`,_);var v=document.createElement(`span`);v.innerHTML=m,g.appendChild(v),e.buttonElements[t]||(e.buttonElements[t]=[]),e.buttonElements[t].push(g),s.appendChild(g)})),s=e.parseRowDOMContainers(s,n,c,l),e.keyboardRowsDOM.appendChild(s)})),this.keyboardDOM.appendChild(this.keyboardRowsDOM),this.onRender(),this.initialized||(this.initialized=!0,!this.utilities.pointerEventsSupported()||r||a?r?(document.ontouchend=function(t){return e.handleButtonMouseUp(void 0,t)},document.ontouchcancel=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.ontouchstart=function(t){return e.handleKeyboardContainerMouseDown(t)}):r||(document.onmouseup=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.onmousedown=function(t){return e.handleKeyboardContainerMouseDown(t)}):(document.onpointerup=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.onpointerdown=function(t){return e.handleKeyboardContainerMouseDown(t)}),this.onInit())}}],t&&D(e.prototype,t),n&&D(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}(),j=A;return r}()},442:function(t){t.exports=e}},n={};function r(e){var i=n[e];if(i!==void 0)return i.exports;var a=n[e]={exports:{}};return t[e].call(a.exports,a,a.exports,r),a.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){typeof Symbol<`u`&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return function(){r.r(i),r.d(i,{KeyboardReact:function(){return u},default:function(){return d}}),r(981);var e=r(442),t=r(548),n=r.n(t);function a(e){return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function s(e){for(var t=1;t{e?.(t)},[t,e]);let d=(0,y.useCallback)(e=>{if(a.current)return;let t=e.target;if(!t.closest(`[data-vkb="false"]`)){if(t instanceof HTMLInputElement){if(!_1e.has(t.type))return}else if(!(t instanceof HTMLTextAreaElement))return;c.current=t,n(!0),s(`default`),l.current?.setInput?.(c.current.value),setTimeout(()=>{(t.closest(`.bg-zinc-800, .rounded-lg, [data-vkb-group]`)??t).scrollIntoView({behavior:`smooth`,block:`nearest`})},100)}},[]),f=(0,y.useCallback)(()=>{setTimeout(()=>{let e=document.activeElement;e&&(u.current?.contains(e)||e===c.current)||(n(!1),c.current=null)},150)},[]);(0,y.useEffect)(()=>(document.addEventListener(`focusin`,d),document.addEventListener(`focusout`,f),()=>{document.removeEventListener(`focusin`,d),document.removeEventListener(`focusout`,f)}),[d,f]);let p=(0,y.useCallback)(()=>{a.current=!0,i(!0),c.current?.blur(),c.current=null,setTimeout(()=>{n(!1),i(!1),a.current=!1},400)},[]),m=(0,y.useCallback)(e=>{let t=c.current;if(t){if(e===`{shift}`){s(e=>e==="default"?`shift`:`default`);return}if(e===`{lock}`){s(e=>e==="default"?`shift`:`default`);return}if(e===`{close}`){p();return}e===`{bksp}`?W9(t,t.value.slice(0,-1)):e===`{space}`?W9(t,t.value+` `):(W9(t,t.value+e),o===`shift`&&s(`default`)),t.focus(),l.current?.setInput?.(t.value)}},[o,p]);return t?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-[9998] bg-transparent`,onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),r||p()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation(),r||p()},onClick:e=>{e.preventDefault(),e.stopPropagation()}}),!r&&(0,G.jsx)(`div`,{ref:u,className:`relative z-[9999] shrink-0`,onMouseDown:e=>e.preventDefault(),onTouchStart:e=>{e.target.closest(`.hg-button`)||e.preventDefault()},children:(0,G.jsx)(g1e,{keyboardRef:e=>{l.current=e},layoutName:o,onKeyPress:m,theme:`simple-keyboard vkb-theme`,layout:{default:[`1 2 3 4 5 6 7 8 9 0 {bksp}`,`q w e r t y u i o p`,`{lock} a s d f g h j k l`,`{shift} z x c v b n m . @`,`{space} {close}`],shift:[`! @ # $ % ^ & * ( ) {bksp}`,`Q W E R T Y U I O P`,`{lock} A S D F G H J K L`,`{shift} Z X C V B N M , _`,`{space} {close}`]},display:{"{bksp}":`⌫`,"{close}":`✕ Close`,"{shift}":`⇧`,"{lock}":`⇪`,"{space}":` `}})})]}):null}function y1e(){Of();let[e,t]=(0,y.useState)(null),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(100),{i18n:o}=U(),s=or(),c=rr(),l=p1e(),{setViewportSuppressed:u}=Hd();(0,y.useEffect)(()=>(u(!0),()=>u(!1)),[u]);let{data:d}=K({queryKey:[`settings`],queryFn:Z.getSettings});(0,y.useEffect)(()=>{d?.language&&d.language!==o.language&&o.changeLanguage(d.language)},[d?.language,o]);let{data:f=[]}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Cd.getDevices(),refetchInterval:3e4}),p=f[0],m=l.deviceOnline||!!p?.online,h=(0,y.useMemo)(()=>({...l,deviceOnline:m}),[l,m]),g=(0,y.useRef)(!1);(0,y.useEffect)(()=>{p&&!g.current&&(a(p.display_brightness),g.current=!0)},[p]),(0,y.useEffect)(()=>{let e=document.documentElement,t=e.classList.contains(`dark`);return e.classList.add(`dark`),()=>{t||e.classList.remove(`dark`)}},[]);let{data:_}=K({queryKey:[`spoolbuddy-update-check`,p?.device_id],queryFn:()=>p?Cd.checkDaemonUpdate(p.device_id):Promise.resolve(null),enabled:!!p,refetchInterval:300*1e3,staleTime:0}),v=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!m){let e=`SpoolBuddy device disconnected`;r({type:`warning`,message:e}),v.current=e}else if(_?.update_available&&_.latest_version){let e=`Update available: v${_.latest_version}`;r({type:`info`,message:e}),v.current=e}else v.current&&=(r(null),null)},[m,_?.update_available,_?.latest_version]);let b=!!(l.matchedSpool||l.unknownTagUid||l.unknownTrayUuid),x=(0,y.useRef)(!1);(0,y.useEffect)(()=>{b&&!x.current&&c.pathname!==`/spoolbuddy`&&s(`/spoolbuddy`),x.current=b},[b,c.pathname,s]);let{data:S=[]}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),C=Co({queries:S.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id),refetchInterval:1e4,select:e=>({connected:e?.connected})}))}),w=(0,y.useMemo)(()=>S.filter((e,t)=>C[t]?.data?.connected),[S,C]),T=(0,y.useRef)(null),E=(0,y.useRef)(!1),D=(0,y.useRef)(null),O=(0,y.useCallback)(e=>{T.current={x:e.touches[0].clientX,y:e.touches[0].clientY},E.current=!1},[]),k=(0,y.useCallback)(n=>{if(!T.current)return;let r=n.changedTouches[0].clientX-T.current.x,i=n.changedTouches[0].clientY-T.current.y,a=T.current.y;if(T.current=null,E.current=!1,i>=50&&Math.abs(i)>Math.abs(r)&&a<120){N(!0);return}if(w.length<2||Math.abs(r)<50||Math.abs(i)>Math.abs(r))return;let o=w.findIndex(t=>t.id===e);t(w[r<0?(o+1)%w.length:(o-1+w.length)%w.length].id)},[w,e,t]);(0,y.useEffect)(()=>{let e=D.current;if(!e)return;let t=e=>{if(!T.current)return;let t=Math.abs(e.touches[0].clientX-T.current.x),n=Math.abs(e.touches[0].clientY-T.current.y);if(E.current){e.preventDefault();return}t>10&&t>n&&(E.current=!0,e.preventDefault())};return e.addEventListener(`touchmove`,t,{passive:!1}),()=>e.removeEventListener(`touchmove`,t)},[]);let[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(!1);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{ref:D,"data-spoolbuddy-kiosk":!0,className:`w-screen h-screen bg-bambu-dark text-white flex flex-col overflow-hidden`,style:{...i<100?{filter:`brightness(${i/100})`}:void 0,overscrollBehaviorX:`none`},onTouchStart:O,onTouchEnd:k,children:[(0,G.jsx)(`button`,{onClick:()=>N(!0),className:`w-full h-1.5 bg-bambu-dark-secondary flex justify-center items-center shrink-0 touch-none`,"aria-label":`Open quick menu`,children:(0,G.jsx)(`div`,{className:`w-8 h-0.5 rounded-full bg-zinc-600`})}),(0,G.jsx)(o1e,{selectedPrinterId:e,onPrinterChange:t,deviceOnline:m}),(0,G.jsx)(`main`,{className:`flex-1 overflow-y-auto`,children:(0,G.jsx)(Ir,{context:{selectedPrinterId:e,setSelectedPrinterId:t,sbState:h,setAlert:r,displayBrightness:i,setDisplayBrightness:a}})}),!A&&(0,G.jsx)(l1e,{alert:n}),!A&&(0,G.jsx)(c1e,{}),(0,G.jsx)(v1e,{onVisibilityChange:j})]}),(0,G.jsx)(u1e,{isOpen:M,onClose:()=>N(!1),deviceId:p?.device_id??null,deviceOnline:m})]})}function G9({color:e,isEmpty:t,size:n=32}){return t?(0,G.jsx)(`div`,{className:`rounded-full border-2 border-dashed border-zinc-500 flex items-center justify-center`,style:{width:n,height:n},children:(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-zinc-600`})}):(0,G.jsxs)(`svg`,{width:n,height:n,viewBox:`0 0 32 32`,children:[(0,G.jsx)(`circle`,{cx:`16`,cy:`16`,r:`14`,fill:e,stroke:`white`,strokeWidth:`1.5`,strokeOpacity:`0.7`}),(0,G.jsx)(`circle`,{cx:`16`,cy:`16`,r:`11`,fill:e,style:{filter:`brightness(0.85)`}})]})}var b1e=`spoolbuddy-default-core-weight`;function x1e(){try{let e=localStorage.getItem(b1e);if(e){let t=parseInt(e,10);if(t>=0&&t<=500)return t}}catch{}return 250}function S1e({spool:e,scaleWeight:t,onClose:n,onSyncWeight:r,onAssignToAms:i,isAssigned:a,onUnassignFromAms:o}){let{t:s}=U(),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(!1),f=wf(e.rgba),p=e.core_weight&&e.core_weight>0?e.core_weight:x1e(),m=t===null?null:Math.round(Math.max(0,t)),h=m===null?null:Math.round(Math.max(0,m-p)),g=Math.round(e.label_weight||1e3),_=h===null?null:Math.min(100,Math.round(h/g*100)),v=_===null?`#808080`:_>50?`#22c55e`:_>20?`#eab308`:`#ef4444`,b=Math.max(0,(e.label_weight||0)-(e.weight_used||0))+p,x=m===null?null:m-b,S=x===null?null:Math.abs(x)<=50,C=async()=>{if(t!==null){l(!0);try{await Cd.updateSpoolWeight(e.id,Math.round(t)),d(!0),r?.(),setTimeout(()=>d(!1),3e3)}catch(e){console.error(`Failed to sync weight:`,e)}finally{l(!1)}}};return(0,G.jsxs)(`div`,{className:`flex flex-col items-center space-y-4 max-w-md`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-5`,children:[(0,G.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,G.jsx)(G9,{color:f,isEmpty:!1,size:100}),_!==null&&(0,G.jsxs)(`div`,{className:`absolute -bottom-2 -right-2 px-2 py-0.5 rounded-full text-xs font-bold text-white shadow-lg`,style:{backgroundColor:v},children:[_,`%`]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:e.color_name||`Unknown color`}),(0,G.jsxs)(`span`,{className:`text-xs font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,G.jsxs)(`p`,{className:`text-sm text-zinc-400`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]}),h!==null&&(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-3xl font-bold font-mono text-zinc-100`,children:[h,`g`]}),(0,G.jsxs)(`span`,{className:`text-sm text-zinc-500`,children:[`/ `,g,`g`]})]}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mt-0.5`,children:s(`spoolbuddy.spool.remaining`,`Remaining`)}),(0,G.jsx)(`div`,{className:`mt-2 max-w-xs`,children:(0,G.jsx)(`div`,{className:`h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500`,style:{width:`${_}%`,backgroundColor:v}})})})]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-2 text-sm bg-zinc-800 rounded-lg p-4 w-full`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.dashboard.grossWeight`,`Gross weight`)}),(0,G.jsx)(`span`,{className:`font-mono text-zinc-300`,children:m===null?`—`:`${m}g`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.spool.coreWeight`,`Core`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[p,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.dashboard.spoolSize`,`Spool size`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[g,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.spool.scaleWeight`,`Scale`)}),m===null?(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`—`}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 font-mono ${S?`text-green-500`:`text-yellow-500`}`,children:[m,`g`,S?(0,G.jsx)(ds,{className:`w-3.5 h-3.5`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Iu,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`button`,{onClick:C,className:`p-1 hover:bg-green-500/20 rounded transition-colors text-green-500`,title:s(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`),children:(0,G.jsx)(Vl,{className:`w-4 h-4`})})]})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.dashboard.tagId`,`Tag`)}),(0,G.jsx)(`span`,{className:`font-mono text-xs text-zinc-400 truncate max-w-[120px]`,title:e.tag_uid||``,children:e.tag_uid?e.tag_uid.slice(-8):`—`})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[i&&(0,G.jsx)(`button`,{onClick:a?void 0:i,disabled:!!a,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px] disabled:opacity-50 disabled:cursor-not-allowed`,children:s(`spoolbuddy.modal.assignToAms`,`Assign to AMS`)}),o&&(0,G.jsxs)(`button`,{onClick:o,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-red-600/20 text-red-400 hover:bg-red-600/30 transition-colors min-h-[44px]`,children:[(0,G.jsx)(zu,{className:`w-4 h-4 inline mr-1`}),s(`inventory.unassignSpool`)]}),(0,G.jsx)(`button`,{onClick:C,disabled:t===null||c,className:`px-5 py-2.5 rounded-lg text-sm font-medium transition-colors min-h-[44px] ${u?`bg-green-600/20 text-green-400`:i?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600 disabled:opacity-40 disabled:cursor-not-allowed`:`bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed`}`,children:c?`...`:u?s(`spoolbuddy.dashboard.weightSynced`,`Synced!`):s(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`)}),n&&(0,G.jsx)(`button`,{onClick:n,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:s(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function C1e({tagUid:e,scaleWeight:t,coreWeight:n,onLinkSpool:r,onAddToInventory:i,onClose:a}){let{t:o}=U(),s=n??x1e(),c=t===null?null:Math.round(Math.max(0,t)),l=c===null?null:Math.round(Math.max(0,c-s));return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-5`,children:[(0,G.jsx)(`div`,{className:`w-20 h-20 rounded-2xl bg-green-500/15 flex items-center justify-center`,children:(0,G.jsx)(`svg`,{className:`w-10 h-10 text-green-500`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z`})})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:o(`spoolbuddy.dashboard.newTag`,`New Tag Detected`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-500 font-mono mt-1`,children:e})]}),c!==null&&(0,G.jsxs)(`div`,{className:`text-sm text-zinc-400`,children:[(0,G.jsxs)(`span`,{className:`font-mono font-semibold`,children:[c,`g`]}),` `,o(`spoolbuddy.dashboard.onScale`,`on scale`),l!==null&&l>0&&(0,G.jsxs)(`span`,{className:`text-zinc-500`,children:[` • ~`,l,`g filament`]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2 justify-center`,children:[i&&(0,G.jsx)(`button`,{onClick:i,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:o(`spoolbuddy.modal.addToInventory`,`Add to Inventory`)}),r&&(0,G.jsxs)(`button`,{onClick:r,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4 inline-block mr-1.5 -mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1`})}),o(`inventory.assignSpool`,`Assign Spool`)]}),a&&(0,G.jsx)(`button`,{onClick:a,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:o(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function w1e(e){return e?`#${e.slice(0,6)}`:`#808080`}function T1e(e){return!e.tray_type||e.tray_type===``}function E1e(e){if(e.tray_type)return null;if(e.exists===!0)return`reset`;if(e.exists===!1)return`physical`;let t=e.state??null;return t===9||t===10?`physical`:`reset`}function D1e(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function O1e({className:e}){return(0,G.jsx)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,G.jsx)(`path`,{d:`M17.8131 0.00538C18.4463 -0.15091 20.3648 3.14642 20.8264 3.84781C25.4187 10.816 35.3089 26.9368 35.9383 34.8694C37.4182 53.5822 11.882 61.3357 2.53721 45.3789C-1.73471 38.0791 0.016 32.2049 3.178 25.0232C6.99221 16.3662 12.6411 7.90372 17.8131 0.00538ZM18.3738 7.24807L17.5881 7.48441C14.4452 12.9431 10.917 18.2341 8.19369 23.9368C4.6808 31.29 1.18317 38.5479 7.69403 45.5657C17.3058 55.9228 34.9847 46.8808 31.4604 32.8681C29.2558 24.0969 22.4207 15.2913 18.3776 7.24807H18.3738Z`,fill:`#C3C2C1`})})}function k1e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 35 53`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`path`,{d:`M17.3165 0.0038C17.932 -0.14959 19.7971 3.08645 20.2458 3.77481C24.7103 10.6135 34.3251 26.4346 34.937 34.2198C36.3757 52.5848 11.5505 60.1942 2.46584 44.534C-1.68714 37.3735 0.0148 31.6085 3.08879 24.5603C6.79681 16.0605 12.2884 7.75907 17.3165 0.0038ZM17.8615 7.11561L17.0977 7.34755C14.0423 12.7048 10.6124 17.8974 7.96483 23.4941C4.54975 30.7107 1.14949 37.8337 7.47908 44.721C16.8233 54.8856 34.01 46.0117 30.5838 32.2595C28.4405 23.6512 21.7957 15.0093 17.8652 7.11561H17.8615Z`,fill:`#C3C2C1`}),(0,G.jsx)(`path`,{d:`M5.03547 30.112C9.64453 30.4936 11.632 35.7985 16.4154 35.791C19.6339 35.7873 20.2161 33.2283 22.3853 31.6197C31.6776 24.7286 33.5835 37.4894 27.9881 44.4254C18.1878 56.5653 -1.16063 44.6013 5.03917 30.1158L5.03547 30.112Z`,fill:`#1F8FEB`})]})}function A1e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`path`,{d:`M17.9625 4.48059L4.77216 26.3154L2.08228 40.2175L10.0224 50.8414H23.1594L33.3246 42.1693V30.2455L17.9625 4.48059Z`,fill:`#1F8FEB`}),(0,G.jsx)(`path`,{d:`M17.7948 0.00538C18.4273 -0.15091 20.3438 3.14642 20.8048 3.84781C25.3921 10.816 35.2715 26.9368 35.9001 34.8694C37.3784 53.5822 11.8702 61.3357 2.53562 45.3789C-1.73163 38.0829 0.0134 32.2087 3.1757 25.027C6.98574 16.3662 12.6284 7.90372 17.7948 0.00538ZM18.3549 7.24807L17.57 7.48441C14.4306 12.9431 10.9063 18.2341 8.1859 23.9368C4.67686 31.29 1.18305 38.5479 7.68679 45.5657C17.2881 55.9228 34.9476 46.8808 31.4271 32.8681C29.2249 24.0969 22.3974 15.2913 18.3587 7.24807H18.3549Z`,fill:`#C3C2C1`})]})}function j1e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`}),(0,G.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2.5`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function M1e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`rect`,{x:`4.5`,y:`8`,width:`3`,height:`4.5`,fill:`#d4a017`,rx:`0.5`}),(0,G.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#d4a017`}),(0,G.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function N1e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`rect`,{x:`4.5`,y:`3`,width:`3`,height:`9.5`,fill:`#c62828`,rx:`0.5`}),(0,G.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#c62828`}),(0,G.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function P1e({humidity:e,goodThreshold:t=40,fairThreshold:n=60}){let r,i;return e<=t?(r=`#22a352`,i=O1e):e<=n?(r=`#d4a017`,i=k1e):(r=`#c62828`,i=A1e),(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,G.jsx)(i,{className:`w-3 h-3.5`}),(0,G.jsxs)(`span`,{className:`font-medium tabular-nums text-xs`,style:{color:r},children:[e,`%`]})]})}function F1e({temp:e,goodThreshold:t=28,fairThreshold:n=35}){let r,i;return e<=t?(r=`#22a352`,i=j1e):e<=n?(r=`#d4a017`,i=M1e):(r=`#c62828`,i=N1e),(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,G.jsx)(i,{className:`w-3 h-3.5`}),(0,G.jsxs)(`span`,{className:`font-medium tabular-nums text-xs`,style:{color:r},children:[e,`°C`]})]})}function K9({side:e}){return(0,G.jsx)(`span`,{className:`inline-flex items-center justify-center w-4 h-4 text-[9px] font-bold rounded`,style:{backgroundColor:`#1a4d2e`,color:`#00ae42`},children:e})}function I1e({tray:e,slotIndex:t,isActive:n,fillOverride:r,spoolmanFill:i,onClick:a}){let o=T1e(e),s=E1e(e),c=w1e(e.tray_color),l=e.remain!==null&&e.remain!==void 0&&e.remain>=0?e.remain:null,u=i??(r===0&&l!==null&&l>0?null:r)??l;return(0,G.jsxs)(`div`,{className:`relative flex flex-col items-center p-2.5 rounded-lg transition-all ${n?`ring-2 ring-bambu-green`:``} ${a?`cursor-pointer hover:bg-white/5`:``}`,onClick:a,title:a?`AMS Slot ${t+1}`:void 0,children:[(0,G.jsxs)(`div`,{className:`relative w-16 h-16 mb-1`,children:[o?(0,G.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-full bg-gray-600`})}):(0,G.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:c}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:c,style:{filter:`brightness(0.85)`}}),(0,G.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]}),n&&(0,G.jsx)(`div`,{className:`absolute -bottom-1 left-1/2 -translate-x-1/2 w-2.5 h-2.5 bg-bambu-green rounded-full`})]}),(0,G.jsx)(`span`,{className:`text-sm text-white/70 truncate max-w-full`,title:s===`reset`?`Spool loaded — slot not configured`:void 0,children:o?s===`reset`?`?`:`Empty`:e.tray_type||`Unknown`}),!o&&u!==null&&u>=0&&(0,G.jsx)(`div`,{className:`w-full h-1 bg-bambu-dark-tertiary rounded-full overflow-hidden mt-1`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${u}%`,backgroundColor:Ep(u)}})}),(0,G.jsx)(`span`,{className:`absolute top-1 right-1 text-xs text-white/30`,children:t+1})]})}function L1e({unit:e,activeSlot:t,onConfigureSlot:n,isDualNozzle:r,nozzleSide:i,thresholds:a,fillOverrides:o,spoolmanFillOverrides:s}){let c=e.tray||[],l=e.is_ams_ht,u=l?1:4;return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-white font-medium text-base`,children:D1e(e.id)}),r&&i&&(0,G.jsx)(K9,{side:i})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.temp!=null&&(0,G.jsx)(F1e,{temp:e.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair}),e.humidity!=null&&(0,G.jsx)(P1e,{humidity:e.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair})]})]}),(0,G.jsx)(`div`,{className:`grid ${l?`grid-cols-1 max-w-[100px] mx-auto`:`grid-cols-4`} gap-2`,children:Array.from({length:u}).map((r,i)=>{let a=c[i]||{id:i,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null};return(0,G.jsx)(I1e,{tray:a,slotIndex:i,isActive:t===i,fillOverride:o?.[`${e.id}-${i}`]??null,spoolmanFill:s?.[`${e.id}-${i}`]??null,onClick:n?()=>n(e.id,i,T1e(a)?null:a):void 0},i)})})]})}function q9(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function J9(e){return!e.tray_type||e.tray_type===``}function R1e(e){return e?`#${e.slice(0,6)}`:`#808080`}var Y9=e=>(e??``).trim().toUpperCase();function z1e(e,t){let n=Y9(e),r=Y9(t);return!n||!r?`none`:n===r?`exact`:r.includes(n)||n.includes(r)?`partial`:`none`}function B1e(e,t){let n=Y9(e),r=Y9(t);return!n||!r?!1:n===r}function V1e({isOpen:e,onClose:t,spool:n,printerId:r,spoolmanMode:i=!1}){let{t:a}=U(),o=co(),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null);(0,y.useEffect)(()=>{e&&(c(null),u(null),f(!1),m(null),g(null))},[e]);let _=(0,y.useCallback)(e=>{e.key===`Escape`&&t()},[t]);(0,y.useEffect)(()=>(e&&document.addEventListener(`keydown`,_),()=>document.removeEventListener(`keydown`,_)),[e,_]);let{data:v}=K({queryKey:[`printerStatus`,r],queryFn:()=>Z.getPrinterStatus(r),enabled:e&&r!==null,refetchInterval:5e3}),{data:b}=K({queryKey:[`printer`,r],queryFn:()=>Z.getPrinter(r),enabled:e&&r!==null}),{data:x}=K({queryKey:[`settings`],queryFn:()=>Z.getSettings(),enabled:e,staleTime:300*1e3}),{data:S}=K({queryKey:[`spool-assignments`,r],queryFn:()=>Z.getAssignments(r),enabled:e&&r!==null,staleTime:30*1e3}),{data:C=[]}=K({queryKey:[`spoolman-slot-assignments`,r],queryFn:()=>Z.getSpoolmanSlotAssignments(r??void 0),enabled:e&&!!i&&r!==null,staleTime:30*1e3}),w=i?C.find(e=>e.spoolman_spool_id===n.id):void 0,T=(0,y.useMemo)(()=>{let e={};if(!S)return e;for(let t of S){let n=t.spool;if(n&&n.label_weight>0&&n.weight_used!=null){let r=Math.round(Math.max(0,n.label_weight-n.weight_used)/n.label_weight*100);e[`${t.ams_id}-${t.tray_id}`]=r}}return e},[S]),E=x?{humidityGood:Number(x.ams_humidity_good)||40,humidityFair:Number(x.ams_humidity_fair)||60,tempGood:Number(x.ams_temp_good)||28,tempFair:Number(x.ams_temp_fair)||35}:void 0,D=v?.connected??!1,O=(0,y.useMemo)(()=>v?.ams??[],[v?.ams]),k=(0,y.useMemo)(()=>O.filter(e=>!e.is_ams_ht),[O]),A=(0,y.useMemo)(()=>O.filter(e=>e.is_ams_ht),[O]),j=(0,y.useMemo)(()=>[...v?.vt_tray??[]].sort((e,t)=>(e.id??254)-(t.id??254)),[v?.vt_tray]),M=b?.nozzle_count===2||v?.temperatures?.nozzle_2!==void 0,N=(0,y.useRef)({});(0,y.useEffect)(()=>{v?.ams_extruder_map&&Object.keys(v.ams_extruder_map).length>0&&(N.current=v.ams_extruder_map)},[v?.ams_extruder_map]);let P=v?.ams_extruder_map&&Object.keys(v.ams_extruder_map).length>0?v.ams_extruder_map:N.current,F=v?.fila_switch?.installed===!0,I=(0,y.useCallback)(e=>{if(!M)return null;let t=P[String(e)];return t===void 0?F?null:(e>=128?e-128:e)===1?`L`:`R`:t===1?`L`:`R`},[M,P,F]),L=q({mutationFn:async({amsId:e,trayId:t})=>{if(!r)throw Error(`No printer selected`);return i?await Z.assignSpoolmanSlot({spoolman_spool_id:n.id,printer_id:r,ams_id:e,tray_id:t}):await Z.assignSpool({spool_id:n.id,printer_id:r,ams_id:e,tray_id:t})},onSuccess:e=>{u(`success`);let n=e&&`pending_config`in e&&e.pending_config;c(n?a(`spoolbuddy.modal.assignPendingInsert`,`Assigned. Slot will configure when you insert the spool.`):a(`spoolbuddy.modal.assignSuccess`,`Assigned!`)),o.invalidateQueries({queryKey:[`slotPresets`]}),o.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),o.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),setTimeout(()=>t(),n?2500:1500)},onError:e=>{u(`error`),c(e instanceof Error?e.message:a(`spoolbuddy.modal.assignError`,`Failed to assign spool.`))}}),R=L.isPending,z=(0,y.useCallback)((e,t)=>{if(e===254||e===255){let n=e===254?254:254+t;return j.find(e=>(e.id??254)===n)||null}return O.find(t=>t.id===e)?.tray?.find(e=>e.id===t)||null},[O,j]),B=(0,y.useCallback)((e,t)=>e<=3?`${q9(e)} ${a(`ams.slot`,`Slot`)} ${t+1}`:e>=128&&e<=135?q9(e):e===254?a(`printers.extL`,`Ext-L`):M?a(`printers.extR`,`Ext-R`):a(`printers.ext`,`Ext`),[a,M]),V=(0,y.useCallback)((e,t)=>{u(`info`),c(a(`spoolbuddy.modal.assigning`,`Configuring slot...`)),L.mutate({amsId:e,trayId:t})},[L,a]),ee=(0,y.useCallback)((e,t)=>{if(!R){if(!x?.disable_filament_warnings){let r=z(e,t);if(r&&!J9(r)){let i=r.tray_sub_brands||r.tray_type||``,a=z1e(n.material,i),o=n.slicer_filament_name||n.slicer_filament,s=r.tray_type||``,c=B1e(o,s);if(a!==`exact`){let r;r=a===`none`&&!c?`material_profile`:a===`partial`&&!c?`partial_profile`:a===`none`?`material`:`partial`;let l=B(e,t);g({amsId:e,trayId:t}),m({type:r,spoolMaterial:n.material||``,trayMaterial:i||``,spoolProfile:o||void 0,trayProfile:s||void 0,location:l}),f(!0);return}}}V(e,t)}},[R,x?.disable_filament_warnings,n,z,B,V]),te=(0,y.useCallback)(()=>{h&&(f(!1),m(null),V(h.amsId,h.trayId),g(null))},[h,V]),ne=(0,y.useMemo)(()=>{let e=[];for(let t of A){let n=t.tray?.[0]||{id:0,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},r=T[`${t.id}-0`]??null,i=n.remain!=null&&n.remain>=0?n.remain:null,a=r===0&&i!==null&&i>0?null:r;e.push({key:`ht-${t.id}`,label:q9(t.id),amsId:t.id,trayId:0,tray:n,isEmpty:J9(n),nozzleSide:I(t.id),effectiveFill:a??i})}for(let t of j){let n=t.id??254,r=n-254,i=T[`255-${r}`]??null,o=t.remain!=null&&t.remain>=0?t.remain:null,s=i===0&&o!==null&&o>0?null:i;e.push({key:`ext-${n}`,label:M?n===254?a(`printers.extL`,`Ext-L`):a(`printers.extR`,`Ext-R`):a(`printers.ext`,`Ext`),amsId:255,trayId:r,tray:t,isEmpty:J9(t),nozzleSide:M?n===254?`L`:`R`:null,effectiveFill:s??o})}return e},[A,j,M,a,I,T]);return e?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`fixed inset-0 z-[60] bg-bambu-dark flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-zinc-800 shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,G.jsx)(`div`,{className:`w-7 h-7 rounded-full shrink-0`,style:Tf(n.rgba)}),(0,G.jsx)(`div`,{className:`min-w-0`,children:(0,G.jsxs)(`h2`,{className:`text-sm font-semibold text-zinc-100 truncate`,children:[a(`spoolbuddy.modal.assignToAmsTitle`,`Assign to AMS`),(0,G.jsxs)(`span`,{className:`font-normal text-zinc-500 ml-2`,children:[n.color_name||`Unknown`,` • `,n.brand,` `,n.material,n.subtype&&` ${n.subtype}`]}),(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 ml-2 shrink-0`,children:[`#`,n.id]})]})})]}),(0,G.jsx)(`button`,{onClick:t,disabled:R,className:`p-2 rounded-lg text-zinc-500 hover:text-zinc-300 hover:bg-zinc-800 transition-colors shrink-0 disabled:opacity-50`,children:(0,G.jsx)(td,{className:`w-5 h-5`})})]}),s&&(0,G.jsxs)(`div`,{className:`mx-5 mt-3 p-3 rounded-lg flex items-center gap-3 border shrink-0 ${l===`info`?`bg-blue-500/10 border-blue-500/40`:l===`success`?`bg-green-500/10 border-green-500/40`:`bg-red-500/10 border-red-500/40`}`,children:[l===`info`&&(0,G.jsx)(Y,{className:`w-4 h-4 text-blue-400 animate-spin shrink-0`}),l===`success`&&(0,G.jsx)(bs,{className:`w-4 h-4 text-green-400 shrink-0`}),l===`error`&&(0,G.jsx)(Es,{className:`w-4 h-4 text-red-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm ${l===`info`?`text-blue-300`:l===`success`?`text-green-300`:`text-red-300`}`,children:s})]}),(0,G.jsx)(`div`,{className:`flex-1 flex flex-col gap-3 p-4 min-h-0 overflow-y-auto`,children:!D&&r?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`text-center text-white/50`,children:(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:a(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)})})}):O.length===0&&j.length===0?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,G.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,G.jsx)(qc,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:a(`spoolbuddy.ams.noData`,`No AMS detected`)}),(0,G.jsx)(`p`,{className:`text-sm`,children:a(`spoolbuddy.ams.connectAms`,`Connect an AMS to see filament slots`)})]})}):(0,G.jsxs)(G.Fragment,{children:[k.length>0&&(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3 flex-1 min-h-0`,children:k.map(e=>(0,G.jsx)(L1e,{unit:e,activeSlot:w?.ams_id===e.id?w.tray_id??null:null,onConfigureSlot:(t,n)=>ee(e.id,n),isDualNozzle:M,nozzleSide:I(e.id),thresholds:E,fillOverrides:T},e.id))}),ne.length>0&&(0,G.jsx)(`div`,{className:`flex gap-2 shrink-0`,children:ne.map(({key:e,label:t,amsId:n,trayId:r,tray:i,isEmpty:a,nozzleSide:o,effectiveFill:s})=>{let c=R1e(i.tray_color);return(0,G.jsxs)(`div`,{onClick:()=>ee(n,r),className:`bg-bambu-dark-secondary rounded-lg px-3 py-2 cursor-pointer hover:bg-bambu-dark-secondary/80 transition-all flex items-center gap-2 ${w&&w.ams_id===n&&w.tray_id===r?`ring-2 ring-bambu-green`:``} ${R?`opacity-50 pointer-events-none`:``}`,children:[(0,G.jsx)(`div`,{className:`relative w-10 h-10 shrink-0`,children:a?(0,G.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-gray-600`})}):(0,G.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:c}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:c,style:{filter:`brightness(0.85)`}}),(0,G.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]})}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`text-xs text-white/50 font-medium`,children:t}),o&&(0,G.jsx)(K9,{side:o})]}),(0,G.jsx)(`div`,{className:`text-sm text-white/80 truncate`,children:a?`Empty`:i.tray_type||`?`})]}),!a&&s!=null&&s>=0&&(0,G.jsx)(`div`,{className:`w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden shrink-0 flex flex-col-reverse`,children:(0,G.jsx)(`div`,{className:`w-full rounded-full`,style:{height:`${s}%`,backgroundColor:Ep(s)}})})]},e)})})]})}),(0,G.jsx)(`div`,{className:`flex justify-end gap-3 px-5 py-3 border-t border-zinc-800 shrink-0`,children:(0,G.jsx)(`button`,{onClick:t,disabled:R,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-800 text-zinc-300 hover:bg-zinc-700 transition-colors min-h-[44px] disabled:opacity-50`,children:l===`success`?a(`spoolbuddy.dashboard.close`,`Close`):a(`spoolbuddy.modal.cancel`,`Cancel`)})})]}),d&&p&&(()=>{let e=``;return p.type===`material`?e=a(`inventory.assignMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location}):p.type===`partial`?e=a(`inventory.assignPartialMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location}):p.type===`material_profile`?e=`${a(`inventory.assignMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location})}\n\n${a(`inventory.assignProfileMismatchMessage`,{spoolProfile:p.spoolProfile||a(`common.unknown`),trayProfile:p.trayProfile||a(`common.unknown`),location:p.location})}`:p.type===`partial_profile`&&(e=`${a(`inventory.assignPartialMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location})}\n\n${a(`inventory.assignProfileMismatchMessage`,{spoolProfile:p.spoolProfile||a(`common.unknown`),trayProfile:p.trayProfile||a(`common.unknown`),location:p.location})}`),e=`${e}\n\n${a(`inventory.assignReconfigureNote`)}`,(0,G.jsx)(ef,{title:a(`inventory.assignMismatchTitle`),message:e,confirmText:a(`inventory.assignMismatchConfirm`),variant:`warning`,isLoading:L.isPending,onConfirm:te,onCancel:()=>{L.isPending||(f(!1),g(null),m(null))}})})()]}):null}function H1e({isOpen:e,onClose:t,tagId:n,untaggedSpools:r,onLink:i}){let{t:a}=U(),[o,s]=(0,y.useState)(null),c=(0,y.useCallback)(()=>{s(null),t()},[t]),l=(0,y.useCallback)(e=>{e.key===`Escape`&&c()},[c]);return(0,y.useEffect)(()=>(e&&(document.addEventListener(`keydown`,l),document.body.style.overflow=`hidden`),()=>{document.removeEventListener(`keydown`,l),document.body.style.overflow=``}),[e,l]),e?(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 animate-fade-in`,onClick:c,children:(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-xl shadow-2xl w-full max-w-lg mx-4 animate-slide-up`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b border-zinc-700`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-base font-semibold text-zinc-100`,children:a(`spoolbuddy.dashboard.linkTagTitle`,`Link Tag to Spool`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-500 font-mono`,children:n})]}),(0,G.jsx)(`button`,{onClick:c,className:`p-2 rounded-lg text-zinc-500 hover:text-zinc-300 hover:bg-zinc-700 transition-colors`,children:(0,G.jsx)(td,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`px-5 py-4 space-y-3 max-h-[400px] overflow-y-auto`,children:[(0,G.jsx)(`p`,{className:`text-sm text-zinc-400`,children:a(`spoolbuddy.dashboard.selectSpool`,`Select a spool to link this tag to:`)}),r.length===0?(0,G.jsx)(`div`,{className:`text-center py-8 text-zinc-500`,children:a(`spoolbuddy.dashboard.noUntagged`,`No spools without tags found`)}):(0,G.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(e),className:`w-full flex items-center gap-3 p-3 rounded-lg border-2 transition-all text-left ${o?.id===e.id?`border-green-500 bg-green-500/10`:`border-zinc-700 hover:border-green-500/50 hover:bg-zinc-700/50`}`,children:[(0,G.jsx)(G9,{color:wf(e.rgba),isEmpty:!1,size:40}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`font-medium text-zinc-100 truncate`,children:e.color_name||`Unknown color`}),(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,G.jsxs)(`div`,{className:`text-sm text-zinc-400 truncate`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]})]}),(0,G.jsxs)(`div`,{className:`text-sm font-mono text-zinc-500`,children:[Math.max(0,e.label_weight-e.weight_used),`g`]})]},e.id))})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 px-5 py-4 border-t border-zinc-700`,children:[(0,G.jsx)(`button`,{onClick:c,className:`px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:a(`common.cancel`,`Cancel`)}),(0,G.jsx)(`button`,{onClick:()=>{o&&(i(o),s(null))},disabled:!o,className:`px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors min-h-[44px]`,children:a(`spoolbuddy.dashboard.linkTag`,`Link Tag`)})]})]})}):null}function U1e(e){return e?e.replace(/[^0-9a-f]/gi,``).toUpperCase():``}function W1e(e,t){let n=U1e(e),r=U1e(t);return!n||!r?!1:n===r?!0:n.endsWith(r)||r.endsWith(n)}var G1e=[`#00AE42`,`#FF6B35`,`#3B82F6`,`#EF4444`,`#A855F7`,`#FBBF24`,`#14B8A6`,`#EC4899`,`#F97316`,`#22C55E`];function K1e(){let{t:e}=U(),[t,n]=(0,y.useState)(0);(0,y.useEffect)(()=>{let e=setInterval(()=>{n(e=>(e+1)%G1e.length)},5e3);return()=>clearInterval(e)},[]);let r=G1e[t];return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,G.jsxs)(`div`,{className:`relative mb-6 flex items-center justify-center`,style:{width:160,height:160},children:[(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:[0,1].map(e=>(0,G.jsx)(`div`,{className:`absolute rounded-full border spoolbuddy-optimized-ping`,style:{width:80,height:80,borderColor:`${r}4D`,transition:`border-color 140ms linear`,animationDelay:`${e*.8}s`}},e))}),(0,G.jsxs)(`div`,{className:`relative overflow-hidden rounded-full`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 rounded-full opacity-30 spoolbuddy-spool-glow`,style:{background:`radial-gradient(circle, ${r} 0%, transparent 70%)`}}),(0,G.jsx)(`div`,{className:`relative`,style:{transition:`opacity 140ms linear`},children:(0,G.jsx)(G9,{color:r,isEmpty:!1,size:100})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xl font-medium text-zinc-300`,children:e(`spoolbuddy.dashboard.readyToScan`,`Ready to scan`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-500`,children:e(`spoolbuddy.dashboard.idleMessage`,`Place a spool on the scale to identify it`)})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex items-center gap-2 text-sm text-zinc-600`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z`})}),(0,G.jsx)(`span`,{children:e(`spoolbuddy.dashboard.nfcHint`,`NFC tag will be read automatically`)})]})]})}function q1e(){let{t:e}=U();return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,G.jsx)(`div`,{className:`relative mb-6 flex items-center justify-center`,style:{width:160,height:160},children:(0,G.jsx)(`div`,{className:`w-24 h-24 rounded-full bg-zinc-800 flex items-center justify-center`,children:(0,G.jsx)(`svg`,{className:`w-12 h-12 text-zinc-600`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,d:`M18.364 5.636a9 9 0 010 12.728m0 0l-12.728-12.728m12.728 12.728L5.636 5.636m12.728 0a9 9 0 00-12.728 0m0 12.728a9 9 0 010-12.728`})})})}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-lg font-medium text-zinc-500`,children:e(`spoolbuddy.status.deviceOffline`,`Device Offline`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-600`,children:e(`spoolbuddy.status.connectDisplay`,`Connect the SpoolBuddy display to scan spools`)})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex items-center gap-2 text-xs text-zinc-600`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M8.111 16.404a5.5 5.5 0 017.778 0M12 20h.01m-7.08-7.071c3.904-3.905 10.236-3.905 14.14 0M1.394 9.393c5.857-5.857 15.355-5.857 21.213 0`})}),(0,G.jsx)(`span`,{children:e(`spoolbuddy.status.waitingConnection`,`Waiting for device connection...`)})]})]})}function J1e(){let{sbState:e,selectedPrinterId:t}=lr(),{t:n}=U(),{showToast:r}=Hd(),{data:i}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,staleTime:300*1e3}),a=i?.spoolman_enabled===`true`&&!!i?.spoolman_url,{data:o=[],refetch:s}=K({queryKey:a?[`spoolman-inventory-spools`]:[`inventory-spools`],queryFn:()=>a?Z.getSpoolmanInventorySpools(!1):Z.getSpools(!1),enabled:i!==void 0}),{data:c=[]}=K({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:a,staleTime:3*1e3,refetchInterval:3*1e3,refetchIntervalInBackground:!1}),{data:l=[]}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),u=Co({queries:l.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id),refetchInterval:1e4,select:e=>({connected:e?.connected,awaiting_plate_clear:e?.awaiting_plate_clear===!0})}))}),d=l.map((e,t)=>({printer:e,pending:u[t]?.data?.awaiting_plate_clear===!0})).filter(e=>e.pending),f=co(),p=q({mutationFn:e=>Z.clearPlate(e),onSuccess:(e,t)=>{f.setQueryData([`printerStatus`,t],e=>e&&{...e,awaiting_plate_clear:!1}),r(n(`spoolbuddy.dashboard.plateClearedToast`,`Plate marked as cleared`),`success`)},onError:()=>{r(n(`spoolbuddy.dashboard.plateClearFailed`,`Could not mark plate as cleared`),`error`)}}),m=q({mutationFn:e=>Z.unassignSpoolmanSlot(e),onSuccess:()=>{f.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),f.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},onError:()=>r(n(`inventory.unassignFailed`,`Failed to unassign spool`),`error`)}),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(null),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(null),M=e.matchedSpool?.tag_uid??e.unknownTagUid??null,N=e.weight,P=e.weightStable,F=(0,y.useRef)(null);N===null?F.current=null:(F.current===null||Math.abs(N-F.current)>=3||P)&&(F.current=N);let I=F.current,L=(0,y.useMemo)(()=>{if(e.matchedSpool?.id){let t=o.find(t=>t.id===e.matchedSpool?.id);if(t)return t}return h&&(o.find(e=>W1e(e.tag_uid,h))||A)||null},[h,e.matchedSpool,o,A]),R=(0,y.useMemo)(()=>{if(L&&!A)return L;let t=e.matchedSpool;return t?{id:t.id,tag_uid:t.tag_uid,material:t.material,subtype:t.subtype,color_name:t.color_name,rgba:t.rgba,brand:t.brand,label_weight:t.label_weight,core_weight:t.core_weight,weight_used:t.weight_used}:null},[L,A,e.matchedSpool]),z=a&&R!=null?c.some(e=>e.spoolman_spool_id===R.id):!1,B=(0,y.useMemo)(()=>a?o.filter(e=>!e.tag_uid&&!e.tray_uuid&&!e.archived_at):o.filter(e=>!e.tag_uid&&!e.archived_at),[o,a]);(0,y.useEffect)(()=>{if(M){let e=b===M;(h!==null&&h!==M||!e&&h!==M)&&(g(M),v(null),x(null),j(null)),!e&&N!==null&&P&&v(Math.round(Math.max(0,N)))}else b&&(g(null),x(null),v(null),j(null))},[M,N,P,h,b]);let V=()=>{x(h)},ee=async t=>{if(h)try{if(a){let i=e.unknownTagUid||void 0,a=!e.unknownTagUid&&e.unknownTrayUuid?e.unknownTrayUuid:void 0;if(!i&&!a){r(n(`spoolman.linkFailed`),`error`);return}let o=await Z.linkTagToSpoolmanSpool(t.id,{tray_uuid:a,tag_uid:i});if(!o){r(n(`spoolman.linkFailed`),`error`);return}let{id:s,material:c,subtype:l,color_name:u,rgba:d,brand:f,label_weight:p,core_weight:m,weight_used:h}=o;j({id:s,material:c,subtype:l,color_name:u,rgba:d,brand:f,label_weight:p,core_weight:m,weight_used:h}),r(n(`spoolman.linkSuccess`),`success`)}else await Z.linkTagToSpool(t.id,{tag_uid:h,tag_type:`generic`,data_origin:`nfc_link`});s()}catch(e){console.error(`Failed to link tag:`,e),r(n(`spoolman.linkFailed`),`error`)}finally{C(!1)}},te=async()=>{if(h){k(!0);try{let t=ne??_;if(a){let n=await Z.createSpoolmanInventorySpool({material:`PLA`,subtype:null,color_name:null,rgba:null,extra_colors:null,effect_type:null,brand:null,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,nozzle_temp_min:null,nozzle_temp_max:null,note:null,added_full:null,last_used:null,encode_time:null,tag_uid:null,tray_uuid:null,data_origin:null,tag_type:null,cost_per_kg:null,last_scale_weight:t===null?null:Math.round(t),last_weighed_at:t===null?null:new Date().toISOString(),category:null,low_stock_threshold_pct:null});await Z.linkTagToSpoolmanSpool(n.id,{tag_uid:e.unknownTagUid||void 0,tray_uuid:!e.unknownTagUid&&e.unknownTrayUuid?e.unknownTrayUuid:void 0})}else await Z.createSpool({material:`PLA`,subtype:null,color_name:null,rgba:null,extra_colors:null,effect_type:null,brand:null,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,nozzle_temp_min:null,nozzle_temp_max:null,note:null,added_full:null,last_used:null,encode_time:null,tag_uid:h,tray_uuid:null,data_origin:`spoolbuddy`,tag_type:`generic`,cost_per_kg:null,last_scale_weight:t===null?null:Math.round(t),last_weighed_at:t===null?null:new Date().toISOString(),category:null,low_stock_threshold_pct:null})}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`Failed to quick-add spool:`,t),r(t||n(`spoolbuddy.errors.quickAddFailed`,`Failed to add spool`),`error`)}finally{D(!1),k(!1),s()}}},ne=N!==null&&(M===h||M===null&&h!==null)?N:null,re=o.length,ie=new Set(o.map(e=>e.material)).size,ae=new Set(o.filter(e=>e.brand).map(e=>e.brand)).size;return(0,G.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-6 px-4 py-1.5 bg-zinc-800/50 rounded-xl border border-zinc-700/50 mb-3 shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:re}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.inventory.spools`,`Spools`)})]}),(0,G.jsx)(`div`,{className:`w-px h-5 bg-zinc-700`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:ie}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.material`,`Materials`)})]}),(0,G.jsx)(`div`,{className:`w-px h-5 bg-zinc-700`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:ae}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.brand`,`Brands`)})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex gap-4 min-h-0`,children:[(0,G.jsxs)(`div`,{className:`w-5/12 flex flex-col min-h-0`,children:[(0,G.jsxs)(`div`,{className:`border border-dashed border-zinc-700/50 rounded-xl p-4`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-3`,children:n(`spoolbuddy.dashboard.device`,`Device`)}),(0,G.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full ${e.deviceOnline?`bg-green-500`:`bg-red-500`}`}),(0,G.jsx)(`span`,{className:`text-base text-zinc-400`,children:e.deviceOnline?n(`spoolbuddy.status.online`,`Online`):n(`spoolbuddy.status.offline`,`Disconnected`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-zinc-800/50 rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4 ${e.deviceOnline?`text-green-500`:`text-zinc-500`}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M3 6l3 1m0 0l-3 9a5.002 5.002 0 006.001 0M6 7l3 9M6 7l6-2m6 2l3-1m-3 1l-3 9a5.002 5.002 0 006.001 0M18 7l3 9m-3-9l-6-2m0-2v2m0 16V5m0 16H9m3 0h3`})}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.scaleWeight`,`Scale`)})]}),(0,G.jsx)(`span`,{className:`text-lg font-mono font-semibold text-zinc-100`,children:I===null?`—`:`${Math.abs(I)<=20?0:Math.round(Math.max(0,I))}g`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-zinc-800/50 rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4 ${e.deviceOnline?`text-green-500`:`text-zinc-500`}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z`})}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:`NFC`})]}),(0,G.jsx)(`span`,{className:`text-sm font-medium ${M?`text-green-500`:`text-zinc-500`}`,children:M?n(`spoolbuddy.dashboard.tagDetected`,`Tag detected`):n(`spoolbuddy.dashboard.noTag`,`No tag`)})]})]})]}),l.length>0&&(0,G.jsxs)(`div`,{className:`mt-3 border border-dashed border-zinc-700/50 rounded-xl p-4`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-2.5`,children:n(`spoolbuddy.dashboard.printers`,`Printers`)}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2 overflow-hidden`,children:l.map((e,t)=>{let n=u[t]?.data?.connected??!1;return(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2.5 py-1 bg-zinc-800/50 rounded-lg`,title:`${e.name} — ${n?`Online`:`Offline`}`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${n?`bg-green-500`:`bg-zinc-600`}`}),(0,G.jsx)(`span`,{className:`text-xs text-zinc-400 truncate max-w-[100px]`,children:e.name})]},e.id)})}),d.length>0&&(0,G.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,"data-testid":`plate-clear-section`,"aria-label":n(`spoolbuddy.dashboard.plateReadyLabel`,`Plates ready to clear`),children:d.map(({printer:e})=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>p.mutate(e.id),disabled:p.isPending,"data-testid":`plate-clear-button-${e.id}`,title:n(`spoolbuddy.dashboard.plateReady`,`Plate ready: {{name}}`,{name:e.name}),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-amber-500/10 hover:bg-amber-500/20 active:bg-amber-500/30 border border-amber-500/30 text-amber-200 transition-colors disabled:opacity-60 disabled:cursor-wait`,children:[(0,G.jsxs)(`svg`,{className:`w-3 h-3 shrink-0`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,G.jsx)(`path`,{d:`M12 9v4`}),(0,G.jsx)(`path`,{d:`M12 17h.01`}),(0,G.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`})]}),(0,G.jsx)(`span`,{className:`text-xs truncate max-w-[100px]`,children:e.name}),(0,G.jsx)(`span`,{className:`text-xs opacity-70`,"aria-hidden":`true`,children:`·`}),(0,G.jsx)(`span`,{className:`text-xs font-medium`,children:n(`spoolbuddy.dashboard.plateClearAction`,`Clear`)})]},e.id))})]})]}),(0,G.jsx)(`div`,{className:`w-7/12 min-h-0`,children:(0,G.jsxs)(`div`,{className:`border border-dashed border-zinc-700/50 rounded-xl p-6 h-full flex flex-col`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-4 shrink-0`,children:n(`spoolbuddy.dashboard.currentSpool`,`Current Spool`)}),(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:e.deviceOnline?(L||e.matchedSpool)&&h&&b!==h?(0,G.jsx)(S1e,{spool:(()=>{let t=L??e.matchedSpool;return{id:t.id,tag_uid:h,material:t.material,subtype:t.subtype,color_name:t.color_name,rgba:t.rgba,brand:t.brand,label_weight:t.label_weight,core_weight:t.core_weight,weight_used:t.weight_used}})(),scaleWeight:ne??_,onSyncWeight:()=>s(),onAssignToAms:()=>T(!0),isAssigned:z,onUnassignFromAms:z&&L?.id!=null?()=>m.mutate(L.id):void 0,onClose:V}):M&&h&&!L&&!e.matchedSpool&&b!==h?(0,G.jsx)(C1e,{tagUid:h,scaleWeight:ne??_,onLinkSpool:B.length>0?()=>C(!0):void 0,onAddToInventory:()=>D(!0),onClose:V}):(0,G.jsx)(K1e,{}):(0,G.jsx)(q1e,{})})]})})]}),R&&!A&&h&&(0,G.jsx)(V1e,{isOpen:w,onClose:()=>T(!1),spool:R,printerId:t,spoolmanMode:a}),h&&(0,G.jsx)(H1e,{isOpen:S,onClose:()=>C(!1),tagId:h,untaggedSpools:B,onLink:ee}),E&&h&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,children:(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-2xl p-6 mx-4 max-w-sm w-full border border-zinc-700`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100 mb-3`,children:n(`spoolbuddy.modal.addToInventory`,`Add to Inventory`)}),(0,G.jsxs)(`div`,{className:`flex gap-2.5 p-3 bg-amber-500/10 border border-amber-500/20 rounded-lg mb-4`,children:[(0,G.jsx)(`svg`,{className:`w-5 h-5 text-amber-500 shrink-0 mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z`})}),(0,G.jsx)(`p`,{className:`text-sm text-amber-200/80`,children:n(`spoolbuddy.modal.quickAddHint`,`For best results, add the spool in the Bambuddy web interface first (with material, color, brand), then use "Assign Spool" here to assign the NFC tag.`)})]}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-400 mb-1`,children:n(`spoolbuddy.modal.quickAddDesc`,`This will create a basic PLA spool entry with this NFC tag. You can edit the details later in Bambuddy.`)}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 font-mono mb-5`,children:h}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(`button`,{onClick:()=>D(!1),className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:n(`common.cancel`,`Cancel`)}),(0,G.jsx)(`button`,{onClick:te,disabled:O,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-50 transition-colors min-h-[44px]`,children:O?n(`common.saving`,`Saving...`):n(`spoolbuddy.modal.addAnyway`,`Add Anyway`)})]})]})})]})}function Y1e(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function X1e(e){return e?{O1D:`H2D`,O1E:`H2D Pro`,O2D:`H2D Pro`,O1C:`H2C`,O1C2:`H2C`,O1S:`H2S`,"BL-P001":`X1C`,"BL-P002":`X1`,"BL-P003":`X1E`,N6:`X2D`,N9:`A2L`,C11:`P1S`,C12:`P1P`,C13:`P2S`,N2S:`A1`,N1:`A1 Mini`,X1C:`X1C`,X1:`X1`,X1E:`X1E`,X2D:`X2D`,P1S:`P1S`,P1P:`P1P`,P2S:`P2S`,A1:`A1`,"A1 Mini":`A1 Mini`,A2L:`A2L`,H2D:`H2D`,"H2D Pro":`H2D Pro`,H2C:`H2C`,H2S:`H2S`}[e]||e:``}function X9(e){return!e.tray_type||e.tray_type===``}function Z1e(e){return e?`#${e.slice(0,6)}`:`#808080`}function Q1e(){let{selectedPrinterId:e,setAlert:t}=lr(),{t:n}=U(),r=co(),{showToast:i}=Hd(),{data:a}=K({queryKey:[`printerStatus`,e],queryFn:()=>Z.getPrinterStatus(e),enabled:e!==null,staleTime:30*1e3}),{data:o}=K({queryKey:[`printer`,e],queryFn:()=>Z.getPrinter(e),enabled:e!==null,staleTime:60*1e3}),{data:s}=K({queryKey:[`slotPresets`,e],queryFn:()=>Z.getSlotPresets(e),enabled:e!==null,staleTime:120*1e3}),{data:c}=K({queryKey:[`settings`],queryFn:()=>Z.getSettings(),staleTime:300*1e3}),{data:l}=K({queryKey:[`spoolman-status`],queryFn:Z.getSpoolmanStatus,staleTime:60*1e3}),u=l?.enabled&&l?.connected,{data:d}=K({queryKey:[`linked-spools`],queryFn:Z.getLinkedSpools,enabled:!!u,staleTime:30*1e3}),f=d?.linked,{data:p=[]}=K({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:!!u,staleTime:30*1e3}),{data:m=[]}=K({queryKey:[`spoolman-inventory-spools`],queryFn:()=>Z.getSpoolmanInventorySpools(!1),enabled:!!u,staleTime:30*1e3}),{data:h}=K({queryKey:[`spool-assignments`,e],queryFn:()=>Z.getAssignments(e),enabled:e!==null,staleTime:30*1e3}),g=(0,y.useMemo)(()=>{let e={};if(!h)return e;for(let t of h){let n=t.spool;if(n&&n.label_weight>0&&n.weight_used!=null){let r=Math.round(Math.max(0,n.label_weight-n.weight_used)/n.label_weight*100);e[`${t.ams_id}-${t.tray_id}`]=r}}return e},[h]),_=o?.serial_number??``,v=(0,y.useCallback)((t,n,r)=>{if(e!==null&&p.length&&m.length){let r=p.find(r=>r.printer_id===e&&r.ams_id===t&&r.tray_id===n);if(r){let e=m.find(e=>e.id===r.spoolman_spool_id);if(e&&(e.label_weight??0)>0)return Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100)}}if(f&&_){let e=(r?.tray_uuid||r?.tag_uid||Ap(_,t,n))?.toUpperCase(),i=Dp(e?f[e]:void 0);if(i!==null)return i}return null},[f,_,e,p,m]),b=a?.connected??!1,x=(0,y.useRef)({});(0,y.useEffect)(()=>{e&&a?.ams&&a.ams.length>0&&(x.current[e]=a.ams)},[a?.ams,e]);let S=(0,y.useMemo)(()=>{let t=a?.ams;return t&&t.length>0?t:(e?x.current[e]:null)??[]},[a?.ams,e]),C=(0,y.useMemo)(()=>S.filter(e=>!e.is_ams_ht),[S]),w=(0,y.useMemo)(()=>S.filter(e=>e.is_ams_ht),[S]),T=(0,y.useMemo)(()=>{let e={};if(!f||!_)return e;for(let t of C)for(let n=0;n<(t.tray?.length??0);n++){let r=t.tray[n],i=v(t.id,n,X9(r)?null:r);i!==null&&(e[`${t.id}-${n}`]=i)}return e},[f,_,C,v]),E=(0,y.useRef)(void 0),D=a?.tray_now;D!==void 0&&D!==255?E.current=D:D===255&&(E.current=void 0);let O=D!==void 0&&D!==255?D:E.current,k=o?.nozzle_count===2||a?.temperatures?.nozzle_2!==void 0,A=(0,y.useMemo)(()=>[...a?.vt_tray??[]].sort((e,t)=>(e.id??254)-(t.id??254)),[a?.vt_tray]),j=c?{humidityGood:Number(c.ams_humidity_good)||40,humidityFair:Number(c.ams_humidity_fair)||60,tempGood:Number(c.ams_temp_good)||28,tempFair:Number(c.ams_temp_fair)||35}:void 0,M=(0,y.useRef)({});(0,y.useEffect)(()=>{a?.ams_extruder_map&&Object.keys(a.ams_extruder_map).length>0&&(M.current=a.ams_extruder_map)},[a?.ams_extruder_map]);let N=a?.ams_extruder_map&&Object.keys(a.ams_extruder_map).length>0?a.ams_extruder_map:M.current,P=(0,y.useCallback)(e=>{if(!k)return null;let t=N[String(e)],n=e>=128?e-128:e;return(t===void 0?n:t)===1?`L`:`R`},[k,N]),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(null),[z,B]=(0,y.useState)(null),[V,ee]=(0,y.useState)(null),te=(0,y.useCallback)((e,t)=>h?.find(n=>n.ams_id===Number(e)&&n.tray_id===Number(t)),[h]),ne=(0,y.useCallback)((e,t,n)=>{if(!f||!_)return;let r=(n?.tray_uuid||n?.tag_uid||Ap(_,e,t))?.toUpperCase();return r?f[r]:void 0},[f,_]),re=q({mutationFn:({printerId:e,amsId:t,trayId:n})=>Z.unassignSpool(e,t,n),onSuccess:()=>{r.invalidateQueries({queryKey:[`spool-assignments`,e]}),r.invalidateQueries({queryKey:[`spool-assignments`]}),i(n(`inventory.unassignSuccess`,`Spool unassigned`),`success`),R(null)}}),ie=q({mutationFn:e=>Z.unlinkSpool(e),onSuccess:e=>{i(n(`spoolman.unlinkSuccess`)||e?.message,`success`),r.invalidateQueries({queryKey:[`linked-spools`]}),r.invalidateQueries({queryKey:[`unlinked-spools`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),r.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),R(null)},onError:e=>{i(e.message||n(`spoolman.unlinkFailed`),`error`)}}),ae=q({mutationFn:e=>Z.unassignSpoolmanSlot(e),onSuccess:()=>{i(n(`inventory.unassignSuccess`,`Spool unassigned`),`success`),r.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),r.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),r.invalidateQueries({queryKey:[`unlinked-spools`]}),r.invalidateQueries({queryKey:[`linked-spools`]}),R(null)},onError:e=>{i(e.message||n(`inventory.assignFailed`,`Failed to unassign spool`),`error`)}}),oe=(0,y.useCallback)(e=>O===void 0?null:e<=3&&Math.floor(O/4)===e?O%4:e>=128&&e<=135&&O===Tp(e,0,!1)?0:null,[O]),se=(0,y.useCallback)((e,t,n)=>{let r=Tp(e,t,!1),i=s?.[r],a=N[String(e)],o=e>=128?e-128:e,c=a===void 0?o:a;R({amsId:e,trayId:t,trayCount:n&&e>=128?1:4,tray:n,trayType:n?.tray_type||void 0,trayColor:n?.tray_color||void 0,traySubBrands:n?.tray_sub_brands||void 0,trayInfoIdx:n?.tray_info_idx||void 0,extruderId:k?c:void 0,caliIdx:n?.cali_idx,savedPresetId:i?.preset_id,location:`${Y1e(e)} Slot ${t+1}`})},[s,N,k]),H=(0,y.useCallback)(e=>{let t=e.id??254,n=t-254,r=s?.[1020+n];R({amsId:255,trayId:n,trayCount:1,tray:X9(e)?null:e,trayType:e.tray_type||void 0,trayColor:e.tray_color||void 0,traySubBrands:e.tray_sub_brands||void 0,trayInfoIdx:e.tray_info_idx||void 0,extruderId:k?+(t===254):void 0,caliIdx:e.cali_idx,savedPresetId:r?.preset_id,location:k?t===254?`Ext-L`:`Ext-R`:`External`})},[s,k]),ce=(0,y.useCallback)(()=>{if(!L)return;let{tray:e,location:t,...n}=L;R(null),I(n)},[L]),le=(0,y.useCallback)(()=>{if(!L||!e)return;let{amsId:t,trayId:n,trayType:r,trayColor:i,location:a}=L;R(null),B({printerId:e,amsId:t,trayId:n,trayInfo:{type:r||``,material:r,color:i?.slice(0,6)||``,location:a}})},[L,e]),ue=(0,y.useCallback)(()=>{if(!L||!e)return;let{amsId:t,trayId:n,tray:r}=L,i=(r?.tray_uuid||r?.tag_uid||Ap(_,t,n))?.toUpperCase()||``;R(null),ee({tagUid:r?.tag_uid||i,trayUuid:r?.tray_uuid||``,printerId:e,amsId:t,trayId:n})},[L,e,_]),de=(0,y.useCallback)(()=>{if(!L||!e)return;let{amsId:t,trayId:n}=L;re.mutate({printerId:e,amsId:t,trayId:n})},[L,e,re]);(0,y.useEffect)(()=>{if(!b&&e){t({type:`warning`,message:n(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)});return}for(let e of S){let n=e.tray||[];for(let r=0;r=0&&i.remain<15&&i.tray_type){let n=e.id===254||e.id===255,a=!n&&e.id>=128,o=wp(e.id,r,a,n);t({type:`warning`,message:`Low Filament: ${i.tray_type} (${o}) - ${i.remain}% remaining`});return}}}t(null)},[S,b,e,t,n]);let fe=(0,y.useMemo)(()=>{let e=[];for(let t of w){let n=t.tray?.[0]||{id:0,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},r=v(t.id,0,X9(n)?null:n),i=g[`${t.id}-0`]??null,a=n.remain!=null&&n.remain>=0?n.remain:null,o=i===0&&a!==null&&a>0?null:i;e.push({key:`ht-${t.id}`,label:Y1e(t.id),tray:n,isEmpty:X9(n),isActive:oe(t.id)===0,temp:t.temp,humidity:t.humidity,nozzleSide:P(t.id),effectiveFill:r??o??a,onClick:()=>se(t.id,0,X9(n)?null:n)})}for(let t of A){let r=t.id??254,i=k&&O===254?r===254&&a?.active_extruder===1||r===255&&a?.active_extruder===0:O===r,o=r-254,s=v(255,o,X9(t)?null:t),c=g[`255-${o}`]??null,l=t.remain!=null&&t.remain>=0?t.remain:null,u=c===0&&l!==null&&l>0?null:c;e.push({key:`ext-${r}`,label:k?r===254?n(`printers.extL`,`Ext-L`):n(`printers.extR`,`Ext-R`):n(`printers.ext`,`Ext`),tray:t,isEmpty:X9(t),isActive:i,nozzleSide:null,effectiveFill:s??u??l,onClick:()=>H(t)})}return e},[w,A,k,O,a?.active_extruder,n,oe,P,se,H,g,v]);return(0,G.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,G.jsx)(`div`,{className:`flex-1 min-h-0`,children:e?b?S.length===0&&A.length===0?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,G.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,G.jsx)(qc,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.noData`,`No AMS detected`)}),(0,G.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.ams.connectAms`,`Connect an AMS to see filament slots`)})]})}):(0,G.jsxs)(`div`,{className:`flex flex-col gap-3 h-full`,children:[(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:C.map(e=>(0,G.jsx)(L1e,{unit:e,activeSlot:oe(e.id),onConfigureSlot:se,isDualNozzle:k,nozzleSide:P(e.id),thresholds:j,fillOverrides:g,spoolmanFillOverrides:T},e.id))}),fe.length>0&&(0,G.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-3`,children:fe.map(({key:e,label:t,tray:n,isEmpty:r,isActive:i,temp:a,humidity:o,nozzleSide:s,effectiveFill:c,onClick:l})=>{let u=Z1e(n.tray_color);return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg px-3 py-2 cursor-pointer hover:bg-bambu-dark-secondary/80 transition-all flex items-center gap-3 ${i?`ring-2 ring-bambu-green`:``}`,onClick:l,children:[(0,G.jsxs)(`div`,{className:`relative w-10 h-10 flex-shrink-0`,children:[r?(0,G.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-gray-600`})}):(0,G.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:u}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:u,style:{filter:`brightness(0.85)`}}),(0,G.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]}),i&&(0,G.jsx)(`div`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1.5 h-1.5 bg-bambu-green rounded-full`})]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`text-xs text-white/50 font-medium truncate`,children:t}),s&&(0,G.jsx)(K9,{side:s})]}),(0,G.jsx)(`div`,{className:`text-sm text-white/80 truncate`,children:r?`Empty`:n.tray_type||`?`}),(a!=null||o!=null)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[a!=null&&(0,G.jsx)(F1e,{temp:a,goodThreshold:j?.tempGood,fairThreshold:j?.tempFair}),o!=null&&(0,G.jsx)(P1e,{humidity:o,goodThreshold:j?.humidityGood,fairThreshold:j?.humidityFair})]})]}),!r&&c!=null&&c>=0&&(0,G.jsx)(`div`,{className:`w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0 flex flex-col-reverse`,children:(0,G.jsx)(`div`,{className:`w-full rounded-full`,style:{height:`${c}%`,backgroundColor:Ep(c)}})})]},e)})})]}):(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,G.jsx)(`div`,{className:`text-center text-white/50`,children:(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)})})}):(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,G.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.noPrinter`,`No printer selected`)}),(0,G.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.ams.selectPrinter`,`Select a printer from the top bar`)})]})})}),F&&e&&(0,G.jsx)(PU,{isOpen:!!F,onClose:()=>I(null),printerId:e,slotInfo:F,printerModel:X1e(o?.model??null)||void 0,nozzleDiameter:zp(a,F.amsId),fullScreen:!0,onSuccess:()=>{r.invalidateQueries({queryKey:[`slotPresets`,e]}),r.invalidateQueries({queryKey:[`printerStatus`,e]})}}),L&&e&&(()=>{let t=te(L.amsId,L.trayId),r=ne(L.amsId,L.trayId,L.tray),i=u?p.find(t=>t.printer_id===e&&t.ams_id===L.amsId&&t.tray_id===L.trayId):void 0,a=i?m.find(e=>e.id===i.spoolman_spool_id)??null:null;return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:()=>R(null)}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-sm mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[L.trayColor&&(0,G.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:{backgroundColor:`#${L.trayColor.slice(0,6)}`}}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:L.location}),L.traySubBrands&&(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,L.traySubBrands,`)`]})]}),(0,G.jsx)(`button`,{onClick:()=>R(null),className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(td,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-2`,children:[!u&&t?.spool&&(0,G.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`inventory.assignedSpool`,`Assigned spool`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.spool.rgba&&(0,G.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:Tf(t.spool.rgba)}),(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[t.spool.brand?`${t.spool.brand} `:``,t.spool.material,t.spool.subtype?` ${t.spool.subtype}`:``,t.spool.color_name?` - ${t.spool.color_name}`:``]}),(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0 ml-auto`,children:[`#`,t.spool.id]})]})]}),u&&r&&!a&&(0,G.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`spoolman.linkedSpool`,`Linked spool`)}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[`Spoolman #`,r.id,r.remaining_weight==null?``:` (${Math.round(r.remaining_weight)}g)`]})})]}),u&&a&&(0,G.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`inventory.assignedSpool`,`Assigned spool`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a.rgba&&(0,G.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:Tf(a.rgba)}),(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[a.brand?`${a.brand} `:``,a.material,a.subtype?` ${a.subtype}`:``,a.color_name?` - ${a.color_name}`:``]})]})]}),(0,G.jsxs)(`button`,{onClick:ce,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-blue transition-colors text-left`,children:[(0,G.jsx)(tu,{className:`w-5 h-5 text-bambu-blue flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:n(`configureAmsSlot.title`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.configureDesc`,`Set filament preset, K-profile, and color`)})]})]}),!u&&(Bp(L?.tray)?null:t?(0,G.jsxs)(`button`,{onClick:de,disabled:re.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left`,children:[(0,G.jsx)(zu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`,`Unassign`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unassignDesc`,`Remove inventory spool from this slot`)})]})]}):(0,G.jsxs)(`button`,{onClick:le,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors text-left`,children:[(0,G.jsx)(Sl,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.assignSpool`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.assignDesc`,`Track a spool from your inventory`)})]})]})),u&&(r?.id?(0,G.jsxs)(`button`,{onClick:()=>ie.mutate(r.id),disabled:ie.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left active:opacity-50`,children:[(0,G.jsx)(zu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unlinkDesc`,`Remove Spoolman link from this slot`)})]})]}):a?(0,G.jsxs)(`button`,{onClick:()=>ae.mutate(a.id),disabled:ae.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left active:opacity-50`,children:[(0,G.jsx)(zu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unassignDesc`,`Remove inventory spool from this slot`)})]})]}):(0,G.jsxs)(`button`,{onClick:ue,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors text-left`,children:[(0,G.jsx)(Yc,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.assignSpool`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.linkDesc`,`Link a Spoolman spool to this slot`)})]})]}))]})]})]})})(),z&&(0,G.jsx)(YH,{isOpen:!!z,onClose:()=>{B(null),r.invalidateQueries({queryKey:[`spool-assignments`,e]}),r.invalidateQueries({queryKey:[`spool-assignments`]})},printerId:z.printerId,amsId:z.amsId,trayId:z.trayId,trayInfo:z.trayInfo,spoolmanEnabled:!!u}),V&&(0,G.jsx)(qH,{isOpen:!!V,onClose:()=>ee(null),tagUid:V.tagUid,trayUuid:V.trayUuid,printerId:V.printerId,amsId:V.amsId,trayId:V.trayId})]})}function $1e({type:e,deviceId:t,onClose:n}){let{t:r}=U(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)(!1);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!i&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i,n]);let f=(0,y.useCallback)(async()=>{a(!0),s(``),l(``),d(!0);try{s(r(`spoolbuddy.diagnostic.queuing`,`Queuing diagnostic on device... +`)),await Cd.queueDiagnostics(t,e);let n=null,i=0;for(;i<60&&!n;){await new Promise(e=>setTimeout(e,500));try{n=await Cd.getDiagnosticResult(t,e);break}catch{i++,i%4==0&&s(e=>e+`.`)}}if(!n)throw Error(`Diagnostic timed out - device did not report results`);s(n.output),n.success||l(`Exit code: ${n.exit_code}`)}catch(e){l(e instanceof Error?e.message:`Unknown error`),s(``)}finally{a(!1)}},[e,t,r]);return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 animate-fade-in`,onClick:n,children:(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg shadow-xl w-full max-w-2xl mx-4 max-h-[80vh] flex flex-col animate-slide-up`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex justify-between items-center p-4 border-b border-zinc-700`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e===`scale`?r(`spoolbuddy.diagnostic.scaleTitle`,`Scale Diagnostic`):e===`read_tag`?r(`spoolbuddy.diagnostic.readTagTitle`,`Read Tag Diagnostic`):r(`spoolbuddy.diagnostic.nfcTitle`,`NFC Reader Diagnostic`)}),(0,G.jsx)(`button`,{onClick:n,className:`text-zinc-400 hover:text-white transition-colors`,"aria-label":`Close`,children:(0,G.jsx)(td,{size:20})})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-auto p-4 bg-black/50 font-mono text-sm`,children:i?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-green-400`,children:[(0,G.jsx)(`div`,{className:`animate-spin w-4 h-4 border-2 border-green-400 border-t-transparent rounded-full`}),(0,G.jsx)(`span`,{children:r(`spoolbuddy.diagnostic.running`,`Running diagnostic on device...`)})]}):o?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`text-green-400 whitespace-pre-wrap break-words`,children:o}),c&&(0,G.jsxs)(`div`,{className:`text-red-400 mt-2`,children:[`❌ `,c]})]}):u?(0,G.jsx)(`div`,{children:c?(0,G.jsxs)(`div`,{className:`text-red-400`,children:[`ERROR: `,c]}):(0,G.jsx)(`span`,{className:`text-green-400`,children:r(`spoolbuddy.diagnostic.completed`,`Diagnostic completed successfully.`)})}):(0,G.jsxs)(`div`,{className:`text-zinc-500`,children:[r(`spoolbuddy.diagnostic.clickStart`,`Click "Run Diagnostic" to start the hardware diagnostic on`),` `,t,`.`]})}),(0,G.jsxs)(`div`,{className:`flex gap-2 p-4 border-t border-zinc-700 bg-zinc-800`,children:[(0,G.jsx)(`button`,{onClick:f,disabled:i,className:`flex-1 flex items-center justify-center gap-2 bg-green-600 hover:bg-green-700 disabled:bg-gray-600 disabled:cursor-not-allowed px-4 py-2 rounded font-semibold text-white transition-colors`,children:i?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`animate-spin w-4 h-4 border-2 border-white border-t-transparent rounded-full`}),r(`spoolbuddy.diagnostic.runningBtn`,`Running...`)]}):u?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Wl,{size:16}),r(`spoolbuddy.diagnostic.runAgain`,`Run Again`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ml,{size:16}),r(`spoolbuddy.diagnostic.runBtn`,`Run Diagnostic`)]})}),(0,G.jsx)(`button`,{onClick:n,className:`px-4 py-2 rounded bg-zinc-700 hover:bg-zinc-600 text-white font-semibold transition-colors`,children:r(`spoolbuddy.diagnostic.close`,`Close`)})]})]})})}function e0e(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m`:`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`}function t0e(e){if(!e)return`-`;let t=Xf(e);return t?t.toLocaleDateString(void 0,{month:`short`,day:`numeric`})+` `+t.toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`}):`-`}var n0e=[{label:`Off`,value:0},{label:`1m`,value:60},{label:`2m`,value:120},{label:`5m`,value:300},{label:`10m`,value:600},{label:`30m`,value:1800}];function r0e({device:e}){let{t}=U(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(null);return(0,y.useEffect)(()=>{!i&&e.backend_url&&a(e.backend_url)},[e.backend_url,i]),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.nfcReader`,`NFC Reader`)}),(0,G.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.type`,`Type`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:e.nfc_reader_type||`N/A`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.connection`,`Connection`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:e.nfc_connection||`N/A`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.status.status`,`Status`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full ${e.nfc_ok?`bg-green-500`:e.nfc_reader_type?`bg-red-500`:`bg-zinc-600`}`}),(0,G.jsx)(`span`,{className:e.nfc_ok?`text-green-400`:e.nfc_reader_type?`text-red-400`:`text-zinc-500`,children:e.nfc_ok?t(`spoolbuddy.status.nfcReady`,`Ready`):e.nfc_reader_type?t(`common.error`,`Error`):t(`spoolbuddy.settings.notConnected`,`N/A`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.deviceInfo`,`Device Info`)}),(0,G.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.hostname`,`Host`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 truncate ml-2`,children:e.hostname})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`IP`}),(0,G.jsx)(`span`,{className:`text-zinc-300`,children:e.ip_address})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.uptime`,`Uptime`)}),(0,G.jsx)(`span`,{className:`text-zinc-300`,children:e0e(e.uptime_s)})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`ID`}),(0,G.jsx)(`span`,{className:`text-zinc-400 font-mono truncate ml-2`,children:e.device_id})]})]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 space-y-2`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300`,children:t(`spoolbuddy.settings.systemConfig`,`Backend & Auth`)}),(0,G.jsx)(`input`,{value:i,onChange:e=>a(e.target.value),placeholder:`http://192.168.1.100:5000`,className:`w-full px-2 py-1.5 rounded bg-zinc-900 border border-zinc-700 text-zinc-100 text-xs`}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`password`,value:o,onChange:e=>s(e.target.value),placeholder:t(`spoolbuddy.settings.apiTokenPlaceholder`,`API token`),className:`flex-1 px-2 py-1.5 rounded bg-zinc-900 border border-zinc-700 text-zinc-100 text-xs`}),(0,G.jsx)(`button`,{onClick:async()=>{if(!i.trim()){d({type:`error`,text:t(`spoolbuddy.settings.systemFieldsRequired`,`Backend URL is required.`)});return}l(!0),d(null);try{await Cd.updateSystemConfig(e.device_id,i.trim(),o.trim()||void 0),d({type:`ok`,text:t(`spoolbuddy.settings.systemQueued`,`Config queued.`)})}catch(e){d({type:`error`,text:e instanceof Error?e.message:t(`common.error`,`Error`)})}finally{l(!1)}},disabled:c,className:`px-3 py-1.5 rounded bg-green-700 hover:bg-green-600 disabled:bg-zinc-700 text-xs font-medium text-zinc-100`,children:t(`spoolbuddy.settings.saveConfig`,`Save`)})]}),u&&(0,G.jsx)(`div`,{className:`text-xs ${u.type===`ok`?`text-green-400`:`text-red-400`}`,children:u.text})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 flex flex-col gap-2`,children:[(0,G.jsxs)(`button`,{onClick:()=>r(`nfc`),className:`flex-1 bg-blue-700 hover:bg-blue-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,G.jsx)(Ju,{className:`w-4 h-4 text-blue-300 shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium text-blue-100`,children:t(`spoolbuddy.settings.nfcDiagnostic`,`NFC Diagnostic`)})]}),(0,G.jsxs)(`button`,{onClick:()=>r(`scale`),className:`flex-1 bg-yellow-700 hover:bg-yellow-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,G.jsx)(rd,{className:`w-4 h-4 text-yellow-300 shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium text-yellow-100`,children:t(`spoolbuddy.settings.scaleDiagnostic`,`Scale Diagnostic`)})]}),(0,G.jsxs)(`button`,{onClick:()=>r(`read_tag`),className:`flex-1 bg-emerald-700 hover:bg-emerald-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,G.jsx)(dc,{className:`w-4 h-4 text-emerald-300 shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium text-emerald-100`,children:t(`spoolbuddy.settings.readTagDiagnostic`,`Read Tag`)})]})]})]}),n&&e&&(0,G.jsx)($1e,{type:n,deviceId:e.device_id,onClose:()=>r(null)})]})}function i0e({device:e,onBrightnessChange:t}){let{t:n}=U(),[r,i]=(0,y.useState)(e.display_brightness),[a,o]=(0,y.useState)(e.display_blank_timeout),[s,c]=(0,y.useState)(!1),l=(0,y.useRef)(void 0),u=(0,y.useRef)(void 0);(0,y.useEffect)(()=>{i(e.display_brightness),o(e.display_blank_timeout)},[e.display_brightness,e.display_blank_timeout]);let d=(0,y.useCallback)(()=>{c(!0),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>c(!1),1500)},[]),f=(0,y.useCallback)((t,n)=>{l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{Cd.updateDisplay(e.device_id,t,n).then(()=>d()).catch(e=>console.error(`Failed to update display:`,e))},300)},[e.device_id,d]),p=e=>{i(e),t(e),f(e,a)},m=e=>{o(e),f(r,e)};return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300`,children:n(`spoolbuddy.settings.brightness`,`Brightness`)}),s&&(0,G.jsxs)(`span`,{className:`text-xs text-green-400 flex items-center gap-1 animate-pulse`,children:[(0,G.jsx)(`svg`,{className:`w-3 h-3`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:3,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}),n(`spoolbuddy.settings.saved`,`Saved`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4 text-zinc-500 flex-shrink-0`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z`})}),(0,G.jsx)(`input`,{type:`range`,min:0,max:100,value:r,onChange:e=>p(parseInt(e.target.value)),className:`flex-1 h-2 bg-zinc-700 rounded-lg appearance-none cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-sm font-mono text-zinc-400 w-10 text-right`,children:[r,`%`]})]}),!e.has_backlight&&(0,G.jsx)(`p`,{className:`text-xs text-zinc-600 mt-2`,children:n(`spoolbuddy.settings.noBacklight`,`No DSI backlight detected. Brightness control requires a DSI display.`)})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1`,children:n(`spoolbuddy.settings.screenBlank`,`Screen Blank Timeout`)}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mb-3`,children:n(`spoolbuddy.settings.screenBlankDesc`,`Screen turns off after inactivity. Touch to wake.`)}),(0,G.jsx)(`div`,{className:`grid grid-cols-3 gap-2`,children:n0e.map(e=>(0,G.jsx)(`button`,{onClick:()=>m(e.value),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors min-h-[40px] ${a===e.value?`bg-green-600 text-white`:`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`}`,children:e.label},e.value))})]}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-600 text-center`,children:n(`spoolbuddy.settings.displayNote`,`Brightness is applied as a software filter.`)})]})}function a0e({step:e,labels:t}){return(0,G.jsxs)(`div`,{className:`flex flex-col items-center w-16 shrink-0 pt-1`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center w-7 h-7 rounded-full text-xs font-bold ${e===`tare`?`bg-green-600 text-white`:`bg-green-600/20 text-green-400`}`,children:e===`weight`?(0,G.jsx)(`svg`,{className:`w-3.5 h-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:3,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}):`1`}),(0,G.jsx)(`span`,{className:`text-[10px] mt-0.5 ${e===`tare`?`text-green-400 font-medium`:`text-green-400/60`}`,children:t.tare}),(0,G.jsx)(`div`,{className:`w-px h-5 my-1 ${e===`weight`?`bg-green-600/40`:`bg-zinc-700`}`}),(0,G.jsx)(`div`,{className:`flex items-center justify-center w-7 h-7 rounded-full text-xs font-bold ${e===`weight`?`bg-green-600 text-white`:`bg-zinc-700 text-zinc-500`}`,children:`2`}),(0,G.jsx)(`span`,{className:`text-[10px] mt-0.5 ${e===`weight`?`text-green-400 font-medium`:`text-zinc-600`}`,children:t.weight})]})}function o0e({device:e,weight:t,weightStable:n,rawAdc:r}){let{t:i}=U(),a=co(),[o,s]=(0,y.useState)(`idle`),[c,l]=(0,y.useState)(`500`),[u,d]=(0,y.useState)(null),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),v=(0,y.useRef)(null);(0,y.useEffect)(()=>()=>{v.current&&clearTimeout(v.current)},[]);let b=(0,y.useCallback)(e=>{v.current&&clearTimeout(v.current),v.current=setTimeout(()=>h(null),e)},[]);(0,y.useEffect)(()=>{if(!g)return;let e=()=>Date.now()-g.startedAtMs,t=setInterval(()=>{a.invalidateQueries({queryKey:[`spoolbuddy-devices`]})},1e3),n=setTimeout(()=>{_(null),h({type:`error`,msg:i(`spoolbuddy.settings.tareTimedOut`,`Tare timed out — is the SpoolBuddy daemon running?`)}),b(5e3)},Math.max(0,15e3-e()));return()=>{clearInterval(t),clearTimeout(n)}},[g,a,i,b]),(0,y.useEffect)(()=>{g&&(e?.last_calibrated_at??null)!==g.snapshot&&(_(null),h({type:`ok`,msg:i(`spoolbuddy.settings.tareComplete`,`Tare complete!`)}),b(3e3))},[e?.last_calibrated_at,g,i,b]);let x=e=>{e===`backspace`?l(e=>e.slice(0,-1)||``):e===`.`&&!c.includes(`.`)?l(e=>e+`.`):e>=`0`&&e<=`9`&&l(t=>t===`0`?e:t+e)};return o===`idle`?(0,G.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,G.jsx)(`span`,{className:`text-lg font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`})]}),(0,G.jsxs)(`div`,{className:`text-xs text-zinc-500 text-right`,children:[(0,G.jsxs)(`span`,{children:[i(`spoolbuddy.settings.tareOffset`,`Tare`),`: `,e.tare_offset]}),(0,G.jsx)(`span`,{className:`mx-1.5`,children:`·`}),(0,G.jsxs)(`span`,{children:[i(`spoolbuddy.settings.calFactor`,`Factor`),`: `,e.calibration_factor.toFixed(2)]})]})]}),e.last_calibrated_at&&(0,G.jsxs)(`div`,{className:`text-xs text-zinc-600 mt-1`,children:[i(`spoolbuddy.settings.lastCalibrated`,`Last calibrated`),`: `,t0e(e.last_calibrated_at)]})]}),m&&(0,G.jsx)(`div`,{className:`rounded-lg px-3 py-2 mb-3 text-sm ${m.type===`ok`?`bg-green-900/30 text-green-300 border border-green-800`:`bg-red-900/30 text-red-300 border border-red-800`}`,children:m.msg}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`button`,{onClick:async()=>{p(!0),h(null),v.current&&=(clearTimeout(v.current),null);let t=e?.last_calibrated_at??null;try{await Cd.tare(e.device_id),h({type:`ok`,msg:i(`spoolbuddy.settings.tareSet`,`Tare command sent. Waiting for device...`)}),_({snapshot:t,startedAtMs:Date.now()})}catch{h({type:`error`,msg:i(`spoolbuddy.settings.tareFailed`,`Failed to send tare command`)}),b(5e3)}finally{p(!1)}},disabled:f,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-200 hover:bg-zinc-600 disabled:opacity-40 transition-colors min-h-[44px] flex items-center justify-center gap-2`,children:[f&&(0,G.jsxs)(`svg`,{className:`w-4 h-4 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,G.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,G.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),i(`spoolbuddy.weight.tare`,`Tare`)]}),(0,G.jsx)(`button`,{onClick:()=>{s(`tare`),h(null)},className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:i(`spoolbuddy.weight.calibrate`,`Calibrate`)})]})]}):(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(a0e,{step:o,labels:{tare:i(`spoolbuddy.weight.tare`,`Tare`),weight:i(`spoolbuddy.settings.knownWeight`,`Known weight`)}}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 bg-zinc-800 rounded-lg px-3 py-1.5 mb-1.5`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,G.jsx)(`span`,{className:`text-sm font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`}),(0,G.jsx)(`span`,{className:`text-xs ml-auto ${n?`text-green-400`:`text-amber-400`}`,children:n?i(`spoolbuddy.settings.stable`,`Stable`):i(`spoolbuddy.settings.settling`,`Settling...`)})]}),m&&(0,G.jsx)(`div`,{className:`rounded-lg px-3 py-1.5 mb-1.5 text-xs ${m.type===`ok`?`bg-green-900/30 text-green-300 border border-green-800`:`bg-red-900/30 text-red-300 border border-red-800`}`,children:m.msg}),o===`tare`?(0,G.jsx)(`p`,{className:`text-sm text-zinc-300 mb-3`,children:i(`spoolbuddy.settings.calStep1`,`Remove all items from the scale and press Set Zero.`)}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-zinc-400 shrink-0`,children:i(`spoolbuddy.settings.knownWeight`,`Known weight`)}),(0,G.jsxs)(`div`,{className:`flex-1 bg-zinc-900 border border-zinc-600 rounded px-3 py-1 text-right text-lg font-mono text-zinc-100`,children:[c||`0`,(0,G.jsx)(`span`,{className:`text-zinc-500 ml-1`,children:`g`})]})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-4 gap-1 mb-1.5`,children:[`7`,`8`,`9`,`backspace`,`4`,`5`,`6`,`.`,`1`,`2`,`3`,`0`].map(e=>(0,G.jsx)(`button`,{onClick:()=>x(e),className:`rounded text-lg font-medium transition-colors h-[48px] active:scale-95 ${e===`backspace`?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`:`bg-zinc-800 text-zinc-100 hover:bg-zinc-700 border border-zinc-700`}`,children:e===`backspace`?`⌫`:e},e))})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`button`,{onClick:()=>{s(`idle`),h(null)},className:`flex-1 px-4 py-2 rounded-lg text-sm bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors h-[40px]`,children:i(`common.cancel`,`Cancel`)}),(0,G.jsxs)(`button`,{onClick:async()=>{if(o===`tare`){p(!0),h(null);try{d(r),await Cd.tare(e.device_id),h({type:`ok`,msg:i(`spoolbuddy.settings.zeroSet`,`Zero point set. Place known weight on scale.`)}),s(`weight`)}catch{h({type:`error`,msg:i(`spoolbuddy.settings.tareFailed`,`Failed to send tare command`)})}finally{p(!1)}}else if(o===`weight`){let t=parseFloat(c);if(r===null||!t||t<=0)return;p(!0),h(null);try{await Cd.setCalibrationFactor(e.device_id,t,r,u??void 0),h({type:`ok`,msg:i(`spoolbuddy.settings.calibrationDone`,`Calibration complete!`)}),b(3e3),s(`idle`)}catch{h({type:`error`,msg:i(`spoolbuddy.settings.calibrationFailed`,`Calibration failed`)}),b(5e3)}finally{p(!1)}}},disabled:f,className:`flex-1 px-4 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors h-[40px] flex items-center justify-center gap-2`,children:[f&&(0,G.jsxs)(`svg`,{className:`w-4 h-4 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,G.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,G.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),o===`tare`?i(`spoolbuddy.settings.setZero`,`Set Zero`):i(`spoolbuddy.settings.calibrateNow`,`Calibrate`)]})]})]})]})}function s0e({device:e}){let{t}=U(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(null),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),u=e.update_status===`pending`||e.update_status===`updating`;(0,y.useEffect)(()=>{u&&n===`applying`&&r(null)},[u,n]),(0,y.useEffect)(()=>{let e=()=>{u&&setTimeout(()=>window.location.reload(),1e3)};return window.addEventListener(`spoolbuddy-online`,e),()=>window.removeEventListener(`spoolbuddy-online`,e)},[u]);let{data:d,refetch:f}=K({queryKey:[`spoolbuddy-update-check`,e.device_id],queryFn:()=>Cd.checkDaemonUpdate(e.device_id),staleTime:0}),{data:p}=K({queryKey:[`spoolbuddy-ssh-key`],queryFn:()=>Cd.getSSHPublicKey(),enabled:o,staleTime:1/0}),m=async()=>{r(`checking`),a(null);try{await f()}finally{r(null)}},h=async()=>{r(`applying`),a(null);try{await Cd.triggerUpdate(e.device_id)}catch(e){a(e instanceof Error?e.message:`Failed to trigger update`),r(null)}},g=n!=null||u,_=()=>{p?.public_key&&(navigator.clipboard.writeText(p.public_key),l(!0),setTimeout(()=>l(!1),2e3))},v=e.firmware_version||(d?.current_version&&d.current_version!==`0.0.0`?d.current_version:null);return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between items-center text-sm`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.currentVersion`,`Current Version`)}),(0,G.jsx)(`span`,{className:`text-zinc-200 font-mono`,children:v||(0,G.jsx)(`span`,{className:`text-zinc-500 italic text-xs`,children:t(`spoolbuddy.settings.versionPending`,`Waiting for daemon...`)})})]}),g?(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`svg`,{className:`w-4 h-4 animate-spin text-green-400 flex-shrink-0`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,G.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,G.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),(0,G.jsx)(`span`,{className:`text-green-300 text-xs`,children:n===`checking`?t(`spoolbuddy.settings.checking`,`Checking for updates...`):e.update_message||t(`spoolbuddy.settings.updateWaiting`,`Updating...`)})]}):e.update_status===`error`?(0,G.jsx)(`p`,{className:`text-xs text-red-300`,children:e.update_message||t(`spoolbuddy.settings.updateFailed`,`Update failed`)}):i?(0,G.jsx)(`p`,{className:`text-xs text-red-300`,children:i}):d?.update_available?(0,G.jsxs)(`p`,{className:`text-xs text-green-300`,children:[t(`spoolbuddy.settings.updateAvailable`,`Update available`),`: `,v,` → `,d.latest_version]}):null,!g&&(d?.update_available?(0,G.jsx)(`button`,{onClick:h,disabled:!e.online,className:`w-full px-3 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors`,children:e.online?t(`spoolbuddy.settings.applyUpdate`,`Apply Update`):t(`spoolbuddy.settings.deviceOffline`,`Device Offline`)}):(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`button`,{onClick:m,className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors`,children:t(`spoolbuddy.settings.checkUpdates`,`Check for Updates`)}),(0,G.jsx)(`button`,{onClick:h,disabled:!e.online,className:`px-3 py-2 rounded-lg text-xs font-medium bg-zinc-700 text-zinc-400 hover:bg-zinc-600 hover:text-zinc-200 disabled:opacity-40 transition-colors`,children:t(`spoolbuddy.settings.forceUpdate`,`Force Update`)})]}))]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsxs)(`button`,{onClick:()=>s(!o),className:`w-full flex justify-between items-center text-xs`,children:[(0,G.jsx)(`span`,{className:`font-medium text-zinc-400`,children:t(`spoolbuddy.settings.sshSetup`,`SSH Setup`)}),(0,G.jsx)(`svg`,{className:`w-3 h-3 text-zinc-500 transition-transform ${o?`rotate-180`:``}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 9l-7 7-7-7`})})]}),o&&(0,G.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-zinc-500`,children:t(`spoolbuddy.settings.sshDescription`,`SSH key is deployed automatically. For manual setup, add this key to ~/.ssh/authorized_keys on the device.`)}),p?.public_key?(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`pre`,{className:`bg-zinc-900 rounded p-2 text-[10px] text-zinc-400 font-mono break-all whitespace-pre-wrap`,children:p.public_key}),(0,G.jsx)(`button`,{onClick:_,className:`absolute top-1 right-1 px-1.5 py-0.5 rounded text-[10px] bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors`,children:c?t(`common.copied`,`Copied!`):t(`common.copy`,`Copy`)})]}):(0,G.jsx)(`span`,{className:`text-[10px] text-zinc-500 italic`,children:t(`spoolbuddy.settings.sshKeyLoading`,`Loading...`)})]})]})]})}function c0e({percent:e,color:t}){return(0,G.jsx)(`div`,{className:`w-full h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all ${t}`,style:{width:`${Math.min(100,Math.max(0,e))}%`}})})}function l0e(e){let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h ${r}m`:n>0?`${n}h ${r}m`:`${r}m`}function u0e({device:e}){let{t}=U(),n=e.system_stats;if(!n)return(0,G.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,G.jsx)(`p`,{className:`text-sm text-zinc-500`,children:t(`spoolbuddy.settings.systemStatsWaiting`,`Waiting for system stats...`)})});let r=n.memory,i=n.disk,a=(n.cpu_temp_c??0)>=80?`text-red-400`:(n.cpu_temp_c??0)>=65?`text-amber-400`:`text-green-400`,o=(r?.percent??0)>=90?`bg-red-500`:(r?.percent??0)>=70?`bg-amber-500`:`bg-green-500`,s=(i?.percent??0)>=90?`bg-red-500`:(i?.percent??0)>=70?`bg-amber-500`:`bg-green-500`;return(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:`CPU`}),(0,G.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.cores`,`Cores`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.cpu_count??`-`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.loadAvg`,`Load Avg`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.load_avg?n.load_avg.join(` / `):`-`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.temp`,`Temp`)}),(0,G.jsx)(`span`,{className:`font-mono font-medium ${a}`,children:n.cpu_temp_c==null?`-`:`${n.cpu_temp_c}\u00B0C`})]})]})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.memory`,`Memory`)}),r?(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(c0e,{percent:r.percent??0,color:o}),(0,G.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.used`,`Used`)}),(0,G.jsxs)(`span`,{className:`text-zinc-300 font-mono`,children:[r.used_mb,` / `,r.total_mb,` MB`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.available`,`Free`)}),(0,G.jsxs)(`span`,{className:`text-zinc-300 font-mono`,children:[r.available_mb,` MB`]})]})]})]}):(0,G.jsx)(`span`,{className:`text-xs text-zinc-500`,children:`-`})]})]}),(0,G.jsx)(`div`,{className:`bg-zinc-800 rounded-lg px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 shrink-0`,children:t(`spoolbuddy.settings.disk`,`Disk`)}),i?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`flex-1`,children:(0,G.jsx)(c0e,{percent:i.percent??0,color:s})}),(0,G.jsxs)(`span`,{className:`text-xs text-zinc-300 font-mono shrink-0`,children:[i.used_gb,` / `,i.total_gb,` GB`]})]}):(0,G.jsx)(`span`,{className:`text-xs text-zinc-500`,children:`-`})]})}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1.5`,children:t(`spoolbuddy.settings.osInfo`,`OS`)}),(0,G.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[n.os?.os&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.distro`,`Distro`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 truncate ml-2`,children:n.os.os})]}),n.os?.kernel&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.kernel`,`Kernel`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono truncate ml-2`,children:n.os.kernel})]}),n.os?.arch&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.arch`,`Arch`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.os.arch})]})]})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1.5`,children:t(`spoolbuddy.settings.runtime`,`Runtime`)}),(0,G.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[n.os?.python&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`Python`}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.os.python})]}),n.system_uptime_s!=null&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.systemUptime`,`Uptime`)}),(0,G.jsx)(`span`,{className:`text-zinc-300`,children:l0e(n.system_uptime_s)})]})]})]})]})]})}function d0e(){let{sbState:e,setDisplayBrightness:t}=lr(),{t:n}=U(),[r,i]=(0,y.useState)(`device`),{data:a=[]}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Cd.getDevices(),refetchInterval:1e4}),o=e.deviceId?a.find(t=>t.device_id===e.deviceId)??a[0]:a[0],s=[{id:`device`,label:n(`spoolbuddy.settings.tabDevice`,`Device`)},{id:`display`,label:n(`spoolbuddy.settings.tabDisplay`,`Display`)},{id:`scale`,label:n(`spoolbuddy.settings.tabScale`,`Scale`)},{id:`updates`,label:n(`spoolbuddy.settings.tabUpdates`,`Updates`)},{id:`system`,label:n(`spoolbuddy.settings.tabSystem`,`System`)}];return(0,G.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,G.jsx)(`h1`,{className:`text-xl font-semibold text-zinc-100 mb-3`,children:n(`spoolbuddy.nav.settings`,`Settings`)}),(0,G.jsx)(`div`,{className:`flex gap-1 bg-zinc-800/50 rounded-lg p-1 mb-4`,children:s.map(e=>(0,G.jsx)(`button`,{onClick:()=>i(e.id),className:`flex-1 px-2 py-2 rounded-md text-sm font-medium transition-colors min-h-[36px] ${r===e.id?`bg-zinc-700 text-zinc-100`:`text-zinc-500 hover:text-zinc-300`}`,children:e.label},e.id))}),(0,G.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:o?(0,G.jsxs)(G.Fragment,{children:[r===`device`&&(0,G.jsx)(r0e,{device:o}),r===`display`&&(0,G.jsx)(i0e,{device:o,onBrightnessChange:t}),r===`scale`&&(0,G.jsx)(o0e,{device:o,weight:e.weight,weightStable:e.weightStable,rawAdc:e.rawAdc}),r===`updates`&&(0,G.jsx)(s0e,{device:o}),r===`system`&&(0,G.jsx)(u0e,{device:o})]}):(0,G.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,G.jsx)(`div`,{className:`text-center text-zinc-500`,children:(0,G.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.settings.noDevice`,`No SpoolBuddy device found`)})})})})]})}function f0e({device:e,weight:t,weightStable:n,rawAdc:r}){let{t:i}=U(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(`idle`),[l,u]=(0,y.useState)(`500`),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(!1),h=e=>{e===`backspace`?u(e=>e.slice(0,-1)||``):e===`.`&&!l.includes(`.`)?u(e=>e+`.`):e>=`0`&&e<=`9`&&u(t=>t===`0`?e:t+e)};return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-zinc-400`,children:i(`spoolbuddy.settings.currentWeight`,`Current weight`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,G.jsx)(`span`,{className:`text-lg font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 mt-3 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:i(`spoolbuddy.settings.tareOffset`,`Tare offset`)}),(0,G.jsx)(`span`,{className:`text-zinc-400 font-mono`,children:e.tare_offset})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:i(`spoolbuddy.settings.calFactor`,`Cal. factor`)}),(0,G.jsx)(`span`,{className:`text-zinc-400 font-mono`,children:e.calibration_factor.toFixed(2)})]})]})]}),s===`idle`?(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`button`,{onClick:async()=>{m(!0);try{await Cd.tare(e.device_id)}catch(e){console.error(`Failed to tare:`,e)}finally{m(!1)}},disabled:p,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-200 hover:bg-zinc-600 disabled:opacity-40 transition-colors min-h-[44px]`,children:p?`...`:i(`spoolbuddy.weight.tare`,`Tare`)}),(0,G.jsx)(`button`,{onClick:()=>{c(`tare`)},className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:i(`spoolbuddy.weight.calibrate`,`Calibrate`)})]}):(0,G.jsxs)(`div`,{className:`bg-zinc-800 border border-zinc-700 rounded-lg p-3 space-y-2`,children:[(0,G.jsx)(`div`,{className:`text-sm font-medium text-zinc-200`,children:s===`tare`?i(`spoolbuddy.settings.calStep1`,`Step 1: Remove all items from the scale`):i(`spoolbuddy.settings.calStep2`,`Step 2: Place known weight on scale`)}),s===`weight`&&(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs text-zinc-400`,children:i(`spoolbuddy.settings.knownWeight`,`Known weight (g)`)}),(0,G.jsxs)(`div`,{className:`flex-1 bg-zinc-900 border border-zinc-600 rounded px-3 py-1.5 text-right text-base font-mono text-zinc-100`,children:[l||`0`,(0,G.jsx)(`span`,{className:`text-zinc-500 ml-1`,children:`g`})]})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-4 gap-1`,children:[`7`,`8`,`9`,`backspace`,`4`,`5`,`6`,`.`,`1`,`2`,`3`,`0`].map(e=>(0,G.jsx)(`button`,{onClick:()=>h(e),className:`py-2 rounded text-sm font-medium transition-colors min-h-[36px] ${e===`backspace`?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`:`bg-zinc-800 text-zinc-100 hover:bg-zinc-700 border border-zinc-700`}`,children:e===`backspace`?`⌫`:e},e))})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`button`,{onClick:()=>c(`idle`),className:`flex-1 px-4 py-2 rounded-lg text-sm bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[40px]`,children:i(`common.cancel`,`Cancel`)}),(0,G.jsx)(`button`,{onClick:async()=>{if(s===`tare`){o(!0);try{f(r),await Cd.tare(e.device_id),c(`weight`)}catch(e){console.error(`Failed to tare:`,e)}finally{o(!1)}}else if(s===`weight`){let t=parseFloat(l);if(r===null||!t||t<=0)return;o(!0);try{await Cd.setCalibrationFactor(e.device_id,t,r,d??void 0),c(`idle`)}catch(e){console.error(`Failed to calibrate:`,e)}finally{o(!1)}}},disabled:a,className:`flex-1 px-4 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors min-h-[40px]`,children:a?`...`:s===`tare`?i(`spoolbuddy.settings.setZero`,`Set Zero`):i(`spoolbuddy.settings.calibrateNow`,`Calibrate`)})]})]})]})}function p0e(){let{sbState:e}=lr(),{t}=U(),n=or(),{data:r=[]}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Cd.getDevices(),refetchInterval:1e4}),i=e.deviceId?r.find(t=>t.device_id===e.deviceId)??r[0]:r[0];return(0,G.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,G.jsx)(`button`,{onClick:()=>n(`/spoolbuddy/settings`),className:`p-1.5 rounded-lg text-zinc-400 hover:text-zinc-200 hover:bg-zinc-800 transition-colors`,children:(0,G.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 19l-7-7 7-7`})})}),(0,G.jsx)(`h1`,{className:`text-xl font-semibold text-zinc-100`,children:t(`spoolbuddy.settings.scaleCalibration`,`Scale Calibration`)})]}),(0,G.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:i?(0,G.jsx)(f0e,{device:i,weight:e.weight,weightStable:e.weightStable,rawAdc:e.rawAdc}):(0,G.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,G.jsx)(`div`,{className:`text-center text-zinc-500`,children:(0,G.jsx)(`p`,{className:`text-sm`,children:t(`spoolbuddy.settings.noDevice`,`No SpoolBuddy device found`)})})})})]})}var m0e=[`PLA`,`PETG`,`ABS`,`ASA`,`TPU`,`PA`,`PC`,`PVA`,`HIPS`];function h0e(){let{t:e}=U(),{showToast:t}=Hd(),{sbState:n}=lr(),[r,i]=(0,y.useState)(`existing`),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`idle`),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(null),{data:b}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,staleTime:300*1e3}),x=b!==void 0,S=b?.spoolman_enabled===`true`&&!!b?.spoolman_url,{data:C=[],refetch:w}=K({queryKey:[S?`spoolman-inventory-spools`:`inventory-spools`,`write-tag`],queryFn:()=>S?Z.getSpoolmanInventorySpools(!1):Z.getSpools(!1),refetchInterval:1e4,enabled:x}),{data:T=[]}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Cd.getDevices(),refetchInterval:5e3}),{data:E}=K({queryKey:[`settings`],queryFn:Z.getSettings}),D=T[0],O=n.deviceOnline,k=Af(E?.currency||`USD`),A=(0,y.useMemo)(()=>{let e;if(r===`existing`)e=C.filter(e=>!e.tag_uid&&!e.archived_at);else if(r===`replace`)e=C.filter(e=>(e.tag_uid||e.tray_uuid)&&!e.archived_at);else return[];if(s){let t=s.toLowerCase();e=e.filter(e=>e.material?.toLowerCase().includes(t)||e.color_name?.toLowerCase().includes(t)||e.brand?.toLowerCase().includes(t)||e.subtype?.toLowerCase().includes(t))}return e},[C,r,s]),j=(0,y.useCallback)(e=>{let t=e.detail;(t.sak??t.data?.sak)===0&&(g(!0),v(t.tag_uid??t.data?.tag_uid??null))},[]),M=(0,y.useCallback)(e=>{let t=e.detail;g(!0),v(t.tag_uid??t.data?.tag_uid??null)},[]),N=(0,y.useCallback)(()=>{g(!1),v(null)},[]),P=(0,y.useCallback)(t=>{let n=t.detail;(n.spool_id===a?.id||n.data?.spool_id===a?.id)&&(u(`success`),f(e(`spoolbuddy.writeTag.writeSuccess`,`Tag written successfully!`)),w(),setTimeout(()=>{u(`idle`),o(null),f(``)},5e3))},[a,e,w]),F=(0,y.useCallback)(t=>{let n=t.detail;(n.spool_id===a?.id||n.data?.spool_id===a?.id)&&(u(`error`),f(n.message??n.data?.message??e(`spoolbuddy.writeTag.writeFailed`,`Write failed`)))},[a,e]);(0,y.useEffect)(()=>(window.addEventListener(`spoolbuddy-unknown-tag`,j),window.addEventListener(`spoolbuddy-tag-matched`,M),window.addEventListener(`spoolbuddy-tag-removed`,N),window.addEventListener(`spoolbuddy-tag-written`,P),window.addEventListener(`spoolbuddy-tag-write-failed`,F),()=>{window.removeEventListener(`spoolbuddy-unknown-tag`,j),window.removeEventListener(`spoolbuddy-tag-matched`,M),window.removeEventListener(`spoolbuddy-tag-removed`,N),window.removeEventListener(`spoolbuddy-tag-written`,P),window.removeEventListener(`spoolbuddy-tag-write-failed`,F)}),[j,M,N,P,F]),(0,y.useEffect)(()=>{o(null),u(`idle`),f(``),c(``)},[r]);let I=async()=>{if(!(!a||!D)){u(`writing`),f(e(`spoolbuddy.writeTag.waiting`,`Waiting for SpoolBuddy...`));try{let e=await Cd.writeTag(D.device_id,a.id);if(e?.warnings?.length)for(let n of e.warnings)t(n,`warning`)}catch{u(`error`),f(e(`spoolbuddy.writeTag.queueFailed`,`Failed to queue write command`))}}},L=async()=>{if(D){try{await Cd.cancelWrite(D.device_id)}catch{}u(`idle`),f(``)}},R=async()=>{if(!(!a||!g0e(a))){m(!0),u(`idle`),f(``);try{S?await Z.linkTagToSpoolmanSpool(a.id,{tag_uid:``,tray_uuid:``}):await Z.linkTagToSpool(a.id,{tag_uid:``,tray_uuid:``,data_origin:`manual`}),await w(),o(null),u(`success`),f(e(`spoolbuddy.writeTag.untagSuccess`,`Tag removed from spool`)),setTimeout(()=>{u(`idle`),f(``)},2500)}catch{u(`error`),f(e(`spoolbuddy.writeTag.untagFailed`,`Failed to remove tag from spool`))}finally{m(!1)}}},z=(0,y.useCallback)(e=>{o(e),u(`idle`),f(``),w()},[w]),B=a&&O&&l!==`writing`&&l!==`success`;return(0,G.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,G.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary shrink-0`,children:[{key:`existing`,label:e(`spoolbuddy.writeTag.tabExisting`,`Existing Spool`)},{key:`new`,label:e(`spoolbuddy.writeTag.tabNew`,`New Spool`)},{key:`replace`,label:e(`spoolbuddy.writeTag.tabReplace`,`Replace Tag`)}].map(e=>(0,G.jsx)(`button`,{onClick:()=>i(e.key),className:`flex-1 py-3 text-sm font-medium transition-colors ${r===e.key?`text-bambu-green border-b-2 border-bambu-green bg-bambu-dark`:`text-zinc-400 hover:text-zinc-200 hover:bg-bambu-dark-tertiary`}`,children:e.label},e.key))}),(0,G.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,G.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden border-r border-bambu-dark-tertiary`,children:r===`new`?(0,G.jsx)(v0e,{currencySymbol:k,onCreated:z,selectedSpool:a,spoolmanMode:S,t:e}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`p-3 shrink-0`,children:(0,G.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:e(`spoolbuddy.writeTag.searchPlaceholder`,`Search by material, color, brand...`),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 pb-3 space-y-2`,children:A.length===0?(0,G.jsx)(`div`,{className:`text-center text-zinc-500 py-8 text-sm`,children:r===`existing`?e(`spoolbuddy.writeTag.noUntaggedSpools`,`No spools without tags`):e(`spoolbuddy.writeTag.noTaggedSpools`,`No spools with tags`)}):A.map(e=>(0,G.jsx)(_0e,{spool:e,selected:a?.id===e.id,showTag:r===`replace`,onClick:()=>{o(e),u(`idle`),f(``)}},e.id))})]})}),(0,G.jsx)(`div`,{className:`w-[340px] flex flex-col items-center justify-center p-6 shrink-0`,children:(0,G.jsx)(y0e,{writeStatus:l,writeMessage:d,selectedSpool:a,tagOnReader:h,tagUid:_,deviceOnline:O,canWrite:!!B,isReplace:r===`replace`,canUntag:r===`replace`&&!!a&&g0e(a),untagging:p,onWrite:I,onUntag:R,onCancel:L,onRetry:()=>{u(`idle`),f(``)},t:e})})]})]})}function g0e(e){return!!(e.tag_uid||e.tray_uuid)}function _0e({spool:e,selected:t,showTag:n,onClick:r}){let i=Math.max(0,e.label_weight-e.weight_used),a=e.label_weight>0?Math.round(i/e.label_weight*100):0;return(0,G.jsxs)(`button`,{onClick:r,className:`w-full flex items-center gap-3 p-3 rounded-lg text-left transition-colors ${t?`bg-bambu-green/15 border border-bambu-green/50`:`bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-transparent`}`,children:[(0,G.jsx)(`div`,{className:`w-8 h-8 rounded-full shrink-0 border border-white/10`,style:e.rgba?Tf(e.rgba):{backgroundColor:`#666`}}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-sm font-medium text-white truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-zinc-400`,children:[e.color_name&&(0,G.jsx)(`span`,{children:e.color_name}),(0,G.jsxs)(`span`,{children:[i,`g / `,e.label_weight,`g (`,a,`%)`]})]}),n&&e.tag_uid&&(0,G.jsx)(`div`,{className:`text-xs text-zinc-500 mt-0.5 font-mono`,children:e.tag_uid})]}),t&&(0,G.jsx)(`svg`,{className:`w-5 h-5 text-bambu-green shrink-0`,fill:`currentColor`,viewBox:`0 0 20 20`,children:(0,G.jsx)(`path`,{fillRule:`evenodd`,d:`M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z`,clipRule:`evenodd`})})]})}function v0e({currencySymbol:e,onCreated:t,selectedSpool:n,spoolmanMode:r,t:i}){let{data:a=[]}=K({queryKey:[r?`spoolman-inventory-spools`:`inventory-spools`,`write-tag-form`],queryFn:()=>r?Z.getSpoolmanInventorySpools(!0):Z.getSpools(!0)}),{data:o}=K({queryKey:[`settings`],queryFn:Z.getSettings}),[s,c]=(0,y.useState)(`simple`),[l,u]=(0,y.useState)(`filament`),[d,f]=(0,y.useState)(v9),[p,m]=(0,y.useState)({}),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)([]),[A,j]=(0,y.useState)([]),[M,N]=(0,y.useState)([]),[P,F]=(0,y.useState)([]),[I,L]=(0,y.useState)([]),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)([]),[ee,te]=(0,y.useState)([]),[ne,re]=(0,y.useState)(new Set),[ie,ae]=(0,y.useState)(new Set);(0,y.useEffect)(()=>{V(vU())},[]),(0,y.useEffect)(()=>{let e=!1;return(async()=>{if(s===`full`){D(!0);try{let[t,n]=await Promise.allSettled([(async()=>(await Z.getCloudStatus()).is_authenticated?{connected:!0,presets:await Z.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await Z.orcaCloudStatus()).connected?{connected:!0,presets:(await Z.orcaCloudListProfiles()).filament}:{connected:!1,presets:[]})()]);if(e)return;let r=t.status===`fulfilled`&&t.value.connected,i=n.status===`fulfilled`&&n.value.connected,a=t.status===`fulfilled`?t.value.presets:[],o=n.status===`fulfilled`?n.value.presets:[];T(r||i),k([...a,...o])}catch{e||T(!1)}finally{e||D(!1)}Z.getSpoolCatalog().then(t=>{e||F(t)}).catch(()=>void 0),Z.getColorCatalog().then(t=>{e||L(t)}).catch(()=>void 0),Z.getLocalPresets().then(t=>{e||j(t.filament)}).catch(()=>void 0),Z.getBuiltinFilaments().then(t=>{e||N(t)}).catch(()=>void 0);try{let t=await Z.getPrinters(),n=await Promise.all(t.map(e=>Z.getPrinterStatus(e.id).catch(()=>null))),r=[];for(let e=0;e{e=!0}},[s]),(0,y.useEffect)(()=>{ee.length>0&&ae(new Set(ee.map(e=>String(e.printer.id))))},[ee]);let oe=(0,y.useMemo)(()=>mU(O,new Set,A,M),[O,A,M]),se=(0,y.useMemo)(()=>hU(d.slicer_filament,oe),[d.slicer_filament,oe]),H=(0,y.useMemo)(()=>{let e=pU(O,A),t=I.map(e=>e.manufacturer?.trim()).filter(e=>!!e);return Array.from(new Set([...e,...t])).sort((e,t)=>e.localeCompare(t))},[O,A,I]),ce=(0,y.useMemo)(()=>{let e=I.map(e=>e.material?.trim()).filter(e=>!!e);return Array.from(new Set([...aU,...e])).sort((e,t)=>e.localeCompare(t))},[I]),le=(0,y.useMemo)(()=>{let e=[];for(let t of I){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of O){let n=fU(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of A){let n=fU(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[O,I,A]),ue=(0,y.useMemo)(()=>{let e=new Map;for(let t of le){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[le]),de=(0,y.useMemo)(()=>{let e=new Map;for(let t of le){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[le]),fe=(0,y.useMemo)(()=>gU(H,d.brand),[H,d.brand]),pe=(0,y.useMemo)(()=>gU(ce,d.material),[ce,d.material]),me=(0,y.useMemo)(()=>_U(fe,d.material,de),[fe,d.material,de]),he=(0,y.useMemo)(()=>_U(pe,d.brand,ue),[pe,d.brand,ue]),ge=(e,t)=>{f(n=>({...n,[e]:t})),p[e]&&m(t=>({...t,[e]:void 0}))},_e=e=>{V(t=>yU(e,t))},ve=async e=>{let t=r?Z.saveSpoolmanKProfiles:Z.saveSpoolKProfiles;if(ne.size===0){try{await t(e,[])}catch{}return}let n=[];for(let e of ne){let[t,r,i]=e.split(`:`),a=parseInt(t),o=parseInt(r),s=i===`null`?0:parseInt(i),c=ee.find(e=>e.printer.id===a);if(c){let e=c.calibrations.find(e=>e.cali_idx===o);e&&n.push({printer_id:a,extruder:s,nozzle_diameter:e.nozzle_diameter||`0.4`,k_value:e.k_value,name:e.name||null,cali_idx:e.cali_idx,setting_id:e.setting_id||null})}}n.length>0&&await t(e,n)},ye=async()=>{C(null);let e=WQe(d,s===`simple`?!0:h);if(!e.isValid){m(e.errors),u(`filament`);return}let n=se?.displayName||R||null,a={material:d.material,subtype:d.subtype||null,brand:d.brand||null,color_name:d.color_name||null,rgba:d.rgba||null,extra_colors:d.extra_colors||null,effect_type:d.effect_type||null,label_weight:d.label_weight,core_weight:d.core_weight,core_weight_catalog_id:d.core_weight_catalog_id,weight_used:d.weight_used,slicer_filament:d.slicer_filament||null,slicer_filament_name:n,nozzle_temp_min:null,nozzle_temp_max:null,note:d.note||null,cost_per_kg:d.cost_per_kg,added_full:null,last_used:null,encode_time:null,tag_uid:null,tray_uuid:null,data_origin:null,tag_type:null,last_scale_weight:null,last_weighed_at:null,category:d.category.trim()||null,low_stock_threshold_pct:d.low_stock_threshold_pct};x(!0);try{if(_>1){let e=r?await Z.bulkCreateSpoolmanInventorySpools(a,_):await Z.bulkCreateSpools(a,_),n=r&&e&&typeof e==`object`&&`created`in e?e.created:e;for(let e of n)await ve(e.id);n.length>0&&t(n[0])}else{let e=r?await Z.createSpoolmanInventorySpool(a):await Z.createSpool(a);await ve(e.id),t(e)}}catch{C(i(`spoolbuddy.writeTag.createFailed`,`Failed to create spool`))}finally{x(!1)}},be=`#${(d.rgba||`808080FF`).slice(0,6)}`;return(0,G.jsxs)(`div`,{className:`p-3 space-y-3 overflow-y-auto h-full`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-sm text-zinc-200`,children:i(`spoolbuddy.writeTag.viewMode`,`View`)}),(0,G.jsxs)(`div`,{className:`flex rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>c(`simple`),className:`px-3 py-1.5 text-xs font-medium ${s===`simple`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:i(`spoolbuddy.writeTag.simpleView`,`Simple`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>c(`full`),className:`px-3 py-1.5 text-xs font-medium ${s===`full`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:i(`spoolbuddy.writeTag.fullView`,`Full`)})]})]}),s===`simple`?n?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full p-6 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:n.rgba?Tf(n.rgba):{backgroundColor:`#666`}}),(0,G.jsxs)(`p`,{className:`text-white font-medium`,children:[n.brand?`${n.brand} `:``,n.material]}),n.color_name&&(0,G.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:n.color_name}),(0,G.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[n.label_weight,`g`]}),(0,G.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:i(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]}):(0,G.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.material`,`Material`)}),(0,G.jsx)(`select`,{value:d.material,onChange:e=>ge(`material`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,children:m0e.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))})]}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.colorName`,`Color Name`)}),(0,G.jsx)(`input`,{type:`text`,value:d.color_name,onChange:e=>ge(`color_name`,e.target.value),placeholder:`Jade White`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.color`,`Color`)}),(0,G.jsx)(`input`,{type:`color`,value:be,onChange:e=>ge(`rgba`,e.target.value.replace(`#`,``).toUpperCase()+`FF`),className:`w-10 h-9 bg-transparent border border-bambu-dark-tertiary rounded cursor-pointer`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.brand`,`Brand`)}),(0,G.jsx)(`input`,{type:`text`,value:d.brand,onChange:e=>ge(`brand`,e.target.value),placeholder:`Polymaker`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.weight`,`Weight (g)`)}),(0,G.jsx)(`input`,{type:`number`,value:d.label_weight,onChange:e=>ge(`label_weight`,parseInt(e.target.value)||0),min:0,max:1e4,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`})]}),(0,G.jsx)(`button`,{onClick:ye,disabled:b||!d.material,className:`w-full py-2.5 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:b?i(`spoolbuddy.writeTag.creating`,`Creating...`):i(`spoolbuddy.writeTag.createSpool`,`Create Spool`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-sm text-zinc-200`,children:i(`inventory.quickAdd`,`Quick Add`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${h?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(`span`,{className:`inline-block h-4.5 w-4.5 rounded-full bg-white transition-transform ${h?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{className:`flex border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsx)(`button`,{onClick:()=>u(`filament`),className:`flex-1 py-2.5 text-sm font-medium ${l===`filament`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:i(`inventory.filamentInfoTab`,`Filament`)}),!h&&(0,G.jsx)(`button`,{onClick:()=>u(`pa-profile`),className:`flex-1 py-2.5 text-sm font-medium ${l===`pa-profile`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:i(`inventory.paProfileTab`,`PA Profile`)})]}),(0,G.jsx)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-3`,children:l===`filament`?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(KQe,{formData:d,updateField:ge,cloudAuthenticated:w,loadingCloudPresets:E,presetInputValue:R,setPresetInputValue:z,selectedPresetOption:se,filamentOptions:oe,availableBrands:fe,availableMaterials:pe,suggestedBrands:me,suggestedMaterials:he,quickAdd:h,detailsRequired:!h,quantity:_,onQuantityChange:v,errors:p}),(0,G.jsx)(JQe,{formData:d,updateField:ge,recentColors:B,onColorUsed:_e,catalogColors:I}),(0,G.jsx)(XQe,{formData:d,updateField:ge,spoolCatalog:P,currencySymbol:e,availableCategories:Array.from(new Set(a.map(e=>e.category?.trim()).filter(e=>!!e))).sort((e,t)=>e.localeCompare(t)),globalLowStockThreshold:o?.low_stock_threshold??20})]}):(0,G.jsx)(QQe,{formData:d,updateField:ge,printersWithCalibrations:ee,selectedProfiles:ne,setSelectedProfiles:re,expandedPrinters:ie,setExpandedPrinters:ae})})]}),S&&(0,G.jsx)(`div`,{className:`text-sm text-red-400 bg-red-900/20 border border-red-900/40 rounded-lg px-3 py-2`,children:S}),s===`full`&&(0,G.jsx)(`button`,{onClick:ye,disabled:b,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:b?i(`spoolbuddy.writeTag.creating`,`Creating...`):i(`spoolbuddy.writeTag.createSpool`,`Create Spool`)}),s===`full`&&n&&(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-4 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:n.rgba?Tf(n.rgba):{backgroundColor:`#666`}}),(0,G.jsxs)(`p`,{className:`text-white font-medium`,children:[n.brand?`${n.brand} `:``,n.material]}),n.color_name&&(0,G.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:n.color_name}),(0,G.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[n.label_weight,`g`]}),(0,G.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:i(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]})]})}function y0e({writeStatus:e,writeMessage:t,selectedSpool:n,tagOnReader:r,tagUid:i,deviceOnline:a,canWrite:o,isReplace:s,canUntag:c,untagging:l,onWrite:u,onUntag:d,onCancel:f,onRetry:p,t:m}){if(e===`success`)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,G.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-green-500/20 flex items-center justify-center`,children:(0,G.jsx)(`svg`,{className:`w-8 h-8 text-green-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M5 13l4 4L19 7`})})}),(0,G.jsx)(`p`,{className:`text-green-400 font-medium`,children:t}),n&&(0,G.jsxs)(`p`,{className:`text-zinc-400 text-sm`,children:[n.brand?`${n.brand} `:``,n.material,n.subtype?` ${n.subtype}`:``,n.color_name?` - ${n.color_name}`:``]})]});if(e===`error`)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,G.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,G.jsx)(`svg`,{className:`w-8 h-8 text-red-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})}),(0,G.jsx)(`p`,{className:`text-red-400 font-medium`,children:t}),(0,G.jsx)(`button`,{onClick:p,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-white text-sm rounded transition-colors`,children:m(`spoolbuddy.writeTag.tryAgain`,`Try Again`)})]});if(e===`writing`)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,G.jsxs)(`div`,{className:`relative w-16 h-16`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-bambu-green/30 animate-ping`}),(0,G.jsx)(`div`,{className:`absolute inset-2 rounded-full border-2 border-bambu-green/50 animate-pulse`}),(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,G.jsx)(Z9,{className:`w-8 h-8 text-bambu-green`})})]}),(0,G.jsx)(`p`,{className:`text-bambu-green font-medium`,children:m(`spoolbuddy.writeTag.writing`,`Writing tag...`)}),(0,G.jsx)(`p`,{className:`text-zinc-500 text-xs`,children:t}),(0,G.jsx)(`button`,{onClick:f,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-zinc-400 text-sm rounded transition-colors`,children:m(`spoolbuddy.writeTag.cancel`,`Cancel`)})]});if(!a)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,G.jsx)(Z9,{className:`w-12 h-12 text-zinc-600`}),(0,G.jsx)(`p`,{className:`text-zinc-500 text-sm`,children:m(`spoolbuddy.writeTag.deviceOffline`,`SpoolBuddy is offline`)})]});if(!n)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,G.jsx)(Z9,{className:`w-12 h-12 text-zinc-600`}),(0,G.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:m(`spoolbuddy.writeTag.selectSpool`,`Select a spool, then place a blank NTAG on the reader`)})]});let h=n.rgba?Tf(n.rgba):{backgroundColor:`#666`};return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4 w-full`,children:[(0,G.jsx)(`div`,{className:`relative w-16 h-16`,children:r?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`absolute inset-0 rounded-full bg-bambu-green/10`}),(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,G.jsx)(Z9,{className:`w-8 h-8 text-bambu-green`})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-zinc-600 animate-pulse`}),(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,G.jsx)(Z9,{className:`w-8 h-8 text-zinc-500`})})]})}),r?(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(`p`,{className:`text-bambu-green text-sm font-medium`,children:m(`spoolbuddy.writeTag.tagReady`,`Tag detected — ready to write`)}),i&&(0,G.jsx)(`p`,{className:`text-zinc-500 text-xs font-mono`,children:i})]}):(0,G.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:m(`spoolbuddy.writeTag.placeTag`,`Place an NTAG on the reader`)}),(0,G.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-3 space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-8 h-8 rounded-full border border-white/10 shrink-0`,style:h}),(0,G.jsxs)(`div`,{className:`text-left min-w-0`,children:[(0,G.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[n.brand?`${n.brand} `:``,n.material]}),n.color_name&&(0,G.jsx)(`p`,{className:`text-zinc-400 text-xs`,children:n.color_name})]})]}),(0,G.jsxs)(`div`,{className:`text-xs text-zinc-500`,children:[n.label_weight,`g`]})]}),s&&n.tag_uid&&(0,G.jsx)(`p`,{className:`text-yellow-500/80 text-xs`,children:m(`spoolbuddy.writeTag.replaceWarning`,`Old tag will be unlinked. New tag will replace it.`)}),(0,G.jsx)(`button`,{onClick:u,disabled:!o,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-40 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors text-sm`,children:s?m(`spoolbuddy.writeTag.replaceTag`,`Replace Tag`):m(`spoolbuddy.writeTag.writeTag`,`Write Tag`)}),s&&c&&(0,G.jsx)(`button`,{onClick:d,disabled:l,className:`w-full py-2.5 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary disabled:opacity-40 disabled:cursor-not-allowed text-zinc-200 rounded-lg transition-colors text-sm`,children:l?m(`spoolbuddy.writeTag.untagging`,`Removing tag...`):m(`spoolbuddy.writeTag.untagSpool`,`Untag Selected Spool`)})]})}function Z9({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,children:[(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0`}),(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z`})]})}var b0e=`spoolbuddy-default-core-weight`;function x0e(){try{let e=localStorage.getItem(b0e);if(e){let t=parseInt(e,10);if(t>=0&&t<=500)return t}}catch{}return 250}function S0e({spool:e,liveScaleWeight:t,persistedGrossWeight:n,onClose:r,onSyncWeight:i,onAssignToAms:a,isAssigned:o,onUnassignFromAms:s,className:c}){let{t:l}=U(),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),{data:g}=K({queryKey:[`spool-k-profiles`,e.id],queryFn:()=>Z.getSpoolKProfiles(e.id),enabled:!e.k_profiles||e.k_profiles.length===0,staleTime:300*1e3}),_=e.k_profiles&&e.k_profiles.length>0?e.k_profiles:g,v=wf(e.rgba),b=e.core_weight&&e.core_weight>0?e.core_weight:x0e(),x=t===null?null:Math.round(Math.max(0,t)),S=m??(n===void 0?x:n===null?null:Math.round(Math.max(0,n))),C=Math.round(Math.max(0,(e.label_weight||0)-(e.weight_used||0))),w=x!==null&&x>=10?Math.round(Math.max(0,x-b)):C,T=Math.round(e.label_weight||1e3),E=T>0?Math.min(100,Math.round(w/T*100)):null,D=E===null?`#808080`:E>50?`#22c55e`:E>20?`#eab308`:`#ef4444`,O=Math.max(0,(e.label_weight||0)-(e.weight_used||0))+b,k=x===null?null:x-O,A=k===null?null:Math.abs(k)<=50,j=S??Math.round(O),M=e.nozzle_temp_min!=null&&e.nozzle_temp_max!=null?`${e.nozzle_temp_min}-${e.nozzle_temp_max}\u00B0C`:null,N=e.slicer_filament_name||e.slicer_filament||null,P=e.note?.trim()||null,F=_&&_.length>0?Array.from(new Set(_.map(e=>e.k_value.toFixed(3)))).join(`, `):null,I=async()=>{if(t===null)return;let n=Math.round(Math.max(0,t));d(!0);try{await Cd.updateSpoolWeight(e.id,n),h(n),p(!0),i?.(),setTimeout(()=>p(!1),3e3)}catch(e){console.error(`Failed to sync weight:`,e)}finally{d(!1)}};return(0,G.jsxs)(`div`,{className:`flex flex-col items-center space-y-4 max-w-md ${c??``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-5`,children:[(0,G.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,G.jsx)(G9,{color:v,isEmpty:!1,size:100}),E!==null&&(0,G.jsxs)(`div`,{className:`absolute -bottom-2 -right-2 px-2 py-0.5 rounded-full text-xs font-bold text-white shadow-lg`,style:{backgroundColor:D},children:[E,`%`]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:e.color_name||`Unknown color`}),(0,G.jsxs)(`span`,{className:`text-xs font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,G.jsxs)(`p`,{className:`text-sm text-zinc-400`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]}),(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-3xl font-bold font-mono text-zinc-100`,children:[w,`g`]}),(0,G.jsxs)(`span`,{className:`text-sm text-zinc-500`,children:[`/ `,T,`g`]})]}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mt-0.5`,children:l(`spoolbuddy.spool.remaining`,`Remaining`)}),(0,G.jsx)(`div`,{className:`mt-2 max-w-xs`,children:(0,G.jsx)(`div`,{className:`h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500`,style:{width:`${E??0}%`,backgroundColor:D}})})})]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-2 text-sm bg-zinc-800 rounded-lg p-4 w-full`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.grossWeight`,`Gross weight`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[j,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.spool.coreWeight`,`Core`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[b,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.spoolSize`,`Spool size`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[T,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.spool.scaleWeight`,`Scale`)}),x===null?(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`—`}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 font-mono ${A?`text-green-500`:`text-yellow-500`}`,children:[x,`g`,A?(0,G.jsx)(ds,{className:`w-3.5 h-3.5`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Iu,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`button`,{onClick:I,className:`p-1 hover:bg-green-500/20 rounded transition-colors text-green-500`,title:l(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`),children:(0,G.jsx)(Vl,{className:`w-4 h-4`})})]})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.tagId`,`Tag`)}),(0,G.jsx)(`span`,{className:`font-mono text-xs text-zinc-400 truncate max-w-[120px]`,title:e.tag_uid||``,children:e.tag_uid?e.tag_uid.slice(-8):`—`})]}),M&&(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.inventory.nozzleTemp`,`Nozzle`)}),(0,G.jsx)(`span`,{className:`font-mono text-zinc-300`,children:M})]}),e.cost_per_kg!=null&&e.cost_per_kg>0&&(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.inventory.costPerKg`,`Cost/kg`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[e.cost_per_kg.toFixed(2),`/kg`]})]}),F&&(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.inventory.kProfiles`,`K-Profile`)}),(0,G.jsx)(`span`,{className:`font-mono text-zinc-300 truncate max-w-[220px] text-right`,title:F,children:F})]}),N&&(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mb-1`,children:l(`spoolbuddy.inventory.slicerFilament`,`Slicer Filament`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-300 whitespace-pre-wrap break-words`,children:N})]}),P&&(0,G.jsxs)(`div`,{className:`col-span-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mb-1`,children:l(`spoolbuddy.inventory.note`,`Note`)}),(0,G.jsx)(`p`,{className:`text-sm leading-5 text-zinc-300 whitespace-pre-wrap break-words max-h-[3.75rem] overflow-y-auto pr-1`,children:P})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[a&&(0,G.jsx)(`button`,{onClick:o?void 0:a,disabled:!!o,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px] disabled:opacity-50 disabled:cursor-not-allowed`,children:l(`spoolbuddy.modal.assignToAms`,`Assign to AMS`)}),s&&(0,G.jsxs)(`button`,{onClick:s,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-red-600/20 text-red-400 hover:bg-red-600/30 transition-colors min-h-[44px]`,children:[(0,G.jsx)(zu,{className:`w-4 h-4 inline mr-1`}),l(`inventory.unassignSpool`)]}),(0,G.jsx)(`button`,{onClick:I,disabled:t===null||u,className:`px-5 py-2.5 rounded-lg text-sm font-medium transition-colors min-h-[44px] ${f?`bg-green-600/20 text-green-400`:a?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600 disabled:opacity-40 disabled:cursor-not-allowed`:`bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed`}`,children:u?`...`:f?l(`spoolbuddy.dashboard.weightSynced`,`Synced!`):l(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`)}),r&&(0,G.jsx)(`button`,{onClick:r,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:l(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function C0e(e){return wf(e.rgba)}function w0e(e){return Math.max(0,e.label_weight-e.weight_used)}function T0e(e){return e.label_weight<=0?0:Math.max(0,Math.min(100,(e.label_weight-e.weight_used)/e.label_weight*100))}function E0e(e){let t=[e.material];return e.subtype&&t.push(e.subtype),t.join(` `)}function D0e(e){let t=e.ams_id===254||e.ams_id===255,n=!t&&e.ams_id>=128;return wp(e.ams_id,e.tray_id,n,t)}function O0e({color:e,size:t=56}){return(0,G.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 56 56`,children:[(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:e}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:e,style:{filter:`brightness(0.85)`}}),(0,G.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]})}function k0e(){let{sbState:e,selectedPrinterId:t}=lr(),{t:n}=U(),{showToast:r}=Hd(),i=co(),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`all`),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(!1),{data:p}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,staleTime:300*1e3}),m=p?.spoolman_enabled===`true`&&!!p?.spoolman_url,{data:h=[],isLoading:g,refetch:_}=K({queryKey:m?[`spoolman-inventory-spools`]:[`inventory-spools`],queryFn:()=>m?Z.getSpoolmanInventorySpools(!1):Z.getSpools(!1),enabled:p!==void 0,refetchInterval:3e4}),{data:v=[]}=K({queryKey:[`spool-assignments`],queryFn:()=>Z.getAssignments(),refetchInterval:3e4,enabled:!m}),{data:b=[]}=K({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Z.getSpoolmanSlotAssignments(),refetchInterval:3e4,enabled:m}),x=q({mutationFn:e=>Z.unassignSpoolmanSlot(e),onSuccess:()=>{i.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),i.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},onError:()=>r(n(`inventory.unassignFailed`,`Failed to unassign spool`),`error`)}),S=(0,y.useMemo)(()=>{if(m){let e={};return b.forEach(t=>{e[t.spoolman_spool_id]={ams_id:t.ams_id,tray_id:t.tray_id}}),e}let e={};return v.forEach(t=>{e[t.spool_id]={ams_id:t.ams_id,tray_id:t.tray_id,printer_name:t.printer_name}}),e},[m,v,b]),C=(0,y.useMemo)(()=>h.filter(e=>!e.archived_at),[h]),w=(0,y.useMemo)(()=>new Set(Object.keys(S).map(Number)),[S]),T=(0,y.useMemo)(()=>C.filter(e=>w.has(e.id)).length,[C,w]),E=(0,y.useMemo)(()=>{let e=new Set;return C.forEach(t=>e.add(t.material)),Array.from(e).sort()},[C]),D=(0,y.useMemo)(()=>{let e=C;return s===`in_ams`?e=e.filter(e=>w.has(e.id)):s!==`all`&&(e=e.filter(e=>e.material===s)),e=JH(e,a.trim()),[...e].sort((e,t)=>{let n=+!w.has(e.id),r=+!w.has(t.id);return n===r?new Date(t.updated_at).getTime()-new Date(e.updated_at).getTime():n-r})},[C,s,a,w]);return(0,G.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`px-3 pt-3 pb-2 space-y-2.5`,children:[(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Zl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-white/40`}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:n(`spoolbuddy.inventory.searchPlaceholder`,`Search spools...`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-white/30 focus:outline-none focus:border-bambu-green`}),a&&(0,G.jsx)(`button`,{onClick:()=>o(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-white/40 hover:text-white/60`,children:(0,G.jsx)(td,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-1.5 overflow-x-auto no-scrollbar`,children:[(0,G.jsx)(Q9,{active:s===`all`,onClick:()=>c(`all`),label:`${n(`spoolbuddy.inventory.all`,`All`)} (${C.length})`,green:!0}),T>0&&(0,G.jsx)(Q9,{active:s===`in_ams`,onClick:()=>c(`in_ams`),label:`${n(`spoolbuddy.inventory.inAms`,`In AMS`)} (${T})`}),E.map(e=>(0,G.jsx)(Q9,{active:s===e,onClick:()=>c(s===e?`all`:e),label:e},e))]})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 pb-3`,children:g?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(`div`,{className:`w-8 h-8 border-2 border-bambu-green border-t-transparent rounded-full animate-spin`})}):D.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-white/30`,children:[(0,G.jsx)(Sl,{className:`w-12 h-12 mb-3`}),(0,G.jsx)(`p`,{className:`text-sm`,children:a||s!==`all`?n(`spoolbuddy.inventory.noResults`,`No spools match your filters`):n(`spoolbuddy.inventory.empty`,`No spools in inventory`)})]}):(0,G.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(130px,1fr))] gap-2`,children:D.map(e=>(0,G.jsx)(A0e,{spool:e,assignment:S[e.id],onClick:()=>u(e.id)},e.id))})}),l!=null&&(()=>{let n=h.find(e=>e.id===l);return n?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(j0e,{spool:n,assignment:S[n.id],sbState:e,onSyncWeight:()=>{_()},onAssignToAms:()=>f(!0),onUnassignFromAms:m&&S[n.id]?()=>x.mutate(n.id):void 0,onClose:()=>{u(null),f(!1)}}),(0,G.jsx)(V1e,{isOpen:d,onClose:()=>f(!1),spool:n,printerId:t,spoolmanMode:m})]}):null})()]})}function Q9({active:e,onClick:t,label:n,green:r}){return(0,G.jsx)(`button`,{onClick:t,className:`px-4 py-1.5 rounded-full text-sm font-medium border whitespace-nowrap shrink-0 transition-colors ${e?r?`bg-bambu-green/20 text-bambu-green border-bambu-green/50`:`bg-white/10 text-white border-white/20`:`bg-transparent text-white/40 border-bambu-dark-tertiary hover:text-white/60`}`,children:n})}function A0e({spool:e,assignment:t,onClick:n}){let r=C0e(e),i=T0e(e),a=w0e(e),o=Cf(e.color_name,e.rgba);return(0,G.jsxs)(`button`,{onClick:n,className:`bg-bambu-dark-secondary rounded-xl p-3 flex flex-col items-center text-center gap-1.5 border border-transparent hover:border-bambu-green/50 transition-colors`,children:[(0,G.jsx)(O0e,{color:r,size:56}),(0,G.jsx)(`p`,{className:`text-xs font-semibold text-white leading-tight truncate w-full`,children:E0e(e)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 max-w-full`,children:[(0,G.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full shrink-0 border border-white/10`,style:Tf(e.rgba)}),(0,G.jsx)(`span`,{className:`text-[11px] text-white/50 truncate`,children:o||`-`})]}),(0,G.jsxs)(`div`,{className:`w-full space-y-0.5`,children:[(0,G.jsx)(`div`,{className:`h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full ${i>50?`bg-bambu-green`:i>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(i,100)}%`}})}),(0,G.jsxs)(`p`,{className:`text-[11px] text-white/40`,children:[Math.round(a),`g (`,Math.round(i),`%)`]})]}),t&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded text-[10px] font-bold bg-bambu-green/20 text-bambu-green`,children:D0e(t)})]})}function j0e({spool:e,assignment:t,sbState:n,onSyncWeight:r,onAssignToAms:i,onUnassignFromAms:a,onClose:o}){let s=n.deviceOnline&&n.weight!==null?Math.round(n.weight):null,c=e.last_scale_weight==null?null:Math.round(e.last_scale_weight);return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/70 flex items-center justify-center p-4`,onClick:o,children:(0,G.jsx)(`div`,{className:`w-full max-w-md bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-2xl p-4 overflow-y-auto max-h-[90vh]`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[t&&(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,G.jsx)(`span`,{className:`px-2.5 py-1 rounded-md text-xs font-bold bg-bambu-green/20 text-bambu-green`,children:D0e(t)}),t.printer_name&&(0,G.jsx)(`span`,{className:`text-xs text-zinc-400`,children:t.printer_name})]}),(0,G.jsx)(`div`,{className:`flex justify-center`,children:(0,G.jsx)(S0e,{spool:e,liveScaleWeight:s,persistedGrossWeight:c,onSyncWeight:r,onAssignToAms:i,isAssigned:!!t,onUnassignFromAms:a,onClose:o,className:`max-w-md`})})]})})})}var M0e=class extends y.Component{state={error:null,errorInfo:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){this.setState({errorInfo:t}),console.error(`React crash:`,e,t)}render(){return this.state.error?(0,G.jsxs)(`div`,{style:{padding:24,color:`#ef4444`,backgroundColor:`#18181b`,minHeight:`100vh`,fontFamily:`monospace`},children:[(0,G.jsx)(`h1`,{style:{fontSize:20,marginBottom:12},children:`UI Crash`}),(0,G.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,fontSize:14},children:this.state.error.message}),(0,G.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,fontSize:12,color:`#a1a1aa`,marginTop:12},children:this.state.error.stack}),(0,G.jsx)(`button`,{onClick:()=>{this.setState({error:null,errorInfo:null})},style:{marginTop:16,padding:`8px 16px`,backgroundColor:`#3b82f6`,color:`#fff`,border:`none`,borderRadius:8,cursor:`pointer`},children:`Retry`})]}):this.props.children}},N0e=new ao({defaultOptions:{queries:{staleTime:1e3*60,retry:1}}});function P0e(){return rQe(),null}function F0e({children:e}){return $$e(),i1e(),(0,G.jsx)(G.Fragment,{children:e})}function I0e({children:e}){let{authEnabled:t,loading:n,user:r}=Od(),i=rr();return n?(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):t&&!r?(0,G.jsx)(Fr,{to:`/login`,replace:!0,state:{from:i}}):(0,G.jsx)(G.Fragment,{children:e})}function $9({permission:e,children:t}){let{authEnabled:n,loading:r,user:i,hasPermission:a}=Od(),o=rr();return r?(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):n?i?a(e)?(0,G.jsx)(G.Fragment,{children:t}):(0,G.jsx)(Fr,{to:`/`,replace:!0}):(0,G.jsx)(Fr,{to:`/login`,replace:!0,state:{from:o}}):(0,G.jsx)(G.Fragment,{children:t})}function L0e({children:e}){let{authEnabled:t,loading:n}=Od();return n?(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):t?(0,G.jsx)(Fr,{to:`/login`,replace:!0}):(0,G.jsx)(G.Fragment,{children:e})}function R0e(){return(0,G.jsx)(M0e,{children:(0,G.jsx)(Qd,{children:(0,G.jsx)(lo,{client:N0e,children:(0,G.jsx)(Dd,{children:(0,G.jsx)(Ad,{children:(0,G.jsx)(a1e,{children:(0,G.jsxs)(jke,{children:[(0,G.jsx)(P0e,{}),(0,G.jsx)(Oi,{children:(0,G.jsxs)(zr,{children:[(0,G.jsx)(Lr,{path:`/setup`,element:(0,G.jsx)(L0e,{children:(0,G.jsx)(Y$e,{})})}),(0,G.jsx)(Lr,{path:`/login`,element:(0,G.jsx)(J$e,{})}),(0,G.jsx)(Lr,{path:`/camera/:printerId`,element:(0,G.jsx)(sQe,{})}),(0,G.jsx)(Lr,{path:`/overlay/:printerId`,element:(0,G.jsx)(CQe,{})}),(0,G.jsx)(Lr,{path:`/camwall`,element:(0,G.jsx)(_Qe,{})}),(0,G.jsxs)(Lr,{element:(0,G.jsx)(I0e,{children:(0,G.jsx)(F0e,{children:(0,G.jsx)(y1e,{})})}),children:[(0,G.jsx)(Lr,{path:`spoolbuddy`,element:(0,G.jsx)(J1e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/ams`,element:(0,G.jsx)(Q1e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/write-tag`,element:(0,G.jsx)(h0e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/inventory`,element:(0,G.jsx)(k0e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/settings`,element:(0,G.jsx)(d0e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/calibration`,element:(0,G.jsx)(p0e,{})})]}),(0,G.jsxs)(Lr,{element:(0,G.jsx)(I0e,{children:(0,G.jsx)(F0e,{children:(0,G.jsx)(mee,{})})}),children:[(0,G.jsx)(Lr,{index:!0,element:(0,G.jsx)(Eke,{})}),(0,G.jsx)(Lr,{path:`archives`,element:(0,G.jsx)(wze,{})}),(0,G.jsx)(Lr,{path:`queue`,element:(0,G.jsx)(jVe,{})}),(0,G.jsx)(Lr,{path:`pipelines/runs`,element:(0,G.jsx)(Fr,{to:`/queue?tab=pipelines`,replace:!0})}),(0,G.jsx)(Lr,{path:`stats`,element:(0,G.jsx)(XVe,{})}),(0,G.jsx)(Lr,{path:`profiles`,element:(0,G.jsx)(rWe,{})}),(0,G.jsx)(Lr,{path:`finance`,element:(0,G.jsx)($9,{permission:`cost_centers:read_own`,children:(0,G.jsx)(IUe,{})})}),(0,G.jsx)(Lr,{path:`maintenance`,element:(0,G.jsx)(cWe,{})}),(0,G.jsx)(Lr,{path:`projects`,element:(0,G.jsx)(dWe,{})}),(0,G.jsx)(Lr,{path:`projects/:id`,element:(0,G.jsx)(hWe,{})}),(0,G.jsx)(Lr,{path:`inventory`,element:(0,G.jsx)(T$e,{})}),(0,G.jsx)(Lr,{path:`files`,element:(0,G.jsx)(QZe,{})}),(0,G.jsx)(Lr,{path:`files/trash`,element:(0,G.jsx)(tQe,{})}),(0,G.jsx)(Lr,{path:`makerworld`,element:(0,G.jsx)($9,{permission:`makerworld:view`,children:(0,G.jsx)(L$e,{})})}),(0,G.jsx)(Lr,{path:`settings`,element:(0,G.jsx)($9,{permission:`settings:read`,children:(0,G.jsx)(MUe,{})})}),(0,G.jsx)(Lr,{path:`groups/new`,element:(0,G.jsx)($9,{permission:`groups:create`,children:(0,G.jsx)(TQe,{})})}),(0,G.jsx)(Lr,{path:`groups/:id/edit`,element:(0,G.jsx)($9,{permission:`groups:update`,children:(0,G.jsx)(TQe,{})})}),(0,G.jsx)(Lr,{path:`users`,element:(0,G.jsx)(Fr,{to:`/settings?tab=users`,replace:!0})}),(0,G.jsx)(Lr,{path:`groups`,element:(0,G.jsx)(Fr,{to:`/settings?tab=users`,replace:!0})}),(0,G.jsx)(Lr,{path:`system`,element:(0,G.jsx)(U$e,{})}),(0,G.jsx)(Lr,{path:`notifications`,element:(0,G.jsx)(X$e,{})}),(0,G.jsx)(Lr,{path:`gcode-viewer`,element:(0,G.jsx)(Z$e,{})}),(0,G.jsx)(Lr,{path:`external/:id`,element:(0,G.jsx)(wQe,{})}),(0,G.jsx)(Lr,{path:`camera-tokens`,element:(0,G.jsx)(Fr,{to:`/settings?tab=apikeys#card-camera-tokens`,replace:!0})})]})]})})]})})})})})})})}(0,b.createRoot)(document.getElementById(`root`)).render((0,G.jsx)(y.StrictMode,{children:(0,G.jsx)(R0e,{})})); \ No newline at end of file diff --git a/static/index.html b/static/index.html index fd6d50bcd..c9cfab6e0 100644 --- a/static/index.html +++ b/static/index.html @@ -26,7 +26,7 @@ - +