From 800c45536e45b858605785f1f99f0c9f51f6dcb8 Mon Sep 17 00:00:00 2001 From: maziggy Date: Fri, 24 Jul 2026 13:13:04 +0200 Subject: [PATCH] fix(scheduler): pin the force-color variant when selecting the AMS slot (#2650) Follow-up to 0f203ce: force color match now picks the right AMS slot, not just the right printer. The slot mapper cleared tray_info_idx when applying an override, so on a printer holding two same-colour PLA spools of different variants (Basic GFA00 / Matte GFA01 / Silk GFA06) it could map to the wrong one. It now keeps the variant for force_color_match overrides (both the 3MF and no-3MF fallback paths) so the matcher pins the matching tray, and falls back to type+colour when that variant isn't loaded. A manual filament swap (a preference override) still clears the idx so it matches the swapped-in spool rather than the old one. The printer-card queue-compatibility hint applies the same variant rule. --- CHANGELOG.md | 2 +- backend/app/services/print_scheduler.py | 21 +++- ...test_scheduler_force_color_ams_fallback.py | 99 +++++++++++++++++++ frontend/src/__tests__/utils/printer.test.ts | 42 +++++++- frontend/src/api/client.ts | 2 +- .../src/components/PrinterQueueWidget.tsx | 5 +- frontend/src/pages/PrintersPage.tsx | 29 +++++- frontend/src/utils/printer.ts | 21 +++- .../{index-ByvLwk1T.js => index-Bx0t8q7D.js} | 6 +- static/index.html | 2 +- 10 files changed, 211 insertions(+), 18 deletions(-) rename static/assets/{index-ByvLwk1T.js => index-Bx0t8q7D.js} (98%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62d5f1c0a..4d2af54ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to Bambuddy will be documented in this file. ## [1.2.6b1] - Unreleased ### Fixed -- **Force color match dispatched a print onto the wrong PLA variant — Matte jobs went to Basic and Silk printers alike (#2650, reporter @MartinNYHC)** — With **Force color match** on, a job sliced for **White PLA Matte** was dispatched to every printer that had *any* white PLA loaded — the ones holding White PLA **Basic** and White PLA **Silk+** included — so a matte model came out glossy on the wrong machine. **Root cause.** Bambu's MQTT status reports every PLA sub-variant as `tray_type == "PLA"`; the Basic/Matte/Silk distinction is carried only in `tray_info_idx` (`GFA00` = Basic, `GFA01` = Matte, `GFA06` = Silk, …), which the 3MF's `slice_info.config` also records per filament. Two places dropped it: the Virtual-Printer queue built each force override as `{slot_id, type, color, force_color_match}` without the parsed `tray_info_idx`, and the scheduler's eligibility check (`_get_missing_force_color_slots`) compared loaded trays on `(type, colour)` only — so `(PLA, #FFFFFF)` matched Basic, Matte and Silk indiscriminately and all three printers looked eligible. **Fix.** The force override now carries the 3MF's `tray_info_idx`, and a slot counts as satisfied only when a loaded tray matches type **and** colour **and** the variant — identical `tray_info_idx`, *or* either side lacks one. A blank idx on either side (custom/third-party spools report none, and older 3MFs carry none) falls back to the historical type+colour behaviour, so those setups are unaffected. A job sliced for GFA01 now goes only to a printer with GFA01 loaded; Basic/Silk report a mismatch. Covered by scheduler tests (Matte requirement rejects Basic/Silk, accepts Matte, blank loaded idx falls back, requirement without an idx is unchanged) and a Virtual-Printer test asserting the override carries `tray_info_idx`. +- **Force color match dispatched a print onto the wrong PLA variant — Matte jobs went to Basic and Silk printers alike, and the wrong AMS slot on a printer holding two same-colour variants (#2650, reporter @MartinNYHC)** — With **Force color match** on, a job sliced for **White PLA Matte** was dispatched to every printer that had *any* white PLA loaded — the ones holding White PLA **Basic** and White PLA **Silk+** included — so a matte model came out glossy on the wrong machine. **Root cause.** Bambu's MQTT status reports every PLA sub-variant as `tray_type == "PLA"`; the Basic/Matte/Silk distinction is carried only in `tray_info_idx` (`GFA00` = Basic, `GFA01` = Matte, `GFA06` = Silk, …), which the 3MF's `slice_info.config` also records per filament. Three places dropped it: the Virtual-Printer queue built each force override as `{slot_id, type, color, force_color_match}` without the parsed `tray_info_idx`; the scheduler's eligibility check (`_get_missing_force_color_slots`) compared loaded trays on `(type, colour)` only — so `(PLA, #FFFFFF)` matched Basic, Matte and Silk indiscriminately and all three printers looked eligible; and the AMS slot mapper cleared `tray_info_idx` when applying the override, so even on the correct printer it could pick a different-variant tray of the same colour. **Fix.** The force override now carries the 3MF's `tray_info_idx`; a slot counts as satisfied only when a loaded tray matches type **and** colour **and** the variant (identical `tray_info_idx`, *or* either side lacks one); and the slot mapper now keeps the variant for force-colour overrides so it pins the matching tray. A blank idx on either side (custom/third-party spools report none, and older 3MFs carry none) falls back to the historical type+colour behaviour, so those setups are unaffected, and a manual filament *swap* (a preference override) still clears the idx so it matches the swapped-in spool rather than the old one. A job sliced for GFA01 now goes only to a printer with GFA01 loaded, and lands on that printer's GFA01 tray. The printer-card queue-compatibility hint (which printers show a pending job as runnable) now applies the same variant rule. Covered by scheduler tests (Matte requirement rejects Basic/Silk, accepts Matte, blank loaded idx falls back, requirement without an idx unchanged; the mapper pins the GFA01 tray over a same-colour GFA00 on both the 3MF and no-3MF paths; a preference swap still matches by colour), a Virtual-Printer test asserting the override carries `tray_info_idx`, and frontend tests for the variant-aware queue hint (rejects other variants, accepts the match, blank-idx and no-variant-data fall back). ## [1.2.5] - 2026-07-24 diff --git a/backend/app/services/print_scheduler.py b/backend/app/services/print_scheduler.py index 5fe80714e..9403f15ff 100644 --- a/backend/app/services/print_scheduler.py +++ b/backend/app/services/print_scheduler.py @@ -1388,9 +1388,18 @@ class PrintScheduler: override = override_map[req["slot_id"]] req["type"] = override["type"] req["color"] = override["color"] - # Clear tray_info_idx so matching uses type+color instead of - # the original 3MF's tray_info_idx (which would match the old filament) - req["tray_info_idx"] = "" + # A manual/preference override SWAPS the slot's filament, so the + # 3MF's original tray_info_idx now points at the old spool and must + # be cleared — matching then falls back to type+colour. A + # force_color_match override is not a swap: it carries the 3MF's + # intended variant (Basic GFA00 / Matte GFA01 / Silk GFA06), so keep + # it here too, letting the matcher pin the correct variant slot on a + # printer holding two same-colour spools of different variants (#2650). + # If that variant isn't loaded the matcher falls back to type+colour, + # so an eligible printer never fails to map. + req["tray_info_idx"] = ( + override.get("tray_info_idx", "") if override.get("force_color_match") else "" + ) logger.debug( "Queue item %s: Override slot %d -> %s %s", item.id, @@ -1454,7 +1463,11 @@ class PrintScheduler: "slot_id": o["slot_id"], "type": o.get("type", ""), "color": o.get("color", ""), - "tray_info_idx": "", + # These are all force_color_match overrides, so the idx (when the + # 3MF carried one) is the intended variant, not a stale swap — + # keep it so the matcher pins the right variant slot, falling back + # to type+colour when it isn't loaded (#2650). + "tray_info_idx": o.get("tray_info_idx", ""), } for o in force_overrides ] diff --git a/backend/tests/unit/test_scheduler_force_color_ams_fallback.py b/backend/tests/unit/test_scheduler_force_color_ams_fallback.py index f6cc66fa9..ad96e9bfa 100644 --- a/backend/tests/unit/test_scheduler_force_color_ams_fallback.py +++ b/backend/tests/unit/test_scheduler_force_color_ams_fallback.py @@ -124,6 +124,27 @@ class TestBuildOverrideDirectMapping: # Should match by colour (#CBC6B8 ≈ CBC6B8FF after strip), not by tray_info_idx. assert result == [0] + def test_direct_mapping_pins_variant_when_override_carries_idx(self, scheduler): + """#2650: the no-3MF fallback honours a force override's own tray_info_idx, + so two same-colour PLA variants map to the intended slot rather than the + first same-colour tray.""" + status = self._status( + ams=[ + { + "id": 0, + "tray": [ + {"id": 0, "tray_type": "PLA", "tray_color": "FFFFFFFF", "tray_info_idx": "GFA00"}, + {"id": 1, "tray_type": "PLA", "tray_color": "FFFFFFFF", "tray_info_idx": "GFA01"}, + ], + } + ] + ) + overrides = [ + {"slot_id": 1, "type": "PLA", "color": "#FFFFFF", "tray_info_idx": "GFA01", "force_color_match": True} + ] + result = scheduler._build_override_direct_mapping(overrides, status) + assert result == [1] # global_tray_id 1 = GFA01 (Matte), not GFA00 (Basic) at 0 + class TestComputeAmsMappingFallback: """Integration tests for the force-color fallback inside @@ -242,6 +263,84 @@ class TestComputeAmsMappingFallback: assert result is None + @pytest.mark.asyncio + @patch("backend.app.services.print_scheduler.printer_manager") + async def test_force_color_override_pins_the_matching_variant_slot(self, mock_pm, scheduler): + """#2650 slot selection: with two same-colour PLA spools of different + variants loaded, applying a force_color_match override must map to the + tray whose tray_info_idx matches the 3MF (Matte GFA01), not the first + same-colour tray (Basic GFA00).""" + mock_pm.get_status.return_value = MagicMock( + raw_data={ + "ams": [ + { + "id": 0, + "tray": [ + {"id": 0, "tray_type": "PLA", "tray_color": "FFFFFFFF", "tray_info_idx": "GFA00"}, + {"id": 1, "tray_type": "PLA", "tray_color": "FFFFFFFF", "tray_info_idx": "GFA01"}, + ], + } + ] + }, + ams_filament_backup=None, + ) + item = self._make_item( + filament_overrides_json=( + '[{"slot_id": 1, "type": "PLA", "color": "#FFFFFF", ' + '"tray_info_idx": "GFA01", "force_color_match": true}]' + ) + ) + filament_reqs = [{"slot_id": 1, "type": "PLA", "color": "#FFFFFF", "tray_info_idx": "GFA01"}] + db = AsyncMock() + + with ( + patch.object(scheduler, "_get_filament_requirements", return_value=filament_reqs), + patch.object(scheduler, "_get_bool_setting", new=AsyncMock(return_value=False)), + ): + result = await scheduler._compute_ams_mapping_for_printer(db, 5, item) + + assert result == [1] # global_tray_id 1 = GFA01 (Matte), not GFA00 (Basic) at 0 + + @pytest.mark.asyncio + @patch("backend.app.services.print_scheduler.printer_manager") + async def test_preference_override_still_clears_idx_so_a_swap_matches_by_colour(self, mock_pm, scheduler): + """A non-force (preference) override is a filament SWAP: its slot must + match by the new type+colour, never by a stale 3MF variant that would pin + the old spool. Only force_color_match overrides keep their idx — anything + else is cleared, exactly as before #2650.""" + mock_pm.get_status.return_value = MagicMock( + raw_data={ + "ams": [ + { + "id": 0, + "tray": [ + # The 3MF's original variant (blue GFA01) and the swapped-to red. + {"id": 0, "tray_type": "PLA", "tray_color": "0000FFFF", "tray_info_idx": "GFA01"}, + {"id": 1, "tray_type": "PLA", "tray_color": "FF0000FF", "tray_info_idx": "GFA00"}, + ], + } + ] + }, + ams_filament_backup=None, + ) + # 3MF wants blue GFA01; the user swaps this slot to red via a preference + # override that (defensively) also carries the stale GFA01 idx. + item = self._make_item( + filament_overrides_json='[{"slot_id": 1, "type": "PLA", "color": "#FF0000", "tray_info_idx": "GFA01"}]' + ) + filament_reqs = [{"slot_id": 1, "type": "PLA", "color": "#0000FF", "tray_info_idx": "GFA01"}] + db = AsyncMock() + + with ( + patch.object(scheduler, "_get_filament_requirements", return_value=filament_reqs), + patch.object(scheduler, "_get_bool_setting", new=AsyncMock(return_value=False)), + ): + result = await scheduler._compute_ams_mapping_for_printer(db, 5, item) + + # idx cleared → matches the swapped-to red spool (global 1), not the stale + # GFA01 blue (global 0) that a preserved idx would have pinned. + assert result == [1] + class TestGetMissingForceColorSlotsVariant: """force_color_match must distinguish Bambu PLA variants that share a base diff --git a/frontend/src/__tests__/utils/printer.test.ts b/frontend/src/__tests__/utils/printer.test.ts index fc5642605..cf426fc05 100644 --- a/frontend/src/__tests__/utils/printer.test.ts +++ b/frontend/src/__tests__/utils/printer.test.ts @@ -8,7 +8,8 @@ */ import { describe, it, expect } from 'vitest'; -import { getPrinterImage, isGcodeCompatible } from '../../utils/printer'; +import { getPrinterImage, isGcodeCompatible, filterCompatibleQueueItems } from '../../utils/printer'; +import type { PrintQueueItem } from '../../api/client'; describe('getPrinterImage', () => { describe('X2D (#988)', () => { @@ -136,3 +137,42 @@ describe('isGcodeCompatible', () => { expect(isGcodeCompatible('H2D Pro', 'H2DPRO')).toBe(true); }); }); + +describe('filterCompatibleQueueItems — force-color PLA variant (#2650)', () => { + const makeItem = ( + overrides: Array<{ slot_id: number; type: string; color: string; tray_info_idx?: string; force_color_match?: boolean }>, + ): PrintQueueItem => ({ id: 1, filament_overrides: overrides } as unknown as PrintQueueItem); + + // A job sliced for White PLA Matte (GFA01). + const matteJob = makeItem([ + { slot_id: 1, type: 'PLA', color: '#FFFFFF', tray_info_idx: 'GFA01', force_color_match: true }, + ]); + const loadedTypes = new Set(['PLA']); + const loaded = new Set(['PLA:ffffff']); + + it('rejects a printer loaded only with other white PLA variants (Basic/Silk)', () => { + const variants = new Set(['PLA:ffffff:GFA00', 'PLA:ffffff:GFA06']); + expect(filterCompatibleQueueItems([matteJob], loadedTypes, loaded, variants)).toHaveLength(0); + }); + + it('accepts a printer loaded with the matching variant (Matte GFA01)', () => { + const variants = new Set(['PLA:ffffff:GFA00', 'PLA:ffffff:GFA01']); + expect(filterCompatibleQueueItems([matteJob], loadedTypes, loaded, variants)).toHaveLength(1); + }); + + it('accepts a same-colour spool that reports no tray_info_idx (custom/third-party)', () => { + const variants = new Set(['PLA:ffffff:']); + expect(filterCompatibleQueueItems([matteJob], loadedTypes, loaded, variants)).toHaveLength(1); + }); + + it('falls back to type+colour when no variant data is supplied', () => { + // loadedVariants omitted → the hint is never stricter than the data it has. + expect(filterCompatibleQueueItems([matteJob], loadedTypes, loaded)).toHaveLength(1); + }); + + it('an override without a tray_info_idx keeps the old type+colour behaviour', () => { + const noIdxJob = makeItem([{ slot_id: 1, type: 'PLA', color: '#FFFFFF', force_color_match: true }]); + const variants = new Set(['PLA:ffffff:GFA06']); + expect(filterCompatibleQueueItems([noIdxJob], loadedTypes, loaded, variants)).toHaveLength(1); + }); +}); diff --git a/frontend/src/api/client.ts b/frontend/src/api/client.ts index a87b9cae0..bbdd8189e 100644 --- a/frontend/src/api/client.ts +++ b/frontend/src/api/client.ts @@ -2192,7 +2192,7 @@ export interface PrintQueueItem { // PrintModal's deficit warning was acknowledged. skip_filament_check: boolean; ams_mapping: number[] | null; // AMS slot mapping for multi-color prints - filament_overrides: Array<{ slot_id: number; type: string; color: string; color_name?: string; force_color_match?: boolean }> | null; // Filament overrides for model-based assignment + filament_overrides: Array<{ slot_id: number; type: string; color: string; color_name?: string; tray_info_idx?: string; force_color_match?: boolean }> | null; // Filament overrides for model-based assignment plate_id: number | null; // Plate ID for multi-plate 3MF files // Print options bed_levelling: CalibrationMode; diff --git a/frontend/src/components/PrinterQueueWidget.tsx b/frontend/src/components/PrinterQueueWidget.tsx index 0f08be721..8acce0ddb 100644 --- a/frontend/src/components/PrinterQueueWidget.tsx +++ b/frontend/src/components/PrinterQueueWidget.tsx @@ -11,10 +11,11 @@ interface PrinterQueueWidgetProps { printerModel?: string | null; loadedFilamentTypes?: Set; loadedFilaments?: Set; // "TYPE:rrggbb" pairs for filament override color matching + loadedVariants?: Set; // "TYPE:rrggbb:idx" triples for PLA sub-variant matching (#2650) variant?: 'card' | 'panelExtension'; } -export function PrinterQueueWidget({ printerId, printerModel, loadedFilamentTypes, loadedFilaments, variant = 'card' }: PrinterQueueWidgetProps) { +export function PrinterQueueWidget({ printerId, printerModel, loadedFilamentTypes, loadedFilaments, loadedVariants, variant = 'card' }: PrinterQueueWidgetProps) { const { t } = useTranslation(); const { data: queue } = useQuery({ queryKey: ['queue', printerId, 'pending', printerModel], @@ -23,7 +24,7 @@ export function PrinterQueueWidget({ printerId, printerModel, loadedFilamentType }); // Filter queue to items this printer can actually print (filament type + color check) - const compatibleQueue = queue ? filterCompatibleQueueItems(queue, loadedFilamentTypes, loadedFilaments) : undefined; + const compatibleQueue = queue ? filterCompatibleQueueItems(queue, loadedFilamentTypes, loadedFilaments, loadedVariants) : undefined; const totalPending = compatibleQueue?.length || 0; if (totalPending === 0) { diff --git a/frontend/src/pages/PrintersPage.tsx b/frontend/src/pages/PrintersPage.tsx index ec45b1810..65e3262f8 100644 --- a/frontend/src/pages/PrintersPage.tsx +++ b/frontend/src/pages/PrintersPage.tsx @@ -1990,6 +1990,30 @@ function PrinterCard({ return filaments; }, [status?.ams, status?.vt_tray]); + // Collect loaded type+color+tray_info_idx triples for variant-aware force-color + // matching. Format: "TYPE:rrggbb:idx" (idx "" for custom/third-party spools) — + // distinguishes Bambu PLA sub-variants that share a base type+colour (#2650). + const loadedVariants = useMemo(() => { + const variants = new Set(); + if (status?.ams) { + for (const ams of status.ams) { + for (const tray of ams.tray || []) { + if (tray.tray_type && tray.tray_color) { + const color = tray.tray_color.replace('#', '').toLowerCase().slice(0, 6); + variants.add(`${tray.tray_type.toUpperCase()}:${color}:${tray.tray_info_idx || ''}`); + } + } + } + } + for (const vt of status?.vt_tray ?? []) { + if (vt.tray_type && vt.tray_color) { + const color = vt.tray_color.replace('#', '').toLowerCase().slice(0, 6); + variants.add(`${vt.tray_type.toUpperCase()}:${color}:${vt.tray_info_idx || ''}`); + } + } + return variants; + }, [status?.ams, status?.vt_tray]); + // Fetch cloud filament info for tooltips (name includes color, also has K value) const { data: filamentInfo } = useQuery({ queryKey: ['filamentInfo', trayInfoIds], @@ -2163,8 +2187,8 @@ function PrinterCard({ // An empty Set means no filaments are loaded — jobs requiring specific types are incompatible. const queueCount = useMemo(() => { if (!queueItems?.length) return 0; - return filterCompatibleQueueItems(queueItems, loadedFilamentTypes, loadedFilaments).length; - }, [queueItems, loadedFilamentTypes, loadedFilaments]); + return filterCompatibleQueueItems(queueItems, loadedFilamentTypes, loadedFilaments, loadedVariants).length; + }, [queueItems, loadedFilamentTypes, loadedFilaments, loadedVariants]); // Fetch currently printing queue item to show who started it (Issue #206) const { data: printingQueueItems } = useQuery({ @@ -3740,6 +3764,7 @@ function PrinterCard({ printerModel={printer.model} loadedFilamentTypes={loadedFilamentTypes} loadedFilaments={loadedFilaments} + loadedVariants={loadedVariants} variant="panelExtension" /> diff --git a/frontend/src/utils/printer.ts b/frontend/src/utils/printer.ts index 4fc45248a..18035aba2 100644 --- a/frontend/src/utils/printer.ts +++ b/frontend/src/utils/printer.ts @@ -56,12 +56,19 @@ import type { PrintQueueItem } from '../api/client'; * @param items - Array of queue items to filter * @param loadedFilamentTypes - Set of loaded filament types (e.g., "PLA", "PETG") * @param loadedFilaments - Set of loaded filament type+color pairs (e.g., "PLA:ffffff", "PETG:ff0000") + * @param loadedVariants - Set of loaded type+color+tray_info_idx triples + * (e.g., "PLA:ffffff:GFA01"; the idx is "" for custom/third-party spools). Used to + * distinguish Bambu PLA sub-variants (Basic GFA00 / Matte GFA01 / Silk GFA06) that + * share a base type+colour, mirroring the backend _get_missing_force_color_slots (#2650). + * When omitted, force matching falls back to type+colour so the hint is never stricter + * than the data available. * @returns Array of compatible queue items */ export function filterCompatibleQueueItems( items: PrintQueueItem[], loadedFilamentTypes?: Set, - loadedFilaments?: Set + loadedFilaments?: Set, + loadedVariants?: Set ): PrintQueueItem[] { return items.filter(item => { // Type check: all required filament types must be loaded @@ -78,12 +85,20 @@ export function filterCompatibleQueueItems( const forceOverrides = item.filament_overrides.filter(o => o.force_color_match === true); const prefOverrides = item.filament_overrides.filter(o => o.force_color_match !== true); - // All force-matched slots must have exact type+color on this printer + // All force-matched slots must have an exact type+color match — and, when the + // override carries a tray_info_idx, the same variant too (a loaded tray with a + // blank idx still satisfies it, matching the backend's type+colour fallback). if (forceOverrides.length > 0) { const allForceMatch = forceOverrides.every(o => { const oType = (o.type || '').toUpperCase(); const oColor = (o.color || '').replace('#', '').toLowerCase().slice(0, 6); - return loadedFilaments.has(`${oType}:${oColor}`); + const oIdx = o.tray_info_idx || ''; + // No variant on the override, or no variant data supplied → type+colour only. + if (!oIdx || loadedVariants === undefined) { + return loadedFilaments.has(`${oType}:${oColor}`); + } + // Variant-specific: same idx, or a same-colour tray that reports no idx. + return loadedVariants.has(`${oType}:${oColor}:${oIdx}`) || loadedVariants.has(`${oType}:${oColor}:`); }); if (!allForceMatch) return false; } diff --git a/static/assets/index-ByvLwk1T.js b/static/assets/index-Bx0t8q7D.js similarity index 98% rename from static/assets/index-ByvLwk1T.js rename to static/assets/index-Bx0t8q7D.js index aaa098acc..62add1933 100644 --- a/static/assets/index-ByvLwk1T.js +++ b/static/assets/index-Bx0t8q7D.js @@ -8446,7 +8446,7 @@ void main() { `};var Vw=class extends DS{constructor(e){super({type:`LineMaterial`,uniforms:ES.clone(VS.line.uniforms),vertexShader:VS.line.vertexShader,fragmentShader:VS.line.fragmentShader,clipping:!0}),this.isLineMaterial=!0,this.setValues(e)}get color(){return this.uniforms.diffuse.value}set color(e){this.uniforms.diffuse.value=e}get worldUnits(){return`WORLD_UNITS`in this.defines}set worldUnits(e){!0===e?this.defines.WORLD_UNITS=``:delete this.defines.WORLD_UNITS}get linewidth(){return this.uniforms.linewidth.value}set linewidth(e){this.uniforms.linewidth&&(this.uniforms.linewidth.value=e)}get dashed(){return`USE_DASH`in this.defines}set dashed(e){!0===e!==this.dashed&&(this.needsUpdate=!0),!0===e?this.defines.USE_DASH=``:delete this.defines.USE_DASH}get dashScale(){return this.uniforms.dashScale.value}set dashScale(e){this.uniforms.dashScale.value=e}get dashSize(){return this.uniforms.dashSize.value}set dashSize(e){this.uniforms.dashSize.value=e}get dashOffset(){return this.uniforms.dashOffset.value}set dashOffset(e){this.uniforms.dashOffset.value=e}get gapSize(){return this.uniforms.gapSize.value}set gapSize(e){this.uniforms.gapSize.value=e}get opacity(){return this.uniforms.opacity.value}set opacity(e){this.uniforms&&(this.uniforms.opacity.value=e)}get resolution(){return this.uniforms.resolution.value}set resolution(e){this.uniforms.resolution.value.copy(e)}get alphaToCoverage(){return`USE_ALPHA_TO_COVERAGE`in this.defines}set alphaToCoverage(e){this.defines&&(!0===e!==this.alphaToCoverage&&(this.needsUpdate=!0),!0===e?(this.defines.USE_ALPHA_TO_COVERAGE=``,this.extensions.derivatives=!0):(delete this.defines.USE_ALPHA_TO_COVERAGE,this.extensions.derivatives=!1))}},Hw=new Pb,Uw=new jb,Ww=class extends zce{constructor(){super(),this.isLineSegmentsGeometry=!0,this.type=`LineSegmentsGeometry`,this.setIndex([0,2,1,2,3,1,2,4,3,4,5,3,4,6,5,6,7,5]),this.setAttribute(`position`,new Yx([-1,2,0,1,2,0,-1,1,0,1,1,0,-1,0,0,1,0,0,-1,-1,0,1,-1,0],3)),this.setAttribute(`uv`,new Yx([-1,2,1,2,-1,1,1,1,-1,-1,1,-1,-1,-2,1,-2],2))}applyMatrix4(e){let t=this.attributes.instanceStart,n=this.attributes.instanceEnd;return t!==void 0&&(t.applyMatrix4(e),n.applyMatrix4(e),t.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}setPositions(e){let t;e instanceof Float32Array?t=e:Array.isArray(e)&&(t=new Float32Array(e));let n=new bw(t,6,1);return this.setAttribute(`instanceStart`,new zC(n,3,0)),this.setAttribute(`instanceEnd`,new zC(n,3,3)),this.computeBoundingBox(),this.computeBoundingSphere(),this}setColors(e){let t;e instanceof Float32Array?t=e:Array.isArray(e)&&(t=new Float32Array(e));let n=new bw(t,6,1);return this.setAttribute(`instanceColorStart`,new zC(n,3,0)),this.setAttribute(`instanceColorEnd`,new zC(n,3,3)),this}fromWireframeGeometry(e){return this.setPositions(e.attributes.position.array),this}fromEdgesGeometry(e){return this.setPositions(e.attributes.position.array),this}fromMesh(e){return this.fromWireframeGeometry(new Sce(e.geometry)),this}fromLineSegments(e){let t=e.geometry;return this.setPositions(t.attributes.position.array),this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Pb);let e=this.attributes.instanceStart,t=this.attributes.instanceEnd;e!==void 0&&t!==void 0&&(this.boundingBox.setFromBufferAttribute(e),Hw.setFromBufferAttribute(t),this.boundingBox.union(Hw))}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new Zb),this.boundingBox===null&&this.computeBoundingBox();let e=this.attributes.instanceStart,t=this.attributes.instanceEnd;if(e!==void 0&&t!==void 0){let n=this.boundingSphere.center;this.boundingBox.getCenter(n);let r=0;for(let i=0,a=e.count;iu&&Jw.z>u)continue;if(qw.z>u){let e=qw.z-Jw.z,t=(qw.z-u)/e;qw.lerp(Jw,t)}else if(Jw.z>u){let e=Jw.z-qw.z,t=(Jw.z-u)/e;Jw.lerp(qw,t)}qw.applyMatrix4(r),Jw.applyMatrix4(r),qw.multiplyScalar(1/qw.w),Jw.multiplyScalar(1/Jw.w),qw.x*=i.x/2,qw.y*=i.y/2,Jw.x*=i.x/2,Jw.y*=i.y/2,Qw.start.copy(qw),Qw.start.z=0,Qw.end.copy(Jw),Qw.end.z=0;let o=Qw.closestPointToPointParameter(Xw,!0);Qw.at(o,$w);let l=ub.lerp(qw.z,Jw.z,o),d=l>=-1&&l<=1,f=Xw.distanceTo($w)<.5*iT;if(d&&f){Qw.start.fromBufferAttribute(s,t),Qw.end.fromBufferAttribute(c,t),Qw.start.applyMatrix4(a),Qw.end.applyMatrix4(a);let r=new jb,i=new jb;rT.distanceSqToSegment(Qw.start,Qw.end,i,r),n.push({point:i,pointOnLine:r,distance:rT.origin.distanceTo(i),object:e,face:null,faceIndex:t,uv:null,uv1:null})}}}(this,r,t)))}},fle=class extends rw{constructor(e,t,n,r,i=4473924,a=8947848){i=new Vx(i),a=new Vx(a);let o=Math.round(e/t);n=Math.round(n/r)*r/2;let s=[],c=[],l=0;for(let r=-1*(e=o*t/2);r<=e;r+=t){s.push(r,0,-1*n,r,0,n);let e=r===0?i:a;e.toArray(c,l),l+=3,e.toArray(c,l),l+=3,e.toArray(c,l),l+=3,e.toArray(c,l),l+=3}for(let t=-1*n;t<=n;t+=r){s.push(-1*e,0,t,e,0,t);let n=t===0?i:a;n.toArray(c,l),l+=3,n.toArray(c,l),l+=3,n.toArray(c,l),l+=3,n.toArray(c,l),l+=3}let u=new nS;u.setAttribute(`position`,new Yx(s,3)),u.setAttribute(`color`,new Yx(c,3)),super(u,new YC({vertexColors:!0,toneMapped:!1}))}};function ple(e,t,n,r){let i=new rw(function(e,t,n){e*=.5,t*=.5,n*=.5;let r=new nS,i=[];return i.push(-e,-t,-n,-e,t,-n,-e,t,-n,e,t,-n,e,t,-n,e,-t,-n,e,-t,-n,-e,-t,-n,-e,-t,n,-e,t,n,-e,t,n,e,t,n,e,t,n,e,-t,n,e,-t,n,-e,-t,n,-e,-t,-n,-e,-t,n,-e,t,-n,-e,t,n,e,t,-n,e,t,n,e,-t,-n,e,-t,n),r.setAttribute(`position`,new Yx(i,3)),r}(e,t,n),new wce({color:new Vx(r),dashSize:3,gapSize:1}));return i.computeLineDistances(),i}var oT=function(){var e=0,t=document.createElement(`div`);function n(e){return t.appendChild(e.dom),e}function r(n){for(var r=0;r=a+1e3&&(s.update(1e3*o/(e-a),100),a=e,o=0,l)){var t=performance.memory;l.update(t.usedJSHeapSize/1048576,t.jsHeapSizeLimit/1048576)}return e},update:function(){i=this.end()},domElement:t,setMode:r}};oT.Panel=function(e,t,n){var r=1/0,i=0,a=Math.round,o=a(window.devicePixelRatio||1),s=80*o,c=48*o,l=3*o,u=2*o,d=3*o,f=15*o,p=74*o,m=30*o,h=document.createElement(`canvas`);h.width=s,h.height=c,h.style.cssText=`width:80px;height:48px`;var g=h.getContext(`2d`);return g.font=`bold `+9*o+`px Helvetica,Arial,sans-serif`,g.textBaseline=`top`,g.fillStyle=n,g.fillRect(0,0,s,c),g.fillStyle=t,g.fillText(e,l,u),g.fillRect(d,f,p,m),g.fillStyle=n,g.globalAlpha=.9,g.fillRect(d,f,p,m),{dom:h,update:function(c,_){r=Math.min(r,c),i=Math.max(i,c),g.fillStyle=n,g.globalAlpha=1,g.fillRect(0,0,s,f),g.fillStyle=t,g.fillText(a(c)+` `+e+` (`+a(r)+`-`+a(i)+`)`,l,u),g.drawImage(h,d+o,f,p-o,m,d,f,p-o,m),g.fillRect(d+p-o,f,o,m),g.fillStyle=n,g.globalAlpha=.9,g.fillRect(d+p-o,f,o,a((1-c/_)*m))}}};var mle=oT,sT=class{constructor(e,t){this.openFolders=[],this.watchedObject=e,this.options=t,this.gui=new kw,this.gui.title(`Dev info`),this.setup()}setup(){this.loadOpenFolders(),this.options&&!this.options.renderer||this.setupRedererFolder(),this.options&&!this.options.camera||this.setupCameraFolder(),this.options&&!this.options.parser||this.setupParserFolder(),this.options&&!this.options.buildVolume||this.setupBuildVolumeFolder(),this.options&&!this.options.devHelpers||this.setupDevHelpers()}reset(){this.gui.destroy(),this.gui=new kw,this.gui.title(`Dev info`),this.setup()}loadOpenFolders(){this.openFolders=JSON.parse(localStorage.getItem(`dev-gui-open`)||`{}`).open||[]}saveOpenFolders(){this.openFolders=this.gui.foldersRecursive().filter((e=>!e._closed)).map((e=>e._title)),console.log(this.openFolders),localStorage.setItem(`dev-gui-open`,JSON.stringify({open:this.openFolders}))}setupRedererFolder(){let e=this.gui.addFolder(`Render Info`);this.openFolders.includes(`Render Info`)||e.close(),e.onOpenClose((()=>{this.saveOpenFolders()})),e.add(this.watchedObject.renderer.info.render,`triangles`).listen(),e.add(this.watchedObject.renderer.info.render,`calls`).listen(),e.add(this.watchedObject.renderer.info.render,`lines`).listen(),e.add(this.watchedObject.renderer.info.render,`points`).listen(),e.add(this.watchedObject.renderer.info.memory,`geometries`).listen(),e.add(this.watchedObject.renderer.info.memory,`textures`).listen(),e.add(this.watchedObject,`_lastRenderTime`).listen()}setupCameraFolder(){let e=this.gui.addFolder(`Camera`);this.openFolders.includes(`Camera`)||e.close(),e.onOpenClose((()=>{this.saveOpenFolders()}));let t=e.addFolder(`Camera position`);t.add(this.watchedObject.camera.position,`x`).listen(),t.add(this.watchedObject.camera.position,`y`).listen(),t.add(this.watchedObject.camera.position,`z`).listen();let n=e.addFolder(`Camera rotation`);n.add(this.watchedObject.camera.rotation,`x`).listen(),n.add(this.watchedObject.camera.rotation,`y`).listen(),n.add(this.watchedObject.camera.rotation,`z`).listen()}setupParserFolder(){let e=this.gui.addFolder(`Parser`);this.openFolders.includes(`Parser`)||e.close(),e.onOpenClose((()=>{this.saveOpenFolders()})),e.add(this.watchedObject.parser,`curZ`).listen(),e.add(this.watchedObject.parser,`maxZ`).listen(),e.add(this.watchedObject.parser,`tolerance`).listen(),e.add(this.watchedObject.parser.layers,`length`).name(`layers.count`).listen(),e.add(this.watchedObject.parser.lines,`length`).name(`lines.count`).listen()}setupBuildVolumeFolder(){let e=this.gui.addFolder(`Build Volume`);this.openFolders.includes(`Build Volume`)||e.close(),e.onOpenClose((()=>{this.saveOpenFolders()})),e.add(this.watchedObject.buildVolume,`x`).min(0).max(600).listen().onChange((()=>{this.watchedObject.render()})),e.add(this.watchedObject.buildVolume,`y`).min(0).max(600).listen().onChange((()=>{this.watchedObject.render()})),e.add(this.watchedObject.buildVolume,`z`).min(0).max(600).listen().onChange((()=>{this.watchedObject.render()}))}setupDevHelpers(){let e=this.gui.addFolder(`Dev Helpers`);this.openFolders.includes(`Dev Helpers`)||e.close(),e.onOpenClose((()=>{this.saveOpenFolders()})),e.add(this.watchedObject,`_wireframe`).listen().onChange((()=>{this.watchedObject.render()})),e.add(this.watchedObject,`render`).listen(),e.add(this.watchedObject,`clear`).listen()}},hle=class extends nS{constructor(e=[new jb],t=.6,n=.2,r=8){super(),this.type=`ExtrusionGeometry`,this.parameters={points:e,lineWidth:t,lineHeight:n,radialSegments:r,closed:!1};let i=new jb,a=new jb,o=new db,s=[],c=[],l=[],u=[];function d(o){let[l,u,d]=function(t){let n=e[t],r=new jb,i=new jb,a=new jb,o=new jb;r.copy(n).sub(e[t-1]||n).normalize().add((e[t+1]||n).clone().sub(n).normalize()).normalize();let s=Number.MAX_VALUE,c=Math.abs(r.x),l=Math.abs(r.y),u=Math.abs(r.z);return c<=s&&(s=c,i.set(1,0,0)),l<=s&&(s=l,i.set(0,1,0)),u<=s&&i.set(0,0,1),o.crossVectors(r,i).normalize(),i.crossVectors(r,o),a.crossVectors(r,i),[n,i,a]}(o);for(let e=0;e<=r;e++){let o=e/r*Math.PI*2,f=Math.sin(o),p=-Math.cos(o);a.x=p*u.x+f*d.x,a.y=p*u.y+f*d.y,a.z=p*u.z+f*d.z,a.normalize(),c.push(a.x,a.y,a.z),i.x=l.x+t*a.x*.5,i.y=l.y+t*a.y*.5,i.z=l.z+n*a.z*.5,s.push(i.x,i.y,i.z)}}(function(){for(let t=0;tthis.animate())),this.controls.update(),this.renderer.render(this.scene,this.camera),(e=this.stats)==null||e.update()}processGCode(e){this.parser.parseGCode(e),this.render()}initScene(){for(;this.scene.children.length>0;)this.scene.remove(this.scene.children[0]);for(;this.disposables.length>0;){let e=this.disposables.pop();e&&e.dispose()}if(this.debug&&this.buildVolume){let e=new Zce(Math.max(this.buildVolume.x/2,this.buildVolume.y/2)+20);this.scene.add(e)}if(this.buildVolume&&this.drawBuildVolume(),this.renderTubes){console.warn(`Volumetric rendering is experimental. It may not work as expected or change in the future.`);let e=new Rce(13421772,.3*Math.PI),t=new Lce(16777215,Math.PI,void 0,.001);t.position.set(0,500,500),this.scene.add(e),this.scene.add(t)}}createGroup(e){let t=new FC;return t.name=e,t.quaternion.setFromEuler(new mx(-Math.PI/2,0,0)),this.buildVolume?t.position.set(-this.buildVolume.x/2,0,this.buildVolume.y/2):t.position.set(-100,0,100),t}render(){let e=performance.now();this.group=this.createGroup(`allLayers`),this.state=cT.initial,this.initScene();for(let e=0;e0?e:1)}))}renderFrameLoop(e){return new Promise((t=>{let n=()=>{this.renderLayerIndex>this.layers.length-1?t():(this.renderFrame(e),requestAnimationFrame(n))};n()}))}renderFrame(e){this.group=this.createGroup(`layer`+this.renderLayerIndex);for(let t=0;tthis.maxLayerIndex)return;let t=this.layers[e],n={extrusion:[],travel:[],z:this.state.z,height:t.height};for(let r of t.commands)if(r.gcode!=`g20`){if(r.gcode.startsWith(`t`)){this.doRenderExtrusion(n,e),n.extrusion=[];let t=r;this.state.t=t.toolIndex}else if([`g0`,`g00`,`g1`,`g01`,`g2`,`g02`,`g3`,`g03`].indexOf(r.gcode)>-1){let t=r,i={x:t.params.x??this.state.x,y:t.params.y??this.state.y,z:t.params.z??this.state.z,r:t.params.r??this.state.r,e:t.params.e??this.state.e,i:t.params.i??this.state.i,j:t.params.j??this.state.j,t:this.state.t};if(e>=this.minLayerIndex){let e=(t.params.e??0)>0||this.nonTravelmoves.indexOf(r.gcode)>-1;(i.x!=this.state.x||i.y!=this.state.y||i.z!=this.state.z)&&(e&&this.renderExtrusion||!e&&this.renderTravel)&&(r.gcode==`g2`||r.gcode==`g3`||r.gcode==`g02`||r.gcode==`g03`?this.addArcSegment(n,this.state,i,e,r.gcode==`g2`||r.gcode==`g02`):this.addLineSegment(n,this.state,i,e))}this.state.x=i.x,this.state.y=i.y,this.state.z=i.z,this.beyondFirstMove||=!0}}else this.setInches();this.doRenderExtrusion(n,e)}doRenderExtrusion(e,t){if(this.renderExtrusion){let n=this.currentToolColor;if(!this.singleLayerMode&&!this.renderTubes&&!this.disableGradient){let e=.1+.7*t/this.layers.length;n.getHSL(lT),n=new Vx().setHSL(lT.h,lT.s,e)}if(t==this.layers.length-1){let t=this._topLayerColor??n,r=this._lastSegmentColor??t,i=e.extrusion.splice(-3),a=e.extrusion.splice(-3);this.renderTubes?(this.addTubeLine(e.extrusion,t.getHex(),e.height),this.addTubeLine([...a,...i],r.getHex(),e.height)):(this.addLine(e.extrusion,t.getHex()),this.addLine([...a,...i],r.getHex()))}else this.renderTubes?this.addTubeLine(e.extrusion,n.getHex(),e.height):this.addLine(e.extrusion,n.getHex())}this.renderTravel&&this.addLine(e.travel,this._travelColor.getHex())}setInches(){this.beyondFirstMove?console.warn(`Switching units after movement is already made is discouraged and is not supported.`):this.inches=!0}drawBuildVolume(){if(!this.buildVolume)return;this.scene.add(new fle(this.buildVolume.x,10,this.buildVolume.y,10));let e=ple(this.buildVolume.x,this.buildVolume.z,this.buildVolume.y,8947848);e.position.setY(this.buildVolume.z/2),this.scene.add(e)}clear(){this.resetState(),this.parser=new Fw(this.minLayerThreshold)}resetState(){var e;this.startLayer=1,this.endLayer=1/0,this.singleLayerMode=!1,this.beyondFirstMove=!1,this.state=cT.initial,(e=this.devGui)==null||e.reset(),this._geometries={}}resize(){let[e,t]=[this.canvas.offsetWidth,this.canvas.offsetHeight];this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(e,t,!1)}addLineSegment(e,t,n,r){(r?e.extrusion:e.travel).push(t.x,t.y,t.z,n.x,n.y,n.z)}addArcSegment(e,t,n,r,i){let a=r?e.extrusion:e.travel,o=t.x,s=t.y,c=t.z,l=n.x,u=n.y,d=n.z,f=n.r,p=n.i,m=n.j;if(f){let e=l-o,t=u-s,n=Math.sqrt((e/2)**2+(t/2)**2);f=Math.max(f,n);let r=e**2+t**2,a=f**2-r/4,c=Math.sqrt(a/r);(i&&f<0||!i&&f>0)&&(c=-c),p=e/2+t*c,m=t/2-e*c}let h=o==l&&s==u,g=o+p,_=s+m,v=Math.sqrt(p*p+m*m),y=Math.atan2(-m,-p),b=Math.atan2(u-_,l-g),x;h?x=2*Math.PI:(x=i?y-b:b-y,x<0&&(x+=2*Math.PI));let S=v*x/1.8;this.inches&&(S*=25),S<1&&(S=1);let C=x/S;C*=i?-1:1;let w=[];w.push({x:o,y:s,z:c});let T=(c-d)/S,E=o,D=s,O=c,k=y;for(let e=0;e0)return void this.addThickLine(e,t);let r=new nS;r.setAttribute(`position`,new Yx(e,3)),this.disposables.push(r);let i=new YC({color:t});this.disposables.push(i);let a=new rw(r,i);(n=this.group)==null||n.add(a)}addTubeLine(e,t,n=.2){let r=[],i=[];for(let t=0;t{var r;let i=new hle(e,this.extrusionWidth,this.lineHeight||n,4);(r=this._geometries)[t]||(r[t]=[]),this._geometries[t].push(i)}))}addThickLine(e,t){var n;if(!e.length||!this.lineWidth)return;let r=new Ww;this.disposables.push(r);let i=new Vw({color:t,linewidth:this.lineWidth/(1e3*window.devicePixelRatio)});this.disposables.push(i),r.setPositions(e);let a=new dle(r,i);(n=this.group)==null||n.add(a)}dispose(){this.disposables.forEach((e=>e.dispose())),this.disposables=[],this.controls.dispose(),this.renderer.dispose(),this.cancelAnimation()}cancelAnimation(){this.animationFrameId!==void 0&&cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0}_enableDropHandler(){console.warn(`Drag and drop is deprecated as a library feature. See the demo how to implement your own.`),this.canvas.addEventListener(`dragover`,(e=>{e.stopPropagation(),e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`copy`),this.canvas.classList.add(`dragging`)})),this.canvas.addEventListener(`dragleave`,(e=>{e.stopPropagation(),e.preventDefault(),this.canvas.classList.remove(`dragging`)})),this.canvas.addEventListener(`drop`,(e=>Aw(this,void 0,void 0,(function*(){e.stopPropagation(),e.preventDefault(),this.canvas.classList.remove(`dragging`);let t=(e.dataTransfer?.files??[])[0];this.clear(),yield this._readFromStream(t.stream()),this.render()}))))}batchGeometries(){if(this._geometries)for(let e in this._geometries){let t=this.createBatchMesh(parseInt(e));for(;this._geometries[e].length>0;){let n=this._geometries[e].pop();t.addGeometry(n)}}}createBatchMesh(e){var t;let n=this._geometries[e],r=new Cce({color:e,wireframe:this._wireframe});this.disposables.push(r);let i=n.reduce(((e,t)=>3*t.attributes.position.count+e),0),a=new bce(n.length,i,void 0,r);return this.disposables.push(a),(t=this.group)==null||t.add(a),a}_readFromStream(e){return Aw(this,void 0,void 0,(function*(){let t=e.getReader(),n,r=``,i=0;do{console.debug(`reading from stream`),n=yield t.read(),i+=n.value?.length??0;let e=(a=n.value,new TextDecoder(`utf-8`).decode(a)),o=e.lastIndexOf(` `),s=e.slice(0,o);this.parser.parseGCode(r+s),r=e.slice(o)}while(!n.done);var a;console.debug(`read from stream`,i)}))}initGui(){typeof this.devMode==`boolean`&&!0===this.devMode?this.devGui=new sT(this):typeof this.devMode==`object`&&(this.devGui=new sT(this,this.devMode))}initStats(){this.stats&&(typeof this.devMode==`object`&&(this.statsContainer=this.devMode.statsContainer),(this.statsContainer??document.body).appendChild(this.stats.dom),this.stats.dom.classList.add(`stats`),this.initGui())}};uT.defaultExtrusionColor=new Vx(`hotpink`);function dT({gcodeUrl:e,buildVolume:t={x:256,y:256,z:256},filamentColors:n,className:r=``}){let i=(0,y.useRef)(null),a=(0,y.useRef)(null),o=(0,y.useRef)(null),s=(0,y.useRef)(!1),[c,l]=(0,y.useState)(!0),[u,d]=(0,y.useState)(null),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(0),[g,_]=(0,y.useState)(0);(0,y.useEffect)(()=>{if(!i.current||s.current)return;s.current=!0;let r=i.current,c=r.parentElement?.getBoundingClientRect();c&&(r.width=c.width,r.height=c.height);let u=n&&n.length>1,f=n?.[0]||`#00ae42`,m=new uT({canvas:r,buildVolume:t,backgroundColor:1710618,extrusionColor:u?n:f,disableGradient:!0,lineHeight:.2,lineWidth:2,renderTravel:!1,renderExtrusion:!0});a.current=m;let g={},v=td();v&&(g.Authorization=`Bearer ${v}`),fetch(e,{headers:g}).then(async e=>{if(!e.ok)throw e.status===404&&(await e.json().catch(()=>({}))).detail?.includes(`sliced`)?(p(!0),Error(`not_sliced`)):Error(`Failed to load G-code`);return e.text()}).then(e=>{let t=new Set,r=/^(\s*)T(\d+)(\s*;.*)?$/gim,i;for(;(i=r.exec(e))!==null;){let e=parseInt(i[2],10);e<=15&&t.add(e)}let a=new Map,o=Array.from(t).sort((e,t)=>e-t);o.forEach((e,t)=>{a.set(e,t%8)});let s=[];o.forEach((e,t)=>{let r=n?.[e]||`#00ae42`;s[t%8]=r});let c=e.split(` `).map(e=>{let t=e.match(/^(\s*)T(\d+)(\s*;.*)?$/i);if(t){let n=parseInt(t[2],10);if(n>15)return`; FILTERED: ${e.trim()}`;let r=a.get(n)??0;return`${t[1]}T${r}${t[3]||``}`}return e}).join(` -`);s.length>0&&(m.extrusionColor=s),m.processGCode(c);let u=m.layers?.length||0;_(u),h(u),m.render(),l(!1)}).catch(e=>{e.message!==`not_sliced`&&d(e.message),l(!1)});let y=()=>{if(r.parentElement&&a.current){let e=r.parentElement.getBoundingClientRect();r.width=e.width,r.height=e.height,a.current.resize()}};return window.addEventListener(`resize`,y),()=>{window.removeEventListener(`resize`,y),o.current&&cancelAnimationFrame(o.current),a.current&&=(a.current.dispose(),null),s.current=!1}},[e,(0,y.useMemo)(()=>JSON.stringify(n),[n])]);let v=(0,y.useCallback)(e=>{if(!a.current)return;let t=Math.max(1,Math.min(e,g));h(t),o.current&&cancelAnimationFrame(o.current),o.current=requestAnimationFrame(()=>{a.current&&(a.current.endLayer=t,a.current.render())})},[g]);return(0,K.jsxs)(`div`,{className:`relative flex flex-col h-full ${r}`,children:[(0,K.jsxs)(`div`,{className:`flex-1 relative bg-bambu-dark rounded-lg overflow-hidden`,children:[(0,K.jsx)(`canvas`,{ref:i,className:`w-full h-full`}),c&&(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-bambu-dark/80`,children:(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green mx-auto mb-2`}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:`Loading G-code...`})]})}),f&&(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-bambu-dark/80`,children:(0,K.jsxs)(`div`,{className:`text-center max-w-sm px-4`,children:[(0,K.jsx)(rc,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3`}),(0,K.jsx)(`p`,{className:`text-white font-medium mb-2`,children:`G-code not available`}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:`This file hasn't been sliced yet. G-code preview is only available after slicing in Bambu Studio or Orca Slicer.`})]})}),u&&!f&&(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-bambu-dark/80`,children:(0,K.jsx)(`div`,{className:`text-center text-red-400`,children:(0,K.jsx)(`p`,{className:`text-sm`,children:u})})})]}),!c&&!u&&!f&&g>0&&(0,K.jsx)(`div`,{className:`mt-4 px-2`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(Vc,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsx)(`button`,{onClick:()=>v(m-1),disabled:m<=1,className:`p-1 rounded hover:bg-bambu-dark-tertiary disabled:opacity-30 disabled:cursor-not-allowed`,children:(0,K.jsx)(ls,{className:`w-4 h-4`})}),(0,K.jsx)(`input`,{type:`range`,min:1,max:g,value:m,onChange:e=>{v(parseInt(e.target.value,10))},className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-lg appearance-none cursor-pointer accent-bambu-green`}),(0,K.jsx)(`button`,{onClick:()=>v(m+1),disabled:m>=g,className:`p-1 rounded hover:bg-bambu-dark-tertiary disabled:opacity-30 disabled:cursor-not-allowed`,children:(0,K.jsx)(cs,{className:`w-4 h-4`})}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray min-w-[80px] text-right`,children:[m,` / `,g]})]})})]})}function gle({printerId:e,filePath:t,filename:n,onClose:r}){let[i,a]=(0,y.useState)(null),[o,s]=(0,y.useState)([]),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(null),f=n.toLowerCase().split(`.`).pop()||``,p=f===`3mf`||f===`stl`,m=f===`gcode`||f===`3mf`;(0,y.useEffect)(()=>{a(p?`3d`:m?`gcode`:null)},[p,m]),(0,y.useEffect)(()=>{s([]),d(null),p&&(l(!0),Q.getPrinterFilePlates(e,t).then(e=>s(e.plates||[])).catch(()=>s([])).finally(()=>l(!1)))},[t,p,e]);let h=o.length>1,g=u==null?null:o.find(e=>e.index===u)??null;return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-6`,onClick:r,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-4xl h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate flex-1 mr-4`,children:n}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:r,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`button`,{onClick:()=>p&&a(`3d`),disabled:!p,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${i===`3d`?`text-bambu-green border-b-2 border-bambu-green`:p?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,K.jsx)(qo,{className:`w-4 h-4`}),`3D Model`,!p&&(0,K.jsx)(`span`,{className:`text-xs`,children:`(not available)`})]}),(0,K.jsxs)(`button`,{onClick:()=>m&&a(`gcode`),disabled:!m,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${i===`gcode`?`text-bambu-green border-b-2 border-bambu-green`:m?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,K.jsx)(ac,{className:`w-4 h-4`}),`G-code Preview`,!m&&(0,K.jsx)(`span`,{className:`text-xs`,children:`(not sliced)`})]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-hidden p-4`,children:i===`3d`&&p?(0,K.jsxs)(`div`,{className:`w-full h-full flex flex-col gap-3`,children:[h&&(0,K.jsxs)(`div`,{className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray mb-2`,children:[(0,K.jsx)(qo,{className:`w-4 h-4`}),`Plates`,c&&(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 gap-2`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>d(null),className:`flex items-center gap-2 rounded-lg border p-2 text-left transition-colors ${u==null?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,K.jsx)(qo,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:`All Plates`}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[o.length,` plate`,o.length===1?``:`s`]})]}),u==null&&(0,K.jsx)(uu,{className:`w-4 h-4 text-bambu-green flex-shrink-0`})]}),o.map(n=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>d(n.index),className:`flex items-center gap-2 rounded-lg border p-2 text-left transition-colors ${u===n.index?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[n.has_thumbnail?(0,K.jsx)(`img`,{src:Q.getPrinterFilePlateThumbnail(e,n.index,t),alt:`Plate ${n.index}`,className:`w-10 h-10 rounded object-cover bg-bambu-dark-tertiary`}):(0,K.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,K.jsx)(qo,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:n.name||`Plate ${n.index}`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:n.objects.length>0?n.objects.slice(0,2).join(`, `)+(n.objects.length>2?`…`:``):`${n.filaments.length} filament${n.filaments.length===1?``:`s`}`})]}),u===n.index&&(0,K.jsx)(uu,{className:`w-4 h-4 text-bambu-green flex-shrink-0`})]},n.index))]}),g&&(0,K.jsxs)(`div`,{className:`mt-3 text-xs text-bambu-gray flex flex-wrap gap-x-4 gap-y-1`,children:[(0,K.jsxs)(`span`,{children:[`Plate `,g.index]}),g.print_time_seconds!=null&&(0,K.jsxs)(`span`,{children:[`ETA `,Math.round(g.print_time_seconds/60),` min`]}),g.filament_used_grams!=null&&(0,K.jsxs)(`span`,{children:[g.filament_used_grams.toFixed(1),` g`]}),g.filaments.length>0&&(0,K.jsxs)(`span`,{children:[g.filaments.length,` filament`,g.filaments.length===1?``:`s`]})]})]}),(0,K.jsx)(`div`,{className:`flex-1`,children:(0,K.jsx)(_y,{url:Q.getPrinterFileDownloadUrl(e,t),fileType:f,selectedPlateId:u,className:`w-full h-full`})})]}):i===`gcode`&&m?(0,K.jsx)(dT,{gcodeUrl:Q.getPrinterFileGcodeUrl(e,t),className:`w-full h-full`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:`No preview available for this file`})})]})})}function fT(e){if(e===0)return`0 GB`;let t=e/(1024*1024*1024);return t>=1?`${t.toFixed(1)} GB`:`${(e/(1024*1024)).toFixed(0)} MB`}function _le(e,t){if(t)return hc;switch(e.toLowerCase().split(`.`).pop()||``){case`3mf`:return tc;case`gcode`:return ac;case`mp4`:case`avi`:return sc;case`png`:case`jpg`:case`jpeg`:return Fc;default:return oc}}var vle=[{value:`name-asc`,label:`Name (A-Z)`},{value:`name-desc`,label:`Name (Z-A)`},{value:`size-asc`,label:`Size (smallest)`},{value:`size-desc`,label:`Size (largest)`},{value:`date-asc`,label:`Date (oldest)`},{value:`date-desc`,label:`Date (newest)`}];function yle({printerId:e,printerName:t,onClose:n}){let{t:r}=W(),{showToast:i}=Pd(),a=oo(),[o,s]=(0,y.useState)(`/`),[c,l]=(0,y.useState)(new Set),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)([]),[m,h]=(0,y.useState)(`name-asc`),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(null);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let{data:x,isLoading:S,refetch:C}=q({queryKey:[`printerFiles`,e,o],queryFn:()=>Q.getPrinterFiles(e,o)}),{data:w}=q({queryKey:[`printerStorage`,e],queryFn:()=>Q.getPrinterStorage(e),staleTime:3e4}),T=J({mutationFn:async t=>{for(let n of t)await Q.deletePrinterFile(e,n)},onSuccess:()=>{i(r(`printerFiles.toast.filesDeleted`,{count:f.length})),a.invalidateQueries({queryKey:[`printerFiles`,e]}),l(new Set),p([])},onError:e=>{i(r(`printerFiles.toast.deleteFailed`,{error:e.message}),`error`)}}),E=e=>{s(e),l(new Set)},D=()=>{if(o===`/`)return;let e=o.split(`/`).filter(Boolean);e.pop(),s(e.length?`/`+e.join(`/`):`/`),l(new Set)},O=(e,t)=>{t.stopPropagation(),l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},k=()=>{if(!x?.files)return;let e=x.files.filter(e=>!e.is_directory&&(!u||e.name.toLowerCase().includes(u.toLowerCase()))).map(e=>e.path);l(new Set(e))},A=()=>{l(new Set)},j=async()=>{if(c.size===0)return;let n=Array.from(c);if(n.length===1){Q.downloadPrinterFile(e,n[0]).catch(e=>{console.error(`Printer file download failed:`,e)}),l(new Set);return}_({current:0,total:n.length});try{let r=await Q.downloadPrinterFilesAsZip(e,n),a=URL.createObjectURL(r),o=document.createElement(`a`);o.href=a,o.download=`${t.replace(/[^a-zA-Z0-9]/g,`_`)}-files.zip`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a),i(`Downloaded ${n.length} files as ZIP`),l(new Set)}catch(e){i(`Download failed: ${e instanceof Error?e.message:`Unknown error`}`,`error`)}finally{_(null)}},M=()=>{c.size!==0&&p(Array.from(c))};return(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:n,children:[(0,K.jsxs)(`div`,{className:`w-full max-w-3xl max-h-[85vh] flex flex-col bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(Dc,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`printerFiles.title`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[w&&(w.used_bytes!=null||w.free_bytes!=null)&&(0,K.jsxs)(`div`,{className:`text-sm text-bambu-gray flex items-center gap-2`,children:[w.used_bytes!=null&&(0,K.jsxs)(`span`,{children:[r(`printerFiles.storageUsed`),` `,fT(w.used_bytes)]}),w.used_bytes!=null&&w.free_bytes!=null&&(0,K.jsx)(`span`,{className:`text-bambu-dark-tertiary`,children:`|`}),w.free_bytes!=null&&(0,K.jsxs)(`span`,{children:[r(`printerFiles.storageFree`),` `,fT(w.free_bytes)]})]}),(0,K.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:`Close file manager`,"aria-label":`Close file manager`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50 flex-shrink-0`,children:[[{path:`/`,label:`Root`},{path:`/cache`,label:`Cache`},{path:`/model`,label:`Models`},{path:`/timelapse`,label:`Timelapse`}].map(e=>(0,K.jsx)(`button`,{onClick:()=>{E(e.path),d(``)},className:`px-3 py-1 text-sm rounded-full transition-colors ${o===e.path?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:e.label},e.path)),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Wl,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,placeholder:r(`printerFiles.filterPlaceholder`),value:u,onChange:e=>d(e.target.value),className:`w-40 pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`relative flex items-center gap-1`,children:[(0,K.jsx)(Lo,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`select`,{value:m,onChange:e=>h(e.target.value),className:`appearance-none bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm py-1.5 pl-2 pr-6 focus:border-bambu-green focus:outline-none cursor-pointer`,title:`Sort files`,"aria-label":`Sort files`,children:vle.map(e=>(0,K.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>C(),disabled:S,children:(0,K.jsx)(Pl,{className:`w-4 h-4 ${S?`animate-spin`:``}`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 bg-bambu-dark text-sm flex-shrink-0`,children:[(0,K.jsx)(`button`,{onClick:D,disabled:o===`/`,className:`p-1 rounded hover:bg-bambu-dark-tertiary disabled:opacity-50 disabled:cursor-not-allowed`,title:`Go to parent folder`,"aria-label":`Go to parent folder`,children:(0,K.jsx)(ls,{className:`w-4 h-4`})}),(0,K.jsx)(`span`,{className:`text-bambu-gray font-mono`,children:o})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2 min-h-0`,children:S?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):x?.files?.length?(0,K.jsx)(`div`,{className:`space-y-1`,children:[...x.files].filter(e=>!u||e.name.toLowerCase().includes(u.toLowerCase())).sort((e,t)=>{if(e.is_directory&&!t.is_directory)return-1;if(!e.is_directory&&t.is_directory)return 1;switch(m){case`name-asc`:return e.name.localeCompare(t.name);case`name-desc`:return t.name.localeCompare(e.name);case`size-asc`:return e.size-t.size;case`size-desc`:return t.size-e.size;case`date-asc`:return(e.mtime?jf(e.mtime)?.getTime()??0:0)-(t.mtime?jf(t.mtime)?.getTime()??0:0);case`date-desc`:{let n=e.mtime?jf(e.mtime)?.getTime()??0:0;return(t.mtime?jf(t.mtime)?.getTime()??0:0)-n}default:return e.name.localeCompare(t.name)}}).map(e=>{let t=_le(e.name,e.is_directory),n=c.has(e.path);return(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-lg cursor-pointer transition-colors ${n?`bg-bambu-green/20 border border-bambu-green/50`:`hover:bg-bambu-dark-tertiary`}`,onClick:()=>{e.is_directory&&E(e.path)},children:[e.is_directory?null:(0,K.jsx)(`button`,{onClick:t=>O(e.path,t),className:`flex-shrink-0 text-bambu-gray hover:text-white`,children:n?(0,K.jsx)(uu,{className:`w-5 h-5 text-bambu-green`}):(0,K.jsx)(fu,{className:`w-5 h-5`})}),(0,K.jsx)(t,{className:`w-5 h-5 flex-shrink-0 ${e.is_directory?`text-bambu-green`:`text-bambu-gray`}`}),(0,K.jsx)(`span`,{className:`flex-1 text-white truncate`,children:e.name}),!e.is_directory&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:Md(e.size)}),(e.name.toLowerCase().endsWith(`.3mf`)||e.name.toLowerCase().endsWith(`.gcode`)||e.name.toLowerCase().endsWith(`.stl`))&&(0,K.jsx)(`button`,{onClick:t=>{t.stopPropagation(),b({path:e.path,name:e.name})},className:`p-1 rounded hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`,title:`3D View`,children:(0,K.jsx)(qo,{className:`w-4 h-4`})})]}),e.is_directory&&(0,K.jsx)(ls,{className:`w-4 h-4 text-bambu-gray rotate-180`})]},e.path)})}):(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:`No files in this directory`})}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary bg-bambu-dark/50 flex-shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:c.size>0?`${c.size} selected`:u?`${x?.files?.filter(e=>e.name.toLowerCase().includes(u.toLowerCase())).length||0} of ${x?.files?.length||0} items`:`${x?.files?.length||0} items`}),x?.files?.some(e=>!e.is_directory)&&(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:c.size>0?(0,K.jsxs)(`button`,{onClick:A,className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,K.jsx)(du,{className:`w-4 h-4`}),`Deselect All`]}):(0,K.jsxs)(`button`,{onClick:k,className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,K.jsx)(uu,{className:`w-4 h-4`}),`Select All`]})})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,disabled:c.size===0||g!==null,onClick:j,children:g?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),g.current,`/`,g.total]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Ws,{className:`w-4 h-4`}),`Download`,c.size>1?` (${c.size})`:``]})}),(0,K.jsxs)($,{variant:`secondary`,disabled:c.size===0||T.isPending,onClick:M,className:`text-red-700 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300`,children:[T.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Eu,{className:`w-4 h-4`}),r(`printerFiles.deleteButton`),c.size>1?` (${c.size})`:``]})]})]})]}),f.length>0&&(0,K.jsx)(Vd,{title:f.length>1?r(`printerFiles.deleteFiles`,{count:f.length}):r(`fileManager.deleteFile`),message:f.length>1?r(`printerFiles.deleteFilesConfirm`,{count:f.length}):r(`printerFiles.deleteFileConfirm`,{name:f[0].split(`/`).pop()}),confirmText:r(`common.delete`),variant:`danger`,onConfirm:()=>{T.mutate(f)},onCancel:()=>p([])}),v&&(0,K.jsx)(gle,{printerId:e,filePath:v.path,filename:v.name,onClose:()=>b(null)})]})}function pT({on:e,className:t=`w-5 h-5`}){let n=e?`#facc15`:`none`,r=e?`#78350f`:`currentColor`;return(0,K.jsxs)(`svg`,{viewBox:`0 0 32 32`,fill:`none`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:t,children:[(0,K.jsxs)(`g`,{stroke:r,opacity:+!!e,children:[(0,K.jsx)(`line`,{x1:`16`,y1:`2`,x2:`16`,y2:`6`}),(0,K.jsx)(`line`,{x1:`6.1`,y1:`6.1`,x2:`8.9`,y2:`8.9`}),(0,K.jsx)(`line`,{x1:`25.9`,y1:`6.1`,x2:`23.1`,y2:`8.9`}),(0,K.jsx)(`line`,{x1:`2`,y1:`16`,x2:`6`,y2:`16`}),(0,K.jsx)(`line`,{x1:`30`,y1:`16`,x2:`26`,y2:`16`})]}),(0,K.jsx)(`path`,{d:`M12 24v-2.3c0-.9-.4-1.7-1-2.3C9.2 17.6 8 15.4 8 13c0-4.4 3.6-8 8-8s8 3.6 8 8c0 2.4-1.2 4.6-3 6.4-.6.6-1 1.4-1 2.3V24`,fill:n,stroke:r}),(0,K.jsx)(`path`,{d:`M12 24h8`,stroke:r}),(0,K.jsx)(`path`,{d:`M12 27h8`,stroke:r}),(0,K.jsx)(`path`,{d:`M13 30h6`,stroke:r})]})}function ble(e,t,n){let r=Math.max(0,Math.min(e.width-1,Math.floor(t))),i=(Math.max(0,Math.min(e.height-1,Math.floor(n)))*e.width+r)*4,a=e.data[i],o=e.data[i+1],s=e.data[i+2];return!e.data[i+3]||a===0&&o===0&&s===0?null:a+(o<<8)+(s<<16)}function xle(e,t,n,r,i){let a=Math.min(e.width/t,e.height/n);if(!(a>0))return null;let o=(r-e.left-(e.width-t*a)/2)/a,s=(i-e.top-(e.height-n*a)/2)/a;return o<0||s<0||o>=t||s>=n?null:{x:o,y:s}}var mT=({className:e})=>(0,K.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,children:[(0,K.jsx)(`rect`,{x:`2`,y:`15`,width:`5`,height:`5`,rx:`0.5`}),(0,K.jsx)(`rect`,{x:`9.5`,y:`15`,width:`5`,height:`5`,rx:`0.5`,fill:`currentColor`,opacity:`0.3`}),(0,K.jsx)(`rect`,{x:`17`,y:`15`,width:`5`,height:`5`,rx:`0.5`}),(0,K.jsx)(`path`,{d:`M4 12 C4 6, 14 6, 14 12`}),(0,K.jsx)(`polyline`,{points:`12,10 14,12 12,14`})]});function hT({printerId:e,isOpen:t,onClose:n}){let{t:r}=W(),{showToast:i}=Pd(),{hasPermission:a}=bd(),[o,s]=(0,y.useState)(new Set),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(!1),m=(0,y.useRef)(null),h=(0,y.useRef)(null),g=(0,y.useRef)(null),{data:_}=q({queryKey:[`printerStatus`,e],queryFn:()=>Q.getPrinterStatus(e),refetchInterval:3e4,enabled:t}),{data:v,refetch:b}=q({queryKey:[`printableObjects`,e],queryFn:()=>Q.getPrintableObjects(e),enabled:t,refetchInterval:t?5e3:!1}),x=(v?.objects.length??0)>0,S=x&&_?.cover_url?ad(`${_.cover_url}?view=top`):null,C=x&&_?.cover_url?ad(`${_.cover_url}?view=pick`):null,w=(0,y.useMemo)(()=>(v?.objects??[]).filter(e=>!e.skipped),[v]),T=(0,y.useMemo)(()=>w.filter(e=>o.has(e.id)),[w,o]),E=w.length>0&&T.length===w.length,D=E&&o.size>0,O=o.size>0&&(_?.layer_num??0)>1&&a(`printers:control`),k=J({mutationFn:t=>Q.skipObjects(e,t),onSuccess:async e=>{i(e.message||r(`printers.skipObjects.objectsSkipped`)),await b(),l(!1),s(new Set),n()},onError:e=>{l(!1),i(e.message||r(`printers.toast.failedToSkipObjects`),`error`)}});(0,y.useEffect)(()=>{t||(s(new Set),l(!1),d(!1))},[t]),(0,y.useEffect)(()=>{if(m.current=null,p(!1),!t||!C)return;let e=!1,n=new Image;return n.onload=()=>{if(e)return;let t=document.createElement(`canvas`);t.width=n.naturalWidth||512,t.height=n.naturalHeight||512;let r=t.getContext(`2d`,{willReadFrequently:!0});r&&(r.drawImage(n,0,0),m.current=r.getImageData(0,0,t.width,t.height),p(!0))},n.onerror=()=>{e||p(!1)},n.src=C,()=>{e=!0}},[t,C]),(0,y.useEffect)(()=>{let e=m.current;if(!e||!v)return;let t=new Set(v.objects.filter(e=>e.skipped).map(e=>e.id));for(let n of[h.current,g.current]){if(!n)continue;n.width=e.width,n.height=e.height;let r=n.getContext(`2d`);if(!r)continue;let i=r.createImageData(e.width,e.height);for(let n=0;n{e.skipped||s(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n})},j=e=>{let t=m.current;if(!t)return;let n=xle(e.currentTarget.getBoundingClientRect(),t.width,t.height,e.clientX,e.clientY);if(!n)return;let r=ble(t,n.x,n.y),i=v?.objects.find(e=>e.id===r);i&&A(i)},M=(e=!1)=>(0,K.jsxs)(`div`,{className:`relative aspect-square overflow-hidden rounded-lg border border-gray-300 bg-gray-900 dark:border-gray-600 ${f?`cursor-crosshair`:``}`,children:[S?(0,K.jsx)(`img`,{src:S,alt:r(`printers.printPreview`),className:`absolute inset-0 h-full w-full object-contain`}):(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,K.jsx)(qo,{className:`h-10 w-10 text-gray-500`})}),(0,K.jsx)(`canvas`,{ref:e?g:h,onClick:j,className:`absolute inset-0 h-full w-full object-contain`,"aria-label":r(`printers.skipObjects.selectObjectsToSkip`)}),!e&&S&&(0,K.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),d(!0)},className:`absolute right-2 top-2 rounded bg-black/65 p-1.5 text-white/80 hover:text-white`,title:r(`common.expand`),children:(0,K.jsx)(nl,{className:`h-4 w-4`})}),!f&&S&&(0,K.jsx)(`div`,{className:`absolute bottom-2 left-2 rounded bg-black/70 px-2 py-1 text-[10px] text-white/80`,children:r(`common.unavailable`)})]});return t?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4`,onClick:n,onKeyDown:e=>{e.key===`Escape`&&(u?d(!1):n())},tabIndex:-1,ref:e=>e?.focus(),children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/55`}),(0,K.jsxs)(`section`,{className:`relative z-10 flex max-h-[88vh] w-full max-w-[980px] flex-col overflow-hidden rounded-lg border border-gray-200 bg-white shadow-2xl dark:border-bambu-dark-tertiary dark:bg-bambu-dark`,onClick:e=>e.stopPropagation(),"aria-label":r(`printers.skipObjects.title`),children:[(0,K.jsxs)(`header`,{className:`flex items-center justify-between border-b border-gray-200 bg-gray-50 px-4 py-3 dark:border-bambu-dark-tertiary dark:bg-bambu-dark`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(mT,{className:`h-5 w-5 text-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900 dark:text-white`,children:r(`printers.skipObjects.title`)}),(0,K.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-bambu-gray`,children:r(`printers.skipObjects.selectObjectsToSkip`)})]})]}),(0,K.jsx)(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-gray-500 hover:text-gray-900 dark:text-bambu-gray dark:hover:text-white`,children:(0,K.jsx)(qu,{className:`h-5 w-5`})})]}),v?v.objects.length===0?(0,K.jsxs)(`div`,{className:`px-4 py-12 text-center text-bambu-gray`,children:[(0,K.jsx)(`p`,{className:`text-sm`,children:r(`printers.noObjectsFound`)}),(0,K.jsx)(`p`,{className:`mt-1 text-xs opacity-70`,children:r(`printers.objectsLoadedOnPrintStart`)})]}):(0,K.jsxs)(K.Fragment,{children:[(_?.layer_num??0)<=1&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-amber-400/20 bg-amber-500/10 px-4 py-2 text-xs text-amber-400`,children:[(0,K.jsx)(ps,{className:`h-4 w-4 flex-shrink-0`}),r(`printers.skipObjects.waitForLayer`,{layer:_?.layer_num??0})]}),(0,K.jsxs)(`div`,{className:`grid min-h-0 flex-1 grid-cols-[minmax(320px,1fr)_minmax(340px,0.9fr)] overflow-hidden max-md:grid-cols-1 max-md:overflow-y-auto`,children:[(0,K.jsxs)(`div`,{className:`border-r border-gray-200 bg-gray-50 p-4 dark:border-bambu-dark-tertiary dark:bg-bambu-dark-secondary max-md:border-b-0 max-md:border-r-0`,children:[M(),(0,K.jsxs)(`div`,{className:`mt-3 flex items-center justify-between text-xs text-gray-500 dark:text-bambu-gray`,children:[(0,K.jsxs)(`span`,{children:[o.size,`/`,w.length]}),(0,K.jsxs)(`span`,{children:[v.skipped_count,` `,r(`printers.skipObjects.skipped`)]})]})]}),(0,K.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>s(E?new Set:new Set(w.map(e=>e.id))),className:`flex items-center gap-3 border-b border-gray-200 px-4 py-3 text-left text-sm font-semibold text-gray-900 hover:bg-gray-50 dark:border-bambu-dark-tertiary dark:text-white dark:hover:bg-white/5`,children:[E?(0,K.jsx)(uu,{className:`h-5 w-5 text-bambu-green`}):(0,K.jsx)(fu,{className:`h-5 w-5 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`flex-1`,children:r(E?`common.deselectAll`:`common.selectAll`)}),(0,K.jsx)(`span`,{className:`text-xs font-normal text-bambu-gray`,children:w.length})]}),(0,K.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:v.objects.map((e,t)=>{let n=o.has(e.id);return(0,K.jsxs)(`button`,{type:`button`,onClick:()=>A(e),disabled:e.skipped,className:`flex w-full items-center gap-3 border-b border-gray-200 px-4 py-2.5 text-left transition-colors dark:border-bambu-dark-tertiary/60 ${e.skipped?`cursor-not-allowed bg-red-500/5 opacity-55`:n?`bg-bambu-green/15 hover:bg-bambu-green/20`:`hover:bg-gray-50 dark:hover:bg-white/5`}`,children:[e.skipped||n?(0,K.jsx)(uu,{className:`h-5 w-5 flex-shrink-0 ${e.skipped?`text-red-400`:`text-bambu-green`}`}):(0,K.jsx)(fu,{className:`h-5 w-5 flex-shrink-0 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`w-8 flex-shrink-0 text-xs font-bold text-bambu-gray`,children:t+1}),(0,K.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm ${e.skipped?`text-red-400 line-through`:`text-gray-900 dark:text-white`}`,children:e.name}),(0,K.jsxs)(`span`,{className:`text-[10px] text-bambu-gray`,children:[`ID `,e.id]})]},e.id)})})]})]}),(0,K.jsxs)(`footer`,{className:`flex items-center gap-3 border-t border-gray-200 bg-gray-50 px-4 py-3 dark:border-bambu-dark-tertiary dark:bg-bambu-dark`,children:[(0,K.jsx)(`span`,{className:`mr-auto text-sm text-gray-600 dark:text-bambu-gray`,children:o.size===0?r(`printers.skipObjects.noObjectsSelected`):`${o.size}/${w.length}`}),(0,K.jsx)(`button`,{type:`button`,onClick:n,className:`rounded-md border border-gray-300 px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:border-bambu-dark-tertiary dark:text-white dark:hover:bg-white/5`,children:r(`common.cancel`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>l(!0),disabled:!O||k.isPending,className:`rounded-md bg-red-500 px-4 py-2 text-sm font-semibold text-white hover:bg-red-600 disabled:cursor-not-allowed disabled:opacity-35`,children:k.isPending?r(`printers.skipObjects.skipping`):r(`printers.skipObjects.skipSelected`)})]})]}):(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`h-6 w-6 animate-spin text-bambu-gray`})})]})]}),c&&(0,K.jsx)(Vd,{variant:`warning`,title:r(`printers.skipObjects.confirmTitle`),message:D?r(`printers.skipObjects.confirmAllMessage`):T.length===1?r(`printers.skipObjects.confirmMessage`,{name:T[0].name}):r(`printers.skipObjects.confirmMultipleMessage`,{count:T.length}),confirmText:r(`printers.skipObjects.skipSelected`),isLoading:k.isPending,onConfirm:()=>k.mutate([...o]),onCancel:()=>l(!1)}),u&&(0,K.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/90 p-8`,onClick:()=>d(!1),children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>d(!1),className:`absolute right-4 top-4 rounded p-2 text-white/70 hover:text-white`,children:(0,K.jsx)(qu,{className:`h-6 w-6`})}),(0,K.jsx)(`div`,{className:`aspect-square max-h-[86vh] w-full max-w-[86vh]`,onClick:e=>e.stopPropagation(),children:M(!0)})]})]}):null}function Sle({status:e}){return e===`ok`?(0,K.jsx)(gs,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}):e===`failed`?(0,K.jsx)(xs,{className:`w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0`}):(0,K.jsx)(vs,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`})}function gT({printerId:e,printerName:t,onClose:n}){let{t:r}=W(),i=J({mutationFn:()=>Q.diagnoseCamera(e)});(0,y.useEffect)(()=>{i.mutate()},[]),(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let a=i.data;return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsx)(mu,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:r(`camera.diagnose.modalTitle`,{name:t||``})})]}),(0,K.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:r(`common.close`),children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-6 space-y-4`,children:[i.isPending&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),(0,K.jsx)(`span`,{children:r(`camera.diagnose.running`)})]}),i.isError&&(0,K.jsx)(`div`,{className:`rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 px-4 py-3 text-sm text-red-700 dark:text-red-300`,children:r(`camera.diagnose.runFailed`,{error:i.error.message})}),a&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`ol`,{className:`space-y-2`,children:a.stages.map(e=>(0,K.jsxs)(`li`,{className:`flex items-center gap-3 bg-bambu-dark rounded-lg px-4 py-2.5`,children:[(0,K.jsx)(Sle,{status:e.status}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-sm text-white`,children:r(`camera.diagnose.stage.${e.name}`)}),e.code&&(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray font-mono`,children:e.code})]}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray tabular-nums flex-shrink-0`,children:[e.duration_ms,` ms`]})]},e.name))}),(0,K.jsx)(`div`,{className:a.overall_status===`ok`?`rounded-lg bg-bambu-green/10 border border-bambu-green/30 px-4 py-3 text-sm text-bambu-green`:`rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 px-4 py-3 text-sm text-red-700 dark:text-red-300`,children:r(`camera.diagnose.summary.${a.summary_code}`,{defaultValue:r(`camera.diagnose.summary.unknown_failure`)})}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray space-y-0.5`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[r(`camera.diagnose.meta.protocol`),`: `]}),(0,K.jsx)(`span`,{className:`font-mono`,children:a.protocol}),` • `,(0,K.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[r(`camera.diagnose.meta.port`),`: `]}),(0,K.jsx)(`span`,{className:`font-mono`,children:a.port}),` • `,(0,K.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[r(`camera.diagnose.meta.profile`),`: `]}),(0,K.jsx)(`span`,{className:`font-mono`,children:a.profile})]})})]})]}),(0,K.jsxs)(`div`,{className:`px-6 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>i.mutate(),disabled:i.isPending,className:`px-4 py-2 bg-bambu-dark hover:bg-bambu-dark-tertiary disabled:opacity-50 text-white text-sm rounded-lg transition-colors`,children:r(`camera.diagnose.retry`)}),(0,K.jsx)(`button`,{onClick:n,className:`px-4 py-2 bg-bambu-green hover:bg-bambu-green/90 text-white text-sm rounded-lg transition-colors`,children:r(`common.close`)})]})]})})}var Cle=`embeddedCameraState_`,_T=5,wle=2e3,Tle=3e4,Ele=5e3,vT={x:window.innerWidth-420,y:20,width:400,height:300};function Dle({printerId:e,printerName:t,viewerIndex:n=0,onClose:r}){let{t:i}=W(),a=oo(),{showToast:o}=Pd(),{hasPermission:s}=bd(),c=`${Cle}${e}`,[l,u]=(0,y.useState)(()=>{try{let e=localStorage.getItem(c);if(e){let t=JSON.parse(e);return{x:Math.min(Math.max(0,t.x),window.innerWidth-100),y:Math.min(Math.max(0,t.y),window.innerHeight-100),width:Math.max(200,Math.min(t.width,window.innerWidth-20)),height:Math.max(150,Math.min(t.height,window.innerHeight-20))}}}catch{}let e=n*30;return{...vT,x:Math.max(0,vT.x-e),y:Math.max(0,vT.y+e)}}),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)({x:0,y:0}),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(1),[w,T]=(0,y.useState)({x:0,y:0}),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)({x:0,y:0}),[A,j]=(0,y.useState)(null),[M,N]=(0,y.useState)(null),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(!0),[R,z]=(0,y.useState)(Date.now()),[B,V]=(0,y.useState)(0),[ee,te]=(0,y.useState)(!1),[ne,re]=(0,y.useState)(0),ie=(0,y.useRef)(null),H=(0,y.useRef)(null),ae=(0,y.useRef)(null),oe=(0,y.useRef)(null),U=(0,y.useRef)(null),[se,ce]=(0,y.useState)(!1),[le,ue]=(0,y.useState)(!1),{data:de}=q({queryKey:[`printer`,e],queryFn:()=>Q.getPrinter(e),enabled:e>0}),{data:fe}=q({queryKey:[`printerStatus`,e],queryFn:()=>Q.getPrinterStatus(e),refetchInterval:3e4,enabled:e>0}),pe=J({mutationFn:t=>Q.setChamberLight(e,t),onMutate:async t=>{await a.cancelQueries({queryKey:[`printerStatus`,e]});let n=a.getQueryData([`printerStatus`,e]);return a.setQueryData([`printerStatus`,e],e=>({...e,chamber_light:t})),{previousStatus:n}},onSuccess:(e,t)=>{o(`Chamber light ${t?`on`:`off`}`)},onError:(t,n,r)=>{r?.previousStatus&&a.setQueryData([`printerStatus`,e],r.previousStatus),o(t.message||i(`printers.toast.failedToControlChamberLight`),`error`)}}),me=(fe?.state===`RUNNING`||fe?.state===`PAUSE`)&&(fe?.printable_objects_count??0)>=2;(0,y.useEffect)(()=>{let e=setTimeout(()=>{localStorage.setItem(c,JSON.stringify(l))},500);return()=>clearTimeout(e)},[l,c]);let he=(0,y.useRef)(!1);(0,y.useEffect)(()=>{he.current=!1;let t=`/api/v1/printers/${e}/camera/stop`,n=()=>{if(e>0&&!he.current){he.current=!0;let e={},n=td();n&&(e.Authorization=`Bearer ${n}`),fetch(t,{method:`POST`,keepalive:!0,headers:e}).catch(()=>{})}},r=H.current;return()=>{r&&(r.src=``),n(),ae.current&&clearTimeout(ae.current),oe.current&&clearInterval(oe.current),U.current&&clearInterval(U.current)}},[e]),(0,y.useEffect)(()=>{if(I){let e=setTimeout(()=>L(!1),3e3);return()=>clearTimeout(e)}},[I,R]);let ge=(0,y.useCallback)(()=>{if(B>=_T){te(!1),F(!0);return}let e=Math.min(wle*2**B,Tle);te(!0),re(Math.ceil(e/1e3)),oe.current=setInterval(()=>{re(e=>e<=1?(oe.current&&clearInterval(oe.current),0):e-1)},1e3),ae.current=setTimeout(()=>{V(e=>e+1),te(!1),L(!0),F(!1),H.current&&(H.current.src=``),z(Date.now())},e)},[B]);(0,y.useEffect)(()=>{if(I||ee||_){U.current&&=(clearInterval(U.current),null);return}return U.current=setInterval(async()=>{try{let t=await Q.getCameraStatus(e);(t.stalled||!t.active&&!P)&&(U.current&&=(clearInterval(U.current),null),L(!1),ge())}catch{}},Ele),()=>{U.current&&=(clearInterval(U.current),null)}},[I,P,ee,_,e,ge]),(0,y.useEffect)(()=>{let e=()=>{let e=!!document.fullscreenElement;x(e),e||(C(1),T({x:0,y:0}))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]);let _e=()=>{ie.current&&(document.fullscreenElement?document.exitFullscreen():ie.current.requestFullscreen())},ve=()=>{C(e=>Math.min(e+.5,4))},ye=()=>{C(e=>{let t=Math.max(e-.5,1);return t===1&&T({x:0,y:0}),t})},be=e=>{e.preventDefault(),e.deltaY<0?ve():ye()},xe=e=>{S>1&&(e.preventDefault(),D(!0),k({x:e.clientX-w.x,y:e.clientY-w.y}))},Se=(0,y.useCallback)(()=>{if(!ie.current||!H.current)return{x:200,y:150};let e=ie.current.getBoundingClientRect(),t=e.width*(S-1)/2,n=e.height*(S-1)/2;return{x:Math.max(50,t),y:Math.max(50,n)}},[S]),Ce=e=>{if(E&&S>1){let t=e.clientX-O.x,n=e.clientY-O.y,r=Se();T({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},we=()=>{D(!1)},Te=e=>{if(e.length<2)return 0;let t=e[0].clientX-e[1].clientX,n=e[0].clientY-e[1].clientY;return Math.sqrt(t*t+n*n)},Ee=e=>e.length<2?{x:e[0].clientX,y:e[0].clientY}:{x:(e[0].clientX+e[1].clientX)/2,y:(e[0].clientY+e[1].clientY)/2},De=e=>{e.touches.length===2?(e.preventDefault(),j(Te(e.touches)),N(Ee(e.touches))):e.touches.length===1&&S>1&&(e.preventDefault(),D(!0),k({x:e.touches[0].clientX-w.x,y:e.touches[0].clientY-w.y}))},Oe=e=>{if(e.touches.length===2&&A!==null){e.preventDefault();let t=Te(e.touches),n=t/A;C(e=>{let t=Math.max(1,Math.min(4,e*n));return t===1&&T({x:0,y:0}),t}),j(t);let r=Ee(e.touches);if(M){let e=Se();T(t=>({x:Math.max(-e.x,Math.min(e.x,t.x+(r.x-M.x))),y:Math.max(-e.y,Math.min(e.y,t.y+(r.y-M.y)))}))}N(r)}else if(e.touches.length===1&&E&&S>1){e.preventDefault();let t=e.touches[0].clientX-O.x,n=e.touches[0].clientY-O.y,r=Se();T({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},ke=e=>{e.touches.length<2&&(j(null),N(null)),e.touches.length===0&&D(!1)},Ae=()=>{C(1),T({x:0,y:0})},je=()=>{L(!1),B<_T?ge():F(!0)},Me=()=>{L(!1),F(!1),V(0),te(!1),ae.current&&clearTimeout(ae.current),oe.current&&clearInterval(oe.current)},Ne=()=>{L(!0),F(!1),V(0),te(!1),ae.current&&clearTimeout(ae.current),oe.current&&clearInterval(oe.current);let t={},n=td();n&&(t.Authorization=`Bearer ${n}`),fetch(`/api/v1/printers/${e}/camera/stop`,{method:`POST`,headers:t}).catch(()=>{}),H.current&&(H.current.src=``),setTimeout(()=>z(Date.now()),100)},Pe=e=>{e.target.closest(`.no-drag`)||(f(!0),g({x:e.clientX-l.x,y:e.clientY-l.y}))},Fe=e=>{if(e.target.closest(`.no-drag`))return;let t=e.touches[0];f(!0),g({x:t.clientX-l.x,y:t.clientY-l.y})},Ie=e=>{e.stopPropagation(),m(!0)},Le=e=>{e.stopPropagation(),m(!0)};(0,y.useEffect)(()=>{let e=e=>{if(d)u(t=>({...t,x:Math.max(0,Math.min(e.clientX-h.x,window.innerWidth-t.width)),y:Math.max(0,Math.min(e.clientY-h.y,window.innerHeight-t.height))}));else if(p&&ie.current){let t=ie.current.getBoundingClientRect();u(n=>({...n,width:Math.max(200,Math.min(e.clientX-t.left,window.innerWidth-n.x-10)),height:Math.max(150,Math.min(e.clientY-t.top,window.innerHeight-n.y-10))}))}},t=e=>{if(!d&&!p)return;e.preventDefault();let t=e.touches[0];if(d)u(e=>({...e,x:Math.max(0,Math.min(t.clientX-h.x,window.innerWidth-e.width)),y:Math.max(0,Math.min(t.clientY-h.y,window.innerHeight-e.height))}));else if(p&&ie.current){let e=ie.current.getBoundingClientRect();u(n=>({...n,width:Math.max(200,Math.min(t.clientX-e.left,window.innerWidth-n.x-10)),height:Math.max(150,Math.min(t.clientY-e.top,window.innerHeight-n.y-10))}))}},n=()=>{f(!1),m(!1)};if(d||p)return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,n),document.addEventListener(`touchmove`,t,{passive:!1}),document.addEventListener(`touchend`,n),document.addEventListener(`touchcancel`,n),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,n),document.removeEventListener(`touchmove`,t),document.removeEventListener(`touchend`,n),document.removeEventListener(`touchcancel`,n)}},[d,p,h]);let Re=ad(`/api/v1/printers/${e}/camera/stream?fps=15&t=${R}`);return(0,K.jsxs)(`div`,{ref:ie,className:`${b?`fixed inset-0 z-[100]`:`fixed z-40 rounded-lg shadow-2xl border border-bambu-dark-tertiary`} bg-bambu-dark-secondary overflow-hidden`,style:b?void 0:{left:l.x,top:l.y,width:_?200:l.width,height:_?40:l.height,cursor:d?`grabbing`:`default`},children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 bg-bambu-dark border-b border-bambu-dark-tertiary cursor-grab active:cursor-grabbing`,onMouseDown:Pe,onTouchStart:Fe,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-white truncate`,children:[(0,K.jsx)(wc,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:de?.name||t})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 no-drag`,children:[(0,K.jsx)(`button`,{onClick:()=>pe.mutate(!fe?.chamber_light),disabled:!fe?.connected||pe.isPending||!s(`printers:control`),className:`p-1 rounded disabled:opacity-50 ${fe?.chamber_light?`bg-yellow-500/20 hover:bg-yellow-500/30`:`hover:bg-bambu-dark-tertiary`}`,title:s(`printers:control`)?i(`camera.chamberLight`):i(`printers.permission.noControl`),children:(0,K.jsx)(pT,{on:fe?.chamber_light??!1,className:`w-3.5 h-3.5`})}),(0,K.jsx)(`button`,{onClick:()=>ce(!0),disabled:!me||!s(`printers:control`),className:`p-1 rounded disabled:opacity-50 ${me&&s(`printers:control`)?`hover:bg-bambu-dark-tertiary`:``}`,title:s(`printers:control`)?i(me?`printers.skipObjects.tooltip`:`printers.skipObjects.onlyWhilePrinting`):i(`printers.permission.noControl`),children:(0,K.jsx)(mT,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,K.jsx)(`button`,{onClick:Ne,disabled:I||ee,className:`p-1 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,title:`Refresh stream`,children:(0,K.jsx)(Pl,{className:`w-3.5 h-3.5 text-bambu-gray ${I?`animate-spin`:``}`})}),(0,K.jsx)(`button`,{onClick:()=>ue(!0),className:`p-1 hover:bg-bambu-dark-tertiary rounded`,title:i(`camera.diagnose.button`),children:(0,K.jsx)(mu,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,K.jsx)(`button`,{onClick:_e,className:`p-1 hover:bg-bambu-dark-tertiary rounded`,title:b?`Exit fullscreen`:`Fullscreen`,children:b?(0,K.jsx)(sl,{className:`w-3.5 h-3.5 text-bambu-gray`}):(0,K.jsx)(gc,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,K.jsx)(`button`,{onClick:()=>v(!_),className:`p-1 hover:bg-bambu-dark-tertiary rounded`,title:_?`Expand`:`Minimize`,children:_?(0,K.jsx)(nl,{className:`w-3.5 h-3.5 text-bambu-gray`}):(0,K.jsx)(ol,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,K.jsx)(`button`,{onClick:r,className:`p-1 hover:bg-red-500/20 rounded`,title:`Close`,children:(0,K.jsx)(qu,{className:`w-3.5 h-3.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400`})})]})]}),!_&&(0,K.jsxs)(`div`,{className:`relative w-full bg-black flex items-center justify-center overflow-hidden h-[calc(100%-40px)]`,onWheel:be,onMouseMove:Ce,onMouseUp:we,onMouseLeave:we,onTouchStart:De,onTouchMove:Oe,onTouchEnd:ke,style:{touchAction:`none`},children:[I&&!ee&&(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/50 z-10`,children:(0,K.jsx)(Pl,{className:`w-6 h-6 text-bambu-gray animate-spin`})}),ee&&(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/80 z-10`,children:(0,K.jsxs)(`div`,{className:`text-center p-2`,children:[(0,K.jsx)(Hu,{className:`w-6 h-6 text-orange-400 mx-auto mb-2`}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[`Reconnecting in `,ne,`s...`]})]})}),P&&!ee&&(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black z-10`,children:(0,K.jsxs)(`div`,{className:`text-center p-2`,children:[(0,K.jsx)(ku,{className:`w-6 h-6 text-orange-400 mx-auto mb-2`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:i(`camera.unavailable`)}),(0,K.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,K.jsx)(`button`,{onClick:Ne,className:`px-2 py-1 text-xs bg-bambu-green text-white rounded hover:bg-bambu-green/80`,children:i(`camera.retry`)}),(0,K.jsx)(`button`,{onClick:()=>ue(!0),className:`px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white rounded transition-colors`,children:i(`camera.diagnose.button`)})]})]})}),(0,K.jsx)(`img`,{ref:H,src:Re,alt:`Camera stream`,className:`max-w-full max-h-full object-contain select-none`,style:{transform:`scale(${S}) translate(${w.x/S}px, ${w.y/S}px) rotate(${de?.camera_rotation||0}deg)`,...de?.camera_rotation===90||de?.camera_rotation===270?{maxWidth:`100%`,maxHeight:`100%`}:{},cursor:S>1?E?`grabbing`:`grab`:`default`},onError:je,onLoad:Me,onMouseDown:xe,draggable:!1},R),(0,K.jsxs)(`div`,{className:`absolute bottom-2 left-2 flex items-center gap-1 bg-black/60 rounded px-1.5 py-1 no-drag`,children:[(0,K.jsx)(`button`,{onClick:ye,disabled:S<=1,className:`p-1 hover:bg-white/10 rounded disabled:opacity-30`,title:`Zoom out`,children:(0,K.jsx)(Xu,{className:`w-3.5 h-3.5 text-white`})}),(0,K.jsxs)(`button`,{onClick:Ae,className:`px-1.5 py-0.5 text-xs text-white hover:bg-white/10 rounded min-w-[32px]`,title:`Reset zoom`,children:[Math.round(S*100),`%`]}),(0,K.jsx)(`button`,{onClick:ve,disabled:S>=4,className:`p-1 hover:bg-white/10 rounded disabled:opacity-30`,title:`Zoom in`,children:(0,K.jsx)(Ju,{className:`w-3.5 h-3.5 text-white`})})]}),!b&&(0,K.jsx)(`div`,{className:`absolute bottom-0 right-0 w-6 h-6 cursor-se-resize no-drag hover:bg-white/10 rounded-tl transition-colors`,onMouseDown:Ie,onTouchStart:Le,title:`Drag to resize`,children:(0,K.jsx)(`svg`,{className:`w-6 h-6 text-bambu-gray/70 hover:text-bambu-gray`,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,K.jsx)(`path`,{d:`M22 22H20V20H22V22ZM22 18H20V16H22V18ZM18 22H16V20H18V22ZM22 14H20V12H22V14ZM18 18H16V16H18V18ZM14 22H12V20H14V22ZM22 10H20V8H22V10ZM18 14H16V12H18V14ZM14 18H12V16H14V18ZM10 22H8V20H10V22Z`})})})]}),(0,K.jsx)(hT,{printerId:e,isOpen:se,onClose:()=>ce(!1)}),le&&(0,K.jsx)(gT,{printerId:e,printerName:de?.name||null,onClose:()=>ue(!1)})]})}var Ole=8;function kle(e,t){if(t>0)return`error`;switch(e){case`RUNNING`:return`printing`;case`PAUSE`:return`paused`;case`FINISH`:case`FAILED`:return`finished`;default:return`idle`}}var Ale={printing:`bg-bambu-green/85 text-black`,paused:`bg-amber-500/85 text-black`,finished:`bg-sky-500/80 text-white`,error:`bg-red-500/85 text-white`,idle:`bg-bambu-dark-tertiary/80 text-bambu-gray`};function jle({printerId:e,printerName:t,cameraRotation:n=0,mode:r,snapshotIntervalMs:i,connected:a,onClick:o,statusMode:s=`off`,printerState:c=null,progress:l=null,remainingMin:u=null,layerNum:d=null,totalLayers:f=null,printName:p=null,hmsErrorCount:m=0}){let{t:h}=W(),[g,_]=(0,y.useState)(0),[v,b]=(0,y.useState)(!1),x=(0,y.useRef)(r);(0,y.useEffect)(()=>{let t=x.current===`live`,n=r===`live`;if(x.current=r,t&&!n){let t={},n=td();n&&(t.Authorization=`Bearer ${n}`),fetch(`/api/v1/printers/${e}/camera/stop`,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}b(!1),_(e=>e+1)},[r,e]),(0,y.useEffect)(()=>()=>{if(x.current===`live`){let t={},n=td();n&&(t.Authorization=`Bearer ${n}`),fetch(`/api/v1/printers/${e}/camera/stop`,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}},[e]),(0,y.useEffect)(()=>{if(r!==`snapshot`)return;let e=setInterval(()=>_(e=>e+1),i);return()=>clearInterval(e)},[r,i]);let S=ad(`/api/v1/printers/${e}/camera/stream?fps=${Ole}&t=${g}`),C=ad(`/api/v1/printers/${e}/camera/snapshot?t=${g}`),w=o!=null,T=n?`rotate(${n}deg)`:void 0,E=kle(c,m),D=a&&s!==`off`&&E!==`idle`,O=a&&s===`full`&&(E===`printing`||E===`paused`),k=p??null,A=l==null?null:Math.round(l),j=d!=null&&f!=null&&f>0,M=u!=null&&u>0,N=`group relative aspect-video w-full overflow-hidden rounded-lg border border-bambu-dark-tertiary bg-black text-left ${w?`focus:outline-none focus:ring-2 focus:ring-bambu-green`:`cursor-default`}`,P=(0,K.jsxs)(K.Fragment,{children:[!a||r===`paused`?(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-bambu-dark/60`,children:a?(0,K.jsx)(Iu,{className:`h-8 w-8 text-bambu-gray/70`,"aria-hidden":`true`}):(0,K.jsx)(Hu,{className:`h-8 w-8 text-bambu-gray/70`,"aria-hidden":`true`})}):v?(0,K.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-1 bg-black/80 text-bambu-gray`,children:[(0,K.jsx)(Iu,{className:`h-7 w-7`,"aria-hidden":`true`}),(0,K.jsx)(`span`,{className:`text-xs`,children:h(`printers.camWall.noSignal`)})]}):(0,K.jsx)(`img`,{src:r===`live`?S:C,alt:t,draggable:!1,loading:`lazy`,className:`h-full w-full select-none object-contain`,style:{transform:T},onError:()=>b(!0)},`${r}-${g}`),D&&(0,K.jsxs)(`span`,{className:`absolute left-2 top-2 flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide ${Ale[E]}`,children:[m>0&&(0,K.jsx)(ku,{className:`h-3 w-3`,"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:h(`printers.status.${E}`)})]}),(0,K.jsx)(`span`,{className:`absolute right-2 top-2 rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide ${r===`live`?`bg-red-500/80 text-white`:r===`snapshot`?`bg-amber-500/70 text-black`:`bg-bambu-dark-tertiary/70 text-bambu-gray`}`,children:h(r===`live`?`printers.camWall.live`:r===`snapshot`?`printers.camWall.snap`:`printers.camWall.off`)}),(0,K.jsxs)(`div`,{className:`absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/85 via-black/55 to-transparent px-2 pb-1.5 pt-3 text-white`,children:[O&&(0,K.jsxs)(`div`,{className:`mb-0.5 space-y-0.5 text-[11px] leading-tight text-white/90`,children:[k&&(0,K.jsx)(`div`,{className:`truncate`,title:k,children:k}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 text-bambu-gray`,children:[A!=null&&(0,K.jsxs)(`span`,{className:`font-semibold text-white`,children:[A,`%`]}),j&&(0,K.jsx)(`span`,{children:h(`printers.camWall.layer`,{cur:d,total:f})}),M&&(0,K.jsx)(`span`,{children:h(`printers.camWall.timeLeft`,{time:If((u??0)*60)})})]})]}),(0,K.jsx)(`span`,{className:`block truncate text-xs font-medium`,children:t})]})]});return w?(0,K.jsx)(`button`,{type:`button`,onClick:o,className:N,title:t,children:P}):(0,K.jsx)(`div`,{className:N,title:t,children:P})}var yT=1,bT=16,xT=2,ST=60,Mle=[`off`,`compact`,`full`];function CT({printers:e,maxLive:t,snapshotIntervalSec:n,statusMode:r,onTileClick:i,onChangeMaxLive:a,onChangeSnapshotIntervalSec:o,onChangeStatusMode:s,statuses:c,showSettings:l=!0}){let{t:u}=W(),d=(0,y.useRef)(new Map),f=c?[]:e,p=xo({queries:f.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id),staleTime:5e3}))}),m=(0,y.useMemo)(()=>{let e=new Map;return f.forEach((t,n)=>{e.set(t.id,p[n]?.data)}),e},[e,p,c]),h=c??m,[g,_]=(0,y.useState)(()=>new Set),[v,b]=(0,y.useState)(!1),x=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!v)return;let e=e=>{x.current&&!x.current.contains(e.target)&&b(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[v]),(0,y.useEffect)(()=>{let e=new IntersectionObserver(e=>{_(t=>{let n=new Set(t);for(let t of e){let e=Number(t.target.dataset.printerId);Number.isFinite(e)&&(t.isIntersecting?n.add(e):n.delete(e))}return n})},{threshold:.4});for(let[,t]of d.current)t&&e.observe(t);return()=>e.disconnect()},[e]);let S=(0,y.useMemo)(()=>{let n=new Map,r=Math.max(0,t);for(let t of e){let e=h.get(t.id)?.connected??!1;if(!g.has(t.id)||!e){n.set(t.id,`paused`);continue}r>0?(n.set(t.id,`live`),--r):n.set(t.id,`snapshot`)}return n},[e,g,t,h]);return e.length===0?(0,K.jsx)(`div`,{className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-6 text-center text-bambu-gray`,children:u(`printers.camWall.noPrinters`)}):(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:u(`printers.camWall.summary`,{live:Array.from(S.values()).filter(e=>e===`live`).length,snap:Array.from(S.values()).filter(e=>e===`snapshot`).length,total:e.length})}),l&&(0,K.jsxs)(`div`,{className:`relative`,ref:x,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>b(e=>!e),className:`flex h-7 items-center gap-1 rounded-md border border-bambu-dark-tertiary bg-bambu-dark px-2 text-white hover:bg-bambu-dark-tertiary`,title:u(`printers.camWall.settings.title`),children:[(0,K.jsx)(Yl,{className:`h-3.5 w-3.5`}),(0,K.jsx)(`span`,{children:u(`printers.camWall.settings.title`)})]}),v&&(0,K.jsxs)(`div`,{className:`absolute right-0 top-9 z-30 w-72 space-y-3 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark-secondary p-3 shadow-xl`,children:[(0,K.jsxs)(`label`,{className:`block space-y-1`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium text-white`,children:u(`printers.camWall.settings.maxLive`)}),(0,K.jsx)(`input`,{type:`number`,min:yT,max:bT,value:t,onChange:e=>{a(Math.min(bT,Math.max(yT,Number(e.target.value)||yT)))},className:`w-full rounded-md border border-bambu-dark-tertiary bg-bambu-dark px-2 py-1 text-sm text-white`}),(0,K.jsx)(`span`,{className:`block text-[11px] text-bambu-gray`,children:u(`printers.camWall.settings.maxLiveHint`)})]}),(0,K.jsxs)(`label`,{className:`block space-y-1`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium text-white`,children:u(`printers.camWall.settings.snapshotInterval`)}),(0,K.jsx)(`input`,{type:`number`,min:xT,max:ST,value:n,onChange:e=>{o(Math.min(ST,Math.max(xT,Number(e.target.value)||xT)))},className:`w-full rounded-md border border-bambu-dark-tertiary bg-bambu-dark px-2 py-1 text-sm text-white`}),(0,K.jsx)(`span`,{className:`block text-[11px] text-bambu-gray`,children:u(`printers.camWall.settings.snapshotIntervalHint`)})]}),(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`span`,{className:`block text-xs font-medium text-white`,children:u(`printers.camWall.settings.statusOverlay`)}),(0,K.jsx)(`div`,{role:`radiogroup`,"aria-label":u(`printers.camWall.settings.statusOverlay`),className:`flex overflow-hidden rounded-md border border-bambu-dark-tertiary`,children:Mle.map(e=>(0,K.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":r===e,onClick:()=>s(e),className:`flex-1 px-2 py-1 text-xs ${r===e?`bg-bambu-green text-black font-semibold`:`bg-bambu-dark text-white hover:bg-bambu-dark-tertiary`}`,children:u(`printers.camWall.statusMode.${e}`)},e))}),(0,K.jsx)(`span`,{className:`block text-[11px] text-bambu-gray`,children:u(`printers.camWall.settings.statusOverlayHint`)})]})]})]})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`,children:e.map(e=>{let t=S.get(e.id)??`paused`;return(0,K.jsx)(`div`,{ref:t=>{d.current.set(e.id,t)},"data-printer-id":e.id,children:(0,K.jsx)(jle,{printerId:e.id,printerName:e.name,cameraRotation:e.camera_rotation,mode:t,snapshotIntervalMs:n*1e3,connected:h.get(e.id)?.connected??!1,statusMode:r,printerState:h.get(e.id)?.state??null,progress:h.get(e.id)?.progress??null,remainingMin:h.get(e.id)?.remaining_time??null,layerNum:h.get(e.id)?.layer_num??null,totalLayers:h.get(e.id)?.total_layers??null,printName:h.get(e.id)?.subtask_name??h.get(e.id)?.gcode_file??null,hmsErrorCount:Xp(h.get(e.id)?.hms_errors??[]).length,onClick:i?()=>i(e.id,e.name):void 0})},e.id)})})]})}function Nle({printerId:e,printerName:t,onClose:n}){let{t:r}=W(),i=oo(),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(new Set),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(`all`),p=(0,y.useRef)(null),{data:m,isLoading:h,refetch:g}=q({queryKey:[`mqtt-logs`,e],queryFn:()=>Q.getMQTTLogs(e),refetchInterval:1e3}),_=J({mutationFn:()=>Q.enableMQTTLogging(e),onSuccess:()=>{i.invalidateQueries({queryKey:[`mqtt-logs`,e]})}}),v=J({mutationFn:()=>Q.disableMQTTLogging(e),onSuccess:()=>{i.invalidateQueries({queryKey:[`mqtt-logs`,e]})}}),b=J({mutationFn:()=>Q.clearMQTTLogs(e),onSuccess:()=>{i.invalidateQueries({queryKey:[`mqtt-logs`,e]})}});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,y.useEffect)(()=>{a&&p.current&&(p.current.scrollTop=p.current.scrollHeight)},[m?.logs,a]);let x=e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},S=e=>new Date(e).toLocaleTimeString(`en-US`,{hour12:!1,fractionalSecondDigits:3}),C=(e,t)=>{if(e==null)return``;let n=typeof e==`string`?JSON.parse(e):e,r=JSON.stringify(n,null,t?2:0);return!t&&r.length>100?r.substring(0,100)+`...`:r},w=m?.logging_enabled??!1,T=(0,y.useMemo)(()=>m?.logs??[],[m?.logs]),E=(0,y.useMemo)(()=>T.filter(e=>{if(d!==`all`&&e.direction!==d)return!1;if(l.trim()){let t=l.toLowerCase(),n=e.topic.toLowerCase().includes(t),r=JSON.stringify(e.payload).toLowerCase().includes(t);return n||r}return!0}),[T,l,d]);return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg max-w-4xl w-full max-h-[85vh] flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`mqttDebug.title`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t})]}),(0,K.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[w?(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>v.mutate(),disabled:v.isPending,children:[(0,K.jsx)(fu,{className:`w-4 h-4`}),r(`mqttDebug.stopLogging`)]}):(0,K.jsxs)($,{size:`sm`,onClick:()=>_.mutate(),disabled:_.isPending,children:[(0,K.jsx)(El,{className:`w-4 h-4`}),r(`mqttDebug.startLogging`)]}),(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>b.mutate(),disabled:b.isPending||T.length===0,children:[(0,K.jsx)(Eu,{className:`w-4 h-4`}),r(`mqttDebug.clearLog`)]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>g(),disabled:h,children:(0,K.jsx)(Pl,{className:`w-4 h-4 ${h?`animate-spin`:``}`})}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:a,onChange:e=>o(e.target.checked),className:`rounded border-bambu-dark-tertiary`}),`Auto-scroll`]}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[E.length,`/`,T.length]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(Wl,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,placeholder:r(`mqttDebug.searchPlaceholder`),value:l,onChange:e=>u(e.target.value),className:`w-full pl-8 pr-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),l&&(0,K.jsx)(`button`,{onClick:()=>u(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,K.jsx)(qu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`button`,{onClick:()=>f(`all`),className:`px-2 py-1.5 text-xs rounded-l transition-colors ${d===`all`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:r(`mqttDebug.all`)}),(0,K.jsxs)(`button`,{onClick:()=>f(`in`),className:`px-2 py-1.5 text-xs transition-colors flex items-center gap-1 ${d===`in`?`bg-blue-500 text-white`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(No,{className:`w-3 h-3`}),r(`mqttDebug.incoming`)]}),(0,K.jsxs)(`button`,{onClick:()=>f(`out`),className:`px-2 py-1.5 text-xs rounded-r transition-colors flex items-center gap-1 ${d===`out`?`bg-green-500 text-white`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(zo,{className:`w-3 h-3`}),r(`mqttDebug.outgoing`)]})]})]})]}),(0,K.jsx)(`div`,{ref:p,className:`flex-1 overflow-auto p-4 font-mono text-xs bg-black min-h-[400px]`,children:T.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-bambu-gray`,children:[(0,K.jsx)(`p`,{className:`mb-2`,children:r(`mqttDebug.noMessages`)}),!w&&(0,K.jsx)(`p`,{className:`text-sm`,children:r(`mqttDebug.startLoggingHint`)})]}):E.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-bambu-gray`,children:[(0,K.jsx)(`p`,{className:`mb-2`,children:r(`mqttDebug.noMessagesMatch`)}),(0,K.jsx)(`p`,{className:`text-sm`,children:r(`mqttDebug.adjustFilterHint`)})]}):(0,K.jsx)(`div`,{className:`space-y-1`,children:E.map((e,t)=>{let n=s.has(t),i=e.direction===`in`;return(0,K.jsxs)(`div`,{className:`p-2 rounded cursor-pointer hover:bg-bambu-dark-secondary transition-colors ${n?`bg-bambu-dark-secondary`:``}`,onClick:()=>x(t),children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray shrink-0`,children:S(e.timestamp)}),(0,K.jsx)(`span`,{className:`shrink-0 ${i?`text-blue-400`:`text-green-400`}`,title:r(i?`mqttDebug.incoming`:`mqttDebug.outgoing`),children:i?(0,K.jsx)(No,{className:`w-3 h-3`}):(0,K.jsx)(zo,{className:`w-3 h-3`})}),(0,K.jsx)(`span`,{className:`text-purple-400 shrink-0`,children:e.topic})]}),n?(0,K.jsx)(`pre`,{className:`mt-2 p-3 bg-gray-900 border border-gray-700 rounded text-green-400 overflow-x-auto whitespace-pre-wrap break-all max-h-96 overflow-y-auto text-xs`,children:C(e.payload,!0)}):(0,K.jsx)(`pre`,{className:`mt-1 text-white/80 truncate`,children:C(e.payload,!1)})]},t)})})}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:w?(0,K.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 bg-green-500 rounded-full animate-pulse`}),r(`mqttDebug.loggingActive`)]}):(0,K.jsx)(`span`,{children:r(`mqttDebug.loggingStopped`)})}),(0,K.jsx)($,{variant:`secondary`,onClick:n,children:r(`common.close`)})]})]})})}function wT(e){if(!e)return`/img/printers/default.png`;let t=e.toLowerCase().replace(/\s+/g,``);return t.includes(`x1e`)?`/img/printers/x1e.png`:t.includes(`x1c`)||t.includes(`x1carbon`)||t.includes(`x1`)?`/img/printers/x1c.png`:t.includes(`x2d`)||t===`n6`?`/img/printers/x2d.png`:t.includes(`h2dpro`)||t.includes(`h2d-pro`)?`/img/printers/h2dpro.png`:t.includes(`h2d`)?`/img/printers/h2d.png`:t.includes(`h2c`)?`/img/printers/h2c.png`:t.includes(`h2s`)?`/img/printers/h2d.png`:t.includes(`p2s`)||t.includes(`p1s`)?`/img/printers/p1s.png`:t.includes(`p1p`)?`/img/printers/p1p.png`:t.includes(`a2l`)||t===`n9`?`/img/printers/a2l.png`:t.includes(`a1mini`)?`/img/printers/a1mini.png`:t.includes(`a1`)?`/img/printers/a1.png`:`/img/printers/default.png`}var Ple=[new Set([`X1`,`X1C`,`X1E`,`P1P`,`P1S`])];function TT(e,t){if(!e||!t)return!0;let n=e=>e.trim().toUpperCase().replace(/[\s-]/g,``),r=n(e),i=n(t);return r===i?!0:Ple.some(e=>e.has(r)&&e.has(i))}function ET(e){return e>=-50?{labelKey:`printers.wifiSignal.excellent`,color:`text-bambu-green`,bars:4}:e>=-60?{labelKey:`printers.wifiSignal.good`,color:`text-bambu-green`,bars:3}:e>=-70?{labelKey:`printers.wifiSignal.fair`,color:`text-yellow-400`,bars:2}:e>=-80?{labelKey:`printers.wifiSignal.weak`,color:`text-orange-400`,bars:1}:{labelKey:`printers.wifiSignal.veryWeak`,color:`text-red-400`,bars:1}}function DT(e,t,n){return e.filter(e=>{if(e.required_filament_types&&e.required_filament_types.length>0&&t!==void 0&&!e.required_filament_types.every(e=>t.has(e.toUpperCase())))return!1;if(e.filament_overrides&&e.filament_overrides.length>0&&n!==void 0){let t=e.filament_overrides.filter(e=>e.force_color_match===!0),r=e.filament_overrides.filter(e=>e.force_color_match!==!0);if(t.length>0&&!t.every(e=>{let t=(e.type||``).toUpperCase(),r=(e.color||``).replace(`#`,``).toLowerCase().slice(0,6);return n.has(`${t}:${r}`)})||r.length>0&&t.length===0&&!r.some(e=>{let t=(e.type||``).toUpperCase(),r=(e.color||``).replace(`#`,``).toLowerCase().slice(0,6);return n.has(`${t}:${r}`)}))return!1}return!0})}function Fle({printerId:e,printerModel:t,loadedFilamentTypes:n,loadedFilaments:r,variant:i=`card`}){let{t:a}=W(),{data:o}=q({queryKey:[`queue`,e,`pending`,t],queryFn:()=>Q.getQueue(e,`pending`,t||void 0),refetchInterval:3e4}),s=o?DT(o,n,r):void 0,c=s?.length||0;if(c===0)return null;let l=s?.[0];return(0,K.jsx)(Oi,{to:`/queue`,className:i===`panelExtension`?`block mt-2 border-t border-bambu-dark-tertiary pt-2 pl-1 hover:opacity-90 transition-opacity`:`block mb-3 p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,K.jsx)($o,{className:`w-5 h-5 text-yellow-600 dark:text-yellow-400 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:a(`queue.nextInQueue`)}),(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:l?.archive_name||l?.library_file_name||`File #${l?.archive_id||l?.library_file_id}`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray flex items-center gap-1`,children:[(0,K.jsx)(ws,{className:`w-3 h-3`}),l?.scheduled_time?Lf(l.scheduled_time,`system`,a):a(`time.waiting`)]}),c>1&&(0,K.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 bg-yellow-100 dark:bg-yellow-400/20 text-yellow-700 dark:text-yellow-400 rounded`,children:[`+`,c-1]}),(0,K.jsx)(cs,{className:`w-4 h-4 text-bambu-gray`})]})]})})}function OT(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`)if(Array.isArray(e)){var i=e.length;for(t=0;t{var{children:n,width:r,height:i,viewBox:a,className:o,style:s,title:c,desc:l}=e,u=Ble(e,zle),d=a||{width:r,height:i,x:0,y:0},f=kT(`recharts-surface`,o);return y.createElement(`svg`,IT({},FT(u),{className:f,width:r,height:i,style:s,viewBox:`${d.x} ${d.y} ${d.width} ${d.height}`,ref:t}),y.createElement(`title`,null,c),y.createElement(`desc`,null,l),n)}),Hle=[`children`,`className`];function RT(){return RT=Object.assign?Object.assign.bind():function(e){for(var t=1;t{var{children:n,className:r}=e,i=Ule(e,Hle),a=kT(`recharts-layer`,r);return y.createElement(`g`,RT({className:a},FT(i),{ref:t}),n)}),BT=(0,y.createContext)(null),Gle=()=>(0,y.useContext)(BT);function VT(e){return function(){return e}}var HT=Math.cos,UT=Math.sin,WT=Math.sqrt,GT=Math.PI;GT/2;var KT=2*GT,qT=Math.PI,JT=2*qT,YT=1e-6,Kle=JT-YT;function XT(e){this._+=e[0];for(let t=1,n=e.length;t=0))throw Error(`invalid digits: ${e}`);if(t>15)return XT;let n=10**t;return function(e){this._+=e[0];for(let t=1,r=e.length;tYT)if(!(Math.abs(u*s-c*l)>YT)||!i)this._append`L${this._x1=e},${this._y1=t}`;else{let f=n-a,p=r-o,m=s*s+c*c,h=f*f+p*p,g=Math.sqrt(m),_=Math.sqrt(d),v=i*Math.tan((qT-Math.acos((m+d-h)/(2*g*_)))/2),y=v/_,b=v/g;Math.abs(y-1)>YT&&this._append`L${e+y*l},${t+y*u}`,this._append`A${i},${i},0,0,${+(u*f>l*p)},${this._x1=e+b*s},${this._y1=t+b*c}`}}arc(e,t,n,r,i,a){if(e=+e,t=+t,n=+n,a=!!a,n<0)throw Error(`negative radius: ${n}`);let o=n*Math.cos(r),s=n*Math.sin(r),c=e+o,l=t+s,u=1^a,d=a?r-i:i-r;this._x1===null?this._append`M${c},${l}`:(Math.abs(this._x1-c)>YT||Math.abs(this._y1-l)>YT)&&this._append`L${c},${l}`,n&&(d<0&&(d=d%JT+JT),d>Kle?this._append`A${n},${n},0,1,${u},${e-o},${t-s}A${n},${n},0,1,${u},${this._x1=c},${this._y1=l}`:d>YT&&this._append`A${n},${n},0,${+(d>=qT)},${u},${this._x1=e+n*Math.cos(i)},${this._y1=t+n*Math.sin(i)}`)}rect(e,t,n,r){this._append`M${this._x0=this._x1=+e},${this._y0=this._y1=+t}h${n=+n}v${+r}h${-n}Z`}toString(){return this._}};function Jle(){return new ZT}Jle.prototype=ZT.prototype;function QT(e){let t=3;return e.digits=function(n){if(!arguments.length)return t;if(n==null)t=null;else{let e=Math.floor(n);if(!(e>=0))throw RangeError(`invalid digits: ${n}`);t=e}return e},()=>new ZT(t)}Array.prototype.slice;function $T(e){return typeof e==`object`&&`length`in e?e:Array.from(e)}function eE(e){this._context=e}eE.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:this._context.lineTo(e,t);break}}};function tE(e){return new eE(e)}function nE(e){return e[0]}function rE(e){return e[1]}function iE(e,t){var n=VT(!0),r=null,i=tE,a=null,o=QT(s);e=typeof e==`function`?e:e===void 0?nE:VT(e),t=typeof t==`function`?t:t===void 0?rE:VT(t);function s(s){var c,l=(s=$T(s)).length,u,d=!1,f;for(r??(a=i(f=o())),c=0;c<=l;++c)!(c=d;--f)s.point(_[f],v[f]);s.lineEnd(),s.areaEnd()}h&&(_[u]=+e(m,u,l),v[u]=+t(m,u,l),s.point(r?+r(m,u,l):_[u],n?+n(m,u,l):v[u]))}if(g)return s=null,g+``||null}function u(){return iE().defined(i).curve(o).context(a)}return l.x=function(t){return arguments.length?(e=typeof t==`function`?t:VT(+t),r=null,l):e},l.x0=function(t){return arguments.length?(e=typeof t==`function`?t:VT(+t),l):e},l.x1=function(e){return arguments.length?(r=e==null?null:typeof e==`function`?e:VT(+e),l):r},l.y=function(e){return arguments.length?(t=typeof e==`function`?e:VT(+e),n=null,l):t},l.y0=function(e){return arguments.length?(t=typeof e==`function`?e:VT(+e),l):t},l.y1=function(e){return arguments.length?(n=e==null?null:typeof e==`function`?e:VT(+e),l):n},l.lineX0=l.lineY0=function(){return u().x(e).y(t)},l.lineY1=function(){return u().x(e).y(n)},l.lineX1=function(){return u().x(r).y(t)},l.defined=function(e){return arguments.length?(i=typeof e==`function`?e:VT(!!e),l):i},l.curve=function(e){return arguments.length?(o=e,a!=null&&(s=o(a)),l):o},l.context=function(e){return arguments.length?(e==null?a=s=null:s=o(a=e),l):a},l}var oE=class{constructor(e,t){this._context=e,this._x=t}areaStart(){this._line=0}areaEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line}point(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:this._x?this._context.bezierCurveTo(this._x0=(this._x0+e)/2,this._y0,this._x0,t,e,t):this._context.bezierCurveTo(this._x0,this._y0=(this._y0+t)/2,e,this._y0,e,t);break}this._x0=e,this._y0=t}};function Yle(e){return new oE(e,!0)}function Xle(e){return new oE(e,!1)}var sE={draw(e,t){let n=WT(t/GT);e.moveTo(n,0),e.arc(0,0,n,0,KT)}},Zle={draw(e,t){let n=WT(t/5)/2;e.moveTo(-3*n,-n),e.lineTo(-n,-n),e.lineTo(-n,-3*n),e.lineTo(n,-3*n),e.lineTo(n,-n),e.lineTo(3*n,-n),e.lineTo(3*n,n),e.lineTo(n,n),e.lineTo(n,3*n),e.lineTo(-n,3*n),e.lineTo(-n,n),e.lineTo(-3*n,n),e.closePath()}},cE=WT(1/3),Qle=cE*2,$le={draw(e,t){let n=WT(t/Qle),r=n*cE;e.moveTo(0,-n),e.lineTo(r,0),e.lineTo(0,n),e.lineTo(-r,0),e.closePath()}},eue={draw(e,t){let n=WT(t),r=-n/2;e.rect(r,r,n,n)}},tue=.8908130915292852,lE=UT(GT/10)/UT(7*GT/10),nue=UT(KT/10)*lE,rue=-HT(KT/10)*lE,iue={draw(e,t){let n=WT(t*tue),r=nue*n,i=rue*n;e.moveTo(0,-n),e.lineTo(r,i);for(let t=1;t<5;++t){let a=KT*t/5,o=HT(a),s=UT(a);e.lineTo(s*n,-o*n),e.lineTo(o*r-s*i,s*r+o*i)}e.closePath()}},uE=WT(3),aue={draw(e,t){let n=-WT(t/(uE*3));e.moveTo(0,n*2),e.lineTo(-uE*n,-n),e.lineTo(uE*n,-n),e.closePath()}},dE=-.5,fE=WT(3)/2,pE=1/WT(12),oue=(pE/2+1)*3,sue={draw(e,t){let n=WT(t/oue),r=n/2,i=n*pE,a=r,o=n*pE+n,s=-a,c=o;e.moveTo(r,i),e.lineTo(a,o),e.lineTo(s,c),e.lineTo(dE*r-fE*i,fE*r+dE*i),e.lineTo(dE*a-fE*o,fE*a+dE*o),e.lineTo(dE*s-fE*c,fE*s+dE*c),e.lineTo(dE*r+fE*i,dE*i-fE*r),e.lineTo(dE*a+fE*o,dE*o-fE*a),e.lineTo(dE*s+fE*c,dE*c-fE*s),e.closePath()}};function cue(e,t){let n=null,r=QT(i);e=typeof e==`function`?e:VT(e||sE),t=typeof t==`function`?t:VT(t===void 0?64:+t);function i(){let i;if(n||=i=r(),e.apply(this,arguments).draw(n,+t.apply(this,arguments)),i)return n=null,i+``||null}return i.type=function(t){return arguments.length?(e=typeof t==`function`?t:VT(t),i):e},i.size=function(e){return arguments.length?(t=typeof e==`function`?e:VT(+e),i):t},i.context=function(e){return arguments.length?(n=e??null,i):n},i}function mE(){}function hE(e,t,n){e._context.bezierCurveTo((2*e._x0+e._x1)/3,(2*e._y0+e._y1)/3,(e._x0+2*e._x1)/3,(e._y0+2*e._y1)/3,(e._x0+4*e._x1+t)/6,(e._y0+4*e._y1+n)/6)}function gE(e){this._context=e}gE.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:hE(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1);break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:hE(this,e,t);break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function lue(e){return new gE(e)}function _E(e){this._context=e}_E.prototype={areaStart:mE,areaEnd:mE,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x2,this._y2),this._context.closePath();break;case 2:this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath();break;case 3:this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4);break}},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._x2=e,this._y2=t;break;case 1:this._point=2,this._x3=e,this._y3=t;break;case 2:this._point=3,this._x4=e,this._y4=t,this._context.moveTo((this._x0+4*this._x1+e)/6,(this._y0+4*this._y1+t)/6);break;default:hE(this,e,t);break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function uue(e){return new _E(e)}function vE(e){this._context=e}vE.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===3)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3;var n=(this._x0+4*this._x1+e)/6,r=(this._y0+4*this._y1+t)/6;this._line?this._context.lineTo(n,r):this._context.moveTo(n,r);break;case 3:this._point=4;default:hE(this,e,t);break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function due(e){return new vE(e)}function yE(e){this._context=e}yE.prototype={areaStart:mE,areaEnd:mE,lineStart:function(){this._point=0},lineEnd:function(){this._point&&this._context.closePath()},point:function(e,t){e=+e,t=+t,this._point?this._context.lineTo(e,t):(this._point=1,this._context.moveTo(e,t))}};function fue(e){return new yE(e)}function bE(e){return e<0?-1:1}function xE(e,t,n){var r=e._x1-e._x0,i=t-e._x1,a=(e._y1-e._y0)/(r||i<0&&-0),o=(n-e._y1)/(i||r<0&&-0),s=(a*i+o*r)/(r+i);return(bE(a)+bE(o))*Math.min(Math.abs(a),Math.abs(o),.5*Math.abs(s))||0}function SE(e,t){var n=e._x1-e._x0;return n?(3*(e._y1-e._y0)/n-t)/2:t}function CE(e,t,n){var r=e._x0,i=e._y0,a=e._x1,o=e._y1,s=(a-r)/3;e._context.bezierCurveTo(r+s,i+s*t,a-s,o-s*n,a,o)}function wE(e){this._context=e}wE.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:CE(this,this._t0,SE(this,this._t0));break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){var n=NaN;if(e=+e,t=+t,!(e===this._x1&&t===this._y1)){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,CE(this,SE(this,n=xE(this,e,t)),n);break;default:CE(this,this._t0,n=xE(this,e,t));break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t,this._t0=n}}};function TE(e){this._context=new EE(e)}(TE.prototype=Object.create(wE.prototype)).point=function(e,t){wE.prototype.point.call(this,t,e)};function EE(e){this._context=e}EE.prototype={moveTo:function(e,t){this._context.moveTo(t,e)},closePath:function(){this._context.closePath()},lineTo:function(e,t){this._context.lineTo(t,e)},bezierCurveTo:function(e,t,n,r,i,a){this._context.bezierCurveTo(t,e,r,n,a,i)}};function pue(e){return new wE(e)}function mue(e){return new TE(e)}function DE(e){this._context=e}DE.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=[],this._y=[]},lineEnd:function(){var e=this._x,t=this._y,n=e.length;if(n)if(this._line?this._context.lineTo(e[0],t[0]):this._context.moveTo(e[0],t[0]),n===2)this._context.lineTo(e[1],t[1]);else for(var r=OE(e),i=OE(t),a=0,o=1;o=0;--t)i[t]=(o[t]-i[t+1])/a[t];for(a[n-1]=(e[n]+i[n-1])/2,t=0;t=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:if(this._t<=0)this._context.lineTo(this._x,t),this._context.lineTo(e,t);else{var n=this._x*(1-this._t)+e*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,t)}break}this._x=e,this._y=t}};function gue(e){return new kE(e,.5)}function _ue(e){return new kE(e,0)}function vue(e){return new kE(e,1)}function AE(e,t){if((o=e.length)>1)for(var n=1,r,i,a=e[t[0]],o,s=a.length;n=0;)n[t]=t;return n}function yue(e,t){return e[t]}function bue(e){let t=[];return t.key=e,t}function xue(){var e=VT([]),t=jE,n=AE,r=yue;function i(i){var a=Array.from(e.apply(this,arguments),bue),o,s=a.length,c=-1,l;for(let e of i)for(o=0,++c;o0){for(var n,r,i=0,a=e[0].length,o;i0){for(var n=0,r=e[t[0]],i,a=r.length;n0)||!((a=(i=e[t[0]]).length)>0))){for(var n=0,r=1,i,a,o;r{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return e===`__proto__`}e.isUnsafeProperty=t})),ME=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){switch(typeof e){case`number`:case`symbol`:return!1;case`string`:return e.includes(`.`)||e.includes(`[`)||e.includes(`]`)}}e.isDeepKey=t})),NE=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return typeof e==`string`||typeof e==`symbol`?e:Object.is(e?.valueOf?.(),-0)?`-0`:String(e)}e.toKey=t})),Eue=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){if(e==null)return``;if(typeof e==`string`)return e;if(Array.isArray(e))return e.map(t).join(`,`);let n=String(e);return n===`0`&&Object.is(Number(e),-0)?`-0`:n}e.toString=t})),PE=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Eue(),n=NE();function r(e){if(Array.isArray(e))return e.map(n.toKey);if(typeof e==`symbol`)return[e];e=t.toString(e);let r=[],i=e.length;if(i===0)return r;let a=0,o=``,s=``,c=!1;for(e.charCodeAt(0)===46&&(r.push(``),a++);a{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Tue(),n=ME(),r=NE(),i=PE();function a(e,s,c){if(e==null)return c;switch(typeof s){case`string`:{if(t.isUnsafeProperty(s))return c;let r=e[s];return r===void 0?n.isDeepKey(s)?a(e,i.toPath(s),c):c:r}case`number`:case`symbol`:{typeof s==`number`&&(s=r.toKey(s));let t=e[s];return t===void 0?c:t}default:{if(Array.isArray(s))return o(e,s,c);if(s=Object.is(s?.valueOf(),-0)?`-0`:String(s),t.isUnsafeProperty(s))return c;let n=e[s];return n===void 0?c:n}}}function o(e,n,r){if(n.length===0)return r;let i=e;for(let e=0;e{t.exports=FE().get})),Oue=4;function IE(e){var t=10**(arguments.length>1&&arguments[1]!==void 0?arguments[1]:Oue),n=Math.round(e*t)/t;return Object.is(n,-0)?0:n}function LE(e){var t=[...arguments].slice(1);return e.reduce((e,n,r)=>{var i=t[r-1];return typeof i==`string`?e+i+n:i===void 0?e+n:e+IE(i)+n},``)}var RE=l(Due()),zE=e=>e===0?0:e>0?1:-1,BE=e=>typeof e==`number`&&e!=+e,VE=e=>typeof e==`string`&&e.indexOf(`%`)===e.length-1,HE=e=>(typeof e==`number`||e instanceof Number)&&!BE(e),UE=e=>HE(e)||typeof e==`string`,kue=0,WE=e=>{var t=++kue;return`${e||``}${t}`},GE=function(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:!1;if(!HE(e)&&typeof e!=`string`)return n;var i;if(VE(e)){if(t==null)return n;var a=e.indexOf(`%`);i=t*parseFloat(e.slice(0,a))/100}else i=+e;return BE(i)&&(i=n),r&&t!=null&&i>t&&(i=t),i},KE=e=>{if(!Array.isArray(e))return!1;for(var t=e.length,n={},r=0;re&&(typeof t==`function`?t(e):(0,RE.default)(e,t))===n)}var YE=e=>e==null,XE=e=>YE(e)?e:`${e.charAt(0).toUpperCase()}${e.slice(1)}`;function ZE(e){return e!=null}function QE(){}var Aue=[`type`,`size`,`sizeType`];function $E(){return $E=Object.assign?Object.assign.bind():function(e){for(var t=1;tnD[`symbol${XE(e)}`]||sE,Rue=(e,t,n)=>{if(t===`area`)return e;switch(n){case`cross`:return 5*e*e/9;case`diamond`:return .5*e*e/Math.sqrt(3);case`square`:return e*e;case`star`:var r=18*Iue;return 1.25*e*e*(Math.tan(r)-Math.tan(r*2)*Math.tan(r)**2);case`triangle`:return Math.sqrt(3)*e*e/4;case`wye`:return(21-10*Math.sqrt(3))*e*e/8;default:return Math.PI*e*e/4}},zue=(e,t)=>{nD[`symbol${XE(e)}`]=t},rD=e=>{var{type:t=`circle`,size:n=64,sizeType:r=`area`}=e,i=tD(tD({},Pue(e,Aue)),{},{type:t,size:n,sizeType:r}),a=`circle`;typeof t==`string`&&(a=t);var o=()=>{var e=Lue(a),t=cue().type(e).size(Rue(n,r,a))();if(t!==null)return t},{className:s,cx:c,cy:l}=i,u=FT(i);return HE(c)&&HE(l)&&HE(n)?y.createElement(`path`,$E({},u,{className:kT(`recharts-symbols`,s),transform:`translate(${c}, ${l})`,d:o()})):null};rD.registerSymbol=zue;var iD=e=>`radius`in e&&`startAngle`in e&&`endAngle`in e,aD=(e,t)=>{if(!e||typeof e==`function`||typeof e==`boolean`)return null;var n=e;if((0,y.isValidElement)(e)&&(n=e.props),typeof n!=`object`&&typeof n!=`function`)return null;var r={};return Object.keys(n).forEach(e=>{AT(e)&&(r[e]=t||(t=>n[e](n,t)))}),r},Bue=(e,t,n)=>r=>(e(t,n,r),null),oD=(e,t,n)=>{if(e===null||typeof e!=`object`&&typeof e!=`function`)return null;var r=null;return Object.keys(e).forEach(i=>{var a=e[i];AT(i)&&typeof a==`function`&&(r||={},r[i]=Bue(a,t,n))}),r};function sD(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 Vue(e){for(var t=1;t(e[t]===void 0&&r[t]!==void 0&&(e[t]=r[t]),e),n)}function lD(){return lD=Object.assign?Object.assign.bind():function(e){for(var t=1;t0&&(m.extrusionColor=s),m.processGCode(c);let u=m.layers?.length||0;_(u),h(u),m.render(),l(!1)}).catch(e=>{e.message!==`not_sliced`&&d(e.message),l(!1)});let y=()=>{if(r.parentElement&&a.current){let e=r.parentElement.getBoundingClientRect();r.width=e.width,r.height=e.height,a.current.resize()}};return window.addEventListener(`resize`,y),()=>{window.removeEventListener(`resize`,y),o.current&&cancelAnimationFrame(o.current),a.current&&=(a.current.dispose(),null),s.current=!1}},[e,(0,y.useMemo)(()=>JSON.stringify(n),[n])]);let v=(0,y.useCallback)(e=>{if(!a.current)return;let t=Math.max(1,Math.min(e,g));h(t),o.current&&cancelAnimationFrame(o.current),o.current=requestAnimationFrame(()=>{a.current&&(a.current.endLayer=t,a.current.render())})},[g]);return(0,K.jsxs)(`div`,{className:`relative flex flex-col h-full ${r}`,children:[(0,K.jsxs)(`div`,{className:`flex-1 relative bg-bambu-dark rounded-lg overflow-hidden`,children:[(0,K.jsx)(`canvas`,{ref:i,className:`w-full h-full`}),c&&(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-bambu-dark/80`,children:(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green mx-auto mb-2`}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:`Loading G-code...`})]})}),f&&(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-bambu-dark/80`,children:(0,K.jsxs)(`div`,{className:`text-center max-w-sm px-4`,children:[(0,K.jsx)(rc,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3`}),(0,K.jsx)(`p`,{className:`text-white font-medium mb-2`,children:`G-code not available`}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:`This file hasn't been sliced yet. G-code preview is only available after slicing in Bambu Studio or Orca Slicer.`})]})}),u&&!f&&(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-bambu-dark/80`,children:(0,K.jsx)(`div`,{className:`text-center text-red-400`,children:(0,K.jsx)(`p`,{className:`text-sm`,children:u})})})]}),!c&&!u&&!f&&g>0&&(0,K.jsx)(`div`,{className:`mt-4 px-2`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(Vc,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsx)(`button`,{onClick:()=>v(m-1),disabled:m<=1,className:`p-1 rounded hover:bg-bambu-dark-tertiary disabled:opacity-30 disabled:cursor-not-allowed`,children:(0,K.jsx)(ls,{className:`w-4 h-4`})}),(0,K.jsx)(`input`,{type:`range`,min:1,max:g,value:m,onChange:e=>{v(parseInt(e.target.value,10))},className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-lg appearance-none cursor-pointer accent-bambu-green`}),(0,K.jsx)(`button`,{onClick:()=>v(m+1),disabled:m>=g,className:`p-1 rounded hover:bg-bambu-dark-tertiary disabled:opacity-30 disabled:cursor-not-allowed`,children:(0,K.jsx)(cs,{className:`w-4 h-4`})}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray min-w-[80px] text-right`,children:[m,` / `,g]})]})})]})}function gle({printerId:e,filePath:t,filename:n,onClose:r}){let[i,a]=(0,y.useState)(null),[o,s]=(0,y.useState)([]),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(null),f=n.toLowerCase().split(`.`).pop()||``,p=f===`3mf`||f===`stl`,m=f===`gcode`||f===`3mf`;(0,y.useEffect)(()=>{a(p?`3d`:m?`gcode`:null)},[p,m]),(0,y.useEffect)(()=>{s([]),d(null),p&&(l(!0),Q.getPrinterFilePlates(e,t).then(e=>s(e.plates||[])).catch(()=>s([])).finally(()=>l(!1)))},[t,p,e]);let h=o.length>1,g=u==null?null:o.find(e=>e.index===u)??null;return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-6`,onClick:r,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-4xl h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate flex-1 mr-4`,children:n}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:r,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`button`,{onClick:()=>p&&a(`3d`),disabled:!p,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${i===`3d`?`text-bambu-green border-b-2 border-bambu-green`:p?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,K.jsx)(qo,{className:`w-4 h-4`}),`3D Model`,!p&&(0,K.jsx)(`span`,{className:`text-xs`,children:`(not available)`})]}),(0,K.jsxs)(`button`,{onClick:()=>m&&a(`gcode`),disabled:!m,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${i===`gcode`?`text-bambu-green border-b-2 border-bambu-green`:m?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,K.jsx)(ac,{className:`w-4 h-4`}),`G-code Preview`,!m&&(0,K.jsx)(`span`,{className:`text-xs`,children:`(not sliced)`})]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-hidden p-4`,children:i===`3d`&&p?(0,K.jsxs)(`div`,{className:`w-full h-full flex flex-col gap-3`,children:[h&&(0,K.jsxs)(`div`,{className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray mb-2`,children:[(0,K.jsx)(qo,{className:`w-4 h-4`}),`Plates`,c&&(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 gap-2`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>d(null),className:`flex items-center gap-2 rounded-lg border p-2 text-left transition-colors ${u==null?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,K.jsx)(qo,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:`All Plates`}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[o.length,` plate`,o.length===1?``:`s`]})]}),u==null&&(0,K.jsx)(uu,{className:`w-4 h-4 text-bambu-green flex-shrink-0`})]}),o.map(n=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>d(n.index),className:`flex items-center gap-2 rounded-lg border p-2 text-left transition-colors ${u===n.index?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[n.has_thumbnail?(0,K.jsx)(`img`,{src:Q.getPrinterFilePlateThumbnail(e,n.index,t),alt:`Plate ${n.index}`,className:`w-10 h-10 rounded object-cover bg-bambu-dark-tertiary`}):(0,K.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,K.jsx)(qo,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:n.name||`Plate ${n.index}`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:n.objects.length>0?n.objects.slice(0,2).join(`, `)+(n.objects.length>2?`…`:``):`${n.filaments.length} filament${n.filaments.length===1?``:`s`}`})]}),u===n.index&&(0,K.jsx)(uu,{className:`w-4 h-4 text-bambu-green flex-shrink-0`})]},n.index))]}),g&&(0,K.jsxs)(`div`,{className:`mt-3 text-xs text-bambu-gray flex flex-wrap gap-x-4 gap-y-1`,children:[(0,K.jsxs)(`span`,{children:[`Plate `,g.index]}),g.print_time_seconds!=null&&(0,K.jsxs)(`span`,{children:[`ETA `,Math.round(g.print_time_seconds/60),` min`]}),g.filament_used_grams!=null&&(0,K.jsxs)(`span`,{children:[g.filament_used_grams.toFixed(1),` g`]}),g.filaments.length>0&&(0,K.jsxs)(`span`,{children:[g.filaments.length,` filament`,g.filaments.length===1?``:`s`]})]})]}),(0,K.jsx)(`div`,{className:`flex-1`,children:(0,K.jsx)(_y,{url:Q.getPrinterFileDownloadUrl(e,t),fileType:f,selectedPlateId:u,className:`w-full h-full`})})]}):i===`gcode`&&m?(0,K.jsx)(dT,{gcodeUrl:Q.getPrinterFileGcodeUrl(e,t),className:`w-full h-full`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:`No preview available for this file`})})]})})}function fT(e){if(e===0)return`0 GB`;let t=e/(1024*1024*1024);return t>=1?`${t.toFixed(1)} GB`:`${(e/(1024*1024)).toFixed(0)} MB`}function _le(e,t){if(t)return hc;switch(e.toLowerCase().split(`.`).pop()||``){case`3mf`:return tc;case`gcode`:return ac;case`mp4`:case`avi`:return sc;case`png`:case`jpg`:case`jpeg`:return Fc;default:return oc}}var vle=[{value:`name-asc`,label:`Name (A-Z)`},{value:`name-desc`,label:`Name (Z-A)`},{value:`size-asc`,label:`Size (smallest)`},{value:`size-desc`,label:`Size (largest)`},{value:`date-asc`,label:`Date (oldest)`},{value:`date-desc`,label:`Date (newest)`}];function yle({printerId:e,printerName:t,onClose:n}){let{t:r}=W(),{showToast:i}=Pd(),a=oo(),[o,s]=(0,y.useState)(`/`),[c,l]=(0,y.useState)(new Set),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)([]),[m,h]=(0,y.useState)(`name-asc`),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(null);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let{data:x,isLoading:S,refetch:C}=q({queryKey:[`printerFiles`,e,o],queryFn:()=>Q.getPrinterFiles(e,o)}),{data:w}=q({queryKey:[`printerStorage`,e],queryFn:()=>Q.getPrinterStorage(e),staleTime:3e4}),T=J({mutationFn:async t=>{for(let n of t)await Q.deletePrinterFile(e,n)},onSuccess:()=>{i(r(`printerFiles.toast.filesDeleted`,{count:f.length})),a.invalidateQueries({queryKey:[`printerFiles`,e]}),l(new Set),p([])},onError:e=>{i(r(`printerFiles.toast.deleteFailed`,{error:e.message}),`error`)}}),E=e=>{s(e),l(new Set)},D=()=>{if(o===`/`)return;let e=o.split(`/`).filter(Boolean);e.pop(),s(e.length?`/`+e.join(`/`):`/`),l(new Set)},O=(e,t)=>{t.stopPropagation(),l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},k=()=>{if(!x?.files)return;let e=x.files.filter(e=>!e.is_directory&&(!u||e.name.toLowerCase().includes(u.toLowerCase()))).map(e=>e.path);l(new Set(e))},A=()=>{l(new Set)},j=async()=>{if(c.size===0)return;let n=Array.from(c);if(n.length===1){Q.downloadPrinterFile(e,n[0]).catch(e=>{console.error(`Printer file download failed:`,e)}),l(new Set);return}_({current:0,total:n.length});try{let r=await Q.downloadPrinterFilesAsZip(e,n),a=URL.createObjectURL(r),o=document.createElement(`a`);o.href=a,o.download=`${t.replace(/[^a-zA-Z0-9]/g,`_`)}-files.zip`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a),i(`Downloaded ${n.length} files as ZIP`),l(new Set)}catch(e){i(`Download failed: ${e instanceof Error?e.message:`Unknown error`}`,`error`)}finally{_(null)}},M=()=>{c.size!==0&&p(Array.from(c))};return(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:n,children:[(0,K.jsxs)(`div`,{className:`w-full max-w-3xl max-h-[85vh] flex flex-col bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(Dc,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`printerFiles.title`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[w&&(w.used_bytes!=null||w.free_bytes!=null)&&(0,K.jsxs)(`div`,{className:`text-sm text-bambu-gray flex items-center gap-2`,children:[w.used_bytes!=null&&(0,K.jsxs)(`span`,{children:[r(`printerFiles.storageUsed`),` `,fT(w.used_bytes)]}),w.used_bytes!=null&&w.free_bytes!=null&&(0,K.jsx)(`span`,{className:`text-bambu-dark-tertiary`,children:`|`}),w.free_bytes!=null&&(0,K.jsxs)(`span`,{children:[r(`printerFiles.storageFree`),` `,fT(w.free_bytes)]})]}),(0,K.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:`Close file manager`,"aria-label":`Close file manager`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50 flex-shrink-0`,children:[[{path:`/`,label:`Root`},{path:`/cache`,label:`Cache`},{path:`/model`,label:`Models`},{path:`/timelapse`,label:`Timelapse`}].map(e=>(0,K.jsx)(`button`,{onClick:()=>{E(e.path),d(``)},className:`px-3 py-1 text-sm rounded-full transition-colors ${o===e.path?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:e.label},e.path)),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Wl,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,placeholder:r(`printerFiles.filterPlaceholder`),value:u,onChange:e=>d(e.target.value),className:`w-40 pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`relative flex items-center gap-1`,children:[(0,K.jsx)(Lo,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`select`,{value:m,onChange:e=>h(e.target.value),className:`appearance-none bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm py-1.5 pl-2 pr-6 focus:border-bambu-green focus:outline-none cursor-pointer`,title:`Sort files`,"aria-label":`Sort files`,children:vle.map(e=>(0,K.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>C(),disabled:S,children:(0,K.jsx)(Pl,{className:`w-4 h-4 ${S?`animate-spin`:``}`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 bg-bambu-dark text-sm flex-shrink-0`,children:[(0,K.jsx)(`button`,{onClick:D,disabled:o===`/`,className:`p-1 rounded hover:bg-bambu-dark-tertiary disabled:opacity-50 disabled:cursor-not-allowed`,title:`Go to parent folder`,"aria-label":`Go to parent folder`,children:(0,K.jsx)(ls,{className:`w-4 h-4`})}),(0,K.jsx)(`span`,{className:`text-bambu-gray font-mono`,children:o})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2 min-h-0`,children:S?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):x?.files?.length?(0,K.jsx)(`div`,{className:`space-y-1`,children:[...x.files].filter(e=>!u||e.name.toLowerCase().includes(u.toLowerCase())).sort((e,t)=>{if(e.is_directory&&!t.is_directory)return-1;if(!e.is_directory&&t.is_directory)return 1;switch(m){case`name-asc`:return e.name.localeCompare(t.name);case`name-desc`:return t.name.localeCompare(e.name);case`size-asc`:return e.size-t.size;case`size-desc`:return t.size-e.size;case`date-asc`:return(e.mtime?jf(e.mtime)?.getTime()??0:0)-(t.mtime?jf(t.mtime)?.getTime()??0:0);case`date-desc`:{let n=e.mtime?jf(e.mtime)?.getTime()??0:0;return(t.mtime?jf(t.mtime)?.getTime()??0:0)-n}default:return e.name.localeCompare(t.name)}}).map(e=>{let t=_le(e.name,e.is_directory),n=c.has(e.path);return(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-lg cursor-pointer transition-colors ${n?`bg-bambu-green/20 border border-bambu-green/50`:`hover:bg-bambu-dark-tertiary`}`,onClick:()=>{e.is_directory&&E(e.path)},children:[e.is_directory?null:(0,K.jsx)(`button`,{onClick:t=>O(e.path,t),className:`flex-shrink-0 text-bambu-gray hover:text-white`,children:n?(0,K.jsx)(uu,{className:`w-5 h-5 text-bambu-green`}):(0,K.jsx)(fu,{className:`w-5 h-5`})}),(0,K.jsx)(t,{className:`w-5 h-5 flex-shrink-0 ${e.is_directory?`text-bambu-green`:`text-bambu-gray`}`}),(0,K.jsx)(`span`,{className:`flex-1 text-white truncate`,children:e.name}),!e.is_directory&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:Md(e.size)}),(e.name.toLowerCase().endsWith(`.3mf`)||e.name.toLowerCase().endsWith(`.gcode`)||e.name.toLowerCase().endsWith(`.stl`))&&(0,K.jsx)(`button`,{onClick:t=>{t.stopPropagation(),b({path:e.path,name:e.name})},className:`p-1 rounded hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`,title:`3D View`,children:(0,K.jsx)(qo,{className:`w-4 h-4`})})]}),e.is_directory&&(0,K.jsx)(ls,{className:`w-4 h-4 text-bambu-gray rotate-180`})]},e.path)})}):(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:`No files in this directory`})}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary bg-bambu-dark/50 flex-shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:c.size>0?`${c.size} selected`:u?`${x?.files?.filter(e=>e.name.toLowerCase().includes(u.toLowerCase())).length||0} of ${x?.files?.length||0} items`:`${x?.files?.length||0} items`}),x?.files?.some(e=>!e.is_directory)&&(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:c.size>0?(0,K.jsxs)(`button`,{onClick:A,className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,K.jsx)(du,{className:`w-4 h-4`}),`Deselect All`]}):(0,K.jsxs)(`button`,{onClick:k,className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,K.jsx)(uu,{className:`w-4 h-4`}),`Select All`]})})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,disabled:c.size===0||g!==null,onClick:j,children:g?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),g.current,`/`,g.total]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Ws,{className:`w-4 h-4`}),`Download`,c.size>1?` (${c.size})`:``]})}),(0,K.jsxs)($,{variant:`secondary`,disabled:c.size===0||T.isPending,onClick:M,className:`text-red-700 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300`,children:[T.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Eu,{className:`w-4 h-4`}),r(`printerFiles.deleteButton`),c.size>1?` (${c.size})`:``]})]})]})]}),f.length>0&&(0,K.jsx)(Vd,{title:f.length>1?r(`printerFiles.deleteFiles`,{count:f.length}):r(`fileManager.deleteFile`),message:f.length>1?r(`printerFiles.deleteFilesConfirm`,{count:f.length}):r(`printerFiles.deleteFileConfirm`,{name:f[0].split(`/`).pop()}),confirmText:r(`common.delete`),variant:`danger`,onConfirm:()=>{T.mutate(f)},onCancel:()=>p([])}),v&&(0,K.jsx)(gle,{printerId:e,filePath:v.path,filename:v.name,onClose:()=>b(null)})]})}function pT({on:e,className:t=`w-5 h-5`}){let n=e?`#facc15`:`none`,r=e?`#78350f`:`currentColor`;return(0,K.jsxs)(`svg`,{viewBox:`0 0 32 32`,fill:`none`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:t,children:[(0,K.jsxs)(`g`,{stroke:r,opacity:+!!e,children:[(0,K.jsx)(`line`,{x1:`16`,y1:`2`,x2:`16`,y2:`6`}),(0,K.jsx)(`line`,{x1:`6.1`,y1:`6.1`,x2:`8.9`,y2:`8.9`}),(0,K.jsx)(`line`,{x1:`25.9`,y1:`6.1`,x2:`23.1`,y2:`8.9`}),(0,K.jsx)(`line`,{x1:`2`,y1:`16`,x2:`6`,y2:`16`}),(0,K.jsx)(`line`,{x1:`30`,y1:`16`,x2:`26`,y2:`16`})]}),(0,K.jsx)(`path`,{d:`M12 24v-2.3c0-.9-.4-1.7-1-2.3C9.2 17.6 8 15.4 8 13c0-4.4 3.6-8 8-8s8 3.6 8 8c0 2.4-1.2 4.6-3 6.4-.6.6-1 1.4-1 2.3V24`,fill:n,stroke:r}),(0,K.jsx)(`path`,{d:`M12 24h8`,stroke:r}),(0,K.jsx)(`path`,{d:`M12 27h8`,stroke:r}),(0,K.jsx)(`path`,{d:`M13 30h6`,stroke:r})]})}function ble(e,t,n){let r=Math.max(0,Math.min(e.width-1,Math.floor(t))),i=(Math.max(0,Math.min(e.height-1,Math.floor(n)))*e.width+r)*4,a=e.data[i],o=e.data[i+1],s=e.data[i+2];return!e.data[i+3]||a===0&&o===0&&s===0?null:a+(o<<8)+(s<<16)}function xle(e,t,n,r,i){let a=Math.min(e.width/t,e.height/n);if(!(a>0))return null;let o=(r-e.left-(e.width-t*a)/2)/a,s=(i-e.top-(e.height-n*a)/2)/a;return o<0||s<0||o>=t||s>=n?null:{x:o,y:s}}var mT=({className:e})=>(0,K.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,children:[(0,K.jsx)(`rect`,{x:`2`,y:`15`,width:`5`,height:`5`,rx:`0.5`}),(0,K.jsx)(`rect`,{x:`9.5`,y:`15`,width:`5`,height:`5`,rx:`0.5`,fill:`currentColor`,opacity:`0.3`}),(0,K.jsx)(`rect`,{x:`17`,y:`15`,width:`5`,height:`5`,rx:`0.5`}),(0,K.jsx)(`path`,{d:`M4 12 C4 6, 14 6, 14 12`}),(0,K.jsx)(`polyline`,{points:`12,10 14,12 12,14`})]});function hT({printerId:e,isOpen:t,onClose:n}){let{t:r}=W(),{showToast:i}=Pd(),{hasPermission:a}=bd(),[o,s]=(0,y.useState)(new Set),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(!1),m=(0,y.useRef)(null),h=(0,y.useRef)(null),g=(0,y.useRef)(null),{data:_}=q({queryKey:[`printerStatus`,e],queryFn:()=>Q.getPrinterStatus(e),refetchInterval:3e4,enabled:t}),{data:v,refetch:b}=q({queryKey:[`printableObjects`,e],queryFn:()=>Q.getPrintableObjects(e),enabled:t,refetchInterval:t?5e3:!1}),x=(v?.objects.length??0)>0,S=x&&_?.cover_url?ad(`${_.cover_url}?view=top`):null,C=x&&_?.cover_url?ad(`${_.cover_url}?view=pick`):null,w=(0,y.useMemo)(()=>(v?.objects??[]).filter(e=>!e.skipped),[v]),T=(0,y.useMemo)(()=>w.filter(e=>o.has(e.id)),[w,o]),E=w.length>0&&T.length===w.length,D=E&&o.size>0,O=o.size>0&&(_?.layer_num??0)>1&&a(`printers:control`),k=J({mutationFn:t=>Q.skipObjects(e,t),onSuccess:async e=>{i(e.message||r(`printers.skipObjects.objectsSkipped`)),await b(),l(!1),s(new Set),n()},onError:e=>{l(!1),i(e.message||r(`printers.toast.failedToSkipObjects`),`error`)}});(0,y.useEffect)(()=>{t||(s(new Set),l(!1),d(!1))},[t]),(0,y.useEffect)(()=>{if(m.current=null,p(!1),!t||!C)return;let e=!1,n=new Image;return n.onload=()=>{if(e)return;let t=document.createElement(`canvas`);t.width=n.naturalWidth||512,t.height=n.naturalHeight||512;let r=t.getContext(`2d`,{willReadFrequently:!0});r&&(r.drawImage(n,0,0),m.current=r.getImageData(0,0,t.width,t.height),p(!0))},n.onerror=()=>{e||p(!1)},n.src=C,()=>{e=!0}},[t,C]),(0,y.useEffect)(()=>{let e=m.current;if(!e||!v)return;let t=new Set(v.objects.filter(e=>e.skipped).map(e=>e.id));for(let n of[h.current,g.current]){if(!n)continue;n.width=e.width,n.height=e.height;let r=n.getContext(`2d`);if(!r)continue;let i=r.createImageData(e.width,e.height);for(let n=0;n{e.skipped||s(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n})},j=e=>{let t=m.current;if(!t)return;let n=xle(e.currentTarget.getBoundingClientRect(),t.width,t.height,e.clientX,e.clientY);if(!n)return;let r=ble(t,n.x,n.y),i=v?.objects.find(e=>e.id===r);i&&A(i)},M=(e=!1)=>(0,K.jsxs)(`div`,{className:`relative aspect-square overflow-hidden rounded-lg border border-gray-300 bg-gray-900 dark:border-gray-600 ${f?`cursor-crosshair`:``}`,children:[S?(0,K.jsx)(`img`,{src:S,alt:r(`printers.printPreview`),className:`absolute inset-0 h-full w-full object-contain`}):(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,K.jsx)(qo,{className:`h-10 w-10 text-gray-500`})}),(0,K.jsx)(`canvas`,{ref:e?g:h,onClick:j,className:`absolute inset-0 h-full w-full object-contain`,"aria-label":r(`printers.skipObjects.selectObjectsToSkip`)}),!e&&S&&(0,K.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),d(!0)},className:`absolute right-2 top-2 rounded bg-black/65 p-1.5 text-white/80 hover:text-white`,title:r(`common.expand`),children:(0,K.jsx)(nl,{className:`h-4 w-4`})}),!f&&S&&(0,K.jsx)(`div`,{className:`absolute bottom-2 left-2 rounded bg-black/70 px-2 py-1 text-[10px] text-white/80`,children:r(`common.unavailable`)})]});return t?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4`,onClick:n,onKeyDown:e=>{e.key===`Escape`&&(u?d(!1):n())},tabIndex:-1,ref:e=>e?.focus(),children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/55`}),(0,K.jsxs)(`section`,{className:`relative z-10 flex max-h-[88vh] w-full max-w-[980px] flex-col overflow-hidden rounded-lg border border-gray-200 bg-white shadow-2xl dark:border-bambu-dark-tertiary dark:bg-bambu-dark`,onClick:e=>e.stopPropagation(),"aria-label":r(`printers.skipObjects.title`),children:[(0,K.jsxs)(`header`,{className:`flex items-center justify-between border-b border-gray-200 bg-gray-50 px-4 py-3 dark:border-bambu-dark-tertiary dark:bg-bambu-dark`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(mT,{className:`h-5 w-5 text-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900 dark:text-white`,children:r(`printers.skipObjects.title`)}),(0,K.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-bambu-gray`,children:r(`printers.skipObjects.selectObjectsToSkip`)})]})]}),(0,K.jsx)(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-gray-500 hover:text-gray-900 dark:text-bambu-gray dark:hover:text-white`,children:(0,K.jsx)(qu,{className:`h-5 w-5`})})]}),v?v.objects.length===0?(0,K.jsxs)(`div`,{className:`px-4 py-12 text-center text-bambu-gray`,children:[(0,K.jsx)(`p`,{className:`text-sm`,children:r(`printers.noObjectsFound`)}),(0,K.jsx)(`p`,{className:`mt-1 text-xs opacity-70`,children:r(`printers.objectsLoadedOnPrintStart`)})]}):(0,K.jsxs)(K.Fragment,{children:[(_?.layer_num??0)<=1&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-amber-400/20 bg-amber-500/10 px-4 py-2 text-xs text-amber-400`,children:[(0,K.jsx)(ps,{className:`h-4 w-4 flex-shrink-0`}),r(`printers.skipObjects.waitForLayer`,{layer:_?.layer_num??0})]}),(0,K.jsxs)(`div`,{className:`grid min-h-0 flex-1 grid-cols-[minmax(320px,1fr)_minmax(340px,0.9fr)] overflow-hidden max-md:grid-cols-1 max-md:overflow-y-auto`,children:[(0,K.jsxs)(`div`,{className:`border-r border-gray-200 bg-gray-50 p-4 dark:border-bambu-dark-tertiary dark:bg-bambu-dark-secondary max-md:border-b-0 max-md:border-r-0`,children:[M(),(0,K.jsxs)(`div`,{className:`mt-3 flex items-center justify-between text-xs text-gray-500 dark:text-bambu-gray`,children:[(0,K.jsxs)(`span`,{children:[o.size,`/`,w.length]}),(0,K.jsxs)(`span`,{children:[v.skipped_count,` `,r(`printers.skipObjects.skipped`)]})]})]}),(0,K.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>s(E?new Set:new Set(w.map(e=>e.id))),className:`flex items-center gap-3 border-b border-gray-200 px-4 py-3 text-left text-sm font-semibold text-gray-900 hover:bg-gray-50 dark:border-bambu-dark-tertiary dark:text-white dark:hover:bg-white/5`,children:[E?(0,K.jsx)(uu,{className:`h-5 w-5 text-bambu-green`}):(0,K.jsx)(fu,{className:`h-5 w-5 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`flex-1`,children:r(E?`common.deselectAll`:`common.selectAll`)}),(0,K.jsx)(`span`,{className:`text-xs font-normal text-bambu-gray`,children:w.length})]}),(0,K.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:v.objects.map((e,t)=>{let n=o.has(e.id);return(0,K.jsxs)(`button`,{type:`button`,onClick:()=>A(e),disabled:e.skipped,className:`flex w-full items-center gap-3 border-b border-gray-200 px-4 py-2.5 text-left transition-colors dark:border-bambu-dark-tertiary/60 ${e.skipped?`cursor-not-allowed bg-red-500/5 opacity-55`:n?`bg-bambu-green/15 hover:bg-bambu-green/20`:`hover:bg-gray-50 dark:hover:bg-white/5`}`,children:[e.skipped||n?(0,K.jsx)(uu,{className:`h-5 w-5 flex-shrink-0 ${e.skipped?`text-red-400`:`text-bambu-green`}`}):(0,K.jsx)(fu,{className:`h-5 w-5 flex-shrink-0 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`w-8 flex-shrink-0 text-xs font-bold text-bambu-gray`,children:t+1}),(0,K.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm ${e.skipped?`text-red-400 line-through`:`text-gray-900 dark:text-white`}`,children:e.name}),(0,K.jsxs)(`span`,{className:`text-[10px] text-bambu-gray`,children:[`ID `,e.id]})]},e.id)})})]})]}),(0,K.jsxs)(`footer`,{className:`flex items-center gap-3 border-t border-gray-200 bg-gray-50 px-4 py-3 dark:border-bambu-dark-tertiary dark:bg-bambu-dark`,children:[(0,K.jsx)(`span`,{className:`mr-auto text-sm text-gray-600 dark:text-bambu-gray`,children:o.size===0?r(`printers.skipObjects.noObjectsSelected`):`${o.size}/${w.length}`}),(0,K.jsx)(`button`,{type:`button`,onClick:n,className:`rounded-md border border-gray-300 px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:border-bambu-dark-tertiary dark:text-white dark:hover:bg-white/5`,children:r(`common.cancel`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>l(!0),disabled:!O||k.isPending,className:`rounded-md bg-red-500 px-4 py-2 text-sm font-semibold text-white hover:bg-red-600 disabled:cursor-not-allowed disabled:opacity-35`,children:k.isPending?r(`printers.skipObjects.skipping`):r(`printers.skipObjects.skipSelected`)})]})]}):(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`h-6 w-6 animate-spin text-bambu-gray`})})]})]}),c&&(0,K.jsx)(Vd,{variant:`warning`,title:r(`printers.skipObjects.confirmTitle`),message:D?r(`printers.skipObjects.confirmAllMessage`):T.length===1?r(`printers.skipObjects.confirmMessage`,{name:T[0].name}):r(`printers.skipObjects.confirmMultipleMessage`,{count:T.length}),confirmText:r(`printers.skipObjects.skipSelected`),isLoading:k.isPending,onConfirm:()=>k.mutate([...o]),onCancel:()=>l(!1)}),u&&(0,K.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/90 p-8`,onClick:()=>d(!1),children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>d(!1),className:`absolute right-4 top-4 rounded p-2 text-white/70 hover:text-white`,children:(0,K.jsx)(qu,{className:`h-6 w-6`})}),(0,K.jsx)(`div`,{className:`aspect-square max-h-[86vh] w-full max-w-[86vh]`,onClick:e=>e.stopPropagation(),children:M(!0)})]})]}):null}function Sle({status:e}){return e===`ok`?(0,K.jsx)(gs,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}):e===`failed`?(0,K.jsx)(xs,{className:`w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0`}):(0,K.jsx)(vs,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`})}function gT({printerId:e,printerName:t,onClose:n}){let{t:r}=W(),i=J({mutationFn:()=>Q.diagnoseCamera(e)});(0,y.useEffect)(()=>{i.mutate()},[]),(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let a=i.data;return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsx)(mu,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:r(`camera.diagnose.modalTitle`,{name:t||``})})]}),(0,K.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:r(`common.close`),children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-6 space-y-4`,children:[i.isPending&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),(0,K.jsx)(`span`,{children:r(`camera.diagnose.running`)})]}),i.isError&&(0,K.jsx)(`div`,{className:`rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 px-4 py-3 text-sm text-red-700 dark:text-red-300`,children:r(`camera.diagnose.runFailed`,{error:i.error.message})}),a&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`ol`,{className:`space-y-2`,children:a.stages.map(e=>(0,K.jsxs)(`li`,{className:`flex items-center gap-3 bg-bambu-dark rounded-lg px-4 py-2.5`,children:[(0,K.jsx)(Sle,{status:e.status}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-sm text-white`,children:r(`camera.diagnose.stage.${e.name}`)}),e.code&&(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray font-mono`,children:e.code})]}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray tabular-nums flex-shrink-0`,children:[e.duration_ms,` ms`]})]},e.name))}),(0,K.jsx)(`div`,{className:a.overall_status===`ok`?`rounded-lg bg-bambu-green/10 border border-bambu-green/30 px-4 py-3 text-sm text-bambu-green`:`rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 px-4 py-3 text-sm text-red-700 dark:text-red-300`,children:r(`camera.diagnose.summary.${a.summary_code}`,{defaultValue:r(`camera.diagnose.summary.unknown_failure`)})}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray space-y-0.5`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[r(`camera.diagnose.meta.protocol`),`: `]}),(0,K.jsx)(`span`,{className:`font-mono`,children:a.protocol}),` • `,(0,K.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[r(`camera.diagnose.meta.port`),`: `]}),(0,K.jsx)(`span`,{className:`font-mono`,children:a.port}),` • `,(0,K.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[r(`camera.diagnose.meta.profile`),`: `]}),(0,K.jsx)(`span`,{className:`font-mono`,children:a.profile})]})})]})]}),(0,K.jsxs)(`div`,{className:`px-6 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>i.mutate(),disabled:i.isPending,className:`px-4 py-2 bg-bambu-dark hover:bg-bambu-dark-tertiary disabled:opacity-50 text-white text-sm rounded-lg transition-colors`,children:r(`camera.diagnose.retry`)}),(0,K.jsx)(`button`,{onClick:n,className:`px-4 py-2 bg-bambu-green hover:bg-bambu-green/90 text-white text-sm rounded-lg transition-colors`,children:r(`common.close`)})]})]})})}var Cle=`embeddedCameraState_`,_T=5,wle=2e3,Tle=3e4,Ele=5e3,vT={x:window.innerWidth-420,y:20,width:400,height:300};function Dle({printerId:e,printerName:t,viewerIndex:n=0,onClose:r}){let{t:i}=W(),a=oo(),{showToast:o}=Pd(),{hasPermission:s}=bd(),c=`${Cle}${e}`,[l,u]=(0,y.useState)(()=>{try{let e=localStorage.getItem(c);if(e){let t=JSON.parse(e);return{x:Math.min(Math.max(0,t.x),window.innerWidth-100),y:Math.min(Math.max(0,t.y),window.innerHeight-100),width:Math.max(200,Math.min(t.width,window.innerWidth-20)),height:Math.max(150,Math.min(t.height,window.innerHeight-20))}}}catch{}let e=n*30;return{...vT,x:Math.max(0,vT.x-e),y:Math.max(0,vT.y+e)}}),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)({x:0,y:0}),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(1),[w,T]=(0,y.useState)({x:0,y:0}),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)({x:0,y:0}),[A,j]=(0,y.useState)(null),[M,N]=(0,y.useState)(null),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(!0),[R,z]=(0,y.useState)(Date.now()),[B,V]=(0,y.useState)(0),[ee,te]=(0,y.useState)(!1),[ne,re]=(0,y.useState)(0),ie=(0,y.useRef)(null),H=(0,y.useRef)(null),ae=(0,y.useRef)(null),oe=(0,y.useRef)(null),U=(0,y.useRef)(null),[se,ce]=(0,y.useState)(!1),[le,ue]=(0,y.useState)(!1),{data:de}=q({queryKey:[`printer`,e],queryFn:()=>Q.getPrinter(e),enabled:e>0}),{data:fe}=q({queryKey:[`printerStatus`,e],queryFn:()=>Q.getPrinterStatus(e),refetchInterval:3e4,enabled:e>0}),pe=J({mutationFn:t=>Q.setChamberLight(e,t),onMutate:async t=>{await a.cancelQueries({queryKey:[`printerStatus`,e]});let n=a.getQueryData([`printerStatus`,e]);return a.setQueryData([`printerStatus`,e],e=>({...e,chamber_light:t})),{previousStatus:n}},onSuccess:(e,t)=>{o(`Chamber light ${t?`on`:`off`}`)},onError:(t,n,r)=>{r?.previousStatus&&a.setQueryData([`printerStatus`,e],r.previousStatus),o(t.message||i(`printers.toast.failedToControlChamberLight`),`error`)}}),me=(fe?.state===`RUNNING`||fe?.state===`PAUSE`)&&(fe?.printable_objects_count??0)>=2;(0,y.useEffect)(()=>{let e=setTimeout(()=>{localStorage.setItem(c,JSON.stringify(l))},500);return()=>clearTimeout(e)},[l,c]);let he=(0,y.useRef)(!1);(0,y.useEffect)(()=>{he.current=!1;let t=`/api/v1/printers/${e}/camera/stop`,n=()=>{if(e>0&&!he.current){he.current=!0;let e={},n=td();n&&(e.Authorization=`Bearer ${n}`),fetch(t,{method:`POST`,keepalive:!0,headers:e}).catch(()=>{})}},r=H.current;return()=>{r&&(r.src=``),n(),ae.current&&clearTimeout(ae.current),oe.current&&clearInterval(oe.current),U.current&&clearInterval(U.current)}},[e]),(0,y.useEffect)(()=>{if(I){let e=setTimeout(()=>L(!1),3e3);return()=>clearTimeout(e)}},[I,R]);let ge=(0,y.useCallback)(()=>{if(B>=_T){te(!1),F(!0);return}let e=Math.min(wle*2**B,Tle);te(!0),re(Math.ceil(e/1e3)),oe.current=setInterval(()=>{re(e=>e<=1?(oe.current&&clearInterval(oe.current),0):e-1)},1e3),ae.current=setTimeout(()=>{V(e=>e+1),te(!1),L(!0),F(!1),H.current&&(H.current.src=``),z(Date.now())},e)},[B]);(0,y.useEffect)(()=>{if(I||ee||_){U.current&&=(clearInterval(U.current),null);return}return U.current=setInterval(async()=>{try{let t=await Q.getCameraStatus(e);(t.stalled||!t.active&&!P)&&(U.current&&=(clearInterval(U.current),null),L(!1),ge())}catch{}},Ele),()=>{U.current&&=(clearInterval(U.current),null)}},[I,P,ee,_,e,ge]),(0,y.useEffect)(()=>{let e=()=>{let e=!!document.fullscreenElement;x(e),e||(C(1),T({x:0,y:0}))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]);let _e=()=>{ie.current&&(document.fullscreenElement?document.exitFullscreen():ie.current.requestFullscreen())},ve=()=>{C(e=>Math.min(e+.5,4))},ye=()=>{C(e=>{let t=Math.max(e-.5,1);return t===1&&T({x:0,y:0}),t})},be=e=>{e.preventDefault(),e.deltaY<0?ve():ye()},xe=e=>{S>1&&(e.preventDefault(),D(!0),k({x:e.clientX-w.x,y:e.clientY-w.y}))},Se=(0,y.useCallback)(()=>{if(!ie.current||!H.current)return{x:200,y:150};let e=ie.current.getBoundingClientRect(),t=e.width*(S-1)/2,n=e.height*(S-1)/2;return{x:Math.max(50,t),y:Math.max(50,n)}},[S]),Ce=e=>{if(E&&S>1){let t=e.clientX-O.x,n=e.clientY-O.y,r=Se();T({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},we=()=>{D(!1)},Te=e=>{if(e.length<2)return 0;let t=e[0].clientX-e[1].clientX,n=e[0].clientY-e[1].clientY;return Math.sqrt(t*t+n*n)},Ee=e=>e.length<2?{x:e[0].clientX,y:e[0].clientY}:{x:(e[0].clientX+e[1].clientX)/2,y:(e[0].clientY+e[1].clientY)/2},De=e=>{e.touches.length===2?(e.preventDefault(),j(Te(e.touches)),N(Ee(e.touches))):e.touches.length===1&&S>1&&(e.preventDefault(),D(!0),k({x:e.touches[0].clientX-w.x,y:e.touches[0].clientY-w.y}))},Oe=e=>{if(e.touches.length===2&&A!==null){e.preventDefault();let t=Te(e.touches),n=t/A;C(e=>{let t=Math.max(1,Math.min(4,e*n));return t===1&&T({x:0,y:0}),t}),j(t);let r=Ee(e.touches);if(M){let e=Se();T(t=>({x:Math.max(-e.x,Math.min(e.x,t.x+(r.x-M.x))),y:Math.max(-e.y,Math.min(e.y,t.y+(r.y-M.y)))}))}N(r)}else if(e.touches.length===1&&E&&S>1){e.preventDefault();let t=e.touches[0].clientX-O.x,n=e.touches[0].clientY-O.y,r=Se();T({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},ke=e=>{e.touches.length<2&&(j(null),N(null)),e.touches.length===0&&D(!1)},Ae=()=>{C(1),T({x:0,y:0})},je=()=>{L(!1),B<_T?ge():F(!0)},Me=()=>{L(!1),F(!1),V(0),te(!1),ae.current&&clearTimeout(ae.current),oe.current&&clearInterval(oe.current)},Ne=()=>{L(!0),F(!1),V(0),te(!1),ae.current&&clearTimeout(ae.current),oe.current&&clearInterval(oe.current);let t={},n=td();n&&(t.Authorization=`Bearer ${n}`),fetch(`/api/v1/printers/${e}/camera/stop`,{method:`POST`,headers:t}).catch(()=>{}),H.current&&(H.current.src=``),setTimeout(()=>z(Date.now()),100)},Pe=e=>{e.target.closest(`.no-drag`)||(f(!0),g({x:e.clientX-l.x,y:e.clientY-l.y}))},Fe=e=>{if(e.target.closest(`.no-drag`))return;let t=e.touches[0];f(!0),g({x:t.clientX-l.x,y:t.clientY-l.y})},Ie=e=>{e.stopPropagation(),m(!0)},Le=e=>{e.stopPropagation(),m(!0)};(0,y.useEffect)(()=>{let e=e=>{if(d)u(t=>({...t,x:Math.max(0,Math.min(e.clientX-h.x,window.innerWidth-t.width)),y:Math.max(0,Math.min(e.clientY-h.y,window.innerHeight-t.height))}));else if(p&&ie.current){let t=ie.current.getBoundingClientRect();u(n=>({...n,width:Math.max(200,Math.min(e.clientX-t.left,window.innerWidth-n.x-10)),height:Math.max(150,Math.min(e.clientY-t.top,window.innerHeight-n.y-10))}))}},t=e=>{if(!d&&!p)return;e.preventDefault();let t=e.touches[0];if(d)u(e=>({...e,x:Math.max(0,Math.min(t.clientX-h.x,window.innerWidth-e.width)),y:Math.max(0,Math.min(t.clientY-h.y,window.innerHeight-e.height))}));else if(p&&ie.current){let e=ie.current.getBoundingClientRect();u(n=>({...n,width:Math.max(200,Math.min(t.clientX-e.left,window.innerWidth-n.x-10)),height:Math.max(150,Math.min(t.clientY-e.top,window.innerHeight-n.y-10))}))}},n=()=>{f(!1),m(!1)};if(d||p)return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,n),document.addEventListener(`touchmove`,t,{passive:!1}),document.addEventListener(`touchend`,n),document.addEventListener(`touchcancel`,n),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,n),document.removeEventListener(`touchmove`,t),document.removeEventListener(`touchend`,n),document.removeEventListener(`touchcancel`,n)}},[d,p,h]);let Re=ad(`/api/v1/printers/${e}/camera/stream?fps=15&t=${R}`);return(0,K.jsxs)(`div`,{ref:ie,className:`${b?`fixed inset-0 z-[100]`:`fixed z-40 rounded-lg shadow-2xl border border-bambu-dark-tertiary`} bg-bambu-dark-secondary overflow-hidden`,style:b?void 0:{left:l.x,top:l.y,width:_?200:l.width,height:_?40:l.height,cursor:d?`grabbing`:`default`},children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 bg-bambu-dark border-b border-bambu-dark-tertiary cursor-grab active:cursor-grabbing`,onMouseDown:Pe,onTouchStart:Fe,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-white truncate`,children:[(0,K.jsx)(wc,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:de?.name||t})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 no-drag`,children:[(0,K.jsx)(`button`,{onClick:()=>pe.mutate(!fe?.chamber_light),disabled:!fe?.connected||pe.isPending||!s(`printers:control`),className:`p-1 rounded disabled:opacity-50 ${fe?.chamber_light?`bg-yellow-500/20 hover:bg-yellow-500/30`:`hover:bg-bambu-dark-tertiary`}`,title:s(`printers:control`)?i(`camera.chamberLight`):i(`printers.permission.noControl`),children:(0,K.jsx)(pT,{on:fe?.chamber_light??!1,className:`w-3.5 h-3.5`})}),(0,K.jsx)(`button`,{onClick:()=>ce(!0),disabled:!me||!s(`printers:control`),className:`p-1 rounded disabled:opacity-50 ${me&&s(`printers:control`)?`hover:bg-bambu-dark-tertiary`:``}`,title:s(`printers:control`)?i(me?`printers.skipObjects.tooltip`:`printers.skipObjects.onlyWhilePrinting`):i(`printers.permission.noControl`),children:(0,K.jsx)(mT,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,K.jsx)(`button`,{onClick:Ne,disabled:I||ee,className:`p-1 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,title:`Refresh stream`,children:(0,K.jsx)(Pl,{className:`w-3.5 h-3.5 text-bambu-gray ${I?`animate-spin`:``}`})}),(0,K.jsx)(`button`,{onClick:()=>ue(!0),className:`p-1 hover:bg-bambu-dark-tertiary rounded`,title:i(`camera.diagnose.button`),children:(0,K.jsx)(mu,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,K.jsx)(`button`,{onClick:_e,className:`p-1 hover:bg-bambu-dark-tertiary rounded`,title:b?`Exit fullscreen`:`Fullscreen`,children:b?(0,K.jsx)(sl,{className:`w-3.5 h-3.5 text-bambu-gray`}):(0,K.jsx)(gc,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,K.jsx)(`button`,{onClick:()=>v(!_),className:`p-1 hover:bg-bambu-dark-tertiary rounded`,title:_?`Expand`:`Minimize`,children:_?(0,K.jsx)(nl,{className:`w-3.5 h-3.5 text-bambu-gray`}):(0,K.jsx)(ol,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,K.jsx)(`button`,{onClick:r,className:`p-1 hover:bg-red-500/20 rounded`,title:`Close`,children:(0,K.jsx)(qu,{className:`w-3.5 h-3.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400`})})]})]}),!_&&(0,K.jsxs)(`div`,{className:`relative w-full bg-black flex items-center justify-center overflow-hidden h-[calc(100%-40px)]`,onWheel:be,onMouseMove:Ce,onMouseUp:we,onMouseLeave:we,onTouchStart:De,onTouchMove:Oe,onTouchEnd:ke,style:{touchAction:`none`},children:[I&&!ee&&(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/50 z-10`,children:(0,K.jsx)(Pl,{className:`w-6 h-6 text-bambu-gray animate-spin`})}),ee&&(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/80 z-10`,children:(0,K.jsxs)(`div`,{className:`text-center p-2`,children:[(0,K.jsx)(Hu,{className:`w-6 h-6 text-orange-400 mx-auto mb-2`}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[`Reconnecting in `,ne,`s...`]})]})}),P&&!ee&&(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black z-10`,children:(0,K.jsxs)(`div`,{className:`text-center p-2`,children:[(0,K.jsx)(ku,{className:`w-6 h-6 text-orange-400 mx-auto mb-2`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:i(`camera.unavailable`)}),(0,K.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,K.jsx)(`button`,{onClick:Ne,className:`px-2 py-1 text-xs bg-bambu-green text-white rounded hover:bg-bambu-green/80`,children:i(`camera.retry`)}),(0,K.jsx)(`button`,{onClick:()=>ue(!0),className:`px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white rounded transition-colors`,children:i(`camera.diagnose.button`)})]})]})}),(0,K.jsx)(`img`,{ref:H,src:Re,alt:`Camera stream`,className:`max-w-full max-h-full object-contain select-none`,style:{transform:`scale(${S}) translate(${w.x/S}px, ${w.y/S}px) rotate(${de?.camera_rotation||0}deg)`,...de?.camera_rotation===90||de?.camera_rotation===270?{maxWidth:`100%`,maxHeight:`100%`}:{},cursor:S>1?E?`grabbing`:`grab`:`default`},onError:je,onLoad:Me,onMouseDown:xe,draggable:!1},R),(0,K.jsxs)(`div`,{className:`absolute bottom-2 left-2 flex items-center gap-1 bg-black/60 rounded px-1.5 py-1 no-drag`,children:[(0,K.jsx)(`button`,{onClick:ye,disabled:S<=1,className:`p-1 hover:bg-white/10 rounded disabled:opacity-30`,title:`Zoom out`,children:(0,K.jsx)(Xu,{className:`w-3.5 h-3.5 text-white`})}),(0,K.jsxs)(`button`,{onClick:Ae,className:`px-1.5 py-0.5 text-xs text-white hover:bg-white/10 rounded min-w-[32px]`,title:`Reset zoom`,children:[Math.round(S*100),`%`]}),(0,K.jsx)(`button`,{onClick:ve,disabled:S>=4,className:`p-1 hover:bg-white/10 rounded disabled:opacity-30`,title:`Zoom in`,children:(0,K.jsx)(Ju,{className:`w-3.5 h-3.5 text-white`})})]}),!b&&(0,K.jsx)(`div`,{className:`absolute bottom-0 right-0 w-6 h-6 cursor-se-resize no-drag hover:bg-white/10 rounded-tl transition-colors`,onMouseDown:Ie,onTouchStart:Le,title:`Drag to resize`,children:(0,K.jsx)(`svg`,{className:`w-6 h-6 text-bambu-gray/70 hover:text-bambu-gray`,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,K.jsx)(`path`,{d:`M22 22H20V20H22V22ZM22 18H20V16H22V18ZM18 22H16V20H18V22ZM22 14H20V12H22V14ZM18 18H16V16H18V18ZM14 22H12V20H14V22ZM22 10H20V8H22V10ZM18 14H16V12H18V14ZM14 18H12V16H14V18ZM10 22H8V20H10V22Z`})})})]}),(0,K.jsx)(hT,{printerId:e,isOpen:se,onClose:()=>ce(!1)}),le&&(0,K.jsx)(gT,{printerId:e,printerName:de?.name||null,onClose:()=>ue(!1)})]})}var Ole=8;function kle(e,t){if(t>0)return`error`;switch(e){case`RUNNING`:return`printing`;case`PAUSE`:return`paused`;case`FINISH`:case`FAILED`:return`finished`;default:return`idle`}}var Ale={printing:`bg-bambu-green/85 text-black`,paused:`bg-amber-500/85 text-black`,finished:`bg-sky-500/80 text-white`,error:`bg-red-500/85 text-white`,idle:`bg-bambu-dark-tertiary/80 text-bambu-gray`};function jle({printerId:e,printerName:t,cameraRotation:n=0,mode:r,snapshotIntervalMs:i,connected:a,onClick:o,statusMode:s=`off`,printerState:c=null,progress:l=null,remainingMin:u=null,layerNum:d=null,totalLayers:f=null,printName:p=null,hmsErrorCount:m=0}){let{t:h}=W(),[g,_]=(0,y.useState)(0),[v,b]=(0,y.useState)(!1),x=(0,y.useRef)(r);(0,y.useEffect)(()=>{let t=x.current===`live`,n=r===`live`;if(x.current=r,t&&!n){let t={},n=td();n&&(t.Authorization=`Bearer ${n}`),fetch(`/api/v1/printers/${e}/camera/stop`,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}b(!1),_(e=>e+1)},[r,e]),(0,y.useEffect)(()=>()=>{if(x.current===`live`){let t={},n=td();n&&(t.Authorization=`Bearer ${n}`),fetch(`/api/v1/printers/${e}/camera/stop`,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}},[e]),(0,y.useEffect)(()=>{if(r!==`snapshot`)return;let e=setInterval(()=>_(e=>e+1),i);return()=>clearInterval(e)},[r,i]);let S=ad(`/api/v1/printers/${e}/camera/stream?fps=${Ole}&t=${g}`),C=ad(`/api/v1/printers/${e}/camera/snapshot?t=${g}`),w=o!=null,T=n?`rotate(${n}deg)`:void 0,E=kle(c,m),D=a&&s!==`off`&&E!==`idle`,O=a&&s===`full`&&(E===`printing`||E===`paused`),k=p??null,A=l==null?null:Math.round(l),j=d!=null&&f!=null&&f>0,M=u!=null&&u>0,N=`group relative aspect-video w-full overflow-hidden rounded-lg border border-bambu-dark-tertiary bg-black text-left ${w?`focus:outline-none focus:ring-2 focus:ring-bambu-green`:`cursor-default`}`,P=(0,K.jsxs)(K.Fragment,{children:[!a||r===`paused`?(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-bambu-dark/60`,children:a?(0,K.jsx)(Iu,{className:`h-8 w-8 text-bambu-gray/70`,"aria-hidden":`true`}):(0,K.jsx)(Hu,{className:`h-8 w-8 text-bambu-gray/70`,"aria-hidden":`true`})}):v?(0,K.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-1 bg-black/80 text-bambu-gray`,children:[(0,K.jsx)(Iu,{className:`h-7 w-7`,"aria-hidden":`true`}),(0,K.jsx)(`span`,{className:`text-xs`,children:h(`printers.camWall.noSignal`)})]}):(0,K.jsx)(`img`,{src:r===`live`?S:C,alt:t,draggable:!1,loading:`lazy`,className:`h-full w-full select-none object-contain`,style:{transform:T},onError:()=>b(!0)},`${r}-${g}`),D&&(0,K.jsxs)(`span`,{className:`absolute left-2 top-2 flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide ${Ale[E]}`,children:[m>0&&(0,K.jsx)(ku,{className:`h-3 w-3`,"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:h(`printers.status.${E}`)})]}),(0,K.jsx)(`span`,{className:`absolute right-2 top-2 rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide ${r===`live`?`bg-red-500/80 text-white`:r===`snapshot`?`bg-amber-500/70 text-black`:`bg-bambu-dark-tertiary/70 text-bambu-gray`}`,children:h(r===`live`?`printers.camWall.live`:r===`snapshot`?`printers.camWall.snap`:`printers.camWall.off`)}),(0,K.jsxs)(`div`,{className:`absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/85 via-black/55 to-transparent px-2 pb-1.5 pt-3 text-white`,children:[O&&(0,K.jsxs)(`div`,{className:`mb-0.5 space-y-0.5 text-[11px] leading-tight text-white/90`,children:[k&&(0,K.jsx)(`div`,{className:`truncate`,title:k,children:k}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 text-bambu-gray`,children:[A!=null&&(0,K.jsxs)(`span`,{className:`font-semibold text-white`,children:[A,`%`]}),j&&(0,K.jsx)(`span`,{children:h(`printers.camWall.layer`,{cur:d,total:f})}),M&&(0,K.jsx)(`span`,{children:h(`printers.camWall.timeLeft`,{time:If((u??0)*60)})})]})]}),(0,K.jsx)(`span`,{className:`block truncate text-xs font-medium`,children:t})]})]});return w?(0,K.jsx)(`button`,{type:`button`,onClick:o,className:N,title:t,children:P}):(0,K.jsx)(`div`,{className:N,title:t,children:P})}var yT=1,bT=16,xT=2,ST=60,Mle=[`off`,`compact`,`full`];function CT({printers:e,maxLive:t,snapshotIntervalSec:n,statusMode:r,onTileClick:i,onChangeMaxLive:a,onChangeSnapshotIntervalSec:o,onChangeStatusMode:s,statuses:c,showSettings:l=!0}){let{t:u}=W(),d=(0,y.useRef)(new Map),f=c?[]:e,p=xo({queries:f.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id),staleTime:5e3}))}),m=(0,y.useMemo)(()=>{let e=new Map;return f.forEach((t,n)=>{e.set(t.id,p[n]?.data)}),e},[e,p,c]),h=c??m,[g,_]=(0,y.useState)(()=>new Set),[v,b]=(0,y.useState)(!1),x=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!v)return;let e=e=>{x.current&&!x.current.contains(e.target)&&b(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[v]),(0,y.useEffect)(()=>{let e=new IntersectionObserver(e=>{_(t=>{let n=new Set(t);for(let t of e){let e=Number(t.target.dataset.printerId);Number.isFinite(e)&&(t.isIntersecting?n.add(e):n.delete(e))}return n})},{threshold:.4});for(let[,t]of d.current)t&&e.observe(t);return()=>e.disconnect()},[e]);let S=(0,y.useMemo)(()=>{let n=new Map,r=Math.max(0,t);for(let t of e){let e=h.get(t.id)?.connected??!1;if(!g.has(t.id)||!e){n.set(t.id,`paused`);continue}r>0?(n.set(t.id,`live`),--r):n.set(t.id,`snapshot`)}return n},[e,g,t,h]);return e.length===0?(0,K.jsx)(`div`,{className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-6 text-center text-bambu-gray`,children:u(`printers.camWall.noPrinters`)}):(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:u(`printers.camWall.summary`,{live:Array.from(S.values()).filter(e=>e===`live`).length,snap:Array.from(S.values()).filter(e=>e===`snapshot`).length,total:e.length})}),l&&(0,K.jsxs)(`div`,{className:`relative`,ref:x,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>b(e=>!e),className:`flex h-7 items-center gap-1 rounded-md border border-bambu-dark-tertiary bg-bambu-dark px-2 text-white hover:bg-bambu-dark-tertiary`,title:u(`printers.camWall.settings.title`),children:[(0,K.jsx)(Yl,{className:`h-3.5 w-3.5`}),(0,K.jsx)(`span`,{children:u(`printers.camWall.settings.title`)})]}),v&&(0,K.jsxs)(`div`,{className:`absolute right-0 top-9 z-30 w-72 space-y-3 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark-secondary p-3 shadow-xl`,children:[(0,K.jsxs)(`label`,{className:`block space-y-1`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium text-white`,children:u(`printers.camWall.settings.maxLive`)}),(0,K.jsx)(`input`,{type:`number`,min:yT,max:bT,value:t,onChange:e=>{a(Math.min(bT,Math.max(yT,Number(e.target.value)||yT)))},className:`w-full rounded-md border border-bambu-dark-tertiary bg-bambu-dark px-2 py-1 text-sm text-white`}),(0,K.jsx)(`span`,{className:`block text-[11px] text-bambu-gray`,children:u(`printers.camWall.settings.maxLiveHint`)})]}),(0,K.jsxs)(`label`,{className:`block space-y-1`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium text-white`,children:u(`printers.camWall.settings.snapshotInterval`)}),(0,K.jsx)(`input`,{type:`number`,min:xT,max:ST,value:n,onChange:e=>{o(Math.min(ST,Math.max(xT,Number(e.target.value)||xT)))},className:`w-full rounded-md border border-bambu-dark-tertiary bg-bambu-dark px-2 py-1 text-sm text-white`}),(0,K.jsx)(`span`,{className:`block text-[11px] text-bambu-gray`,children:u(`printers.camWall.settings.snapshotIntervalHint`)})]}),(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`span`,{className:`block text-xs font-medium text-white`,children:u(`printers.camWall.settings.statusOverlay`)}),(0,K.jsx)(`div`,{role:`radiogroup`,"aria-label":u(`printers.camWall.settings.statusOverlay`),className:`flex overflow-hidden rounded-md border border-bambu-dark-tertiary`,children:Mle.map(e=>(0,K.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":r===e,onClick:()=>s(e),className:`flex-1 px-2 py-1 text-xs ${r===e?`bg-bambu-green text-black font-semibold`:`bg-bambu-dark text-white hover:bg-bambu-dark-tertiary`}`,children:u(`printers.camWall.statusMode.${e}`)},e))}),(0,K.jsx)(`span`,{className:`block text-[11px] text-bambu-gray`,children:u(`printers.camWall.settings.statusOverlayHint`)})]})]})]})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`,children:e.map(e=>{let t=S.get(e.id)??`paused`;return(0,K.jsx)(`div`,{ref:t=>{d.current.set(e.id,t)},"data-printer-id":e.id,children:(0,K.jsx)(jle,{printerId:e.id,printerName:e.name,cameraRotation:e.camera_rotation,mode:t,snapshotIntervalMs:n*1e3,connected:h.get(e.id)?.connected??!1,statusMode:r,printerState:h.get(e.id)?.state??null,progress:h.get(e.id)?.progress??null,remainingMin:h.get(e.id)?.remaining_time??null,layerNum:h.get(e.id)?.layer_num??null,totalLayers:h.get(e.id)?.total_layers??null,printName:h.get(e.id)?.subtask_name??h.get(e.id)?.gcode_file??null,hmsErrorCount:Xp(h.get(e.id)?.hms_errors??[]).length,onClick:i?()=>i(e.id,e.name):void 0})},e.id)})})]})}function Nle({printerId:e,printerName:t,onClose:n}){let{t:r}=W(),i=oo(),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(new Set),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(`all`),p=(0,y.useRef)(null),{data:m,isLoading:h,refetch:g}=q({queryKey:[`mqtt-logs`,e],queryFn:()=>Q.getMQTTLogs(e),refetchInterval:1e3}),_=J({mutationFn:()=>Q.enableMQTTLogging(e),onSuccess:()=>{i.invalidateQueries({queryKey:[`mqtt-logs`,e]})}}),v=J({mutationFn:()=>Q.disableMQTTLogging(e),onSuccess:()=>{i.invalidateQueries({queryKey:[`mqtt-logs`,e]})}}),b=J({mutationFn:()=>Q.clearMQTTLogs(e),onSuccess:()=>{i.invalidateQueries({queryKey:[`mqtt-logs`,e]})}});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,y.useEffect)(()=>{a&&p.current&&(p.current.scrollTop=p.current.scrollHeight)},[m?.logs,a]);let x=e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},S=e=>new Date(e).toLocaleTimeString(`en-US`,{hour12:!1,fractionalSecondDigits:3}),C=(e,t)=>{if(e==null)return``;let n=typeof e==`string`?JSON.parse(e):e,r=JSON.stringify(n,null,t?2:0);return!t&&r.length>100?r.substring(0,100)+`...`:r},w=m?.logging_enabled??!1,T=(0,y.useMemo)(()=>m?.logs??[],[m?.logs]),E=(0,y.useMemo)(()=>T.filter(e=>{if(d!==`all`&&e.direction!==d)return!1;if(l.trim()){let t=l.toLowerCase(),n=e.topic.toLowerCase().includes(t),r=JSON.stringify(e.payload).toLowerCase().includes(t);return n||r}return!0}),[T,l,d]);return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg max-w-4xl w-full max-h-[85vh] flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`mqttDebug.title`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t})]}),(0,K.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[w?(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>v.mutate(),disabled:v.isPending,children:[(0,K.jsx)(fu,{className:`w-4 h-4`}),r(`mqttDebug.stopLogging`)]}):(0,K.jsxs)($,{size:`sm`,onClick:()=>_.mutate(),disabled:_.isPending,children:[(0,K.jsx)(El,{className:`w-4 h-4`}),r(`mqttDebug.startLogging`)]}),(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>b.mutate(),disabled:b.isPending||T.length===0,children:[(0,K.jsx)(Eu,{className:`w-4 h-4`}),r(`mqttDebug.clearLog`)]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>g(),disabled:h,children:(0,K.jsx)(Pl,{className:`w-4 h-4 ${h?`animate-spin`:``}`})}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:a,onChange:e=>o(e.target.checked),className:`rounded border-bambu-dark-tertiary`}),`Auto-scroll`]}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[E.length,`/`,T.length]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(Wl,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,placeholder:r(`mqttDebug.searchPlaceholder`),value:l,onChange:e=>u(e.target.value),className:`w-full pl-8 pr-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),l&&(0,K.jsx)(`button`,{onClick:()=>u(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,K.jsx)(qu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`button`,{onClick:()=>f(`all`),className:`px-2 py-1.5 text-xs rounded-l transition-colors ${d===`all`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:r(`mqttDebug.all`)}),(0,K.jsxs)(`button`,{onClick:()=>f(`in`),className:`px-2 py-1.5 text-xs transition-colors flex items-center gap-1 ${d===`in`?`bg-blue-500 text-white`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(No,{className:`w-3 h-3`}),r(`mqttDebug.incoming`)]}),(0,K.jsxs)(`button`,{onClick:()=>f(`out`),className:`px-2 py-1.5 text-xs rounded-r transition-colors flex items-center gap-1 ${d===`out`?`bg-green-500 text-white`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(zo,{className:`w-3 h-3`}),r(`mqttDebug.outgoing`)]})]})]})]}),(0,K.jsx)(`div`,{ref:p,className:`flex-1 overflow-auto p-4 font-mono text-xs bg-black min-h-[400px]`,children:T.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-bambu-gray`,children:[(0,K.jsx)(`p`,{className:`mb-2`,children:r(`mqttDebug.noMessages`)}),!w&&(0,K.jsx)(`p`,{className:`text-sm`,children:r(`mqttDebug.startLoggingHint`)})]}):E.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-bambu-gray`,children:[(0,K.jsx)(`p`,{className:`mb-2`,children:r(`mqttDebug.noMessagesMatch`)}),(0,K.jsx)(`p`,{className:`text-sm`,children:r(`mqttDebug.adjustFilterHint`)})]}):(0,K.jsx)(`div`,{className:`space-y-1`,children:E.map((e,t)=>{let n=s.has(t),i=e.direction===`in`;return(0,K.jsxs)(`div`,{className:`p-2 rounded cursor-pointer hover:bg-bambu-dark-secondary transition-colors ${n?`bg-bambu-dark-secondary`:``}`,onClick:()=>x(t),children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray shrink-0`,children:S(e.timestamp)}),(0,K.jsx)(`span`,{className:`shrink-0 ${i?`text-blue-400`:`text-green-400`}`,title:r(i?`mqttDebug.incoming`:`mqttDebug.outgoing`),children:i?(0,K.jsx)(No,{className:`w-3 h-3`}):(0,K.jsx)(zo,{className:`w-3 h-3`})}),(0,K.jsx)(`span`,{className:`text-purple-400 shrink-0`,children:e.topic})]}),n?(0,K.jsx)(`pre`,{className:`mt-2 p-3 bg-gray-900 border border-gray-700 rounded text-green-400 overflow-x-auto whitespace-pre-wrap break-all max-h-96 overflow-y-auto text-xs`,children:C(e.payload,!0)}):(0,K.jsx)(`pre`,{className:`mt-1 text-white/80 truncate`,children:C(e.payload,!1)})]},t)})})}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:w?(0,K.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 bg-green-500 rounded-full animate-pulse`}),r(`mqttDebug.loggingActive`)]}):(0,K.jsx)(`span`,{children:r(`mqttDebug.loggingStopped`)})}),(0,K.jsx)($,{variant:`secondary`,onClick:n,children:r(`common.close`)})]})]})})}function wT(e){if(!e)return`/img/printers/default.png`;let t=e.toLowerCase().replace(/\s+/g,``);return t.includes(`x1e`)?`/img/printers/x1e.png`:t.includes(`x1c`)||t.includes(`x1carbon`)||t.includes(`x1`)?`/img/printers/x1c.png`:t.includes(`x2d`)||t===`n6`?`/img/printers/x2d.png`:t.includes(`h2dpro`)||t.includes(`h2d-pro`)?`/img/printers/h2dpro.png`:t.includes(`h2d`)?`/img/printers/h2d.png`:t.includes(`h2c`)?`/img/printers/h2c.png`:t.includes(`h2s`)?`/img/printers/h2d.png`:t.includes(`p2s`)||t.includes(`p1s`)?`/img/printers/p1s.png`:t.includes(`p1p`)?`/img/printers/p1p.png`:t.includes(`a2l`)||t===`n9`?`/img/printers/a2l.png`:t.includes(`a1mini`)?`/img/printers/a1mini.png`:t.includes(`a1`)?`/img/printers/a1.png`:`/img/printers/default.png`}var Ple=[new Set([`X1`,`X1C`,`X1E`,`P1P`,`P1S`])];function TT(e,t){if(!e||!t)return!0;let n=e=>e.trim().toUpperCase().replace(/[\s-]/g,``),r=n(e),i=n(t);return r===i?!0:Ple.some(e=>e.has(r)&&e.has(i))}function ET(e){return e>=-50?{labelKey:`printers.wifiSignal.excellent`,color:`text-bambu-green`,bars:4}:e>=-60?{labelKey:`printers.wifiSignal.good`,color:`text-bambu-green`,bars:3}:e>=-70?{labelKey:`printers.wifiSignal.fair`,color:`text-yellow-400`,bars:2}:e>=-80?{labelKey:`printers.wifiSignal.weak`,color:`text-orange-400`,bars:1}:{labelKey:`printers.wifiSignal.veryWeak`,color:`text-red-400`,bars:1}}function DT(e,t,n,r){return e.filter(e=>{if(e.required_filament_types&&e.required_filament_types.length>0&&t!==void 0&&!e.required_filament_types.every(e=>t.has(e.toUpperCase())))return!1;if(e.filament_overrides&&e.filament_overrides.length>0&&n!==void 0){let t=e.filament_overrides.filter(e=>e.force_color_match===!0),i=e.filament_overrides.filter(e=>e.force_color_match!==!0);if(t.length>0&&!t.every(e=>{let t=(e.type||``).toUpperCase(),i=(e.color||``).replace(`#`,``).toLowerCase().slice(0,6),a=e.tray_info_idx||``;return!a||r===void 0?n.has(`${t}:${i}`):r.has(`${t}:${i}:${a}`)||r.has(`${t}:${i}:`)})||i.length>0&&t.length===0&&!i.some(e=>{let t=(e.type||``).toUpperCase(),r=(e.color||``).replace(`#`,``).toLowerCase().slice(0,6);return n.has(`${t}:${r}`)}))return!1}return!0})}function Fle({printerId:e,printerModel:t,loadedFilamentTypes:n,loadedFilaments:r,loadedVariants:i,variant:a=`card`}){let{t:o}=W(),{data:s}=q({queryKey:[`queue`,e,`pending`,t],queryFn:()=>Q.getQueue(e,`pending`,t||void 0),refetchInterval:3e4}),c=s?DT(s,n,r,i):void 0,l=c?.length||0;if(l===0)return null;let u=c?.[0];return(0,K.jsx)(Oi,{to:`/queue`,className:a===`panelExtension`?`block mt-2 border-t border-bambu-dark-tertiary pt-2 pl-1 hover:opacity-90 transition-opacity`:`block mb-3 p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,K.jsx)($o,{className:`w-5 h-5 text-yellow-600 dark:text-yellow-400 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:o(`queue.nextInQueue`)}),(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:u?.archive_name||u?.library_file_name||`File #${u?.archive_id||u?.library_file_id}`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray flex items-center gap-1`,children:[(0,K.jsx)(ws,{className:`w-3 h-3`}),u?.scheduled_time?Lf(u.scheduled_time,`system`,o):o(`time.waiting`)]}),l>1&&(0,K.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 bg-yellow-100 dark:bg-yellow-400/20 text-yellow-700 dark:text-yellow-400 rounded`,children:[`+`,l-1]}),(0,K.jsx)(cs,{className:`w-4 h-4 text-bambu-gray`})]})]})})}function OT(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`)if(Array.isArray(e)){var i=e.length;for(t=0;t{var{children:n,width:r,height:i,viewBox:a,className:o,style:s,title:c,desc:l}=e,u=Ble(e,zle),d=a||{width:r,height:i,x:0,y:0},f=kT(`recharts-surface`,o);return y.createElement(`svg`,IT({},FT(u),{className:f,width:r,height:i,style:s,viewBox:`${d.x} ${d.y} ${d.width} ${d.height}`,ref:t}),y.createElement(`title`,null,c),y.createElement(`desc`,null,l),n)}),Hle=[`children`,`className`];function RT(){return RT=Object.assign?Object.assign.bind():function(e){for(var t=1;t{var{children:n,className:r}=e,i=Ule(e,Hle),a=kT(`recharts-layer`,r);return y.createElement(`g`,RT({className:a},FT(i),{ref:t}),n)}),BT=(0,y.createContext)(null),Gle=()=>(0,y.useContext)(BT);function VT(e){return function(){return e}}var HT=Math.cos,UT=Math.sin,WT=Math.sqrt,GT=Math.PI;GT/2;var KT=2*GT,qT=Math.PI,JT=2*qT,YT=1e-6,Kle=JT-YT;function XT(e){this._+=e[0];for(let t=1,n=e.length;t=0))throw Error(`invalid digits: ${e}`);if(t>15)return XT;let n=10**t;return function(e){this._+=e[0];for(let t=1,r=e.length;tYT)if(!(Math.abs(u*s-c*l)>YT)||!i)this._append`L${this._x1=e},${this._y1=t}`;else{let f=n-a,p=r-o,m=s*s+c*c,h=f*f+p*p,g=Math.sqrt(m),_=Math.sqrt(d),v=i*Math.tan((qT-Math.acos((m+d-h)/(2*g*_)))/2),y=v/_,b=v/g;Math.abs(y-1)>YT&&this._append`L${e+y*l},${t+y*u}`,this._append`A${i},${i},0,0,${+(u*f>l*p)},${this._x1=e+b*s},${this._y1=t+b*c}`}}arc(e,t,n,r,i,a){if(e=+e,t=+t,n=+n,a=!!a,n<0)throw Error(`negative radius: ${n}`);let o=n*Math.cos(r),s=n*Math.sin(r),c=e+o,l=t+s,u=1^a,d=a?r-i:i-r;this._x1===null?this._append`M${c},${l}`:(Math.abs(this._x1-c)>YT||Math.abs(this._y1-l)>YT)&&this._append`L${c},${l}`,n&&(d<0&&(d=d%JT+JT),d>Kle?this._append`A${n},${n},0,1,${u},${e-o},${t-s}A${n},${n},0,1,${u},${this._x1=c},${this._y1=l}`:d>YT&&this._append`A${n},${n},0,${+(d>=qT)},${u},${this._x1=e+n*Math.cos(i)},${this._y1=t+n*Math.sin(i)}`)}rect(e,t,n,r){this._append`M${this._x0=this._x1=+e},${this._y0=this._y1=+t}h${n=+n}v${+r}h${-n}Z`}toString(){return this._}};function Jle(){return new ZT}Jle.prototype=ZT.prototype;function QT(e){let t=3;return e.digits=function(n){if(!arguments.length)return t;if(n==null)t=null;else{let e=Math.floor(n);if(!(e>=0))throw RangeError(`invalid digits: ${n}`);t=e}return e},()=>new ZT(t)}Array.prototype.slice;function $T(e){return typeof e==`object`&&`length`in e?e:Array.from(e)}function eE(e){this._context=e}eE.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:this._context.lineTo(e,t);break}}};function tE(e){return new eE(e)}function nE(e){return e[0]}function rE(e){return e[1]}function iE(e,t){var n=VT(!0),r=null,i=tE,a=null,o=QT(s);e=typeof e==`function`?e:e===void 0?nE:VT(e),t=typeof t==`function`?t:t===void 0?rE:VT(t);function s(s){var c,l=(s=$T(s)).length,u,d=!1,f;for(r??(a=i(f=o())),c=0;c<=l;++c)!(c=d;--f)s.point(_[f],v[f]);s.lineEnd(),s.areaEnd()}h&&(_[u]=+e(m,u,l),v[u]=+t(m,u,l),s.point(r?+r(m,u,l):_[u],n?+n(m,u,l):v[u]))}if(g)return s=null,g+``||null}function u(){return iE().defined(i).curve(o).context(a)}return l.x=function(t){return arguments.length?(e=typeof t==`function`?t:VT(+t),r=null,l):e},l.x0=function(t){return arguments.length?(e=typeof t==`function`?t:VT(+t),l):e},l.x1=function(e){return arguments.length?(r=e==null?null:typeof e==`function`?e:VT(+e),l):r},l.y=function(e){return arguments.length?(t=typeof e==`function`?e:VT(+e),n=null,l):t},l.y0=function(e){return arguments.length?(t=typeof e==`function`?e:VT(+e),l):t},l.y1=function(e){return arguments.length?(n=e==null?null:typeof e==`function`?e:VT(+e),l):n},l.lineX0=l.lineY0=function(){return u().x(e).y(t)},l.lineY1=function(){return u().x(e).y(n)},l.lineX1=function(){return u().x(r).y(t)},l.defined=function(e){return arguments.length?(i=typeof e==`function`?e:VT(!!e),l):i},l.curve=function(e){return arguments.length?(o=e,a!=null&&(s=o(a)),l):o},l.context=function(e){return arguments.length?(e==null?a=s=null:s=o(a=e),l):a},l}var oE=class{constructor(e,t){this._context=e,this._x=t}areaStart(){this._line=0}areaEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line}point(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:this._x?this._context.bezierCurveTo(this._x0=(this._x0+e)/2,this._y0,this._x0,t,e,t):this._context.bezierCurveTo(this._x0,this._y0=(this._y0+t)/2,e,this._y0,e,t);break}this._x0=e,this._y0=t}};function Yle(e){return new oE(e,!0)}function Xle(e){return new oE(e,!1)}var sE={draw(e,t){let n=WT(t/GT);e.moveTo(n,0),e.arc(0,0,n,0,KT)}},Zle={draw(e,t){let n=WT(t/5)/2;e.moveTo(-3*n,-n),e.lineTo(-n,-n),e.lineTo(-n,-3*n),e.lineTo(n,-3*n),e.lineTo(n,-n),e.lineTo(3*n,-n),e.lineTo(3*n,n),e.lineTo(n,n),e.lineTo(n,3*n),e.lineTo(-n,3*n),e.lineTo(-n,n),e.lineTo(-3*n,n),e.closePath()}},cE=WT(1/3),Qle=cE*2,$le={draw(e,t){let n=WT(t/Qle),r=n*cE;e.moveTo(0,-n),e.lineTo(r,0),e.lineTo(0,n),e.lineTo(-r,0),e.closePath()}},eue={draw(e,t){let n=WT(t),r=-n/2;e.rect(r,r,n,n)}},tue=.8908130915292852,lE=UT(GT/10)/UT(7*GT/10),nue=UT(KT/10)*lE,rue=-HT(KT/10)*lE,iue={draw(e,t){let n=WT(t*tue),r=nue*n,i=rue*n;e.moveTo(0,-n),e.lineTo(r,i);for(let t=1;t<5;++t){let a=KT*t/5,o=HT(a),s=UT(a);e.lineTo(s*n,-o*n),e.lineTo(o*r-s*i,s*r+o*i)}e.closePath()}},uE=WT(3),aue={draw(e,t){let n=-WT(t/(uE*3));e.moveTo(0,n*2),e.lineTo(-uE*n,-n),e.lineTo(uE*n,-n),e.closePath()}},dE=-.5,fE=WT(3)/2,pE=1/WT(12),oue=(pE/2+1)*3,sue={draw(e,t){let n=WT(t/oue),r=n/2,i=n*pE,a=r,o=n*pE+n,s=-a,c=o;e.moveTo(r,i),e.lineTo(a,o),e.lineTo(s,c),e.lineTo(dE*r-fE*i,fE*r+dE*i),e.lineTo(dE*a-fE*o,fE*a+dE*o),e.lineTo(dE*s-fE*c,fE*s+dE*c),e.lineTo(dE*r+fE*i,dE*i-fE*r),e.lineTo(dE*a+fE*o,dE*o-fE*a),e.lineTo(dE*s+fE*c,dE*c-fE*s),e.closePath()}};function cue(e,t){let n=null,r=QT(i);e=typeof e==`function`?e:VT(e||sE),t=typeof t==`function`?t:VT(t===void 0?64:+t);function i(){let i;if(n||=i=r(),e.apply(this,arguments).draw(n,+t.apply(this,arguments)),i)return n=null,i+``||null}return i.type=function(t){return arguments.length?(e=typeof t==`function`?t:VT(t),i):e},i.size=function(e){return arguments.length?(t=typeof e==`function`?e:VT(+e),i):t},i.context=function(e){return arguments.length?(n=e??null,i):n},i}function mE(){}function hE(e,t,n){e._context.bezierCurveTo((2*e._x0+e._x1)/3,(2*e._y0+e._y1)/3,(e._x0+2*e._x1)/3,(e._y0+2*e._y1)/3,(e._x0+4*e._x1+t)/6,(e._y0+4*e._y1+n)/6)}function gE(e){this._context=e}gE.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:hE(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1);break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:hE(this,e,t);break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function lue(e){return new gE(e)}function _E(e){this._context=e}_E.prototype={areaStart:mE,areaEnd:mE,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x2,this._y2),this._context.closePath();break;case 2:this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath();break;case 3:this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4);break}},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._x2=e,this._y2=t;break;case 1:this._point=2,this._x3=e,this._y3=t;break;case 2:this._point=3,this._x4=e,this._y4=t,this._context.moveTo((this._x0+4*this._x1+e)/6,(this._y0+4*this._y1+t)/6);break;default:hE(this,e,t);break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function uue(e){return new _E(e)}function vE(e){this._context=e}vE.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===3)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3;var n=(this._x0+4*this._x1+e)/6,r=(this._y0+4*this._y1+t)/6;this._line?this._context.lineTo(n,r):this._context.moveTo(n,r);break;case 3:this._point=4;default:hE(this,e,t);break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function due(e){return new vE(e)}function yE(e){this._context=e}yE.prototype={areaStart:mE,areaEnd:mE,lineStart:function(){this._point=0},lineEnd:function(){this._point&&this._context.closePath()},point:function(e,t){e=+e,t=+t,this._point?this._context.lineTo(e,t):(this._point=1,this._context.moveTo(e,t))}};function fue(e){return new yE(e)}function bE(e){return e<0?-1:1}function xE(e,t,n){var r=e._x1-e._x0,i=t-e._x1,a=(e._y1-e._y0)/(r||i<0&&-0),o=(n-e._y1)/(i||r<0&&-0),s=(a*i+o*r)/(r+i);return(bE(a)+bE(o))*Math.min(Math.abs(a),Math.abs(o),.5*Math.abs(s))||0}function SE(e,t){var n=e._x1-e._x0;return n?(3*(e._y1-e._y0)/n-t)/2:t}function CE(e,t,n){var r=e._x0,i=e._y0,a=e._x1,o=e._y1,s=(a-r)/3;e._context.bezierCurveTo(r+s,i+s*t,a-s,o-s*n,a,o)}function wE(e){this._context=e}wE.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:CE(this,this._t0,SE(this,this._t0));break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){var n=NaN;if(e=+e,t=+t,!(e===this._x1&&t===this._y1)){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,CE(this,SE(this,n=xE(this,e,t)),n);break;default:CE(this,this._t0,n=xE(this,e,t));break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t,this._t0=n}}};function TE(e){this._context=new EE(e)}(TE.prototype=Object.create(wE.prototype)).point=function(e,t){wE.prototype.point.call(this,t,e)};function EE(e){this._context=e}EE.prototype={moveTo:function(e,t){this._context.moveTo(t,e)},closePath:function(){this._context.closePath()},lineTo:function(e,t){this._context.lineTo(t,e)},bezierCurveTo:function(e,t,n,r,i,a){this._context.bezierCurveTo(t,e,r,n,a,i)}};function pue(e){return new wE(e)}function mue(e){return new TE(e)}function DE(e){this._context=e}DE.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=[],this._y=[]},lineEnd:function(){var e=this._x,t=this._y,n=e.length;if(n)if(this._line?this._context.lineTo(e[0],t[0]):this._context.moveTo(e[0],t[0]),n===2)this._context.lineTo(e[1],t[1]);else for(var r=OE(e),i=OE(t),a=0,o=1;o=0;--t)i[t]=(o[t]-i[t+1])/a[t];for(a[n-1]=(e[n]+i[n-1])/2,t=0;t=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:if(this._t<=0)this._context.lineTo(this._x,t),this._context.lineTo(e,t);else{var n=this._x*(1-this._t)+e*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,t)}break}this._x=e,this._y=t}};function gue(e){return new kE(e,.5)}function _ue(e){return new kE(e,0)}function vue(e){return new kE(e,1)}function AE(e,t){if((o=e.length)>1)for(var n=1,r,i,a=e[t[0]],o,s=a.length;n=0;)n[t]=t;return n}function yue(e,t){return e[t]}function bue(e){let t=[];return t.key=e,t}function xue(){var e=VT([]),t=jE,n=AE,r=yue;function i(i){var a=Array.from(e.apply(this,arguments),bue),o,s=a.length,c=-1,l;for(let e of i)for(o=0,++c;o0){for(var n,r,i=0,a=e[0].length,o;i0){for(var n=0,r=e[t[0]],i,a=r.length;n0)||!((a=(i=e[t[0]]).length)>0))){for(var n=0,r=1,i,a,o;r{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return e===`__proto__`}e.isUnsafeProperty=t})),ME=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){switch(typeof e){case`number`:case`symbol`:return!1;case`string`:return e.includes(`.`)||e.includes(`[`)||e.includes(`]`)}}e.isDeepKey=t})),NE=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return typeof e==`string`||typeof e==`symbol`?e:Object.is(e?.valueOf?.(),-0)?`-0`:String(e)}e.toKey=t})),Eue=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){if(e==null)return``;if(typeof e==`string`)return e;if(Array.isArray(e))return e.map(t).join(`,`);let n=String(e);return n===`0`&&Object.is(Number(e),-0)?`-0`:n}e.toString=t})),PE=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Eue(),n=NE();function r(e){if(Array.isArray(e))return e.map(n.toKey);if(typeof e==`symbol`)return[e];e=t.toString(e);let r=[],i=e.length;if(i===0)return r;let a=0,o=``,s=``,c=!1;for(e.charCodeAt(0)===46&&(r.push(``),a++);a{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Tue(),n=ME(),r=NE(),i=PE();function a(e,s,c){if(e==null)return c;switch(typeof s){case`string`:{if(t.isUnsafeProperty(s))return c;let r=e[s];return r===void 0?n.isDeepKey(s)?a(e,i.toPath(s),c):c:r}case`number`:case`symbol`:{typeof s==`number`&&(s=r.toKey(s));let t=e[s];return t===void 0?c:t}default:{if(Array.isArray(s))return o(e,s,c);if(s=Object.is(s?.valueOf(),-0)?`-0`:String(s),t.isUnsafeProperty(s))return c;let n=e[s];return n===void 0?c:n}}}function o(e,n,r){if(n.length===0)return r;let i=e;for(let e=0;e{t.exports=FE().get})),Oue=4;function IE(e){var t=10**(arguments.length>1&&arguments[1]!==void 0?arguments[1]:Oue),n=Math.round(e*t)/t;return Object.is(n,-0)?0:n}function LE(e){var t=[...arguments].slice(1);return e.reduce((e,n,r)=>{var i=t[r-1];return typeof i==`string`?e+i+n:i===void 0?e+n:e+IE(i)+n},``)}var RE=l(Due()),zE=e=>e===0?0:e>0?1:-1,BE=e=>typeof e==`number`&&e!=+e,VE=e=>typeof e==`string`&&e.indexOf(`%`)===e.length-1,HE=e=>(typeof e==`number`||e instanceof Number)&&!BE(e),UE=e=>HE(e)||typeof e==`string`,kue=0,WE=e=>{var t=++kue;return`${e||``}${t}`},GE=function(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:!1;if(!HE(e)&&typeof e!=`string`)return n;var i;if(VE(e)){if(t==null)return n;var a=e.indexOf(`%`);i=t*parseFloat(e.slice(0,a))/100}else i=+e;return BE(i)&&(i=n),r&&t!=null&&i>t&&(i=t),i},KE=e=>{if(!Array.isArray(e))return!1;for(var t=e.length,n={},r=0;re&&(typeof t==`function`?t(e):(0,RE.default)(e,t))===n)}var YE=e=>e==null,XE=e=>YE(e)?e:`${e.charAt(0).toUpperCase()}${e.slice(1)}`;function ZE(e){return e!=null}function QE(){}var Aue=[`type`,`size`,`sizeType`];function $E(){return $E=Object.assign?Object.assign.bind():function(e){for(var t=1;tnD[`symbol${XE(e)}`]||sE,Rue=(e,t,n)=>{if(t===`area`)return e;switch(n){case`cross`:return 5*e*e/9;case`diamond`:return .5*e*e/Math.sqrt(3);case`square`:return e*e;case`star`:var r=18*Iue;return 1.25*e*e*(Math.tan(r)-Math.tan(r*2)*Math.tan(r)**2);case`triangle`:return Math.sqrt(3)*e*e/4;case`wye`:return(21-10*Math.sqrt(3))*e*e/8;default:return Math.PI*e*e/4}},zue=(e,t)=>{nD[`symbol${XE(e)}`]=t},rD=e=>{var{type:t=`circle`,size:n=64,sizeType:r=`area`}=e,i=tD(tD({},Pue(e,Aue)),{},{type:t,size:n,sizeType:r}),a=`circle`;typeof t==`string`&&(a=t);var o=()=>{var e=Lue(a),t=cue().type(e).size(Rue(n,r,a))();if(t!==null)return t},{className:s,cx:c,cy:l}=i,u=FT(i);return HE(c)&&HE(l)&&HE(n)?y.createElement(`path`,$E({},u,{className:kT(`recharts-symbols`,s),transform:`translate(${c}, ${l})`,d:o()})):null};rD.registerSymbol=zue;var iD=e=>`radius`in e&&`startAngle`in e&&`endAngle`in e,aD=(e,t)=>{if(!e||typeof e==`function`||typeof e==`boolean`)return null;var n=e;if((0,y.isValidElement)(e)&&(n=e.props),typeof n!=`object`&&typeof n!=`function`)return null;var r={};return Object.keys(n).forEach(e=>{AT(e)&&(r[e]=t||(t=>n[e](n,t)))}),r},Bue=(e,t,n)=>r=>(e(t,n,r),null),oD=(e,t,n)=>{if(e===null||typeof e!=`object`&&typeof e!=`function`)return null;var r=null;return Object.keys(e).forEach(i=>{var a=e[i];AT(i)&&typeof a==`function`&&(r||={},r[i]=Bue(a,t,n))}),r};function sD(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 Vue(e){for(var t=1;t(e[t]===void 0&&r[t]!==void 0&&(e[t]=r[t]),e),n)}function lD(){return lD=Object.assign?Object.assign.bind():function(e){for(var t=1;t{var u=t.formatter||i,d=kT({"recharts-legend-item":!0,[`legend-item-${r}`]:!0,inactive:t.inactive});if(t.type===`none`)return null;var f=t.inactive?a:t.color,p=u?u(t.value,t,r):t.value;return y.createElement(`li`,lD({className:d,style:c,key:`legend-item-${r}`},oD(e,t,r)),y.createElement(LT,{width:n,height:n,viewBox:s,style:l,"aria-label":`${p} legend icon`},y.createElement(Xue,{data:t,iconType:o,inactiveColor:a})),y.createElement(`span`,{className:`recharts-legend-item-text`,style:{color:f}},p))})}var Que=e=>{var t=cD(e,Yue),{payload:n,layout:r,align:i}=t;if(!n||!n.length)return null;var a={padding:0,margin:0,textAlign:r===`horizontal`?i:`left`};return y.createElement(`ul`,{className:`recharts-default-legend`,style:a},y.createElement(Zue,lD({},t,{payload:n})))},$ue=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e,t){let n=new Map;for(let r=0;r{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e,t){return function(...n){return e.apply(this,n.slice(0,t))}}e.ary=t})),fD=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return e}e.identity=t})),tde=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return Number.isSafeInteger(e)&&e>=0}e.isLength=t})),pD=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=tde();function n(e){return e!=null&&typeof e!=`function`&&t.isLength(e.length)}e.isArrayLike=n})),nde=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return typeof e==`object`&&!!e}e.isObjectLike=t})),rde=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=pD(),n=nde();function r(e){return n.isObjectLike(e)&&t.isArrayLike(e)}e.isArrayLikeObject=r})),ide=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=FE();function n(e){return function(n){return t.get(n,e)}}e.property=n})),mD=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return e!==null&&(typeof e==`object`||typeof e==`function`)}e.isObject=t})),hD=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return e==null||typeof e!=`object`&&typeof e!=`function`}e.isPrimitive=t})),gD=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e,t){return e===t||Number.isNaN(e)&&Number.isNaN(t)}e.isEqualsSameValueZero=t})),ade=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=mD(),n=hD(),r=gD();function i(e,t,n){return typeof n==`function`?a(e,t,function e(t,r,i,o,s,c){let l=n(t,r,i,o,s,c);return l===void 0?a(t,r,e,c):!!l},new Map):i(e,t,()=>void 0)}function a(e,n,i,s){if(n===e)return!0;switch(typeof n){case`object`:return o(e,n,i,s);case`function`:return Object.keys(n).length>0?a(e,{...n},i,s):r.isEqualsSameValueZero(e,n);default:return t.isObject(e)?typeof n==`string`?n===``:!0:r.isEqualsSameValueZero(e,n)}}function o(e,t,r,i){if(t==null)return!0;if(Array.isArray(t))return c(e,t,r,i);if(t instanceof Map)return s(e,t,r,i);if(t instanceof Set)return l(e,t,r,i);let a=Object.keys(t);if(e==null||n.isPrimitive(e))return a.length===0;if(a.length===0)return!0;if(i?.has(t))return i.get(t)===e;i?.set(t,e);try{for(let o=0;o{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=ade();function n(e,n){return t.isMatchWith(e,n,()=>void 0)}e.isMatch=n})),ode=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return Object.getOwnPropertySymbols(e).filter(t=>Object.prototype.propertyIsEnumerable.call(e,t))}e.getSymbols=t})),vD=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return e==null?e===void 0?`[object Undefined]`:`[object Null]`:Object.prototype.toString.call(e)}e.getTag=t})),yD=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),e.argumentsTag=`[object Arguments]`,e.arrayBufferTag=`[object ArrayBuffer]`,e.arrayTag=`[object Array]`,e.bigInt64ArrayTag=`[object BigInt64Array]`,e.bigUint64ArrayTag=`[object BigUint64Array]`,e.booleanTag=`[object Boolean]`,e.dataViewTag=`[object DataView]`,e.dateTag=`[object Date]`,e.errorTag=`[object Error]`,e.float32ArrayTag=`[object Float32Array]`,e.float64ArrayTag=`[object Float64Array]`,e.functionTag=`[object Function]`,e.int16ArrayTag=`[object Int16Array]`,e.int32ArrayTag=`[object Int32Array]`,e.int8ArrayTag=`[object Int8Array]`,e.mapTag=`[object Map]`,e.numberTag=`[object Number]`,e.objectTag=`[object Object]`,e.regexpTag=`[object RegExp]`,e.setTag=`[object Set]`,e.stringTag=`[object String]`,e.symbolTag=`[object Symbol]`,e.uint16ArrayTag=`[object Uint16Array]`,e.uint32ArrayTag=`[object Uint32Array]`,e.uint8ArrayTag=`[object Uint8Array]`,e.uint8ClampedArrayTag=`[object Uint8ClampedArray]`})),sde=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}e.isTypedArray=t})),bD=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=ode(),n=vD(),r=yD(),i=hD(),a=sde();function o(e,t){return s(e,void 0,e,new Map,t)}function s(e,t,n,r=new Map,o=void 0){let u=o?.(e,t,n,r);if(u!==void 0)return u;if(i.isPrimitive(e))return e;if(r.has(e))return r.get(e);if(Array.isArray(e)){let t=Array(e.length);r.set(e,t);for(let i=0;i{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=bD();function n(e){return t.cloneDeepWithImpl(e,void 0,e,new Map,void 0)}e.cloneDeep=n})),lde=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=_D(),n=cde();function r(e){return e=n.cloneDeep(e),n=>t.isMatch(n,e)}e.matches=r})),ude=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=bD(),n=vD(),r=yD();function i(e,i){return t.cloneDeepWith(e,(a,o,s,c)=>{let l=i?.(a,o,s,c);if(l!==void 0)return l;if(typeof e==`object`){if(n.getTag(e)===r.objectTag&&typeof e.constructor!=`function`){let n={};return c.set(e,n),t.copyProperties(n,e,s,c),n}switch(Object.prototype.toString.call(e)){case r.numberTag:case r.stringTag:case r.booleanTag:{let n=new e.constructor(e?.valueOf());return t.copyProperties(n,e),n}case r.argumentsTag:{let n={};return t.copyProperties(n,e),n.length=e.length,n[Symbol.iterator]=e[Symbol.iterator],n}default:return}}})}e.cloneDeepWith=i})),dde=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=ude();function n(e){return t.cloneDeepWith(e)}e.cloneDeep=n})),xD=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=/^(?:0|[1-9]\d*)$/;function n(e,n=2**53-1){switch(typeof e){case`number`:return Number.isInteger(e)&&e>=0&&e{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=vD();function n(e){return typeof e==`object`&&!!e&&t.getTag(e)===`[object Arguments]`}e.isArguments=n})),pde=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=ME(),n=xD(),r=fde(),i=PE();function a(e,a){let o;if(o=Array.isArray(a)?a:typeof a==`string`&&t.isDeepKey(a)&&e?.[a]==null?i.toPath(a):[a],o.length===0)return!1;let s=e;for(let e=0;e{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=_D(),n=NE(),r=dde(),i=FE(),a=pde();function o(e,o){switch(typeof e){case`object`:Object.is(e?.valueOf(),-0)&&(e=`-0`);break;case`number`:e=n.toKey(e);break}return o=r.cloneDeep(o),function(n){let r=i.get(n,e);return r===void 0?a.has(n,e):o===void 0?r===void 0:t.isMatch(r,o)}}e.matchesProperty=o})),hde=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=fD(),n=ide(),r=lde(),i=mde();function a(e){if(e==null)return t.identity;switch(typeof e){case`function`:return e;case`object`:return Array.isArray(e)&&e.length===2?i.matchesProperty(e[0],e[1]):r.matches(e);case`string`:case`symbol`:case`number`:return n.property(e)}}e.iteratee=a})),gde=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=$ue(),n=ede(),r=fD(),i=rde(),a=hde();function o(e,o=r.identity){return i.isArrayLikeObject(e)?t.uniqBy(Array.from(e),n.ary(a.iteratee(o),1)):[]}e.uniqBy=o})),SD=l(o(((e,t)=>{t.exports=gde().uniqBy}))());function CD(e,t,n){return t===!0?(0,SD.default)(e,n):typeof t==`function`?(0,SD.default)(e,t):e}var _de=o((e=>{var t=f(),n=Xe();function r(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var i=typeof Object.is==`function`?Object.is:r,a=n.useSyncExternalStore,o=t.useRef,s=t.useEffect,c=t.useMemo,l=t.useDebugValue;e.useSyncExternalStoreWithSelector=function(e,t,n,r,u){var d=o(null);if(d.current===null){var f={hasValue:!1,value:null};d.current=f}else f=d.current;d=c(function(){function e(e){if(!a){if(a=!0,o=e,e=r(e),u!==void 0&&f.hasValue){var t=f.value;if(u(t,e))return s=t}return s=e}if(t=s,i(o,e))return t;var n=r(e);return u!==void 0&&u(t,n)?(o=e,t):(o=e,s=n)}var a=!1,o,s,c=n===void 0?null:n;return[function(){return e(t())},c===null?void 0:function(){return e(c())}]},[t,n,r,u]);var p=a(e,d[0],d[1]);return s(function(){f.hasValue=!0,f.value=p},[p]),l(p),p}})),vde=o(((e,t)=>{t.exports=_de()})),wD=(0,y.createContext)(null),TD=vde(),yde=e=>e,ED=()=>{var e=(0,y.useContext)(wD);return e?e.store.dispatch:yde},DD=()=>{},bde=()=>DD,xde=(e,t)=>e===t;function OD(e){var t=(0,y.useContext)(wD),n=(0,y.useMemo)(()=>t?t=>{if(t!=null)return e(t)}:DD,[t,e]);return(0,TD.useSyncExternalStoreWithSelector)(t?t.subscription.addNestedSub:bde,t?t.store.getState:DD,t?t.store.getState:DD,n,xde)}function Sde(e,t=`expected a function, instead received ${typeof e}`){if(typeof e!=`function`)throw TypeError(t)}function Cde(e,t=`expected an object, instead received ${typeof e}`){if(typeof e!=`object`)throw TypeError(t)}function wde(e,t=`expected all items to be functions, instead received the following types: `){if(!e.every(e=>typeof e==`function`)){let n=e.map(e=>typeof e==`function`?`function ${e.name||`unnamed`}()`:typeof e).join(`, `);throw TypeError(`${t}[${n}]`)}}var kD=e=>Array.isArray(e)?e:[e];function Tde(e){let t=Array.isArray(e[0])?e[0]:e;return wde(t,`createSelector expects all input-selectors to be functions, but received the following types: `),t}function Ede(e,t){let n=[],{length:r}=e;for(let i=0;i{n=jD(),o.resetResultsCount()},o.resultsCount=()=>a,o.resetResultsCount=()=>{a=0},o}function Ade(e,...t){let n=typeof e==`function`?{memoize:e,memoizeOptions:t}:e,r=(...e)=>{let t=0,r=0,i,a={},o=e.pop();typeof o==`object`&&(a=o,o=e.pop()),Sde(o,`createSelector expects an output function after the inputs, but received: [${typeof o}]`);let{memoize:s,memoizeOptions:c=[],argsMemoize:l=MD,argsMemoizeOptions:u=[],devModeChecks:d={}}={...n,...a},f=kD(c),p=kD(u),m=Tde(e),h=s(function(){return t++,o.apply(null,arguments)},...f),g=l(function(){r++;let e=Ede(m,arguments);return i=h.apply(null,e),i},...p);return Object.assign(g,{resultFunc:o,memoizedResultFunc:h,dependencies:m,dependencyRecomputations:()=>r,resetDependencyRecomputations:()=>{r=0},lastResult:()=>i,recomputations:()=>t,resetRecomputations:()=>{t=0},memoize:s,argsMemoize:l})};return Object.assign(r,{withTypes:()=>r}),r}var ND=Ade(MD),jde=Object.assign((e,t=ND)=>{Cde(e,`createStructuredSelector expects first argument to be an object where each property is a selector, instead received a ${typeof e}`);let n=Object.keys(e);return t(n.map(t=>e[t]),(...e)=>e.reduce((e,t,r)=>(e[n[r]]=t,e),{}))},{withTypes:()=>jde}),Mde=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return typeof e==`symbol`?1:e===null?2:e===void 0?3:e===e?0:4}e.compareValues=(e,n,r)=>{if(e!==n){let i=t(e),a=t(n);if(i===a&&i===0){if(en)return r===`desc`?-1:1}return r===`desc`?a-i:i-a}return 0}})),PD=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return typeof e==`symbol`||e instanceof Symbol}e.isSymbol=t})),Nde=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=PD(),n=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,r=/^\w*$/;function i(e,i){return Array.isArray(e)?!1:typeof e==`number`||typeof e==`boolean`||e==null||t.isSymbol(e)?!0:typeof e==`string`&&(r.test(e)||!n.test(e))||i!=null&&Object.hasOwn(i,e)}e.isKey=i})),Pde=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Mde(),n=Nde(),r=PE();function i(e,i,a,o){if(e==null)return[];a=o?void 0:a,Array.isArray(e)||(e=Object.values(e)),Array.isArray(i)||(i=i==null?[null]:[i]),i.length===0&&(i=[null]),Array.isArray(a)||(a=a==null?[]:[a]),a=a.map(e=>String(e));let s=(e,t)=>{let n=e;for(let e=0;et==null||e==null?t:typeof e==`object`&&`key`in e?Object.hasOwn(t,e.key)?t[e.key]:s(t,e.path):typeof e==`function`?e(t):Array.isArray(e)?s(t,e):typeof t==`object`?t[e]:t,l=i.map(e=>(Array.isArray(e)&&e.length===1&&(e=e[0]),e==null||typeof e==`function`||Array.isArray(e)||n.isKey(e)?e:{key:e,path:r.toPath(e)}));return e.map(e=>({original:e,criteria:l.map(t=>c(t,e))})).slice().sort((e,n)=>{for(let r=0;re.original)}e.orderBy=i})),Fde=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e,t=1){let n=[],r=Math.floor(t),i=(e,t)=>{for(let a=0;a{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=xD(),n=pD(),r=mD(),i=gD();function a(e,a,o){return r.isObject(o)&&(typeof a==`number`&&n.isArrayLike(o)&&t.isIndex(a)&&a{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Pde(),n=Fde(),r=FD();function i(e,...i){let a=i.length;return a>1&&r.isIterateeCall(e,i[0],i[1])?i=[]:a>2&&r.isIterateeCall(i[0],i[1],i[2])&&(i=[i[0]]),t.orderBy(e,n.flatten(i),[`asc`])}e.sortBy=i})),ID=l(o(((e,t)=>{t.exports=Ide().sortBy}))()),LD=e=>e.legend.settings,Lde=e=>e.legend.size,Rde=ND([e=>e.legend.payload,LD],(e,t)=>{var{itemSorter:n}=t,r=e.flat(1);return n?(0,ID.default)(r,n):r});function zde(){return OD(Rde)}var RD=1;function zD(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],[t,n]=(0,y.useState)({height:0,left:0,top:0,width:0});return[t,(0,y.useCallback)(e=>{if(e!=null){var r=e.getBoundingClientRect(),i={height:r.height,left:r.left,top:r.top,width:r.width};(Math.abs(i.height-t.height)>RD||Math.abs(i.left-t.left)>RD||Math.abs(i.top-t.top)>RD||Math.abs(i.width-t.width)>RD)&&n({height:i.height,left:i.left,top:i.top,width:i.width})}},[t.width,t.height,t.top,t.left,...e])]}function BD(e){return`Minified Redux error #${e}; visit https://redux.js.org/Errors?code=${e} for the full message or use the non-minified dev environment for full errors. `}var VD=typeof Symbol==`function`&&Symbol.observable||`@@observable`,HD=()=>Math.random().toString(36).substring(7).split(``).join(`.`),UD={INIT:`@@redux/INIT${HD()}`,REPLACE:`@@redux/REPLACE${HD()}`,PROBE_UNKNOWN_ACTION:()=>`@@redux/PROBE_UNKNOWN_ACTION${HD()}`};function WD(e){if(typeof e!=`object`||!e)return!1;let t=e;for(;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t||Object.getPrototypeOf(e)===null}function GD(e,t,n){if(typeof e!=`function`)throw Error(BD(2));if(typeof t==`function`&&typeof n==`function`||typeof n==`function`&&typeof arguments[3]==`function`)throw Error(BD(0));if(typeof t==`function`&&n===void 0&&(n=t,t=void 0),n!==void 0){if(typeof n!=`function`)throw Error(BD(1));return n(GD)(e,t)}let r=e,i=t,a=new Map,o=a,s=0,c=!1;function l(){o===a&&(o=new Map,a.forEach((e,t)=>{o.set(t,e)}))}function u(){if(c)throw Error(BD(3));return i}function d(e){if(typeof e!=`function`)throw Error(BD(4));if(c)throw Error(BD(5));let t=!0;l();let n=s++;return o.set(n,e),function(){if(t){if(c)throw Error(BD(6));t=!1,l(),o.delete(n),a=null}}}function f(e){if(!WD(e))throw Error(BD(7));if(e.type===void 0)throw Error(BD(8));if(typeof e.type!=`string`)throw Error(BD(17));if(c)throw Error(BD(9));try{c=!0,i=r(i,e)}finally{c=!1}return(a=o).forEach(e=>{e()}),e}function p(e){if(typeof e!=`function`)throw Error(BD(10));r=e,f({type:UD.REPLACE})}function m(){let e=d;return{subscribe(t){if(typeof t!=`object`||!t)throw Error(BD(11));function n(){let e=t;e.next&&e.next(u())}return n(),{unsubscribe:e(n)}},[VD](){return this}}}return f({type:UD.INIT}),{dispatch:f,subscribe:d,getState:u,replaceReducer:p,[VD]:m}}function Bde(e){Object.keys(e).forEach(t=>{let n=e[t];if(n(void 0,{type:UD.INIT})===void 0)throw Error(BD(12));if(n(void 0,{type:UD.PROBE_UNKNOWN_ACTION()})===void 0)throw Error(BD(13))})}function KD(e){let t=Object.keys(e),n={};for(let r=0;re:e.length===1?e[0]:e.reduce((e,t)=>(...n)=>e(t(...n)))}function Vde(...e){return t=>(n,r)=>{let i=t(n,r),a=()=>{throw Error(BD(15))},o={getState:i.getState,dispatch:(e,...t)=>a(e,...t)};return a=qD(...e.map(e=>e(o)))(i.dispatch),{...i,dispatch:a}}}function JD(e){return WD(e)&&`type`in e&&typeof e.type==`string`}var YD=Symbol.for(`immer-nothing`),XD=Symbol.for(`immer-draftable`),ZD=Symbol.for(`immer-state`);function QD(e,...t){throw Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var $D=Object,eO=$D.getPrototypeOf,tO=`constructor`,nO=`prototype`,rO=`configurable`,iO=`enumerable`,aO=`writable`,oO=`value`,sO=e=>!!e&&!!e[ZD];function cO(e){return e?uO(e)||gO(e)||!!e[XD]||!!e[tO]?.[XD]||_O(e)||vO(e):!1}var Hde=$D[nO][tO].toString(),lO=new WeakMap;function uO(e){if(!e||!yO(e))return!1;let t=eO(e);if(t===null||t===$D[nO])return!0;let n=$D.hasOwnProperty.call(t,tO)&&t[tO];if(n===Object)return!0;if(!bO(n))return!1;let r=lO.get(n);return r===void 0&&(r=Function.toString.call(n),lO.set(n,r)),r===Hde}function dO(e,t,n=!0){fO(e)===0?(n?Reflect.ownKeys(e):$D.keys(e)).forEach(n=>{t(n,e[n],e)}):e.forEach((n,r)=>t(r,n,e))}function fO(e){let t=e[ZD];return t?t.type_:gO(e)?1:_O(e)?2:vO(e)?3:0}var pO=(e,t,n=fO(e))=>n===2?e.has(t):$D[nO].hasOwnProperty.call(e,t),mO=(e,t,n=fO(e))=>n===2?e.get(t):e[t],hO=(e,t,n,r=fO(e))=>{r===2?e.set(t,n):r===3?e.add(n):e[t]=n};function Ude(e,t){return e===t?e!==0||1/e==1/t:e!==e&&t!==t}var gO=Array.isArray,_O=e=>e instanceof Map,vO=e=>e instanceof Set,yO=e=>typeof e==`object`,bO=e=>typeof e==`function`,xO=e=>typeof e==`boolean`;function Wde(e){let t=+e;return Number.isInteger(t)&&String(t)===e}var SO=e=>e.copy_||e.base_,CO=e=>e.modified_?e.copy_:e.base_;function wO(e,t){if(_O(e))return new Map(e);if(vO(e))return new Set(e);if(gO(e))return Array[nO].slice.call(e);let n=uO(e);if(t===!0||t===`class_only`&&!n){let t=$D.getOwnPropertyDescriptors(e);delete t[ZD];let n=Reflect.ownKeys(t);for(let r=0;r1&&$D.defineProperties(e,{set:EO,add:EO,clear:EO,delete:EO}),$D.freeze(e),t&&dO(e,(e,t)=>{TO(t,!0)},!1),e)}function Gde(){QD(2)}var EO={[oO]:Gde};function DO(e){return e===null||!yO(e)?!0:$D.isFrozen(e)}var OO=`MapSet`,kO=`Patches`,AO=`ArrayMethods`,jO={};function MO(e){let t=jO[e];return t||QD(0,e),t}var NO=e=>!!jO[e],PO,FO=()=>PO,Kde=(e,t)=>({drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0,handledSet_:new Set,processedForPatches_:new Set,mapSetPlugin_:NO(OO)?MO(OO):void 0,arrayMethodsPlugin_:NO(AO)?MO(AO):void 0});function IO(e,t){t&&(e.patchPlugin_=MO(kO),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function LO(e){RO(e),e.drafts_.forEach(qde),e.drafts_=null}function RO(e){e===PO&&(PO=e.parent_)}var zO=e=>PO=Kde(PO,e);function qde(e){let t=e[ZD];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function BO(e,t){t.unfinalizedDrafts_=t.drafts_.length;let n=t.drafts_[0];if(e!==void 0&&e!==n){n[ZD].modified_&&(LO(t),QD(4)),cO(e)&&(e=VO(t,e));let{patchPlugin_:r}=t;r&&r.generateReplacementPatches_(n[ZD].base_,e,t)}else e=VO(t,n);return Jde(t,e,!0),LO(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e===YD?void 0:e}function VO(e,t){if(DO(t))return t;let n=t[ZD];if(!n)return KO(t,e.handledSet_,e);if(!UO(n,e))return t;if(!n.modified_)return n.base_;if(!n.finalized_){let{callbacks_:t}=n;if(t)for(;t.length>0;)t.pop()(e);GO(n,e)}return n.copy_}function Jde(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&TO(t,n)}function HO(e){e.finalized_=!0,e.scope_.unfinalizedDrafts_--}var UO=(e,t)=>e.scope_===t,Yde=[];function WO(e,t,n,r){let i=SO(e),a=e.type_;if(r!==void 0&&mO(i,r,a)===t){hO(i,r,n,a);return}if(!e.draftLocations_){let t=e.draftLocations_=new Map;dO(i,(e,n)=>{if(sO(n)){let r=t.get(n)||[];r.push(e),t.set(n,r)}})}let o=e.draftLocations_.get(t)??Yde;for(let e of o)hO(i,e,n,a)}function Xde(e,t,n){e.callbacks_.push(function(r){let i=t;if(!i||!UO(i,r))return;r.mapSetPlugin_?.fixSetContents(i);let a=CO(i);WO(e,i.draft_??i,a,n),GO(i,r)})}function GO(e,t){if(e.modified_&&!e.finalized_&&(e.type_===3||e.type_===1&&e.allIndicesReassigned_||(e.assigned_?.size??0)>0)){let{patchPlugin_:n}=t;if(n){let r=n.getPath(e);r&&n.generatePatches_(e,r,t)}HO(e)}}function Zde(e,t,n){let{scope_:r}=e;if(sO(n)){let i=n[ZD];UO(i,r)&&i.callbacks_.push(function(){QO(e),WO(e,n,CO(i),t)})}else cO(n)&&e.callbacks_.push(function(){let i=SO(e);e.type_===3?i.has(n)&&KO(n,r.handledSet_,r):mO(i,t,e.type_)===n&&r.drafts_.length>1&&(e.assigned_.get(t)??!1)===!0&&e.copy_&&KO(mO(e.copy_,t,e.type_),r.handledSet_,r)})}function KO(e,t,n){return!n.immer_.autoFreeze_&&n.unfinalizedDrafts_<1||sO(e)||t.has(e)||!cO(e)||DO(e)?e:(t.add(e),dO(e,(r,i)=>{if(sO(i)){let t=i[ZD];UO(t,n)&&(hO(e,r,CO(t),e.type_),HO(t))}else cO(i)&&KO(i,t,n)}),e)}function Qde(e,t){let n=gO(e),r={type_:+!!n,scope_:t?t.scope_:FO(),modified_:!1,finalized_:!1,assigned_:void 0,parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1,callbacks_:void 0},i=r,a=qO;n&&(i=[r],a=JO);let{revoke:o,proxy:s}=Proxy.revocable(i,a);return r.draft_=s,r.revoke_=o,[s,r]}var qO={get(e,t){if(t===ZD)return e;let n=e.scope_.arrayMethodsPlugin_,r=e.type_===1&&typeof t==`string`;if(r&&n?.isArrayOperationMethod(t))return n.createMethodInterceptor(e,t);let i=SO(e);if(!pO(i,t,e.type_))return $de(e,i,t);let a=i[t];if(e.finalized_||!cO(a)||r&&e.operationMethod&&n?.isMutatingArrayMethod(e.operationMethod)&&Wde(t))return a;if(a===YO(e.base_,t)){QO(e);let n=e.type_===1?+t:t,r=$O(e.scope_,a,e,n);return e.copy_[n]=r}return a},has(e,t){return t in SO(e)},ownKeys(e){return Reflect.ownKeys(SO(e))},set(e,t,n){let r=XO(SO(e),t);if(r?.set)return r.set.call(e.draft_,n),!0;if(!e.modified_){let r=YO(SO(e),t),i=r?.[ZD];if(i&&i.base_===n)return e.copy_[t]=n,e.assigned_.set(t,!1),!0;if(Ude(n,r)&&(n!==void 0||pO(e.base_,t,e.type_)))return!0;QO(e),ZO(e)}return e.copy_[t]===n&&(n!==void 0||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])?!0:(e.copy_[t]=n,e.assigned_.set(t,!0),Zde(e,t,n),!0)},deleteProperty(e,t){return QO(e),YO(e.base_,t)!==void 0||t in e.base_?(e.assigned_.set(t,!1),ZO(e)):e.assigned_.delete(t),e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){let n=SO(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r&&{[aO]:!0,[rO]:e.type_!==1||t!==`length`,[iO]:r[iO],[oO]:n[t]}},defineProperty(){QD(11)},getPrototypeOf(e){return eO(e.base_)},setPrototypeOf(){QD(12)}},JO={};for(let e in qO){let t=qO[e];JO[e]=function(){let e=arguments;return e[0]=e[0][0],t.apply(this,e)}}JO.deleteProperty=function(e,t){return JO.set.call(this,e,t,void 0)},JO.set=function(e,t,n){return qO.set.call(this,e[0],t,n,e[0])};function YO(e,t){let n=e[ZD];return(n?SO(n):e)[t]}function $de(e,t,n){let r=XO(t,n);return r?oO in r?r[oO]:r.get?.call(e.draft_):void 0}function XO(e,t){if(!(t in e))return;let n=eO(e);for(;n;){let e=Object.getOwnPropertyDescriptor(n,t);if(e)return e;n=eO(n)}}function ZO(e){e.modified_||(e.modified_=!0,e.parent_&&ZO(e.parent_))}function QO(e){e.copy_||=(e.assigned_=new Map,wO(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var efe=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!1,this.produce=(e,t,n)=>{if(bO(e)&&!bO(t)){let n=t;t=e;let r=this;return function(e=n,...i){return r.produce(e,e=>t.call(this,e,...i))}}bO(t)||QD(6),n!==void 0&&!bO(n)&&QD(7);let r;if(cO(e)){let i=zO(this),a=$O(i,e,void 0),o=!0;try{r=t(a),o=!1}finally{o?LO(i):RO(i)}return IO(i,n),BO(r,i)}else if(!e||!yO(e)){if(r=t(e),r===void 0&&(r=e),r===YD&&(r=void 0),this.autoFreeze_&&TO(r,!0),n){let t=[],i=[];MO(kO).generateReplacementPatches_(e,r,{patches_:t,inversePatches_:i}),n(t,i)}return r}else QD(1,e)},this.produceWithPatches=(e,t)=>{if(bO(e))return(t,...n)=>this.produceWithPatches(t,t=>e(t,...n));let n,r;return[this.produce(e,t,(e,t)=>{n=e,r=t}),n,r]},xO(e?.autoFreeze)&&this.setAutoFreeze(e.autoFreeze),xO(e?.useStrictShallowCopy)&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),xO(e?.useStrictIteration)&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){cO(e)||QD(8),sO(e)&&(e=ek(e));let t=zO(this),n=$O(t,e,void 0);return n[ZD].isManual_=!0,RO(t),n}finishDraft(e,t){let n=e&&e[ZD];(!n||!n.isManual_)&&QD(9);let{scope_:r}=n;return IO(r,t),BO(void 0,r)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){let r=t[n];if(r.path.length===0&&r.op===`replace`){e=r.value;break}}n>-1&&(t=t.slice(n+1));let r=MO(kO).applyPatches_;return sO(e)?r(e,t):this.produce(e,e=>r(e,t))}};function $O(e,t,n,r){let[i,a]=_O(t)?MO(OO).proxyMap_(t,n):vO(t)?MO(OO).proxySet_(t,n):Qde(t,n);return(n?.scope_??FO()).drafts_.push(i),a.callbacks_=n?.callbacks_??[],a.key_=r,n&&r!==void 0?Xde(n,a,r):a.callbacks_.push(function(e){e.mapSetPlugin_?.fixSetContents(a);let{patchPlugin_:t}=e;a.modified_&&t&&t.generatePatches_(a,[],e)}),i}function ek(e){return sO(e)||QD(10,e),tk(e)}function tk(e){if(!cO(e)||DO(e))return e;let t=e[ZD],n,r=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=wO(e,t.scope_.immer_.useStrictShallowCopy_),r=t.scope_.immer_.shouldUseStrictIteration()}else n=wO(e,!0);return dO(n,(e,t)=>{hO(n,e,tk(t))},r),t&&(t.finalized_=!1),n}var nk=new efe().produce;function rk(e){return({dispatch:t,getState:n})=>r=>i=>typeof i==`function`?i(t,n,e):r(i)}var tfe=rk(),nfe=rk,rfe=typeof window<`u`&&window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__:function(){if(arguments.length!==0)return typeof arguments[0]==`object`?qD:qD.apply(null,arguments)};typeof window<`u`&&window.__REDUX_DEVTOOLS_EXTENSION__&&window.__REDUX_DEVTOOLS_EXTENSION__;function ik(e,t){function n(...n){if(t){let r=t(...n);if(!r)throw Error(zk(0));return{type:e,payload:r.payload,...`meta`in r&&{meta:r.meta},...`error`in r&&{error:r.error}}}return{type:e,payload:n[0]}}return n.toString=()=>`${e}`,n.type=e,n.match=t=>JD(t)&&t.type===e,n}var ak=class e extends Array{constructor(...t){super(...t),Object.setPrototypeOf(this,e.prototype)}static get[Symbol.species](){return e}concat(...e){return super.concat.apply(this,e)}prepend(...t){return t.length===1&&Array.isArray(t[0])?new e(...t[0].concat(this)):new e(...t.concat(this))}};function ok(e){return cO(e)?nk(e,()=>{}):e}function sk(e,t,n){return e.has(t)?e.get(t):e.set(t,n(t)).get(t)}function ife(e){return typeof e==`boolean`}var afe=()=>function(e){let{thunk:t=!0,immutableCheck:n=!0,serializableCheck:r=!0,actionCreatorCheck:i=!0}=e??{},a=new ak;return t&&(ife(t)?a.push(tfe):a.push(nfe(t.extraArgument))),a},ck=`RTK_autoBatch`,lk=()=>e=>({payload:e,meta:{[ck]:!0}}),uk=e=>t=>{setTimeout(t,e)},dk=(e={type:`raf`})=>t=>(...n)=>{let r=t(...n),i=!0,a=!1,o=!1,s=new Set,c=e.type===`tick`?queueMicrotask:e.type===`raf`?typeof window<`u`&&window.requestAnimationFrame?window.requestAnimationFrame:uk(10):e.type===`callback`?e.queueNotification:uk(e.timeout),l=()=>{o=!1,a&&(a=!1,s.forEach(e=>e()))};return Object.assign({},r,{subscribe(e){let t=r.subscribe(()=>i&&e());return s.add(e),()=>{t(),s.delete(e)}},dispatch(e){try{return i=!e?.meta?.[ck],a=!i,a&&(o||(o=!0,c(l))),r.dispatch(e)}finally{i=!0}}})},ofe=e=>function(t){let{autoBatch:n=!0}=t??{},r=new ak(e);return n&&r.push(dk(typeof n==`object`?n:void 0)),r};function sfe(e){let t=afe(),{reducer:n=void 0,middleware:r,devTools:i=!0,duplicateMiddlewareCheck:a=!0,preloadedState:o=void 0,enhancers:s=void 0}=e||{},c;if(typeof n==`function`)c=n;else if(WD(n))c=KD(n);else throw Error(zk(1));let l;l=typeof r==`function`?r(t):t();let u=qD;i&&(u=rfe({trace:!1,...typeof i==`object`&&i}));let d=ofe(Vde(...l)),f=typeof s==`function`?s(d):d(),p=u(...f);return GD(c,o,p)}function fk(e){let t={},n=[],r,i={addCase(e,n){let r=typeof e==`string`?e:e.type;if(!r)throw Error(zk(28));if(r in t)throw Error(zk(29));return t[r]=n,i},addAsyncThunk(e,r){return r.pending&&(t[e.pending.type]=r.pending),r.rejected&&(t[e.rejected.type]=r.rejected),r.fulfilled&&(t[e.fulfilled.type]=r.fulfilled),r.settled&&n.push({matcher:e.settled,reducer:r.settled}),i},addMatcher(e,t){return n.push({matcher:e,reducer:t}),i},addDefaultCase(e){return r=e,i}};return e(i),[t,n,r]}function cfe(e){return typeof e==`function`}function lfe(e,t){let[n,r,i]=fk(t),a;if(cfe(e))a=()=>ok(e());else{let t=ok(e);a=()=>t}function o(e=a(),t){let o=[n[t.type],...r.filter(({matcher:e})=>e(t)).map(({reducer:e})=>e)];return o.filter(e=>!!e).length===0&&(o=[i]),o.reduce((e,n)=>{if(n)if(sO(e)){let r=n(e,t);return r===void 0?e:r}else if(cO(e))return nk(e,e=>n(e,t));else{let r=n(e,t);if(r===void 0){if(e===null)return e;throw Error(`A case reducer on a non-draftable value must not return undefined`)}return r}return e},e)}return o.getInitialState=a,o}var ufe=`ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW`,dfe=(e=21)=>{let t=``,n=e;for(;n--;)t+=ufe[Math.random()*64|0];return t},ffe=Symbol.for(`rtk-slice-createasyncthunk`);function pfe(e,t){return`${e}/${t}`}function mfe({creators:e}={}){let t=e?.asyncThunk?.[ffe];return function(e){let{name:n,reducerPath:r=n}=e;if(!n)throw Error(zk(11));let i=(typeof e.reducers==`function`?e.reducers(gfe()):e.reducers)||{},a=Object.keys(i),o={sliceCaseReducersByName:{},sliceCaseReducersByType:{},actionCreators:{},sliceMatchers:[]},s={addCase(e,t){let n=typeof e==`string`?e:e.type;if(!n)throw Error(zk(12));if(n in o.sliceCaseReducersByType)throw Error(zk(13));return o.sliceCaseReducersByType[n]=t,s},addMatcher(e,t){return o.sliceMatchers.push({matcher:e,reducer:t}),s},exposeAction(e,t){return o.actionCreators[e]=t,s},exposeCaseReducer(e,t){return o.sliceCaseReducersByName[e]=t,s}};a.forEach(r=>{let a=i[r],o={reducerName:r,type:pfe(n,r),createNotation:typeof e.reducers==`function`};vfe(a)?bfe(o,a,s,t):_fe(o,a,s)});function c(){let[t={},n=[],r=void 0]=typeof e.extraReducers==`function`?fk(e.extraReducers):[e.extraReducers],i={...t,...o.sliceCaseReducersByType};return lfe(e.initialState,e=>{for(let t in i)e.addCase(t,i[t]);for(let t of o.sliceMatchers)e.addMatcher(t.matcher,t.reducer);for(let t of n)e.addMatcher(t.matcher,t.reducer);r&&e.addDefaultCase(r)})}let l=e=>e,u=new Map,d=new WeakMap,f;function p(e,t){return f||=c(),f(e,t)}function m(){return f||=c(),f.getInitialState()}function h(t,n=!1){function r(e){let i=e[t];return i===void 0&&n&&(i=sk(d,r,m)),i}function i(t=l){return sk(sk(u,n,()=>new WeakMap),t,()=>{let r={};for(let[i,a]of Object.entries(e.selectors??{}))r[i]=hfe(a,t,()=>sk(d,t,m),n);return r})}return{reducerPath:t,getSelectors:i,get selectors(){return i(r)},selectSlice:r}}let g={name:n,reducer:p,actions:o.actionCreators,caseReducers:o.sliceCaseReducersByName,getInitialState:m,...h(r),injectInto(e,{reducerPath:t,...n}={}){let i=t??r;return e.inject({reducerPath:i,reducer:p},n),{...g,...h(i,!0)}}};return g}}function hfe(e,t,n,r){function i(i,...a){let o=t(i);return o===void 0&&r&&(o=n()),e(o,...a)}return i.unwrapped=e,i}var pk=mfe();function gfe(){function e(e,t){return{_reducerDefinitionType:`asyncThunk`,payloadCreator:e,...t}}return e.withTypes=()=>e,{reducer(e){return Object.assign({[e.name](...t){return e(...t)}}[e.name],{_reducerDefinitionType:`reducer`})},preparedReducer(e,t){return{_reducerDefinitionType:`reducerWithPrepare`,prepare:e,reducer:t}},asyncThunk:e}}function _fe({type:e,reducerName:t,createNotation:n},r,i){let a,o;if(`reducer`in r){if(n&&!yfe(r))throw Error(zk(17));a=r.reducer,o=r.prepare}else a=r;i.addCase(e,a).exposeCaseReducer(t,a).exposeAction(t,o?ik(e,o):ik(e))}function vfe(e){return e._reducerDefinitionType===`asyncThunk`}function yfe(e){return e._reducerDefinitionType===`reducerWithPrepare`}function bfe({type:e,reducerName:t},n,r,i){if(!i)throw Error(zk(18));let{payloadCreator:a,fulfilled:o,pending:s,rejected:c,settled:l,options:u}=n,d=i(e,a,u);r.exposeAction(t,d),o&&r.addCase(d.fulfilled,o),s&&r.addCase(d.pending,s),c&&r.addCase(d.rejected,c),l&&r.addMatcher(d.settled,l),r.exposeCaseReducer(t,{fulfilled:o||mk,pending:s||mk,rejected:c||mk,settled:l||mk})}function mk(){}var xfe=`task`,hk=`listener`,gk=`completed`,_k=`cancelled`,Sfe=`task-${_k}`,Cfe=`task-${gk}`,vk=`${hk}-${_k}`,wfe=`${hk}-${gk}`,yk=class{constructor(e){this.code=e,this.message=`${xfe} ${_k} (reason: ${e})`}name=`TaskAbortError`;message},bk=(e,t)=>{if(typeof e!=`function`)throw TypeError(zk(32))},xk=()=>{},Sk=(e,t=xk)=>(e.catch(t),e),Ck=(e,t)=>(e.addEventListener(`abort`,t,{once:!0}),()=>e.removeEventListener(`abort`,t)),wk=e=>{if(e.aborted)throw new yk(e.reason)};function Tk(e,t){let n=xk;return new Promise((r,i)=>{let a=()=>i(new yk(e.reason));if(e.aborted){a();return}n=Ck(e,a),t.finally(()=>n()).then(r,i)}).finally(()=>{n=xk})}var Tfe=async(e,t)=>{try{return await Promise.resolve(),{status:`ok`,value:await e()}}catch(e){return{status:e instanceof yk?`cancelled`:`rejected`,error:e}}finally{t?.()}},Ek=e=>t=>Sk(Tk(e,t).then(t=>(wk(e),t))),Dk=e=>{let t=Ek(e);return e=>t(new Promise(t=>setTimeout(t,e)))},{assign:Ok}=Object,kk={},Ak=`listenerMiddleware`,Efe=(e,t)=>{let n=t=>Ck(e,()=>t.abort(e.reason));return(r,i)=>{bk(r,`taskExecutor`);let a=new AbortController;n(a);let o=Tfe(async()=>{wk(e),wk(a.signal);let t=await r({pause:Ek(a.signal),delay:Dk(a.signal),signal:a.signal});return wk(a.signal),t},()=>a.abort(Cfe));return i?.autoJoin&&t.push(o.catch(xk)),{result:Ek(e)(o),cancel(){a.abort(Sfe)}}}},Dfe=(e,t)=>{let n=async(n,r)=>{wk(t);let i=()=>{},a=[new Promise((t,r)=>{let a=e({predicate:n,effect:(e,n)=>{n.unsubscribe(),t([e,n.getState(),n.getOriginalState()])}});i=()=>{a(),r()}})];r!=null&&a.push(new Promise(e=>setTimeout(e,r,null)));try{let e=await Tk(t,Promise.race(a));return wk(t),e}finally{i()}};return(e,t)=>Sk(n(e,t))},jk=e=>{let{type:t,actionCreator:n,matcher:r,predicate:i,effect:a}=e;if(t)i=ik(t).match;else if(n)t=n.type,i=n.match;else if(r)i=r;else if(!i)throw Error(zk(21));return bk(a,`options.listener`),{predicate:i,type:t,effect:a}},Mk=Ok(e=>{let{type:t,predicate:n,effect:r}=jk(e);return{id:dfe(),effect:r,type:t,predicate:n,pending:new Set,unsubscribe:()=>{throw Error(zk(22))}}},{withTypes:()=>Mk}),Nk=(e,t)=>{let{type:n,effect:r,predicate:i}=jk(t);return Array.from(e.values()).find(e=>(typeof n==`string`?e.type===n:e.predicate===i)&&e.effect===r)},Pk=e=>{e.pending.forEach(e=>{e.abort(vk)})},Ofe=(e,t)=>()=>{for(let e of t.keys())Pk(e);e.clear()},Fk=(e,t,n)=>{try{e(t,n)}catch(e){setTimeout(()=>{throw e},0)}},Ik=Ok(ik(`${Ak}/add`),{withTypes:()=>Ik}),kfe=ik(`${Ak}/removeAll`),Lk=Ok(ik(`${Ak}/remove`),{withTypes:()=>Lk}),Afe=(...e)=>{console.error(`${Ak}/error`,...e)},Rk=(e={})=>{let t=new Map,n=new Map,r=e=>{let t=n.get(e)??0;n.set(e,t+1)},i=e=>{let t=n.get(e)??1;t===1?n.delete(e):n.set(e,t-1)},{extra:a,onError:o=Afe}=e;bk(o,`onError`);let s=e=>(e.unsubscribe=()=>t.delete(e.id),t.set(e.id,e),t=>{e.unsubscribe(),t?.cancelActive&&Pk(e)}),c=e=>s(Nk(t,e)??Mk(e));Ok(c,{withTypes:()=>c});let l=e=>{let n=Nk(t,e);return n&&(n.unsubscribe(),e.cancelActive&&Pk(n)),!!n};Ok(l,{withTypes:()=>l});let u=async(e,n,s,l)=>{let u=new AbortController,d=Dfe(c,u.signal),f=[];try{e.pending.add(u),r(e),await Promise.resolve(e.effect(n,Ok({},s,{getOriginalState:l,condition:(e,t)=>d(e,t).then(Boolean),take:d,delay:Dk(u.signal),pause:Ek(u.signal),extra:a,signal:u.signal,fork:Efe(u.signal,f),unsubscribe:e.unsubscribe,subscribe:()=>{t.set(e.id,e)},cancelActiveListeners:()=>{e.pending.forEach((e,t,n)=>{e!==u&&(e.abort(vk),n.delete(e))})},cancel:()=>{u.abort(vk),e.pending.delete(u)},throwIfCancelled:()=>{wk(u.signal)}})))}catch(e){e instanceof yk||Fk(o,e,{raisedBy:`effect`})}finally{await Promise.all(f),u.abort(wfe),i(e),e.pending.delete(u)}},d=Ofe(t,n);return{middleware:e=>n=>r=>{if(!JD(r))return n(r);if(Ik.match(r))return c(r.payload);if(kfe.match(r)){d();return}if(Lk.match(r))return l(r.payload);let i=e.getState(),a=()=>{if(i===kk)throw Error(zk(23));return i},s;try{if(s=n(r),t.size>0){let n=e.getState(),s=Array.from(t.values());for(let t of s){let s=!1;try{s=t.predicate(r,n,i)}catch(e){s=!1,Fk(o,e,{raisedBy:`predicate`})}s&&u(t,r,e,a)}}}finally{i=kk}return s},startListening:c,stopListening:l,clearListeners:d}};function zk(e){return`Minified Redux Toolkit error #${e}; visit https://redux-toolkit.js.org/Errors?code=${e} for the full message or use the non-minified dev environment for full errors. `}var Bk=pk({name:`chartLayout`,initialState:{layoutType:`horizontal`,width:0,height:0,margin:{top:5,right:5,bottom:5,left:5},scale:1},reducers:{setLayout(e,t){e.layoutType=t.payload},setChartSize(e,t){e.width=t.payload.width,e.height=t.payload.height},setMargin(e,t){e.margin.top=t.payload.top??0,e.margin.right=t.payload.right??0,e.margin.bottom=t.payload.bottom??0,e.margin.left=t.payload.left??0},setScale(e,t){e.scale=t.payload}}}),{setMargin:jfe,setLayout:Mfe,setChartSize:Nfe,setScale:Pfe}=Bk.actions,Ffe=Bk.reducer;function Vk(e,t,n){return Array.isArray(e)&&e&&t+n!==0?e.slice(t,n+1):e}function Hk(e){return Number.isFinite(e)}function Uk(e){return typeof e==`number`&&e>0&&Number.isFinite(e)}function Wk(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 Gk(e){for(var t=1;t{if(t&&n){var{width:r,height:i}=n,{align:a,verticalAlign:o,layout:s}=t;if((s===`vertical`||s===`horizontal`&&o===`middle`)&&a!==`center`&&HE(e[a]))return Gk(Gk({},e),{},{[a]:e[a]+(r||0)});if((s===`horizontal`||s===`vertical`&&a===`center`)&&o!==`middle`&&HE(e[o]))return Gk(Gk({},e),{},{[o]:e[o]+(i||0)})}return e},qk=(e,t)=>e===`horizontal`&&t===`xAxis`||e===`vertical`&&t===`yAxis`||e===`centric`&&t===`angleAxis`||e===`radial`&&t===`radiusAxis`,Jk=(e,t,n,r)=>{if(r)return e.map(e=>e.coordinate);var i,a,o=e.map(e=>(e.coordinate===t&&(i=!0),e.coordinate===n&&(a=!0),e.coordinate));return i||o.push(t),a||o.push(n),o},Yk=(e,t,n)=>{if(!e)return null;var{duplicateDomain:r,type:i,range:a,scale:o,realScaleType:s,isCategorical:c,categoricalDomain:l,tickCount:u,ticks:d,niceTicks:f,axisType:p}=e;if(!o)return null;var m=s===`scaleBand`&&o.bandwidth?o.bandwidth()/2:2,h=(t||n)&&i===`category`&&o.bandwidth?o.bandwidth()/m:0;return h=p===`angleAxis`&&a&&a.length>=2?zE(a[0]-a[1])*2*h:h,t&&(d||f)?(d||f||[]).map((e,t)=>{var n=r?r.indexOf(e):e,i=o.map(n);return Hk(i)?{coordinate:i+h,value:e,offset:h,index:t}:null}).filter(ZE):c&&l?l.map((e,t)=>{var n=o.map(e);return Hk(n)?{coordinate:n+h,value:e,index:t,offset:h}:null}).filter(ZE):o.ticks&&!n&&u!=null?o.ticks(u).map((e,t)=>{var n=o.map(e);return Hk(n)?{coordinate:n+h,value:e,index:t,offset:h}:null}).filter(ZE):o.domain().map((e,t)=>{var n=o.map(e);return Hk(n)?{coordinate:n+h,value:r?r[e]:e,index:t,offset:h}:null}).filter(ZE)},Bfe=(e,t)=>{if(!t||t.length!==2||!HE(t[0])||!HE(t[1]))return e;var n=Math.min(t[0],t[1]),r=Math.max(t[0],t[1]),i=[e[0],e[1]];return(!HE(e[0])||e[0]r)&&(i[1]=r),i[0]>r&&(i[0]=r),i[1]{var t=e.length;if(!(t<=0)){var n=e[0]?.length;if(!(n==null||n<=0))for(var r=0;r=0?(s[0]=i,i+=u,s[1]=i):(s[0]=a,a+=u,s[1]=a)}}}},expand:Sue,none:AE,silhouette:Cue,wiggle:wue,positive:e=>{var t=e.length;if(!(t<=0)){var n=e[0]?.length;if(!(n==null||n<=0))for(var r=0;r=0?(o[0]=i,i+=s,o[1]=i):(o[0]=0,o[1]=0)}}}}},Hfe=(e,t,n)=>{var r=Vfe[n]??AE,i=xue().keys(t).value((e,t)=>Number(Kk(e,t,0))).order(jE).offset(r)(e);return i.forEach((n,r)=>{n.forEach((n,i)=>{var a=Kk(e[i],t[r],0);Array.isArray(a)&&a.length===2&&HE(a[0])&&HE(a[1])&&(n[0]=a[0],n[1]=a[1])})}),i};function Xk(e){return e==null?void 0:String(e)}function Zk(e){var{axis:t,ticks:n,bandSize:r,entry:i,index:a,dataKey:o}=e;if(t.type===`category`){if(!t.allowDuplicatedCategory&&t.dataKey&&!YE(i[t.dataKey])){var s=JE(n,`value`,i[t.dataKey]);if(s)return s.coordinate+r/2}return n!=null&&n[a]?n[a].coordinate+r/2:null}var c=Kk(i,YE(o)?t.dataKey:o),l=t.scale.map(c);return HE(l)?l:null}var Qk=e=>{var{axis:t,ticks:n,offset:r,bandSize:i,entry:a,index:o}=e;if(t.type===`category`)return n[o]?n[o].coordinate+r:null;var s=Kk(a,t.dataKey,t.scale.domain()[o]);if(YE(s))return null;var c=t.scale.map(s);return HE(c)?c-i/2+r:null},Ufe=e=>{var{numericAxis:t}=e,n=t.scale.domain();if(t.type===`number`){var r=Math.min(n[0],n[1]),i=Math.max(n[0],n[1]);return r<=0&&i>=0?0:i<0?i:r}return n[0]},Wfe=e=>{var t=e.flat(2).filter(HE);return[Math.min(...t),Math.max(...t)]},Gfe=e=>[e[0]===1/0?0:e[0],e[1]===-1/0?0:e[1]],Kfe=(e,t,n)=>{if(e!=null)return Gfe(Object.keys(e).reduce((r,i)=>{var a=e[i];if(!a)return r;var{stackedData:o}=a,s=o.reduce((e,r)=>{var i=Wfe(Vk(r,t,n));return!Hk(i[0])||!Hk(i[1])?e:[Math.min(e[0],i[0]),Math.max(e[1],i[1])]},[1/0,-1/0]);return[Math.min(s[0],r[0]),Math.max(s[1],r[1])]},[1/0,-1/0]))},$k=/^dataMin[\s]*-[\s]*([0-9]+([.]{1}[0-9]+){0,1})$/,eA=/^dataMax[\s]*\+[\s]*([0-9]+([.]{1}[0-9]+){0,1})$/,tA=(e,t,n)=>{if(e&&e.scale&&e.scale.bandwidth){var r=e.scale.bandwidth();if(!n||r>0)return r}if(e&&t&&t.length>=2){for(var i=(0,ID.default)(t,e=>e.coordinate),a=1/0,o=1,s=i.length;o{if(t===`horizontal`)return e.chartX;if(t===`vertical`)return e.chartY},Jfe=(e,t)=>t===`centric`?e.angle:e.radius,iA=e=>e.layout.width,aA=e=>e.layout.height,Yfe=e=>e.layout.scale,oA=e=>e.layout.margin,sA=ND(e=>e.cartesianAxis.xAxis,e=>Object.values(e)),cA=ND(e=>e.cartesianAxis.yAxis,e=>Object.values(e)),lA=`data-recharts-item-index`,Xfe=`data-recharts-item-id`;function uA(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 dA(e){for(var t=1;te.brush.height;function tpe(e){return cA(e).reduce((e,t)=>t.orientation===`left`&&!t.mirror&&!t.hide?e+(typeof t.width==`number`?t.width:60):e,0)}function npe(e){return cA(e).reduce((e,t)=>t.orientation===`right`&&!t.mirror&&!t.hide?e+(typeof t.width==`number`?t.width:60):e,0)}function rpe(e){return sA(e).reduce((e,t)=>t.orientation===`top`&&!t.mirror&&!t.hide?e+t.height:e,0)}function ipe(e){return sA(e).reduce((e,t)=>t.orientation===`bottom`&&!t.mirror&&!t.hide?e+t.height:e,0)}var fA=ND([iA,aA,oA,epe,tpe,npe,rpe,ipe,LD,Lde],(e,t,n,r,i,a,o,s,c,l)=>{var u={left:(n.left||0)+i,right:(n.right||0)+a},d=dA(dA({},{top:(n.top||0)+o,bottom:(n.bottom||0)+s}),u),f=d.bottom;d.bottom+=r,d=zfe(d,c,l);var p=e-d.left-d.right,m=t-d.top-d.bottom;return dA(dA({brushBottom:f},d),{},{width:Math.max(p,0),height:Math.max(m,0)})}),ape=ND(fA,e=>({x:e.left,y:e.top,width:e.width,height:e.height})),pA=ND(iA,aA,(e,t)=>({x:0,y:0,width:e,height:t})),ope=(0,y.createContext)(null),mA=()=>(0,y.useContext)(ope)!=null,hA=e=>e.brush,gA=ND([hA,fA,oA],(e,t,n)=>({height:e.height,x:HE(e.x)?e.x:t.left,y:HE(e.y)?e.y:t.top+t.height+t.brushBottom-(n?.bottom||0),width:HE(e.width)?e.width:t.width})),spe=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e,t,{signal:n,edges:r}={}){let i,a=null,o=r!=null&&r.includes(`leading`),s=r==null||r.includes(`trailing`),c=()=>{a!==null&&(e.apply(i,a),i=void 0,a=null)},l=()=>{s&&c(),p()},u=null,d=()=>{u!=null&&clearTimeout(u),u=setTimeout(()=>{u=null,l()},t)},f=()=>{u!==null&&(clearTimeout(u),u=null)},p=()=>{f(),i=void 0,a=null},m=()=>{c()},h=function(...e){if(n?.aborted)return;i=this,a=e;let t=u==null;d(),o&&t&&c()};return h.schedule=d,h.cancel=p,h.flush=m,n?.addEventListener(`abort`,p,{once:!0}),h}e.debounce=t})),cpe=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=spe();function n(e,n=0,r={}){typeof r!=`object`&&(r={});let{leading:i=!1,trailing:a=!0,maxWait:o}=r,s=[,,];i&&(s[0]=`leading`),a&&(s[1]=`trailing`);let c,l=null,u=t.debounce(function(...t){c=e.apply(this,t),l=null},n,{edges:s}),d=function(...t){return o!=null&&(l===null&&(l=Date.now()),Date.now()-l>=o)?(c=e.apply(this,t),l=Date.now(),u.cancel(),u.schedule(),c):(u.apply(this,t),c)};return d.cancel=u.cancel,d.flush=()=>(u.flush(),c),d}e.debounce=n})),lpe=o((e=>{Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=cpe();function n(e,n=0,r={}){let{leading:i=!0,trailing:a=!0}=r;return t.debounce(e,n,{leading:i,maxWait:n,trailing:a})}e.throttle=n})),upe=o(((e,t)=>{t.exports=lpe().throttle})),dpe=!0,_A=function(e,t){var n=[...arguments].slice(2);if(dpe&&typeof console<`u`&&console.warn&&(t===void 0&&console.warn(`LogUtils requires an error message argument`),!e))if(t===void 0)console.warn(`Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.`);else{var r=0;console.warn(t.replace(/%s/g,()=>n[r++]))}},vA={width:`100%`,height:`100%`,debounce:0,minWidth:0,initialDimension:{width:-1,height:-1}},yA=(e,t,n)=>{var{width:r=vA.width,height:i=vA.height,aspect:a,maxHeight:o}=n,s=VE(r)?e:Number(r),c=VE(i)?t:Number(i);return a&&a>0&&(s?c=s/a:c&&(s=c*a),o&&c!=null&&c>o&&(c=o)),{calculatedWidth:s,calculatedHeight:c}},fpe={width:0,height:0,overflow:`visible`},ppe={width:0,overflowX:`visible`},mpe={height:0,overflowY:`visible`},hpe={},gpe=e=>{var{width:t,height:n}=e,r=VE(t),i=VE(n);return r&&i?fpe:r?ppe:i?mpe:hpe};function _pe(e){var{width:t,height:n,aspect:r}=e,i=t,a=n;return i===void 0&&a===void 0?(i=vA.width,a=vA.height):i===void 0?i=r&&r>0?void 0:vA.width:a===void 0&&(a=r&&r>0?void 0:vA.height),{width:i,height:a}}var vpe=l(upe());function bA(){return bA=Object.assign?Object.assign.bind():function(e){for(var t=1;t({width:n,height:r}),[n,r]);return Spe(i)?y.createElement(CA.Provider,{value:i},t):null}var TA=()=>(0,y.useContext)(CA),Cpe=(0,y.forwardRef)((e,t)=>{var{aspect:n,initialDimension:r=vA.initialDimension,width:i,height:a,minWidth:o=vA.minWidth,minHeight:s,maxHeight:c,children:l,debounce:u=vA.debounce,id:d,className:f,onResize:p,style:m={}}=e,h=(0,y.useRef)(null),g=(0,y.useRef)();g.current=p,(0,y.useImperativeHandle)(t,()=>h.current);var[_,v]=(0,y.useState)({containerWidth:r.width,containerHeight:r.height}),b=(0,y.useCallback)((e,t)=>{v(n=>{var r=Math.round(e),i=Math.round(t);return n.containerWidth===r&&n.containerHeight===i?n:{containerWidth:r,containerHeight:i}})},[]);(0,y.useEffect)(()=>{if(h.current==null||typeof ResizeObserver>`u`)return QE;var e=e=>{var t,n=e[0];if(n!=null){var{width:r,height:i}=n.contentRect;b(r,i),(t=g.current)==null||t.call(g,r,i)}};u>0&&(e=(0,vpe.default)(e,u,{trailing:!0,leading:!1}));var t=new ResizeObserver(e),{width:n,height:r}=h.current.getBoundingClientRect();return b(n,r),t.observe(h.current),()=>{t.disconnect()}},[b,u]);var{containerWidth:x,containerHeight:S}=_;_A(!n||n>0,`The aspect(%s) must be greater than zero.`,n);var{calculatedWidth:C,calculatedHeight:w}=yA(x,S,{width:i,height:a,aspect:n,maxHeight:c});return _A(C!=null&&C>0||w!=null&&w>0,`The width(%s) and height(%s) of chart should be greater than 0, @@ -8528,13 +8528,13 @@ void main() { absolute left-0 z-50 ${u===`top`?`bottom-full mb-2`:`top-full mt-2`} animate-in fade-in-0 zoom-in-95 duration-150 - `,style:{maxWidth:`calc(100vw - 24px)`},onMouseEnter:w,onMouseLeave:T,children:(0,K.jsxs)(`div`,{className:`w-52 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl overflow-hidden backdrop-blur-sm p-2.5 space-y-2`,children:[(0,K.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:n}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[10px] tracking-wide text-bambu-gray font-medium shrink-0`,children:s(`printers.amsPopup.serialNumber`)}),(0,K.jsx)(`span`,{className:`text-[10px] text-white font-mono truncate`,children:e.serial_number||`—`})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[10px] tracking-wide text-bambu-gray font-medium shrink-0`,children:s(`printers.amsPopup.firmwareVersion`)}),(0,K.jsx)(`span`,{className:`text-[10px] text-white font-mono truncate`,children:e.sw_ver||`—`})]}),(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[10px] text-bambu-gray font-medium shrink-0`,children:s(`printers.amsPopup.friendlyName`)}),(0,K.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary/50`})]}),(0,K.jsx)(`input`,{type:`text`,value:f,onChange:e=>i&&p(e.target.value),onKeyDown:e=>e.key===`Enter`&&E(),onFocus:()=>b(!0),onBlur:()=>{b(!1),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>l(!1),200)},placeholder:i?s(`printers.amsPopup.friendlyNamePlaceholder`):r?.[e.id]||`—`,disabled:!i,title:i?void 0:s(`printers.amsPopup.noEditPermission`),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1 text-xs text-white placeholder-bambu-gray/60 focus:outline-none focus:border-bambu-green disabled:opacity-50 disabled:cursor-not-allowed`,maxLength:100}),i&&(0,K.jsxs)(`div`,{className:`space-y-1`,children:[g&&(0,K.jsx)(`p`,{className:`text-[10px] text-red-700 dark:text-red-400 break-words`,children:g}),(0,K.jsxs)(`div`,{className:`flex gap-1 justify-end`,children:[(0,K.jsx)(`button`,{onClick:E,disabled:m,className:`px-2 py-0.5 text-[10px] bg-bambu-green text-white rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:s(`printers.amsPopup.save`)}),r?.[e.id]&&(0,K.jsx)(`button`,{onClick:async()=>{if(i){h(!0),_(null);try{await Q.deleteAmsLabel(t,e.id,e.serial_number),a(),l(!1)}catch(e){_(e instanceof Error?e.message:String(e))}finally{h(!1)}}},disabled:m,className:`px-2 py-0.5 text-[10px] bg-bambu-dark-tertiary text-bambu-gray rounded hover:bg-bambu-dark-tertiary/70 disabled:opacity-50`,children:s(`printers.amsPopup.clear`)})]})]})]})]})})]})}var MW={PLA:{n3f:45,n3s:45,n3f_hours:12,n3s_hours:12},PETG:{n3f:65,n3s:65,n3f_hours:12,n3s_hours:12},TPU:{n3f:65,n3s:75,n3f_hours:12,n3s_hours:18},ABS:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},ASA:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:12},PC:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PVA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:18}};function NW({printer:e,hideIfDisconnected:t,maintenanceInfo:n,viewMode:r=`expanded`,cardSize:i=2,amsThresholds:a,spoolmanEnabled:o=!1,linkedSpools:s,spoolmanUrl:c,spoolmanSyncMode:l,onGetAssignment:u,onUnassignSpool:d,spoolmanSpools:f,spoolmanSlotAssignments:p,spoolmanLoading:m=!1,onUnassignSpoolmanSpool:h,timeFormat:g=`system`,cameraViewMode:_=`window`,onOpenEmbeddedCamera:v,checkPrinterFirmware:b=!0,dryingPresets:x=MW,requirePlateClear:S=!1,selectionMode:C=!1,isSelected:w=!1,onToggleSelect:T,onOpenCompactCard:E,nozzleTempPresets:D=Hp,bedTempPresets:O=Up,chamberTempPresets:k=Wp,fanSpeedPresets:A=Gp}){let{t:j}=W(),M=oo(),N=ir(),{showToast:P}=Pd(),{hasPermission:F}=bd(),[I,L]=(0,y.useState)(!1),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(!0),[ee,te]=(0,y.useState)(!1),[ne,re]=(0,y.useState)(!1),[ie,H]=(0,y.useState)(!1),[ae,oe]=(0,y.useState)(!1),[U,se]=(0,y.useState)(!1),[ce,le]=(0,y.useState)(null),[ue,de]=(0,y.useState)(!1),[fe,pe]=(0,y.useState)(!1),[me,he]=(0,y.useState)(!1),[ge,_e]=(0,y.useState)(!1),[ve,ye]=(0,y.useState)(null),[be,xe]=(0,y.useState)(null),[Se,Ce]=(0,y.useState)(null),[we,Te]=(0,y.useState)(null),[Ee,De]=(0,y.useState)(10),[Oe,ke]=(0,y.useState)(!1),[Ae,je]=(0,y.useState)(!1),[Me,Ne]=(0,y.useState)(!1),[Pe,Fe]=(0,y.useState)(!1),[Ie,Le]=(0,y.useState)(!1),Re=(0,y.useCallback)(()=>Fe(!1),[]),[ze,Be]=(0,y.useState)(null),[Ve,He]=(0,y.useState)(null),[Ue,We]=(0,y.useState)(`n3f`),[Ge,Ke]=(0,y.useState)(`PLA`),[qe,Je]=(0,y.useState)(50),[Ye,Xe]=(0,y.useState)(4),[Ze,Qe]=(0,y.useState)(!1),[$e,et]=(0,y.useState)(null),[tt,nt]=(0,y.useState)(null),[rt,it]=(0,y.useState)(!1),[at,ot]=(0,y.useState)(!1),st=(0,y.useRef)(null),ct=(0,y.useRef)(0),[lt,ut]=(0,y.useState)(null),[dt,ft]=(0,y.useState)(null),[pt,mt]=(0,y.useState)(null),[ht,gt]=(0,y.useState)(null),[_t,vt]=(0,y.useState)(null),[yt,bt]=(0,y.useState)(!1),[xt,St]=(0,y.useState)(null),[Ct,wt]=(0,y.useState)(!1),[Tt,Et]=(0,y.useState)(!1),[Dt,Ot]=(0,y.useState)(null),[kt,At]=(0,y.useState)(!1),[jt,Mt]=(0,y.useState)(!1),{data:G}=q({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id),refetchInterval:3e4}),{data:Nt}=q({queryKey:[`firmwareUpdate`,e.id],queryFn:()=>pd.checkPrinterUpdate(e.id),staleTime:300*1e3,refetchInterval:300*1e3,enabled:b&&F(`firmware:read`)}),Pt=(0,y.useMemo)(()=>{let e=new Set;if(G?.ams)for(let t of G.ams)for(let n of t.tray||[])n.tray_info_idx&&e.add(n.tray_info_idx);for(let t of G?.vt_tray??[])t.tray_info_idx&&e.add(t.tray_info_idx);if(G?.nozzle_rack)for(let t of G.nozzle_rack)t.filament_id&&e.add(t.filament_id);return Array.from(e)},[G?.ams,G?.vt_tray,G?.nozzle_rack]),Ft=(0,y.useMemo)(()=>{let e=new Set;if(G?.ams)for(let t of G.ams)for(let n of t.tray||[])n.tray_type&&e.add(n.tray_type.toUpperCase());for(let t of G?.vt_tray??[])t.tray_type&&e.add(t.tray_type.toUpperCase());return e},[G?.ams,G?.vt_tray]),It=(0,y.useMemo)(()=>{let e=new Set;if(G?.ams){for(let t of G.ams)for(let n of t.tray||[])if(n.tray_type&&n.tray_color){let t=n.tray_color.replace(`#`,``).toLowerCase().slice(0,6);e.add(`${n.tray_type.toUpperCase()}:${t}`)}}for(let t of G?.vt_tray??[])if(t.tray_type&&t.tray_color){let n=t.tray_color.replace(`#`,``).toLowerCase().slice(0,6);e.add(`${t.tray_type.toUpperCase()}:${n}`)}return e},[G?.ams,G?.vt_tray]),{data:Lt}=q({queryKey:[`filamentInfo`,Pt],queryFn:()=>Q.getFilamentInfo(Pt),enabled:Pt.length>0,staleTime:300*1e3}),{data:Rt}=q({queryKey:[`slotPresets`,e.id],queryFn:()=>Q.getSlotPresets(e.id),staleTime:120*1e3}),zt=G?.state===`RUNNING`||G?.state===`PAUSE`?G?.current_archive_id??null:null,{data:Bt}=q({queryKey:[`archive-plates`,zt],queryFn:()=>Q.getArchivePlates(zt),enabled:zt!=null,staleTime:300*1e3}),Vt=!Bt?.is_multi_plate||G?.current_plate_id==null?null:Bt.plates.find(e=>e.index===G.current_plate_id)?.name||j(`printers.plateNumber`,`Plate {{number}}`,{number:G.current_plate_id}),{data:Ht,refetch:Ut}=q({queryKey:[`amsLabels`,e.id],queryFn:()=>Q.getAmsLabels(e.id),staleTime:300*1e3}),[Wt,Gt]=(0,y.useState)(null);(0,y.useEffect)(()=>{G?.wifi_signal!=null&&Gt(G.wifi_signal)},[G?.wifi_signal]);let Kt=G?.wifi_signal??Wt,qt=(0,y.useRef)(void 0);(0,y.useEffect)(()=>{G?.connected!==void 0&&(qt.current=G.connected)},[G?.connected]);let Jt=G?.connected??qt.current,Yt=(0,y.useRef)({});(0,y.useEffect)(()=>{G?.ams_extruder_map&&Object.keys(G.ams_extruder_map).length>0&&(Yt.current=G.ams_extruder_map)},[G?.ams_extruder_map]);let Xt=G?.ams_extruder_map&&Object.keys(G.ams_extruder_map).length>0?G.ams_extruder_map:Yt.current,Zt=(0,y.useRef)([]);(0,y.useEffect)(()=>{G?.ams&&G.ams.length>0&&(Zt.current=G.ams)},[G?.ams]);let Qt=G?.ams&&G.ams.length>0?G.ams:Zt.current;(0,y.useEffect)(()=>{if(!tt)return;let e=Qt.find(e=>e.id===tt.amsId);e&&(e.dry_time>0||e.dry_status>0)&&nt(null)},[tt,Qt]),(0,y.useEffect)(()=>{if(!tt)return;let e=setTimeout(()=>{nt(null),P(j(`printers.drying.toastNotStarted`),`error`)},cAe);return()=>clearTimeout(e)},[tt,P,j]);let $t=(0,y.useRef)(void 0),en=G?.tray_now;en!==void 0&&en!==255?$t.current=en:en===255&&($t.current=void 0);let tn=en!==void 0&&en!==255?en:$t.current,nn=G?.expected_tray??null,rn=G?.previous_tray??null,an=e=>{if(e===null)return null;if(e===254)return j(`printers.expectedSlot.external`);if(e>=128&&e<=135)return Ht?.[e]||Uf(e,1);let t=Math.floor(e/4),n=e%4;return j(`printers.expectedSlot.label`,{ams:Ht?.[t]||Uf(t,4),slot:n+1})},on=G?.state===`PAUSE`?{expectedSlotLabel:an(nn),ranOutSlotLabel:an(rn)}:null,{data:sn}=q({queryKey:[`smartPlugByPrinter`,e.id],queryFn:()=>Q.getSmartPlugByPrinter(e.id)}),{data:cn}=q({queryKey:[`scriptPlugsByPrinter`,e.id],queryFn:()=>Q.getScriptPlugsByPrinter(e.id)}),{data:ln}=q({queryKey:[`smartPlugStatus`,sn?.id],queryFn:()=>sn?Q.getSmartPlugStatus(sn.id):null,enabled:!!sn,refetchInterval:1e4}),{data:un}=q({queryKey:[`queue`,e.id,`pending`],queryFn:()=>Q.getQueue(e.id,`pending`)}),dn=(0,y.useMemo)(()=>un?.length?DT(un,Ft,It).length:0,[un,Ft,It]),{data:fn}=q({queryKey:[`queue`,e.id,`printing`],queryFn:()=>Q.getQueue(e.id,`printing`),enabled:G?.state===`RUNNING`}),{data:pn}=q({queryKey:[`currentPrintUser`,e.id],queryFn:()=>Q.getCurrentPrintUser(e.id),enabled:G?.state===`RUNNING`}),mn=fn?.[0]?.created_by_username||pn?.username,{data:hn}=q({queryKey:[`archives`,e.id,`last`],queryFn:()=>Q.getArchives(e.id,1,0),enabled:G?.connected&&G?.state!==`RUNNING`}),gn=hn?.[0],_n=G?.state===`RUNNING`||G?.state===`PAUSE`,vn=S&&G?.awaiting_plate_clear===!0,yn=G?.connected&&vn&&!_n,bn=G?.current_print&&_n?see(G.subtask_name||G.current_print||null,G.gcode_file,j,Vt):null,[xn,Sn]=(0,y.useState)(null);(0,y.useEffect)(()=>{bn?Sn({name:bn,coverUrl:G?.cover_url??null}):vn||Sn(null)},[bn,vn,G?.cover_url]);let Cn=!S||!G?.connected?null:_n?{label:j(`printers.plateStatus.inUse`),className:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`}:G.awaiting_plate_clear?{label:j(`printers.plateStatus.notCleared`),className:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`}:{label:j(`printers.plateStatus.cleared`),className:`bg-status-ok/20 text-status-ok`},wn=Cn?(0,K.jsx)(`span`,{className:`inline-flex flex-shrink-0 items-center rounded-full px-2 py-0.5 text-[10px] font-medium ${Cn.className}`,children:Cn.label}):null,Tn=t&&Jt===!1,En=J({mutationFn:t=>Q.deletePrinter(e.id,t.deleteArchives),onSuccess:()=>{M.invalidateQueries({queryKey:[`printers`]}),M.invalidateQueries({queryKey:[`archives`]}),M.invalidateQueries({queryKey:[`maintenanceOverview`]})},onError:e=>P(e.message||j(`printers.toast.failedToDelete`),`error`)}),Dn=J({mutationFn:()=>Q.connectPrinter(e.id),onSuccess:()=>{M.invalidateQueries({queryKey:[`printerStatus`,e.id]})}}),On=J({mutationFn:()=>Q.refreshPrinterStatus(e.id),onSuccess:()=>{M.invalidateQueries({queryKey:[`printerStatus`,e.id]}),P(j(`printers.forceRefreshSuccess`),`success`)},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),kn=J({mutationFn:e=>Q.unlinkSpool(e),onSuccess:e=>{P(j(`spoolman.unlinkSuccess`)||e?.message,`success`),M.invalidateQueries({queryKey:[`linked-spools`]}),M.invalidateQueries({queryKey:[`unlinked-spools`]}),M.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})},onError:e=>{P(e.message||j(`spoolman.unlinkFailed`),`error`)}}),An=J({mutationFn:({amsId:t,temp:n,duration:r,filament:i,rotateTray:a})=>Q.startDrying(e.id,t,n,r,i,a),onSuccess:(t,{amsId:n})=>{He(null),nt({amsId:n}),P(j(`printers.drying.toastCommandSent`),`success`),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),jn=J({mutationFn:t=>Q.stopDrying(e.id,t),onSuccess:()=>{nt(null),P(j(`printers.drying.toastStopped`),`success`),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Mn=J({mutationFn:t=>Q.setAmsFilamentBackup(e.id,t),onSuccess:(t,n)=>{M.invalidateQueries({queryKey:[`printerStatus`,e.id]}),M.invalidateQueries({queryKey:[`printer-status`,e.id]}),P(j(n?`printers.amsBackup.toastEnabled`:`printers.amsBackup.toastDisabled`),`success`)},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Nn=J({mutationFn:e=>sn?Q.controlSmartPlug(sn.id,e):Promise.reject(`No plug`),onSuccess:()=>{M.invalidateQueries({queryKey:[`smartPlugStatus`,sn?.id]})}}),Pn=J({mutationFn:e=>sn?Q.updateSmartPlug(sn.id,{auto_off:e}):Promise.reject(`No plug`),onSuccess:()=>{M.invalidateQueries({queryKey:[`smartPlugByPrinter`,e.id]}),M.invalidateQueries({queryKey:[`smart-plugs`]})}}),Fn=J({mutationFn:({id:e,action:t})=>Q.controlSmartPlug(e,t),onSuccess:()=>{P(j(`printers.toast.scriptTriggered`))},onError:e=>P(e.message||j(`printers.toast.failedToRunScript`),`error`)}),In=J({mutationFn:()=>Q.stopPrint(e.id),onSuccess:()=>{P(j(`printers.toast.printStopped`)),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToStopPrint`),`error`)}),Ln=J({mutationFn:()=>Q.pausePrint(e.id),onSuccess:()=>{P(j(`printers.toast.printPaused`)),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToPausePrint`),`error`)}),Rn=J({mutationFn:()=>Q.resumePrint(e.id),onSuccess:()=>{P(j(`printers.toast.printResumed`)),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToResumePrint`),`error`)}),zn=J({mutationFn:()=>Q.clearPlate(e.id),onSuccess:()=>{P(j(`queue.clearPlateSuccess`)),M.setQueryData([`printerStatus`,e.id],e=>e&&{...e,awaiting_plate_clear:!1}),M.invalidateQueries({queryKey:[`printerStatus`,e.id]}),M.invalidateQueries({queryKey:[`queue`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Bn=J({mutationFn:({target:t,nozzle:n})=>Q.setNozzleTemperature(e.id,t,n),onSuccess:t=>{Te(null),P(t.message),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Vn=J({mutationFn:t=>Q.setBedTemperature(e.id,t),onSuccess:t=>{Te(null),P(t.message),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Hn=J({mutationFn:t=>Q.setChamberTemperature(e.id,t),onSuccess:t=>{Te(null),P(t.message),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Un=J({mutationFn:({fan:t,speed:n})=>Q.setFanSpeed(e.id,t,n),onMutate:async({fan:t,speed:n})=>{await M.cancelQueries({queryKey:[`printerStatus`,e.id]});let r=M.getQueryData([`printerStatus`,e.id]),i={part:`cooling_fan_speed`,aux:`big_fan1_speed`,chamber:`big_fan2_speed`}[t];return M.setQueryData([`printerStatus`,e.id],e=>e&&{...e,[i]:n}),{previousStatus:r}},onSuccess:t=>{Te(null),P(t.message),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:(t,n,r)=>{r?.previousStatus&&M.setQueryData([`printerStatus`,e.id],r.previousStatus),P(t.message||j(`printers.toast.failedToSendCommand`),`error`)}}),Wn=J({mutationFn:t=>Q.selectExtruder(e.id,t),onMutate:async t=>{await M.cancelQueries({queryKey:[`printerStatus`,e.id]});let n=M.getQueryData([`printerStatus`,e.id]);return M.setQueryData([`printerStatus`,e.id],e=>e&&{...e,active_extruder:t}),{previousStatus:n}},onSuccess:t=>{Te(null),P(t.message),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:(t,n,r)=>{r?.previousStatus&&M.setQueryData([`printerStatus`,e.id],r.previousStatus),P(t.message||j(`printers.toast.failedToSendCommand`),`error`)}}),Gn=J({mutationFn:t=>Q.setChamberLight(e.id,t),onMutate:async t=>{await M.cancelQueries({queryKey:[`printerStatus`,e.id]});let n=M.getQueryData([`printerStatus`,e.id]);return M.setQueryData([`printerStatus`,e.id],e=>({...e,chamber_light:t})),{previousStatus:n}},onSuccess:(e,t)=>{P(`Chamber light ${t?`on`:`off`}`)},onError:(t,n,r)=>{r?.previousStatus&&M.setQueryData([`printerStatus`,e.id],r.previousStatus),P(t.message||j(`printers.toast.failedToControlChamberLight`),`error`)}}),Kn=J({mutationFn:t=>Q.setPrintSpeed(e.id,t),onMutate:async t=>{await M.cancelQueries({queryKey:[`printerStatus`,e.id]});let n=M.getQueryData([`printerStatus`,e.id]);return M.setQueryData([`printerStatus`,e.id],e=>({...e,speed_level:t})),{previousStatus:n}},onError:(t,n,r)=>{r?.previousStatus&&M.setQueryData([`printerStatus`,e.id],r.previousStatus),P(t.message||j(`printers.toast.failedToSetSpeed`),`error`)}}),qn=J({mutationFn:t=>Q.setAirductMode(e.id,t),onMutate:async t=>{await M.cancelQueries({queryKey:[`printerStatus`,e.id]});let n=M.getQueryData([`printerStatus`,e.id]);return M.setQueryData([`printerStatus`,e.id],e=>({...e,airduct_mode:t===`cooling`?0:1})),{previousStatus:n}},onError:(t,n,r)=>{r?.previousStatus&&M.setQueryData([`printerStatus`,e.id],r.previousStatus),P(t.message||j(`printers.toast.failedToSendCommand`),`error`)}}),Jn=J({mutationFn:({distance:t})=>Q.bedJog(e.id,t),onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Yn=J({mutationFn:({x:t,y:n})=>Q.xyJog(e.id,t,n),onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Xn=J({mutationFn:t=>Q.extruderJog(e.id,t),onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Zn=J({mutationFn:t=>Q.homeAxes(e.id,t),onSuccess:()=>{P(j(`printers.bedJog.homingStarted`))},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Qn=J({mutationFn:t=>Q.updatePrinter(e.id,{plate_detection_enabled:t}),onSuccess:()=>{M.invalidateQueries({queryKey:[`printers`]}),P(Qn.variables?j(`printers.toast.plateCheckEnabled`):j(`printers.toast.plateCheckDisabled`))},onError:e=>P(e.message||j(`printers.toast.failedToUpdateSetting`),`error`)}),$n=J({mutationFn:t=>Q.updatePrinter(e.id,{is_active:t}),onSuccess:(t,n)=>{M.invalidateQueries({queryKey:[`printers`]}),M.invalidateQueries({queryKey:[`printerStatus`,e.id]}),P(j(n?`printers.maintenance.toastExited`:`printers.maintenance.toastEntered`,{name:e.name}),`success`)},onError:e=>P(e.message||j(`printers.toast.failedToUpdateSetting`),`error`)}),[er,tr]=(0,y.useState)(!1),nr=()=>{G?.state===`RUNNING`||G?.state===`PAUSE`?tr(!0):$n.mutate(!1)},rr=(G?.state===`RUNNING`||G?.state===`PAUSE`)&&(G?.printable_objects_count??0)>=2,{data:ar}=q({queryKey:[`printableObjects`,e.id],queryFn:()=>Q.getPrintableObjects(e.id),enabled:Ae||rr,refetchInterval:Ae?5e3:rr?3e4:!1}),[or,sr]=(0,y.useState)(null),cr=(0,y.useRef)(!1),lr=(0,y.useRef)(null),ur=(0,y.useRef)(!1),dr=J({mutationFn:({amsId:t,slotId:n})=>Q.refreshAmsSlot(e.id,t,n),onMutate:({amsId:e,slotId:t})=>{lr.current&&clearTimeout(lr.current),cr.current=!1,ur.current=!1,sr({amsId:e,slotId:t}),setTimeout(()=>{ur.current=!0},2e3),lr.current=setTimeout(()=>{sr(null)},3e4)},onSuccess:e=>{P(e.message||j(`printers.toast.rfidRereadInitiated`))},onError:e=>{P(e.message||j(`printers.toast.failedToRereadRfid`),`error`),lr.current&&clearTimeout(lr.current),sr(null)}}),fr=J({mutationFn:({trayId:t})=>Q.loadAmsTray(e.id,t),onSuccess:e=>{P(e.message||j(`printers.toast.loadInitiated`))},onError:e=>{P(e.message||j(`printers.toast.failedToLoad`),`error`)}}),pr=J({mutationFn:()=>Q.unloadAms(e.id),onSuccess:e=>{P(e.message||j(`printers.toast.unloadInitiated`))},onError:e=>{P(e.message||j(`printers.toast.failedToUnload`),`error`)}}),[mr,hr]=(0,y.useState)(null),[gr,_r]=(0,y.useState)(null),vr=async()=>{try{hr(await Q.getPlateReferences(e.id))}catch{}},yr=()=>{Qn.mutate(!e.plate_detection_enabled)},br=async()=>{wt(!0),St(null);let t=G?.chamber_light===!1;Mt(t),t&&(await Q.setChamberLight(e.id,!0),await new Promise(e=>setTimeout(e,2500)));try{St(await Q.checkPlateEmpty(e.id,{includeDebugImage:!0})),vr()}catch(n){P(n instanceof Error?n.message:j(`printers.toast.failedToCheckPlate`),`error`),t&&(await Q.setChamberLight(e.id,!1),Mt(!1))}finally{wt(!1)}},xr=(0,y.useCallback)(async()=>{St(null),jt&&(await Q.setChamberLight(e.id,!1),Mt(!1))},[jt,e.id]),Sr=async t=>{Et(!0);try{let n=await Q.calibratePlateDetection(e.id,{label:t});n.success?(P(n.message||j(`printers.toast.calibrationSaved`),`success`),vr(),St(await Q.checkPlateEmpty(e.id,{includeDebugImage:!0}))):P(n.message||j(`printers.toast.calibrationFailed`),`error`)}catch(e){P(e instanceof Error?e.message:j(`printers.toast.calibrationFailed`),`error`)}finally{Et(!1)}},Cr=async(t,n)=>{try{await Q.updatePlateReferenceLabel(e.id,t,n),_r(null),vr()}catch(e){P(e instanceof Error?e.message:j(`printers.toast.failedToUpdateLabel`),`error`)}},wr=async t=>{try{await Q.deletePlateReference(e.id,t),P(j(`printers.toast.referenceDeleted`),`success`),vr(),St(await Q.checkPlateEmpty(e.id,{includeDebugImage:!0}))}catch(e){P(e instanceof Error?e.message:j(`printers.toast.failedToDeleteReference`),`error`)}},Tr=async()=>{if(Dt){At(!0);try{await Q.updatePrinter(e.id,{plate_detection_roi:Dt}),P(j(`printers.toast.detectionAreaSaved`),`success`),Ot(null),St(await Q.checkPlateEmpty(e.id,{includeDebugImage:!0}))}catch(e){P(e instanceof Error?e.message:j(`printers.toast.failedToSaveDetectionArea`),`error`)}finally{At(!1)}}};(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&xt&&xr()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[xt,xr]);let Er=(0,y.useRef)(null);if((0,y.useEffect)(()=>{if(!or)return;let e=G?.ams_status_main??0;return e!==0&&(cr.current=!0,Er.current&&=(clearTimeout(Er.current),null)),cr.current&&e===0&&(ur.current?(lr.current&&clearTimeout(lr.current),sr(null)):Er.current||=setTimeout(()=>{lr.current&&clearTimeout(lr.current),sr(null)},2e3)),()=>{Er.current&&clearTimeout(Er.current)}},[G?.ams_status_main,or]),(0,y.useEffect)(()=>{if(!I)return;let e=e=>{let t=e.target;st.current?.contains(t)||L(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[I]),Tn)return null;let Dr=()=>{switch(i){case 1:return`w-10 h-10`;case 2:return`w-14 h-14`;case 3:return`w-16 h-16`;case 4:return`w-20 h-20`;default:return`w-14 h-14`}},Or=()=>{switch(i){case 1:return`text-base truncate`;case 2:return`text-lg`;case 3:return`text-xl`;case 4:return`text-2xl`;default:return`text-lg`}},kr=()=>{switch(i){case 1:return`mb-2`;case 2:return`mb-4`;case 3:return`mb-5`;case 4:return`mb-6`;default:return`mb-4`}},Ar=Jt&&G?.state!==`RUNNING`&&G?.state!==`PAUSE`&&F(`printers:control`),jr=e=>{e.preventDefault(),ct.current++,ct.current===1&&it(!0)},Mr=e=>{e.preventDefault(),e.dataTransfer.dropEffect=Ar?`copy`:`none`},Nr=e=>{e.preventDefault(),ct.current--,ct.current===0&&it(!1)},Pr=async t=>{if(t.preventDefault(),ct.current=0,it(!1),!Ar)return;let n=Array.from(t.dataTransfer.files)[0];if(!n)return;let r=n.name.toLowerCase();if(!r.endsWith(`.gcode`)&&!r.includes(`.gcode.`)){P(j(`printers.dropNotPrintable`,`Only .gcode and .gcode.3mf files can be printed`),`error`);return}ot(!0);try{let t=await Q.uploadLibraryFile(n,null),r=t.metadata?.sliced_for_model,i=AW(e.model);if(r&&i&&r.toLowerCase()!==i.toLowerCase()){await Q.deleteLibraryFile(t.id).catch(()=>{}),P(j(`printers.incompatibleFile`,`This file was sliced for {{slicedFor}}, but this printer is a {{printerModel}}`,{slicedFor:r,printerModel:i}),`error`);return}Be({id:t.id,filename:t.filename})}catch{P(j(`common.uploadFailed`,`Upload failed`),`error`)}finally{ot(!1)}},Fr=t=>{r!==`compact`||C||t.target.closest(`button, a, input, select, textarea, [role="button"]`)||E?.(e.id)},Ir=`!h-8 !min-h-8 !w-8 !px-0 !py-0`,Lr=({amsId:e,slotId:t,loadTrayId:n,isRefreshing:r,includeRfid:i=!0})=>{let a=G?.state===`RUNNING`;return(0,K.jsxs)(K.Fragment,{children:[i&&(0,K.jsxs)(`button`,{className:`w-full px-2 py-1.5 text-left text-xs flex items-center gap-2 rounded transition-colors ${F(`printers:ams_rfid`)?`text-white hover:bg-bambu-dark-tertiary`:`text-bambu-gray/50 cursor-not-allowed`}`,onClick:n=>{n.stopPropagation(),!(a||!F(`printers:ams_rfid`))&&dr.mutate({amsId:e,slotId:t})},disabled:a||r||!F(`printers:ams_rfid`),title:a?j(`printers.bedJog.disabledWhilePrinting`):F(`printers:ams_rfid`)?void 0:j(`printers.permission.noAmsRfid`),children:[(0,K.jsx)(Pl,{className:`w-3 h-3 ${r?`animate-spin`:``}`}),j(`printers.rfid.reread`)]}),(0,K.jsxs)(`button`,{className:`w-full px-2 py-1.5 text-left text-xs flex items-center gap-2 rounded transition-colors ${F(`printers:control`)?`text-white hover:bg-bambu-dark-tertiary`:`text-bambu-gray/50 cursor-not-allowed`}`,onClick:e=>{e.stopPropagation(),!(a||!F(`printers:control`))&&fr.mutate({trayId:n})},disabled:a||!F(`printers:control`),title:a?j(`printers.bedJog.disabledWhilePrinting`):F(`printers:control`)?void 0:j(`printers.permission.noControl`),children:[(0,K.jsx)(Zc,{className:`w-3 h-3`}),j(`printers.ams.load`)]}),(0,K.jsxs)(`button`,{className:`w-full px-2 py-1.5 text-left text-xs flex items-center gap-2 rounded transition-colors ${F(`printers:control`)?`text-white hover:bg-bambu-dark-tertiary`:`text-bambu-gray/50 cursor-not-allowed`}`,onClick:e=>{e.stopPropagation(),!(a||!F(`printers:control`))&&pr.mutate()},disabled:a||!F(`printers:control`),title:a?j(`printers.bedJog.disabledWhilePrinting`):F(`printers:control`)?void 0:j(`printers.permission.noControl`),children:[(0,K.jsx)(Qc,{className:`w-3 h-3`}),j(`printers.ams.unload`)]})]})},Rr=(0,K.jsxs)(`div`,{ref:st,className:`relative flex-shrink-0`,children:[(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>L(!I),title:j(`common.more`,`More`),className:Ir,children:(0,K.jsx)(qs,{className:`w-4 h-4`})}),I&&(0,K.jsxs)(`div`,{className:`absolute left-0 bottom-full mb-2 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-20`,children:[(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm flex items-center gap-2 ${F(`printers:update`)?`hover:bg-bambu-dark-tertiary`:`opacity-50 cursor-not-allowed`}`,onClick:()=>{F(`printers:update`)&&(te(!0),L(!1))},title:F(`printers:update`)?void 0:j(`printers.permission.noEdit`),children:[(0,K.jsx)(wl,{className:`w-4 h-4`}),j(`common.edit`)]}),(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2`,onClick:()=>{Fe(!0),L(!1)},children:[(0,K.jsx)(Lc,{className:`w-4 h-4`}),j(`printers.printerInformation`)]}),(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm flex items-center gap-2 ${F(`printers:update`)?`hover:bg-bambu-dark-tertiary`:`opacity-50 cursor-not-allowed`}`,disabled:$n.isPending||!F(`printers:update`),onClick:()=>{F(`printers:update`)&&(L(!1),e.is_active===!1?$n.mutate(!0):nr())},title:F(`printers:update`)?void 0:j(`printers.permission.noEdit`),children:[(0,K.jsx)(Ku,{className:`w-4 h-4`}),e.is_active===!1?j(`printers.maintenance.menuExit`):j(`printers.maintenance.menuEnter`)]}),(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2`,onClick:()=>{Dn.mutate(),L(!1)},children:[(0,K.jsx)(Pl,{className:`w-4 h-4`}),j(`printers.reconnect`)]}),(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2 disabled:opacity-50`,disabled:On.isPending,onClick:()=>{On.mutate(),L(!1)},children:[(0,K.jsx)(Ll,{className:`w-4 h-4 ${On.isPending?`animate-spin`:``}`}),j(`printers.forceRefresh`)]}),(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2`,onClick:()=>{H(!0),L(!1)},children:[(0,K.jsx)(bu,{className:`w-4 h-4`}),j(`printers.mqttDebug`)]}),(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2`,onClick:()=>{Le(!0),L(!1)},children:[(0,K.jsx)(mu,{className:`w-4 h-4`}),j(`diagnostic.runButton`)]}),(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm flex items-center gap-2 ${F(`printers:delete`)?`text-red-700 dark:text-red-400 hover:bg-bambu-dark-tertiary`:`text-red-700/50 dark:text-red-400/50 cursor-not-allowed`}`,onClick:()=>{F(`printers:delete`)&&(z(!0),L(!1))},title:F(`printers:delete`)?void 0:j(`printers.permission.noDelete`),children:[(0,K.jsx)(Eu,{className:`w-4 h-4`}),j(`common.delete`)]})]})]});return(0,K.jsxs)(Ed,{id:`printer-card-${e.id}`,className:`relative flex h-full flex-col ${w?`ring-2 ring-bambu-green`:``} ${C||r===`compact`?`cursor-pointer`:``}`,onClick:Fr,onDragEnter:jr,onDragOver:Mr,onDragLeave:Nr,onDrop:Pr,children:[C&&(0,K.jsx)(`div`,{className:`absolute inset-0 z-20 flex items-start p-2`,onClick:t=>{t.stopPropagation(),T?.(e.id)},children:w?(0,K.jsx)(uu,{className:`w-5 h-5 text-bambu-green`}):(0,K.jsx)(fu,{className:`w-5 h-5 text-bambu-gray`})}),(rt||at)&&(0,K.jsx)(`div`,{className:`absolute inset-0 z-10 rounded-xl border-2 border-dashed flex items-center justify-center transition-colors ${at?`bg-bambu-green/10 border-bambu-green/50`:Ar?`bg-bambu-green/10 border-bambu-green`:`bg-red-50 dark:bg-red-500/10 border-red-300 dark:border-red-500/50`}`,children:(0,K.jsx)(`div`,{className:`text-center`,children:at?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-8 h-8 mx-auto mb-2 text-bambu-green animate-spin`}),(0,K.jsx)(`p`,{className:`text-sm font-medium text-bambu-green`,children:j(`common.uploading`,`Uploading...`)})]}):Ar?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(jl,{className:`w-8 h-8 mx-auto mb-2 text-bambu-green`}),(0,K.jsx)(`p`,{className:`text-sm font-medium text-bambu-green`,children:j(`printers.dropToPrint`,`Drop to print`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(qu,{className:`w-8 h-8 mx-auto mb-2 text-red-600 dark:text-red-400`}),(0,K.jsx)(`p`,{className:`text-sm font-medium text-red-700 dark:text-red-400`,children:j(`printers.cannotPrint`,`Printer busy`)})]})})}),(0,K.jsxs)(Od,{className:`${i>=3?`p-5`:``} flex flex-1 flex-col`,children:[(0,K.jsxs)(`div`,{className:kr(),children:[(0,K.jsx)(`div`,{className:`flex items-start justify-between gap-2`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,K.jsx)(`img`,{src:wT(e.model),alt:e.model||j(`common.printer`),className:`object-contain rounded-lg flex-shrink-0 ${Dr()}`}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(`h3`,{className:`font-semibold text-white ${Or()}`,children:e.name}),r===`compact`&&(()=>{let e=G?.connected&&G.hms_errors?Xp(G.hms_errors):[],t=e.some(e=>e.severity<=2),n=e.length>0,r=G?.connected?t?`bg-status-error`:n?`bg-status-warning`:`bg-status-ok`:`bg-status-error`,i=G?.connected?n?`${e.length} HMS ${e.length===1?`error`:`errors`}`:j(`printers.connection.connected`):j(`printers.connection.offline`);return(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full flex-shrink-0 ${r}`,title:i})})()]}),r===`compact`&&yn&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>zn.mutate(),disabled:zn.isPending||!F(`printers:clear_plate`),"aria-label":j(`printers.plateStatus.markCleared`),className:`inline-flex h-5 w-5 flex-shrink-0 items-center justify-center rounded-md bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-300 dark:border-yellow-400/40 text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/30 transition-colors disabled:opacity-50`,title:F(`printers:clear_plate`)?j(`printers.plateStatus.markCleared`):j(`printers.permission.noControl`),children:zn.isPending?(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`}):(0,K.jsx)(qU,{className:`w-3 h-3`})})]}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[e.model||`Unknown Model`,r===`expanded`&&G?.nozzles&&G.nozzles[0]?.nozzle_diameter&&(0,K.jsxs)(`span`,{className:`ml-1.5 text-bambu-gray`,title:G.nozzles[0].nozzle_type||`Nozzle`,children:[`• `,G.nozzles[0].nozzle_diameter,`mm`]}),r===`expanded`&&n&&n.total_print_hours>0&&(0,K.jsxs)(`span`,{className:`ml-2 text-bambu-gray`,children:[(0,K.jsx)(ws,{className:`w-3 h-3 inline-block mr-1`}),Math.round(n.total_print_hours),`h`]})]})]})]})}),r===`expanded`&&(0,K.jsx)(`div`,{className:`mt-2`,children:(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.is_active===!1?(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2 py-1 rounded-full text-xs bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,title:j(`printers.maintenance.subtitle`),children:[(0,K.jsx)(Ku,{className:`w-3 h-3`}),j(`printers.maintenance.pillLabel`)]}):(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2 py-1 rounded-full text-xs ${G?.connected?`bg-status-ok/20 text-status-ok`:`bg-status-error/20 text-status-error`}`,children:[G?.connected?(0,K.jsx)(Gc,{className:`w-3 h-3`}):(0,K.jsx)(Mu,{className:`w-3 h-3`}),G?.connected?j(`printers.connection.connected`):j(`printers.connection.offline`)]}),e.is_active!==!1&&!G?.connected&&(0,K.jsxs)(`button`,{onClick:()=>Le(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs cursor-pointer bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,title:j(`diagnostic.runButton`),children:[(0,K.jsx)(mu,{className:`w-3 h-3`}),j(`diagnostic.runButton`)]}),G?.connected&&G?.wired_network&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-status-ok/20 text-status-ok`,title:j(`printers.connection.ethernet`,`Ethernet`),children:[(0,K.jsx)(Xo,{className:`w-3 h-3`}),j(`printers.connection.ethernet`,`Ethernet`)]}),G?.connected&&!G?.wired_network&&Kt!=null&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs ${Kt>=-50||Kt>=-60?`bg-status-ok/20 text-status-ok`:Kt>=-70?`bg-status-warning/20 text-status-warning`:Kt>=-80?`bg-orange-500/20 text-orange-600`:`bg-status-error/20 text-status-error`}`,title:`WiFi: ${Kt} dBm - ${j(ET(Kt).labelKey)}`,children:[(0,K.jsx)(tu,{className:`w-3 h-3`}),Kt,`dBm`]}),G?.connected&&(()=>{let e=G.hms_errors?Xp(G.hms_errors):[];return(0,K.jsxs)(`button`,{onClick:()=>de(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs cursor-pointer hover:opacity-80 transition-opacity ${e.length>0?e.some(e=>e.severity<=2)?`bg-status-error/20 text-status-error`:`bg-status-warning/20 text-status-warning`:`bg-status-ok/20 text-status-ok`}`,title:j(`printers.clickToViewHmsErrors`),children:[(0,K.jsx)(ku,{className:`w-3 h-3`}),e.length>0?e.length:`OK`]})})(),n&&(0,K.jsxs)(`button`,{onClick:()=>N(`/maintenance`),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs cursor-pointer hover:opacity-80 transition-opacity ${n.due_count>0?`bg-status-error/20 text-status-error`:n.warning_count>0?`bg-status-warning/20 text-status-warning`:`bg-status-ok/20 text-status-ok`}`,title:n.due_count>0||n.warning_count>0?`${n.due_count>0?`${n.due_count} maintenance due`:``}${n.due_count>0&&n.warning_count>0?`, `:``}${n.warning_count>0?`${n.warning_count} due soon`:``} - Click to view`:j(`printers.maintenanceUpToDate`),children:[(0,K.jsx)(Ku,{className:`w-3 h-3`}),n.due_count>0||n.warning_count>0?n.due_count+n.warning_count:`OK`]}),dn>0&&(0,K.jsxs)(`button`,{onClick:()=>N(`/queue`),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-400 hover:opacity-80 transition-opacity`,title:j(`printers.queue.inQueue`,{count:dn}),children:[(0,K.jsx)(Vc,{className:`w-3 h-3`}),dn]}),b&&Nt?.current_version&&Nt?.latest_version?(0,K.jsxs)(`button`,{onClick:()=>bt(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs hover:opacity-80 transition-opacity ${Nt.update_available?`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`:`bg-status-ok/20 text-status-ok`}`,title:Nt.update_available?j(`printers.firmwareUpdateAvailable`,{current:Nt.current_version,latest:Nt.latest_version}):j(`printers.firmwareUpToDate`,{version:Nt.current_version}),children:[Nt.update_available?(0,K.jsx)(Ws,{className:`w-3 h-3`}):(0,K.jsx)(hs,{className:`w-3 h-3`}),Nt.current_version]}):G?.firmware_version?(0,K.jsx)(`span`,{className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-bambu-dark-tertiary/50 text-bambu-gray`,children:G.firmware_version}):null,G?.connected&&[`X1C`,`X1`,`X1E`,`X2D`,`P2S`,`H2D`,`H2D Pro`,`H2C`,`H2S`].includes(e.model??``)&&(0,K.jsx)(`span`,{className:`flex items-center px-2 py-1 rounded-full text-xs ${G.door_open?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:`bg-status-ok/20 text-status-ok`}`,title:G.door_open?j(`printers.door.open`):j(`printers.door.closed`),children:G.door_open?(0,K.jsx)(Us,{className:`w-3 h-3`}):(0,K.jsx)(Hs,{className:`w-3 h-3`})})]})})]}),R&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,K.jsx)(Ed,{className:`w-full max-w-md mx-4`,children:(0,K.jsxs)(Od,{children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-full bg-red-100 dark:bg-red-500/20`,children:(0,K.jsx)(ku,{className:`w-5 h-5 text-red-600 dark:text-red-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:j(`printers.confirm.deleteTitle`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:j(`printers.confirm.deleteMessage`,{name:e.name})})]})]}),(0,K.jsx)(`div`,{className:`bg-bambu-dark rounded-lg p-3 mb-4`,children:(0,K.jsxs)(`label`,{className:`flex items-start gap-3 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:B,onChange:e=>V(e.target.checked),className:`mt-0.5 w-4 h-4 rounded border-bambu-gray bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green focus:ring-offset-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:j(`printers.deleteArchives`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:j(B?`printers.confirm.deleteArchivesNote`:`printers.confirm.keepArchivesNote`)})]})]})}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>{z(!1),V(!0)},children:j(`common.cancel`)}),(0,K.jsx)($,{variant:`danger`,onClick:()=>{En.mutate({deleteArchives:B}),z(!1),V(!0)},children:`Delete`})]})]})})}),e.is_active===!1?(0,K.jsx)(K.Fragment,{children:r===`compact`?(0,K.jsxs)(`div`,{className:`mt-2 flex items-center gap-2 px-2 py-1.5 rounded-full bg-amber-50 dark:bg-amber-500/15 border border-amber-300 dark:border-amber-500/30`,children:[(0,K.jsx)(Ku,{className:`w-3 h-3 text-amber-600 dark:text-amber-400 shrink-0`}),(0,K.jsx)(`span`,{className:`text-[11px] text-amber-700 dark:text-amber-400 font-medium truncate`,children:j(`printers.maintenance.pillLabel`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:j(`printers.status.title`,`Status`)}),(0,K.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,K.jsxs)(`div`,{className:`p-3 bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded-[10px] flex items-center gap-3`,children:[(0,K.jsx)(Ku,{className:`w-6 h-6 text-amber-600 dark:text-amber-400 shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-400 font-medium`,children:j(`printers.maintenance.title`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:j(`printers.maintenance.subtitle`)})]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,disabled:$n.isPending||!F(`printers:update`),onClick:()=>$n.mutate(!0),title:F(`printers:update`)?void 0:j(`printers.permission.noEdit`),children:j(`printers.maintenance.exitButton`)})]})]})}):G?.connected&&(0,K.jsxs)(K.Fragment,{children:[r===`compact`?(()=>{let e=G.hms_errors?Xp(G.hms_errors):[],t=G.state===`FAILED`||e.length>0,n=G.state===`RUNNING`||G.state===`PAUSE`?Math.max(0,Math.min(100,G.progress||0)):yn||t?100:0,r=G.state===`RUNNING`||G.state===`PAUSE`;return(0,K.jsxs)(`div`,{className:`relative mt-2 flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-bambu-dark-tertiary`,children:(0,K.jsx)(`div`,{className:`${t?`bg-status-error`:G.state===`PAUSE`?`bg-status-warning`:`bg-bambu-green`} h-1.5 rounded-full transition-all`,style:{width:`${n}%`}})}),(0,K.jsx)(`span`,{className:`w-9 shrink-0 text-right text-[11px] leading-none ${r?`text-white`:`text-bambu-gray`}`,children:r?`${Math.round(n)}%`:`---%`})]})})():(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:j(`printers.status.title`,`Status`)}),(0,K.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(()=>{let t=!!(G.current_print&&(G.state===`RUNNING`||G.state===`PAUSE`)),n=!t&&vn&&xn,r=t?bn:n?xn.name:null,i=t?G.cover_url:n?xn.coverUrl:null,a=t?G.progress||0:n?100:0;return(0,K.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded-[10px] relative overflow-hidden`,children:[(0,K.jsxs)(`button`,{onClick:()=>je(!0),disabled:!t||(G.printable_objects_count??0)<2||!F(`printers:control`),className:`absolute top-2 right-2 p-1.5 rounded transition-colors z-10 ${t&&(G.printable_objects_count??0)>=2&&F(`printers:control`)?`text-bambu-gray hover:text-white hover:bg-white/10`:`text-bambu-gray/30 cursor-not-allowed`}`,title:F(`printers:control`)?t?(G.printable_objects_count??0)>=2?j(`printers.skipObjects.tooltip`):j(`printers.skipObjects.requiresMultiple`):j(`printers.skipObjects.onlyWhilePrinting`):j(`printers.permission.noControl`),children:[(0,K.jsx)(mT,{className:`w-4 h-4`}),ar&&ar.skipped_count>0&&(0,K.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[16px] h-4 px-1 flex items-center justify-center text-[10px] font-bold bg-red-500 text-white rounded-full`,children:ar.skipped_count})]}),(0,K.jsxs)(`div`,{className:`flex items-stretch gap-2`,children:[(0,K.jsx)(lAe,{url:i,printName:r||void 0,className:`w-24 h-24 max-[520px]:w-20 max-[520px]:h-20`}),(0,K.jsxs)(`div`,{className:`flex h-24 max-[520px]:h-20 min-w-0 flex-1 flex-col justify-between pt-1`,children:[(0,K.jsxs)(`div`,{className:`flex min-h-[18px] items-center gap-2 pr-8`,children:[(0,K.jsx)(`p`,{className:`min-w-0 truncate text-sm text-bambu-gray`,children:pAe(G.state,G.stg_cur_name)}),wn]}),(0,K.jsx)(`p`,{className:`min-h-[18px] truncate pr-8 text-sm ${r?`text-white`:`text-bambu-gray/70`}`,children:r||j(`printers.noActiveJob`,`No active job`)}),(0,K.jsxs)(`div`,{className:`flex h-3 items-center gap-2 text-sm`,children:[(0,K.jsx)(`div`,{className:`h-1.5 min-w-0 flex-1 rounded-full bg-bambu-dark-tertiary`,children:(0,K.jsx)(`div`,{className:`${t?G.state===`PAUSE`?`bg-status-warning`:`bg-bambu-green`:n?`bg-bambu-green`:`bg-bambu-dark-tertiary`} h-1.5 rounded-full transition-all`,style:{width:`${a}%`}})}),(0,K.jsx)(`span`,{className:`w-9 shrink-0 pr-1 text-right text-[11px] leading-none ${t||n?`text-white`:`text-bambu-gray`}`,children:t||n?`${Math.round(a)}%`:`---%`})]}),(0,K.jsx)(`div`,{className:`flex min-h-[16px] items-center gap-2 text-xs text-bambu-gray`,children:t?(0,K.jsxs)(K.Fragment,{children:[G.remaining_time!=null&&G.remaining_time>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(ws,{className:`w-3 h-3`}),If(G.remaining_time*60)]}),(0,K.jsxs)(`span`,{className:`text-bambu-green font-medium`,title:j(`printers.estimatedCompletion`),children:[`ETA `,Ff(G.remaining_time,g,j)]})]}),G.layer_num!=null&&G.total_layers!=null&&G.total_layers>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(Vc,{className:`w-3 h-3`}),G.layer_num,`/`,G.total_layers]}),mn&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,title:`Started by ${mn}`,children:[(0,K.jsx)(Pu,{className:`w-3 h-3`}),mn]})]}):gn?(0,K.jsxs)(`p`,{className:`truncate`,title:gn.print_name||gn.filename,children:[`Last: `,gn.print_name||gn.filename,gn.completed_at&&(0,K.jsxs)(`span`,{className:`ml-1 text-bambu-gray/60`,children:[`• `,Mf(gn.completed_at,{month:`short`,day:`numeric`})]})]}):(0,K.jsx)(`span`,{children:j(`printers.readyToPrint`)})})]})]}),(0,K.jsx)(Fle,{printerId:e.id,printerModel:e.model,loadedFilamentTypes:Ft,loadedFilaments:It,variant:`panelExtension`})]})})()]}),G.temperatures&&r===`expanded`&&(()=>{let t=G.temperatures.nozzle_heating||G.temperatures.nozzle_2_heating||!1,n=G.temperatures.bed_heating||!1,r=G.temperatures.chamber_heating||!1,i=e.nozzle_count===2||G.temperatures.nozzle_2!==void 0,a=(()=>{let e=[`nozzle`];return G.temperatures.nozzle_2!==void 0&&e.push(`nozzle_2`),e.push(`bed`),G.temperatures.chamber!==void 0&&e.push(`chamber`),e})(),o=G.active_extruder===1?`L`:`R`,s=G.nozzle_rack?.find(e=>e.id===1),c=G.nozzle_rack?.find(e=>e.id===0),l=c||s,u=G.connected&&F(`printers:control`),d=u?void 0:j(`printers.permission.noControl`),f=`relative text-center px-2 py-1.5 bg-bambu-dark rounded-lg flex-1 flex flex-col justify-center items-center transition-colors ${u?`cursor-pointer hover:bg-bambu-dark-tertiary`:`cursor-default opacity-80`}`,p=mAe.has(e.model??``),m=[{key:`part`,label:j(`printers.fans.partCooling`),value:G.cooling_fan_speed??0,Icon:ec,activeClass:`text-cyan-600 dark:text-cyan-400`},{key:`aux`,label:j(`printers.fans.auxiliary`),value:G.big_fan1_speed??0,Icon:Wu,activeClass:`text-blue-600 dark:text-blue-400`},...p?[{key:`chamber`,label:j(`printers.fans.chamber`),value:G.big_fan2_speed??0,Icon:Ao,activeClass:`text-green-600 dark:text-green-400`}]:[]];return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`mt-2 flex items-stretch gap-1.5 flex-wrap`,children:[(0,K.jsxs)(`div`,{className:f,title:d,onClick:()=>u&&Te(we===`nozzle-temp`?null:`nozzle-temp`),children:[(0,K.jsx)(`button`,{type:`button`,className:`absolute top-0.5 right-0.5 p-0.5 rounded text-bambu-gray hover:text-white hover:bg-white/10 transition-colors`,title:j(`printers.heaterHistory.openLabel`,`View heater history`),onClick:e=>{e.stopPropagation(),ft({initialKind:`nozzle`,availableKinds:a})},children:(0,K.jsx)(ns,{className:`w-2.5 h-2.5`})}),(0,K.jsx)(bW,{className:`w-3.5 h-3.5 mb-0.5`,color:`text-orange-400`,isHeating:t}),G.temperatures.nozzle_2===void 0?l?(0,K.jsx)(yW,{slot:l,index:0,activeStatus:!0,filamentName:l.filament_id?Lt?.[l.filament_id]?.name:void 0,children:(0,K.jsxs)(`div`,{className:`cursor-default`,children:[(0,K.jsx)(`p`,{className:`text-[9px] text-bambu-gray`,children:j(`printers.temperatures.nozzle`)}),(0,K.jsxs)(`p`,{className:`text-[11px] text-white`,children:[Math.round(G.temperatures.nozzle||0),`°C`]})]})}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-[9px] text-bambu-gray`,children:j(`printers.temperatures.nozzle`)}),(0,K.jsxs)(`p`,{className:`text-[11px] text-white`,children:[Math.round(G.temperatures.nozzle||0),`°C`]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-[9px] text-bambu-gray`,children:`L / R`}),(0,K.jsxs)(`p`,{className:`text-[11px] text-white`,children:[Math.round(G.temperatures.nozzle||0),`° / `,Math.round(G.temperatures.nozzle_2||0),`°`]})]}),we===`nozzle-temp`&&(i?(0,K.jsx)(EW,{title:`Set Nozzle Temperatures`,widthClass:`w-[300px]`,popoverWidth:300,popoverHeight:260,isPending:Bn.isPending,onClose:()=>Te(null),children:(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 px-3 py-2.5`,children:[(0,K.jsx)(DW,{label:`Left Temp`,current:G.temperatures.nozzle,target:G.temperatures.nozzle_target,isActive:o===`L`,isPending:Bn.isPending,onSubmit:e=>Bn.mutate({target:e,nozzle:1}),options:qp(D,`C`)}),(0,K.jsx)(DW,{label:`Right Temp`,current:G.temperatures.nozzle_2,target:G.temperatures.nozzle_2_target,isActive:o===`R`,isPending:Bn.isPending,onSubmit:e=>Bn.mutate({target:e,nozzle:0}),options:qp(D,`C`)})]})}):(0,K.jsx)(EW,{title:`Set Nozzle Temperature`,unit:`°C`,customMin:0,customMax:320,isPending:Bn.isPending,options:qp(D,`C`),onClose:()=>Te(null),onSubmit:e=>Bn.mutate({target:e,nozzle:G.active_extruder??0})}))]}),(0,K.jsxs)(`div`,{className:f,title:d,onClick:()=>u&&Te(we===`bed-temp`?null:`bed-temp`),children:[(0,K.jsx)(`button`,{type:`button`,className:`absolute top-0.5 right-0.5 p-0.5 rounded text-bambu-gray hover:text-white hover:bg-white/10 transition-colors`,title:j(`printers.heaterHistory.openLabel`,`View heater history`),onClick:e=>{e.stopPropagation(),ft({initialKind:`bed`,availableKinds:a})},children:(0,K.jsx)(ns,{className:`w-2.5 h-2.5`})}),(0,K.jsx)(bW,{className:`w-3.5 h-3.5 mb-0.5`,color:`text-blue-400`,isHeating:n}),(0,K.jsx)(`p`,{className:`text-[9px] text-bambu-gray`,children:j(`printers.temperatures.bed`)}),(0,K.jsxs)(`p`,{className:`text-[11px] text-white`,children:[Math.round(G.temperatures.bed||0),`°C`]}),we===`bed-temp`&&(0,K.jsx)(EW,{title:`Set Bed Temperature`,unit:`°C`,customMin:0,customMax:140,isPending:Vn.isPending,options:qp(O,`C`),onClose:()=>Te(null),onSubmit:e=>Vn.mutate(e)})]}),G.temperatures.chamber!==void 0&&(()=>{let e=G.supports_chamber_heater===!0;return(0,K.jsxs)(`div`,{className:e?f:`relative text-center px-2 py-1.5 bg-bambu-dark rounded-lg flex-1 flex flex-col justify-center items-center`,title:e?d:void 0,onClick:e?()=>u&&Te(we===`chamber-temp`?null:`chamber-temp`):void 0,children:[(0,K.jsx)(`button`,{type:`button`,className:`absolute top-0.5 right-0.5 p-0.5 rounded text-bambu-gray hover:text-white hover:bg-white/10 transition-colors`,title:j(`printers.heaterHistory.openLabel`,`View heater history`),onClick:e=>{e.stopPropagation(),ft({initialKind:`chamber`,availableKinds:a})},children:(0,K.jsx)(ns,{className:`w-2.5 h-2.5`})}),(0,K.jsx)(bW,{className:`w-3.5 h-3.5 mb-0.5`,color:`text-green-400`,isHeating:r}),(0,K.jsx)(`p`,{className:`text-[9px] text-bambu-gray`,children:j(`printers.temperatures.chamber`)}),(0,K.jsxs)(`p`,{className:`text-[11px] text-white`,children:[Math.round(G.temperatures.chamber||0),`°C`]}),e&&we===`chamber-temp`&&(0,K.jsx)(EW,{title:`Set Chamber Temperature`,unit:`°C`,customMin:0,customMax:60,isPending:Hn.isPending,options:qp(k,`C`),onClose:()=>Te(null),onSubmit:e=>Hn.mutate(e)})]})})(),i&&(0,K.jsx)(Qke,{leftSlot:s,rightSlot:c,activeNozzle:o,filamentInfo:Lt,children:(0,K.jsxs)(`div`,{className:`relative text-center px-3 py-1.5 bg-bambu-dark rounded-lg h-full flex flex-col justify-center items-center transition-colors ${u?`cursor-pointer hover:bg-bambu-dark-tertiary`:`cursor-default opacity-80`}`,title:u?j(`printers.activeNozzle`,{nozzle:j(o===`L`?`common.left`:`common.right`)}):d,onClick:()=>u&&Te(we===`nozzle-select`?null:`nozzle-select`),children:[(0,K.jsx)(oAe,{className:`w-3.5 h-3.5 mb-0.5 text-amber-600 dark:text-amber-400`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-[11px] font-bold ${o===`L`?`text-amber-700 dark:text-amber-400`:`text-gray-500`}`,children:[`L`,s?.nozzle_diameter?` ${s.nozzle_diameter}`:``]}),(0,K.jsx)(`span`,{className:`text-[9px] text-bambu-gray/40`,children:`·`}),(0,K.jsxs)(`span`,{className:`text-[11px] font-bold ${o===`R`?`text-amber-700 dark:text-amber-400`:`text-gray-500`}`,children:[`R`,c?.nozzle_diameter?` ${c.nozzle_diameter}`:``]})]}),(0,K.jsx)(`p`,{className:`text-[9px] text-bambu-gray`,children:j(`printers.temperatures.nozzle`)}),we===`nozzle-select`&&(0,K.jsx)(EW,{title:`Set Nozzle Selection`,widthClass:`w-[300px]`,popoverWidth:300,popoverHeight:140,isPending:Wn.isPending,options:[{label:`Left`,value:1},{label:`Right`,value:0}],onClose:()=>Te(null),onSubmit:e=>Wn.mutate(e)})]})}),G.nozzle_rack&&G.nozzle_rack.some(e=>e.id>=2)&&(0,K.jsx)($ke,{slots:G.nozzle_rack,filamentInfo:Lt})]}),(0,K.jsx)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:m.map(({key:e,label:t,value:n,Icon:r,activeClass:i})=>{let a=n>0;return(0,K.jsxs)(`div`,{className:`relative px-2 py-1.5 bg-bambu-dark rounded-lg flex-1 min-w-0 flex items-center justify-center gap-1 transition-colors ${u?`cursor-pointer hover:bg-bambu-dark-tertiary`:`cursor-default opacity-80`}`,title:u?t:d,onClick:()=>u&&Te(we===`fan-${e}`?null:`fan-${e}`),children:[(0,K.jsx)(r,{className:`w-3 h-3 shrink-0 ${a?i:`text-bambu-gray/50`}`}),(0,K.jsxs)(`span`,{className:`text-[10px] leading-none ${a?`text-white`:`text-bambu-gray/50`}`,children:[n,`%`]}),we===`fan-${e}`&&(0,K.jsx)(EW,{title:`Set ${t} Speed`,unit:`%`,customMin:0,customMax:100,isPending:Un.isPending,options:qp(A,`%`),onClose:()=>Te(null),onSubmit:t=>Un.mutate({fan:e,speed:t})})]},e)})})]})})(),r===`expanded`&&yn&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>zn.mutate(),disabled:zn.isPending||!F(`printers:clear_plate`),className:`mt-2 w-full inline-flex items-center justify-center gap-2 px-3 py-1.5 rounded-lg bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-300 dark:border-yellow-400/40 text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/30 transition-colors text-xs font-medium disabled:opacity-50`,title:F(`printers:clear_plate`)?j(`printers.plateStatus.markCleared`):j(`printers.permission.noControl`),children:[zn.isPending?(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`}):(0,K.jsx)(qU,{className:`w-4 h-4`}),j(`printers.plateStatus.markCleared`)]}),r===`expanded`&&(()=>{let t=G.state===`RUNNING`,n=G.state===`PAUSE`,r=t||n,i=In.isPending||Ln.isPending||Rn.isPending,a=`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed opacity-50`,o=`flex h-8 w-8 items-center justify-center rounded-lg text-xs font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,s=`flex h-8 w-20 items-center justify-center gap-1 px-2 rounded-lg text-xs font-medium transition-colors`;return(0,K.jsxs)(`div`,{className:`mt-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:j(`printers.controls`)}),(0,K.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-x-2 gap-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 min-w-0`,children:[(0,K.jsx)(`button`,{onClick:()=>Gn.mutate(!G.chamber_light),disabled:!G.connected||Gn.isPending||!F(`printers:control`),className:`${o} ${G.chamber_light?`bg-yellow-50 dark:bg-yellow-500/10 text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/20`:`bg-bambu-dark text-bambu-gray/50 hover:bg-bambu-dark-tertiary hover:text-white`}`,title:F(`printers:control`)?G.chamber_light?j(`printers.chamberLightOff`):j(`printers.chamberLightOn`):j(`printers.permission.noControl`),children:(0,K.jsx)(pT,{on:G.chamber_light??!1,className:`w-4 h-4`})}),[`P2S`,`X2D`,`H2D`,`H2C`,`H2S`].includes(e.model??``)&&(()=>{let t=G.airduct_mode===1,n=t?cc:cu,r=t?`text-orange-600 dark:text-orange-400`:`text-sky-600 dark:text-sky-400`,i=t?`bg-orange-50 dark:bg-orange-500/10 text-orange-700 dark:text-orange-400 hover:bg-orange-500/20`:`bg-sky-50 dark:bg-sky-500/10 text-sky-700 dark:text-sky-400 hover:bg-sky-500/20`;return(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`button`,{onClick:()=>xe(be===e.id?null:e.id),disabled:!F(`printers:control`),className:`${o} ${i}`,title:`${j(`printers.airduct.title`)}: ${j(t?`printers.airduct.heating`:`printers.airduct.cooling`)}`,children:(0,K.jsx)(n,{className:`w-4 h-4 ${r}`})}),be===e.id&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>xe(null)}),(0,K.jsx)(`div`,{className:`absolute bottom-full left-0 mb-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg py-1 min-w-[130px]`,children:[{mode:`cooling`,label:j(`printers.airduct.cooling`),modeId:0},{mode:`heating`,label:j(`printers.airduct.heating`),modeId:1}].map(({mode:e,label:t,modeId:n})=>(0,K.jsxs)(`button`,{onClick:()=>{qn.mutate(e),xe(null)},className:`w-full text-left px-3 py-1.5 text-xs transition-colors flex items-center gap-2 ${G.airduct_mode===n?`text-bambu-green bg-bambu-green/10`:`text-white hover:bg-bambu-dark-tertiary`}`,children:[e===`heating`?(0,K.jsx)(cc,{className:`w-3 h-3`}):(0,K.jsx)(cu,{className:`w-3 h-3`}),t]},e))})]})]})})(),(()=>{let t=F(`printers:control`),n=r||!t,i=`flex h-8 w-8 items-center justify-center rounded bg-indigo-100 dark:bg-indigo-500/15 text-indigo-700 dark:text-indigo-300 transition-colors hover:bg-indigo-200 dark:hover:bg-indigo-500/30 disabled:cursor-not-allowed disabled:opacity-50`,a=e=>{let t=e*Ee*1;Jn.mutate({distance:t})},s=(e,t)=>{Yn.mutate({x:e,y:t})},c=e=>{Xn.mutate(e)};return(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`button`,{onClick:()=>Ce(Se===e.id?null:e.id),disabled:n,className:`${o} ${n?`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed`:`bg-indigo-50 dark:bg-indigo-500/10 text-indigo-700 dark:text-indigo-400 hover:bg-indigo-500/20`}`,title:j(t?r?`printers.bedJog.disabledWhilePrinting`:`printers.bedJog.title`:`printers.permission.noControl`),children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),Se===e.id&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>Ce(null)}),(0,K.jsxs)(`div`,{className:`absolute bottom-full left-0 mb-1 z-50 flex w-[216px] flex-col overflow-hidden rounded-xl border border-bambu-dark-tertiary bg-bambu-dark-secondary shadow-2xl`,children:[(0,K.jsx)(`div`,{className:`shrink-0 px-3 py-2.5 text-center text-sm font-medium text-white`,children:j(`printers.bedJog.title`)}),(0,K.jsx)(`div`,{className:`h-px bg-bambu-dark-tertiary`}),(0,K.jsxs)(`div`,{className:`flex items-start gap-1.5 bg-yellow-500/10 px-3 py-2 text-[11px] leading-snug text-yellow-700 dark:text-yellow-400`,children:[(0,K.jsx)(ku,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,K.jsx)(`span`,{children:j(`printers.bedJog.limitWarning`)})]}),(0,K.jsx)(`div`,{className:`h-px bg-bambu-dark-tertiary`}),(0,K.jsx)(`div`,{className:`flex justify-center px-3 py-2.5`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-1`,children:[(0,K.jsx)(`div`,{}),(0,K.jsx)(`button`,{onClick:()=>s(0,Ee),disabled:Yn.isPending,className:i,"aria-label":`Move Y forward`,children:(0,K.jsx)(zo,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{}),(0,K.jsx)(`button`,{onClick:()=>s(-Ee,0),disabled:Yn.isPending,className:i,"aria-label":`Move X left`,children:(0,K.jsx)(Po,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>{Ce(null),Zn.mutate(`all`)},disabled:Zn.isPending,className:i,"aria-label":j(`printers.bedJog.homeZ`),children:(0,K.jsx)(Nc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>s(Ee,0),disabled:Yn.isPending,className:i,"aria-label":`Move X right`,children:(0,K.jsx)(Io,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{}),(0,K.jsx)(`button`,{onClick:()=>s(0,-Ee),disabled:Yn.isPending,className:i,"aria-label":`Move Y back`,children:(0,K.jsx)(No,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{})]}),(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>a(-1),disabled:Jn.isPending,className:i,"aria-label":j(`printers.bedJog.up`),children:(0,K.jsx)(zo,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center text-bambu-gray/80`,children:(0,K.jsx)(Vc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>a(1),disabled:Jn.isPending,className:i,"aria-label":j(`printers.bedJog.down`),children:(0,K.jsx)(No,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>c(-Ee),disabled:Xn.isPending,className:i,"aria-label":`Retract filament`,children:(0,K.jsx)(zo,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center text-bambu-gray/80`,children:(0,K.jsx)(`span`,{className:`text-sm font-semibold leading-none`,children:`E`})}),(0,K.jsx)(`button`,{onClick:()=>c(Ee),disabled:Xn.isPending,className:i,"aria-label":`Extrude filament`,children:(0,K.jsx)(No,{className:`w-4 h-4`})})]})]})}),(0,K.jsx)(`div`,{className:`h-px bg-bambu-dark-tertiary`}),(0,K.jsxs)(`div`,{className:`px-3 pt-2.5 pb-3`,children:[(0,K.jsx)(`div`,{className:`mb-1 text-[9px] uppercase tracking-wider text-bambu-gray/70`,children:j(`printers.bedJog.step`)}),(0,K.jsx)(`div`,{className:`flex gap-1`,children:[1,10,50].map(e=>(0,K.jsx)(`button`,{onClick:()=>De(e),className:`flex-1 px-1 py-1 rounded text-[10px] transition-colors ${Ee===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:e},e))})]})]})]})]})})(),(0,K.jsxs)(`div`,{className:`inline-flex rounded-lg ${e.plate_detection_enabled?`ring-1 ring-green-500`:``}`,children:[(0,K.jsx)(`button`,{onClick:yr,disabled:!G.connected||Qn.isPending||!F(`printers:update`),className:`${o} rounded-r-none ${e.plate_detection_enabled?`bg-green-50 dark:bg-green-500/10 text-green-700 dark:text-green-400 hover:bg-green-500/20`:`bg-bambu-dark text-bambu-gray/50 hover:bg-bambu-dark-tertiary hover:text-white`}`,title:F(`printers:update`)?e.plate_detection_enabled?j(`printers.plateDetection.enabledClick`):j(`printers.plateDetection.disabledClick`):j(`printers.plateDetection.noPermission`),children:Qn.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Hl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:br,disabled:!G.connected||Ct||!F(`printers:update`),className:`flex h-8 w-8 items-center justify-center rounded-r-lg border-l border-bambu-dark-tertiary transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${e.plate_detection_enabled?`bg-green-50 dark:bg-green-500/10 text-green-700 dark:text-green-400 hover:bg-green-500/20`:`bg-bambu-dark text-bambu-gray/50 hover:bg-bambu-dark-tertiary hover:text-white`}`,title:F(`printers:update`)?j(`printers.plateDetection.manageCalibration`):j(`printers.plateDetection.noPermission`),children:Ct?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(ss,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`button`,{"data-testid":`speed-control`,onClick:()=>ye(ve===e.id?null:e.id),disabled:!r||!F(`printers:control`),className:`${o} ${r?`bg-amber-50 dark:bg-amber-500/10 text-amber-700 dark:text-amber-400 hover:bg-amber-500/20`:`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed`}`,title:r?j(`printers.speed.title`):void 0,children:(0,K.jsx)(vc,{className:`w-4 h-4`})}),ve===e.id&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>ye(null)}),(0,K.jsx)(`div`,{className:`absolute bottom-full left-0 mb-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg py-1 min-w-[130px]`,children:[{mode:1,label:j(`printers.speed.silent`)},{mode:2,label:j(`printers.speed.standard`)},{mode:3,label:j(`printers.speed.sport`)},{mode:4,label:j(`printers.speed.ludicrous`)}].map(({mode:e,label:t})=>(0,K.jsx)(`button`,{onClick:()=>{Kn.mutate(e),ye(null)},className:`w-full text-left px-3 py-1.5 text-xs transition-colors ${G.speed_level===e?`text-bambu-green bg-bambu-green/10`:`text-white hover:bg-bambu-dark-tertiary`}`,children:t},e))})]})]})]}),(0,K.jsxs)(`div`,{className:`ml-auto flex items-center justify-end gap-2 flex-shrink-0`,children:[(()=>{let e=!r||i||!F(`printers:control`);return(0,K.jsxs)(`button`,{onClick:()=>n?ke(!0):_e(!0),disabled:e,className:` + `,style:{maxWidth:`calc(100vw - 24px)`},onMouseEnter:w,onMouseLeave:T,children:(0,K.jsxs)(`div`,{className:`w-52 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl overflow-hidden backdrop-blur-sm p-2.5 space-y-2`,children:[(0,K.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:n}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[10px] tracking-wide text-bambu-gray font-medium shrink-0`,children:s(`printers.amsPopup.serialNumber`)}),(0,K.jsx)(`span`,{className:`text-[10px] text-white font-mono truncate`,children:e.serial_number||`—`})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[10px] tracking-wide text-bambu-gray font-medium shrink-0`,children:s(`printers.amsPopup.firmwareVersion`)}),(0,K.jsx)(`span`,{className:`text-[10px] text-white font-mono truncate`,children:e.sw_ver||`—`})]}),(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[10px] text-bambu-gray font-medium shrink-0`,children:s(`printers.amsPopup.friendlyName`)}),(0,K.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary/50`})]}),(0,K.jsx)(`input`,{type:`text`,value:f,onChange:e=>i&&p(e.target.value),onKeyDown:e=>e.key===`Enter`&&E(),onFocus:()=>b(!0),onBlur:()=>{b(!1),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>l(!1),200)},placeholder:i?s(`printers.amsPopup.friendlyNamePlaceholder`):r?.[e.id]||`—`,disabled:!i,title:i?void 0:s(`printers.amsPopup.noEditPermission`),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1 text-xs text-white placeholder-bambu-gray/60 focus:outline-none focus:border-bambu-green disabled:opacity-50 disabled:cursor-not-allowed`,maxLength:100}),i&&(0,K.jsxs)(`div`,{className:`space-y-1`,children:[g&&(0,K.jsx)(`p`,{className:`text-[10px] text-red-700 dark:text-red-400 break-words`,children:g}),(0,K.jsxs)(`div`,{className:`flex gap-1 justify-end`,children:[(0,K.jsx)(`button`,{onClick:E,disabled:m,className:`px-2 py-0.5 text-[10px] bg-bambu-green text-white rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:s(`printers.amsPopup.save`)}),r?.[e.id]&&(0,K.jsx)(`button`,{onClick:async()=>{if(i){h(!0),_(null);try{await Q.deleteAmsLabel(t,e.id,e.serial_number),a(),l(!1)}catch(e){_(e instanceof Error?e.message:String(e))}finally{h(!1)}}},disabled:m,className:`px-2 py-0.5 text-[10px] bg-bambu-dark-tertiary text-bambu-gray rounded hover:bg-bambu-dark-tertiary/70 disabled:opacity-50`,children:s(`printers.amsPopup.clear`)})]})]})]})]})})]})}var MW={PLA:{n3f:45,n3s:45,n3f_hours:12,n3s_hours:12},PETG:{n3f:65,n3s:65,n3f_hours:12,n3s_hours:12},TPU:{n3f:65,n3s:75,n3f_hours:12,n3s_hours:18},ABS:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},ASA:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:12},PC:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PVA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:18}};function NW({printer:e,hideIfDisconnected:t,maintenanceInfo:n,viewMode:r=`expanded`,cardSize:i=2,amsThresholds:a,spoolmanEnabled:o=!1,linkedSpools:s,spoolmanUrl:c,spoolmanSyncMode:l,onGetAssignment:u,onUnassignSpool:d,spoolmanSpools:f,spoolmanSlotAssignments:p,spoolmanLoading:m=!1,onUnassignSpoolmanSpool:h,timeFormat:g=`system`,cameraViewMode:_=`window`,onOpenEmbeddedCamera:v,checkPrinterFirmware:b=!0,dryingPresets:x=MW,requirePlateClear:S=!1,selectionMode:C=!1,isSelected:w=!1,onToggleSelect:T,onOpenCompactCard:E,nozzleTempPresets:D=Hp,bedTempPresets:O=Up,chamberTempPresets:k=Wp,fanSpeedPresets:A=Gp}){let{t:j}=W(),M=oo(),N=ir(),{showToast:P}=Pd(),{hasPermission:F}=bd(),[I,L]=(0,y.useState)(!1),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(!0),[ee,te]=(0,y.useState)(!1),[ne,re]=(0,y.useState)(!1),[ie,H]=(0,y.useState)(!1),[ae,oe]=(0,y.useState)(!1),[U,se]=(0,y.useState)(!1),[ce,le]=(0,y.useState)(null),[ue,de]=(0,y.useState)(!1),[fe,pe]=(0,y.useState)(!1),[me,he]=(0,y.useState)(!1),[ge,_e]=(0,y.useState)(!1),[ve,ye]=(0,y.useState)(null),[be,xe]=(0,y.useState)(null),[Se,Ce]=(0,y.useState)(null),[we,Te]=(0,y.useState)(null),[Ee,De]=(0,y.useState)(10),[Oe,ke]=(0,y.useState)(!1),[Ae,je]=(0,y.useState)(!1),[Me,Ne]=(0,y.useState)(!1),[Pe,Fe]=(0,y.useState)(!1),[Ie,Le]=(0,y.useState)(!1),Re=(0,y.useCallback)(()=>Fe(!1),[]),[ze,Be]=(0,y.useState)(null),[Ve,He]=(0,y.useState)(null),[Ue,We]=(0,y.useState)(`n3f`),[Ge,Ke]=(0,y.useState)(`PLA`),[qe,Je]=(0,y.useState)(50),[Ye,Xe]=(0,y.useState)(4),[Ze,Qe]=(0,y.useState)(!1),[$e,et]=(0,y.useState)(null),[tt,nt]=(0,y.useState)(null),[rt,it]=(0,y.useState)(!1),[at,ot]=(0,y.useState)(!1),st=(0,y.useRef)(null),ct=(0,y.useRef)(0),[lt,ut]=(0,y.useState)(null),[dt,ft]=(0,y.useState)(null),[pt,mt]=(0,y.useState)(null),[ht,gt]=(0,y.useState)(null),[_t,vt]=(0,y.useState)(null),[yt,bt]=(0,y.useState)(!1),[xt,St]=(0,y.useState)(null),[Ct,wt]=(0,y.useState)(!1),[Tt,Et]=(0,y.useState)(!1),[Dt,Ot]=(0,y.useState)(null),[kt,At]=(0,y.useState)(!1),[jt,Mt]=(0,y.useState)(!1),{data:G}=q({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id),refetchInterval:3e4}),{data:Nt}=q({queryKey:[`firmwareUpdate`,e.id],queryFn:()=>pd.checkPrinterUpdate(e.id),staleTime:300*1e3,refetchInterval:300*1e3,enabled:b&&F(`firmware:read`)}),Pt=(0,y.useMemo)(()=>{let e=new Set;if(G?.ams)for(let t of G.ams)for(let n of t.tray||[])n.tray_info_idx&&e.add(n.tray_info_idx);for(let t of G?.vt_tray??[])t.tray_info_idx&&e.add(t.tray_info_idx);if(G?.nozzle_rack)for(let t of G.nozzle_rack)t.filament_id&&e.add(t.filament_id);return Array.from(e)},[G?.ams,G?.vt_tray,G?.nozzle_rack]),Ft=(0,y.useMemo)(()=>{let e=new Set;if(G?.ams)for(let t of G.ams)for(let n of t.tray||[])n.tray_type&&e.add(n.tray_type.toUpperCase());for(let t of G?.vt_tray??[])t.tray_type&&e.add(t.tray_type.toUpperCase());return e},[G?.ams,G?.vt_tray]),It=(0,y.useMemo)(()=>{let e=new Set;if(G?.ams){for(let t of G.ams)for(let n of t.tray||[])if(n.tray_type&&n.tray_color){let t=n.tray_color.replace(`#`,``).toLowerCase().slice(0,6);e.add(`${n.tray_type.toUpperCase()}:${t}`)}}for(let t of G?.vt_tray??[])if(t.tray_type&&t.tray_color){let n=t.tray_color.replace(`#`,``).toLowerCase().slice(0,6);e.add(`${t.tray_type.toUpperCase()}:${n}`)}return e},[G?.ams,G?.vt_tray]),Lt=(0,y.useMemo)(()=>{let e=new Set;if(G?.ams){for(let t of G.ams)for(let n of t.tray||[])if(n.tray_type&&n.tray_color){let t=n.tray_color.replace(`#`,``).toLowerCase().slice(0,6);e.add(`${n.tray_type.toUpperCase()}:${t}:${n.tray_info_idx||``}`)}}for(let t of G?.vt_tray??[])if(t.tray_type&&t.tray_color){let n=t.tray_color.replace(`#`,``).toLowerCase().slice(0,6);e.add(`${t.tray_type.toUpperCase()}:${n}:${t.tray_info_idx||``}`)}return e},[G?.ams,G?.vt_tray]),{data:Rt}=q({queryKey:[`filamentInfo`,Pt],queryFn:()=>Q.getFilamentInfo(Pt),enabled:Pt.length>0,staleTime:300*1e3}),{data:zt}=q({queryKey:[`slotPresets`,e.id],queryFn:()=>Q.getSlotPresets(e.id),staleTime:120*1e3}),Bt=G?.state===`RUNNING`||G?.state===`PAUSE`?G?.current_archive_id??null:null,{data:Vt}=q({queryKey:[`archive-plates`,Bt],queryFn:()=>Q.getArchivePlates(Bt),enabled:Bt!=null,staleTime:300*1e3}),Ht=!Vt?.is_multi_plate||G?.current_plate_id==null?null:Vt.plates.find(e=>e.index===G.current_plate_id)?.name||j(`printers.plateNumber`,`Plate {{number}}`,{number:G.current_plate_id}),{data:Ut,refetch:Wt}=q({queryKey:[`amsLabels`,e.id],queryFn:()=>Q.getAmsLabels(e.id),staleTime:300*1e3}),[Gt,Kt]=(0,y.useState)(null);(0,y.useEffect)(()=>{G?.wifi_signal!=null&&Kt(G.wifi_signal)},[G?.wifi_signal]);let qt=G?.wifi_signal??Gt,Jt=(0,y.useRef)(void 0);(0,y.useEffect)(()=>{G?.connected!==void 0&&(Jt.current=G.connected)},[G?.connected]);let Yt=G?.connected??Jt.current,Xt=(0,y.useRef)({});(0,y.useEffect)(()=>{G?.ams_extruder_map&&Object.keys(G.ams_extruder_map).length>0&&(Xt.current=G.ams_extruder_map)},[G?.ams_extruder_map]);let Zt=G?.ams_extruder_map&&Object.keys(G.ams_extruder_map).length>0?G.ams_extruder_map:Xt.current,Qt=(0,y.useRef)([]);(0,y.useEffect)(()=>{G?.ams&&G.ams.length>0&&(Qt.current=G.ams)},[G?.ams]);let $t=G?.ams&&G.ams.length>0?G.ams:Qt.current;(0,y.useEffect)(()=>{if(!tt)return;let e=$t.find(e=>e.id===tt.amsId);e&&(e.dry_time>0||e.dry_status>0)&&nt(null)},[tt,$t]),(0,y.useEffect)(()=>{if(!tt)return;let e=setTimeout(()=>{nt(null),P(j(`printers.drying.toastNotStarted`),`error`)},cAe);return()=>clearTimeout(e)},[tt,P,j]);let en=(0,y.useRef)(void 0),tn=G?.tray_now;tn!==void 0&&tn!==255?en.current=tn:tn===255&&(en.current=void 0);let nn=tn!==void 0&&tn!==255?tn:en.current,rn=G?.expected_tray??null,an=G?.previous_tray??null,on=e=>{if(e===null)return null;if(e===254)return j(`printers.expectedSlot.external`);if(e>=128&&e<=135)return Ut?.[e]||Uf(e,1);let t=Math.floor(e/4),n=e%4;return j(`printers.expectedSlot.label`,{ams:Ut?.[t]||Uf(t,4),slot:n+1})},sn=G?.state===`PAUSE`?{expectedSlotLabel:on(rn),ranOutSlotLabel:on(an)}:null,{data:cn}=q({queryKey:[`smartPlugByPrinter`,e.id],queryFn:()=>Q.getSmartPlugByPrinter(e.id)}),{data:ln}=q({queryKey:[`scriptPlugsByPrinter`,e.id],queryFn:()=>Q.getScriptPlugsByPrinter(e.id)}),{data:un}=q({queryKey:[`smartPlugStatus`,cn?.id],queryFn:()=>cn?Q.getSmartPlugStatus(cn.id):null,enabled:!!cn,refetchInterval:1e4}),{data:dn}=q({queryKey:[`queue`,e.id,`pending`],queryFn:()=>Q.getQueue(e.id,`pending`)}),fn=(0,y.useMemo)(()=>dn?.length?DT(dn,Ft,It,Lt).length:0,[dn,Ft,It,Lt]),{data:pn}=q({queryKey:[`queue`,e.id,`printing`],queryFn:()=>Q.getQueue(e.id,`printing`),enabled:G?.state===`RUNNING`}),{data:mn}=q({queryKey:[`currentPrintUser`,e.id],queryFn:()=>Q.getCurrentPrintUser(e.id),enabled:G?.state===`RUNNING`}),hn=pn?.[0]?.created_by_username||mn?.username,{data:gn}=q({queryKey:[`archives`,e.id,`last`],queryFn:()=>Q.getArchives(e.id,1,0),enabled:G?.connected&&G?.state!==`RUNNING`}),_n=gn?.[0],vn=G?.state===`RUNNING`||G?.state===`PAUSE`,yn=S&&G?.awaiting_plate_clear===!0,bn=G?.connected&&yn&&!vn,xn=G?.current_print&&vn?see(G.subtask_name||G.current_print||null,G.gcode_file,j,Ht):null,[Sn,Cn]=(0,y.useState)(null);(0,y.useEffect)(()=>{xn?Cn({name:xn,coverUrl:G?.cover_url??null}):yn||Cn(null)},[xn,yn,G?.cover_url]);let wn=!S||!G?.connected?null:vn?{label:j(`printers.plateStatus.inUse`),className:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`}:G.awaiting_plate_clear?{label:j(`printers.plateStatus.notCleared`),className:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`}:{label:j(`printers.plateStatus.cleared`),className:`bg-status-ok/20 text-status-ok`},Tn=wn?(0,K.jsx)(`span`,{className:`inline-flex flex-shrink-0 items-center rounded-full px-2 py-0.5 text-[10px] font-medium ${wn.className}`,children:wn.label}):null,En=t&&Yt===!1,Dn=J({mutationFn:t=>Q.deletePrinter(e.id,t.deleteArchives),onSuccess:()=>{M.invalidateQueries({queryKey:[`printers`]}),M.invalidateQueries({queryKey:[`archives`]}),M.invalidateQueries({queryKey:[`maintenanceOverview`]})},onError:e=>P(e.message||j(`printers.toast.failedToDelete`),`error`)}),On=J({mutationFn:()=>Q.connectPrinter(e.id),onSuccess:()=>{M.invalidateQueries({queryKey:[`printerStatus`,e.id]})}}),kn=J({mutationFn:()=>Q.refreshPrinterStatus(e.id),onSuccess:()=>{M.invalidateQueries({queryKey:[`printerStatus`,e.id]}),P(j(`printers.forceRefreshSuccess`),`success`)},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),An=J({mutationFn:e=>Q.unlinkSpool(e),onSuccess:e=>{P(j(`spoolman.unlinkSuccess`)||e?.message,`success`),M.invalidateQueries({queryKey:[`linked-spools`]}),M.invalidateQueries({queryKey:[`unlinked-spools`]}),M.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})},onError:e=>{P(e.message||j(`spoolman.unlinkFailed`),`error`)}}),jn=J({mutationFn:({amsId:t,temp:n,duration:r,filament:i,rotateTray:a})=>Q.startDrying(e.id,t,n,r,i,a),onSuccess:(t,{amsId:n})=>{He(null),nt({amsId:n}),P(j(`printers.drying.toastCommandSent`),`success`),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Mn=J({mutationFn:t=>Q.stopDrying(e.id,t),onSuccess:()=>{nt(null),P(j(`printers.drying.toastStopped`),`success`),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Nn=J({mutationFn:t=>Q.setAmsFilamentBackup(e.id,t),onSuccess:(t,n)=>{M.invalidateQueries({queryKey:[`printerStatus`,e.id]}),M.invalidateQueries({queryKey:[`printer-status`,e.id]}),P(j(n?`printers.amsBackup.toastEnabled`:`printers.amsBackup.toastDisabled`),`success`)},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Pn=J({mutationFn:e=>cn?Q.controlSmartPlug(cn.id,e):Promise.reject(`No plug`),onSuccess:()=>{M.invalidateQueries({queryKey:[`smartPlugStatus`,cn?.id]})}}),Fn=J({mutationFn:e=>cn?Q.updateSmartPlug(cn.id,{auto_off:e}):Promise.reject(`No plug`),onSuccess:()=>{M.invalidateQueries({queryKey:[`smartPlugByPrinter`,e.id]}),M.invalidateQueries({queryKey:[`smart-plugs`]})}}),In=J({mutationFn:({id:e,action:t})=>Q.controlSmartPlug(e,t),onSuccess:()=>{P(j(`printers.toast.scriptTriggered`))},onError:e=>P(e.message||j(`printers.toast.failedToRunScript`),`error`)}),Ln=J({mutationFn:()=>Q.stopPrint(e.id),onSuccess:()=>{P(j(`printers.toast.printStopped`)),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToStopPrint`),`error`)}),Rn=J({mutationFn:()=>Q.pausePrint(e.id),onSuccess:()=>{P(j(`printers.toast.printPaused`)),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToPausePrint`),`error`)}),zn=J({mutationFn:()=>Q.resumePrint(e.id),onSuccess:()=>{P(j(`printers.toast.printResumed`)),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToResumePrint`),`error`)}),Bn=J({mutationFn:()=>Q.clearPlate(e.id),onSuccess:()=>{P(j(`queue.clearPlateSuccess`)),M.setQueryData([`printerStatus`,e.id],e=>e&&{...e,awaiting_plate_clear:!1}),M.invalidateQueries({queryKey:[`printerStatus`,e.id]}),M.invalidateQueries({queryKey:[`queue`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Vn=J({mutationFn:({target:t,nozzle:n})=>Q.setNozzleTemperature(e.id,t,n),onSuccess:t=>{Te(null),P(t.message),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Hn=J({mutationFn:t=>Q.setBedTemperature(e.id,t),onSuccess:t=>{Te(null),P(t.message),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Un=J({mutationFn:t=>Q.setChamberTemperature(e.id,t),onSuccess:t=>{Te(null),P(t.message),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Wn=J({mutationFn:({fan:t,speed:n})=>Q.setFanSpeed(e.id,t,n),onMutate:async({fan:t,speed:n})=>{await M.cancelQueries({queryKey:[`printerStatus`,e.id]});let r=M.getQueryData([`printerStatus`,e.id]),i={part:`cooling_fan_speed`,aux:`big_fan1_speed`,chamber:`big_fan2_speed`}[t];return M.setQueryData([`printerStatus`,e.id],e=>e&&{...e,[i]:n}),{previousStatus:r}},onSuccess:t=>{Te(null),P(t.message),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:(t,n,r)=>{r?.previousStatus&&M.setQueryData([`printerStatus`,e.id],r.previousStatus),P(t.message||j(`printers.toast.failedToSendCommand`),`error`)}}),Gn=J({mutationFn:t=>Q.selectExtruder(e.id,t),onMutate:async t=>{await M.cancelQueries({queryKey:[`printerStatus`,e.id]});let n=M.getQueryData([`printerStatus`,e.id]);return M.setQueryData([`printerStatus`,e.id],e=>e&&{...e,active_extruder:t}),{previousStatus:n}},onSuccess:t=>{Te(null),P(t.message),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:(t,n,r)=>{r?.previousStatus&&M.setQueryData([`printerStatus`,e.id],r.previousStatus),P(t.message||j(`printers.toast.failedToSendCommand`),`error`)}}),Kn=J({mutationFn:t=>Q.setChamberLight(e.id,t),onMutate:async t=>{await M.cancelQueries({queryKey:[`printerStatus`,e.id]});let n=M.getQueryData([`printerStatus`,e.id]);return M.setQueryData([`printerStatus`,e.id],e=>({...e,chamber_light:t})),{previousStatus:n}},onSuccess:(e,t)=>{P(`Chamber light ${t?`on`:`off`}`)},onError:(t,n,r)=>{r?.previousStatus&&M.setQueryData([`printerStatus`,e.id],r.previousStatus),P(t.message||j(`printers.toast.failedToControlChamberLight`),`error`)}}),qn=J({mutationFn:t=>Q.setPrintSpeed(e.id,t),onMutate:async t=>{await M.cancelQueries({queryKey:[`printerStatus`,e.id]});let n=M.getQueryData([`printerStatus`,e.id]);return M.setQueryData([`printerStatus`,e.id],e=>({...e,speed_level:t})),{previousStatus:n}},onError:(t,n,r)=>{r?.previousStatus&&M.setQueryData([`printerStatus`,e.id],r.previousStatus),P(t.message||j(`printers.toast.failedToSetSpeed`),`error`)}}),Jn=J({mutationFn:t=>Q.setAirductMode(e.id,t),onMutate:async t=>{await M.cancelQueries({queryKey:[`printerStatus`,e.id]});let n=M.getQueryData([`printerStatus`,e.id]);return M.setQueryData([`printerStatus`,e.id],e=>({...e,airduct_mode:t===`cooling`?0:1})),{previousStatus:n}},onError:(t,n,r)=>{r?.previousStatus&&M.setQueryData([`printerStatus`,e.id],r.previousStatus),P(t.message||j(`printers.toast.failedToSendCommand`),`error`)}}),Yn=J({mutationFn:({distance:t})=>Q.bedJog(e.id,t),onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Xn=J({mutationFn:({x:t,y:n})=>Q.xyJog(e.id,t,n),onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Zn=J({mutationFn:t=>Q.extruderJog(e.id,t),onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Qn=J({mutationFn:t=>Q.homeAxes(e.id,t),onSuccess:()=>{P(j(`printers.bedJog.homingStarted`))},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),$n=J({mutationFn:t=>Q.updatePrinter(e.id,{plate_detection_enabled:t}),onSuccess:()=>{M.invalidateQueries({queryKey:[`printers`]}),P($n.variables?j(`printers.toast.plateCheckEnabled`):j(`printers.toast.plateCheckDisabled`))},onError:e=>P(e.message||j(`printers.toast.failedToUpdateSetting`),`error`)}),er=J({mutationFn:t=>Q.updatePrinter(e.id,{is_active:t}),onSuccess:(t,n)=>{M.invalidateQueries({queryKey:[`printers`]}),M.invalidateQueries({queryKey:[`printerStatus`,e.id]}),P(j(n?`printers.maintenance.toastExited`:`printers.maintenance.toastEntered`,{name:e.name}),`success`)},onError:e=>P(e.message||j(`printers.toast.failedToUpdateSetting`),`error`)}),[tr,nr]=(0,y.useState)(!1),rr=()=>{G?.state===`RUNNING`||G?.state===`PAUSE`?nr(!0):er.mutate(!1)},ar=(G?.state===`RUNNING`||G?.state===`PAUSE`)&&(G?.printable_objects_count??0)>=2,{data:or}=q({queryKey:[`printableObjects`,e.id],queryFn:()=>Q.getPrintableObjects(e.id),enabled:Ae||ar,refetchInterval:Ae?5e3:ar?3e4:!1}),[sr,cr]=(0,y.useState)(null),lr=(0,y.useRef)(!1),ur=(0,y.useRef)(null),dr=(0,y.useRef)(!1),fr=J({mutationFn:({amsId:t,slotId:n})=>Q.refreshAmsSlot(e.id,t,n),onMutate:({amsId:e,slotId:t})=>{ur.current&&clearTimeout(ur.current),lr.current=!1,dr.current=!1,cr({amsId:e,slotId:t}),setTimeout(()=>{dr.current=!0},2e3),ur.current=setTimeout(()=>{cr(null)},3e4)},onSuccess:e=>{P(e.message||j(`printers.toast.rfidRereadInitiated`))},onError:e=>{P(e.message||j(`printers.toast.failedToRereadRfid`),`error`),ur.current&&clearTimeout(ur.current),cr(null)}}),pr=J({mutationFn:({trayId:t})=>Q.loadAmsTray(e.id,t),onSuccess:e=>{P(e.message||j(`printers.toast.loadInitiated`))},onError:e=>{P(e.message||j(`printers.toast.failedToLoad`),`error`)}}),mr=J({mutationFn:()=>Q.unloadAms(e.id),onSuccess:e=>{P(e.message||j(`printers.toast.unloadInitiated`))},onError:e=>{P(e.message||j(`printers.toast.failedToUnload`),`error`)}}),[hr,gr]=(0,y.useState)(null),[_r,vr]=(0,y.useState)(null),yr=async()=>{try{gr(await Q.getPlateReferences(e.id))}catch{}},br=()=>{$n.mutate(!e.plate_detection_enabled)},xr=async()=>{wt(!0),St(null);let t=G?.chamber_light===!1;Mt(t),t&&(await Q.setChamberLight(e.id,!0),await new Promise(e=>setTimeout(e,2500)));try{St(await Q.checkPlateEmpty(e.id,{includeDebugImage:!0})),yr()}catch(n){P(n instanceof Error?n.message:j(`printers.toast.failedToCheckPlate`),`error`),t&&(await Q.setChamberLight(e.id,!1),Mt(!1))}finally{wt(!1)}},Sr=(0,y.useCallback)(async()=>{St(null),jt&&(await Q.setChamberLight(e.id,!1),Mt(!1))},[jt,e.id]),Cr=async t=>{Et(!0);try{let n=await Q.calibratePlateDetection(e.id,{label:t});n.success?(P(n.message||j(`printers.toast.calibrationSaved`),`success`),yr(),St(await Q.checkPlateEmpty(e.id,{includeDebugImage:!0}))):P(n.message||j(`printers.toast.calibrationFailed`),`error`)}catch(e){P(e instanceof Error?e.message:j(`printers.toast.calibrationFailed`),`error`)}finally{Et(!1)}},wr=async(t,n)=>{try{await Q.updatePlateReferenceLabel(e.id,t,n),vr(null),yr()}catch(e){P(e instanceof Error?e.message:j(`printers.toast.failedToUpdateLabel`),`error`)}},Tr=async t=>{try{await Q.deletePlateReference(e.id,t),P(j(`printers.toast.referenceDeleted`),`success`),yr(),St(await Q.checkPlateEmpty(e.id,{includeDebugImage:!0}))}catch(e){P(e instanceof Error?e.message:j(`printers.toast.failedToDeleteReference`),`error`)}},Er=async()=>{if(Dt){At(!0);try{await Q.updatePrinter(e.id,{plate_detection_roi:Dt}),P(j(`printers.toast.detectionAreaSaved`),`success`),Ot(null),St(await Q.checkPlateEmpty(e.id,{includeDebugImage:!0}))}catch(e){P(e instanceof Error?e.message:j(`printers.toast.failedToSaveDetectionArea`),`error`)}finally{At(!1)}}};(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&xt&&Sr()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[xt,Sr]);let Dr=(0,y.useRef)(null);if((0,y.useEffect)(()=>{if(!sr)return;let e=G?.ams_status_main??0;return e!==0&&(lr.current=!0,Dr.current&&=(clearTimeout(Dr.current),null)),lr.current&&e===0&&(dr.current?(ur.current&&clearTimeout(ur.current),cr(null)):Dr.current||=setTimeout(()=>{ur.current&&clearTimeout(ur.current),cr(null)},2e3)),()=>{Dr.current&&clearTimeout(Dr.current)}},[G?.ams_status_main,sr]),(0,y.useEffect)(()=>{if(!I)return;let e=e=>{let t=e.target;st.current?.contains(t)||L(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[I]),En)return null;let Or=()=>{switch(i){case 1:return`w-10 h-10`;case 2:return`w-14 h-14`;case 3:return`w-16 h-16`;case 4:return`w-20 h-20`;default:return`w-14 h-14`}},kr=()=>{switch(i){case 1:return`text-base truncate`;case 2:return`text-lg`;case 3:return`text-xl`;case 4:return`text-2xl`;default:return`text-lg`}},Ar=()=>{switch(i){case 1:return`mb-2`;case 2:return`mb-4`;case 3:return`mb-5`;case 4:return`mb-6`;default:return`mb-4`}},jr=Yt&&G?.state!==`RUNNING`&&G?.state!==`PAUSE`&&F(`printers:control`),Mr=e=>{e.preventDefault(),ct.current++,ct.current===1&&it(!0)},Nr=e=>{e.preventDefault(),e.dataTransfer.dropEffect=jr?`copy`:`none`},Pr=e=>{e.preventDefault(),ct.current--,ct.current===0&&it(!1)},Fr=async t=>{if(t.preventDefault(),ct.current=0,it(!1),!jr)return;let n=Array.from(t.dataTransfer.files)[0];if(!n)return;let r=n.name.toLowerCase();if(!r.endsWith(`.gcode`)&&!r.includes(`.gcode.`)){P(j(`printers.dropNotPrintable`,`Only .gcode and .gcode.3mf files can be printed`),`error`);return}ot(!0);try{let t=await Q.uploadLibraryFile(n,null),r=t.metadata?.sliced_for_model,i=AW(e.model);if(r&&i&&r.toLowerCase()!==i.toLowerCase()){await Q.deleteLibraryFile(t.id).catch(()=>{}),P(j(`printers.incompatibleFile`,`This file was sliced for {{slicedFor}}, but this printer is a {{printerModel}}`,{slicedFor:r,printerModel:i}),`error`);return}Be({id:t.id,filename:t.filename})}catch{P(j(`common.uploadFailed`,`Upload failed`),`error`)}finally{ot(!1)}},Ir=t=>{r!==`compact`||C||t.target.closest(`button, a, input, select, textarea, [role="button"]`)||E?.(e.id)},Lr=`!h-8 !min-h-8 !w-8 !px-0 !py-0`,Rr=({amsId:e,slotId:t,loadTrayId:n,isRefreshing:r,includeRfid:i=!0})=>{let a=G?.state===`RUNNING`;return(0,K.jsxs)(K.Fragment,{children:[i&&(0,K.jsxs)(`button`,{className:`w-full px-2 py-1.5 text-left text-xs flex items-center gap-2 rounded transition-colors ${F(`printers:ams_rfid`)?`text-white hover:bg-bambu-dark-tertiary`:`text-bambu-gray/50 cursor-not-allowed`}`,onClick:n=>{n.stopPropagation(),!(a||!F(`printers:ams_rfid`))&&fr.mutate({amsId:e,slotId:t})},disabled:a||r||!F(`printers:ams_rfid`),title:a?j(`printers.bedJog.disabledWhilePrinting`):F(`printers:ams_rfid`)?void 0:j(`printers.permission.noAmsRfid`),children:[(0,K.jsx)(Pl,{className:`w-3 h-3 ${r?`animate-spin`:``}`}),j(`printers.rfid.reread`)]}),(0,K.jsxs)(`button`,{className:`w-full px-2 py-1.5 text-left text-xs flex items-center gap-2 rounded transition-colors ${F(`printers:control`)?`text-white hover:bg-bambu-dark-tertiary`:`text-bambu-gray/50 cursor-not-allowed`}`,onClick:e=>{e.stopPropagation(),!(a||!F(`printers:control`))&&pr.mutate({trayId:n})},disabled:a||!F(`printers:control`),title:a?j(`printers.bedJog.disabledWhilePrinting`):F(`printers:control`)?void 0:j(`printers.permission.noControl`),children:[(0,K.jsx)(Zc,{className:`w-3 h-3`}),j(`printers.ams.load`)]}),(0,K.jsxs)(`button`,{className:`w-full px-2 py-1.5 text-left text-xs flex items-center gap-2 rounded transition-colors ${F(`printers:control`)?`text-white hover:bg-bambu-dark-tertiary`:`text-bambu-gray/50 cursor-not-allowed`}`,onClick:e=>{e.stopPropagation(),!(a||!F(`printers:control`))&&mr.mutate()},disabled:a||!F(`printers:control`),title:a?j(`printers.bedJog.disabledWhilePrinting`):F(`printers:control`)?void 0:j(`printers.permission.noControl`),children:[(0,K.jsx)(Qc,{className:`w-3 h-3`}),j(`printers.ams.unload`)]})]})},zr=(0,K.jsxs)(`div`,{ref:st,className:`relative flex-shrink-0`,children:[(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>L(!I),title:j(`common.more`,`More`),className:Lr,children:(0,K.jsx)(qs,{className:`w-4 h-4`})}),I&&(0,K.jsxs)(`div`,{className:`absolute left-0 bottom-full mb-2 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-20`,children:[(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm flex items-center gap-2 ${F(`printers:update`)?`hover:bg-bambu-dark-tertiary`:`opacity-50 cursor-not-allowed`}`,onClick:()=>{F(`printers:update`)&&(te(!0),L(!1))},title:F(`printers:update`)?void 0:j(`printers.permission.noEdit`),children:[(0,K.jsx)(wl,{className:`w-4 h-4`}),j(`common.edit`)]}),(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2`,onClick:()=>{Fe(!0),L(!1)},children:[(0,K.jsx)(Lc,{className:`w-4 h-4`}),j(`printers.printerInformation`)]}),(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm flex items-center gap-2 ${F(`printers:update`)?`hover:bg-bambu-dark-tertiary`:`opacity-50 cursor-not-allowed`}`,disabled:er.isPending||!F(`printers:update`),onClick:()=>{F(`printers:update`)&&(L(!1),e.is_active===!1?er.mutate(!0):rr())},title:F(`printers:update`)?void 0:j(`printers.permission.noEdit`),children:[(0,K.jsx)(Ku,{className:`w-4 h-4`}),e.is_active===!1?j(`printers.maintenance.menuExit`):j(`printers.maintenance.menuEnter`)]}),(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2`,onClick:()=>{On.mutate(),L(!1)},children:[(0,K.jsx)(Pl,{className:`w-4 h-4`}),j(`printers.reconnect`)]}),(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2 disabled:opacity-50`,disabled:kn.isPending,onClick:()=>{kn.mutate(),L(!1)},children:[(0,K.jsx)(Ll,{className:`w-4 h-4 ${kn.isPending?`animate-spin`:``}`}),j(`printers.forceRefresh`)]}),(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2`,onClick:()=>{H(!0),L(!1)},children:[(0,K.jsx)(bu,{className:`w-4 h-4`}),j(`printers.mqttDebug`)]}),(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2`,onClick:()=>{Le(!0),L(!1)},children:[(0,K.jsx)(mu,{className:`w-4 h-4`}),j(`diagnostic.runButton`)]}),(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm flex items-center gap-2 ${F(`printers:delete`)?`text-red-700 dark:text-red-400 hover:bg-bambu-dark-tertiary`:`text-red-700/50 dark:text-red-400/50 cursor-not-allowed`}`,onClick:()=>{F(`printers:delete`)&&(z(!0),L(!1))},title:F(`printers:delete`)?void 0:j(`printers.permission.noDelete`),children:[(0,K.jsx)(Eu,{className:`w-4 h-4`}),j(`common.delete`)]})]})]});return(0,K.jsxs)(Ed,{id:`printer-card-${e.id}`,className:`relative flex h-full flex-col ${w?`ring-2 ring-bambu-green`:``} ${C||r===`compact`?`cursor-pointer`:``}`,onClick:Ir,onDragEnter:Mr,onDragOver:Nr,onDragLeave:Pr,onDrop:Fr,children:[C&&(0,K.jsx)(`div`,{className:`absolute inset-0 z-20 flex items-start p-2`,onClick:t=>{t.stopPropagation(),T?.(e.id)},children:w?(0,K.jsx)(uu,{className:`w-5 h-5 text-bambu-green`}):(0,K.jsx)(fu,{className:`w-5 h-5 text-bambu-gray`})}),(rt||at)&&(0,K.jsx)(`div`,{className:`absolute inset-0 z-10 rounded-xl border-2 border-dashed flex items-center justify-center transition-colors ${at?`bg-bambu-green/10 border-bambu-green/50`:jr?`bg-bambu-green/10 border-bambu-green`:`bg-red-50 dark:bg-red-500/10 border-red-300 dark:border-red-500/50`}`,children:(0,K.jsx)(`div`,{className:`text-center`,children:at?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-8 h-8 mx-auto mb-2 text-bambu-green animate-spin`}),(0,K.jsx)(`p`,{className:`text-sm font-medium text-bambu-green`,children:j(`common.uploading`,`Uploading...`)})]}):jr?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(jl,{className:`w-8 h-8 mx-auto mb-2 text-bambu-green`}),(0,K.jsx)(`p`,{className:`text-sm font-medium text-bambu-green`,children:j(`printers.dropToPrint`,`Drop to print`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(qu,{className:`w-8 h-8 mx-auto mb-2 text-red-600 dark:text-red-400`}),(0,K.jsx)(`p`,{className:`text-sm font-medium text-red-700 dark:text-red-400`,children:j(`printers.cannotPrint`,`Printer busy`)})]})})}),(0,K.jsxs)(Od,{className:`${i>=3?`p-5`:``} flex flex-1 flex-col`,children:[(0,K.jsxs)(`div`,{className:Ar(),children:[(0,K.jsx)(`div`,{className:`flex items-start justify-between gap-2`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,K.jsx)(`img`,{src:wT(e.model),alt:e.model||j(`common.printer`),className:`object-contain rounded-lg flex-shrink-0 ${Or()}`}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(`h3`,{className:`font-semibold text-white ${kr()}`,children:e.name}),r===`compact`&&(()=>{let e=G?.connected&&G.hms_errors?Xp(G.hms_errors):[],t=e.some(e=>e.severity<=2),n=e.length>0,r=G?.connected?t?`bg-status-error`:n?`bg-status-warning`:`bg-status-ok`:`bg-status-error`,i=G?.connected?n?`${e.length} HMS ${e.length===1?`error`:`errors`}`:j(`printers.connection.connected`):j(`printers.connection.offline`);return(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full flex-shrink-0 ${r}`,title:i})})()]}),r===`compact`&&bn&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>Bn.mutate(),disabled:Bn.isPending||!F(`printers:clear_plate`),"aria-label":j(`printers.plateStatus.markCleared`),className:`inline-flex h-5 w-5 flex-shrink-0 items-center justify-center rounded-md bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-300 dark:border-yellow-400/40 text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/30 transition-colors disabled:opacity-50`,title:F(`printers:clear_plate`)?j(`printers.plateStatus.markCleared`):j(`printers.permission.noControl`),children:Bn.isPending?(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`}):(0,K.jsx)(qU,{className:`w-3 h-3`})})]}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[e.model||`Unknown Model`,r===`expanded`&&G?.nozzles&&G.nozzles[0]?.nozzle_diameter&&(0,K.jsxs)(`span`,{className:`ml-1.5 text-bambu-gray`,title:G.nozzles[0].nozzle_type||`Nozzle`,children:[`• `,G.nozzles[0].nozzle_diameter,`mm`]}),r===`expanded`&&n&&n.total_print_hours>0&&(0,K.jsxs)(`span`,{className:`ml-2 text-bambu-gray`,children:[(0,K.jsx)(ws,{className:`w-3 h-3 inline-block mr-1`}),Math.round(n.total_print_hours),`h`]})]})]})]})}),r===`expanded`&&(0,K.jsx)(`div`,{className:`mt-2`,children:(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.is_active===!1?(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2 py-1 rounded-full text-xs bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,title:j(`printers.maintenance.subtitle`),children:[(0,K.jsx)(Ku,{className:`w-3 h-3`}),j(`printers.maintenance.pillLabel`)]}):(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2 py-1 rounded-full text-xs ${G?.connected?`bg-status-ok/20 text-status-ok`:`bg-status-error/20 text-status-error`}`,children:[G?.connected?(0,K.jsx)(Gc,{className:`w-3 h-3`}):(0,K.jsx)(Mu,{className:`w-3 h-3`}),G?.connected?j(`printers.connection.connected`):j(`printers.connection.offline`)]}),e.is_active!==!1&&!G?.connected&&(0,K.jsxs)(`button`,{onClick:()=>Le(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs cursor-pointer bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,title:j(`diagnostic.runButton`),children:[(0,K.jsx)(mu,{className:`w-3 h-3`}),j(`diagnostic.runButton`)]}),G?.connected&&G?.wired_network&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-status-ok/20 text-status-ok`,title:j(`printers.connection.ethernet`,`Ethernet`),children:[(0,K.jsx)(Xo,{className:`w-3 h-3`}),j(`printers.connection.ethernet`,`Ethernet`)]}),G?.connected&&!G?.wired_network&&qt!=null&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs ${qt>=-50||qt>=-60?`bg-status-ok/20 text-status-ok`:qt>=-70?`bg-status-warning/20 text-status-warning`:qt>=-80?`bg-orange-500/20 text-orange-600`:`bg-status-error/20 text-status-error`}`,title:`WiFi: ${qt} dBm - ${j(ET(qt).labelKey)}`,children:[(0,K.jsx)(tu,{className:`w-3 h-3`}),qt,`dBm`]}),G?.connected&&(()=>{let e=G.hms_errors?Xp(G.hms_errors):[];return(0,K.jsxs)(`button`,{onClick:()=>de(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs cursor-pointer hover:opacity-80 transition-opacity ${e.length>0?e.some(e=>e.severity<=2)?`bg-status-error/20 text-status-error`:`bg-status-warning/20 text-status-warning`:`bg-status-ok/20 text-status-ok`}`,title:j(`printers.clickToViewHmsErrors`),children:[(0,K.jsx)(ku,{className:`w-3 h-3`}),e.length>0?e.length:`OK`]})})(),n&&(0,K.jsxs)(`button`,{onClick:()=>N(`/maintenance`),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs cursor-pointer hover:opacity-80 transition-opacity ${n.due_count>0?`bg-status-error/20 text-status-error`:n.warning_count>0?`bg-status-warning/20 text-status-warning`:`bg-status-ok/20 text-status-ok`}`,title:n.due_count>0||n.warning_count>0?`${n.due_count>0?`${n.due_count} maintenance due`:``}${n.due_count>0&&n.warning_count>0?`, `:``}${n.warning_count>0?`${n.warning_count} due soon`:``} - Click to view`:j(`printers.maintenanceUpToDate`),children:[(0,K.jsx)(Ku,{className:`w-3 h-3`}),n.due_count>0||n.warning_count>0?n.due_count+n.warning_count:`OK`]}),fn>0&&(0,K.jsxs)(`button`,{onClick:()=>N(`/queue`),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-400 hover:opacity-80 transition-opacity`,title:j(`printers.queue.inQueue`,{count:fn}),children:[(0,K.jsx)(Vc,{className:`w-3 h-3`}),fn]}),b&&Nt?.current_version&&Nt?.latest_version?(0,K.jsxs)(`button`,{onClick:()=>bt(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs hover:opacity-80 transition-opacity ${Nt.update_available?`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`:`bg-status-ok/20 text-status-ok`}`,title:Nt.update_available?j(`printers.firmwareUpdateAvailable`,{current:Nt.current_version,latest:Nt.latest_version}):j(`printers.firmwareUpToDate`,{version:Nt.current_version}),children:[Nt.update_available?(0,K.jsx)(Ws,{className:`w-3 h-3`}):(0,K.jsx)(hs,{className:`w-3 h-3`}),Nt.current_version]}):G?.firmware_version?(0,K.jsx)(`span`,{className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-bambu-dark-tertiary/50 text-bambu-gray`,children:G.firmware_version}):null,G?.connected&&[`X1C`,`X1`,`X1E`,`X2D`,`P2S`,`H2D`,`H2D Pro`,`H2C`,`H2S`].includes(e.model??``)&&(0,K.jsx)(`span`,{className:`flex items-center px-2 py-1 rounded-full text-xs ${G.door_open?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:`bg-status-ok/20 text-status-ok`}`,title:G.door_open?j(`printers.door.open`):j(`printers.door.closed`),children:G.door_open?(0,K.jsx)(Us,{className:`w-3 h-3`}):(0,K.jsx)(Hs,{className:`w-3 h-3`})})]})})]}),R&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,K.jsx)(Ed,{className:`w-full max-w-md mx-4`,children:(0,K.jsxs)(Od,{children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-full bg-red-100 dark:bg-red-500/20`,children:(0,K.jsx)(ku,{className:`w-5 h-5 text-red-600 dark:text-red-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:j(`printers.confirm.deleteTitle`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:j(`printers.confirm.deleteMessage`,{name:e.name})})]})]}),(0,K.jsx)(`div`,{className:`bg-bambu-dark rounded-lg p-3 mb-4`,children:(0,K.jsxs)(`label`,{className:`flex items-start gap-3 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:B,onChange:e=>V(e.target.checked),className:`mt-0.5 w-4 h-4 rounded border-bambu-gray bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green focus:ring-offset-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:j(`printers.deleteArchives`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:j(B?`printers.confirm.deleteArchivesNote`:`printers.confirm.keepArchivesNote`)})]})]})}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>{z(!1),V(!0)},children:j(`common.cancel`)}),(0,K.jsx)($,{variant:`danger`,onClick:()=>{Dn.mutate({deleteArchives:B}),z(!1),V(!0)},children:`Delete`})]})]})})}),e.is_active===!1?(0,K.jsx)(K.Fragment,{children:r===`compact`?(0,K.jsxs)(`div`,{className:`mt-2 flex items-center gap-2 px-2 py-1.5 rounded-full bg-amber-50 dark:bg-amber-500/15 border border-amber-300 dark:border-amber-500/30`,children:[(0,K.jsx)(Ku,{className:`w-3 h-3 text-amber-600 dark:text-amber-400 shrink-0`}),(0,K.jsx)(`span`,{className:`text-[11px] text-amber-700 dark:text-amber-400 font-medium truncate`,children:j(`printers.maintenance.pillLabel`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:j(`printers.status.title`,`Status`)}),(0,K.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,K.jsxs)(`div`,{className:`p-3 bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded-[10px] flex items-center gap-3`,children:[(0,K.jsx)(Ku,{className:`w-6 h-6 text-amber-600 dark:text-amber-400 shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-400 font-medium`,children:j(`printers.maintenance.title`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:j(`printers.maintenance.subtitle`)})]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,disabled:er.isPending||!F(`printers:update`),onClick:()=>er.mutate(!0),title:F(`printers:update`)?void 0:j(`printers.permission.noEdit`),children:j(`printers.maintenance.exitButton`)})]})]})}):G?.connected&&(0,K.jsxs)(K.Fragment,{children:[r===`compact`?(()=>{let e=G.hms_errors?Xp(G.hms_errors):[],t=G.state===`FAILED`||e.length>0,n=G.state===`RUNNING`||G.state===`PAUSE`?Math.max(0,Math.min(100,G.progress||0)):bn||t?100:0,r=G.state===`RUNNING`||G.state===`PAUSE`;return(0,K.jsxs)(`div`,{className:`relative mt-2 flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-bambu-dark-tertiary`,children:(0,K.jsx)(`div`,{className:`${t?`bg-status-error`:G.state===`PAUSE`?`bg-status-warning`:`bg-bambu-green`} h-1.5 rounded-full transition-all`,style:{width:`${n}%`}})}),(0,K.jsx)(`span`,{className:`w-9 shrink-0 text-right text-[11px] leading-none ${r?`text-white`:`text-bambu-gray`}`,children:r?`${Math.round(n)}%`:`---%`})]})})():(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:j(`printers.status.title`,`Status`)}),(0,K.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(()=>{let t=!!(G.current_print&&(G.state===`RUNNING`||G.state===`PAUSE`)),n=!t&&yn&&Sn,r=t?xn:n?Sn.name:null,i=t?G.cover_url:n?Sn.coverUrl:null,a=t?G.progress||0:n?100:0;return(0,K.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded-[10px] relative overflow-hidden`,children:[(0,K.jsxs)(`button`,{onClick:()=>je(!0),disabled:!t||(G.printable_objects_count??0)<2||!F(`printers:control`),className:`absolute top-2 right-2 p-1.5 rounded transition-colors z-10 ${t&&(G.printable_objects_count??0)>=2&&F(`printers:control`)?`text-bambu-gray hover:text-white hover:bg-white/10`:`text-bambu-gray/30 cursor-not-allowed`}`,title:F(`printers:control`)?t?(G.printable_objects_count??0)>=2?j(`printers.skipObjects.tooltip`):j(`printers.skipObjects.requiresMultiple`):j(`printers.skipObjects.onlyWhilePrinting`):j(`printers.permission.noControl`),children:[(0,K.jsx)(mT,{className:`w-4 h-4`}),or&&or.skipped_count>0&&(0,K.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[16px] h-4 px-1 flex items-center justify-center text-[10px] font-bold bg-red-500 text-white rounded-full`,children:or.skipped_count})]}),(0,K.jsxs)(`div`,{className:`flex items-stretch gap-2`,children:[(0,K.jsx)(lAe,{url:i,printName:r||void 0,className:`w-24 h-24 max-[520px]:w-20 max-[520px]:h-20`}),(0,K.jsxs)(`div`,{className:`flex h-24 max-[520px]:h-20 min-w-0 flex-1 flex-col justify-between pt-1`,children:[(0,K.jsxs)(`div`,{className:`flex min-h-[18px] items-center gap-2 pr-8`,children:[(0,K.jsx)(`p`,{className:`min-w-0 truncate text-sm text-bambu-gray`,children:pAe(G.state,G.stg_cur_name)}),Tn]}),(0,K.jsx)(`p`,{className:`min-h-[18px] truncate pr-8 text-sm ${r?`text-white`:`text-bambu-gray/70`}`,children:r||j(`printers.noActiveJob`,`No active job`)}),(0,K.jsxs)(`div`,{className:`flex h-3 items-center gap-2 text-sm`,children:[(0,K.jsx)(`div`,{className:`h-1.5 min-w-0 flex-1 rounded-full bg-bambu-dark-tertiary`,children:(0,K.jsx)(`div`,{className:`${t?G.state===`PAUSE`?`bg-status-warning`:`bg-bambu-green`:n?`bg-bambu-green`:`bg-bambu-dark-tertiary`} h-1.5 rounded-full transition-all`,style:{width:`${a}%`}})}),(0,K.jsx)(`span`,{className:`w-9 shrink-0 pr-1 text-right text-[11px] leading-none ${t||n?`text-white`:`text-bambu-gray`}`,children:t||n?`${Math.round(a)}%`:`---%`})]}),(0,K.jsx)(`div`,{className:`flex min-h-[16px] items-center gap-2 text-xs text-bambu-gray`,children:t?(0,K.jsxs)(K.Fragment,{children:[G.remaining_time!=null&&G.remaining_time>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(ws,{className:`w-3 h-3`}),If(G.remaining_time*60)]}),(0,K.jsxs)(`span`,{className:`text-bambu-green font-medium`,title:j(`printers.estimatedCompletion`),children:[`ETA `,Ff(G.remaining_time,g,j)]})]}),G.layer_num!=null&&G.total_layers!=null&&G.total_layers>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(Vc,{className:`w-3 h-3`}),G.layer_num,`/`,G.total_layers]}),hn&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,title:`Started by ${hn}`,children:[(0,K.jsx)(Pu,{className:`w-3 h-3`}),hn]})]}):_n?(0,K.jsxs)(`p`,{className:`truncate`,title:_n.print_name||_n.filename,children:[`Last: `,_n.print_name||_n.filename,_n.completed_at&&(0,K.jsxs)(`span`,{className:`ml-1 text-bambu-gray/60`,children:[`• `,Mf(_n.completed_at,{month:`short`,day:`numeric`})]})]}):(0,K.jsx)(`span`,{children:j(`printers.readyToPrint`)})})]})]}),(0,K.jsx)(Fle,{printerId:e.id,printerModel:e.model,loadedFilamentTypes:Ft,loadedFilaments:It,loadedVariants:Lt,variant:`panelExtension`})]})})()]}),G.temperatures&&r===`expanded`&&(()=>{let t=G.temperatures.nozzle_heating||G.temperatures.nozzle_2_heating||!1,n=G.temperatures.bed_heating||!1,r=G.temperatures.chamber_heating||!1,i=e.nozzle_count===2||G.temperatures.nozzle_2!==void 0,a=(()=>{let e=[`nozzle`];return G.temperatures.nozzle_2!==void 0&&e.push(`nozzle_2`),e.push(`bed`),G.temperatures.chamber!==void 0&&e.push(`chamber`),e})(),o=G.active_extruder===1?`L`:`R`,s=G.nozzle_rack?.find(e=>e.id===1),c=G.nozzle_rack?.find(e=>e.id===0),l=c||s,u=G.connected&&F(`printers:control`),d=u?void 0:j(`printers.permission.noControl`),f=`relative text-center px-2 py-1.5 bg-bambu-dark rounded-lg flex-1 flex flex-col justify-center items-center transition-colors ${u?`cursor-pointer hover:bg-bambu-dark-tertiary`:`cursor-default opacity-80`}`,p=mAe.has(e.model??``),m=[{key:`part`,label:j(`printers.fans.partCooling`),value:G.cooling_fan_speed??0,Icon:ec,activeClass:`text-cyan-600 dark:text-cyan-400`},{key:`aux`,label:j(`printers.fans.auxiliary`),value:G.big_fan1_speed??0,Icon:Wu,activeClass:`text-blue-600 dark:text-blue-400`},...p?[{key:`chamber`,label:j(`printers.fans.chamber`),value:G.big_fan2_speed??0,Icon:Ao,activeClass:`text-green-600 dark:text-green-400`}]:[]];return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`mt-2 flex items-stretch gap-1.5 flex-wrap`,children:[(0,K.jsxs)(`div`,{className:f,title:d,onClick:()=>u&&Te(we===`nozzle-temp`?null:`nozzle-temp`),children:[(0,K.jsx)(`button`,{type:`button`,className:`absolute top-0.5 right-0.5 p-0.5 rounded text-bambu-gray hover:text-white hover:bg-white/10 transition-colors`,title:j(`printers.heaterHistory.openLabel`,`View heater history`),onClick:e=>{e.stopPropagation(),ft({initialKind:`nozzle`,availableKinds:a})},children:(0,K.jsx)(ns,{className:`w-2.5 h-2.5`})}),(0,K.jsx)(bW,{className:`w-3.5 h-3.5 mb-0.5`,color:`text-orange-400`,isHeating:t}),G.temperatures.nozzle_2===void 0?l?(0,K.jsx)(yW,{slot:l,index:0,activeStatus:!0,filamentName:l.filament_id?Rt?.[l.filament_id]?.name:void 0,children:(0,K.jsxs)(`div`,{className:`cursor-default`,children:[(0,K.jsx)(`p`,{className:`text-[9px] text-bambu-gray`,children:j(`printers.temperatures.nozzle`)}),(0,K.jsxs)(`p`,{className:`text-[11px] text-white`,children:[Math.round(G.temperatures.nozzle||0),`°C`]})]})}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-[9px] text-bambu-gray`,children:j(`printers.temperatures.nozzle`)}),(0,K.jsxs)(`p`,{className:`text-[11px] text-white`,children:[Math.round(G.temperatures.nozzle||0),`°C`]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-[9px] text-bambu-gray`,children:`L / R`}),(0,K.jsxs)(`p`,{className:`text-[11px] text-white`,children:[Math.round(G.temperatures.nozzle||0),`° / `,Math.round(G.temperatures.nozzle_2||0),`°`]})]}),we===`nozzle-temp`&&(i?(0,K.jsx)(EW,{title:`Set Nozzle Temperatures`,widthClass:`w-[300px]`,popoverWidth:300,popoverHeight:260,isPending:Vn.isPending,onClose:()=>Te(null),children:(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 px-3 py-2.5`,children:[(0,K.jsx)(DW,{label:`Left Temp`,current:G.temperatures.nozzle,target:G.temperatures.nozzle_target,isActive:o===`L`,isPending:Vn.isPending,onSubmit:e=>Vn.mutate({target:e,nozzle:1}),options:qp(D,`C`)}),(0,K.jsx)(DW,{label:`Right Temp`,current:G.temperatures.nozzle_2,target:G.temperatures.nozzle_2_target,isActive:o===`R`,isPending:Vn.isPending,onSubmit:e=>Vn.mutate({target:e,nozzle:0}),options:qp(D,`C`)})]})}):(0,K.jsx)(EW,{title:`Set Nozzle Temperature`,unit:`°C`,customMin:0,customMax:320,isPending:Vn.isPending,options:qp(D,`C`),onClose:()=>Te(null),onSubmit:e=>Vn.mutate({target:e,nozzle:G.active_extruder??0})}))]}),(0,K.jsxs)(`div`,{className:f,title:d,onClick:()=>u&&Te(we===`bed-temp`?null:`bed-temp`),children:[(0,K.jsx)(`button`,{type:`button`,className:`absolute top-0.5 right-0.5 p-0.5 rounded text-bambu-gray hover:text-white hover:bg-white/10 transition-colors`,title:j(`printers.heaterHistory.openLabel`,`View heater history`),onClick:e=>{e.stopPropagation(),ft({initialKind:`bed`,availableKinds:a})},children:(0,K.jsx)(ns,{className:`w-2.5 h-2.5`})}),(0,K.jsx)(bW,{className:`w-3.5 h-3.5 mb-0.5`,color:`text-blue-400`,isHeating:n}),(0,K.jsx)(`p`,{className:`text-[9px] text-bambu-gray`,children:j(`printers.temperatures.bed`)}),(0,K.jsxs)(`p`,{className:`text-[11px] text-white`,children:[Math.round(G.temperatures.bed||0),`°C`]}),we===`bed-temp`&&(0,K.jsx)(EW,{title:`Set Bed Temperature`,unit:`°C`,customMin:0,customMax:140,isPending:Hn.isPending,options:qp(O,`C`),onClose:()=>Te(null),onSubmit:e=>Hn.mutate(e)})]}),G.temperatures.chamber!==void 0&&(()=>{let e=G.supports_chamber_heater===!0;return(0,K.jsxs)(`div`,{className:e?f:`relative text-center px-2 py-1.5 bg-bambu-dark rounded-lg flex-1 flex flex-col justify-center items-center`,title:e?d:void 0,onClick:e?()=>u&&Te(we===`chamber-temp`?null:`chamber-temp`):void 0,children:[(0,K.jsx)(`button`,{type:`button`,className:`absolute top-0.5 right-0.5 p-0.5 rounded text-bambu-gray hover:text-white hover:bg-white/10 transition-colors`,title:j(`printers.heaterHistory.openLabel`,`View heater history`),onClick:e=>{e.stopPropagation(),ft({initialKind:`chamber`,availableKinds:a})},children:(0,K.jsx)(ns,{className:`w-2.5 h-2.5`})}),(0,K.jsx)(bW,{className:`w-3.5 h-3.5 mb-0.5`,color:`text-green-400`,isHeating:r}),(0,K.jsx)(`p`,{className:`text-[9px] text-bambu-gray`,children:j(`printers.temperatures.chamber`)}),(0,K.jsxs)(`p`,{className:`text-[11px] text-white`,children:[Math.round(G.temperatures.chamber||0),`°C`]}),e&&we===`chamber-temp`&&(0,K.jsx)(EW,{title:`Set Chamber Temperature`,unit:`°C`,customMin:0,customMax:60,isPending:Un.isPending,options:qp(k,`C`),onClose:()=>Te(null),onSubmit:e=>Un.mutate(e)})]})})(),i&&(0,K.jsx)(Qke,{leftSlot:s,rightSlot:c,activeNozzle:o,filamentInfo:Rt,children:(0,K.jsxs)(`div`,{className:`relative text-center px-3 py-1.5 bg-bambu-dark rounded-lg h-full flex flex-col justify-center items-center transition-colors ${u?`cursor-pointer hover:bg-bambu-dark-tertiary`:`cursor-default opacity-80`}`,title:u?j(`printers.activeNozzle`,{nozzle:j(o===`L`?`common.left`:`common.right`)}):d,onClick:()=>u&&Te(we===`nozzle-select`?null:`nozzle-select`),children:[(0,K.jsx)(oAe,{className:`w-3.5 h-3.5 mb-0.5 text-amber-600 dark:text-amber-400`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-[11px] font-bold ${o===`L`?`text-amber-700 dark:text-amber-400`:`text-gray-500`}`,children:[`L`,s?.nozzle_diameter?` ${s.nozzle_diameter}`:``]}),(0,K.jsx)(`span`,{className:`text-[9px] text-bambu-gray/40`,children:`·`}),(0,K.jsxs)(`span`,{className:`text-[11px] font-bold ${o===`R`?`text-amber-700 dark:text-amber-400`:`text-gray-500`}`,children:[`R`,c?.nozzle_diameter?` ${c.nozzle_diameter}`:``]})]}),(0,K.jsx)(`p`,{className:`text-[9px] text-bambu-gray`,children:j(`printers.temperatures.nozzle`)}),we===`nozzle-select`&&(0,K.jsx)(EW,{title:`Set Nozzle Selection`,widthClass:`w-[300px]`,popoverWidth:300,popoverHeight:140,isPending:Gn.isPending,options:[{label:`Left`,value:1},{label:`Right`,value:0}],onClose:()=>Te(null),onSubmit:e=>Gn.mutate(e)})]})}),G.nozzle_rack&&G.nozzle_rack.some(e=>e.id>=2)&&(0,K.jsx)($ke,{slots:G.nozzle_rack,filamentInfo:Rt})]}),(0,K.jsx)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:m.map(({key:e,label:t,value:n,Icon:r,activeClass:i})=>{let a=n>0;return(0,K.jsxs)(`div`,{className:`relative px-2 py-1.5 bg-bambu-dark rounded-lg flex-1 min-w-0 flex items-center justify-center gap-1 transition-colors ${u?`cursor-pointer hover:bg-bambu-dark-tertiary`:`cursor-default opacity-80`}`,title:u?t:d,onClick:()=>u&&Te(we===`fan-${e}`?null:`fan-${e}`),children:[(0,K.jsx)(r,{className:`w-3 h-3 shrink-0 ${a?i:`text-bambu-gray/50`}`}),(0,K.jsxs)(`span`,{className:`text-[10px] leading-none ${a?`text-white`:`text-bambu-gray/50`}`,children:[n,`%`]}),we===`fan-${e}`&&(0,K.jsx)(EW,{title:`Set ${t} Speed`,unit:`%`,customMin:0,customMax:100,isPending:Wn.isPending,options:qp(A,`%`),onClose:()=>Te(null),onSubmit:t=>Wn.mutate({fan:e,speed:t})})]},e)})})]})})(),r===`expanded`&&bn&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>Bn.mutate(),disabled:Bn.isPending||!F(`printers:clear_plate`),className:`mt-2 w-full inline-flex items-center justify-center gap-2 px-3 py-1.5 rounded-lg bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-300 dark:border-yellow-400/40 text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/30 transition-colors text-xs font-medium disabled:opacity-50`,title:F(`printers:clear_plate`)?j(`printers.plateStatus.markCleared`):j(`printers.permission.noControl`),children:[Bn.isPending?(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`}):(0,K.jsx)(qU,{className:`w-4 h-4`}),j(`printers.plateStatus.markCleared`)]}),r===`expanded`&&(()=>{let t=G.state===`RUNNING`,n=G.state===`PAUSE`,r=t||n,i=Ln.isPending||Rn.isPending||zn.isPending,a=`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed opacity-50`,o=`flex h-8 w-8 items-center justify-center rounded-lg text-xs font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,s=`flex h-8 w-20 items-center justify-center gap-1 px-2 rounded-lg text-xs font-medium transition-colors`;return(0,K.jsxs)(`div`,{className:`mt-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:j(`printers.controls`)}),(0,K.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-x-2 gap-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 min-w-0`,children:[(0,K.jsx)(`button`,{onClick:()=>Kn.mutate(!G.chamber_light),disabled:!G.connected||Kn.isPending||!F(`printers:control`),className:`${o} ${G.chamber_light?`bg-yellow-50 dark:bg-yellow-500/10 text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/20`:`bg-bambu-dark text-bambu-gray/50 hover:bg-bambu-dark-tertiary hover:text-white`}`,title:F(`printers:control`)?G.chamber_light?j(`printers.chamberLightOff`):j(`printers.chamberLightOn`):j(`printers.permission.noControl`),children:(0,K.jsx)(pT,{on:G.chamber_light??!1,className:`w-4 h-4`})}),[`P2S`,`X2D`,`H2D`,`H2C`,`H2S`].includes(e.model??``)&&(()=>{let t=G.airduct_mode===1,n=t?cc:cu,r=t?`text-orange-600 dark:text-orange-400`:`text-sky-600 dark:text-sky-400`,i=t?`bg-orange-50 dark:bg-orange-500/10 text-orange-700 dark:text-orange-400 hover:bg-orange-500/20`:`bg-sky-50 dark:bg-sky-500/10 text-sky-700 dark:text-sky-400 hover:bg-sky-500/20`;return(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`button`,{onClick:()=>xe(be===e.id?null:e.id),disabled:!F(`printers:control`),className:`${o} ${i}`,title:`${j(`printers.airduct.title`)}: ${j(t?`printers.airduct.heating`:`printers.airduct.cooling`)}`,children:(0,K.jsx)(n,{className:`w-4 h-4 ${r}`})}),be===e.id&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>xe(null)}),(0,K.jsx)(`div`,{className:`absolute bottom-full left-0 mb-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg py-1 min-w-[130px]`,children:[{mode:`cooling`,label:j(`printers.airduct.cooling`),modeId:0},{mode:`heating`,label:j(`printers.airduct.heating`),modeId:1}].map(({mode:e,label:t,modeId:n})=>(0,K.jsxs)(`button`,{onClick:()=>{Jn.mutate(e),xe(null)},className:`w-full text-left px-3 py-1.5 text-xs transition-colors flex items-center gap-2 ${G.airduct_mode===n?`text-bambu-green bg-bambu-green/10`:`text-white hover:bg-bambu-dark-tertiary`}`,children:[e===`heating`?(0,K.jsx)(cc,{className:`w-3 h-3`}):(0,K.jsx)(cu,{className:`w-3 h-3`}),t]},e))})]})]})})(),(()=>{let t=F(`printers:control`),n=r||!t,i=`flex h-8 w-8 items-center justify-center rounded bg-indigo-100 dark:bg-indigo-500/15 text-indigo-700 dark:text-indigo-300 transition-colors hover:bg-indigo-200 dark:hover:bg-indigo-500/30 disabled:cursor-not-allowed disabled:opacity-50`,a=e=>{let t=e*Ee*1;Yn.mutate({distance:t})},s=(e,t)=>{Xn.mutate({x:e,y:t})},c=e=>{Zn.mutate(e)};return(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`button`,{onClick:()=>Ce(Se===e.id?null:e.id),disabled:n,className:`${o} ${n?`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed`:`bg-indigo-50 dark:bg-indigo-500/10 text-indigo-700 dark:text-indigo-400 hover:bg-indigo-500/20`}`,title:j(t?r?`printers.bedJog.disabledWhilePrinting`:`printers.bedJog.title`:`printers.permission.noControl`),children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),Se===e.id&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>Ce(null)}),(0,K.jsxs)(`div`,{className:`absolute bottom-full left-0 mb-1 z-50 flex w-[216px] flex-col overflow-hidden rounded-xl border border-bambu-dark-tertiary bg-bambu-dark-secondary shadow-2xl`,children:[(0,K.jsx)(`div`,{className:`shrink-0 px-3 py-2.5 text-center text-sm font-medium text-white`,children:j(`printers.bedJog.title`)}),(0,K.jsx)(`div`,{className:`h-px bg-bambu-dark-tertiary`}),(0,K.jsxs)(`div`,{className:`flex items-start gap-1.5 bg-yellow-500/10 px-3 py-2 text-[11px] leading-snug text-yellow-700 dark:text-yellow-400`,children:[(0,K.jsx)(ku,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,K.jsx)(`span`,{children:j(`printers.bedJog.limitWarning`)})]}),(0,K.jsx)(`div`,{className:`h-px bg-bambu-dark-tertiary`}),(0,K.jsx)(`div`,{className:`flex justify-center px-3 py-2.5`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-1`,children:[(0,K.jsx)(`div`,{}),(0,K.jsx)(`button`,{onClick:()=>s(0,Ee),disabled:Xn.isPending,className:i,"aria-label":`Move Y forward`,children:(0,K.jsx)(zo,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{}),(0,K.jsx)(`button`,{onClick:()=>s(-Ee,0),disabled:Xn.isPending,className:i,"aria-label":`Move X left`,children:(0,K.jsx)(Po,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>{Ce(null),Qn.mutate(`all`)},disabled:Qn.isPending,className:i,"aria-label":j(`printers.bedJog.homeZ`),children:(0,K.jsx)(Nc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>s(Ee,0),disabled:Xn.isPending,className:i,"aria-label":`Move X right`,children:(0,K.jsx)(Io,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{}),(0,K.jsx)(`button`,{onClick:()=>s(0,-Ee),disabled:Xn.isPending,className:i,"aria-label":`Move Y back`,children:(0,K.jsx)(No,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{})]}),(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>a(-1),disabled:Yn.isPending,className:i,"aria-label":j(`printers.bedJog.up`),children:(0,K.jsx)(zo,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center text-bambu-gray/80`,children:(0,K.jsx)(Vc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>a(1),disabled:Yn.isPending,className:i,"aria-label":j(`printers.bedJog.down`),children:(0,K.jsx)(No,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>c(-Ee),disabled:Zn.isPending,className:i,"aria-label":`Retract filament`,children:(0,K.jsx)(zo,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center text-bambu-gray/80`,children:(0,K.jsx)(`span`,{className:`text-sm font-semibold leading-none`,children:`E`})}),(0,K.jsx)(`button`,{onClick:()=>c(Ee),disabled:Zn.isPending,className:i,"aria-label":`Extrude filament`,children:(0,K.jsx)(No,{className:`w-4 h-4`})})]})]})}),(0,K.jsx)(`div`,{className:`h-px bg-bambu-dark-tertiary`}),(0,K.jsxs)(`div`,{className:`px-3 pt-2.5 pb-3`,children:[(0,K.jsx)(`div`,{className:`mb-1 text-[9px] uppercase tracking-wider text-bambu-gray/70`,children:j(`printers.bedJog.step`)}),(0,K.jsx)(`div`,{className:`flex gap-1`,children:[1,10,50].map(e=>(0,K.jsx)(`button`,{onClick:()=>De(e),className:`flex-1 px-1 py-1 rounded text-[10px] transition-colors ${Ee===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:e},e))})]})]})]})]})})(),(0,K.jsxs)(`div`,{className:`inline-flex rounded-lg ${e.plate_detection_enabled?`ring-1 ring-green-500`:``}`,children:[(0,K.jsx)(`button`,{onClick:br,disabled:!G.connected||$n.isPending||!F(`printers:update`),className:`${o} rounded-r-none ${e.plate_detection_enabled?`bg-green-50 dark:bg-green-500/10 text-green-700 dark:text-green-400 hover:bg-green-500/20`:`bg-bambu-dark text-bambu-gray/50 hover:bg-bambu-dark-tertiary hover:text-white`}`,title:F(`printers:update`)?e.plate_detection_enabled?j(`printers.plateDetection.enabledClick`):j(`printers.plateDetection.disabledClick`):j(`printers.plateDetection.noPermission`),children:$n.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Hl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:xr,disabled:!G.connected||Ct||!F(`printers:update`),className:`flex h-8 w-8 items-center justify-center rounded-r-lg border-l border-bambu-dark-tertiary transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${e.plate_detection_enabled?`bg-green-50 dark:bg-green-500/10 text-green-700 dark:text-green-400 hover:bg-green-500/20`:`bg-bambu-dark text-bambu-gray/50 hover:bg-bambu-dark-tertiary hover:text-white`}`,title:F(`printers:update`)?j(`printers.plateDetection.manageCalibration`):j(`printers.plateDetection.noPermission`),children:Ct?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(ss,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`button`,{"data-testid":`speed-control`,onClick:()=>ye(ve===e.id?null:e.id),disabled:!r||!F(`printers:control`),className:`${o} ${r?`bg-amber-50 dark:bg-amber-500/10 text-amber-700 dark:text-amber-400 hover:bg-amber-500/20`:`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed`}`,title:r?j(`printers.speed.title`):void 0,children:(0,K.jsx)(vc,{className:`w-4 h-4`})}),ve===e.id&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>ye(null)}),(0,K.jsx)(`div`,{className:`absolute bottom-full left-0 mb-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg py-1 min-w-[130px]`,children:[{mode:1,label:j(`printers.speed.silent`)},{mode:2,label:j(`printers.speed.standard`)},{mode:3,label:j(`printers.speed.sport`)},{mode:4,label:j(`printers.speed.ludicrous`)}].map(({mode:e,label:t})=>(0,K.jsx)(`button`,{onClick:()=>{qn.mutate(e),ye(null)},className:`w-full text-left px-3 py-1.5 text-xs transition-colors ${G.speed_level===e?`text-bambu-green bg-bambu-green/10`:`text-white hover:bg-bambu-dark-tertiary`}`,children:t},e))})]})]})]}),(0,K.jsxs)(`div`,{className:`ml-auto flex items-center justify-end gap-2 flex-shrink-0`,children:[(()=>{let e=!r||i||!F(`printers:control`);return(0,K.jsxs)(`button`,{onClick:()=>n?ke(!0):_e(!0),disabled:e,className:` ${s} ${e?a:n?`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30`:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/30`} `,title:F(`printers:control`)?j(n?`printers.resume`:`printers.pause`):j(`printers.permission.noControl`),children:[n?(0,K.jsx)(El,{className:`w-3 h-3`}):(0,K.jsx)(xl,{className:`w-3 h-3`}),j(n?`printers.resume`:`printers.pause`)]})})(),(()=>{let e=!r||i||!F(`printers:control`);return(0,K.jsxs)(`button`,{onClick:()=>he(!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:F(`printers:control`)?j(`printers.stop`):j(`printers.permission.noControl`),children:[(0,K.jsx)(fu,{className:`w-3 h-3`}),j(`printers.stop`)]})})()]})]})]})})(),(Qt?.length>0||G.vt_tray.length>0)&&r===`expanded`&&(()=>{let t=Qt.filter(e=>e.tray.length>1),n=Qt.filter(e=>e.tray.length===1),r=e.nozzle_count===2||G?.temperatures?.nozzle_2!==void 0,i=`min-w-14`,g=(G.state===`RUNNING`||G.state===`PAUSE`)&&Array.isArray(G.ams_mapping)?G.ams_mapping:[],_=e=>{let t=Math.max(1,e),n=`calc(${t} * 3.5rem + ${Math.max(0,t-1)} * 0.25rem + 1rem)`;return{flex:`1 1 ${n}`,minWidth:n}};return(0,K.jsxs)(`div`,{className:`mt-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:j(`printers.filaments`)}),(0,K.jsx)(sAe,{state:G.ams_filament_backup,onClick:()=>pe(!0)}),(0,K.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[t.map(t=>{let n=Xt[String(t.id)],v=t.id>=128?t.id-128:t.id,y=n===void 0?v:n,b=y===1,S=y===0;return(0,K.jsxs)(`div`,{style:_(4),className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,K.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,K.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,K.jsx)(jW,{ams:t,printerId:e.id,label:Uf(t.id,t.tray.length),amsLabels:Ht,canEdit:F(`printers:update`),onSaved:Ut,children:(0,K.jsx)(`span`,{className:`block truncate text-[10px] text-white font-medium cursor-default select-none`,children:Ht?.[t.id]||Uf(t.id,t.tray.length)})}),r&&(b||S)&&(0,K.jsx)(gW,{side:b?`L`:`R`})]}),(t.humidity!=null||t.temp!=null)&&(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[t.humidity!=null&&(0,K.jsx)(xW,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>ut({amsId:t.id,amsLabel:Uf(t.id,t.tray.length),mode:`humidity`}),compact:!0}),t.temp!=null&&(0,K.jsx)(`div`,{className:`mr-1`,children:(0,K.jsx)(SW,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>ut({amsId:t.id,amsLabel:Uf(t.id,t.tray.length),mode:`temperature`}),compact:!0})}),(G.supports_drying||G.drying_screen_only)&&(t.module_type===`n3f`||t.module_type===`n3s`)&&F(`printers:control`)&&(0,K.jsx)(`button`,{disabled:G.drying_screen_only||!!(t.dry_sf_reason?.length&&t.dry_time===0),onClick:e=>{if(t.dry_time>0)jn.mutate(t.id);else if(Ve===t.id)He(null);else{let n=(t.tray.find(e=>e.tray_type)?.tray_type||`PLA`).split(` `)[0].toUpperCase(),r=x[n]||x.PLA,i=t.module_type;Ke(n),Je(r[i]||r.n3f),Xe(i===`n3s`?r.n3s_hours:r.n3f_hours),Qe(!1),We(t.module_type),He(t.id),et(Vp({triggerRect:e.currentTarget.getBoundingClientRect(),popoverWidth:pW,estimatedHeight:mW,horizontalAlign:`center`}))}},className:`ml-1 flex items-center gap-0.5 px-1 py-0.5 rounded text-[9px] transition-colors ${t.dry_time>0?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:G.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:G.drying_screen_only?j(`printers.drying.screenOnly`):t.dry_time>0?j(`printers.drying.stop`):t.dry_sf_reason?.length?j(`printers.drying.powerRequired`):j(`printers.drying.start`),children:(0,K.jsx)(cc,{className:`w-3 h-3`})})]})]}),t.dry_time>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-amber-50 dark:bg-amber-500/10 px-2 py-1 text-[9px]`,children:[(0,K.jsx)(cc,{className:`w-3 h-3 text-amber-600 dark:text-amber-400 shrink-0`}),(0,K.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400 font-medium`,children:j(`printers.drying.active`)}),t.dry_filament&&t.dry_target_temp!=null&&(0,K.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70`,children:j(`printers.drying.targetSummary`,{filament:t.dry_filament,temp:t.dry_target_temp})}),(0,K.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70`,children:j(`printers.drying.timeRemaining`,{time:t.dry_time>=60?`${Math.floor(t.dry_time/60)}h ${t.dry_time%60}m`:`${t.dry_time}m`})}),!G.drying_screen_only&&(0,K.jsx)(`button`,{onClick:()=>jn.mutate(t.id),disabled:jn.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:j(`printers.drying.stop`),children:(0,K.jsx)(qu,{className:`w-3 h-3`})})]}),(0,K.jsx)(`div`,{className:`grid w-full grid-cols-[repeat(4,minmax(3.5rem,1fr))] gap-1`,children:[0,1,2,3].map(r=>{let a=t.tray[r]||t.tray.find(e=>e.id===r),_=a?.tray_type&&a.remain>=0,v=!a?.tray_type,y=CW(a),b=t.id*4+r,x=tn===b,S=nn!==null&&nn===b,C=rn!==null&&rn===b,w=a?.tray_info_idx?Lt?.[a.tray_info_idx]:null,T=Rt?.[b],E=(a?.tray_uuid||a?.tag_uid||tp(e.serial_number,t.id,r))?.toUpperCase(),D=E?s?.[E]:void 0,O=Qf(D),k=o&&!m?p?.find(n=>n.printer_id===e.id&&n.ams_id===t.id&&n.tray_id===r):void 0,A=k?f?.find(e=>e.id===k.spoolman_spool_id):void 0,M=A&&(A.label_weight??0)>0?Math.round(Math.max(0,(A.label_weight??0)-A.weight_used)/(A.label_weight??1)*100):null,N=u?.(e.id,t.id,r),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&&_&&a.remain>0?null:P,L=O??M??I??(_?a.remain:null),R=O!==null||M!==null?`spoolman`:I===null?_?`ams`:void 0:`inventory`,z=a?.tray_type?{vendor:lp(a)?`Bambu Lab`:`Generic`,profile:T?.preset_name||(A?[A.brand,A.slicer_filament_name?.split(`@`)[0].trim()||A.material].filter(Boolean).join(` `).trim():null)||N?.spool?.slicer_filament_name||w?.name||a.tray_sub_brands||a.tray_type,colorName:nf(a.tray_color||``),colorHex:a.tray_color||null,kFactor:hW(a.k),fillLevel:L,trayUuid:a.tray_uuid||null,tagUid:a.tag_uid||null,fillSource:R}:null,B=or?.amsId===t.id&&or?.slotId===r,V=g.indexOf(b),ee=V>=0?`P${V+1}`:null,te=(0,K.jsxs)(`div`,{className:`relative w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${v?`opacity-50`:``} ${S?`ring-2 ring-amber-400 ring-offset-1 ring-offset-bambu-dark animate-pulse`:C?`ring-2 ring-red-500/60 ring-offset-1 ring-offset-bambu-dark`:x?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[S&&(0,K.jsx)(`span`,{"aria-label":j(`printers.expectedSlot.ariaLabel`,{n:r+1}),title:j(`printers.expectedSlot.title`),className:`absolute top-0.5 left-0.5 px-1 py-px text-[8px] font-bold text-bambu-dark bg-amber-400 rounded pointer-events-none leading-none`,children:`↓`}),ee&&(0,K.jsx)(`span`,{"aria-label":j(`printers.activeJobSlot.ariaLabel`,{n:V+1}),title:j(`printers.activeJobSlot.title`,{n:V+1}),className:`absolute top-0.5 right-0.5 px-1 py-px text-[8px] font-bold text-bambu-dark bg-bambu-green rounded pointer-events-none leading-none`,children:ee}),(0,K.jsx)(fW,{trayColor:a?.tray_color,trayType:a?.tray_type,isEmpty:v,emptyKind:y,slotNumber:r+1}),(0,K.jsx)(`div`,{className:`text-[9px] text-white font-bold truncate`,children:a?.tray_type||j(y===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,K.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:L!==null&&L>=0&&!v&&a&&(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${L}%`,backgroundColor:Zf(L)}})})]});return(0,K.jsxs)(`div`,{className:`relative group w-full ${i}`,children:[B&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-tertiary/80 rounded flex items-center justify-center z-20`,children:(0,K.jsx)(Pl,{className:`w-4 h-4 text-bambu-green animate-spin`})}),z?(0,K.jsx)(dU,{data:z,actions:Lr({amsId:t.id,slotId:r,loadTrayId:t.id*4+r,isRefreshing:B}),spoolman:{enabled:o,linkedSpoolId:k?.spoolman_spool_id??(E?s?.[E]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!k&&!N?()=>{let n=(z.trayUuid||z.tagUid||tp(e.serial_number,t.id,r)).toUpperCase();mt({tagUid:z.tagUid||n,trayUuid:z.trayUuid||``,printerId:e.id,amsId:t.id,trayId:r})}:void 0,onUnlinkSpool:D?.id?()=>kn.mutate(D.id):void 0},inventory:(()=>{if(o){if(m)return;let n=k,i=A;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:()=>gt({printerId:e.id,amsId:t.id,trayId:r,trayInfo:{type:a?.tray_type||z.profile,material:a?.tray_type??void 0,profile:z.profile,color:z.colorHex||``,location:`${Uf(t.id,t.tray.length)} Slot ${r+1}`}}),onUnassignSpool:i&&!lp(a)?()=>h?.(i.id):void 0,isAssigned:!!n||lp(a)}}let n=u?.(e.id,t.id,r);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:()=>gt({printerId:e.id,amsId:t.id,trayId:r,trayInfo:{type:a?.tray_type||z.profile,material:a?.tray_type??void 0,profile:z.profile,color:z.colorHex||``,location:`${Uf(t.id,t.tray.length)} Slot ${r+1}`}}),onUnassignSpool:n&&!lp(a)?()=>d?.(e.id,t.id,r):void 0,isAssigned:!!n||lp(a)}})(),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>vt({amsId:t.id,trayId:r,trayCount:t.tray.length,trayType:a?.tray_type||void 0,trayColor:a?.tray_color||void 0,traySubBrands:a?.tray_sub_brands||void 0,trayInfoIdx:a?.tray_info_idx||void 0,extruderId:n,caliIdx:a?.cali_idx,savedPresetId:T?.preset_id})},children:te}):(0,K.jsx)(fU,{kind:y??void 0,actions:Lr({amsId:t.id,slotId:r,loadTrayId:t.id*4+r,isRefreshing:B}),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>vt({amsId:t.id,trayId:r,trayCount:t.tray.length,extruderId:n})},onAssignSpool:()=>gt({printerId:e.id,amsId:t.id,trayId:r,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`${Uf(t.id,t.tray.length)} Slot ${r+1}`}}),children:te})]},r)})})]},t.id)}),n.map(t=>{let n=Xt[String(t.id)],i=t.id>=128?t.id-128:t.id,_=n===void 0?i:n,v=_===1,y=_===0,b=t.tray[0],S=b?.tray_type&&b.remain>=0,C=!b?.tray_type,w=CW(b),T=Xf(t.id,b?.id??0,!1),E=tn===T,D=nn!==null&&nn===T,O=rn!==null&&rn===T,k=b?.tray_info_idx?Lt?.[b.tray_info_idx]:null,A=Rt?.[T],M=b?.id??0,N=(b?.tray_uuid||b?.tag_uid||tp(e.serial_number,t.id,M))?.toUpperCase(),P=N?s?.[N]:void 0,I=Qf(P),L=u?.(e.id,t.id,M),R=(()=>{let e=L?.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})(),z=R===0&&S&&b.remain>0?null:R,B=o&&!m?p?.find(n=>n.printer_id===e.id&&n.ams_id===t.id&&n.tray_id===M):void 0,V=B?f?.find(e=>e.id===B.spoolman_spool_id):void 0,ee=V&&(V.label_weight??0)>0?Math.round(Math.max(0,(V.label_weight??0)-V.weight_used)/(V.label_weight??1)*100):null,te=I??ee??z??(S?b.remain:null),ne=I!==null||ee!==null?`spoolman`:z===null?S?`ams`:void 0:`inventory`,re=b?.tray_type?{vendor:lp(b)?`Bambu Lab`:`Generic`,profile:A?.preset_name||(V?[V.brand,V.slicer_filament_name?.split(`@`)[0].trim()||V.material].filter(Boolean).join(` `).trim():null)||L?.spool?.slicer_filament_name||k?.name||b.tray_sub_brands||b.tray_type,colorName:nf(b.tray_color||``),colorHex:b.tray_color||null,kFactor:hW(b.k),fillLevel:te,trayUuid:b.tray_uuid||null,tagUid:b.tag_uid||null,fillSource:ne}:null,ie=or?.amsId===t.id&&or?.slotId===M,H=g.indexOf(T),ae=H>=0?`P${H+1}`:null,oe=(0,K.jsxs)(`div`,{className:`relative w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${C?`opacity-50`:``} ${D?`ring-2 ring-amber-400 ring-offset-1 ring-offset-bambu-dark animate-pulse`:O?`ring-2 ring-red-500/60 ring-offset-1 ring-offset-bambu-dark`:E?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[D&&(0,K.jsx)(`span`,{"aria-label":j(`printers.expectedSlot.ariaLabel`,{n:1}),title:j(`printers.expectedSlot.title`),className:`absolute top-0.5 left-0.5 px-1 py-px text-[8px] font-bold text-bambu-dark bg-amber-400 rounded pointer-events-none leading-none`,children:`↓`}),ae&&(0,K.jsx)(`span`,{"aria-label":j(`printers.activeJobSlot.ariaLabel`,{n:H+1}),title:j(`printers.activeJobSlot.title`,{n:H+1}),className:`absolute top-0.5 right-0.5 px-1 py-px text-[8px] font-bold text-bambu-dark bg-bambu-green rounded pointer-events-none leading-none`,children:ae}),(0,K.jsx)(fW,{trayColor:b?.tray_color,trayType:b?.tray_type,isEmpty:C,emptyKind:w,slotNumber:1}),(0,K.jsx)(`div`,{className:`text-[9px] text-white font-bold truncate`,children:b?.tray_type||j(w===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,K.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:te!==null&&te>=0&&!C&&(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${te}%`,backgroundColor:Zf(te)}})})]});return(0,K.jsxs)(`div`,{style:{flex:`1 1 11rem`,minWidth:`11rem`},className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,K.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,K.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,K.jsx)(jW,{ams:t,printerId:e.id,label:Uf(t.id,t.tray.length),amsLabels:Ht,canEdit:F(`printers:update`),onSaved:Ut,children:(0,K.jsx)(`span`,{className:`block truncate text-[10px] text-white font-medium cursor-default select-none`,children:Ht?.[t.id]||Uf(t.id,t.tray.length)})}),r&&(v||y)&&(0,K.jsx)(gW,{side:v?`L`:`R`})]}),(G.supports_drying||G.drying_screen_only)&&(t.module_type===`n3f`||t.module_type===`n3s`)&&F(`printers:control`)&&(0,K.jsx)(`div`,{className:`relative ml-auto`,children:(0,K.jsx)(`button`,{disabled:G.drying_screen_only,onClick:e=>{if(t.dry_time>0)jn.mutate(t.id);else if(Ve===t.id)He(null);else{let n=(t.tray.find(e=>e.tray_type)?.tray_type||`PLA`).split(` `)[0].toUpperCase(),r=x[n]||x.PLA,i=t.module_type;Ke(n),Je(r[i]||r.n3f),Xe(i===`n3s`?r.n3s_hours:r.n3f_hours),Qe(!1),We(t.module_type),He(t.id),et(Vp({triggerRect:e.currentTarget.getBoundingClientRect(),popoverWidth:pW,estimatedHeight:mW,horizontalAlign:`center`}))}},className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[9px] transition-colors ${t.dry_time>0?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:G.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:G.drying_screen_only?j(`printers.drying.screenOnly`):t.dry_time>0?j(`printers.drying.stop`):j(`printers.drying.start`),children:(0,K.jsx)(cc,{className:`w-3 h-3`})})})]}),t.dry_time>0&&(0,K.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-[9px]`,children:[(0,K.jsx)(cc,{className:`w-3 h-3 text-amber-600 dark:text-amber-400 shrink-0`}),t.dry_filament&&t.dry_target_temp!=null&&(0,K.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70 text-[8px] truncate`,children:j(`printers.drying.targetSummary`,{filament:t.dry_filament,temp:t.dry_target_temp})}),(0,K.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70 text-[8px] truncate`,children:t.dry_time>=60?`${Math.floor(t.dry_time/60)}h ${t.dry_time%60}m`:`${t.dry_time}m`}),!G.drying_screen_only&&(0,K.jsx)(`button`,{onClick:()=>jn.mutate(t.id),disabled:jn.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:j(`printers.drying.stop`),children:(0,K.jsx)(qu,{className:`w-3 h-3`})})]}),(0,K.jsxs)(`div`,{className:`flex gap-1.5 max-[550px]:flex-col max-[550px]:items-start`,children:[(0,K.jsxs)(`div`,{className:`relative group min-w-14 flex-1`,children:[ie&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-tertiary/80 rounded flex items-center justify-center z-20`,children:(0,K.jsx)(Pl,{className:`w-4 h-4 text-bambu-green animate-spin`})}),re?(0,K.jsx)(dU,{data:re,actions:Lr({amsId:t.id,slotId:M,loadTrayId:t.id*4+M,isRefreshing:ie}),spoolman:{enabled:o,linkedSpoolId:B?.spoolman_spool_id??(N?s?.[N]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!B&&!L?()=>{let n=(re.trayUuid||re.tagUid||tp(e.serial_number,t.id,M)).toUpperCase();mt({tagUid:re.tagUid||n,trayUuid:re.trayUuid||``,printerId:e.id,amsId:t.id,trayId:M})}:void 0,onUnlinkSpool:P?.id?()=>kn.mutate(P.id):void 0},inventory:(()=>{if(o){if(m)return;let n=B,r=V;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:()=>gt({printerId:e.id,amsId:t.id,trayId:M,trayInfo:{type:b?.tray_type||re.profile,material:b?.tray_type??void 0,profile:re.profile,color:re.colorHex||``,location:Uf(t.id,t.tray.length)}}),onUnassignSpool:r&&!lp(b)?()=>h?.(r.id):void 0,isAssigned:!!n||lp(b)}}let n=u?.(e.id,t.id,M);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:()=>gt({printerId:e.id,amsId:t.id,trayId:M,trayInfo:{type:b?.tray_type||re.profile,material:b?.tray_type??void 0,profile:re.profile,color:re.colorHex||``,location:Uf(t.id,t.tray.length)}}),onUnassignSpool:n&&!lp(b)?()=>d?.(e.id,t.id,M):void 0,isAssigned:!!n||lp(b)}})(),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>vt({amsId:t.id,trayId:M,trayCount:t.tray.length,trayType:b?.tray_type||void 0,trayColor:b?.tray_color||void 0,traySubBrands:b?.tray_sub_brands||void 0,trayInfoIdx:b?.tray_info_idx||void 0,extruderId:n,caliIdx:b?.cali_idx,savedPresetId:A?.preset_id})},children:oe}):(0,K.jsx)(fU,{kind:w??void 0,actions:Lr({amsId:t.id,slotId:M,loadTrayId:t.id*4+M,isRefreshing:ie}),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>vt({amsId:t.id,trayId:M,trayCount:t.tray.length,extruderId:n})},onAssignSpool:()=>gt({printerId:e.id,amsId:t.id,trayId:M,trayInfo:{type:``,material:void 0,profile:``,color:``,location:Uf(t.id,t.tray.length)}}),children:oe})]}),(t.humidity!=null||t.temp!=null)&&(0,K.jsxs)(`div`,{className:`flex flex-col justify-center gap-1 shrink-0 max-[550px]:w-full`,children:[t.temp!=null&&(0,K.jsx)(SW,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>ut({amsId:t.id,amsLabel:Uf(t.id,t.tray.length),mode:`temperature`}),compact:!0}),t.humidity!=null&&(0,K.jsx)(xW,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>ut({amsId:t.id,amsLabel:Uf(t.id,t.tray.length),mode:`humidity`}),compact:!0})]})]})]},t.id)}),G.vt_tray.length>0&&(0,K.jsxs)(`div`,{style:_(G.vt_tray.length),className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,K.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,K.jsx)(`span`,{className:`block min-w-0 flex-1 truncate text-[10px] text-white font-medium`,children:j(`printers.external`)})}),(0,K.jsx)(`div`,{className:`grid w-full ${G.vt_tray.length>1?`grid-cols-[repeat(2,minmax(3.5rem,1fr))]`:`grid-cols-[minmax(3.5rem,1fr)]`} gap-1`,children:[...G.vt_tray].sort((e,t)=>(e.id??254)-(t.id??254)).map(t=>{let n=t.id??254,a=r&&tn===254?n===254&&G.active_extruder===1||n===255&&G.active_extruder===0:tn===n,g=n-254,_=r?j(n===254?`printers.extL`:`printers.extR`):``,v=t.tray_info_idx?Lt?.[t.tray_info_idx]:null,y=Rt?.[1020+g],b=(t.tray_uuid||t.tag_uid||tp(e.serial_number,255,g))?.toUpperCase(),x=b?s?.[b]:void 0,S=Qf(x),C=u?.(e.id,255,g),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===g):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),M=S!==null||k!==null?`spoolman`:E===null?T?`ams`:void 0:`inventory`,N={vendor:lp(t)?`Bambu Lab`:`Generic`,profile:y?.preset_name||(O?[O.brand,O.slicer_filament_name?.split(`@`)[0].trim()||O.material].filter(Boolean).join(` `).trim():null)||C?.spool?.slicer_filament_name||v?.name||t.tray_sub_brands||t.tray_type||`Unknown`,colorName:nf(t.tray_color||``),colorHex:t.tray_color||null,kFactor:hW(t.k),fillLevel:A,trayUuid:t.tray_uuid||null,tagUid:t.tag_uid||null,fillSource:M},P=!t.tray_type,I=CW(t),L=(0,K.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${P?`opacity-50`:``} ${a?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[(0,K.jsx)(fW,{trayColor:t.tray_color,trayType:t.tray_type,isEmpty:P,emptyKind:I,slotNumber:r?n===254?`L`:`R`:g+1}),(0,K.jsx)(`div`,{className:`text-[9px] font-bold truncate ${P?`text-white/40`:`text-white`}`,children:t.tray_type||j(`ams.slotEmpty`)}),(0,K.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:A!==null&&A>=0&&!P&&(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${A}%`,backgroundColor:Zf(A)}})})]});return(0,K.jsx)(`div`,{className:`relative group w-full ${i}`,children:P?(0,K.jsx)(fU,{kind:I??void 0,actions:Lr({amsId:255,slotId:g,loadTrayId:n,includeRfid:!1}),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>vt({amsId:255,trayId:g,trayCount:1,extruderId:r?+(n===254):void 0})},onAssignSpool:()=>gt({printerId:e.id,amsId:255,trayId:g,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`External Slot ${g+1}`}}),children:L}):(0,K.jsx)(dU,{data:N,actions:Lr({amsId:255,slotId:g,loadTrayId:n,includeRfid:!1}),spoolman:{enabled:o,linkedSpoolId:D?.spoolman_spool_id??(b?s?.[b]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!D&&!C?()=>{let t=(N.trayUuid||N.tagUid||tp(e.serial_number,255,g)).toUpperCase();mt({tagUid:N.tagUid||t,trayUuid:N.trayUuid||``,printerId:e.id,amsId:255,trayId:g})}:void 0,onUnlinkSpool:x?.id?()=>kn.mutate(x.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:()=>gt({printerId:e.id,amsId:255,trayId:g,trayInfo:{type:t.tray_type||N.profile,material:t.tray_type??void 0,profile:N.profile,color:N.colorHex||``,location:_||j(`printers.external`)}}),onUnassignSpool:r&&!lp(t)?()=>h?.(r.id):void 0,isAssigned:!!n||lp(t)}}let n=u?.(e.id,255,g);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:()=>gt({printerId:e.id,amsId:255,trayId:g,trayInfo:{type:t.tray_type||N.profile,material:t.tray_type??void 0,profile:N.profile,color:N.colorHex||``,location:_||j(`printers.external`)}}),onUnassignSpool:n&&!lp(t)?()=>d?.(e.id,255,g):void 0,isAssigned:!!n||lp(t)}})(),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>vt({amsId:255,trayId:g,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:r?+(n===254):void 0,caliIdx:t.cali_idx,savedPresetId:y?.preset_id})},children:L})},n)})})]})]})]})})()]}),r===`expanded`&&(0,K.jsxs)(`div`,{className:`mt-auto`,children:[sn&&(0,K.jsxs)(`div`,{className:`pt-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:j(`printers.power`,`Power`)}),(0,K.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 rounded-[10px] bg-bambu-dark p-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 pl-1`,children:[(0,K.jsx)(Yu,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm text-white truncate`,children:sn.name}),(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray text-[10px] font-medium flex-shrink-0`,title:j(`smartPlugs.power`),children:ln?.energy?.power!==null&&ln?.energy?.power!==void 0?`${Math.round(ln.energy.power)}W`:`--`})]}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>Pn.mutate(!sn.auto_off),disabled:Pn.isPending||sn.auto_off_executed||!F(`smart_plugs:control`),title:F(`smart_plugs:control`)?sn.auto_off_executed?j(`printers.autoOffExecuted`):j(`printers.autoOffAfterPrint`):j(`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 ${F(`smart_plugs:control`)?sn.auto_off||sn.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,K.jsx)(ws,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>{ln?.state===`ON`?se(!0):oe(!0)},disabled:Nn.isPending||!F(`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 ${F(`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:F(`smart_plugs:control`)?ln?.state===`ON`?`Turn off`:`Turn on`:j(`printers.permission.noSmartPlugControl`),children:(0,K.jsx)(Yu,{className:`w-4 h-4`})})]})]}),cn&&cn.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,K.jsx)(Nc,{className:`w-3.5 h-3.5 text-blue-600 dark:text-blue-400 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`HA:`}),(0,K.jsx)(`div`,{className:`h-[2px] w-5 bg-bambu-dark-tertiary/50`}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:cn.map(e=>{let t=e.ha_entity_id?.startsWith(`script.`);return(0,K.jsxs)(`button`,{onClick:()=>{t?Fn.mutate({id:e.id,action:`on`}):le(e)},disabled:Fn.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,K.jsx)(El,{className:`w-2.5 h-2.5`}),e.name]},e.id)})})]})]}),(0,K.jsxs)(`div`,{className:`pt-4`,children:[(0,K.jsx)(`div`,{className:`mb-3 h-[2px] bg-bambu-dark-tertiary`}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[Rr,(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>{if(_===`embedded`&&v)v(e.id,e.name);else{let t=localStorage.getItem(`cameraWindowState`),n=t?JSON.parse(t):{width:640,height:400},r=[`width=${n.width}`,`height=${n.height}`,n.left===void 0?``:`left=${n.left}`,n.top===void 0?``:`top=${n.top}`,`menubar=no,toolbar=no,location=no,status=no`].filter(Boolean).join(`,`);window.open(`/camera/${e.id}`,`camera-${e.id}`,r)}},disabled:!G?.connected||!F(`camera:view`),title:F(`camera:view`)?j(_===`embedded`?`printers.openCameraOverlay`:`printers.openCameraWindow`):j(`printers.permission.noCamera`),className:Ir,children:(0,K.jsx)(Lu,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>re(!0),disabled:!Jt||!F(`printers:files`),title:F(`printers:files`)?j(`printers.browseFiles`):j(`printers.permission.noFiles`),className:Ir,children:(0,K.jsx)(Dc,{className:`w-4 h-4`})}),Jt&&G?.state!==`RUNNING`&&G?.state!==`PAUSE`&&(0,K.jsxs)($,{size:`sm`,onClick:()=>Ne(!0),disabled:!F(`library:upload`)||!F(`queue:create`),title:F(`library:upload`)?F(`queue:create`)?j(`common.print`):j(`fileManager.noPermissionAddToQueue`):j(`fileManager.noPermissionUpload`),className:`!h-8 !min-h-8 !px-2 !py-0 !bg-bambu-green hover:!bg-bambu-green/80 !text-white`,children:[(0,K.jsx)(jl,{className:`w-4 h-4`}),j(`common.print`)]})]})]})]})]})]}),ne&&(0,K.jsx)(yle,{printerId:e.id,printerName:e.name,onClose:()=>re(!1)}),Me&&(0,K.jsx)(JU,{folderId:null,onClose:()=>Ne(!1),onUploadComplete:()=>{},autoUpload:!0,accept:`.gcode,.3mf`,validateFile:e=>{let t=e.name.toLowerCase();if(!t.endsWith(`.gcode`)&&!t.includes(`.gcode.`))return j(`printers.dropNotPrintable`,`Only .gcode and .gcode.3mf files can be printed`)},onFileUploaded:t=>{let n=t.metadata?.sliced_for_model,r=AW(e.model);if(n&&r&&n.toLowerCase()!==r.toLowerCase())return Q.deleteLibraryFile(t.id).catch(()=>{}),j(`printers.incompatibleFile`,`This file was sliced for {{slicedFor}}, but this printer is a {{printerModel}}`,{slicedFor:n,printerModel:r});Be({id:t.id,filename:t.filename})}}),ze&&(0,K.jsx)(uW,{mode:`create`,libraryFileId:ze.id,archiveName:ze.filename,initialSelectedPrinterIds:[e.id],onClose:()=>Be(null),onSuccess:()=>Be(null),cleanupLibraryAfterDispatch:!0}),ie&&(0,K.jsx)(Nle,{printerId:e.id,printerName:e.name,onClose:()=>H(!1)}),Ie&&(0,K.jsx)(vp,{printerId:e.id,printerName:e.name,onClose:()=>Le(!1)}),Pe&&(0,K.jsx)(Xke,{printer:e,status:G,totalPrintHours:n?.total_print_hours,onClose:Re}),xt&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:()=>xr(),children:(0,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[xt.needs_calibration?(0,K.jsx)(Hl,{className:`w-5 h-5 text-blue-500`}):xt.is_empty?(0,K.jsx)(hs,{className:`w-5 h-5 text-green-500`}):(0,K.jsx)(xs,{className:`w-5 h-5 text-yellow-500`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:`Build Plate Check`}),xt.reference_count!==void 0&&xt.max_references&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[xt.reference_count,`/`,xt.max_references,` refs`]})]}),(0,K.jsx)(`button`,{onClick:()=>xr(),className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[xt.needs_calibration?(0,K.jsxs)(K.Fragment,{children:[(0,K.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,K.jsx)(`p`,{className:`font-medium text-blue-700 dark:text-blue-400`,children:j(`printers.plateDetection.calibrationRequired`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,dangerouslySetInnerHTML:{__html:j(`printers.plateDetection.calibrationInstructions`)}})]}),(0,K.jsxs)(`div`,{className:`text-sm text-bambu-gray space-y-2`,children:[(0,K.jsx)(`p`,{children:j(`printers.plateDetection.calibrationDescription`)}),(0,K.jsx)(`p`,{dangerouslySetInnerHTML:{__html:j(`printers.plateDetection.calibrationTip`)}})]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`p-3 rounded-lg ${xt.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,K.jsx)(`p`,{className:`font-medium ${xt.is_empty?`text-green-700 dark:text-green-400`:`text-yellow-700 dark:text-yellow-400`}`,children:xt.is_empty?j(`printers.plateDetection.plateEmpty`):j(`printers.plateDetection.objectsDetected`)}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:[j(`printers.plateDetection.confidence`),`: `,Math.round(xt.confidence*100),`% | `,j(`printers.plateDetection.difference`),`: `,xt.difference_percent.toFixed(1),`%`]})]}),xt.debug_image_url&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:j(`printers.plateDetection.analysisPreview`)}),(0,K.jsx)(`img`,{src:xt.debug_image_url,alt:j(`printers.plateDetection.analysisPreview`),className:`w-full rounded-lg border border-bambu-dark-tertiary`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:j(`printers.plateDetection.analysisLegend`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:xt.message})]}),mr&&mr.references.length>0&&(0,K.jsxs)(`div`,{className:`mt-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white shrink-0`,children:j(`printers.plateDetection.savedReferences`,{count:mr.references.length,max:mr.max_references})}),(0,K.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-5 gap-2`,children:mr.references.map(t=>(0,K.jsxs)(`div`,{className:`relative group`,children:[(0,K.jsx)(`img`,{src:Q.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,K.jsx)(`button`,{onClick:()=>wr(t.index),className:`absolute top-1 right-1 p-0.5 bg-red-500/80 rounded opacity-0 group-hover:opacity-100 transition-opacity`,title:j(`printers.plateDetection.deleteReference`),children:(0,K.jsx)(qu,{className:`w-3 h-3 text-white`})}),gr?.index===t.index?(0,K.jsx)(`input`,{type:`text`,value:gr.label,onChange:e=>_r({...gr,label:e.target.value}),onBlur:()=>Cr(t.index,gr.label),onKeyDown:e=>{e.key===`Enter`&&Cr(t.index,gr.label),e.key===`Escape`&&_r(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:j(`printers.plateDetection.labelPlaceholder`)}):(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1 truncate cursor-pointer hover:text-white`,onClick:()=>_r({index:t.index,label:t.label}),title:t.label?j(`printers.plateDetection.clickToEdit`,{label:t.label}):j(`printers.plateDetection.clickToAddLabel`),children:t.label||(0,K.jsx)(`span`,{className:`italic opacity-50`,children:j(`printers.noLabel`)})}),(0,K.jsx)(`p`,{className:`text-[10px] text-bambu-gray/60`,children:t.timestamp?jf(t.timestamp)?.toLocaleDateString()??``:``})]},t.index))})]}),!xt.needs_calibration&&(0,K.jsxs)(`div`,{className:`mt-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white shrink-0`,children:j(`printers.roi.title`)}),(0,K.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),Dt?(0,K.jsxs)(`div`,{className:`flex gap-1`,children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>Ot(null),disabled:kt,children:j(`common.cancel`)}),(0,K.jsx)($,{size:`sm`,onClick:Tr,disabled:kt,children:kt?(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`}):j(`common.save`)})]}):(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>Ot(xt.roi||{x:.15,y:.35,w:.7,h:.55}),children:[(0,K.jsx)(wl,{className:`w-3 h-3 mr-1`}),j(`common.edit`)]})]}),Dt?(0,K.jsxs)(`div`,{className:`space-y-3 bg-bambu-dark-tertiary/50 p-3 rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:j(`printers.roi.xStart`)}),(0,K.jsx)(`input`,{type:`range`,min:`0`,max:`0.9`,step:`0.01`,value:Dt.x,onChange:e=>Ot({...Dt,x:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Dt.x*100),`%`]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:j(`printers.roi.yStart`)}),(0,K.jsx)(`input`,{type:`range`,min:`0`,max:`0.9`,step:`0.01`,value:Dt.y,onChange:e=>Ot({...Dt,y:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Dt.y*100),`%`]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:j(`printers.width`)}),(0,K.jsx)(`input`,{type:`range`,min:`0.1`,max:`1`,step:`0.01`,value:Dt.w,onChange:e=>Ot({...Dt,w:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Dt.w*100),`%`]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:j(`printers.height`)}),(0,K.jsx)(`input`,{type:`range`,min:`0.1`,max:`1`,step:`0.01`,value:Dt.h,onChange:e=>Ot({...Dt,h:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Dt.h*100),`%`]})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:j(`printers.roi.instruction`)})]}):(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[`Current: X=`,Math.round((xt.roi?.x||.15)*100),`%, Y=`,Math.round((xt.roi?.y||.35)*100),`%, W=`,Math.round((xt.roi?.w||.7)*100),`%, H=`,Math.round((xt.roi?.h||.55)*100),`%`]})]})]}),(0,K.jsx)(`div`,{className:`flex justify-end gap-2 p-4`,children:xt.needs_calibration?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)($,{variant:`ghost`,onClick:()=>xr(),children:j(`common.cancel`)}),(0,K.jsx)($,{onClick:()=>Sr(),disabled:Tt,children:Tt?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 mr-2 animate-spin`}),`Calibrating...`]}):`Calibrate Empty Plate`})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)($,{variant:`ghost`,onClick:()=>Sr(),disabled:Tt,children:Tt?`Adding...`:`Add Reference (${mr?.references.length||0}/${mr?.max_references||5})`}),(0,K.jsx)($,{onClick:()=>xr(),children:`Close`})]})})]})}),ae&&sn&&(0,K.jsx)(Vd,{title:j(`printers.confirm.powerOnTitle`),message:j(`printers.confirm.powerOnMessage`,{name:e.name}),confirmText:j(`printers.confirm.powerOnButton`),variant:`default`,onConfirm:()=>{Nn.mutate(`on`),oe(!1)},onCancel:()=>oe(!1)}),er&&(0,K.jsx)(Vd,{title:j(`printers.maintenance.confirmMidPrintTitle`),message:j(`printers.maintenance.confirmMidPrintMessage`,{name:e.name}),confirmText:j(`printers.maintenance.menuEnter`),variant:`danger`,onConfirm:()=>{$n.mutate(!1),tr(!1)},onCancel:()=>tr(!1)}),U&&sn&&(0,K.jsx)(Vd,{title:j(`printers.confirm.powerOffTitle`),message:G?.state===`RUNNING`?j(`printers.confirm.powerOffWarning`,{name:e.name}):j(`printers.confirm.powerOffMessage`,{name:e.name}),confirmText:j(`printers.confirm.powerOffButton`),variant:`danger`,onConfirm:()=>{Nn.mutate(`off`),se(!1)},onCancel:()=>se(!1)}),ce&&(0,K.jsx)(Vd,{title:j(`printers.confirm.haToggleTitle`,{name:ce.name}),message:G?.state===`RUNNING`?j(`printers.confirm.haToggleWarning`,{name:e.name,entity:ce.ha_entity_id||ce.name}):j(`printers.confirm.haToggleMessage`,{entity:ce.ha_entity_id||ce.name}),confirmText:j(`printers.confirm.haToggleButton`),variant:G?.state===`RUNNING`?`danger`:`default`,onConfirm:()=>{Fn.mutate({id:ce.id,action:`toggle`}),le(null)},onCancel:()=>le(null)}),me&&(0,K.jsx)(Vd,{title:j(`printers.confirm.stopTitle`),message:j(`printers.confirm.stopMessage`,{name:e.name}),confirmText:j(`printers.confirm.stopButton`),variant:`danger`,onConfirm:()=>{In.mutate(),he(!1)},onCancel:()=>he(!1)}),ge&&(0,K.jsx)(Vd,{title:j(`printers.confirm.pauseTitle`),message:j(`printers.confirm.pauseMessage`,{name:e.name}),confirmText:j(`printers.confirm.pauseButton`),variant:`default`,onConfirm:()=>{Ln.mutate(),_e(!1)},onCancel:()=>_e(!1)}),Oe&&(0,K.jsx)(Vd,{title:j(`printers.confirm.resumeTitle`),message:j(`printers.confirm.resumeMessage`,{name:e.name}),confirmText:j(`printers.confirm.resumeButton`),variant:`default`,onConfirm:()=>{Rn.mutate(),ke(!1)},onCancel:()=>ke(!1)}),(0,K.jsx)(hT,{printerId:e.id,isOpen:Ae,onClose:()=>je(!1)}),ue&&(0,K.jsx)(fee,{printerName:e.name,errors:G?.hms_errors||[],onClose:()=>de(!1),printerId:e.id,hasPermission:F,runoutGuidance:on}),fe&&G&&(0,K.jsx)(vke,{isOpen:fe,state:G.ams_filament_backup,amsUnits:G.ams,amsExtruderMap:G.ams_extruder_map,isDualNozzle:e.nozzle_count===2||G?.temperatures?.nozzle_2!==void 0,canToggle:F(`printers:control`),pending:Mn.isPending,onToggle:e=>Mn.mutate(e),onClose:()=>pe(!1)}),lt&&(0,K.jsx)(mke,{isOpen:!!lt,onClose:()=>ut(null),printerId:e.id,printerName:e.name,amsId:lt.amsId,amsLabel:lt.amsLabel,initialMode:lt.mode,thresholds:a}),dt&&(0,K.jsx)(bke,{isOpen:!!dt,onClose:()=>ft(null),printerId:e.id,printerName:e.name,initialKind:dt.initialKind,availableKinds:dt.availableKinds}),pt&&(0,K.jsx)(pU,{isOpen:!!pt,onClose:()=>mt(null),tagUid:pt.tagUid,trayUuid:pt.trayUuid,printerId:pt.printerId,amsId:pt.amsId,trayId:pt.trayId}),ht&&(0,K.jsx)(hU,{isOpen:!!ht,onClose:()=>gt(null),printerId:ht.printerId,amsId:ht.amsId,trayId:ht.trayId,trayInfo:ht.trayInfo,spoolmanEnabled:!!o}),_t&&(0,K.jsx)(KU,{isOpen:!!_t,onClose:()=>vt(null),printerId:e.id,slotInfo:_t,printerModel:AW(e.model)||void 0,nozzleDiameter:cp(G,_t.amsId),onSuccess:()=>{M.invalidateQueries({queryKey:[`slotPresets`,e.id]}),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})}}),ee&&(0,K.jsx)(_Ae,{printer:e,onClose:()=>te(!1)}),yt&&Nt&&(0,K.jsx)(gAe,{printer:e,firmwareInfo:Nt,onClose:()=>bt(!1)}),Ve!==null&&$e&&(()=>{let e=Ue===`n3s`?85:65,t=e+10;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-[100]`,onClick:()=>He(null)}),(0,K.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:{top:$e.top,left:$e.left,maxHeight:`calc(100dvh - ${$e.top}px - 8px)`},onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`shrink-0 flex items-center justify-center gap-2 px-3 py-2.5`,children:[(0,K.jsx)(cc,{className:`w-3.5 h-3.5 text-bambu-green`}),(0,K.jsx)(`span`,{className:`text-sm text-white font-medium text-center`,children:j(`printers.drying.start`)})]}),(0,K.jsx)(`div`,{className:`shrink-0 h-px bg-bambu-dark-tertiary`}),(0,K.jsxs)(`div`,{className:`px-3 py-2.5 space-y-2.5 overflow-y-auto min-h-0`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-[10px] text-white/70 font-medium mb-1 block`,children:j(`printers.filaments`)}),(0,K.jsx)(wW,{value:Ge,options:Object.keys(x).map(e=>({value:e,label:e})),onChange:e=>{Ke(e);let t=x[e];t&&(Je(t[Ue===`n3s`?`n3s`:`n3f`]),Xe(Ue===`n3s`?t.n3s_hours:t.n3f_hours))},fullWidth:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,K.jsx)(`label`,{className:`text-[10px] text-white/70 font-medium`,children:j(`printers.drying.temperature`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`input`,{type:`number`,min:45,max:e,value:qe,onChange:t=>Je(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-[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,K.jsx)(`span`,{className:`text-[10px] text-bambu-gray`,children:`°C`})]})]}),(0,K.jsx)(`input`,{type:`range`,min:35,max:t,value:qe,onChange:t=>Je(Math.min(e,Math.max(45,Number(t.target.value)))),className:`w-full h-1 accent-bambu-green cursor-pointer`}),(0,K.jsxs)(`div`,{className:`flex justify-between text-[9px] text-bambu-gray/50 mt-0.5`,children:[(0,K.jsx)(`span`,{children:`45°C`}),(0,K.jsxs)(`span`,{children:[e,`°C`]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,K.jsx)(`label`,{className:`text-[10px] text-white/70 font-medium`,children:j(`printers.drying.duration`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`input`,{type:`number`,min:1,max:24,value:Ye,onChange:e=>Xe(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-[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,K.jsx)(`span`,{className:`text-[10px] text-bambu-gray`,children:j(`printers.drying.hours`)})]})]}),(0,K.jsx)(`input`,{type:`range`,min:1,max:24,value:Ye,onChange:e=>Xe(Number(e.target.value)),className:`w-full h-1 accent-bambu-green cursor-pointer`}),(0,K.jsxs)(`div`,{className:`flex justify-between text-[9px] text-bambu-gray/50 mt-0.5`,children:[(0,K.jsx)(`span`,{children:`1h`}),(0,K.jsx)(`span`,{children:`24h`})]})]}),(()=>{let e=((Ve===null?void 0:Qt.find(e=>e.id===Ve))?.tray??[]).some(e=>e.state===11),t=Ze&&!e;return(0,K.jsx)(`button`,{type:`button`,onClick:()=>Qe(e=>!e),"aria-pressed":t,disabled:e,title:e?j(`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:j(`printers.drying.rotateTray`)})})()]}),(0,K.jsx)(`div`,{className:`shrink-0 h-px bg-bambu-dark-tertiary`}),(0,K.jsx)(`div`,{className:`shrink-0 px-3 pt-2.5 pb-3`,children:(0,K.jsx)(`button`,{onClick:()=>{if(Ve!==null){let e=(Qt.find(e=>e.id===Ve)?.tray??[]).some(e=>e.state===11);An.mutate({amsId:Ve,temp:qe,duration:Ye,filament:Ge,rotateTray:Ze&&!e})}},disabled:An.isPending,"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:An.isPending?j(`printers.drying.startingDrying`):j(`printers.drying.start`)})})]})]})})()]})}function hAe({onClose:e,onAdd:t,existingSerials:n}){let{t:r}=W(),[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)(()=>{ld.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 Q.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 ld.startSubnetScan(e);let t=setInterval(async()=>{try{let e=await ld.getScanStatus();E({scanned:e.scanned,total:e.total}),l(await ld.getDiscoveredPrinters()),e.running||(clearInterval(t),s(!1),p(!0))}catch(e){console.error(`Failed to get scan status:`,e)}},500)}else{await ld.startDiscovery(10);let e=setInterval(async()=>{try{l(await ld.getDiscoveredPrinters())}catch(e){console.error(`Failed to get discovered printers:`,e)}},1e3);setTimeout(async()=>{clearInterval(e);try{await ld.stopDiscovery()}catch{}s(!1),p(!0);try{l(await ld.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:AW(e.model)}),l([])};return(0,y.useEffect)(()=>()=>{ld.stopDiscovery().catch(()=>{}),ld.stopSubnetScan().catch(()=>{})},[]),(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,K.jsxs)(K.Fragment,{children:[(0,K.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,K.jsx)(Ed,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(Od,{children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold mb-4`,children:r(`printers.addPrinter`)}),(0,K.jsxs)(`div`,{className:`mb-4 pb-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`mb-3`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.discovery.subnetToScan`)}),g.length>0?(0,K.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,K.jsx)(`option`,{value:e,children:e},e)),(0,K.jsx)(`option`,{value:`__custom__`,children:r(`printers.discovery.customSubnetOption`)})]}):(0,K.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,K.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,K.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:r(m?`printers.discovery.dockerNote`:`printers.discovery.customSubnetNote`)})]}),(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:F,disabled:o,className:`w-full`,children:o?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{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,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Wl,{className:`w-4 h-4`}),r(m||C?`printers.discovery.scanSubnet`:`printers.discovery.discoverNetwork`)]})}),u&&(0,K.jsx)(`div`,{className:`mt-2 text-sm text-red-700 dark:text-red-400`,children:u}),N.length>0&&(0,K.jsx)(`div`,{className:`mt-3 space-y-2 max-h-40 overflow-y-auto`,children:N.map(e=>(0,K.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,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`font-medium text-white text-sm truncate`,children:e.name||e.serial}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[AW(e.model)||r(`printers.discovery.unknown`),` • `,e.ip_address,e.serial.startsWith(`unknown-`)&&(0,K.jsxs)(`span`,{className:`text-yellow-500`,children:[` • `,r(`printers.discovery.serialRequired`)]})]})]}),(0,K.jsx)(ss,{className:`w-4 h-4 text-bambu-gray -rotate-90 flex-shrink-0 ml-2`})]},e.serial))}),o&&(0,K.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,K.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,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray text-center`,children:r(`printers.discovery.allConfigured`)})]}),(0,K.jsxs)(`form`,{onSubmit:P,className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.name`)}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.ipAddress`)}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.serialNumber`)}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.accessCode`)}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.modal.modelOptional`)}),(0,K.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,K.jsx)(`option`,{value:``,children:r(`printers.modal.selectModel`)}),(0,K.jsxs)(`optgroup`,{label:`A1 Series`,children:[(0,K.jsx)(`option`,{value:`A1`,children:`A1`}),(0,K.jsx)(`option`,{value:`A1 Mini`,children:`A1 Mini`})]}),(0,K.jsx)(`optgroup`,{label:`A2 Series`,children:(0,K.jsx)(`option`,{value:`A2L`,children:`A2L`})}),(0,K.jsxs)(`optgroup`,{label:`H2 Series`,children:[(0,K.jsx)(`option`,{value:`H2C`,children:`H2C`}),(0,K.jsx)(`option`,{value:`H2D`,children:`H2D`}),(0,K.jsx)(`option`,{value:`H2D Pro`,children:`H2D Pro`}),(0,K.jsx)(`option`,{value:`H2S`,children:`H2S`})]}),(0,K.jsxs)(`optgroup`,{label:`P Series`,children:[(0,K.jsx)(`option`,{value:`P1P`,children:`P1P`}),(0,K.jsx)(`option`,{value:`P1S`,children:`P1S`}),(0,K.jsx)(`option`,{value:`P2S`,children:`P2S`})]}),(0,K.jsxs)(`optgroup`,{label:`X1 Series`,children:[(0,K.jsx)(`option`,{value:`X1`,children:`X1`}),(0,K.jsx)(`option`,{value:`X1C`,children:`X1 Carbon`}),(0,K.jsx)(`option`,{value:`X1E`,children:`X1E`})]}),(0,K.jsx)(`optgroup`,{label:`X2 Series`,children:(0,K.jsx)(`option`,{value:`X2D`,children:`X2D`})})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.modal.locationGroup`)}),(0,K.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,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`printers.locationHelp`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.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,K.jsx)(`label`,{htmlFor:`auto_archive`,className:`text-sm text-bambu-gray`,children:r(`printers.modal.autoArchiveLabel`)})]}),(0,K.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,K.jsx)(mu,{className:`w-4 h-4`}),r(`diagnostic.runButton`)]}),j?(0,K.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,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(ku,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-amber-600 dark:text-amber-400`}),(0,K.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-300`,children:r(`printers.addPreflight.warning`)})]}),(0,K.jsx)(gp,{result:j}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:()=>M(null),className:`flex-1`,children:r(`printers.addPreflight.back`)}),(0,K.jsx)($,{type:`button`,onClick:()=>t(i),className:`flex-1`,children:r(`printers.addPreflight.saveAnyway`)})]})]}):(0,K.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:e,className:`flex-1`,children:r(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:k,className:`flex-1`,children:r(k?`printers.addPreflight.checking`:`printers.addPrinter`)})]})]})]})})}),D&&(0,K.jsx)(vp,{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 gAe({printer:e,firmwareInfo:t,onClose:n}){let{t:r}=W(),i=oo(),{showToast:a}=Pd(),{hasPermission:o}=bd(),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:_}=q({queryKey:[`firmwarePrepare`,e.id,m],queryFn:()=>pd.prepareUpload(e.id,m??void 0),staleTime:3e4,enabled:!!m&&s&&!u}),v=J({mutationFn:()=>pd.startUpload(e.id,m??void 0),onSuccess:()=>{d(!0);let t=setInterval(async()=>{try{let n=await pd.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,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,K.jsx)(Ed,{className:`w-full max-w-md mx-4`,children:(0,K.jsxs)(Od,{children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,K.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,K.jsx)(Ws,{className:`w-5 h-5 text-orange-600 dark:text-orange-400`}):(0,K.jsx)(hs,{className:`w-5 h-5 text-status-ok`})}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:t.update_available?r(`printers.firmwareModal.title`):r(`printers.firmwareModal.titleUpToDate`)}),(0,K.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,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3 mb-4`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between items-center text-sm`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:r(`printers.firmwareModal.currentVersion`)}),(0,K.jsx)(`span`,{className:`font-mono ${a?`text-white`:`text-status-ok`}`,children:t.current_version||r(`common.unknown`)})]}),a&&(0,K.jsxs)(`div`,{className:`flex justify-between items-center text-sm mt-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:r(`printers.firmwareModal.latestVersion`)}),(0,K.jsx)(`span`,{className:`text-orange-700 dark:text-orange-400 font-mono`,children:n})]}),i&&(0,K.jsxs)(`details`,{className:`mt-3 text-sm`,open:!a,children:[(0,K.jsx)(`summary`,{className:`cursor-pointer hover:underline ${a?`text-orange-700 dark:text-orange-400`:`text-status-ok`}`,children:r(`printers.firmwareModal.releaseNotes`)}),(0,K.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,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mb-2`,children:r(`printers.firmwareModal.availableVersions`)}),(0,K.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?oee(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,K.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,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsx)(`span`,{className:`font-mono text-white`,children:e.version}),(0,K.jsx)(`span`,{className:`text-xs ${c}`,children:o})]}),(0,K.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,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm mb-4`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),r(`printers.firmwareModal.checkingPrereqs`)]}):g&&!u&&!c?(0,K.jsx)(`div`,{className:`mb-4`,children:g.can_proceed?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-green text-sm`,children:[(0,K.jsx)(qo,{className:`w-4 h-4`}),r(`printers.firmwareModal.sdCardReady`)]}):(0,K.jsx)(`div`,{className:`space-y-1`,children:g.errors.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400 text-sm`,children:[(0,K.jsx)(ps,{className:`w-4 h-4 flex-shrink-0`}),e]},t))})}):null:null,(u||c)&&c&&(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-sm mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray capitalize`,children:c.status}),(0,K.jsxs)(`span`,{className:`text-white`,children:[c.progress,`%`]})]}),(0,K.jsx)(`div`,{className:`w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,K.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,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c.message}),c.error&&(0,K.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:c.error})]}),c?.status===`complete`&&(0,K.jsxs)(`div`,{className:`bg-bambu-green/10 border border-bambu-green/30 rounded-lg p-3 mb-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-green font-medium mb-2`,children:r(`printers.firmwareModal.uploadedSuccess`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`printers.firmwareModal.applyInstructions`)}),(0,K.jsxs)(`ol`,{className:`text-xs text-bambu-gray mt-1 list-decimal list-inside space-y-1`,children:[(0,K.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step1`)}}),(0,K.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step2`)}}),(0,K.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step3`)}}),(0,K.jsx)(`li`,{children:r(`printers.firmwareModal.step4`)})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:n,children:c?.status===`complete`?r(`printers.firmwareModal.done`):r(`common.cancel`)}),g?.can_proceed&&!u&&c?.status!==`complete`&&s&&(0,K.jsx)($,{onClick:()=>{l(null),v.mutate()},disabled:v.isPending,children:v.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-2`}),r(`printers.firmwareModal.starting`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Ws,{className:`w-4 h-4 mr-2`}),r(`printers.firmwareModal.uploadFirmware`)]})})]})]})})})}function _Ae({printer:e,onClose:t}){let{t:n}=W(),r=oo(),{showToast:i}=Pd(),[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=J({mutationFn:t=>Q.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,K.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,K.jsx)(Ed,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(Od,{children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold mb-4`,children:n(`printers.editPrinter`)}),(0,K.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault(),c(!0);try{let t=await Q.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.name`)}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.ipAddress`)}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.serialNumber`)}),(0,K.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,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`printers.serialCannotBeChanged`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.accessCode`)}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.model`)}),(0,K.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,K.jsx)(`option`,{value:``,children:n(`printers.modal.selectModel`)}),(0,K.jsxs)(`optgroup`,{label:`A1 Series`,children:[(0,K.jsx)(`option`,{value:`A1`,children:`A1`}),(0,K.jsx)(`option`,{value:`A1 Mini`,children:`A1 Mini`})]}),(0,K.jsx)(`optgroup`,{label:`A2 Series`,children:(0,K.jsx)(`option`,{value:`A2L`,children:`A2L`})}),(0,K.jsxs)(`optgroup`,{label:`H2 Series`,children:[(0,K.jsx)(`option`,{value:`H2C`,children:`H2C`}),(0,K.jsx)(`option`,{value:`H2D`,children:`H2D`}),(0,K.jsx)(`option`,{value:`H2D Pro`,children:`H2D Pro`}),(0,K.jsx)(`option`,{value:`H2S`,children:`H2S`})]}),(0,K.jsxs)(`optgroup`,{label:`P Series`,children:[(0,K.jsx)(`option`,{value:`P1P`,children:`P1P`}),(0,K.jsx)(`option`,{value:`P1S`,children:`P1S`}),(0,K.jsx)(`option`,{value:`P2S`,children:`P2S`})]}),(0,K.jsxs)(`optgroup`,{label:`X1 Series`,children:[(0,K.jsx)(`option`,{value:`X1`,children:`X1`}),(0,K.jsx)(`option`,{value:`X1C`,children:`X1 Carbon`}),(0,K.jsx)(`option`,{value:`X1E`,children:`X1E`})]}),(0,K.jsx)(`optgroup`,{label:`X2 Series`,children:(0,K.jsx)(`option`,{value:`X2D`,children:`X2D`})})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Location / Group`}),(0,K.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,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`printers.locationHelp`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.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,K.jsx)(`label`,{htmlFor:`edit_auto_archive`,className:`text-sm text-bambu-gray`,children:n(`printers.modal.autoArchiveLabel`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.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,K.jsxs)(`label`,{htmlFor:`edit_maintenance_mode`,className:`text-sm text-bambu-gray flex items-center gap-1.5`,children:[(0,K.jsx)(Ku,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400`}),n(`printers.maintenance.editFieldLabel`)]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1 ml-6`,children:n(`printers.maintenance.editFieldHelp`)})]}),l?(0,K.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,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(ku,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-amber-600 dark:text-amber-400`}),(0,K.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-300`,children:n(`printers.addPreflight.warning`)})]}),(0,K.jsx)(gp,{result:l}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:()=>u(null),className:`flex-1`,children:n(`printers.addPreflight.back`)}),(0,K.jsx)($,{type:`button`,onClick:f,className:`flex-1`,disabled:d.isPending,children:n(`printers.addPreflight.saveAnyway`)})]})]}):(0,K.jsxs)(`div`,{className:`flex gap-3 pt-4`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`common.cancel`)}),(0,K.jsx)($,{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 vAe(e){let{data:t}=q({queryKey:[`printerStatus`,e],queryFn:()=>Q.getPrinterStatus(e),refetchInterval:3e4});return!t?.connected}function yAe({printer:e,plug:t,onPowerOn:n,isPowering:r}){let i=vAe(e.id),{data:a}=q({queryKey:[`smartPlugStatus`,t.id],queryFn:()=>Q.getSmartPlugStatus(t.id),refetchInterval:1e4});return i?(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 hover:bg-gray-100 dark:hover:bg-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white truncate`,children:e.name}),a&&(0,K.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,K.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,K.jsx)(Al,{className:`w-3 h-3`}),r?`...`:`On`]})]}):null}function bAe(){let{t:e}=W(),{resolvedMode:t,darkAccent:n,lightAccent:r}=Cd(),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)(`all`),[R,z]=(0,y.useState)(`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=oo(),{showToast:re}=Pd(),{hasPermission:ie}=bd(),[H,ae]=(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(H.values());e.length>0?localStorage.setItem(`openEmbeddedCameras`,JSON.stringify(e)):localStorage.removeItem(`openEmbeddedCameras`)},[H]);let{data:oe,isLoading:U}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:se}=q({queryKey:[`ui-preferences`],queryFn:Q.getUiPreferences}),ce=(0,y.useMemo)(()=>Kp(se?.nozzle_temp_presets,Hp,0,320),[se?.nozzle_temp_presets]),le=(0,y.useMemo)(()=>Kp(se?.bed_temp_presets,Up,0,140),[se?.bed_temp_presets]),ue=(0,y.useMemo)(()=>Kp(se?.chamber_temp_presets,Wp,0,60),[se?.chamber_temp_presets]),de=(0,y.useMemo)(()=>Kp(se?.fan_speed_presets,Gp,0,100),[se?.fan_speed_presets]),fe=(0,y.useMemo)(()=>{if(se?.drying_presets)try{let e=JSON.parse(se.drying_presets);if(typeof e==`object`&&e&&Object.keys(e).length>0)return{...MW,...e}}catch{}return MW},[se?.drying_presets]);(0,y.useEffect)(()=>{se?.camera_view_mode===`window`&&H.size>0&&ae(new Map)},[se?.camera_view_mode,H.size]);let{data:pe}=q({queryKey:[`smart-plugs`],queryFn:Q.getSmartPlugs}),{data:me}=q({queryKey:[`maintenanceOverview`],queryFn:Q.getMaintenanceOverview,staleTime:60*1e3}),{data:he}=q({queryKey:[`spoolman-status`],queryFn:Q.getSpoolmanStatus,staleTime:60*1e3}),ge=he?.enabled&&he?.connected,{data:_e}=q({queryKey:[`spoolman-settings`],queryFn:Q.getSpoolmanSettings,enabled:!!ge,staleTime:60*1e3}),ve=_e?.spoolman_sync_mode,{data:ye}=q({queryKey:[`unlinked-spools`],queryFn:Q.getUnlinkedSpools,enabled:!!ge,staleTime:30*1e3}),be=ye&&ye.length>0,{data:xe}=q({queryKey:[`linked-spools`],queryFn:Q.getLinkedSpools,enabled:!!ge,staleTime:30*1e3}),Se=xe?.linked,{data:Ce}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),enabled:ie(`inventory:view_assignments`),staleTime:30*1e3}),we=J({mutationFn:({printerId:e,amsId:t,trayId:n})=>Q.unassignSpool(e,t,n),onSuccess:()=>{ne.invalidateQueries({queryKey:[`spool-assignments`]})}}),{data:Te,isLoading:Ee}=q({queryKey:[`spoolman-inventory-spools`],queryFn:()=>Q.getSpoolmanInventorySpools(!1),enabled:!!ge,staleTime:30*1e3}),{data:De,isLoading:Oe}=q({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Q.getSpoolmanSlotAssignments(),enabled:!!ge,staleTime:30*1e3}),ke=J({mutationFn:e=>Q.unassignSpoolmanSlot(e),onSuccess:()=>{ne.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),ne.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})}}),Ae=(e,t,n)=>Ce?.find(r=>r.printer_id===e&&r.ams_id===Number(t)&&r.tray_id===Number(n)),je=me?.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),{})||{},Me=pe?.reduce((e,t)=>(t.printer_id&&(e[t.printer_id]=t),e),{})||{},Ne=J({mutationFn:Q.createPrinter,onSuccess:()=>{ne.invalidateQueries({queryKey:[`printers`]}),ne.invalidateQueries({queryKey:[`maintenanceOverview`]}),o(!1)},onError:t=>{if(t instanceof Qu&&t.code===`printer_connection_failed`){re(e(`printers.toast.connectionFailedNotAdded`),`error`);return}re(t.message||e(`printers.toast.failedToAdd`),`error`)}}),Pe=J({mutationFn:e=>Q.controlSmartPlug(e,`on`),onSuccess:()=>{ne.invalidateQueries({queryKey:[`smart-plugs`]}),f(null)},onError:()=>{f(null)}}),[Fe,Ie]=(0,y.useState)(new Set),[Le,Re]=(0,y.useState)(!1),[ze,Be]=(0,y.useState)(null),[Ve,He]=(0,y.useState)(!1),Ue=Le||Fe.size>0,We=(0,y.useCallback)(e=>{Ie(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Ge=(0,y.useCallback)(()=>{Ie(new Set),Re(!1)},[]);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&Ue&&Ge()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Ue,Ge]);let Ke=(0,y.useCallback)(async t=>{He(!0);let n=Array.from(Fe).filter(e=>{let n=ne.getQueryData([`printerStatus`,e]);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`clearPlate`:return!!n.awaiting_plate_clear;case`clearHMS`:return n.hms_errors&&Xp(n.hms_errors).length>0;default:return!1}});if(n.length===0){re(e(`printers.bulk.noneApplicable`),`error`),He(!1),Be(null);return}let r={stop:Q.stopPrint,pause:Q.pausePrint,resume:Q.resumePrint,clearPlate:Q.clearPlate,clearHMS:Q.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]})}),He(!1),Be(null)},[Fe,ne,re,e]),qe=(0,y.useCallback)(e=>{e===`stop`||e===`pause`||e===`clearPlate`?Be(e):Ke(e)},[Ke]),Je=()=>{let e=!s;c(e),localStorage.setItem(`hideDisconnectedPrinters`,String(e))},Ye=e=>{m(e),localStorage.setItem(`printerSortBy`,e)},Xe=()=>{let e=!h;g(e),localStorage.setItem(`printerSortAsc`,String(e))},Ze=()=>{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`}},Qe=[`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 $e=(0,y.useMemo)(()=>{if(!oe)return[];let e=oe;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?Xp(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},[oe,P,I,R,ne,B]),et=(0,y.useMemo)(()=>oe?[...new Set(oe.map(e=>e.location||``).filter(Boolean))].sort():[],[oe]),tt=(0,y.useMemo)(()=>{let e=[...$e];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?Xp(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},[$e,p,h,ne]),nt=(0,y.useCallback)(()=>{Ie(new Set(tt.map(e=>e.id))),Re(!0)},[tt]),rt=(0,y.useCallback)(e=>{Ie(t=>{let n=new Set(t);return tt.forEach(t=>{kW(ne.getQueryData([`printerStatus`,t.id]))===e&&n.add(t.id)}),n}),Re(!0)},[tt,ne]),it=(0,y.useCallback)(e=>{Ie(t=>{let n=new Set(t);return tt.filter(t=>(t.location||``)===e).forEach(e=>n.add(e.id)),n}),Re(!0)},[tt]),at=(0,y.useCallback)(e=>{Ie(t=>{let n=new Set(t);return tt.filter(t=>(t.model||`Unknown`)===e).forEach(e=>n.add(e.id)),n}),Re(!0)},[tt]),ot=(0,y.useCallback)(e=>{te(t=>{let n={...t,[e]:!t[e]};try{localStorage.setItem(`printerCollapsedSections`,JSON.stringify(n))}catch{}return n})},[]),st=(0,y.useMemo)(()=>{if(p===`name`||p===`eta`)return null;let e={};return p===`location`?tt.forEach(t=>{let n=t.location||`Ungrouped`;e[n]||(e[n]=[]),e[n].push(t)}):p===`model`?tt.forEach(t=>{let n=t.model||`Unknown`;e[n]||(e[n]=[]),e[n].push(t)}):p===`status`&&tt.forEach(t=>{let n=kW(ne.getQueryData([`printerStatus`,t.id]));e[n]||(e[n]=[]),e[n].push(t)}),e},[p,tt,ne,B]),ct=(0,y.useRef)(null),lt=(0,y.useRef)(null),ut=(0,y.useRef)(0),[dt,ft]=(0,y.useState)(!1),pt=(0,y.useCallback)(()=>{let e=ct.current;if(!e)return;let t=lt.current?.offsetWidth;t&&(ut.current=t);let n=ut.current>0&&e.clientWidthe===n?e:n)},[]),mt=Object.keys(Me).length;(0,y.useLayoutEffect)(()=>{pt();let e=ct.current;if(!e)return;if(typeof ResizeObserver>`u`)return window.addEventListener(`resize`,pt),()=>window.removeEventListener(`resize`,pt);let t=new ResizeObserver(()=>pt());return t.observe(e),window.addEventListener(`resize`,pt),()=>{t.disconnect(),window.removeEventListener(`resize`,pt)}},[pt,oe?.length,et.length,s,mt]);let ht=(t=!1)=>(0,K.jsxs)(K.Fragment,{children:[oe&&oe.length>0&&(0,K.jsx)(wW,{value:I,onChange:L,fullWidth:t,options:[{value:`all`,label:e(`printers.filter.allStatuses`)},{value:`printing`,label:e(`printers.status.printing`)},{value:`paused`,label:e(`printers.status.paused`)},{value:`idle`,label:e(`printers.status.idle`)},{value:`finished`,label:e(`printers.status.finished`)},{value:`error`,label:e(`printers.status.error`)},{value:`offline`,label:e(`printers.status.offline`)}]}),oe&&oe.length>0&&et.length>0&&(0,K.jsx)(wW,{value:R,onChange:z,fullWidth:t,options:[{value:`all`,label:e(`printers.filter.allLocations`)},...et.map(e=>({value:e,label:e}))]}),(0,K.jsx)(`button`,{type:`button`,onClick:Je,"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`)})]}),gt=(t=!1)=>(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1 ${t?`w-full`:``}`,children:[(0,K.jsx)(wW,{value:p,onChange:Ye,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,K.jsx)(`button`,{onClick:Xe,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,K.jsx)(zo,{className:`w-4 h-4 text-white`}):(0,K.jsx)(No,{className:`w-4 h-4 text-white`})})]}),(0,K.jsxs)(`div`,{className:`flex h-8 items-center bg-bambu-dark rounded-lg border border-bambu-dark-tertiary ${t?`w-full`:``}`,children:[(0,K.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,K.jsx)(Hc,{className:`w-3.5 h-3.5`}),t&&(0,K.jsx)(`span`,{children:e(`printers.pageView.cards`)})]}),(0,K.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,K.jsx)(ll,{className:`w-3.5 h-3.5`}),t&&(0,K.jsx)(`span`,{children:e(`printers.pageView.camWall`)})]})]}),b===`camwall`&&ie(`camera:view`)&&(0,K.jsxs)(Oi,{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,K.jsx)(Zs,{className:`w-3.5 h-3.5`}),t&&(0,K.jsx)(`span`,{children:e(`printers.pageView.openCamWallPage`)})]}),(0,K.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:Qe.map((n,r)=>{let i=r+1,a=_===i;return(0,K.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===Qe.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)})})]}),_t=(t=!1)=>(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`button`,{onClick:()=>{Ue?Ge():Re(!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`:``} ${Ue?`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,K.jsx)(uu,{className:`w-4 h-4`}),t&&(0,K.jsx)(`span`,{children:e(`printers.bulk.select`)})]}),s&&Object.keys(Me).length>0&&(0,K.jsxs)(`div`,{className:`relative ${t?`w-full`:``}`,children:[(0,K.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,K.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(Al,{className:`w-4 h-4`}),e(`printers.powerOn`)]}),(0,K.jsx)(ss,{className:`w-3 h-3 transition-transform ${l?`rotate-180`:``}`})]}),l&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>u(!1)}),(0,K.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,K.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`)}),oe?.filter(e=>Me[e.id]).map(e=>(0,K.jsx)(yAe,{printer:e,plug:Me[e.id],onPowerOn:e=>{f(e),Pe.mutate(e)},isPowering:d===Me[e.id]?.id},e.id)),oe?.filter(e=>Me[e.id]).length===0&&(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:`No printers with smart plugs`})]})]})]}),(0,K.jsxs)($,{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,K.jsx)(Ol,{className:`w-4 h-4`}),e(`printers.addPrinter`)]})]});return(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsxs)(`div`,{className:`space-y-3 mb-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(jl,{className:`w-7 h-7 text-bambu-green`}),e(`printers.title`)]}),(0,K.jsx)(uAe,{printers:oe})]}),(0,K.jsxs)(`div`,{ref:ct,className:`relative flex items-center gap-2`,children:[oe&&oe.length>0&&(0,K.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,K.jsx)(Wl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50`}),(0,K.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,K.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,K.jsx)(qu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{ref:lt,"aria-hidden":dt,inert:dt,className:`${dt?`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,K.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:ht()}),(0,K.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:gt()}),(0,K.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:_t()})]}),dt&&(0,K.jsxs)(`div`,{className:`ml-auto flex items-center justify-end gap-1`,children:[(0,K.jsx)(TW,{label:e(`printers.toolbar.filters`,`Filters`),icon:(0,K.jsx)(_c,{className:`w-4 h-4`}),children:(0,K.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:ht(!0)})}),(0,K.jsx)(TW,{label:e(`printers.toolbar.view`,`View`),icon:(0,K.jsx)(iu,{className:`w-4 h-4`}),children:(0,K.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:gt(!0)})}),(0,K.jsx)(TW,{label:e(`printers.toolbar.actions`,`Actions`),icon:(0,K.jsx)(Js,{className:`w-4 h-4`}),children:(0,K.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:_t(!0)})})]})]})]}),U?(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`common.loading`)}):oe?.length===0?(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`text-center py-12`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`printers.noPrintersConfigured`)}),(0,K.jsxs)($,{onClick:()=>o(!0),disabled:!ie(`printers:create`),title:ie(`printers:create`)?void 0:e(`printers.permission.noAdd`),children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),e(`printers.addPrinter`)]})]})}):tt.length===0&&(P.trim()||I!==`all`||R!==`all`)?(0,K.jsx)(Ed,{children:(0,K.jsx)(Od,{className:`text-center py-12`,children:(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`printers.noSearchResults`)})})}):b===`camwall`?(0,K.jsx)(CT,{printers:tt,maxLive:S,snapshotIntervalSec:w,onTileClick:(e,t)=>{if((se?.camera_view_mode||`window`)===`embedded`)ae(n=>new Map(n).set(e,{id:e,name:t}));else{let t=localStorage.getItem(`cameraWindowState`),n=t?JSON.parse(t):{width:640,height:400},r=[`width=${n.width}`,`height=${n.height}`,n.left===void 0?``:`left=${n.left}`,n.top===void 0?``:`top=${n.top}`,`menubar=no,toolbar=no,location=no,status=no`].filter(Boolean).join(`,`);window.open(`/camera/${e}`,`camera-${e}`,r)}},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)}}):st?(0,K.jsx)(`div`,{className:`space-y-6`,children:(()=>{let e=p===`status`?fAe.filter(e=>st[e]?.length>0):Object.keys(st);return h?e:[...e].reverse()})().map(t=>{let n=st[t],r=`${p}:${t}`,i=!ee[r],a=p===`status`&&OW[t]?.dot||`bg-bambu-green`,o=p===`status`?e(OW[t]?.labelKey||t):t;return(0,K.jsx)(Cp,{open:i,onToggle:()=>ot(r),summaryClassName:`py-1`,summary:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full ${a}`}),o,(0,K.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n.length,`)`]}),Ue&&(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),p===`location`?it(t===`Ungrouped`?``:t):p===`status`?rt(t):p===`model`&&at(t)},className:`text-xs text-bambu-green hover:text-bambu-green-light transition-colors ml-1`,children:e(`printers.bulk.selectAll`)})]}),children:(0,K.jsx)(`div`,{className:`grid gap-4 ${_>=3?`gap-6`:``} ${Ze()}`,children:n.map(e=>(0,K.jsx)(NW,{printer:e,hideIfDisconnected:s,maintenanceInfo:je[e.id],viewMode:O,cardSize:_,amsThresholds:se?{humidityGood:Number(se.ams_humidity_good)||40,humidityFair:Number(se.ams_humidity_fair)||60,tempGood:Number(se.ams_temp_good)||28,tempFair:Number(se.ams_temp_fair)||35}:void 0,spoolmanEnabled:ge,hasUnlinkedSpools:be,linkedSpools:Se,spoolmanUrl:he?.url,spoolmanSyncMode:ve,onGetAssignment:Ae,onUnassignSpool:(e,t,n)=>we.mutate({printerId:e,amsId:t,trayId:n}),spoolmanSpools:Te,spoolmanSlotAssignments:De,spoolmanLoading:Ee||Oe,onUnassignSpoolmanSpool:e=>ke.mutate(e),timeFormat:se?.time_format||`system`,cameraViewMode:se?.camera_view_mode||`window`,onOpenEmbeddedCamera:(e,t)=>ae(n=>new Map(n).set(e,{id:e,name:t})),checkPrinterFirmware:se?.check_printer_firmware!==!1,dryingPresets:fe,nozzleTempPresets:ce,bedTempPresets:le,chamberTempPresets:ue,fanSpeedPresets:de,requirePlateClear:se?.require_plate_clear===!0,selectionMode:Ue,isSelected:Fe.has(e.id),onToggleSelect:We,onOpenCompactCard:M},e.id))})},t)})}):(0,K.jsx)(`div`,{className:`grid gap-4 ${_>=3?`gap-6`:``} ${Ze()}`,children:tt.map(e=>(0,K.jsx)(NW,{printer:e,hideIfDisconnected:s,maintenanceInfo:je[e.id],viewMode:O,cardSize:_,spoolmanEnabled:ge,hasUnlinkedSpools:be,linkedSpools:Se,spoolmanUrl:he?.url,spoolmanSyncMode:ve,onGetAssignment:Ae,onUnassignSpool:(e,t,n)=>we.mutate({printerId:e,amsId:t,trayId:n}),spoolmanSpools:Te,spoolmanSlotAssignments:De,spoolmanLoading:Ee||Oe,onUnassignSpoolmanSpool:e=>ke.mutate(e),amsThresholds:se?{humidityGood:Number(se.ams_humidity_good)||40,humidityFair:Number(se.ams_humidity_fair)||60,tempGood:Number(se.ams_temp_good)||28,tempFair:Number(se.ams_temp_fair)||35}:void 0,timeFormat:se?.time_format||`system`,cameraViewMode:se?.camera_view_mode||`window`,onOpenEmbeddedCamera:(e,t)=>ae(n=>new Map(n).set(e,{id:e,name:t})),checkPrinterFirmware:se?.check_printer_firmware!==!1,dryingPresets:fe,nozzleTempPresets:ce,bedTempPresets:le,chamberTempPresets:ue,fanSpeedPresets:de,requirePlateClear:se?.require_plate_clear===!0,selectionMode:Ue,isSelected:Fe.has(e.id),onToggleSelect:We,onOpenCompactCard:M},e.id))}),_===2&&k!=null&&(0,K.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,K.jsx)(Po,{className:`w-4 h-4`}),e(`common.back`,`Back`)]}),a&&(0,K.jsx)(hAe,{onClose:()=>o(!1),onAdd:e=>Ne.mutate(e),existingSerials:oe?.map(e=>e.serial_number)||[]}),Ue&&oe&&(0,K.jsx)(mee,{selectedIds:Fe,printers:oe,onClose:Ge,onSelectAll:nt,onSelectByLocation:it,onSelectByState:rt,onAction:qe,actionPending:Ve}),ze===`stop`&&(0,K.jsx)(Vd,{title:e(`printers.bulk.confirm.stopTitle`,{count:Fe.size}),message:e(`printers.bulk.confirm.stopMessage`,{count:Fe.size}),confirmText:e(`printers.bulk.confirm.stopButton`),variant:`danger`,isLoading:Ve,onConfirm:()=>Ke(`stop`),onCancel:()=>Be(null)}),ze===`pause`&&(0,K.jsx)(Vd,{title:e(`printers.bulk.confirm.pauseTitle`,{count:Fe.size}),message:e(`printers.bulk.confirm.pauseMessage`,{count:Fe.size}),confirmText:e(`printers.bulk.confirm.pauseButton`),isLoading:Ve,onConfirm:()=>Ke(`pause`),onCancel:()=>Be(null)}),ze===`clearPlate`&&(0,K.jsx)(Vd,{title:e(`printers.bulk.confirm.clearPlateTitle`,{count:Fe.size}),message:e(`printers.bulk.confirm.clearPlateMessage`,{count:Fe.size}),confirmText:e(`printers.bulk.confirm.clearPlateButton`),isLoading:Ve,onConfirm:()=>Ke(`clearPlate`),onCancel:()=>Be(null)}),Array.from(H.values()).map((e,t)=>(0,K.jsx)(Dle,{printerId:e.id,printerName:e.name,viewerIndex:t,onClose:()=>ae(t=>{let n=new Map(t);return n.delete(e.id),n})},e.id))]})}function xAe({title:e,message:t,subtitle:n,closeText:r,variant:i=`error`,onClose:a}){let{t:o}=W(),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,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-[120]`,onClick:a,children:(0,K.jsx)(Ed,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(Od,{className:`p-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,K.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,K.jsx)(ku,{className:`w-6 h-6`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-1`,children:e}),n&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2 truncate`,children:n}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm whitespace-pre-line break-words`,children:t})]})]}),(0,K.jsx)(`div`,{className:`flex mt-6`,children:(0,K.jsx)($,{onClick:a,className:`flex-1`,children:s})})]})})})}var PW=(0,y.createContext)(null),SAe=1500,CAe=1e3,FW=e=>`slice-job-${e}`;function IW(e){try{return decodeURIComponent(e)}catch{return e}}function wAe(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 TAe({children:e}){let{t}=W(),{showToast:n,showPersistentToast:r,dismissToast:i}=Pd(),a=oo(),[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.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=wAe(i),s=p.current.get(e.id)??null,c=s&&s.stage&&s.total_percent>0;if(a===`running`&&c){let n=IW(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(FW(e.id),c,`loading`);return}let l=a===`pending`?`slice.queuedToast`:`slice.runningToast`,u=a===`pending`?`Queued: {{name}} — {{elapsed}}`:`Slicing {{name}} — {{elapsed}}`;r(FW(e.id),t(l,u,{name:IW(e.sourceName),elapsed:o}),`loading`)},[r,t]),h=(0,y.useCallback)((e,t,n)=>{s(r=>r.some(t=>t.id===e)?r:[...r,{id:e,kind:t,sourceName:n}]),d.current.set(e,Date.now()),f.current.set(e,`pending`),p.current.set(e,null),m({id:e,kind:t,sourceName:n})},[m]),g=(0,y.useCallback)((e,r)=>{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(FW(e.id)),r.status===`completed`?n(t(`slice.completedToast`,`Sliced {{name}}`,{name:IW(e.sourceName)}),`success`):r.status===`failed`&&l({name:IW(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=setInterval(async()=>{if(e)return;let t=[...u.current];for(let e of t)try{let t=await Q.getSliceJob(e.id);f.current.set(e.id,t.status),t.progress&&p.current.set(e.id,t.progress),(t.status===`completed`||t.status===`failed`)&&g(e,t)}catch{}},SAe);return()=>{e=!0,clearInterval(t)}},[o.length,g]),(0,y.useEffect)(()=>{if(o.length===0)return;let e=setInterval(()=>{for(let e of u.current)m(e)},CAe);return()=>clearInterval(e)},[o.length,m]),(0,K.jsxs)(PW.Provider,{value:{trackJob:h,activeJobs:o},children:[e,c&&(0,K.jsx)(xAe,{title:t(`slice.failedTitle`),subtitle:c.name,message:c.detail,onClose:()=>l(null)})]})}function LW(){let e=(0,y.useContext)(PW);if(!e)throw Error(`useSliceJobTracker must be used inside SliceJobTrackerProvider`);return e}function RW({plates:e,onSelect:t,onClose:n}){let{t:r}=W();return(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,onClick:n,children:(0,K.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,K.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,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`h3`,{className:`text-white font-medium`,children:r(`archives.platePicker.title`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`archives.platePicker.hint`)})]}),(0,K.jsx)(`button`,{onClick:n,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors`,"aria-label":r(`common.close`,`Close`),children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:(0,K.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:e.map(e=>(0,K.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,K.jsx)(`img`,{src:ad(e.thumbnail_url),alt:`Plate ${e.index}`,className:`w-12 h-12 rounded object-cover bg-bambu-dark-tertiary flex-shrink-0`}):(0,K.jsx)(`div`,{className:`w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center flex-shrink-0`,children:(0,K.jsx)(Vc,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.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,K.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?``:` • ${If(e.print_time_seconds)}`]})]})]},e.index))})})]})})}var zW=[`local`,`orca_cloud`,`cloud`,`standard`],EAe={local:1.75,orca_cloud:1.5,cloud:1,standard:.5};function BW(e,t){for(let n of zW){let r=e[n][t];if(r.length>0)return{source:r[0].source,id:r[0].id}}return null}function VW(e,t,n){return t?e[t.source][n].find(e=>e.id===t.id)??null:null}function HW(e,t,n){if(!n)return null;for(let r of zW){let i=e[r][t].find(e=>e.name===n);if(i)return{source:i.source,id:i.id}}return null}function DAe(e,t,n,r){let i=HW(e,`process`,r);if(i){let r=VW(e,i,`process`);if(r&&CU(r,`process`,t,n)!==`mismatch`)return i}for(let r of[`match`,`unknown`])for(let i of zW)for(let a of e[i].process)if(CU(a,`process`,t,n)===r)return{source:a.source,id:a.id};return BW(e,`process`)}function OAe(e,t,n,r){let i=t.type.trim().toUpperCase(),a=Hf(t.color),o=null,s=null;for(let c of zW)for(let l of e[c].filament){let e=0,u=(l.filament_type??``).trim().toUpperCase(),d=Hf(l.filament_colour??``);i&&u&&i===u&&(e+=10),a&&d&&(d===a?e+=5:Jf(l.filament_colour??``,t.color)&&(e+=2)),e+=EAe[c];let f={source:l.source,id:l.id};CU(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?BW(e,`filament`):s.ref:o.ref}function kAe(e){return e?`${e.source}:${e.id}`:``}function AAe(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 jAe({requestId:e,sourceName:t}){let{t:n}=W(),{showPersistentToast:r,dismissToast:i}=Pd(),[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 Q.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=MAe(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,K.jsxs)(`div`,{className:`flex flex-col gap-1 text-bambu-gray text-sm py-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),p,(0,K.jsxs)(`span`,{className:`text-xs tabular-nums`,children:[a,`s`]})]}),a>=5&&(0,K.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 MAe(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 UW({source:e,onClose:t}){let{t:n}=W(),{trackJob:r}=LW(),i=oo(),[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=q({queryKey:[`slicer-pipelines`],queryFn:()=>Q.listSlicerPipelines(),staleTime:6e4}),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)(``),{showToast:D}=Pd(),O=J({mutationFn:e=>Q.createSlicerPipeline(e),onSuccess:()=>{i.invalidateQueries({queryKey:[`slicer-pipelines`]}),D(n(`slice.pipelines.toast.saved`,`Pipeline saved`),`success`),w(!1),E(``)},onError:e=>{D(e.message||n(`slice.pipelines.toast.saveFailed`,`Save failed`),`error`)}}),k=q({queryKey:[`slicePlates`,e.kind,e.id],queryFn:async()=>e.kind===`libraryFile`?Q.getLibraryFilePlates(e.id):Q.getArchivePlates(e.id),staleTime:6e4}),A=!!k.data?.is_multi_plate&&(k.data?.plates?.length??0)>1,j=A&&p==null,M=p??1,N=(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${M}-${t}`},[e.kind,e.id,M]),P=q({queryKey:[`sliceFilamentReqs`,e.kind,e.id,M],queryFn:async()=>e.kind===`libraryFile`?Q.getLibraryFileFilamentRequirements(e.id,M,N):Q.getArchiveFilamentRequirements(e.id,M,N),enabled:!j,staleTime:6e4}),F=(0,y.useMemo)(()=>{let e=P.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,P.data]),I=q({queryKey:[`slicerPresets`],queryFn:()=>Q.getSlicerPresets(),staleTime:6e4,enabled:!k.isLoading&&!j}),[L,R]=(0,y.useState)(!1),z=async()=>{if(!L){R(!0);try{let e=await Q.getSlicerPresets({refresh:!0});i.setQueryData([`slicerPresets`],e)}catch{i.invalidateQueries({queryKey:[`slicerPresets`]})}finally{R(!1)}}},B=q({queryKey:[`slicerPrinterModels`],queryFn:Q.getSlicerPrinterModels,staleTime:1/0}),V=(0,y.useMemo)(()=>!I.data||!a?null:VW(I.data,a,`printer`)?.name??null,[I.data,a]),ee=(0,y.useMemo)(()=>vU(B.data??{}),[B.data]),te=k.data?.embedded_printer??null,ne=k.data?.embedded_process??null,re=(0,y.useMemo)(()=>{if(!te||!ne||!V)return!1;let e=e=>e.replace(/^#\s*/,``).trim().toLowerCase();return e(V)===e(te)},[te,ne,V]);(0,y.useEffect)(()=>{re||x(!1)},[re]),(0,y.useEffect)(()=>{let e=I.data;e&&(a??o(HW(e,`printer`,te)??BW(e,`printer`)))},[I.data,te]),(0,y.useEffect)(()=>{let e=I.data;e&&c(t=>{if(t){let n=VW(e,t,`process`);if(n&&CU(n,`process`,V,ee)!==`mismatch`)return t}return DAe(e,V,ee,ne)})},[I.data,V,ee,ne]),(0,y.useEffect)(()=>{let e=I.data;e&&u(t=>F.map((n,r)=>{let i=t[r]??null;if(i){let t=VW(e,i,`filament`);if(t&&CU(t,`filament`,V,ee)!==`mismatch`)return i}return OAe(e,{type:n.type,color:n.color},V,ee)}))},[I.data,F,V,ee]);let ie=J({mutationFn:async t=>{let n=H(t);return e.kind===`libraryFile`?Q.sliceLibraryFile(e.id,n):Q.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 H(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&&re?{use_embedded_settings:!0}:{}}}let ae=a!=null&&s!=null&&P.isSuccess&&l.length>0&&l.every(e=>e!=null),oe=ie.isPending,U=k.data?.plates?.length??0,se=A&&U>1&&!j;return j&&k.data?(0,K.jsx)(RW,{plates:k.data.plates,onSelect:e=>m(e),onClose:t}):(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,onClick:()=>{oe||t()},children:(0,K.jsxs)(`div`,{className:`w-full max-w-xl max-h-[85vh] flex flex-col rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary/60`,onClick:e=>e.stopPropagation(),children:[(0,K.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,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsxs)(`h3`,{className:`text-white font-medium flex items-center gap-2`,children:[(0,K.jsx)(Ms,{className:`w-4 h-4`}),n(`slice.title`)]}),(0,K.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,K.jsx)(`button`,{onClick:t,disabled:oe,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors disabled:opacity-50`,"aria-label":n(`common.close`),children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[(k.isLoading||I.isLoading)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),n(`slice.loadingPresets`)]}),I.isError&&(0,K.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.`)}),I.data&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,K.jsx)(WW,{status:I.data.cloud_status,cloudName:`bambu`}),(0,K.jsx)(WW,{status:I.data.orca_cloud_status,cloudName:`orca`})]}),(0,K.jsxs)(`button`,{type:`button`,onClick:z,disabled:L||oe,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,K.jsx)(Pl,{className:`w-3.5 h-3.5 ${L?`animate-spin`:``}`}),n(`slice.refreshPresets`)]})]}),(0,K.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,K.jsxs)(`span`,{className:`text-xs font-medium text-bambu-gray flex items-center gap-1`,children:[(0,K.jsx)(Ms,{className:`w-3.5 h-3.5`}),` `,n(`slice.pipelines.label`,`Pipeline`)]}),(0,K.jsxs)(`select`,{value:``,disabled:oe||(S.data?.pipelines.length??0)===0,onChange:e=>{let t=parseInt(e.target.value,10);if(Number.isNaN(t))return;let r=S.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,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),C?(0,K.jsxs)(`div`,{className:`flex items-center gap-1 flex-1 min-w-[16ch]`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:T,onChange:e=>E(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,K.jsx)(`button`,{type:`button`,onClick:()=>{let e=T.trim();if(!e||!a||!s)return;let t=l.filter(e=>e!==null);t.length!==0&&O.mutate({name:e,printer_preset:a,process_preset:s,filament_presets:t,bed_type:_})},disabled:O.isPending||!T.trim(),className:`text-xs px-2 py-1 bg-bambu-green hover:bg-bambu-green/80 text-white rounded disabled:opacity-50`,children:O.isPending?(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`}):n(`common.save`,`Save`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>{w(!1),E(``)},className:`text-xs px-2 py-1 text-bambu-gray hover:text-white`,children:n(`common.cancel`,`Cancel`)})]}):(0,K.jsx)(`button`,{type:`button`,onClick:()=>{E(``),w(!0)},disabled:oe||!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,K.jsx)(GW,{label:n(`slice.printer`),slot:`printer`,data:I.data,value:a,onChange:o,disabled:oe||b}),re&&(0,K.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-bambu-gray cursor-pointer select-none`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:b,onChange:e=>x(e.target.checked),disabled:oe,className:`mt-0.5 cursor-pointer`}),(0,K.jsxs)(`span`,{children:[n(`slice.useEmbedded`),(0,K.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:n(`slice.useEmbeddedHint`)})]})]}),(0,K.jsx)(GW,{label:n(`slice.process`),slot:`process`,data:I.data,value:s,onChange:c,disabled:oe||b,selectedPrinterName:V,compatIndex:ee}),(0,K.jsx)(PAe,{value:_,onChange:v,disabled:oe||b}),P.isLoading?(0,K.jsx)(jAe,{requestId:N,sourceName:e.filename}):F.map((e,t)=>{let r=e.used_in_plate!==!1,i=F.length>1?n(`slice.filamentSlot`,{index:t+1,type:e.type}):n(`slice.filament`);return(0,K.jsx)(GW,{label:r?i:`${i} ${n(`slice.notUsedByPlate`)}`,slot:`filament`,data:I.data,value:l[t]??null,onChange:e=>u(n=>{let r=n.length===F.length?[...n]:F.map((e,t)=>n[t]??null);return r[t]=e,r}),disabled:oe||!r||b,swatchColor:F.length>1?e.color:void 0,selectedPrinterName:V,compatIndex:ee},`filament-${t}`)})]}),d&&(0,K.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,K.jsxs)(`div`,{className:`flex-shrink-0 flex justify-end gap-2 px-4 py-3 border-t border-bambu-dark-tertiary/40`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:t,disabled:oe,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`)}),se&&(0,K.jsxs)(`label`,{className:`flex items-center gap-2 mr-auto text-sm text-bambu-gray cursor-pointer select-none`,title:n(`slice.actionAllTitle`,{count:U}),children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),disabled:oe,className:`cursor-pointer`}),n(`slice.allPlatesToggle`,{count:U})]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>{f(null);let e=h?0:p;ie.mutate(e)},disabled:!ae||oe,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:oe?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),n(`slice.enqueuing`)]}):h?n(`slice.actionAll`,{count:U}):n(`slice.action`)})]})]})})}function WW({status:e,cloudName:t=`bambu`}){let{t:n}=W();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:Ts},unreachable:{tone:`border-bambu-dark-tertiary/40 bg-bambu-dark text-bambu-gray`,icon:Ts}}[e],{key:o,fallback:s}=r[e];return(0,K.jsxs)(`div`,{className:`flex items-start gap-2 text-xs rounded-md border p-2 ${i}`,role:`status`,children:[(0,K.jsx)(a,{className:`w-4 h-4 flex-shrink-0 mt-0.5`}),(0,K.jsx)(`span`,{children:n(o,s)})]})}var NAe=[{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 PAe({value:e,onChange:t,disabled:n}){let{t:r}=W();return(0,K.jsxs)(`label`,{className:`block`,children:[(0,K.jsx)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:r(`slice.bedType.label`)}),(0,K.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,K.jsx)(`option`,{value:``,children:r(`slice.bedType.auto`)}),NAe.map(e=>(0,K.jsx)(`option`,{value:e.value,children:r(e.labelKey,e.fallback)},e.value))]})]})}function GW({label:e,slot:t,data:n,value:r,onChange:i,disabled:a,swatchColor:o,selectedPrinterName:s,compatIndex:c}){let{t:l}=W(),{sections:u,otherEntries:d}=(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)CU(n,t,s??null,c??Ske)===`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]),f=u.reduce((e,t)=>e+t.entries.length,0)+d.length;return(0,K.jsxs)(`label`,{className:`block`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-2 text-xs text-bambu-gray mb-1`,children:[o&&(0,K.jsx)(`span`,{className:`inline-block w-3 h-3 rounded-full border border-bambu-dark-tertiary`,style:{backgroundColor:o||`transparent`},"aria-hidden":!0}),(0,K.jsx)(`span`,{children:e})]}),(0,K.jsxs)(`select`,{value:kAe(r),onChange:e=>i(AAe(e.target.value)),disabled:a||f===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,K.jsx)(`option`,{value:``,children:l(f===0?`slice.noPresetsForSlot`:`slice.selectPreset`)}),u.map(e=>(0,K.jsx)(`optgroup`,{label:e.tierLabel,children:e.entries.map(e=>(0,K.jsx)(`option`,{value:`${e.source}:${e.id}`,children:e.name},`${e.source}:${e.id}`))},e.tierLabel)),d.length>0&&(0,K.jsx)(`optgroup`,{label:l(`slice.otherPrinters`),children:d.map(e=>(0,K.jsx)(`option`,{value:`${e.source}:${e.id}`,children:e.name},`${e.source}:${e.id}`))})]})]})}function KW({source:e,onClose:t}){let{t:n}=W(),r=oo(),{showToast:i}=Pd(),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(1),{trackJob:d}=LW(),{data:f,isLoading:p}=q({queryKey:[`slicer-pipelines`],queryFn:()=>Q.listSlicerPipelines()}),{data:m}=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters()}),{data:h}=q({queryKey:[`app-settings`],queryFn:()=>Q.getSettings()}),g=h?.pipeline_max_copies??50,_={kind:e.kind,id:e.id},v=J({mutationFn:e=>Q.checkPipelineEligibility(e,_)}),b=J({mutationFn:({pipelineId:e,force:t})=>Q.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,K.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,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h3`,{className:`text-sm font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(El,{className:`w-4 h-4 text-bambu-green`}),a&&s?n(`library.runWithPipeline.confirmTitle`,`Confirm run`):n(`library.runWithPipeline.modalTitle`,`Run with pipeline`)]}),(0,K.jsx)(`button`,{type:`button`,onClick:t,"aria-label":n(`common.close`,`Close`),className:`text-bambu-gray hover:text-white`,children:(0,K.jsx)(qu,{className:`w-4 h-4`})})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-3`,children:a&&s?(0,K.jsx)(IAe,{pipeline:a,report:s,source:e,onBack:()=>{o(null),c(null)},onConfirm:()=>{a&&b.mutate({pipelineId:a.id,force:!0})},running:b.isPending}):(0,K.jsx)(FAe,{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 FAe({source:e,pipelines:t,printerById:n,loading:r,onPick:i,copies:a,maxCopies:o,onCopiesChange:s}){let{t:c}=W();return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[c(`library.runWithPipeline.sourceHint`,`Source`),`:`,` `,(0,K.jsx)(`span`,{className:`text-white`,children:e.filename})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`label`,{className:`text-xs text-bambu-gray`,htmlFor:`run-pipeline-copies`,children:[c(`library.runWithPipeline.copies`,`Copies`),`:`]}),(0,K.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,K.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:c(`library.runWithPipeline.copiesHint`,`max {{n}}`,{n:o})})]}),r&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),c(`library.runWithPipeline.loading`,`Loading…`)]}),!r&&t.length===0&&(0,K.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,K.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,K.jsx)(`li`,{children:(0,K.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,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Ms,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,K.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,K.jsx)(jl,{className:`w-3 h-3`}),a?(0,K.jsx)(`span`,{children:a}):r?(0,K.jsx)(`span`,{children:r}):(0,K.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:c(`library.runWithPipeline.noTarget`,`No target printer set`)})]})]})},e.id)})})]})}function IAe({pipeline:e,report:t,source:n,onBack:r,onConfirm:i,running:a}){let{t:o}=W();return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[(0,K.jsxs)(`p`,{children:[o(`library.runWithPipeline.confirmIntro`,`Pre-flight found issues with this run`),`:`]}),(0,K.jsxs)(`p`,{className:`mt-1`,children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[o(`library.runWithPipeline.sourceHint`,`Source`),`: `]}),(0,K.jsx)(`span`,{className:`text-white`,children:n.filename})]}),(0,K.jsxs)(`p`,{children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[o(`library.runWithPipeline.pipelineHint`,`Pipeline`),`: `]}),(0,K.jsx)(`span`,{className:`text-white`,children:e.name})]}),t.target_printer_name&&(0,K.jsxs)(`p`,{children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[o(`library.runWithPipeline.targetHint`,`Target`),`: `]}),(0,K.jsx)(`span`,{className:`text-white`,children:t.target_printer_name})]})]}),(0,K.jsx)(`ul`,{className:`space-y-1.5`,children:t.issues.map((e,t)=>(0,K.jsxs)(`li`,{className:`flex items-start gap-2 text-xs`,children:[(0,K.jsx)(ku,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:(0,K.jsx)(LAe,{issue:e})})]},t))}),(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.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,K.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,K.jsx)(X,{className:`w-3 h-3 animate-spin`}):(0,K.jsx)(El,{className:`w-3 h-3`}),o(`library.runWithPipeline.runAnyway`,`Run anyway`)]})]})]})}function LAe({issue:e}){let{t}=W();switch(e.kind){case`printer_not_set`:return(0,K.jsx)(K.Fragment,{children:t(`library.runWithPipeline.issue.printerNotSet`,`No target printer set on this pipeline.`)});case`printer_not_found`:return(0,K.jsx)(K.Fragment,{children:t(`library.runWithPipeline.issue.printerNotFound`,`Target printer no longer exists.`)});case`printer_disabled`:return(0,K.jsx)(K.Fragment,{children:t(`library.runWithPipeline.issue.printerDisabled`,`Target printer is disabled.`)});case`printer_offline`:return(0,K.jsx)(K.Fragment,{children:t(`library.runWithPipeline.issue.printerOffline`,`Target printer is offline.`)});case`filament_type_mismatch`:return(0,K.jsx)(K.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,K.jsx)(K.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,K.jsx)(K.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,K.jsx)(K.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,K.jsx)(K.Fragment,{children:e.kind})}}function RAe(){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 qW(e,t=`bambu_studio`){let n,r=encodeURIComponent(e);n=t===`orcaslicer`?`orcaslicer://open?file=${r}`:RAe()===`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)}var JW=768;function YW(){let[e,t]=(0,y.useState)(()=>typeof window<`u`?window.innerWidth{let e=window.matchMedia(`(max-width: ${JW-1}px)`),n=e=>{t(e.matches)};return t(e.matches),e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}function XW({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 zAe({onClose:e,initialFiles:t}){let{t:n}=W(),r=oo(),{showToast:i}=Pd(),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=J({mutationFn:e=>Q.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,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,K.jsx)(Ed,{className:`w-full max-w-2xl max-h-[90vh] flex flex-col`,children:(0,K.jsxs)(Od,{className:`p-0 flex flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:n(`uploadModal.title`)}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`p-4`,children:(0,K.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,K.jsx)(Nu,{className:`w-12 h-12 mx-auto mb-4 text-bambu-gray`}),(0,K.jsx)(`p`,{className:`text-white mb-2`,children:n(`uploadModal.dragDrop`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm mb-4`,children:n(`uploadModal.or`)}),(0,K.jsx)($,{variant:`secondary`,onClick:()=>a.current?.click(),disabled:x,children:n(`uploadModal.browseFiles`)}),(0,K.jsx)(`input`,{ref:a,type:`file`,accept:`.3mf`,multiple:!0,className:`hidden`,onChange:g})]})}),(0,K.jsx)(`div`,{className:`px-4 pb-4`,children:(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`uploadModal.extractionInfo`)})}),o.length>0&&(0,K.jsx)(`div`,{className:`px-4 pb-4 max-h-60 overflow-y-auto`,children:(0,K.jsx)(`div`,{className:`space-y-2`,children:o.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(oc,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`}),(0,K.jsx)(`span`,{className:`flex-1 text-white text-sm truncate`,children:e.file.name}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[(e.file.size/(1024*1024)).toFixed(1),` MB`]}),e.status===`pending`&&(0,K.jsx)(`button`,{onClick:()=>_(t),className:`text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,disabled:x,children:(0,K.jsx)(qu,{className:`w-4 h-4`})}),e.status===`uploading`&&(0,K.jsx)(X,{className:`w-4 h-4 text-bambu-green animate-spin`}),e.status===`success`&&(0,K.jsx)(hs,{className:`w-4 h-4 text-bambu-green`}),e.status===`error`&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-red-700 dark:text-red-400`,children:e.error}),(0,K.jsx)(ps,{className:`w-4 h-4 text-red-600 dark:text-red-400`})]})]},`${e.file.name}-${t}`))})}),u&&(0,K.jsx)(`div`,{className:`px-4 pb-4`,children:(0,K.jsx)(`div`,{className:`p-3 bg-bambu-dark rounded-lg`,children:(0,K.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,K.jsx)(`span`,{className:`text-bambu-green`,children:u.uploaded}),` `,n(`uploadModal.uploaded`),u.failed>0&&(0,K.jsxs)(K.Fragment,{children:[`, `,(0,K.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:u.failed}),` `,n(`uploadModal.failed`)]})]})})}),(0,K.jsxs)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:e,className:`flex-1`,children:n(u?`common.close`:`common.cancel`)}),!u&&(0,K.jsx)($,{onClick:v,disabled:b===0||x,className:`flex-1`,children:x?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),n(`uploadModal.uploading`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Nu,{className:`w-4 h-4`}),n(`uploadModal.upload`),` `,b>0&&`(${b})`]})})]})]})})})}var BAe=365;function VAe({onClose:e,initialDays:t}){let{t:n}=W(),r=oo(),{showToast:i}=Pd(),[a,o]=(0,y.useState)(t??BAe),[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=q({queryKey:[`archive-purge-preview`,l,s],queryFn:()=>Q.previewArchivePurge(l,s),enabled:l>=1}),f=J({mutationFn:()=>Q.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,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg shadow-xl max-w-lg w-full`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,K.jsx)(Eu,{className:`w-5 h-5`}),n(`archivePurge.title`)]}),(0,K.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,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:n(`archivePurge.description`)}),(0,K.jsxs)(`div`,{children:[(0,K.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,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.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,K.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:n(`archivePurge.days`)})]})]}),(0,K.jsxs)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/30 p-3`,children:[(0,K.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-gray-600 dark:text-gray-300 mb-2`,children:n(`archivePurge.effectsTitle`)}),(0,K.jsxs)(`ul`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1 list-disc pl-4`,children:[(0,K.jsx)(`li`,{children:n(`archivePurge.effect1`)}),(0,K.jsx)(`li`,{children:n(`archivePurge.effect2`)}),(0,K.jsx)(`li`,{children:n(`archivePurge.effect3`)}),(0,K.jsx)(`li`,{children:n(`archivePurge.effect4`)})]})]}),(0,K.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,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),` `,n(`archivePurge.previewLoading`)]}):d.isError?(0,K.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:d.error?.message??n(`archivePurge.previewFailed`)}):(0,K.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,K.jsx)(`div`,{className:`font-medium`,children:n(`archivePurge.previewSummary`,{count:m,size:Md(h)})}),p?.sample_filenames&&p.sample_filenames.length>0&&(0,K.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,K.jsx)(`li`,{className:`truncate`,children:e},e)),m>p.sample_filenames.length&&(0,K.jsx)(`li`,{className:`list-none italic text-gray-500`,children:n(`archivePurge.andMore`,{count:m-p.sample_filenames.length})})]})]})}),(0,K.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,K.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked),disabled:f.isPending,className:`mt-0.5 shrink-0`}),(0,K.jsxs)(`span`,{className:`text-xs text-gray-700 dark:text-gray-300`,children:[(0,K.jsx)(`span`,{className:`font-medium block mb-0.5`,children:n(`archivePurge.purgeStatsLabel`)}),(0,K.jsx)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:n(`archivePurge.purgeStatsHint`)})]})]}),(0,K.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,K.jsx)(ku,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,K.jsx)(`span`,{children:n(`archivePurge.warning`)})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:e,disabled:f.isPending,children:n(`common.cancel`)}),(0,K.jsx)($,{variant:`danger`,disabled:!g,onClick:()=>f.mutate(),children:f.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-1`}),n(`archivePurge.purging`)]}):n(`archivePurge.confirmCta`,{count:m})})]})]})})}function HAe(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 UAe(e){if(!e)return`—`;let t=jf(e);return t?t.toLocaleString():`—`}function ZW({archiveId:e}){let{t}=W(),{data:n,isLoading:r}=q({queryKey:[`archive-runs`,e],queryFn:()=>Q.getArchiveRuns(e)});if(r)return(0,K.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,K.jsx)(X,{className:`w-5 h-5 text-bambu-gray animate-spin`})});let i=n?.items||[];return i.length===0?(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:t(`archives.runLog.empty`)}):(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`th`,{className:`text-left py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.date`)}),(0,K.jsx)(`th`,{className:`text-left py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.status`)}),(0,K.jsx)(`th`,{className:`text-right py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.duration`)}),(0,K.jsx)(`th`,{className:`text-right py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.filament`)}),(0,K.jsx)(`th`,{className:`text-right py-1.5 font-medium`,children:t(`archives.runLog.col.cost`)})]})}),(0,K.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,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/40 last:border-0`,children:[(0,K.jsx)(`td`,{className:`py-1.5 pr-2 text-bambu-gray-light`,children:UAe(e.started_at||e.created_at)}),(0,K.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,K.jsx)(`span`,{className:`block text-[10px] text-bambu-gray font-normal`,children:t(`editArchive.failureReasons.${e.failure_reason}`,{defaultValue:e.failure_reason})})]}),(0,K.jsx)(`td`,{className:`py-1.5 pr-2 text-right text-bambu-gray-light`,children:HAe(e.duration_seconds)}),(0,K.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,K.jsx)(`td`,{className:`py-1.5 text-right text-bambu-gray-light`,children:e.cost==null?`—`:e.cost.toFixed(2)})]},e.id)})})]})})}var QW=[`adhesionFailure`,`spaghettiDetached`,`layerShift`,`cloggedNozzle`,`filamentRunout`,`warping`,`stringing`,`underExtrusion`,`powerFailure`,`userCancelled`,`other`],WAe=[`completed`,`failed`,`aborted`,`printing`];function $W({archive:e,onClose:t,existingTags:n=[]}){let{t:r}=W();(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let i=oo(),[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?QW.includes(t)?t:QW.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.photos||[]),[w,T]=(0,y.useState)(e.external_url||``),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),A=(0,y.useRef)(null),j=(0,y.useRef)(null),M=(0,y.useRef)(null),{data:N}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:P}=q({queryKey:[`projects`],queryFn:()=>Q.getProjects(),select:e=>[...e].sort((e,t)=>e.name.localeCompare(t.name))}),{data:F}=q({queryKey:[`tags`],queryFn:Q.getTags,enabled:n.length===0}),I=n.length>0?n:F?.map(e=>e.name)||[],L=p.split(`,`).map(e=>e.trim()).filter(Boolean),R=p.includes(`,`)?p.substring(p.lastIndexOf(`,`)+1).trim().toLowerCase():p.trim().toLowerCase(),z=I.filter(e=>!L.includes(e)&&(R===``||e.toLowerCase().includes(R))),B=e=>{let t;t=R&&!I.includes(R)?p.includes(`,`)?p.substring(0,p.lastIndexOf(`,`)).split(`,`).map(e=>e.trim()).filter(Boolean):[]:L,t.includes(e)||m([...t,e].join(`, `)),M.current!==null&&clearTimeout(M.current),A.current?.focus()},V=e=>{m(L.filter(t=>t!==e).join(`, `))},ee=J({mutationFn:t=>Q.updateArchive(e.id,t),onSuccess:()=>{i.invalidateQueries({queryKey:[`archives`]}),i.invalidateQueries({queryKey:[`projects`]}),t()}}),te=async t=>{let n=t.target.files?.[0];if(n){D(!0);try{C((await Q.uploadArchivePhoto(e.id,n)).photos),i.invalidateQueries({queryKey:[`archives`]})}catch(e){console.error(`Failed to upload photo:`,e)}finally{D(!1),j.current&&(j.current.value=``)}}},ne=async t=>{try{C((await Q.deleteArchivePhoto(e.id,t)).photos||[]),i.invalidateQueries({queryKey:[`archives`]})}catch(e){console.error(`Failed to delete photo:`,e)}};return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`editArchive.title`)}),(0,K.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.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:w||null};_!==e.status&&(n.status=_),_===`failed`||_===`aborted`?n.failure_reason=h||void 0:(e.status===`failed`||e.status===`aborted`)&&(n.failure_reason=null),ee.mutate(n)},className:`p-6 space-y-4 overflow-y-auto flex-1`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`archives.runLog.title`)}),(0,K.jsx)(ZW,{archiveId:e.id})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.name`)}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.printer`)}),(0,K.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,K.jsx)(`option`,{value:``,children:r(`editArchive.noPrinter`)}),N?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,K.jsx)(uc,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.project`)]}),(0,K.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,K.jsx)(`option`,{value:``,children:r(`editArchive.noProject`)}),P?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,K.jsx)(Oc,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.itemsPrinted`)]}),(0,K.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,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`editArchive.itemsPrintedHelp`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.notes`)}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,K.jsx)(Gc,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.externalLink`)]}),(0,K.jsx)(`input`,{type:`url`,value:w,onChange:e=>T(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,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`editArchive.externalLinkHelp`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.tags`)}),L.length>0&&(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:L.map(e=>(0,K.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,K.jsx)(vu,{className:`w-3 h-3`}),e,(0,K.jsx)(`button`,{type:`button`,onClick:()=>V(e),className:`ml-0.5 text-bambu-gray hover:text-white`,children:(0,K.jsx)(qu,{className:`w-3 h-3`})})]},e))}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`input`,{ref:A,type:`text`,value:p,onChange:e=>m(e.target.value),onFocus:()=>{M.current!==null&&clearTimeout(M.current),k(!0)},onBlur:()=>{M.current=window.setTimeout(()=>k(!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:L.length>0?r(`editArchive.addMoreTags`):r(`editArchive.tagsPlaceholder`)}),O&&z.length>0&&(0,K.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,K.jsxs)(`div`,{className:`p-2 text-xs text-bambu-gray border-b border-bambu-dark-tertiary`,children:[R?r(`editArchive.matchingTags`,{query:R}):r(`editArchive.existingTags`),` `,r(`editArchive.clickToAdd`)]}),(0,K.jsx)(`div`,{className:`p-2 flex flex-wrap gap-1.5`,children:z.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>B(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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.status`)}),(0,K.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:WAe.map(e=>(0,K.jsx)(`option`,{value:e,children:r(`editArchive.statuses.${e}`)},e))})]}),(_===`failed`||_===`aborted`)&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`failure-reason-select`,className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.failureReason`)}),(0,K.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,K.jsx)(`option`,{value:``,children:r(`editArchive.selectReason`)}),QW.map(e=>(0,K.jsx)(`option`,{value:e,children:r(`editArchive.failureReasons.${e}`)},e))]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,K.jsx)(es,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.photos`)]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-2`,children:[S.map(t=>(0,K.jsxs)(`div`,{className:`relative group`,children:[(0,K.jsx)(`img`,{src:Q.getArchivePhotoUrl(e.id,t),alt:r(`editArchive.printResult`),className:`w-20 h-20 object-cover rounded-lg border border-bambu-dark-tertiary`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>ne(t),className:`absolute -top-1 -right-1 p-1 bg-red-500 rounded-full opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,K.jsx)(Eu,{className:`w-3 h-3 text-white`})})]},t)),(0,K.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,K.jsx)(`input`,{ref:j,type:`file`,accept:`image/jpeg,image/png,image/webp`,onChange:te,className:`hidden`,disabled:E}),E?(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,K.jsx)(Ol,{className:`w-6 h-6 text-bambu-gray`})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`editArchive.photosHelp`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:r(`common.cancel`)}),(0,K.jsxs)($,{type:`submit`,disabled:ee.isPending,className:`flex-1`,children:[(0,K.jsx)(zl,{className:`w-4 h-4`}),ee.isPending?r(`common.saving`):r(`common.save`)]})]})]})]})})}function eG({archiveId:e,archiveName:t,onClose:n}){let{t:r}=W();return(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsx)(Mc,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,title:t||``,children:r(`archives.runLog.modalTitle`,{name:t||r(`archives.runLog.modalTitleFallback`)})})]}),(0,K.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:r(`common.close`),children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`p-6 overflow-y-auto flex-1`,children:(0,K.jsx)(ZW,{archiveId:e})})]})})}function GAe({items:e,searchPlaceholder:t,onClose:n,className:r,onMouseEnter:i,onMouseLeave:a}){let[o,s]=(0,y.useState)(``),c=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(t){let e=window.setTimeout(()=>c.current?.focus(),0);return()=>window.clearTimeout(e)}},[t]);let l=o.trim().toLowerCase(),u=t&&l?e.filter(e=>e.label.toLowerCase().includes(l)):e;return(0,K.jsxs)(`div`,{className:r,onMouseEnter:i,onMouseLeave:a,children:[t&&(0,K.jsx)(`div`,{className:`sticky top-0 z-[1] px-2 py-1.5 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Wl,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-bambu-gray pointer-events-none`}),(0,K.jsx)(`input`,{ref:c,type:`text`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{if(e.key===`Enter`){let e=u.find(e=>!e.disabled);e&&(e.onClick(),n())}},placeholder:t,className:`w-full pl-7 pr-2 py-1 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})}),u.map((e,t)=>(0,K.jsxs)(`button`,{onClick:()=>{e.disabled||(e.onClick(),n())},disabled:e.disabled,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${e.disabled?`text-bambu-gray cursor-not-allowed`:e.danger?`text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-400/10`:`text-white hover:bg-bambu-dark-tertiary`}`,children:[e.icon&&(0,K.jsx)(`span`,{className:`w-4 h-4 flex-shrink-0 flex items-center justify-center`,children:e.icon}),(0,K.jsx)(`span`,{className:`flex-1 truncate`,children:e.label})]},t)),t&&u.length===0&&(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray text-center italic`,children:`—`})]})}function tG({x:e,y:t,items:n,onClose:r}){let i=(0,y.useRef)(null),[a,o]=(0,y.useState)(null),s=(0,y.useRef)(null),[c,l]=(0,y.useState)({x:e,y:t,visible:!1}),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)({});(0,y.useEffect)(()=>{let e=e=>{i.current&&!i.current.contains(e.target)&&r()},t=e=>{e.key===`Escape`&&r()},n=e=>{i.current&&i.current.contains(e.target)||r()};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),document.addEventListener(`scroll`,n,!0),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t),document.removeEventListener(`scroll`,n,!0),s.current&&clearTimeout(s.current)}},[r]),(0,y.useLayoutEffect)(()=>{if(i.current){i.current.style.visibility=`hidden`,i.current.style.display=`block`;let n=i.current.getBoundingClientRect(),r=window.innerWidth,a=window.innerHeight,o=e,s=t;e+n.width>r-8&&(o=Math.max(8,r-n.width-8)),o<8&&(o=8),t+n.height>a-8&&(s=Math.max(8,a-n.height-8)),s<8&&(s=8),d(r-o-n.width<180&&o>180),l({x:o,y:s,visible:!0})}},[e,t]);let m=(e,t)=>{s.current&&=(clearTimeout(s.current),null);let n=t.getBoundingClientRect(),r=window.innerHeight-n.top-8<300&&n.top>300;p(t=>({...t,[e]:r?`bottom`:`top`})),o(e)},h=()=>{s.current=window.setTimeout(()=>{o(null)},150)};return(0,K.jsx)(`div`,{ref:i,className:`fixed z-50 min-w-[180px] max-w-[280px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1`,style:{left:c.x,top:c.y,visibility:c.visible?`visible`:`hidden`},children:n.map((e,t)=>{if(e.divider)return(0,K.jsx)(`div`,{className:`my-1 border-t border-bambu-dark-tertiary`},t);let n=e.submenu&&e.submenu.length>0;return(0,K.jsxs)(`div`,{className:`relative`,onMouseEnter:e=>n&&m(t,e.currentTarget),onMouseLeave:()=>n&&h(),children:[(0,K.jsxs)(`button`,{onMouseEnter:e=>n&&m(t,e.currentTarget.parentElement),onClick:()=>{n?o(a===t?null:t):e.disabled||(e.onClick(),r())},disabled:e.disabled,title:e.title,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${e.disabled?`text-bambu-gray cursor-not-allowed`:e.danger?`text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-400/10`:`text-white hover:bg-bambu-dark-tertiary`} ${n&&a===t?`bg-bambu-dark-tertiary`:``}`,children:[e.icon&&(0,K.jsx)(`span`,{className:`w-4 h-4 flex-shrink-0 flex items-center justify-center`,children:e.icon}),(0,K.jsx)(`span`,{className:`flex-1`,children:e.label}),n&&(0,K.jsx)(cs,{className:`w-4 h-4 text-bambu-gray`})]}),n&&a===t&&(0,K.jsx)(GAe,{items:e.submenu,searchPlaceholder:e.submenuSearchPlaceholder,onClose:r,className:`absolute min-w-[200px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 overflow-hidden max-h-[300px] overflow-y-auto z-[60] ${u?`right-full mr-1`:`left-full ml-1`} ${f[t]===`bottom`?`bottom-0`:`top-0`}`,onMouseEnter:()=>{s.current&&=(clearTimeout(s.current),null)},onMouseLeave:()=>h()})]},t)})})}function KAe({selectedIds:e,existingTags:t,onClose:n}){let r=oo(),{showToast:i}=Pd(),[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=J({mutationFn:async()=>{let t=Array.from(s),n=0;for(let r of e)try{let e=await Q.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 Q.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,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,K.jsx)(Ed,{className:`w-full max-w-md`,children:(0,K.jsxs)(Od,{className:`p-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(vu,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:l===`add`?`Add Tags`:`Remove Tags`})]}),(0,K.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[l===`add`?`Add`:`Remove`,` tags for `,e.length,` selected archive`,e.length===1?``:`s`]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{size:`sm`,variant:l===`add`?`primary`:`secondary`,onClick:()=>u(`add`),children:`Add Tags`}),(0,K.jsx)($,{size:`sm`,variant:l===`remove`?`primary`:`secondary`,onClick:()=>u(`remove`),children:`Remove Tags`})]}),l===`add`&&(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.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,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:p,disabled:!a.trim(),children:(0,K.jsx)(Ol,{className:`w-4 h-4`})})]}),t.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:`Existing tags:`}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t.map(e=>(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:[`Tags to `,l===`add`?`add`:`remove`,`:`]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Array.from(s).map(e=>(0,K.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,K.jsx)(`button`,{onClick:()=>f(e),className:`hover:opacity-70`,children:(0,K.jsx)(qu,{className:`w-3 h-3`})})]},e))})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:n,className:`flex-1`,children:`Cancel`}),(0,K.jsx)($,{onClick:()=>d.mutate(),disabled:s.size===0||d.isPending,className:`flex-1`,children:d.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),`Processing...`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(vu,{className:`w-4 h-4`}),l===`add`?`Add Tags`:`Remove Tags`]})})]})]})})})}function qAe({selectedIds:e,onClose:t}){let{t:n}=W(),r=oo(),{showToast:i}=Pd(),[a,o]=(0,y.useState)(``),{data:s,isLoading:c}=q({queryKey:[`projects`],queryFn:()=>Q.getProjects()}),l=(0,y.useMemo)(()=>s?[...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=()=>{r.invalidateQueries({queryKey:[`archives`]}),r.invalidateQueries({queryKey:[`projects`]}),r.invalidateQueries({queryKey:[`project`]}),r.invalidateQueries({queryKey:[`project-archives`]})},m=J({mutationFn:async t=>(await Q.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=J({mutationFn:async()=>{for(let t of e)await Q.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,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,K.jsx)(Ed,{className:`w-full max-w-md max-h-[80vh] flex flex-col`,children:(0,K.jsxs)(Od,{className:`p-0 flex flex-col min-h-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(uc,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:`Assign to Project`})]}),(0,K.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,disabled:g,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-3 overflow-y-auto min-h-0`,children:[(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`Assign `,e.length,` selected archive`,e.length===1?``:`s`,` to a project`]}),c?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-gray`})}):(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.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,K.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-red-500/20 flex items-center justify-center shrink-0`,children:(0,K.jsx)(xs,{className:`w-4 h-4 text-red-600 dark:text-red-400`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:`Remove from project`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray truncate`,children:`Clear project assignment`})]}),h.isPending&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin text-bambu-gray shrink-0`})]}),l&&l.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 py-2`,children:[(0,K.jsx)(`div`,{className:`flex-1 h-px bg-bambu-dark-tertiary`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`or assign to`}),(0,K.jsx)(`div`,{className:`flex-1 h-px bg-bambu-dark-tertiary`})]}),f&&(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Wl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,K.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,K.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,K.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,K.jsx)(uc,{className:`w-4 h-4`,style:{color:e.color||`rgb(var(--bambu-green))`}})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.name}),(0,K.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,K.jsx)(X,{className:`w-4 h-4 animate-spin text-bambu-gray shrink-0`})]},e.id)),(!l||l.length===0)&&(0,K.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,K.jsx)(`p`,{className:`text-center text-bambu-gray text-sm py-4`,children:`—`})]})]}),(0,K.jsx)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary shrink-0`,children:(0,K.jsx)($,{variant:`secondary`,onClick:t,className:`flex-1`,disabled:g,children:`Cancel`})})]})})})}function JAe(e,t){return new Date(e,t+1,0).getDate()}function YAe(e,t){return new Date(e,t,1).getDay()}var XAe=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],ZAe=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function QAe({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=jf(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=JAe(o,i),m=YAe(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,K.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-6`,children:[(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsx)(`button`,{onClick:h,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,K.jsx)(ls,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[XAe[i],` `,o]}),(0,K.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,K.jsx)(`button`,{onClick:g,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,K.jsx)(cs,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-7 gap-1 mb-1`,children:ZAe.map(e=>(0,K.jsx)(`div`,{className:`text-center text-xs text-bambu-gray py-2`,children:e},e))}),(0,K.jsx)(`div`,{className:`grid grid-cols-7 gap-1`,children:v.map((e,t)=>{if(e===null)return(0,K.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,K.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,K.jsx)(`span`,{className:`text-sm font-medium ${l&&!u?`text-bambu-green`:``}`,children:e}),s&&(0,K.jsxs)(`div`,{className:`absolute bottom-1 left-1/2 -translate-x-1/2 flex items-center gap-1`,children:[(0,K.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,K.jsx)(`span`,{className:`text-xs font-medium`,children:a.length})]})]},e)})}),(0,K.jsx)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-4 text-center`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-2xl font-bold text-white`,children:e.filter(e=>{let t=jf(e.completed_at||e.created_at)||new Date;return t.getMonth()===i&&t.getFullYear()===o}).length}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Prints this month`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-2xl font-bold text-green-700 dark:text-green-400`,children:e.filter(e=>{let t=jf(e.completed_at||e.created_at)||new Date;return t.getMonth()===i&&t.getFullYear()===o&&e.status===`completed`}).length}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Successful`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-2xl font-bold text-red-700 dark:text-red-400`,children:e.filter(e=>{let t=jf(e.completed_at||e.created_at)||new Date;return t.getMonth()===i&&t.getFullYear()===o&&e.status===`failed`}).length}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Failed`})]})]})})]}),(0,K.jsx)(`div`,{className:`lg:w-80 bg-bambu-dark rounded-xl p-4`,children:c?(0,K.jsxs)(K.Fragment,{children:[(0,K.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,K.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,K.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,K.jsx)(`img`,{src:Q.getArchiveThumbnail(e.id),alt:``,className:`w-12 h-12 rounded object-cover`}):(0,K.jsx)(`div`,{className:`w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`3MF`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.print_name||e.filename}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,K.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,K.jsx)(`div`,{className:`flex gap-0.5`,children:e.filament_color.split(`,`).map((e,t)=>(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:e}},t))})]})]})]},e.id)})}):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:`No prints on this day`})]}):(0,K.jsx)(`div`,{className:`text-center py-8`,children:(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:`Select a day to see prints`})})})]})}function nG({archiveId:e,archiveName:t,onClose:n}){let r=Q.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,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:`QR Code`}),(0,K.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-6 flex flex-col items-center`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 text-center truncate max-w-full`,children:t}),(0,K.jsx)(`div`,{className:`bg-white p-4 rounded-lg mb-4`,children:(0,K.jsx)(`img`,{src:r,alt:`QR Code`,className:`w-64 h-64`})}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4 text-center`,children:`Scan to open this archive`}),(0,K.jsxs)($,{onClick:()=>{let e=document.createElement(`a`);e.href=r,e.download=`${t}_qrcode.png`,e.click()},className:`w-full`,children:[(0,K.jsx)(Ws,{className:`w-4 h-4`}),`Download QR Code`]})]})]})})}function rG({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=Q.getArchivePhotoUrl(e,l);return(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:r,children:[(0,K.jsxs)(`div`,{className:`relative w-full h-full flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 bg-black/50`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`Photo `,a+1,` of `,n.length]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>{let e=document.createElement(`a`);e.href=u,e.download=`${t}_photo_${a+1}.jpg`,e.click()},children:[(0,K.jsx)(Ws,{className:`w-4 h-4`}),`Download`]}),i&&(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>{i&&c(!0)},className:`text-red-400 hover:text-red-300`,children:(0,K.jsx)(Eu,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:r,className:`p-2 text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(qu,{className:`w-6 h-6`})})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-h-0 flex items-center justify-center p-4 relative overflow-hidden`,children:[a>0&&(0,K.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,K.jsx)(ls,{className:`w-8 h-8 text-white`})}),(0,K.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,K.jsx)(cs,{className:`w-8 h-8 text-white`})})]}),n.length>1&&(0,K.jsx)(`div`,{className:`flex justify-center gap-2 p-4 bg-black/50`,children:n.map((t,n)=>(0,K.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,K.jsx)(`img`,{src:Q.getArchivePhotoUrl(e,t),alt:`Thumbnail ${n+1}`,className:`w-full h-full object-cover`})},t))})]}),s&&(0,K.jsx)(Vd,{title:`Delete Photo`,message:`Delete this photo? This cannot be undone.`,confirmText:`Delete`,variant:`danger`,onConfirm:()=>{i?.(l),c(!1)},onCancel:()=>c(!1)})]})}function iG(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n0||G.vt_tray.length>0)&&r===`expanded`&&(()=>{let t=$t.filter(e=>e.tray.length>1),n=$t.filter(e=>e.tray.length===1),r=e.nozzle_count===2||G?.temperatures?.nozzle_2!==void 0,i=`min-w-14`,g=(G.state===`RUNNING`||G.state===`PAUSE`)&&Array.isArray(G.ams_mapping)?G.ams_mapping:[],_=e=>{let t=Math.max(1,e),n=`calc(${t} * 3.5rem + ${Math.max(0,t-1)} * 0.25rem + 1rem)`;return{flex:`1 1 ${n}`,minWidth:n}};return(0,K.jsxs)(`div`,{className:`mt-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:j(`printers.filaments`)}),(0,K.jsx)(sAe,{state:G.ams_filament_backup,onClick:()=>pe(!0)}),(0,K.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[t.map(t=>{let n=Zt[String(t.id)],v=t.id>=128?t.id-128:t.id,y=n===void 0?v:n,b=y===1,S=y===0;return(0,K.jsxs)(`div`,{style:_(4),className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,K.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,K.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,K.jsx)(jW,{ams:t,printerId:e.id,label:Uf(t.id,t.tray.length),amsLabels:Ut,canEdit:F(`printers:update`),onSaved:Wt,children:(0,K.jsx)(`span`,{className:`block truncate text-[10px] text-white font-medium cursor-default select-none`,children:Ut?.[t.id]||Uf(t.id,t.tray.length)})}),r&&(b||S)&&(0,K.jsx)(gW,{side:b?`L`:`R`})]}),(t.humidity!=null||t.temp!=null)&&(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[t.humidity!=null&&(0,K.jsx)(xW,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>ut({amsId:t.id,amsLabel:Uf(t.id,t.tray.length),mode:`humidity`}),compact:!0}),t.temp!=null&&(0,K.jsx)(`div`,{className:`mr-1`,children:(0,K.jsx)(SW,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>ut({amsId:t.id,amsLabel:Uf(t.id,t.tray.length),mode:`temperature`}),compact:!0})}),(G.supports_drying||G.drying_screen_only)&&(t.module_type===`n3f`||t.module_type===`n3s`)&&F(`printers:control`)&&(0,K.jsx)(`button`,{disabled:G.drying_screen_only||!!(t.dry_sf_reason?.length&&t.dry_time===0),onClick:e=>{if(t.dry_time>0)Mn.mutate(t.id);else if(Ve===t.id)He(null);else{let n=(t.tray.find(e=>e.tray_type)?.tray_type||`PLA`).split(` `)[0].toUpperCase(),r=x[n]||x.PLA,i=t.module_type;Ke(n),Je(r[i]||r.n3f),Xe(i===`n3s`?r.n3s_hours:r.n3f_hours),Qe(!1),We(t.module_type),He(t.id),et(Vp({triggerRect:e.currentTarget.getBoundingClientRect(),popoverWidth:pW,estimatedHeight:mW,horizontalAlign:`center`}))}},className:`ml-1 flex items-center gap-0.5 px-1 py-0.5 rounded text-[9px] transition-colors ${t.dry_time>0?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:G.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:G.drying_screen_only?j(`printers.drying.screenOnly`):t.dry_time>0?j(`printers.drying.stop`):t.dry_sf_reason?.length?j(`printers.drying.powerRequired`):j(`printers.drying.start`),children:(0,K.jsx)(cc,{className:`w-3 h-3`})})]})]}),t.dry_time>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-amber-50 dark:bg-amber-500/10 px-2 py-1 text-[9px]`,children:[(0,K.jsx)(cc,{className:`w-3 h-3 text-amber-600 dark:text-amber-400 shrink-0`}),(0,K.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400 font-medium`,children:j(`printers.drying.active`)}),t.dry_filament&&t.dry_target_temp!=null&&(0,K.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70`,children:j(`printers.drying.targetSummary`,{filament:t.dry_filament,temp:t.dry_target_temp})}),(0,K.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70`,children:j(`printers.drying.timeRemaining`,{time:t.dry_time>=60?`${Math.floor(t.dry_time/60)}h ${t.dry_time%60}m`:`${t.dry_time}m`})}),!G.drying_screen_only&&(0,K.jsx)(`button`,{onClick:()=>Mn.mutate(t.id),disabled:Mn.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:j(`printers.drying.stop`),children:(0,K.jsx)(qu,{className:`w-3 h-3`})})]}),(0,K.jsx)(`div`,{className:`grid w-full grid-cols-[repeat(4,minmax(3.5rem,1fr))] gap-1`,children:[0,1,2,3].map(r=>{let a=t.tray[r]||t.tray.find(e=>e.id===r),_=a?.tray_type&&a.remain>=0,v=!a?.tray_type,y=CW(a),b=t.id*4+r,x=nn===b,S=rn!==null&&rn===b,C=an!==null&&an===b,w=a?.tray_info_idx?Rt?.[a.tray_info_idx]:null,T=zt?.[b],E=(a?.tray_uuid||a?.tag_uid||tp(e.serial_number,t.id,r))?.toUpperCase(),D=E?s?.[E]:void 0,O=Qf(D),k=o&&!m?p?.find(n=>n.printer_id===e.id&&n.ams_id===t.id&&n.tray_id===r):void 0,A=k?f?.find(e=>e.id===k.spoolman_spool_id):void 0,M=A&&(A.label_weight??0)>0?Math.round(Math.max(0,(A.label_weight??0)-A.weight_used)/(A.label_weight??1)*100):null,N=u?.(e.id,t.id,r),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&&_&&a.remain>0?null:P,L=O??M??I??(_?a.remain:null),R=O!==null||M!==null?`spoolman`:I===null?_?`ams`:void 0:`inventory`,z=a?.tray_type?{vendor:lp(a)?`Bambu Lab`:`Generic`,profile:T?.preset_name||(A?[A.brand,A.slicer_filament_name?.split(`@`)[0].trim()||A.material].filter(Boolean).join(` `).trim():null)||N?.spool?.slicer_filament_name||w?.name||a.tray_sub_brands||a.tray_type,colorName:nf(a.tray_color||``),colorHex:a.tray_color||null,kFactor:hW(a.k),fillLevel:L,trayUuid:a.tray_uuid||null,tagUid:a.tag_uid||null,fillSource:R}:null,B=sr?.amsId===t.id&&sr?.slotId===r,V=g.indexOf(b),ee=V>=0?`P${V+1}`:null,te=(0,K.jsxs)(`div`,{className:`relative w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${v?`opacity-50`:``} ${S?`ring-2 ring-amber-400 ring-offset-1 ring-offset-bambu-dark animate-pulse`:C?`ring-2 ring-red-500/60 ring-offset-1 ring-offset-bambu-dark`:x?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[S&&(0,K.jsx)(`span`,{"aria-label":j(`printers.expectedSlot.ariaLabel`,{n:r+1}),title:j(`printers.expectedSlot.title`),className:`absolute top-0.5 left-0.5 px-1 py-px text-[8px] font-bold text-bambu-dark bg-amber-400 rounded pointer-events-none leading-none`,children:`↓`}),ee&&(0,K.jsx)(`span`,{"aria-label":j(`printers.activeJobSlot.ariaLabel`,{n:V+1}),title:j(`printers.activeJobSlot.title`,{n:V+1}),className:`absolute top-0.5 right-0.5 px-1 py-px text-[8px] font-bold text-bambu-dark bg-bambu-green rounded pointer-events-none leading-none`,children:ee}),(0,K.jsx)(fW,{trayColor:a?.tray_color,trayType:a?.tray_type,isEmpty:v,emptyKind:y,slotNumber:r+1}),(0,K.jsx)(`div`,{className:`text-[9px] text-white font-bold truncate`,children:a?.tray_type||j(y===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,K.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:L!==null&&L>=0&&!v&&a&&(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${L}%`,backgroundColor:Zf(L)}})})]});return(0,K.jsxs)(`div`,{className:`relative group w-full ${i}`,children:[B&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-tertiary/80 rounded flex items-center justify-center z-20`,children:(0,K.jsx)(Pl,{className:`w-4 h-4 text-bambu-green animate-spin`})}),z?(0,K.jsx)(dU,{data:z,actions:Rr({amsId:t.id,slotId:r,loadTrayId:t.id*4+r,isRefreshing:B}),spoolman:{enabled:o,linkedSpoolId:k?.spoolman_spool_id??(E?s?.[E]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!k&&!N?()=>{let n=(z.trayUuid||z.tagUid||tp(e.serial_number,t.id,r)).toUpperCase();mt({tagUid:z.tagUid||n,trayUuid:z.trayUuid||``,printerId:e.id,amsId:t.id,trayId:r})}:void 0,onUnlinkSpool:D?.id?()=>An.mutate(D.id):void 0},inventory:(()=>{if(o){if(m)return;let n=k,i=A;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:()=>gt({printerId:e.id,amsId:t.id,trayId:r,trayInfo:{type:a?.tray_type||z.profile,material:a?.tray_type??void 0,profile:z.profile,color:z.colorHex||``,location:`${Uf(t.id,t.tray.length)} Slot ${r+1}`}}),onUnassignSpool:i&&!lp(a)?()=>h?.(i.id):void 0,isAssigned:!!n||lp(a)}}let n=u?.(e.id,t.id,r);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:()=>gt({printerId:e.id,amsId:t.id,trayId:r,trayInfo:{type:a?.tray_type||z.profile,material:a?.tray_type??void 0,profile:z.profile,color:z.colorHex||``,location:`${Uf(t.id,t.tray.length)} Slot ${r+1}`}}),onUnassignSpool:n&&!lp(a)?()=>d?.(e.id,t.id,r):void 0,isAssigned:!!n||lp(a)}})(),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>vt({amsId:t.id,trayId:r,trayCount:t.tray.length,trayType:a?.tray_type||void 0,trayColor:a?.tray_color||void 0,traySubBrands:a?.tray_sub_brands||void 0,trayInfoIdx:a?.tray_info_idx||void 0,extruderId:n,caliIdx:a?.cali_idx,savedPresetId:T?.preset_id})},children:te}):(0,K.jsx)(fU,{kind:y??void 0,actions:Rr({amsId:t.id,slotId:r,loadTrayId:t.id*4+r,isRefreshing:B}),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>vt({amsId:t.id,trayId:r,trayCount:t.tray.length,extruderId:n})},onAssignSpool:()=>gt({printerId:e.id,amsId:t.id,trayId:r,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`${Uf(t.id,t.tray.length)} Slot ${r+1}`}}),children:te})]},r)})})]},t.id)}),n.map(t=>{let n=Zt[String(t.id)],i=t.id>=128?t.id-128:t.id,_=n===void 0?i:n,v=_===1,y=_===0,b=t.tray[0],S=b?.tray_type&&b.remain>=0,C=!b?.tray_type,w=CW(b),T=Xf(t.id,b?.id??0,!1),E=nn===T,D=rn!==null&&rn===T,O=an!==null&&an===T,k=b?.tray_info_idx?Rt?.[b.tray_info_idx]:null,A=zt?.[T],M=b?.id??0,N=(b?.tray_uuid||b?.tag_uid||tp(e.serial_number,t.id,M))?.toUpperCase(),P=N?s?.[N]:void 0,I=Qf(P),L=u?.(e.id,t.id,M),R=(()=>{let e=L?.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})(),z=R===0&&S&&b.remain>0?null:R,B=o&&!m?p?.find(n=>n.printer_id===e.id&&n.ams_id===t.id&&n.tray_id===M):void 0,V=B?f?.find(e=>e.id===B.spoolman_spool_id):void 0,ee=V&&(V.label_weight??0)>0?Math.round(Math.max(0,(V.label_weight??0)-V.weight_used)/(V.label_weight??1)*100):null,te=I??ee??z??(S?b.remain:null),ne=I!==null||ee!==null?`spoolman`:z===null?S?`ams`:void 0:`inventory`,re=b?.tray_type?{vendor:lp(b)?`Bambu Lab`:`Generic`,profile:A?.preset_name||(V?[V.brand,V.slicer_filament_name?.split(`@`)[0].trim()||V.material].filter(Boolean).join(` `).trim():null)||L?.spool?.slicer_filament_name||k?.name||b.tray_sub_brands||b.tray_type,colorName:nf(b.tray_color||``),colorHex:b.tray_color||null,kFactor:hW(b.k),fillLevel:te,trayUuid:b.tray_uuid||null,tagUid:b.tag_uid||null,fillSource:ne}:null,ie=sr?.amsId===t.id&&sr?.slotId===M,H=g.indexOf(T),ae=H>=0?`P${H+1}`:null,oe=(0,K.jsxs)(`div`,{className:`relative w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${C?`opacity-50`:``} ${D?`ring-2 ring-amber-400 ring-offset-1 ring-offset-bambu-dark animate-pulse`:O?`ring-2 ring-red-500/60 ring-offset-1 ring-offset-bambu-dark`:E?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[D&&(0,K.jsx)(`span`,{"aria-label":j(`printers.expectedSlot.ariaLabel`,{n:1}),title:j(`printers.expectedSlot.title`),className:`absolute top-0.5 left-0.5 px-1 py-px text-[8px] font-bold text-bambu-dark bg-amber-400 rounded pointer-events-none leading-none`,children:`↓`}),ae&&(0,K.jsx)(`span`,{"aria-label":j(`printers.activeJobSlot.ariaLabel`,{n:H+1}),title:j(`printers.activeJobSlot.title`,{n:H+1}),className:`absolute top-0.5 right-0.5 px-1 py-px text-[8px] font-bold text-bambu-dark bg-bambu-green rounded pointer-events-none leading-none`,children:ae}),(0,K.jsx)(fW,{trayColor:b?.tray_color,trayType:b?.tray_type,isEmpty:C,emptyKind:w,slotNumber:1}),(0,K.jsx)(`div`,{className:`text-[9px] text-white font-bold truncate`,children:b?.tray_type||j(w===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,K.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:te!==null&&te>=0&&!C&&(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${te}%`,backgroundColor:Zf(te)}})})]});return(0,K.jsxs)(`div`,{style:{flex:`1 1 11rem`,minWidth:`11rem`},className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,K.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,K.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,K.jsx)(jW,{ams:t,printerId:e.id,label:Uf(t.id,t.tray.length),amsLabels:Ut,canEdit:F(`printers:update`),onSaved:Wt,children:(0,K.jsx)(`span`,{className:`block truncate text-[10px] text-white font-medium cursor-default select-none`,children:Ut?.[t.id]||Uf(t.id,t.tray.length)})}),r&&(v||y)&&(0,K.jsx)(gW,{side:v?`L`:`R`})]}),(G.supports_drying||G.drying_screen_only)&&(t.module_type===`n3f`||t.module_type===`n3s`)&&F(`printers:control`)&&(0,K.jsx)(`div`,{className:`relative ml-auto`,children:(0,K.jsx)(`button`,{disabled:G.drying_screen_only,onClick:e=>{if(t.dry_time>0)Mn.mutate(t.id);else if(Ve===t.id)He(null);else{let n=(t.tray.find(e=>e.tray_type)?.tray_type||`PLA`).split(` `)[0].toUpperCase(),r=x[n]||x.PLA,i=t.module_type;Ke(n),Je(r[i]||r.n3f),Xe(i===`n3s`?r.n3s_hours:r.n3f_hours),Qe(!1),We(t.module_type),He(t.id),et(Vp({triggerRect:e.currentTarget.getBoundingClientRect(),popoverWidth:pW,estimatedHeight:mW,horizontalAlign:`center`}))}},className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[9px] transition-colors ${t.dry_time>0?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:G.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:G.drying_screen_only?j(`printers.drying.screenOnly`):t.dry_time>0?j(`printers.drying.stop`):j(`printers.drying.start`),children:(0,K.jsx)(cc,{className:`w-3 h-3`})})})]}),t.dry_time>0&&(0,K.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-[9px]`,children:[(0,K.jsx)(cc,{className:`w-3 h-3 text-amber-600 dark:text-amber-400 shrink-0`}),t.dry_filament&&t.dry_target_temp!=null&&(0,K.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70 text-[8px] truncate`,children:j(`printers.drying.targetSummary`,{filament:t.dry_filament,temp:t.dry_target_temp})}),(0,K.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70 text-[8px] truncate`,children:t.dry_time>=60?`${Math.floor(t.dry_time/60)}h ${t.dry_time%60}m`:`${t.dry_time}m`}),!G.drying_screen_only&&(0,K.jsx)(`button`,{onClick:()=>Mn.mutate(t.id),disabled:Mn.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:j(`printers.drying.stop`),children:(0,K.jsx)(qu,{className:`w-3 h-3`})})]}),(0,K.jsxs)(`div`,{className:`flex gap-1.5 max-[550px]:flex-col max-[550px]:items-start`,children:[(0,K.jsxs)(`div`,{className:`relative group min-w-14 flex-1`,children:[ie&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-tertiary/80 rounded flex items-center justify-center z-20`,children:(0,K.jsx)(Pl,{className:`w-4 h-4 text-bambu-green animate-spin`})}),re?(0,K.jsx)(dU,{data:re,actions:Rr({amsId:t.id,slotId:M,loadTrayId:t.id*4+M,isRefreshing:ie}),spoolman:{enabled:o,linkedSpoolId:B?.spoolman_spool_id??(N?s?.[N]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!B&&!L?()=>{let n=(re.trayUuid||re.tagUid||tp(e.serial_number,t.id,M)).toUpperCase();mt({tagUid:re.tagUid||n,trayUuid:re.trayUuid||``,printerId:e.id,amsId:t.id,trayId:M})}:void 0,onUnlinkSpool:P?.id?()=>An.mutate(P.id):void 0},inventory:(()=>{if(o){if(m)return;let n=B,r=V;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:()=>gt({printerId:e.id,amsId:t.id,trayId:M,trayInfo:{type:b?.tray_type||re.profile,material:b?.tray_type??void 0,profile:re.profile,color:re.colorHex||``,location:Uf(t.id,t.tray.length)}}),onUnassignSpool:r&&!lp(b)?()=>h?.(r.id):void 0,isAssigned:!!n||lp(b)}}let n=u?.(e.id,t.id,M);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:()=>gt({printerId:e.id,amsId:t.id,trayId:M,trayInfo:{type:b?.tray_type||re.profile,material:b?.tray_type??void 0,profile:re.profile,color:re.colorHex||``,location:Uf(t.id,t.tray.length)}}),onUnassignSpool:n&&!lp(b)?()=>d?.(e.id,t.id,M):void 0,isAssigned:!!n||lp(b)}})(),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>vt({amsId:t.id,trayId:M,trayCount:t.tray.length,trayType:b?.tray_type||void 0,trayColor:b?.tray_color||void 0,traySubBrands:b?.tray_sub_brands||void 0,trayInfoIdx:b?.tray_info_idx||void 0,extruderId:n,caliIdx:b?.cali_idx,savedPresetId:A?.preset_id})},children:oe}):(0,K.jsx)(fU,{kind:w??void 0,actions:Rr({amsId:t.id,slotId:M,loadTrayId:t.id*4+M,isRefreshing:ie}),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>vt({amsId:t.id,trayId:M,trayCount:t.tray.length,extruderId:n})},onAssignSpool:()=>gt({printerId:e.id,amsId:t.id,trayId:M,trayInfo:{type:``,material:void 0,profile:``,color:``,location:Uf(t.id,t.tray.length)}}),children:oe})]}),(t.humidity!=null||t.temp!=null)&&(0,K.jsxs)(`div`,{className:`flex flex-col justify-center gap-1 shrink-0 max-[550px]:w-full`,children:[t.temp!=null&&(0,K.jsx)(SW,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>ut({amsId:t.id,amsLabel:Uf(t.id,t.tray.length),mode:`temperature`}),compact:!0}),t.humidity!=null&&(0,K.jsx)(xW,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>ut({amsId:t.id,amsLabel:Uf(t.id,t.tray.length),mode:`humidity`}),compact:!0})]})]})]},t.id)}),G.vt_tray.length>0&&(0,K.jsxs)(`div`,{style:_(G.vt_tray.length),className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,K.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,K.jsx)(`span`,{className:`block min-w-0 flex-1 truncate text-[10px] text-white font-medium`,children:j(`printers.external`)})}),(0,K.jsx)(`div`,{className:`grid w-full ${G.vt_tray.length>1?`grid-cols-[repeat(2,minmax(3.5rem,1fr))]`:`grid-cols-[minmax(3.5rem,1fr)]`} gap-1`,children:[...G.vt_tray].sort((e,t)=>(e.id??254)-(t.id??254)).map(t=>{let n=t.id??254,a=r&&nn===254?n===254&&G.active_extruder===1||n===255&&G.active_extruder===0:nn===n,g=n-254,_=r?j(n===254?`printers.extL`:`printers.extR`):``,v=t.tray_info_idx?Rt?.[t.tray_info_idx]:null,y=zt?.[1020+g],b=(t.tray_uuid||t.tag_uid||tp(e.serial_number,255,g))?.toUpperCase(),x=b?s?.[b]:void 0,S=Qf(x),C=u?.(e.id,255,g),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===g):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),M=S!==null||k!==null?`spoolman`:E===null?T?`ams`:void 0:`inventory`,N={vendor:lp(t)?`Bambu Lab`:`Generic`,profile:y?.preset_name||(O?[O.brand,O.slicer_filament_name?.split(`@`)[0].trim()||O.material].filter(Boolean).join(` `).trim():null)||C?.spool?.slicer_filament_name||v?.name||t.tray_sub_brands||t.tray_type||`Unknown`,colorName:nf(t.tray_color||``),colorHex:t.tray_color||null,kFactor:hW(t.k),fillLevel:A,trayUuid:t.tray_uuid||null,tagUid:t.tag_uid||null,fillSource:M},P=!t.tray_type,I=CW(t),L=(0,K.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${P?`opacity-50`:``} ${a?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[(0,K.jsx)(fW,{trayColor:t.tray_color,trayType:t.tray_type,isEmpty:P,emptyKind:I,slotNumber:r?n===254?`L`:`R`:g+1}),(0,K.jsx)(`div`,{className:`text-[9px] font-bold truncate ${P?`text-white/40`:`text-white`}`,children:t.tray_type||j(`ams.slotEmpty`)}),(0,K.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:A!==null&&A>=0&&!P&&(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${A}%`,backgroundColor:Zf(A)}})})]});return(0,K.jsx)(`div`,{className:`relative group w-full ${i}`,children:P?(0,K.jsx)(fU,{kind:I??void 0,actions:Rr({amsId:255,slotId:g,loadTrayId:n,includeRfid:!1}),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>vt({amsId:255,trayId:g,trayCount:1,extruderId:r?+(n===254):void 0})},onAssignSpool:()=>gt({printerId:e.id,amsId:255,trayId:g,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`External Slot ${g+1}`}}),children:L}):(0,K.jsx)(dU,{data:N,actions:Rr({amsId:255,slotId:g,loadTrayId:n,includeRfid:!1}),spoolman:{enabled:o,linkedSpoolId:D?.spoolman_spool_id??(b?s?.[b]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!D&&!C?()=>{let t=(N.trayUuid||N.tagUid||tp(e.serial_number,255,g)).toUpperCase();mt({tagUid:N.tagUid||t,trayUuid:N.trayUuid||``,printerId:e.id,amsId:255,trayId:g})}:void 0,onUnlinkSpool:x?.id?()=>An.mutate(x.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:()=>gt({printerId:e.id,amsId:255,trayId:g,trayInfo:{type:t.tray_type||N.profile,material:t.tray_type??void 0,profile:N.profile,color:N.colorHex||``,location:_||j(`printers.external`)}}),onUnassignSpool:r&&!lp(t)?()=>h?.(r.id):void 0,isAssigned:!!n||lp(t)}}let n=u?.(e.id,255,g);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:()=>gt({printerId:e.id,amsId:255,trayId:g,trayInfo:{type:t.tray_type||N.profile,material:t.tray_type??void 0,profile:N.profile,color:N.colorHex||``,location:_||j(`printers.external`)}}),onUnassignSpool:n&&!lp(t)?()=>d?.(e.id,255,g):void 0,isAssigned:!!n||lp(t)}})(),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>vt({amsId:255,trayId:g,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:r?+(n===254):void 0,caliIdx:t.cali_idx,savedPresetId:y?.preset_id})},children:L})},n)})})]})]})]})})()]}),r===`expanded`&&(0,K.jsxs)(`div`,{className:`mt-auto`,children:[cn&&(0,K.jsxs)(`div`,{className:`pt-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:j(`printers.power`,`Power`)}),(0,K.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 rounded-[10px] bg-bambu-dark p-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 pl-1`,children:[(0,K.jsx)(Yu,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm text-white truncate`,children:cn.name}),(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray text-[10px] font-medium flex-shrink-0`,title:j(`smartPlugs.power`),children:un?.energy?.power!==null&&un?.energy?.power!==void 0?`${Math.round(un.energy.power)}W`:`--`})]}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>Fn.mutate(!cn.auto_off),disabled:Fn.isPending||cn.auto_off_executed||!F(`smart_plugs:control`),title:F(`smart_plugs:control`)?cn.auto_off_executed?j(`printers.autoOffExecuted`):j(`printers.autoOffAfterPrint`):j(`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 ${F(`smart_plugs:control`)?cn.auto_off||cn.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,K.jsx)(ws,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>{un?.state===`ON`?se(!0):oe(!0)},disabled:Pn.isPending||!F(`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 ${F(`smart_plugs:control`)?un?.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:F(`smart_plugs:control`)?un?.state===`ON`?`Turn off`:`Turn on`:j(`printers.permission.noSmartPlugControl`),children:(0,K.jsx)(Yu,{className:`w-4 h-4`})})]})]}),ln&&ln.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,K.jsx)(Nc,{className:`w-3.5 h-3.5 text-blue-600 dark:text-blue-400 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`HA:`}),(0,K.jsx)(`div`,{className:`h-[2px] w-5 bg-bambu-dark-tertiary/50`}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:ln.map(e=>{let t=e.ha_entity_id?.startsWith(`script.`);return(0,K.jsxs)(`button`,{onClick:()=>{t?In.mutate({id:e.id,action:`on`}):le(e)},disabled:In.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,K.jsx)(El,{className:`w-2.5 h-2.5`}),e.name]},e.id)})})]})]}),(0,K.jsxs)(`div`,{className:`pt-4`,children:[(0,K.jsx)(`div`,{className:`mb-3 h-[2px] bg-bambu-dark-tertiary`}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[zr,(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>{if(_===`embedded`&&v)v(e.id,e.name);else{let t=localStorage.getItem(`cameraWindowState`),n=t?JSON.parse(t):{width:640,height:400},r=[`width=${n.width}`,`height=${n.height}`,n.left===void 0?``:`left=${n.left}`,n.top===void 0?``:`top=${n.top}`,`menubar=no,toolbar=no,location=no,status=no`].filter(Boolean).join(`,`);window.open(`/camera/${e.id}`,`camera-${e.id}`,r)}},disabled:!G?.connected||!F(`camera:view`),title:F(`camera:view`)?j(_===`embedded`?`printers.openCameraOverlay`:`printers.openCameraWindow`):j(`printers.permission.noCamera`),className:Lr,children:(0,K.jsx)(Lu,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>re(!0),disabled:!Yt||!F(`printers:files`),title:F(`printers:files`)?j(`printers.browseFiles`):j(`printers.permission.noFiles`),className:Lr,children:(0,K.jsx)(Dc,{className:`w-4 h-4`})}),Yt&&G?.state!==`RUNNING`&&G?.state!==`PAUSE`&&(0,K.jsxs)($,{size:`sm`,onClick:()=>Ne(!0),disabled:!F(`library:upload`)||!F(`queue:create`),title:F(`library:upload`)?F(`queue:create`)?j(`common.print`):j(`fileManager.noPermissionAddToQueue`):j(`fileManager.noPermissionUpload`),className:`!h-8 !min-h-8 !px-2 !py-0 !bg-bambu-green hover:!bg-bambu-green/80 !text-white`,children:[(0,K.jsx)(jl,{className:`w-4 h-4`}),j(`common.print`)]})]})]})]})]})]}),ne&&(0,K.jsx)(yle,{printerId:e.id,printerName:e.name,onClose:()=>re(!1)}),Me&&(0,K.jsx)(JU,{folderId:null,onClose:()=>Ne(!1),onUploadComplete:()=>{},autoUpload:!0,accept:`.gcode,.3mf`,validateFile:e=>{let t=e.name.toLowerCase();if(!t.endsWith(`.gcode`)&&!t.includes(`.gcode.`))return j(`printers.dropNotPrintable`,`Only .gcode and .gcode.3mf files can be printed`)},onFileUploaded:t=>{let n=t.metadata?.sliced_for_model,r=AW(e.model);if(n&&r&&n.toLowerCase()!==r.toLowerCase())return Q.deleteLibraryFile(t.id).catch(()=>{}),j(`printers.incompatibleFile`,`This file was sliced for {{slicedFor}}, but this printer is a {{printerModel}}`,{slicedFor:n,printerModel:r});Be({id:t.id,filename:t.filename})}}),ze&&(0,K.jsx)(uW,{mode:`create`,libraryFileId:ze.id,archiveName:ze.filename,initialSelectedPrinterIds:[e.id],onClose:()=>Be(null),onSuccess:()=>Be(null),cleanupLibraryAfterDispatch:!0}),ie&&(0,K.jsx)(Nle,{printerId:e.id,printerName:e.name,onClose:()=>H(!1)}),Ie&&(0,K.jsx)(vp,{printerId:e.id,printerName:e.name,onClose:()=>Le(!1)}),Pe&&(0,K.jsx)(Xke,{printer:e,status:G,totalPrintHours:n?.total_print_hours,onClose:Re}),xt&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:()=>Sr(),children:(0,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[xt.needs_calibration?(0,K.jsx)(Hl,{className:`w-5 h-5 text-blue-500`}):xt.is_empty?(0,K.jsx)(hs,{className:`w-5 h-5 text-green-500`}):(0,K.jsx)(xs,{className:`w-5 h-5 text-yellow-500`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:`Build Plate Check`}),xt.reference_count!==void 0&&xt.max_references&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[xt.reference_count,`/`,xt.max_references,` refs`]})]}),(0,K.jsx)(`button`,{onClick:()=>Sr(),className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[xt.needs_calibration?(0,K.jsxs)(K.Fragment,{children:[(0,K.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,K.jsx)(`p`,{className:`font-medium text-blue-700 dark:text-blue-400`,children:j(`printers.plateDetection.calibrationRequired`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,dangerouslySetInnerHTML:{__html:j(`printers.plateDetection.calibrationInstructions`)}})]}),(0,K.jsxs)(`div`,{className:`text-sm text-bambu-gray space-y-2`,children:[(0,K.jsx)(`p`,{children:j(`printers.plateDetection.calibrationDescription`)}),(0,K.jsx)(`p`,{dangerouslySetInnerHTML:{__html:j(`printers.plateDetection.calibrationTip`)}})]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`p-3 rounded-lg ${xt.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,K.jsx)(`p`,{className:`font-medium ${xt.is_empty?`text-green-700 dark:text-green-400`:`text-yellow-700 dark:text-yellow-400`}`,children:xt.is_empty?j(`printers.plateDetection.plateEmpty`):j(`printers.plateDetection.objectsDetected`)}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:[j(`printers.plateDetection.confidence`),`: `,Math.round(xt.confidence*100),`% | `,j(`printers.plateDetection.difference`),`: `,xt.difference_percent.toFixed(1),`%`]})]}),xt.debug_image_url&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:j(`printers.plateDetection.analysisPreview`)}),(0,K.jsx)(`img`,{src:xt.debug_image_url,alt:j(`printers.plateDetection.analysisPreview`),className:`w-full rounded-lg border border-bambu-dark-tertiary`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:j(`printers.plateDetection.analysisLegend`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:xt.message})]}),hr&&hr.references.length>0&&(0,K.jsxs)(`div`,{className:`mt-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white shrink-0`,children:j(`printers.plateDetection.savedReferences`,{count:hr.references.length,max:hr.max_references})}),(0,K.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-5 gap-2`,children:hr.references.map(t=>(0,K.jsxs)(`div`,{className:`relative group`,children:[(0,K.jsx)(`img`,{src:Q.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,K.jsx)(`button`,{onClick:()=>Tr(t.index),className:`absolute top-1 right-1 p-0.5 bg-red-500/80 rounded opacity-0 group-hover:opacity-100 transition-opacity`,title:j(`printers.plateDetection.deleteReference`),children:(0,K.jsx)(qu,{className:`w-3 h-3 text-white`})}),_r?.index===t.index?(0,K.jsx)(`input`,{type:`text`,value:_r.label,onChange:e=>vr({..._r,label:e.target.value}),onBlur:()=>wr(t.index,_r.label),onKeyDown:e=>{e.key===`Enter`&&wr(t.index,_r.label),e.key===`Escape`&&vr(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:j(`printers.plateDetection.labelPlaceholder`)}):(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1 truncate cursor-pointer hover:text-white`,onClick:()=>vr({index:t.index,label:t.label}),title:t.label?j(`printers.plateDetection.clickToEdit`,{label:t.label}):j(`printers.plateDetection.clickToAddLabel`),children:t.label||(0,K.jsx)(`span`,{className:`italic opacity-50`,children:j(`printers.noLabel`)})}),(0,K.jsx)(`p`,{className:`text-[10px] text-bambu-gray/60`,children:t.timestamp?jf(t.timestamp)?.toLocaleDateString()??``:``})]},t.index))})]}),!xt.needs_calibration&&(0,K.jsxs)(`div`,{className:`mt-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white shrink-0`,children:j(`printers.roi.title`)}),(0,K.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),Dt?(0,K.jsxs)(`div`,{className:`flex gap-1`,children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>Ot(null),disabled:kt,children:j(`common.cancel`)}),(0,K.jsx)($,{size:`sm`,onClick:Er,disabled:kt,children:kt?(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`}):j(`common.save`)})]}):(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>Ot(xt.roi||{x:.15,y:.35,w:.7,h:.55}),children:[(0,K.jsx)(wl,{className:`w-3 h-3 mr-1`}),j(`common.edit`)]})]}),Dt?(0,K.jsxs)(`div`,{className:`space-y-3 bg-bambu-dark-tertiary/50 p-3 rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:j(`printers.roi.xStart`)}),(0,K.jsx)(`input`,{type:`range`,min:`0`,max:`0.9`,step:`0.01`,value:Dt.x,onChange:e=>Ot({...Dt,x:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Dt.x*100),`%`]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:j(`printers.roi.yStart`)}),(0,K.jsx)(`input`,{type:`range`,min:`0`,max:`0.9`,step:`0.01`,value:Dt.y,onChange:e=>Ot({...Dt,y:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Dt.y*100),`%`]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:j(`printers.width`)}),(0,K.jsx)(`input`,{type:`range`,min:`0.1`,max:`1`,step:`0.01`,value:Dt.w,onChange:e=>Ot({...Dt,w:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Dt.w*100),`%`]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:j(`printers.height`)}),(0,K.jsx)(`input`,{type:`range`,min:`0.1`,max:`1`,step:`0.01`,value:Dt.h,onChange:e=>Ot({...Dt,h:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Dt.h*100),`%`]})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:j(`printers.roi.instruction`)})]}):(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[`Current: X=`,Math.round((xt.roi?.x||.15)*100),`%, Y=`,Math.round((xt.roi?.y||.35)*100),`%, W=`,Math.round((xt.roi?.w||.7)*100),`%, H=`,Math.round((xt.roi?.h||.55)*100),`%`]})]})]}),(0,K.jsx)(`div`,{className:`flex justify-end gap-2 p-4`,children:xt.needs_calibration?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)($,{variant:`ghost`,onClick:()=>Sr(),children:j(`common.cancel`)}),(0,K.jsx)($,{onClick:()=>Cr(),disabled:Tt,children:Tt?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 mr-2 animate-spin`}),`Calibrating...`]}):`Calibrate Empty Plate`})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)($,{variant:`ghost`,onClick:()=>Cr(),disabled:Tt,children:Tt?`Adding...`:`Add Reference (${hr?.references.length||0}/${hr?.max_references||5})`}),(0,K.jsx)($,{onClick:()=>Sr(),children:`Close`})]})})]})}),ae&&cn&&(0,K.jsx)(Vd,{title:j(`printers.confirm.powerOnTitle`),message:j(`printers.confirm.powerOnMessage`,{name:e.name}),confirmText:j(`printers.confirm.powerOnButton`),variant:`default`,onConfirm:()=>{Pn.mutate(`on`),oe(!1)},onCancel:()=>oe(!1)}),tr&&(0,K.jsx)(Vd,{title:j(`printers.maintenance.confirmMidPrintTitle`),message:j(`printers.maintenance.confirmMidPrintMessage`,{name:e.name}),confirmText:j(`printers.maintenance.menuEnter`),variant:`danger`,onConfirm:()=>{er.mutate(!1),nr(!1)},onCancel:()=>nr(!1)}),U&&cn&&(0,K.jsx)(Vd,{title:j(`printers.confirm.powerOffTitle`),message:G?.state===`RUNNING`?j(`printers.confirm.powerOffWarning`,{name:e.name}):j(`printers.confirm.powerOffMessage`,{name:e.name}),confirmText:j(`printers.confirm.powerOffButton`),variant:`danger`,onConfirm:()=>{Pn.mutate(`off`),se(!1)},onCancel:()=>se(!1)}),ce&&(0,K.jsx)(Vd,{title:j(`printers.confirm.haToggleTitle`,{name:ce.name}),message:G?.state===`RUNNING`?j(`printers.confirm.haToggleWarning`,{name:e.name,entity:ce.ha_entity_id||ce.name}):j(`printers.confirm.haToggleMessage`,{entity:ce.ha_entity_id||ce.name}),confirmText:j(`printers.confirm.haToggleButton`),variant:G?.state===`RUNNING`?`danger`:`default`,onConfirm:()=>{In.mutate({id:ce.id,action:`toggle`}),le(null)},onCancel:()=>le(null)}),me&&(0,K.jsx)(Vd,{title:j(`printers.confirm.stopTitle`),message:j(`printers.confirm.stopMessage`,{name:e.name}),confirmText:j(`printers.confirm.stopButton`),variant:`danger`,onConfirm:()=>{Ln.mutate(),he(!1)},onCancel:()=>he(!1)}),ge&&(0,K.jsx)(Vd,{title:j(`printers.confirm.pauseTitle`),message:j(`printers.confirm.pauseMessage`,{name:e.name}),confirmText:j(`printers.confirm.pauseButton`),variant:`default`,onConfirm:()=>{Rn.mutate(),_e(!1)},onCancel:()=>_e(!1)}),Oe&&(0,K.jsx)(Vd,{title:j(`printers.confirm.resumeTitle`),message:j(`printers.confirm.resumeMessage`,{name:e.name}),confirmText:j(`printers.confirm.resumeButton`),variant:`default`,onConfirm:()=>{zn.mutate(),ke(!1)},onCancel:()=>ke(!1)}),(0,K.jsx)(hT,{printerId:e.id,isOpen:Ae,onClose:()=>je(!1)}),ue&&(0,K.jsx)(fee,{printerName:e.name,errors:G?.hms_errors||[],onClose:()=>de(!1),printerId:e.id,hasPermission:F,runoutGuidance:sn}),fe&&G&&(0,K.jsx)(vke,{isOpen:fe,state:G.ams_filament_backup,amsUnits:G.ams,amsExtruderMap:G.ams_extruder_map,isDualNozzle:e.nozzle_count===2||G?.temperatures?.nozzle_2!==void 0,canToggle:F(`printers:control`),pending:Nn.isPending,onToggle:e=>Nn.mutate(e),onClose:()=>pe(!1)}),lt&&(0,K.jsx)(mke,{isOpen:!!lt,onClose:()=>ut(null),printerId:e.id,printerName:e.name,amsId:lt.amsId,amsLabel:lt.amsLabel,initialMode:lt.mode,thresholds:a}),dt&&(0,K.jsx)(bke,{isOpen:!!dt,onClose:()=>ft(null),printerId:e.id,printerName:e.name,initialKind:dt.initialKind,availableKinds:dt.availableKinds}),pt&&(0,K.jsx)(pU,{isOpen:!!pt,onClose:()=>mt(null),tagUid:pt.tagUid,trayUuid:pt.trayUuid,printerId:pt.printerId,amsId:pt.amsId,trayId:pt.trayId}),ht&&(0,K.jsx)(hU,{isOpen:!!ht,onClose:()=>gt(null),printerId:ht.printerId,amsId:ht.amsId,trayId:ht.trayId,trayInfo:ht.trayInfo,spoolmanEnabled:!!o}),_t&&(0,K.jsx)(KU,{isOpen:!!_t,onClose:()=>vt(null),printerId:e.id,slotInfo:_t,printerModel:AW(e.model)||void 0,nozzleDiameter:cp(G,_t.amsId),onSuccess:()=>{M.invalidateQueries({queryKey:[`slotPresets`,e.id]}),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})}}),ee&&(0,K.jsx)(_Ae,{printer:e,onClose:()=>te(!1)}),yt&&Nt&&(0,K.jsx)(gAe,{printer:e,firmwareInfo:Nt,onClose:()=>bt(!1)}),Ve!==null&&$e&&(()=>{let e=Ue===`n3s`?85:65,t=e+10;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-[100]`,onClick:()=>He(null)}),(0,K.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:{top:$e.top,left:$e.left,maxHeight:`calc(100dvh - ${$e.top}px - 8px)`},onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`shrink-0 flex items-center justify-center gap-2 px-3 py-2.5`,children:[(0,K.jsx)(cc,{className:`w-3.5 h-3.5 text-bambu-green`}),(0,K.jsx)(`span`,{className:`text-sm text-white font-medium text-center`,children:j(`printers.drying.start`)})]}),(0,K.jsx)(`div`,{className:`shrink-0 h-px bg-bambu-dark-tertiary`}),(0,K.jsxs)(`div`,{className:`px-3 py-2.5 space-y-2.5 overflow-y-auto min-h-0`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-[10px] text-white/70 font-medium mb-1 block`,children:j(`printers.filaments`)}),(0,K.jsx)(wW,{value:Ge,options:Object.keys(x).map(e=>({value:e,label:e})),onChange:e=>{Ke(e);let t=x[e];t&&(Je(t[Ue===`n3s`?`n3s`:`n3f`]),Xe(Ue===`n3s`?t.n3s_hours:t.n3f_hours))},fullWidth:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,K.jsx)(`label`,{className:`text-[10px] text-white/70 font-medium`,children:j(`printers.drying.temperature`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`input`,{type:`number`,min:45,max:e,value:qe,onChange:t=>Je(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-[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,K.jsx)(`span`,{className:`text-[10px] text-bambu-gray`,children:`°C`})]})]}),(0,K.jsx)(`input`,{type:`range`,min:35,max:t,value:qe,onChange:t=>Je(Math.min(e,Math.max(45,Number(t.target.value)))),className:`w-full h-1 accent-bambu-green cursor-pointer`}),(0,K.jsxs)(`div`,{className:`flex justify-between text-[9px] text-bambu-gray/50 mt-0.5`,children:[(0,K.jsx)(`span`,{children:`45°C`}),(0,K.jsxs)(`span`,{children:[e,`°C`]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,K.jsx)(`label`,{className:`text-[10px] text-white/70 font-medium`,children:j(`printers.drying.duration`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`input`,{type:`number`,min:1,max:24,value:Ye,onChange:e=>Xe(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-[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,K.jsx)(`span`,{className:`text-[10px] text-bambu-gray`,children:j(`printers.drying.hours`)})]})]}),(0,K.jsx)(`input`,{type:`range`,min:1,max:24,value:Ye,onChange:e=>Xe(Number(e.target.value)),className:`w-full h-1 accent-bambu-green cursor-pointer`}),(0,K.jsxs)(`div`,{className:`flex justify-between text-[9px] text-bambu-gray/50 mt-0.5`,children:[(0,K.jsx)(`span`,{children:`1h`}),(0,K.jsx)(`span`,{children:`24h`})]})]}),(()=>{let e=((Ve===null?void 0:$t.find(e=>e.id===Ve))?.tray??[]).some(e=>e.state===11),t=Ze&&!e;return(0,K.jsx)(`button`,{type:`button`,onClick:()=>Qe(e=>!e),"aria-pressed":t,disabled:e,title:e?j(`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:j(`printers.drying.rotateTray`)})})()]}),(0,K.jsx)(`div`,{className:`shrink-0 h-px bg-bambu-dark-tertiary`}),(0,K.jsx)(`div`,{className:`shrink-0 px-3 pt-2.5 pb-3`,children:(0,K.jsx)(`button`,{onClick:()=>{if(Ve!==null){let e=($t.find(e=>e.id===Ve)?.tray??[]).some(e=>e.state===11);jn.mutate({amsId:Ve,temp:qe,duration:Ye,filament:Ge,rotateTray:Ze&&!e})}},disabled:jn.isPending,"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:jn.isPending?j(`printers.drying.startingDrying`):j(`printers.drying.start`)})})]})]})})()]})}function hAe({onClose:e,onAdd:t,existingSerials:n}){let{t:r}=W(),[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)(()=>{ld.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 Q.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 ld.startSubnetScan(e);let t=setInterval(async()=>{try{let e=await ld.getScanStatus();E({scanned:e.scanned,total:e.total}),l(await ld.getDiscoveredPrinters()),e.running||(clearInterval(t),s(!1),p(!0))}catch(e){console.error(`Failed to get scan status:`,e)}},500)}else{await ld.startDiscovery(10);let e=setInterval(async()=>{try{l(await ld.getDiscoveredPrinters())}catch(e){console.error(`Failed to get discovered printers:`,e)}},1e3);setTimeout(async()=>{clearInterval(e);try{await ld.stopDiscovery()}catch{}s(!1),p(!0);try{l(await ld.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:AW(e.model)}),l([])};return(0,y.useEffect)(()=>()=>{ld.stopDiscovery().catch(()=>{}),ld.stopSubnetScan().catch(()=>{})},[]),(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,K.jsxs)(K.Fragment,{children:[(0,K.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,K.jsx)(Ed,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(Od,{children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold mb-4`,children:r(`printers.addPrinter`)}),(0,K.jsxs)(`div`,{className:`mb-4 pb-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`mb-3`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.discovery.subnetToScan`)}),g.length>0?(0,K.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,K.jsx)(`option`,{value:e,children:e},e)),(0,K.jsx)(`option`,{value:`__custom__`,children:r(`printers.discovery.customSubnetOption`)})]}):(0,K.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,K.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,K.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:r(m?`printers.discovery.dockerNote`:`printers.discovery.customSubnetNote`)})]}),(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:F,disabled:o,className:`w-full`,children:o?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{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,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Wl,{className:`w-4 h-4`}),r(m||C?`printers.discovery.scanSubnet`:`printers.discovery.discoverNetwork`)]})}),u&&(0,K.jsx)(`div`,{className:`mt-2 text-sm text-red-700 dark:text-red-400`,children:u}),N.length>0&&(0,K.jsx)(`div`,{className:`mt-3 space-y-2 max-h-40 overflow-y-auto`,children:N.map(e=>(0,K.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,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`font-medium text-white text-sm truncate`,children:e.name||e.serial}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[AW(e.model)||r(`printers.discovery.unknown`),` • `,e.ip_address,e.serial.startsWith(`unknown-`)&&(0,K.jsxs)(`span`,{className:`text-yellow-500`,children:[` • `,r(`printers.discovery.serialRequired`)]})]})]}),(0,K.jsx)(ss,{className:`w-4 h-4 text-bambu-gray -rotate-90 flex-shrink-0 ml-2`})]},e.serial))}),o&&(0,K.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,K.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,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray text-center`,children:r(`printers.discovery.allConfigured`)})]}),(0,K.jsxs)(`form`,{onSubmit:P,className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.name`)}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.ipAddress`)}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.serialNumber`)}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.accessCode`)}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.modal.modelOptional`)}),(0,K.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,K.jsx)(`option`,{value:``,children:r(`printers.modal.selectModel`)}),(0,K.jsxs)(`optgroup`,{label:`A1 Series`,children:[(0,K.jsx)(`option`,{value:`A1`,children:`A1`}),(0,K.jsx)(`option`,{value:`A1 Mini`,children:`A1 Mini`})]}),(0,K.jsx)(`optgroup`,{label:`A2 Series`,children:(0,K.jsx)(`option`,{value:`A2L`,children:`A2L`})}),(0,K.jsxs)(`optgroup`,{label:`H2 Series`,children:[(0,K.jsx)(`option`,{value:`H2C`,children:`H2C`}),(0,K.jsx)(`option`,{value:`H2D`,children:`H2D`}),(0,K.jsx)(`option`,{value:`H2D Pro`,children:`H2D Pro`}),(0,K.jsx)(`option`,{value:`H2S`,children:`H2S`})]}),(0,K.jsxs)(`optgroup`,{label:`P Series`,children:[(0,K.jsx)(`option`,{value:`P1P`,children:`P1P`}),(0,K.jsx)(`option`,{value:`P1S`,children:`P1S`}),(0,K.jsx)(`option`,{value:`P2S`,children:`P2S`})]}),(0,K.jsxs)(`optgroup`,{label:`X1 Series`,children:[(0,K.jsx)(`option`,{value:`X1`,children:`X1`}),(0,K.jsx)(`option`,{value:`X1C`,children:`X1 Carbon`}),(0,K.jsx)(`option`,{value:`X1E`,children:`X1E`})]}),(0,K.jsx)(`optgroup`,{label:`X2 Series`,children:(0,K.jsx)(`option`,{value:`X2D`,children:`X2D`})})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.modal.locationGroup`)}),(0,K.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,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`printers.locationHelp`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.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,K.jsx)(`label`,{htmlFor:`auto_archive`,className:`text-sm text-bambu-gray`,children:r(`printers.modal.autoArchiveLabel`)})]}),(0,K.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,K.jsx)(mu,{className:`w-4 h-4`}),r(`diagnostic.runButton`)]}),j?(0,K.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,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(ku,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-amber-600 dark:text-amber-400`}),(0,K.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-300`,children:r(`printers.addPreflight.warning`)})]}),(0,K.jsx)(gp,{result:j}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:()=>M(null),className:`flex-1`,children:r(`printers.addPreflight.back`)}),(0,K.jsx)($,{type:`button`,onClick:()=>t(i),className:`flex-1`,children:r(`printers.addPreflight.saveAnyway`)})]})]}):(0,K.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:e,className:`flex-1`,children:r(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:k,className:`flex-1`,children:r(k?`printers.addPreflight.checking`:`printers.addPrinter`)})]})]})]})})}),D&&(0,K.jsx)(vp,{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 gAe({printer:e,firmwareInfo:t,onClose:n}){let{t:r}=W(),i=oo(),{showToast:a}=Pd(),{hasPermission:o}=bd(),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:_}=q({queryKey:[`firmwarePrepare`,e.id,m],queryFn:()=>pd.prepareUpload(e.id,m??void 0),staleTime:3e4,enabled:!!m&&s&&!u}),v=J({mutationFn:()=>pd.startUpload(e.id,m??void 0),onSuccess:()=>{d(!0);let t=setInterval(async()=>{try{let n=await pd.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,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,K.jsx)(Ed,{className:`w-full max-w-md mx-4`,children:(0,K.jsxs)(Od,{children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,K.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,K.jsx)(Ws,{className:`w-5 h-5 text-orange-600 dark:text-orange-400`}):(0,K.jsx)(hs,{className:`w-5 h-5 text-status-ok`})}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:t.update_available?r(`printers.firmwareModal.title`):r(`printers.firmwareModal.titleUpToDate`)}),(0,K.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,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3 mb-4`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between items-center text-sm`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:r(`printers.firmwareModal.currentVersion`)}),(0,K.jsx)(`span`,{className:`font-mono ${a?`text-white`:`text-status-ok`}`,children:t.current_version||r(`common.unknown`)})]}),a&&(0,K.jsxs)(`div`,{className:`flex justify-between items-center text-sm mt-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:r(`printers.firmwareModal.latestVersion`)}),(0,K.jsx)(`span`,{className:`text-orange-700 dark:text-orange-400 font-mono`,children:n})]}),i&&(0,K.jsxs)(`details`,{className:`mt-3 text-sm`,open:!a,children:[(0,K.jsx)(`summary`,{className:`cursor-pointer hover:underline ${a?`text-orange-700 dark:text-orange-400`:`text-status-ok`}`,children:r(`printers.firmwareModal.releaseNotes`)}),(0,K.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,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mb-2`,children:r(`printers.firmwareModal.availableVersions`)}),(0,K.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?oee(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,K.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,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsx)(`span`,{className:`font-mono text-white`,children:e.version}),(0,K.jsx)(`span`,{className:`text-xs ${c}`,children:o})]}),(0,K.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,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm mb-4`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),r(`printers.firmwareModal.checkingPrereqs`)]}):g&&!u&&!c?(0,K.jsx)(`div`,{className:`mb-4`,children:g.can_proceed?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-green text-sm`,children:[(0,K.jsx)(qo,{className:`w-4 h-4`}),r(`printers.firmwareModal.sdCardReady`)]}):(0,K.jsx)(`div`,{className:`space-y-1`,children:g.errors.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400 text-sm`,children:[(0,K.jsx)(ps,{className:`w-4 h-4 flex-shrink-0`}),e]},t))})}):null:null,(u||c)&&c&&(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-sm mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray capitalize`,children:c.status}),(0,K.jsxs)(`span`,{className:`text-white`,children:[c.progress,`%`]})]}),(0,K.jsx)(`div`,{className:`w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,K.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,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c.message}),c.error&&(0,K.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:c.error})]}),c?.status===`complete`&&(0,K.jsxs)(`div`,{className:`bg-bambu-green/10 border border-bambu-green/30 rounded-lg p-3 mb-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-green font-medium mb-2`,children:r(`printers.firmwareModal.uploadedSuccess`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`printers.firmwareModal.applyInstructions`)}),(0,K.jsxs)(`ol`,{className:`text-xs text-bambu-gray mt-1 list-decimal list-inside space-y-1`,children:[(0,K.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step1`)}}),(0,K.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step2`)}}),(0,K.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step3`)}}),(0,K.jsx)(`li`,{children:r(`printers.firmwareModal.step4`)})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:n,children:c?.status===`complete`?r(`printers.firmwareModal.done`):r(`common.cancel`)}),g?.can_proceed&&!u&&c?.status!==`complete`&&s&&(0,K.jsx)($,{onClick:()=>{l(null),v.mutate()},disabled:v.isPending,children:v.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-2`}),r(`printers.firmwareModal.starting`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Ws,{className:`w-4 h-4 mr-2`}),r(`printers.firmwareModal.uploadFirmware`)]})})]})]})})})}function _Ae({printer:e,onClose:t}){let{t:n}=W(),r=oo(),{showToast:i}=Pd(),[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=J({mutationFn:t=>Q.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,K.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,K.jsx)(Ed,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(Od,{children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold mb-4`,children:n(`printers.editPrinter`)}),(0,K.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault(),c(!0);try{let t=await Q.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.name`)}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.ipAddress`)}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.serialNumber`)}),(0,K.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,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`printers.serialCannotBeChanged`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.accessCode`)}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.model`)}),(0,K.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,K.jsx)(`option`,{value:``,children:n(`printers.modal.selectModel`)}),(0,K.jsxs)(`optgroup`,{label:`A1 Series`,children:[(0,K.jsx)(`option`,{value:`A1`,children:`A1`}),(0,K.jsx)(`option`,{value:`A1 Mini`,children:`A1 Mini`})]}),(0,K.jsx)(`optgroup`,{label:`A2 Series`,children:(0,K.jsx)(`option`,{value:`A2L`,children:`A2L`})}),(0,K.jsxs)(`optgroup`,{label:`H2 Series`,children:[(0,K.jsx)(`option`,{value:`H2C`,children:`H2C`}),(0,K.jsx)(`option`,{value:`H2D`,children:`H2D`}),(0,K.jsx)(`option`,{value:`H2D Pro`,children:`H2D Pro`}),(0,K.jsx)(`option`,{value:`H2S`,children:`H2S`})]}),(0,K.jsxs)(`optgroup`,{label:`P Series`,children:[(0,K.jsx)(`option`,{value:`P1P`,children:`P1P`}),(0,K.jsx)(`option`,{value:`P1S`,children:`P1S`}),(0,K.jsx)(`option`,{value:`P2S`,children:`P2S`})]}),(0,K.jsxs)(`optgroup`,{label:`X1 Series`,children:[(0,K.jsx)(`option`,{value:`X1`,children:`X1`}),(0,K.jsx)(`option`,{value:`X1C`,children:`X1 Carbon`}),(0,K.jsx)(`option`,{value:`X1E`,children:`X1E`})]}),(0,K.jsx)(`optgroup`,{label:`X2 Series`,children:(0,K.jsx)(`option`,{value:`X2D`,children:`X2D`})})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Location / Group`}),(0,K.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,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`printers.locationHelp`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.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,K.jsx)(`label`,{htmlFor:`edit_auto_archive`,className:`text-sm text-bambu-gray`,children:n(`printers.modal.autoArchiveLabel`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.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,K.jsxs)(`label`,{htmlFor:`edit_maintenance_mode`,className:`text-sm text-bambu-gray flex items-center gap-1.5`,children:[(0,K.jsx)(Ku,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400`}),n(`printers.maintenance.editFieldLabel`)]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1 ml-6`,children:n(`printers.maintenance.editFieldHelp`)})]}),l?(0,K.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,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(ku,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-amber-600 dark:text-amber-400`}),(0,K.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-300`,children:n(`printers.addPreflight.warning`)})]}),(0,K.jsx)(gp,{result:l}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:()=>u(null),className:`flex-1`,children:n(`printers.addPreflight.back`)}),(0,K.jsx)($,{type:`button`,onClick:f,className:`flex-1`,disabled:d.isPending,children:n(`printers.addPreflight.saveAnyway`)})]})]}):(0,K.jsxs)(`div`,{className:`flex gap-3 pt-4`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`common.cancel`)}),(0,K.jsx)($,{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 vAe(e){let{data:t}=q({queryKey:[`printerStatus`,e],queryFn:()=>Q.getPrinterStatus(e),refetchInterval:3e4});return!t?.connected}function yAe({printer:e,plug:t,onPowerOn:n,isPowering:r}){let i=vAe(e.id),{data:a}=q({queryKey:[`smartPlugStatus`,t.id],queryFn:()=>Q.getSmartPlugStatus(t.id),refetchInterval:1e4});return i?(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 hover:bg-gray-100 dark:hover:bg-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white truncate`,children:e.name}),a&&(0,K.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,K.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,K.jsx)(Al,{className:`w-3 h-3`}),r?`...`:`On`]})]}):null}function bAe(){let{t:e}=W(),{resolvedMode:t,darkAccent:n,lightAccent:r}=Cd(),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)(`all`),[R,z]=(0,y.useState)(`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=oo(),{showToast:re}=Pd(),{hasPermission:ie}=bd(),[H,ae]=(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(H.values());e.length>0?localStorage.setItem(`openEmbeddedCameras`,JSON.stringify(e)):localStorage.removeItem(`openEmbeddedCameras`)},[H]);let{data:oe,isLoading:U}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:se}=q({queryKey:[`ui-preferences`],queryFn:Q.getUiPreferences}),ce=(0,y.useMemo)(()=>Kp(se?.nozzle_temp_presets,Hp,0,320),[se?.nozzle_temp_presets]),le=(0,y.useMemo)(()=>Kp(se?.bed_temp_presets,Up,0,140),[se?.bed_temp_presets]),ue=(0,y.useMemo)(()=>Kp(se?.chamber_temp_presets,Wp,0,60),[se?.chamber_temp_presets]),de=(0,y.useMemo)(()=>Kp(se?.fan_speed_presets,Gp,0,100),[se?.fan_speed_presets]),fe=(0,y.useMemo)(()=>{if(se?.drying_presets)try{let e=JSON.parse(se.drying_presets);if(typeof e==`object`&&e&&Object.keys(e).length>0)return{...MW,...e}}catch{}return MW},[se?.drying_presets]);(0,y.useEffect)(()=>{se?.camera_view_mode===`window`&&H.size>0&&ae(new Map)},[se?.camera_view_mode,H.size]);let{data:pe}=q({queryKey:[`smart-plugs`],queryFn:Q.getSmartPlugs}),{data:me}=q({queryKey:[`maintenanceOverview`],queryFn:Q.getMaintenanceOverview,staleTime:60*1e3}),{data:he}=q({queryKey:[`spoolman-status`],queryFn:Q.getSpoolmanStatus,staleTime:60*1e3}),ge=he?.enabled&&he?.connected,{data:_e}=q({queryKey:[`spoolman-settings`],queryFn:Q.getSpoolmanSettings,enabled:!!ge,staleTime:60*1e3}),ve=_e?.spoolman_sync_mode,{data:ye}=q({queryKey:[`unlinked-spools`],queryFn:Q.getUnlinkedSpools,enabled:!!ge,staleTime:30*1e3}),be=ye&&ye.length>0,{data:xe}=q({queryKey:[`linked-spools`],queryFn:Q.getLinkedSpools,enabled:!!ge,staleTime:30*1e3}),Se=xe?.linked,{data:Ce}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),enabled:ie(`inventory:view_assignments`),staleTime:30*1e3}),we=J({mutationFn:({printerId:e,amsId:t,trayId:n})=>Q.unassignSpool(e,t,n),onSuccess:()=>{ne.invalidateQueries({queryKey:[`spool-assignments`]})}}),{data:Te,isLoading:Ee}=q({queryKey:[`spoolman-inventory-spools`],queryFn:()=>Q.getSpoolmanInventorySpools(!1),enabled:!!ge,staleTime:30*1e3}),{data:De,isLoading:Oe}=q({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Q.getSpoolmanSlotAssignments(),enabled:!!ge,staleTime:30*1e3}),ke=J({mutationFn:e=>Q.unassignSpoolmanSlot(e),onSuccess:()=>{ne.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),ne.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})}}),Ae=(e,t,n)=>Ce?.find(r=>r.printer_id===e&&r.ams_id===Number(t)&&r.tray_id===Number(n)),je=me?.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),{})||{},Me=pe?.reduce((e,t)=>(t.printer_id&&(e[t.printer_id]=t),e),{})||{},Ne=J({mutationFn:Q.createPrinter,onSuccess:()=>{ne.invalidateQueries({queryKey:[`printers`]}),ne.invalidateQueries({queryKey:[`maintenanceOverview`]}),o(!1)},onError:t=>{if(t instanceof Qu&&t.code===`printer_connection_failed`){re(e(`printers.toast.connectionFailedNotAdded`),`error`);return}re(t.message||e(`printers.toast.failedToAdd`),`error`)}}),Pe=J({mutationFn:e=>Q.controlSmartPlug(e,`on`),onSuccess:()=>{ne.invalidateQueries({queryKey:[`smart-plugs`]}),f(null)},onError:()=>{f(null)}}),[Fe,Ie]=(0,y.useState)(new Set),[Le,Re]=(0,y.useState)(!1),[ze,Be]=(0,y.useState)(null),[Ve,He]=(0,y.useState)(!1),Ue=Le||Fe.size>0,We=(0,y.useCallback)(e=>{Ie(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Ge=(0,y.useCallback)(()=>{Ie(new Set),Re(!1)},[]);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&Ue&&Ge()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Ue,Ge]);let Ke=(0,y.useCallback)(async t=>{He(!0);let n=Array.from(Fe).filter(e=>{let n=ne.getQueryData([`printerStatus`,e]);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`clearPlate`:return!!n.awaiting_plate_clear;case`clearHMS`:return n.hms_errors&&Xp(n.hms_errors).length>0;default:return!1}});if(n.length===0){re(e(`printers.bulk.noneApplicable`),`error`),He(!1),Be(null);return}let r={stop:Q.stopPrint,pause:Q.pausePrint,resume:Q.resumePrint,clearPlate:Q.clearPlate,clearHMS:Q.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]})}),He(!1),Be(null)},[Fe,ne,re,e]),qe=(0,y.useCallback)(e=>{e===`stop`||e===`pause`||e===`clearPlate`?Be(e):Ke(e)},[Ke]),Je=()=>{let e=!s;c(e),localStorage.setItem(`hideDisconnectedPrinters`,String(e))},Ye=e=>{m(e),localStorage.setItem(`printerSortBy`,e)},Xe=()=>{let e=!h;g(e),localStorage.setItem(`printerSortAsc`,String(e))},Ze=()=>{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`}},Qe=[`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 $e=(0,y.useMemo)(()=>{if(!oe)return[];let e=oe;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?Xp(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},[oe,P,I,R,ne,B]),et=(0,y.useMemo)(()=>oe?[...new Set(oe.map(e=>e.location||``).filter(Boolean))].sort():[],[oe]),tt=(0,y.useMemo)(()=>{let e=[...$e];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?Xp(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},[$e,p,h,ne]),nt=(0,y.useCallback)(()=>{Ie(new Set(tt.map(e=>e.id))),Re(!0)},[tt]),rt=(0,y.useCallback)(e=>{Ie(t=>{let n=new Set(t);return tt.forEach(t=>{kW(ne.getQueryData([`printerStatus`,t.id]))===e&&n.add(t.id)}),n}),Re(!0)},[tt,ne]),it=(0,y.useCallback)(e=>{Ie(t=>{let n=new Set(t);return tt.filter(t=>(t.location||``)===e).forEach(e=>n.add(e.id)),n}),Re(!0)},[tt]),at=(0,y.useCallback)(e=>{Ie(t=>{let n=new Set(t);return tt.filter(t=>(t.model||`Unknown`)===e).forEach(e=>n.add(e.id)),n}),Re(!0)},[tt]),ot=(0,y.useCallback)(e=>{te(t=>{let n={...t,[e]:!t[e]};try{localStorage.setItem(`printerCollapsedSections`,JSON.stringify(n))}catch{}return n})},[]),st=(0,y.useMemo)(()=>{if(p===`name`||p===`eta`)return null;let e={};return p===`location`?tt.forEach(t=>{let n=t.location||`Ungrouped`;e[n]||(e[n]=[]),e[n].push(t)}):p===`model`?tt.forEach(t=>{let n=t.model||`Unknown`;e[n]||(e[n]=[]),e[n].push(t)}):p===`status`&&tt.forEach(t=>{let n=kW(ne.getQueryData([`printerStatus`,t.id]));e[n]||(e[n]=[]),e[n].push(t)}),e},[p,tt,ne,B]),ct=(0,y.useRef)(null),lt=(0,y.useRef)(null),ut=(0,y.useRef)(0),[dt,ft]=(0,y.useState)(!1),pt=(0,y.useCallback)(()=>{let e=ct.current;if(!e)return;let t=lt.current?.offsetWidth;t&&(ut.current=t);let n=ut.current>0&&e.clientWidthe===n?e:n)},[]),mt=Object.keys(Me).length;(0,y.useLayoutEffect)(()=>{pt();let e=ct.current;if(!e)return;if(typeof ResizeObserver>`u`)return window.addEventListener(`resize`,pt),()=>window.removeEventListener(`resize`,pt);let t=new ResizeObserver(()=>pt());return t.observe(e),window.addEventListener(`resize`,pt),()=>{t.disconnect(),window.removeEventListener(`resize`,pt)}},[pt,oe?.length,et.length,s,mt]);let ht=(t=!1)=>(0,K.jsxs)(K.Fragment,{children:[oe&&oe.length>0&&(0,K.jsx)(wW,{value:I,onChange:L,fullWidth:t,options:[{value:`all`,label:e(`printers.filter.allStatuses`)},{value:`printing`,label:e(`printers.status.printing`)},{value:`paused`,label:e(`printers.status.paused`)},{value:`idle`,label:e(`printers.status.idle`)},{value:`finished`,label:e(`printers.status.finished`)},{value:`error`,label:e(`printers.status.error`)},{value:`offline`,label:e(`printers.status.offline`)}]}),oe&&oe.length>0&&et.length>0&&(0,K.jsx)(wW,{value:R,onChange:z,fullWidth:t,options:[{value:`all`,label:e(`printers.filter.allLocations`)},...et.map(e=>({value:e,label:e}))]}),(0,K.jsx)(`button`,{type:`button`,onClick:Je,"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`)})]}),gt=(t=!1)=>(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1 ${t?`w-full`:``}`,children:[(0,K.jsx)(wW,{value:p,onChange:Ye,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,K.jsx)(`button`,{onClick:Xe,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,K.jsx)(zo,{className:`w-4 h-4 text-white`}):(0,K.jsx)(No,{className:`w-4 h-4 text-white`})})]}),(0,K.jsxs)(`div`,{className:`flex h-8 items-center bg-bambu-dark rounded-lg border border-bambu-dark-tertiary ${t?`w-full`:``}`,children:[(0,K.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,K.jsx)(Hc,{className:`w-3.5 h-3.5`}),t&&(0,K.jsx)(`span`,{children:e(`printers.pageView.cards`)})]}),(0,K.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,K.jsx)(ll,{className:`w-3.5 h-3.5`}),t&&(0,K.jsx)(`span`,{children:e(`printers.pageView.camWall`)})]})]}),b===`camwall`&&ie(`camera:view`)&&(0,K.jsxs)(Oi,{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,K.jsx)(Zs,{className:`w-3.5 h-3.5`}),t&&(0,K.jsx)(`span`,{children:e(`printers.pageView.openCamWallPage`)})]}),(0,K.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:Qe.map((n,r)=>{let i=r+1,a=_===i;return(0,K.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===Qe.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)})})]}),_t=(t=!1)=>(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`button`,{onClick:()=>{Ue?Ge():Re(!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`:``} ${Ue?`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,K.jsx)(uu,{className:`w-4 h-4`}),t&&(0,K.jsx)(`span`,{children:e(`printers.bulk.select`)})]}),s&&Object.keys(Me).length>0&&(0,K.jsxs)(`div`,{className:`relative ${t?`w-full`:``}`,children:[(0,K.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,K.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(Al,{className:`w-4 h-4`}),e(`printers.powerOn`)]}),(0,K.jsx)(ss,{className:`w-3 h-3 transition-transform ${l?`rotate-180`:``}`})]}),l&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>u(!1)}),(0,K.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,K.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`)}),oe?.filter(e=>Me[e.id]).map(e=>(0,K.jsx)(yAe,{printer:e,plug:Me[e.id],onPowerOn:e=>{f(e),Pe.mutate(e)},isPowering:d===Me[e.id]?.id},e.id)),oe?.filter(e=>Me[e.id]).length===0&&(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:`No printers with smart plugs`})]})]})]}),(0,K.jsxs)($,{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,K.jsx)(Ol,{className:`w-4 h-4`}),e(`printers.addPrinter`)]})]});return(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsxs)(`div`,{className:`space-y-3 mb-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(jl,{className:`w-7 h-7 text-bambu-green`}),e(`printers.title`)]}),(0,K.jsx)(uAe,{printers:oe})]}),(0,K.jsxs)(`div`,{ref:ct,className:`relative flex items-center gap-2`,children:[oe&&oe.length>0&&(0,K.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,K.jsx)(Wl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50`}),(0,K.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,K.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,K.jsx)(qu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{ref:lt,"aria-hidden":dt,inert:dt,className:`${dt?`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,K.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:ht()}),(0,K.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:gt()}),(0,K.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:_t()})]}),dt&&(0,K.jsxs)(`div`,{className:`ml-auto flex items-center justify-end gap-1`,children:[(0,K.jsx)(TW,{label:e(`printers.toolbar.filters`,`Filters`),icon:(0,K.jsx)(_c,{className:`w-4 h-4`}),children:(0,K.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:ht(!0)})}),(0,K.jsx)(TW,{label:e(`printers.toolbar.view`,`View`),icon:(0,K.jsx)(iu,{className:`w-4 h-4`}),children:(0,K.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:gt(!0)})}),(0,K.jsx)(TW,{label:e(`printers.toolbar.actions`,`Actions`),icon:(0,K.jsx)(Js,{className:`w-4 h-4`}),children:(0,K.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:_t(!0)})})]})]})]}),U?(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`common.loading`)}):oe?.length===0?(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`text-center py-12`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`printers.noPrintersConfigured`)}),(0,K.jsxs)($,{onClick:()=>o(!0),disabled:!ie(`printers:create`),title:ie(`printers:create`)?void 0:e(`printers.permission.noAdd`),children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),e(`printers.addPrinter`)]})]})}):tt.length===0&&(P.trim()||I!==`all`||R!==`all`)?(0,K.jsx)(Ed,{children:(0,K.jsx)(Od,{className:`text-center py-12`,children:(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`printers.noSearchResults`)})})}):b===`camwall`?(0,K.jsx)(CT,{printers:tt,maxLive:S,snapshotIntervalSec:w,onTileClick:(e,t)=>{if((se?.camera_view_mode||`window`)===`embedded`)ae(n=>new Map(n).set(e,{id:e,name:t}));else{let t=localStorage.getItem(`cameraWindowState`),n=t?JSON.parse(t):{width:640,height:400},r=[`width=${n.width}`,`height=${n.height}`,n.left===void 0?``:`left=${n.left}`,n.top===void 0?``:`top=${n.top}`,`menubar=no,toolbar=no,location=no,status=no`].filter(Boolean).join(`,`);window.open(`/camera/${e}`,`camera-${e}`,r)}},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)}}):st?(0,K.jsx)(`div`,{className:`space-y-6`,children:(()=>{let e=p===`status`?fAe.filter(e=>st[e]?.length>0):Object.keys(st);return h?e:[...e].reverse()})().map(t=>{let n=st[t],r=`${p}:${t}`,i=!ee[r],a=p===`status`&&OW[t]?.dot||`bg-bambu-green`,o=p===`status`?e(OW[t]?.labelKey||t):t;return(0,K.jsx)(Cp,{open:i,onToggle:()=>ot(r),summaryClassName:`py-1`,summary:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full ${a}`}),o,(0,K.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n.length,`)`]}),Ue&&(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),p===`location`?it(t===`Ungrouped`?``:t):p===`status`?rt(t):p===`model`&&at(t)},className:`text-xs text-bambu-green hover:text-bambu-green-light transition-colors ml-1`,children:e(`printers.bulk.selectAll`)})]}),children:(0,K.jsx)(`div`,{className:`grid gap-4 ${_>=3?`gap-6`:``} ${Ze()}`,children:n.map(e=>(0,K.jsx)(NW,{printer:e,hideIfDisconnected:s,maintenanceInfo:je[e.id],viewMode:O,cardSize:_,amsThresholds:se?{humidityGood:Number(se.ams_humidity_good)||40,humidityFair:Number(se.ams_humidity_fair)||60,tempGood:Number(se.ams_temp_good)||28,tempFair:Number(se.ams_temp_fair)||35}:void 0,spoolmanEnabled:ge,hasUnlinkedSpools:be,linkedSpools:Se,spoolmanUrl:he?.url,spoolmanSyncMode:ve,onGetAssignment:Ae,onUnassignSpool:(e,t,n)=>we.mutate({printerId:e,amsId:t,trayId:n}),spoolmanSpools:Te,spoolmanSlotAssignments:De,spoolmanLoading:Ee||Oe,onUnassignSpoolmanSpool:e=>ke.mutate(e),timeFormat:se?.time_format||`system`,cameraViewMode:se?.camera_view_mode||`window`,onOpenEmbeddedCamera:(e,t)=>ae(n=>new Map(n).set(e,{id:e,name:t})),checkPrinterFirmware:se?.check_printer_firmware!==!1,dryingPresets:fe,nozzleTempPresets:ce,bedTempPresets:le,chamberTempPresets:ue,fanSpeedPresets:de,requirePlateClear:se?.require_plate_clear===!0,selectionMode:Ue,isSelected:Fe.has(e.id),onToggleSelect:We,onOpenCompactCard:M},e.id))})},t)})}):(0,K.jsx)(`div`,{className:`grid gap-4 ${_>=3?`gap-6`:``} ${Ze()}`,children:tt.map(e=>(0,K.jsx)(NW,{printer:e,hideIfDisconnected:s,maintenanceInfo:je[e.id],viewMode:O,cardSize:_,spoolmanEnabled:ge,hasUnlinkedSpools:be,linkedSpools:Se,spoolmanUrl:he?.url,spoolmanSyncMode:ve,onGetAssignment:Ae,onUnassignSpool:(e,t,n)=>we.mutate({printerId:e,amsId:t,trayId:n}),spoolmanSpools:Te,spoolmanSlotAssignments:De,spoolmanLoading:Ee||Oe,onUnassignSpoolmanSpool:e=>ke.mutate(e),amsThresholds:se?{humidityGood:Number(se.ams_humidity_good)||40,humidityFair:Number(se.ams_humidity_fair)||60,tempGood:Number(se.ams_temp_good)||28,tempFair:Number(se.ams_temp_fair)||35}:void 0,timeFormat:se?.time_format||`system`,cameraViewMode:se?.camera_view_mode||`window`,onOpenEmbeddedCamera:(e,t)=>ae(n=>new Map(n).set(e,{id:e,name:t})),checkPrinterFirmware:se?.check_printer_firmware!==!1,dryingPresets:fe,nozzleTempPresets:ce,bedTempPresets:le,chamberTempPresets:ue,fanSpeedPresets:de,requirePlateClear:se?.require_plate_clear===!0,selectionMode:Ue,isSelected:Fe.has(e.id),onToggleSelect:We,onOpenCompactCard:M},e.id))}),_===2&&k!=null&&(0,K.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,K.jsx)(Po,{className:`w-4 h-4`}),e(`common.back`,`Back`)]}),a&&(0,K.jsx)(hAe,{onClose:()=>o(!1),onAdd:e=>Ne.mutate(e),existingSerials:oe?.map(e=>e.serial_number)||[]}),Ue&&oe&&(0,K.jsx)(mee,{selectedIds:Fe,printers:oe,onClose:Ge,onSelectAll:nt,onSelectByLocation:it,onSelectByState:rt,onAction:qe,actionPending:Ve}),ze===`stop`&&(0,K.jsx)(Vd,{title:e(`printers.bulk.confirm.stopTitle`,{count:Fe.size}),message:e(`printers.bulk.confirm.stopMessage`,{count:Fe.size}),confirmText:e(`printers.bulk.confirm.stopButton`),variant:`danger`,isLoading:Ve,onConfirm:()=>Ke(`stop`),onCancel:()=>Be(null)}),ze===`pause`&&(0,K.jsx)(Vd,{title:e(`printers.bulk.confirm.pauseTitle`,{count:Fe.size}),message:e(`printers.bulk.confirm.pauseMessage`,{count:Fe.size}),confirmText:e(`printers.bulk.confirm.pauseButton`),isLoading:Ve,onConfirm:()=>Ke(`pause`),onCancel:()=>Be(null)}),ze===`clearPlate`&&(0,K.jsx)(Vd,{title:e(`printers.bulk.confirm.clearPlateTitle`,{count:Fe.size}),message:e(`printers.bulk.confirm.clearPlateMessage`,{count:Fe.size}),confirmText:e(`printers.bulk.confirm.clearPlateButton`),isLoading:Ve,onConfirm:()=>Ke(`clearPlate`),onCancel:()=>Be(null)}),Array.from(H.values()).map((e,t)=>(0,K.jsx)(Dle,{printerId:e.id,printerName:e.name,viewerIndex:t,onClose:()=>ae(t=>{let n=new Map(t);return n.delete(e.id),n})},e.id))]})}function xAe({title:e,message:t,subtitle:n,closeText:r,variant:i=`error`,onClose:a}){let{t:o}=W(),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,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-[120]`,onClick:a,children:(0,K.jsx)(Ed,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(Od,{className:`p-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,K.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,K.jsx)(ku,{className:`w-6 h-6`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-1`,children:e}),n&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2 truncate`,children:n}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm whitespace-pre-line break-words`,children:t})]})]}),(0,K.jsx)(`div`,{className:`flex mt-6`,children:(0,K.jsx)($,{onClick:a,className:`flex-1`,children:s})})]})})})}var PW=(0,y.createContext)(null),SAe=1500,CAe=1e3,FW=e=>`slice-job-${e}`;function IW(e){try{return decodeURIComponent(e)}catch{return e}}function wAe(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 TAe({children:e}){let{t}=W(),{showToast:n,showPersistentToast:r,dismissToast:i}=Pd(),a=oo(),[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.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=wAe(i),s=p.current.get(e.id)??null,c=s&&s.stage&&s.total_percent>0;if(a===`running`&&c){let n=IW(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(FW(e.id),c,`loading`);return}let l=a===`pending`?`slice.queuedToast`:`slice.runningToast`,u=a===`pending`?`Queued: {{name}} — {{elapsed}}`:`Slicing {{name}} — {{elapsed}}`;r(FW(e.id),t(l,u,{name:IW(e.sourceName),elapsed:o}),`loading`)},[r,t]),h=(0,y.useCallback)((e,t,n)=>{s(r=>r.some(t=>t.id===e)?r:[...r,{id:e,kind:t,sourceName:n}]),d.current.set(e,Date.now()),f.current.set(e,`pending`),p.current.set(e,null),m({id:e,kind:t,sourceName:n})},[m]),g=(0,y.useCallback)((e,r)=>{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(FW(e.id)),r.status===`completed`?n(t(`slice.completedToast`,`Sliced {{name}}`,{name:IW(e.sourceName)}),`success`):r.status===`failed`&&l({name:IW(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=setInterval(async()=>{if(e)return;let t=[...u.current];for(let e of t)try{let t=await Q.getSliceJob(e.id);f.current.set(e.id,t.status),t.progress&&p.current.set(e.id,t.progress),(t.status===`completed`||t.status===`failed`)&&g(e,t)}catch{}},SAe);return()=>{e=!0,clearInterval(t)}},[o.length,g]),(0,y.useEffect)(()=>{if(o.length===0)return;let e=setInterval(()=>{for(let e of u.current)m(e)},CAe);return()=>clearInterval(e)},[o.length,m]),(0,K.jsxs)(PW.Provider,{value:{trackJob:h,activeJobs:o},children:[e,c&&(0,K.jsx)(xAe,{title:t(`slice.failedTitle`),subtitle:c.name,message:c.detail,onClose:()=>l(null)})]})}function LW(){let e=(0,y.useContext)(PW);if(!e)throw Error(`useSliceJobTracker must be used inside SliceJobTrackerProvider`);return e}function RW({plates:e,onSelect:t,onClose:n}){let{t:r}=W();return(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,onClick:n,children:(0,K.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,K.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,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`h3`,{className:`text-white font-medium`,children:r(`archives.platePicker.title`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`archives.platePicker.hint`)})]}),(0,K.jsx)(`button`,{onClick:n,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors`,"aria-label":r(`common.close`,`Close`),children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:(0,K.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:e.map(e=>(0,K.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,K.jsx)(`img`,{src:ad(e.thumbnail_url),alt:`Plate ${e.index}`,className:`w-12 h-12 rounded object-cover bg-bambu-dark-tertiary flex-shrink-0`}):(0,K.jsx)(`div`,{className:`w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center flex-shrink-0`,children:(0,K.jsx)(Vc,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.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,K.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?``:` • ${If(e.print_time_seconds)}`]})]})]},e.index))})})]})})}var zW=[`local`,`orca_cloud`,`cloud`,`standard`],EAe={local:1.75,orca_cloud:1.5,cloud:1,standard:.5};function BW(e,t){for(let n of zW){let r=e[n][t];if(r.length>0)return{source:r[0].source,id:r[0].id}}return null}function VW(e,t,n){return t?e[t.source][n].find(e=>e.id===t.id)??null:null}function HW(e,t,n){if(!n)return null;for(let r of zW){let i=e[r][t].find(e=>e.name===n);if(i)return{source:i.source,id:i.id}}return null}function DAe(e,t,n,r){let i=HW(e,`process`,r);if(i){let r=VW(e,i,`process`);if(r&&CU(r,`process`,t,n)!==`mismatch`)return i}for(let r of[`match`,`unknown`])for(let i of zW)for(let a of e[i].process)if(CU(a,`process`,t,n)===r)return{source:a.source,id:a.id};return BW(e,`process`)}function OAe(e,t,n,r){let i=t.type.trim().toUpperCase(),a=Hf(t.color),o=null,s=null;for(let c of zW)for(let l of e[c].filament){let e=0,u=(l.filament_type??``).trim().toUpperCase(),d=Hf(l.filament_colour??``);i&&u&&i===u&&(e+=10),a&&d&&(d===a?e+=5:Jf(l.filament_colour??``,t.color)&&(e+=2)),e+=EAe[c];let f={source:l.source,id:l.id};CU(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?BW(e,`filament`):s.ref:o.ref}function kAe(e){return e?`${e.source}:${e.id}`:``}function AAe(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 jAe({requestId:e,sourceName:t}){let{t:n}=W(),{showPersistentToast:r,dismissToast:i}=Pd(),[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 Q.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=MAe(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,K.jsxs)(`div`,{className:`flex flex-col gap-1 text-bambu-gray text-sm py-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),p,(0,K.jsxs)(`span`,{className:`text-xs tabular-nums`,children:[a,`s`]})]}),a>=5&&(0,K.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 MAe(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 UW({source:e,onClose:t}){let{t:n}=W(),{trackJob:r}=LW(),i=oo(),[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=q({queryKey:[`slicer-pipelines`],queryFn:()=>Q.listSlicerPipelines(),staleTime:6e4}),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)(``),{showToast:D}=Pd(),O=J({mutationFn:e=>Q.createSlicerPipeline(e),onSuccess:()=>{i.invalidateQueries({queryKey:[`slicer-pipelines`]}),D(n(`slice.pipelines.toast.saved`,`Pipeline saved`),`success`),w(!1),E(``)},onError:e=>{D(e.message||n(`slice.pipelines.toast.saveFailed`,`Save failed`),`error`)}}),k=q({queryKey:[`slicePlates`,e.kind,e.id],queryFn:async()=>e.kind===`libraryFile`?Q.getLibraryFilePlates(e.id):Q.getArchivePlates(e.id),staleTime:6e4}),A=!!k.data?.is_multi_plate&&(k.data?.plates?.length??0)>1,j=A&&p==null,M=p??1,N=(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${M}-${t}`},[e.kind,e.id,M]),P=q({queryKey:[`sliceFilamentReqs`,e.kind,e.id,M],queryFn:async()=>e.kind===`libraryFile`?Q.getLibraryFileFilamentRequirements(e.id,M,N):Q.getArchiveFilamentRequirements(e.id,M,N),enabled:!j,staleTime:6e4}),F=(0,y.useMemo)(()=>{let e=P.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,P.data]),I=q({queryKey:[`slicerPresets`],queryFn:()=>Q.getSlicerPresets(),staleTime:6e4,enabled:!k.isLoading&&!j}),[L,R]=(0,y.useState)(!1),z=async()=>{if(!L){R(!0);try{let e=await Q.getSlicerPresets({refresh:!0});i.setQueryData([`slicerPresets`],e)}catch{i.invalidateQueries({queryKey:[`slicerPresets`]})}finally{R(!1)}}},B=q({queryKey:[`slicerPrinterModels`],queryFn:Q.getSlicerPrinterModels,staleTime:1/0}),V=(0,y.useMemo)(()=>!I.data||!a?null:VW(I.data,a,`printer`)?.name??null,[I.data,a]),ee=(0,y.useMemo)(()=>vU(B.data??{}),[B.data]),te=k.data?.embedded_printer??null,ne=k.data?.embedded_process??null,re=(0,y.useMemo)(()=>{if(!te||!ne||!V)return!1;let e=e=>e.replace(/^#\s*/,``).trim().toLowerCase();return e(V)===e(te)},[te,ne,V]);(0,y.useEffect)(()=>{re||x(!1)},[re]),(0,y.useEffect)(()=>{let e=I.data;e&&(a??o(HW(e,`printer`,te)??BW(e,`printer`)))},[I.data,te]),(0,y.useEffect)(()=>{let e=I.data;e&&c(t=>{if(t){let n=VW(e,t,`process`);if(n&&CU(n,`process`,V,ee)!==`mismatch`)return t}return DAe(e,V,ee,ne)})},[I.data,V,ee,ne]),(0,y.useEffect)(()=>{let e=I.data;e&&u(t=>F.map((n,r)=>{let i=t[r]??null;if(i){let t=VW(e,i,`filament`);if(t&&CU(t,`filament`,V,ee)!==`mismatch`)return i}return OAe(e,{type:n.type,color:n.color},V,ee)}))},[I.data,F,V,ee]);let ie=J({mutationFn:async t=>{let n=H(t);return e.kind===`libraryFile`?Q.sliceLibraryFile(e.id,n):Q.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 H(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&&re?{use_embedded_settings:!0}:{}}}let ae=a!=null&&s!=null&&P.isSuccess&&l.length>0&&l.every(e=>e!=null),oe=ie.isPending,U=k.data?.plates?.length??0,se=A&&U>1&&!j;return j&&k.data?(0,K.jsx)(RW,{plates:k.data.plates,onSelect:e=>m(e),onClose:t}):(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,onClick:()=>{oe||t()},children:(0,K.jsxs)(`div`,{className:`w-full max-w-xl max-h-[85vh] flex flex-col rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary/60`,onClick:e=>e.stopPropagation(),children:[(0,K.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,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsxs)(`h3`,{className:`text-white font-medium flex items-center gap-2`,children:[(0,K.jsx)(Ms,{className:`w-4 h-4`}),n(`slice.title`)]}),(0,K.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,K.jsx)(`button`,{onClick:t,disabled:oe,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors disabled:opacity-50`,"aria-label":n(`common.close`),children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[(k.isLoading||I.isLoading)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),n(`slice.loadingPresets`)]}),I.isError&&(0,K.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.`)}),I.data&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,K.jsx)(WW,{status:I.data.cloud_status,cloudName:`bambu`}),(0,K.jsx)(WW,{status:I.data.orca_cloud_status,cloudName:`orca`})]}),(0,K.jsxs)(`button`,{type:`button`,onClick:z,disabled:L||oe,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,K.jsx)(Pl,{className:`w-3.5 h-3.5 ${L?`animate-spin`:``}`}),n(`slice.refreshPresets`)]})]}),(0,K.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,K.jsxs)(`span`,{className:`text-xs font-medium text-bambu-gray flex items-center gap-1`,children:[(0,K.jsx)(Ms,{className:`w-3.5 h-3.5`}),` `,n(`slice.pipelines.label`,`Pipeline`)]}),(0,K.jsxs)(`select`,{value:``,disabled:oe||(S.data?.pipelines.length??0)===0,onChange:e=>{let t=parseInt(e.target.value,10);if(Number.isNaN(t))return;let r=S.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,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),C?(0,K.jsxs)(`div`,{className:`flex items-center gap-1 flex-1 min-w-[16ch]`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:T,onChange:e=>E(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,K.jsx)(`button`,{type:`button`,onClick:()=>{let e=T.trim();if(!e||!a||!s)return;let t=l.filter(e=>e!==null);t.length!==0&&O.mutate({name:e,printer_preset:a,process_preset:s,filament_presets:t,bed_type:_})},disabled:O.isPending||!T.trim(),className:`text-xs px-2 py-1 bg-bambu-green hover:bg-bambu-green/80 text-white rounded disabled:opacity-50`,children:O.isPending?(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`}):n(`common.save`,`Save`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>{w(!1),E(``)},className:`text-xs px-2 py-1 text-bambu-gray hover:text-white`,children:n(`common.cancel`,`Cancel`)})]}):(0,K.jsx)(`button`,{type:`button`,onClick:()=>{E(``),w(!0)},disabled:oe||!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,K.jsx)(GW,{label:n(`slice.printer`),slot:`printer`,data:I.data,value:a,onChange:o,disabled:oe||b}),re&&(0,K.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-bambu-gray cursor-pointer select-none`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:b,onChange:e=>x(e.target.checked),disabled:oe,className:`mt-0.5 cursor-pointer`}),(0,K.jsxs)(`span`,{children:[n(`slice.useEmbedded`),(0,K.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:n(`slice.useEmbeddedHint`)})]})]}),(0,K.jsx)(GW,{label:n(`slice.process`),slot:`process`,data:I.data,value:s,onChange:c,disabled:oe||b,selectedPrinterName:V,compatIndex:ee}),(0,K.jsx)(PAe,{value:_,onChange:v,disabled:oe||b}),P.isLoading?(0,K.jsx)(jAe,{requestId:N,sourceName:e.filename}):F.map((e,t)=>{let r=e.used_in_plate!==!1,i=F.length>1?n(`slice.filamentSlot`,{index:t+1,type:e.type}):n(`slice.filament`);return(0,K.jsx)(GW,{label:r?i:`${i} ${n(`slice.notUsedByPlate`)}`,slot:`filament`,data:I.data,value:l[t]??null,onChange:e=>u(n=>{let r=n.length===F.length?[...n]:F.map((e,t)=>n[t]??null);return r[t]=e,r}),disabled:oe||!r||b,swatchColor:F.length>1?e.color:void 0,selectedPrinterName:V,compatIndex:ee},`filament-${t}`)})]}),d&&(0,K.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,K.jsxs)(`div`,{className:`flex-shrink-0 flex justify-end gap-2 px-4 py-3 border-t border-bambu-dark-tertiary/40`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:t,disabled:oe,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`)}),se&&(0,K.jsxs)(`label`,{className:`flex items-center gap-2 mr-auto text-sm text-bambu-gray cursor-pointer select-none`,title:n(`slice.actionAllTitle`,{count:U}),children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),disabled:oe,className:`cursor-pointer`}),n(`slice.allPlatesToggle`,{count:U})]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>{f(null);let e=h?0:p;ie.mutate(e)},disabled:!ae||oe,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:oe?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),n(`slice.enqueuing`)]}):h?n(`slice.actionAll`,{count:U}):n(`slice.action`)})]})]})})}function WW({status:e,cloudName:t=`bambu`}){let{t:n}=W();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:Ts},unreachable:{tone:`border-bambu-dark-tertiary/40 bg-bambu-dark text-bambu-gray`,icon:Ts}}[e],{key:o,fallback:s}=r[e];return(0,K.jsxs)(`div`,{className:`flex items-start gap-2 text-xs rounded-md border p-2 ${i}`,role:`status`,children:[(0,K.jsx)(a,{className:`w-4 h-4 flex-shrink-0 mt-0.5`}),(0,K.jsx)(`span`,{children:n(o,s)})]})}var NAe=[{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 PAe({value:e,onChange:t,disabled:n}){let{t:r}=W();return(0,K.jsxs)(`label`,{className:`block`,children:[(0,K.jsx)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:r(`slice.bedType.label`)}),(0,K.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,K.jsx)(`option`,{value:``,children:r(`slice.bedType.auto`)}),NAe.map(e=>(0,K.jsx)(`option`,{value:e.value,children:r(e.labelKey,e.fallback)},e.value))]})]})}function GW({label:e,slot:t,data:n,value:r,onChange:i,disabled:a,swatchColor:o,selectedPrinterName:s,compatIndex:c}){let{t:l}=W(),{sections:u,otherEntries:d}=(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)CU(n,t,s??null,c??Ske)===`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]),f=u.reduce((e,t)=>e+t.entries.length,0)+d.length;return(0,K.jsxs)(`label`,{className:`block`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-2 text-xs text-bambu-gray mb-1`,children:[o&&(0,K.jsx)(`span`,{className:`inline-block w-3 h-3 rounded-full border border-bambu-dark-tertiary`,style:{backgroundColor:o||`transparent`},"aria-hidden":!0}),(0,K.jsx)(`span`,{children:e})]}),(0,K.jsxs)(`select`,{value:kAe(r),onChange:e=>i(AAe(e.target.value)),disabled:a||f===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,K.jsx)(`option`,{value:``,children:l(f===0?`slice.noPresetsForSlot`:`slice.selectPreset`)}),u.map(e=>(0,K.jsx)(`optgroup`,{label:e.tierLabel,children:e.entries.map(e=>(0,K.jsx)(`option`,{value:`${e.source}:${e.id}`,children:e.name},`${e.source}:${e.id}`))},e.tierLabel)),d.length>0&&(0,K.jsx)(`optgroup`,{label:l(`slice.otherPrinters`),children:d.map(e=>(0,K.jsx)(`option`,{value:`${e.source}:${e.id}`,children:e.name},`${e.source}:${e.id}`))})]})]})}function KW({source:e,onClose:t}){let{t:n}=W(),r=oo(),{showToast:i}=Pd(),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(1),{trackJob:d}=LW(),{data:f,isLoading:p}=q({queryKey:[`slicer-pipelines`],queryFn:()=>Q.listSlicerPipelines()}),{data:m}=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters()}),{data:h}=q({queryKey:[`app-settings`],queryFn:()=>Q.getSettings()}),g=h?.pipeline_max_copies??50,_={kind:e.kind,id:e.id},v=J({mutationFn:e=>Q.checkPipelineEligibility(e,_)}),b=J({mutationFn:({pipelineId:e,force:t})=>Q.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,K.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,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h3`,{className:`text-sm font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(El,{className:`w-4 h-4 text-bambu-green`}),a&&s?n(`library.runWithPipeline.confirmTitle`,`Confirm run`):n(`library.runWithPipeline.modalTitle`,`Run with pipeline`)]}),(0,K.jsx)(`button`,{type:`button`,onClick:t,"aria-label":n(`common.close`,`Close`),className:`text-bambu-gray hover:text-white`,children:(0,K.jsx)(qu,{className:`w-4 h-4`})})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-3`,children:a&&s?(0,K.jsx)(IAe,{pipeline:a,report:s,source:e,onBack:()=>{o(null),c(null)},onConfirm:()=>{a&&b.mutate({pipelineId:a.id,force:!0})},running:b.isPending}):(0,K.jsx)(FAe,{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 FAe({source:e,pipelines:t,printerById:n,loading:r,onPick:i,copies:a,maxCopies:o,onCopiesChange:s}){let{t:c}=W();return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[c(`library.runWithPipeline.sourceHint`,`Source`),`:`,` `,(0,K.jsx)(`span`,{className:`text-white`,children:e.filename})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`label`,{className:`text-xs text-bambu-gray`,htmlFor:`run-pipeline-copies`,children:[c(`library.runWithPipeline.copies`,`Copies`),`:`]}),(0,K.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,K.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:c(`library.runWithPipeline.copiesHint`,`max {{n}}`,{n:o})})]}),r&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),c(`library.runWithPipeline.loading`,`Loading…`)]}),!r&&t.length===0&&(0,K.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,K.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,K.jsx)(`li`,{children:(0,K.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,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Ms,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,K.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,K.jsx)(jl,{className:`w-3 h-3`}),a?(0,K.jsx)(`span`,{children:a}):r?(0,K.jsx)(`span`,{children:r}):(0,K.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:c(`library.runWithPipeline.noTarget`,`No target printer set`)})]})]})},e.id)})})]})}function IAe({pipeline:e,report:t,source:n,onBack:r,onConfirm:i,running:a}){let{t:o}=W();return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[(0,K.jsxs)(`p`,{children:[o(`library.runWithPipeline.confirmIntro`,`Pre-flight found issues with this run`),`:`]}),(0,K.jsxs)(`p`,{className:`mt-1`,children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[o(`library.runWithPipeline.sourceHint`,`Source`),`: `]}),(0,K.jsx)(`span`,{className:`text-white`,children:n.filename})]}),(0,K.jsxs)(`p`,{children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[o(`library.runWithPipeline.pipelineHint`,`Pipeline`),`: `]}),(0,K.jsx)(`span`,{className:`text-white`,children:e.name})]}),t.target_printer_name&&(0,K.jsxs)(`p`,{children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[o(`library.runWithPipeline.targetHint`,`Target`),`: `]}),(0,K.jsx)(`span`,{className:`text-white`,children:t.target_printer_name})]})]}),(0,K.jsx)(`ul`,{className:`space-y-1.5`,children:t.issues.map((e,t)=>(0,K.jsxs)(`li`,{className:`flex items-start gap-2 text-xs`,children:[(0,K.jsx)(ku,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:(0,K.jsx)(LAe,{issue:e})})]},t))}),(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.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,K.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,K.jsx)(X,{className:`w-3 h-3 animate-spin`}):(0,K.jsx)(El,{className:`w-3 h-3`}),o(`library.runWithPipeline.runAnyway`,`Run anyway`)]})]})]})}function LAe({issue:e}){let{t}=W();switch(e.kind){case`printer_not_set`:return(0,K.jsx)(K.Fragment,{children:t(`library.runWithPipeline.issue.printerNotSet`,`No target printer set on this pipeline.`)});case`printer_not_found`:return(0,K.jsx)(K.Fragment,{children:t(`library.runWithPipeline.issue.printerNotFound`,`Target printer no longer exists.`)});case`printer_disabled`:return(0,K.jsx)(K.Fragment,{children:t(`library.runWithPipeline.issue.printerDisabled`,`Target printer is disabled.`)});case`printer_offline`:return(0,K.jsx)(K.Fragment,{children:t(`library.runWithPipeline.issue.printerOffline`,`Target printer is offline.`)});case`filament_type_mismatch`:return(0,K.jsx)(K.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,K.jsx)(K.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,K.jsx)(K.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,K.jsx)(K.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,K.jsx)(K.Fragment,{children:e.kind})}}function RAe(){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 qW(e,t=`bambu_studio`){let n,r=encodeURIComponent(e);n=t===`orcaslicer`?`orcaslicer://open?file=${r}`:RAe()===`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)}var JW=768;function YW(){let[e,t]=(0,y.useState)(()=>typeof window<`u`?window.innerWidth{let e=window.matchMedia(`(max-width: ${JW-1}px)`),n=e=>{t(e.matches)};return t(e.matches),e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}function XW({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 zAe({onClose:e,initialFiles:t}){let{t:n}=W(),r=oo(),{showToast:i}=Pd(),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=J({mutationFn:e=>Q.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,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,K.jsx)(Ed,{className:`w-full max-w-2xl max-h-[90vh] flex flex-col`,children:(0,K.jsxs)(Od,{className:`p-0 flex flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:n(`uploadModal.title`)}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`p-4`,children:(0,K.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,K.jsx)(Nu,{className:`w-12 h-12 mx-auto mb-4 text-bambu-gray`}),(0,K.jsx)(`p`,{className:`text-white mb-2`,children:n(`uploadModal.dragDrop`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm mb-4`,children:n(`uploadModal.or`)}),(0,K.jsx)($,{variant:`secondary`,onClick:()=>a.current?.click(),disabled:x,children:n(`uploadModal.browseFiles`)}),(0,K.jsx)(`input`,{ref:a,type:`file`,accept:`.3mf`,multiple:!0,className:`hidden`,onChange:g})]})}),(0,K.jsx)(`div`,{className:`px-4 pb-4`,children:(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`uploadModal.extractionInfo`)})}),o.length>0&&(0,K.jsx)(`div`,{className:`px-4 pb-4 max-h-60 overflow-y-auto`,children:(0,K.jsx)(`div`,{className:`space-y-2`,children:o.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(oc,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`}),(0,K.jsx)(`span`,{className:`flex-1 text-white text-sm truncate`,children:e.file.name}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[(e.file.size/(1024*1024)).toFixed(1),` MB`]}),e.status===`pending`&&(0,K.jsx)(`button`,{onClick:()=>_(t),className:`text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,disabled:x,children:(0,K.jsx)(qu,{className:`w-4 h-4`})}),e.status===`uploading`&&(0,K.jsx)(X,{className:`w-4 h-4 text-bambu-green animate-spin`}),e.status===`success`&&(0,K.jsx)(hs,{className:`w-4 h-4 text-bambu-green`}),e.status===`error`&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-red-700 dark:text-red-400`,children:e.error}),(0,K.jsx)(ps,{className:`w-4 h-4 text-red-600 dark:text-red-400`})]})]},`${e.file.name}-${t}`))})}),u&&(0,K.jsx)(`div`,{className:`px-4 pb-4`,children:(0,K.jsx)(`div`,{className:`p-3 bg-bambu-dark rounded-lg`,children:(0,K.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,K.jsx)(`span`,{className:`text-bambu-green`,children:u.uploaded}),` `,n(`uploadModal.uploaded`),u.failed>0&&(0,K.jsxs)(K.Fragment,{children:[`, `,(0,K.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:u.failed}),` `,n(`uploadModal.failed`)]})]})})}),(0,K.jsxs)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:e,className:`flex-1`,children:n(u?`common.close`:`common.cancel`)}),!u&&(0,K.jsx)($,{onClick:v,disabled:b===0||x,className:`flex-1`,children:x?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),n(`uploadModal.uploading`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Nu,{className:`w-4 h-4`}),n(`uploadModal.upload`),` `,b>0&&`(${b})`]})})]})]})})})}var BAe=365;function VAe({onClose:e,initialDays:t}){let{t:n}=W(),r=oo(),{showToast:i}=Pd(),[a,o]=(0,y.useState)(t??BAe),[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=q({queryKey:[`archive-purge-preview`,l,s],queryFn:()=>Q.previewArchivePurge(l,s),enabled:l>=1}),f=J({mutationFn:()=>Q.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,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg shadow-xl max-w-lg w-full`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,K.jsx)(Eu,{className:`w-5 h-5`}),n(`archivePurge.title`)]}),(0,K.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,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:n(`archivePurge.description`)}),(0,K.jsxs)(`div`,{children:[(0,K.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,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.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,K.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:n(`archivePurge.days`)})]})]}),(0,K.jsxs)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/30 p-3`,children:[(0,K.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-gray-600 dark:text-gray-300 mb-2`,children:n(`archivePurge.effectsTitle`)}),(0,K.jsxs)(`ul`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1 list-disc pl-4`,children:[(0,K.jsx)(`li`,{children:n(`archivePurge.effect1`)}),(0,K.jsx)(`li`,{children:n(`archivePurge.effect2`)}),(0,K.jsx)(`li`,{children:n(`archivePurge.effect3`)}),(0,K.jsx)(`li`,{children:n(`archivePurge.effect4`)})]})]}),(0,K.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,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),` `,n(`archivePurge.previewLoading`)]}):d.isError?(0,K.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:d.error?.message??n(`archivePurge.previewFailed`)}):(0,K.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,K.jsx)(`div`,{className:`font-medium`,children:n(`archivePurge.previewSummary`,{count:m,size:Md(h)})}),p?.sample_filenames&&p.sample_filenames.length>0&&(0,K.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,K.jsx)(`li`,{className:`truncate`,children:e},e)),m>p.sample_filenames.length&&(0,K.jsx)(`li`,{className:`list-none italic text-gray-500`,children:n(`archivePurge.andMore`,{count:m-p.sample_filenames.length})})]})]})}),(0,K.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,K.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked),disabled:f.isPending,className:`mt-0.5 shrink-0`}),(0,K.jsxs)(`span`,{className:`text-xs text-gray-700 dark:text-gray-300`,children:[(0,K.jsx)(`span`,{className:`font-medium block mb-0.5`,children:n(`archivePurge.purgeStatsLabel`)}),(0,K.jsx)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:n(`archivePurge.purgeStatsHint`)})]})]}),(0,K.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,K.jsx)(ku,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,K.jsx)(`span`,{children:n(`archivePurge.warning`)})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:e,disabled:f.isPending,children:n(`common.cancel`)}),(0,K.jsx)($,{variant:`danger`,disabled:!g,onClick:()=>f.mutate(),children:f.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-1`}),n(`archivePurge.purging`)]}):n(`archivePurge.confirmCta`,{count:m})})]})]})})}function HAe(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 UAe(e){if(!e)return`—`;let t=jf(e);return t?t.toLocaleString():`—`}function ZW({archiveId:e}){let{t}=W(),{data:n,isLoading:r}=q({queryKey:[`archive-runs`,e],queryFn:()=>Q.getArchiveRuns(e)});if(r)return(0,K.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,K.jsx)(X,{className:`w-5 h-5 text-bambu-gray animate-spin`})});let i=n?.items||[];return i.length===0?(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:t(`archives.runLog.empty`)}):(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`th`,{className:`text-left py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.date`)}),(0,K.jsx)(`th`,{className:`text-left py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.status`)}),(0,K.jsx)(`th`,{className:`text-right py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.duration`)}),(0,K.jsx)(`th`,{className:`text-right py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.filament`)}),(0,K.jsx)(`th`,{className:`text-right py-1.5 font-medium`,children:t(`archives.runLog.col.cost`)})]})}),(0,K.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,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/40 last:border-0`,children:[(0,K.jsx)(`td`,{className:`py-1.5 pr-2 text-bambu-gray-light`,children:UAe(e.started_at||e.created_at)}),(0,K.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,K.jsx)(`span`,{className:`block text-[10px] text-bambu-gray font-normal`,children:t(`editArchive.failureReasons.${e.failure_reason}`,{defaultValue:e.failure_reason})})]}),(0,K.jsx)(`td`,{className:`py-1.5 pr-2 text-right text-bambu-gray-light`,children:HAe(e.duration_seconds)}),(0,K.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,K.jsx)(`td`,{className:`py-1.5 text-right text-bambu-gray-light`,children:e.cost==null?`—`:e.cost.toFixed(2)})]},e.id)})})]})})}var QW=[`adhesionFailure`,`spaghettiDetached`,`layerShift`,`cloggedNozzle`,`filamentRunout`,`warping`,`stringing`,`underExtrusion`,`powerFailure`,`userCancelled`,`other`],WAe=[`completed`,`failed`,`aborted`,`printing`];function $W({archive:e,onClose:t,existingTags:n=[]}){let{t:r}=W();(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let i=oo(),[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?QW.includes(t)?t:QW.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.photos||[]),[w,T]=(0,y.useState)(e.external_url||``),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),A=(0,y.useRef)(null),j=(0,y.useRef)(null),M=(0,y.useRef)(null),{data:N}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:P}=q({queryKey:[`projects`],queryFn:()=>Q.getProjects(),select:e=>[...e].sort((e,t)=>e.name.localeCompare(t.name))}),{data:F}=q({queryKey:[`tags`],queryFn:Q.getTags,enabled:n.length===0}),I=n.length>0?n:F?.map(e=>e.name)||[],L=p.split(`,`).map(e=>e.trim()).filter(Boolean),R=p.includes(`,`)?p.substring(p.lastIndexOf(`,`)+1).trim().toLowerCase():p.trim().toLowerCase(),z=I.filter(e=>!L.includes(e)&&(R===``||e.toLowerCase().includes(R))),B=e=>{let t;t=R&&!I.includes(R)?p.includes(`,`)?p.substring(0,p.lastIndexOf(`,`)).split(`,`).map(e=>e.trim()).filter(Boolean):[]:L,t.includes(e)||m([...t,e].join(`, `)),M.current!==null&&clearTimeout(M.current),A.current?.focus()},V=e=>{m(L.filter(t=>t!==e).join(`, `))},ee=J({mutationFn:t=>Q.updateArchive(e.id,t),onSuccess:()=>{i.invalidateQueries({queryKey:[`archives`]}),i.invalidateQueries({queryKey:[`projects`]}),t()}}),te=async t=>{let n=t.target.files?.[0];if(n){D(!0);try{C((await Q.uploadArchivePhoto(e.id,n)).photos),i.invalidateQueries({queryKey:[`archives`]})}catch(e){console.error(`Failed to upload photo:`,e)}finally{D(!1),j.current&&(j.current.value=``)}}},ne=async t=>{try{C((await Q.deleteArchivePhoto(e.id,t)).photos||[]),i.invalidateQueries({queryKey:[`archives`]})}catch(e){console.error(`Failed to delete photo:`,e)}};return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`editArchive.title`)}),(0,K.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.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:w||null};_!==e.status&&(n.status=_),_===`failed`||_===`aborted`?n.failure_reason=h||void 0:(e.status===`failed`||e.status===`aborted`)&&(n.failure_reason=null),ee.mutate(n)},className:`p-6 space-y-4 overflow-y-auto flex-1`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`archives.runLog.title`)}),(0,K.jsx)(ZW,{archiveId:e.id})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.name`)}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.printer`)}),(0,K.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,K.jsx)(`option`,{value:``,children:r(`editArchive.noPrinter`)}),N?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,K.jsx)(uc,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.project`)]}),(0,K.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,K.jsx)(`option`,{value:``,children:r(`editArchive.noProject`)}),P?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,K.jsx)(Oc,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.itemsPrinted`)]}),(0,K.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,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`editArchive.itemsPrintedHelp`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.notes`)}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,K.jsx)(Gc,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.externalLink`)]}),(0,K.jsx)(`input`,{type:`url`,value:w,onChange:e=>T(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,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`editArchive.externalLinkHelp`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.tags`)}),L.length>0&&(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:L.map(e=>(0,K.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,K.jsx)(vu,{className:`w-3 h-3`}),e,(0,K.jsx)(`button`,{type:`button`,onClick:()=>V(e),className:`ml-0.5 text-bambu-gray hover:text-white`,children:(0,K.jsx)(qu,{className:`w-3 h-3`})})]},e))}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`input`,{ref:A,type:`text`,value:p,onChange:e=>m(e.target.value),onFocus:()=>{M.current!==null&&clearTimeout(M.current),k(!0)},onBlur:()=>{M.current=window.setTimeout(()=>k(!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:L.length>0?r(`editArchive.addMoreTags`):r(`editArchive.tagsPlaceholder`)}),O&&z.length>0&&(0,K.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,K.jsxs)(`div`,{className:`p-2 text-xs text-bambu-gray border-b border-bambu-dark-tertiary`,children:[R?r(`editArchive.matchingTags`,{query:R}):r(`editArchive.existingTags`),` `,r(`editArchive.clickToAdd`)]}),(0,K.jsx)(`div`,{className:`p-2 flex flex-wrap gap-1.5`,children:z.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>B(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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.status`)}),(0,K.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:WAe.map(e=>(0,K.jsx)(`option`,{value:e,children:r(`editArchive.statuses.${e}`)},e))})]}),(_===`failed`||_===`aborted`)&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`failure-reason-select`,className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.failureReason`)}),(0,K.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,K.jsx)(`option`,{value:``,children:r(`editArchive.selectReason`)}),QW.map(e=>(0,K.jsx)(`option`,{value:e,children:r(`editArchive.failureReasons.${e}`)},e))]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,K.jsx)(es,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.photos`)]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-2`,children:[S.map(t=>(0,K.jsxs)(`div`,{className:`relative group`,children:[(0,K.jsx)(`img`,{src:Q.getArchivePhotoUrl(e.id,t),alt:r(`editArchive.printResult`),className:`w-20 h-20 object-cover rounded-lg border border-bambu-dark-tertiary`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>ne(t),className:`absolute -top-1 -right-1 p-1 bg-red-500 rounded-full opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,K.jsx)(Eu,{className:`w-3 h-3 text-white`})})]},t)),(0,K.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,K.jsx)(`input`,{ref:j,type:`file`,accept:`image/jpeg,image/png,image/webp`,onChange:te,className:`hidden`,disabled:E}),E?(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,K.jsx)(Ol,{className:`w-6 h-6 text-bambu-gray`})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`editArchive.photosHelp`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:r(`common.cancel`)}),(0,K.jsxs)($,{type:`submit`,disabled:ee.isPending,className:`flex-1`,children:[(0,K.jsx)(zl,{className:`w-4 h-4`}),ee.isPending?r(`common.saving`):r(`common.save`)]})]})]})]})})}function eG({archiveId:e,archiveName:t,onClose:n}){let{t:r}=W();return(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsx)(Mc,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,title:t||``,children:r(`archives.runLog.modalTitle`,{name:t||r(`archives.runLog.modalTitleFallback`)})})]}),(0,K.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:r(`common.close`),children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`p-6 overflow-y-auto flex-1`,children:(0,K.jsx)(ZW,{archiveId:e})})]})})}function GAe({items:e,searchPlaceholder:t,onClose:n,className:r,onMouseEnter:i,onMouseLeave:a}){let[o,s]=(0,y.useState)(``),c=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(t){let e=window.setTimeout(()=>c.current?.focus(),0);return()=>window.clearTimeout(e)}},[t]);let l=o.trim().toLowerCase(),u=t&&l?e.filter(e=>e.label.toLowerCase().includes(l)):e;return(0,K.jsxs)(`div`,{className:r,onMouseEnter:i,onMouseLeave:a,children:[t&&(0,K.jsx)(`div`,{className:`sticky top-0 z-[1] px-2 py-1.5 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Wl,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-bambu-gray pointer-events-none`}),(0,K.jsx)(`input`,{ref:c,type:`text`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{if(e.key===`Enter`){let e=u.find(e=>!e.disabled);e&&(e.onClick(),n())}},placeholder:t,className:`w-full pl-7 pr-2 py-1 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})}),u.map((e,t)=>(0,K.jsxs)(`button`,{onClick:()=>{e.disabled||(e.onClick(),n())},disabled:e.disabled,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${e.disabled?`text-bambu-gray cursor-not-allowed`:e.danger?`text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-400/10`:`text-white hover:bg-bambu-dark-tertiary`}`,children:[e.icon&&(0,K.jsx)(`span`,{className:`w-4 h-4 flex-shrink-0 flex items-center justify-center`,children:e.icon}),(0,K.jsx)(`span`,{className:`flex-1 truncate`,children:e.label})]},t)),t&&u.length===0&&(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray text-center italic`,children:`—`})]})}function tG({x:e,y:t,items:n,onClose:r}){let i=(0,y.useRef)(null),[a,o]=(0,y.useState)(null),s=(0,y.useRef)(null),[c,l]=(0,y.useState)({x:e,y:t,visible:!1}),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)({});(0,y.useEffect)(()=>{let e=e=>{i.current&&!i.current.contains(e.target)&&r()},t=e=>{e.key===`Escape`&&r()},n=e=>{i.current&&i.current.contains(e.target)||r()};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),document.addEventListener(`scroll`,n,!0),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t),document.removeEventListener(`scroll`,n,!0),s.current&&clearTimeout(s.current)}},[r]),(0,y.useLayoutEffect)(()=>{if(i.current){i.current.style.visibility=`hidden`,i.current.style.display=`block`;let n=i.current.getBoundingClientRect(),r=window.innerWidth,a=window.innerHeight,o=e,s=t;e+n.width>r-8&&(o=Math.max(8,r-n.width-8)),o<8&&(o=8),t+n.height>a-8&&(s=Math.max(8,a-n.height-8)),s<8&&(s=8),d(r-o-n.width<180&&o>180),l({x:o,y:s,visible:!0})}},[e,t]);let m=(e,t)=>{s.current&&=(clearTimeout(s.current),null);let n=t.getBoundingClientRect(),r=window.innerHeight-n.top-8<300&&n.top>300;p(t=>({...t,[e]:r?`bottom`:`top`})),o(e)},h=()=>{s.current=window.setTimeout(()=>{o(null)},150)};return(0,K.jsx)(`div`,{ref:i,className:`fixed z-50 min-w-[180px] max-w-[280px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1`,style:{left:c.x,top:c.y,visibility:c.visible?`visible`:`hidden`},children:n.map((e,t)=>{if(e.divider)return(0,K.jsx)(`div`,{className:`my-1 border-t border-bambu-dark-tertiary`},t);let n=e.submenu&&e.submenu.length>0;return(0,K.jsxs)(`div`,{className:`relative`,onMouseEnter:e=>n&&m(t,e.currentTarget),onMouseLeave:()=>n&&h(),children:[(0,K.jsxs)(`button`,{onMouseEnter:e=>n&&m(t,e.currentTarget.parentElement),onClick:()=>{n?o(a===t?null:t):e.disabled||(e.onClick(),r())},disabled:e.disabled,title:e.title,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${e.disabled?`text-bambu-gray cursor-not-allowed`:e.danger?`text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-400/10`:`text-white hover:bg-bambu-dark-tertiary`} ${n&&a===t?`bg-bambu-dark-tertiary`:``}`,children:[e.icon&&(0,K.jsx)(`span`,{className:`w-4 h-4 flex-shrink-0 flex items-center justify-center`,children:e.icon}),(0,K.jsx)(`span`,{className:`flex-1`,children:e.label}),n&&(0,K.jsx)(cs,{className:`w-4 h-4 text-bambu-gray`})]}),n&&a===t&&(0,K.jsx)(GAe,{items:e.submenu,searchPlaceholder:e.submenuSearchPlaceholder,onClose:r,className:`absolute min-w-[200px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 overflow-hidden max-h-[300px] overflow-y-auto z-[60] ${u?`right-full mr-1`:`left-full ml-1`} ${f[t]===`bottom`?`bottom-0`:`top-0`}`,onMouseEnter:()=>{s.current&&=(clearTimeout(s.current),null)},onMouseLeave:()=>h()})]},t)})})}function KAe({selectedIds:e,existingTags:t,onClose:n}){let r=oo(),{showToast:i}=Pd(),[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=J({mutationFn:async()=>{let t=Array.from(s),n=0;for(let r of e)try{let e=await Q.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 Q.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,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,K.jsx)(Ed,{className:`w-full max-w-md`,children:(0,K.jsxs)(Od,{className:`p-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(vu,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:l===`add`?`Add Tags`:`Remove Tags`})]}),(0,K.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[l===`add`?`Add`:`Remove`,` tags for `,e.length,` selected archive`,e.length===1?``:`s`]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{size:`sm`,variant:l===`add`?`primary`:`secondary`,onClick:()=>u(`add`),children:`Add Tags`}),(0,K.jsx)($,{size:`sm`,variant:l===`remove`?`primary`:`secondary`,onClick:()=>u(`remove`),children:`Remove Tags`})]}),l===`add`&&(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.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,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:p,disabled:!a.trim(),children:(0,K.jsx)(Ol,{className:`w-4 h-4`})})]}),t.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:`Existing tags:`}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t.map(e=>(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:[`Tags to `,l===`add`?`add`:`remove`,`:`]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Array.from(s).map(e=>(0,K.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,K.jsx)(`button`,{onClick:()=>f(e),className:`hover:opacity-70`,children:(0,K.jsx)(qu,{className:`w-3 h-3`})})]},e))})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:n,className:`flex-1`,children:`Cancel`}),(0,K.jsx)($,{onClick:()=>d.mutate(),disabled:s.size===0||d.isPending,className:`flex-1`,children:d.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),`Processing...`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(vu,{className:`w-4 h-4`}),l===`add`?`Add Tags`:`Remove Tags`]})})]})]})})})}function qAe({selectedIds:e,onClose:t}){let{t:n}=W(),r=oo(),{showToast:i}=Pd(),[a,o]=(0,y.useState)(``),{data:s,isLoading:c}=q({queryKey:[`projects`],queryFn:()=>Q.getProjects()}),l=(0,y.useMemo)(()=>s?[...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=()=>{r.invalidateQueries({queryKey:[`archives`]}),r.invalidateQueries({queryKey:[`projects`]}),r.invalidateQueries({queryKey:[`project`]}),r.invalidateQueries({queryKey:[`project-archives`]})},m=J({mutationFn:async t=>(await Q.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=J({mutationFn:async()=>{for(let t of e)await Q.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,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,K.jsx)(Ed,{className:`w-full max-w-md max-h-[80vh] flex flex-col`,children:(0,K.jsxs)(Od,{className:`p-0 flex flex-col min-h-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(uc,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:`Assign to Project`})]}),(0,K.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,disabled:g,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-3 overflow-y-auto min-h-0`,children:[(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`Assign `,e.length,` selected archive`,e.length===1?``:`s`,` to a project`]}),c?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-gray`})}):(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.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,K.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-red-500/20 flex items-center justify-center shrink-0`,children:(0,K.jsx)(xs,{className:`w-4 h-4 text-red-600 dark:text-red-400`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:`Remove from project`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray truncate`,children:`Clear project assignment`})]}),h.isPending&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin text-bambu-gray shrink-0`})]}),l&&l.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 py-2`,children:[(0,K.jsx)(`div`,{className:`flex-1 h-px bg-bambu-dark-tertiary`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`or assign to`}),(0,K.jsx)(`div`,{className:`flex-1 h-px bg-bambu-dark-tertiary`})]}),f&&(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Wl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,K.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,K.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,K.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,K.jsx)(uc,{className:`w-4 h-4`,style:{color:e.color||`rgb(var(--bambu-green))`}})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.name}),(0,K.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,K.jsx)(X,{className:`w-4 h-4 animate-spin text-bambu-gray shrink-0`})]},e.id)),(!l||l.length===0)&&(0,K.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,K.jsx)(`p`,{className:`text-center text-bambu-gray text-sm py-4`,children:`—`})]})]}),(0,K.jsx)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary shrink-0`,children:(0,K.jsx)($,{variant:`secondary`,onClick:t,className:`flex-1`,disabled:g,children:`Cancel`})})]})})})}function JAe(e,t){return new Date(e,t+1,0).getDate()}function YAe(e,t){return new Date(e,t,1).getDay()}var XAe=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],ZAe=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function QAe({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=jf(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=JAe(o,i),m=YAe(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,K.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-6`,children:[(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsx)(`button`,{onClick:h,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,K.jsx)(ls,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[XAe[i],` `,o]}),(0,K.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,K.jsx)(`button`,{onClick:g,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,K.jsx)(cs,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-7 gap-1 mb-1`,children:ZAe.map(e=>(0,K.jsx)(`div`,{className:`text-center text-xs text-bambu-gray py-2`,children:e},e))}),(0,K.jsx)(`div`,{className:`grid grid-cols-7 gap-1`,children:v.map((e,t)=>{if(e===null)return(0,K.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,K.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,K.jsx)(`span`,{className:`text-sm font-medium ${l&&!u?`text-bambu-green`:``}`,children:e}),s&&(0,K.jsxs)(`div`,{className:`absolute bottom-1 left-1/2 -translate-x-1/2 flex items-center gap-1`,children:[(0,K.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,K.jsx)(`span`,{className:`text-xs font-medium`,children:a.length})]})]},e)})}),(0,K.jsx)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-4 text-center`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-2xl font-bold text-white`,children:e.filter(e=>{let t=jf(e.completed_at||e.created_at)||new Date;return t.getMonth()===i&&t.getFullYear()===o}).length}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Prints this month`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-2xl font-bold text-green-700 dark:text-green-400`,children:e.filter(e=>{let t=jf(e.completed_at||e.created_at)||new Date;return t.getMonth()===i&&t.getFullYear()===o&&e.status===`completed`}).length}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Successful`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-2xl font-bold text-red-700 dark:text-red-400`,children:e.filter(e=>{let t=jf(e.completed_at||e.created_at)||new Date;return t.getMonth()===i&&t.getFullYear()===o&&e.status===`failed`}).length}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Failed`})]})]})})]}),(0,K.jsx)(`div`,{className:`lg:w-80 bg-bambu-dark rounded-xl p-4`,children:c?(0,K.jsxs)(K.Fragment,{children:[(0,K.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,K.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,K.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,K.jsx)(`img`,{src:Q.getArchiveThumbnail(e.id),alt:``,className:`w-12 h-12 rounded object-cover`}):(0,K.jsx)(`div`,{className:`w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`3MF`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.print_name||e.filename}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,K.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,K.jsx)(`div`,{className:`flex gap-0.5`,children:e.filament_color.split(`,`).map((e,t)=>(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:e}},t))})]})]})]},e.id)})}):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:`No prints on this day`})]}):(0,K.jsx)(`div`,{className:`text-center py-8`,children:(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:`Select a day to see prints`})})})]})}function nG({archiveId:e,archiveName:t,onClose:n}){let r=Q.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,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:`QR Code`}),(0,K.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-6 flex flex-col items-center`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 text-center truncate max-w-full`,children:t}),(0,K.jsx)(`div`,{className:`bg-white p-4 rounded-lg mb-4`,children:(0,K.jsx)(`img`,{src:r,alt:`QR Code`,className:`w-64 h-64`})}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4 text-center`,children:`Scan to open this archive`}),(0,K.jsxs)($,{onClick:()=>{let e=document.createElement(`a`);e.href=r,e.download=`${t}_qrcode.png`,e.click()},className:`w-full`,children:[(0,K.jsx)(Ws,{className:`w-4 h-4`}),`Download QR Code`]})]})]})})}function rG({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=Q.getArchivePhotoUrl(e,l);return(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:r,children:[(0,K.jsxs)(`div`,{className:`relative w-full h-full flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 bg-black/50`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`Photo `,a+1,` of `,n.length]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>{let e=document.createElement(`a`);e.href=u,e.download=`${t}_photo_${a+1}.jpg`,e.click()},children:[(0,K.jsx)(Ws,{className:`w-4 h-4`}),`Download`]}),i&&(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>{i&&c(!0)},className:`text-red-400 hover:text-red-300`,children:(0,K.jsx)(Eu,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:r,className:`p-2 text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(qu,{className:`w-6 h-6`})})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-h-0 flex items-center justify-center p-4 relative overflow-hidden`,children:[a>0&&(0,K.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,K.jsx)(ls,{className:`w-8 h-8 text-white`})}),(0,K.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,K.jsx)(cs,{className:`w-8 h-8 text-white`})})]}),n.length>1&&(0,K.jsx)(`div`,{className:`flex justify-center gap-2 p-4 bg-black/50`,children:n.map((t,n)=>(0,K.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,K.jsx)(`img`,{src:Q.getArchivePhotoUrl(e,t),alt:`Thumbnail ${n+1}`,className:`w-full h-full object-cover`})},t))})]}),s&&(0,K.jsx)(Vd,{title:`Delete Photo`,message:`Delete this photo? This cannot be undone.`,confirmText:`Delete`,variant:`danger`,onConfirm:()=>{i?.(l),c(!1)},onCancel:()=>c(!1)})]})}function iG(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n`u`?null:OG(BigInt.prototype.toString),CG=typeof Symbol>`u`?null:OG(Symbol.prototype.toString),wG=OG(Object.prototype.hasOwnProperty),TG=OG(Object.prototype.toString),EG=OG(RegExp.prototype.test),DG=fje(TypeError);function OG(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return dG(e,t,n)}}function fje(e){return function(){return fG(e,[...arguments])}}function kG(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:_G;if(oG&&oG(e,null),!gG(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(ije(t)||(t[r]=e),i=e)}e[i]=!0}return e}function pje(e){for(let t=0;t/g),bje=cG(/\${[\w\W]*/g),xje=cG(/^data-[\-\w.\u00B7-\uFFFF]+$/),Sje=cG(/^aria-[\-\w]+$/),VG=cG(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Cje=cG(/^(?:\w+script|data):/i),wje=cG(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Tje=cG(/^html$/i),Eje=cG(/^[a-z][.\w]*(-[.\w]+)+$/i),HG=cG(/<[/\w!]/g),UG=cG(/<[/\w]/g),Dje=cG(/<\/no(script|embed|frames)/i),Oje=cG(/\/>/i),WG={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},kje=function(){return typeof window>`u`?null:window},Aje=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}},GG=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},KG=function(e,t,n,r){return wG(e,t)&&gG(e[t])?kG(r.base?AG(r.base):{},e[t],r.transform):n};function qG(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:kje(),t=e=>qG(e);if(t.version=`3.4.12`,t.removed=[],!e||!e.document||e.document.nodeType!==WG.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=jG(d,`cloneNode`),p=jG(d,`remove`),m=jG(d,`nextSibling`),h=jG(d,`childNodes`),g=jG(d,`parentNode`),_=jG(d,`shadowRoot`),v=jG(d,`attributes`),y=o&&o.prototype?jG(o.prototype,`nodeType`):null,b=o&&o.prototype?jG(o.prototype,`nodeName`):null;if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let x,S=``,C,w=!1,T=0,E=function(){if(T>0)throw DG(`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.`)},D=function(e){E(),T++;try{return x.createHTML(e)}finally{T--}},O=function(e){E(),T++;try{return x.createScriptURL(e)}finally{T--}},k=function(){return w||=(C=Aje(u,i),!0),C},A=n,j=A.implementation,M=A.createNodeIterator,N=A.createDocumentFragment,P=A.getElementsByTagName,F=r.importNode,I=GG();t.isSupported=typeof aG==`function`&&typeof g==`function`&&j&&j.createHTMLDocument!==void 0;let L=vje,R=yje,z=bje,B=xje,V=Sje,ee=Cje,te=wje,ne=Eje,re=VG,ie=null,H=kG({},[...MG,...NG,...PG,...FG,...IG]),ae=null,oe=kG({},[...LG,...RG,...zG,...BG]),U=Object.seal(lG(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}})),se=null,ce=null,le=Object.seal(lG(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),ue=!0,de=!0,fe=!1,pe=!0,me=!1,he=!0,ge=!1,_e=!1,ve=null,ye=null,be=!1,xe=!1,Se=!1,Ce=!1,we=!0,Te=!1,Ee=`user-content-`,De=!0,Oe=!1,ke={},Ae=null,je=kG({},`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(`.`)),Me=null,Ne=kG({},[`audio`,`video`,`img`,`source`,`image`,`track`]),Pe=null,Fe=kG({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),Ie=`http://www.w3.org/1998/Math/MathML`,Le=`http://www.w3.org/2000/svg`,Re=`http://www.w3.org/1999/xhtml`,ze=Re,Be=!1,Ve=null,He=kG({},[Ie,Le,Re],vG),Ue=sG([`mi`,`mo`,`mn`,`ms`,`mtext`]),We=kG({},Ue),Ge=sG([`annotation-xml`]),Ke=kG({},Ge),qe=kG({},[`title`,`style`,`font`,`a`,`script`]),Je=null,Ye=[`application/xhtml+xml`,`text/html`],Xe=null,Ze=null,Qe=n.createElement(`form`),$e=function(e){return e instanceof RegExp||e instanceof Function},W=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(Ze&&Ze===e)return;(!e||typeof e!=`object`)&&(e={}),e=AG(e),Je=Ye.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,Xe=Je===`application/xhtml+xml`?vG:_G,ie=KG(e,`ALLOWED_TAGS`,H,{transform:Xe}),ae=KG(e,`ALLOWED_ATTR`,oe,{transform:Xe}),Ve=KG(e,`ALLOWED_NAMESPACES`,He,{transform:vG}),Pe=KG(e,`ADD_URI_SAFE_ATTR`,Fe,{transform:Xe,base:Fe}),Me=KG(e,`ADD_DATA_URI_TAGS`,Ne,{transform:Xe,base:Ne}),Ae=KG(e,`FORBID_CONTENTS`,je,{transform:Xe}),se=KG(e,`FORBID_TAGS`,AG({}),{transform:Xe}),ce=KG(e,`FORBID_ATTR`,AG({}),{transform:Xe}),ke=wG(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?AG(e.USE_PROFILES):e.USE_PROFILES:!1,ue=e.ALLOW_ARIA_ATTR!==!1,de=e.ALLOW_DATA_ATTR!==!1,fe=e.ALLOW_UNKNOWN_PROTOCOLS||!1,pe=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,me=e.SAFE_FOR_TEMPLATES||!1,he=e.SAFE_FOR_XML!==!1,ge=e.WHOLE_DOCUMENT||!1,xe=e.RETURN_DOM||!1,Se=e.RETURN_DOM_FRAGMENT||!1,Ce=e.RETURN_TRUSTED_TYPE||!1,be=e.FORCE_BODY||!1,we=e.SANITIZE_DOM!==!1,Te=e.SANITIZE_NAMED_PROPS||!1,De=e.KEEP_CONTENT!==!1,Oe=e.IN_PLACE||!1,re=hje(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:VG,ze=typeof e.NAMESPACE==`string`?e.NAMESPACE:Re,We=wG(e,`MATHML_TEXT_INTEGRATION_POINTS`)&&e.MATHML_TEXT_INTEGRATION_POINTS&&typeof e.MATHML_TEXT_INTEGRATION_POINTS==`object`?AG(e.MATHML_TEXT_INTEGRATION_POINTS):kG({},Ue),Ke=wG(e,`HTML_INTEGRATION_POINTS`)&&e.HTML_INTEGRATION_POINTS&&typeof e.HTML_INTEGRATION_POINTS==`object`?AG(e.HTML_INTEGRATION_POINTS):kG({},Ge);let t=wG(e,`CUSTOM_ELEMENT_HANDLING`)&&e.CUSTOM_ELEMENT_HANDLING&&typeof e.CUSTOM_ELEMENT_HANDLING==`object`?AG(e.CUSTOM_ELEMENT_HANDLING):lG(null);if(U=lG(null),wG(t,`tagNameCheck`)&&$e(t.tagNameCheck)&&(U.tagNameCheck=t.tagNameCheck),wG(t,`attributeNameCheck`)&&$e(t.attributeNameCheck)&&(U.attributeNameCheck=t.attributeNameCheck),wG(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(U.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),cG(U),me&&(de=!1),Se&&(xe=!0),ke&&(ie=kG({},IG),ae=lG(null),ke.html===!0&&(kG(ie,MG),kG(ae,LG)),ke.svg===!0&&(kG(ie,NG),kG(ae,RG),kG(ae,BG)),ke.svgFilters===!0&&(kG(ie,PG),kG(ae,RG),kG(ae,BG)),ke.mathMl===!0&&(kG(ie,FG),kG(ae,zG),kG(ae,BG))),le.tagCheck=null,le.attributeCheck=null,wG(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?le.tagCheck=e.ADD_TAGS:gG(e.ADD_TAGS)&&(ie===H&&(ie=AG(ie)),kG(ie,e.ADD_TAGS,Xe))),wG(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?le.attributeCheck=e.ADD_ATTR:gG(e.ADD_ATTR)&&(ae===oe&&(ae=AG(ae)),kG(ae,e.ADD_ATTR,Xe))),wG(e,`ADD_URI_SAFE_ATTR`)&&gG(e.ADD_URI_SAFE_ATTR)&&kG(Pe,e.ADD_URI_SAFE_ATTR,Xe),wG(e,`FORBID_CONTENTS`)&&gG(e.FORBID_CONTENTS)&&(Ae===je&&(Ae=AG(Ae)),kG(Ae,e.FORBID_CONTENTS,Xe)),wG(e,`ADD_FORBID_CONTENTS`)&&gG(e.ADD_FORBID_CONTENTS)&&(Ae===je&&(Ae=AG(Ae)),kG(Ae,e.ADD_FORBID_CONTENTS,Xe)),De&&(ie[`#text`]=!0),ge&&kG(ie,[`html`,`head`,`body`]),ie.table&&(kG(ie,[`tbody`]),delete se.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw DG(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw DG(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=x;x=e.TRUSTED_TYPES_POLICY;try{S=D(``)}catch(e){throw x=t,e}}else e.TRUSTED_TYPES_POLICY===null?(x=void 0,S=``):(x===void 0&&(x=k()),x&&typeof S==`string`&&(S=D(``)));sG&&sG(e),Ze=e},et=kG({},[...NG,...PG,...gje]),tt=kG({},[...FG,..._je]),nt=function(e,t,n){return t.namespaceURI===Re?e===`svg`:t.namespaceURI===Ie?e===`svg`&&(n===`annotation-xml`||We[n]):!!et[e]},rt=function(e,t,n){return t.namespaceURI===Re?e===`math`:t.namespaceURI===Le?e===`math`&&Ke[n]:!!tt[e]},it=function(e,t,n){return t.namespaceURI===Le&&!Ke[n]||t.namespaceURI===Ie&&!We[n]?!1:!tt[e]&&(qe[e]||!et[e])},at=function(e){let t=g(e);(!t||!t.tagName)&&(t={namespaceURI:ze,tagName:`template`});let n=_G(e.tagName),r=_G(t.tagName);return Ve[e.namespaceURI]?e.namespaceURI===Le?nt(n,t,r):e.namespaceURI===Ie?rt(n,t,r):e.namespaceURI===Re?it(n,t,r):!!(Je===`application/xhtml+xml`&&Ve[e.namespaceURI]):!1},ot=function(e){hG(t.removed,{element:e});try{g(e).removeChild(e)}catch{if(p(e),!g(e))throw DG(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},st=function(e){ut(e);let t=h(e);if(t){let e=[];pG(t,t=>{hG(e,t)}),pG(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{}}},ct=function(e,n){try{hG(t.removed,{attribute:n.getAttributeNode(e),from:n})}catch{hG(t.removed,{attribute:null,from:n})}if(n.removeAttribute(e),e===`is`)if(xe||Se)try{ot(n)}catch{}else try{n.setAttribute(e,``)}catch{}},lt=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`||ae[Xe(i)]))try{e.removeAttribute(i)}catch{}}},ut=function(e){let t=[e];for(;t.length>0;){let e=t.pop();(y?y(e):e.nodeType)===WG.element&<(e);let n=h(e);if(n)for(let e=n.length-1;e>=0;--e)t.push(n[e])}},dt=function(e){if(!he)return;let t=[e];for(;t.length>0;){let e=t.pop(),n=y?y(e):e.nodeType;if(n===WG.processingInstruction||n===WG.comment&&EG(UG,e.data)){try{p(e)}catch{}continue}if(n===WG.element){let t=e,n=Xe(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])}},ft=function(e){let t=null,r=null;if(be)e=``+e;else{let t=yG(e,/^[\r\n\t ]+/);r=t&&t[0]}Je===`application/xhtml+xml`&&ze===Re&&(e=``+e+``);let i=x?D(e):e;if(ze===Re)try{t=new l().parseFromString(i,Je)}catch{}if(!t||!t.documentElement){t=j.createDocument(ze,`template`,null);try{t.documentElement.innerHTML=Be?S:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),ze===Re?P.call(t,ge?`html`:`body`)[0]:ge?t.documentElement:a},pt=function(e){return M.call(e.ownerDocument||e,e,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},mt=function(e){return e=bG(e,L,` `),e=bG(e,R,` `),e=bG(e,z,` `),e},ht=function(e){e.normalize();let t=M.call(e.ownerDocument||e,e,c.SHOW_TEXT|c.SHOW_COMMENT|c.SHOW_CDATA_SECTION|c.SHOW_PROCESSING_INSTRUCTION,null),n=t.nextNode();for(;n;)n.data=mt(n.data),n=t.nextNode();let r=e.querySelectorAll?.call(e,`template`);r&&pG(r,e=>{_t(e.content)&&ht(e.content)})},gt=function(e){let t=b?b(e):null;return typeof t!=`string`||Xe(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)},_t=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return y(e)===WG.documentFragment}catch{return!1}},vt=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return typeof y(e)==`number`}catch{return!1}};function yt(e,n,r){e.length!==0&&pG(e,e=>{e.call(t,n,r,Ze)})}let bt=function(e,t){return!!(he&&e.hasChildNodes()&&!vt(e.firstElementChild)&&EG(HG,e.textContent)&&EG(HG,e.innerHTML)||he&&e.namespaceURI===Re&&t===`style`&&vt(e.firstElementChild)||e.nodeType===WG.processingInstruction||he&&e.nodeType===WG.comment&&EG(UG,e.data))},xt=function(e,t){if(!se[t]&&Tt(t)&&(U.tagNameCheck instanceof RegExp&&EG(U.tagNameCheck,t)||U.tagNameCheck instanceof Function&&U.tagNameCheck(t)))return!1;if(De&&!Ae[t]){let t=g(e),n=h(e);if(n&&t){let r=n.length;for(let i=r-1;i>=0;--i){let r=Oe?n[i]:f(n[i],!0);t.insertBefore(r,m(e))}}}return ot(e),!0},St=function(e,n){if(yt(I.beforeSanitizeElements,e,null),e!==n&&g(e)===null)return!0;if(gt(e))return ot(e),!0;let r=Xe(b?b(e):e.nodeName);if(yt(I.uponSanitizeElement,e,{tagName:r,allowedTags:ie}),e!==n&&g(e)===null)return!0;if(bt(e,r))return ot(e),!0;if(se[r]||!(le.tagCheck instanceof Function&&le.tagCheck(r))&&!ie[r]){let t=xt(e,r);return t===!1&&yt(I.afterSanitizeElements,e,null),t}if((y?y(e):e.nodeType)===WG.element&&!at(e)||(r===`noscript`||r===`noembed`||r===`noframes`)&&EG(Dje,e.innerHTML))return ot(e),!0;if(me&&e.nodeType===WG.text){let n=mt(e.textContent);e.textContent!==n&&(hG(t.removed,{element:e.cloneNode()}),e.textContent=n)}return yt(I.afterSanitizeElements,e,null),!1},Ct=function(e,t,r){if(ce[t]||he&&t===`patchsrc`||he&&t===`for`&&e!==`label`&&e!==`output`||we&&(t===`id`||t===`name`)&&(r in n||r in Qe))return!1;let i=ae[t]||le.attributeCheck instanceof Function&&le.attributeCheck(t,e);if(!(de&&EG(B,t))&&!(ue&&EG(V,t))){if(!i){if(!(Tt(e)&&(U.tagNameCheck instanceof RegExp&&EG(U.tagNameCheck,e)||U.tagNameCheck instanceof Function&&U.tagNameCheck(e))&&(U.attributeNameCheck instanceof RegExp&&EG(U.attributeNameCheck,t)||U.attributeNameCheck instanceof Function&&U.attributeNameCheck(t,e))||t===`is`&&U.allowCustomizedBuiltInElements&&(U.tagNameCheck instanceof RegExp&&EG(U.tagNameCheck,r)||U.tagNameCheck instanceof Function&&U.tagNameCheck(r))))return!1}else if(!Pe[t]&&!EG(re,bG(r,te,``))&&!((t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&xG(r,`data:`)===0&&Me[e])&&!(fe&&!EG(ee,bG(r,te,``)))&&r)return!1}return!0},wt=kG({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),Tt=function(e){return!wt[_G(e)]&&EG(ne,e)},Et=function(e,t,n,r){if(x&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return D(r);case`TrustedScriptURL`:return O(r)}return r},Dt=function(e,n,r,i){try{r?e.setAttributeNS(r,n,i):e.setAttribute(n,i),gt(e)?ot(e):mG(t.removed)}catch{ct(n,e)}},Ot=function(e){yt(I.beforeSanitizeAttributes,e,null);let t=e.attributes;if(!t||gt(e))return;let n={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:ae,forceKeepAttr:void 0},r=t.length,i=Xe(e.nodeName);for(;r--;){let a=t[r],o=a.name,s=a.namespaceURI,c=a.value,l=Xe(o),u=c,d=o===`value`?u:lje(u);if(n.attrName=l,n.attrValue=d,n.keepAttr=!0,n.forceKeepAttr=void 0,yt(I.uponSanitizeAttribute,e,n),d=n.attrValue,Te&&(l===`id`||l===`name`)&&xG(d,Ee)!==0&&(ct(o,e),d=Ee+d),he&&EG(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,d)){ct(o,e);continue}if(l===`attributename`&&yG(d,`href`)){ct(o,e);continue}if(!n.forceKeepAttr){if(!n.keepAttr){ct(o,e);continue}if(!pe&&EG(Oje,d)){ct(o,e);continue}if(me&&(d=mt(d)),!Ct(i,l,d)){ct(o,e);continue}d=Et(i,l,s,d),d!==u&&Dt(e,o,s,d)}}yt(I.afterSanitizeAttributes,e,null)},kt=function(e){let t=null,n=pt(e);for(yt(I.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(yt(I.uponSanitizeShadowNode,t,null),St(t,e),Ot(t),_t(t.content)&&kt(t.content),(y?y(t):t.nodeType)===WG.element){let e=_(t);_t(e)&&(At(e),kt(e))}yt(I.afterSanitizeShadowDOM,e,null)},At=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){kt(e.shadow);continue}let n=e.node,r=(y?y(n):n.nodeType)===WG.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`&&Xe(e)===`template`){let e=n.content;_t(e)&&t.push({node:e,shadow:null})}}if(r){let e=_(n);_t(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(Be=!e,Be&&(e=``),typeof e!=`string`&&!vt(e)&&(e=mje(e),typeof e!=`string`))throw DG(`dirty is not a string, aborting`);if(!t.isSupported)return e;_e?(ie=ve,ae=ye):W(n),(I.uponSanitizeElement.length>0||I.uponSanitizeAttribute.length>0)&&(ie=AG(ie)),I.uponSanitizeAttribute.length>0&&(ae=AG(ae)),t.removed=[];let c=Oe&&typeof e!=`string`&&vt(e);if(c){dt(e);let t=b?b(e):e.nodeName;if(typeof t==`string`){let n=Xe(t);if(!ie[n]||se[n])throw st(e),DG(`root node is forbidden and cannot be sanitized in-place`)}if(gt(e))throw st(e),DG(`root node is clobbered and cannot be sanitized in-place`);try{At(e)}catch(t){throw st(e),t}}else if(vt(e))i=ft(``),a=i.ownerDocument.importNode(e,!0),a.nodeType===WG.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),At(a);else{if(!xe&&!me&&!ge&&e.indexOf(`<`)===-1)return x&&Ce?D(e):e;if(i=ft(e),!i)return xe?null:Ce?S:``}i&&be&&ot(i.firstChild);let l=c?e:i,u=pt(l);try{for(;o=u.nextNode();)St(o,l),Ot(o),_t(o.content)&&kt(o.content)}catch(n){throw c&&(st(e),pG(t.removed,e=>{e.element&&ut(e.element)})),n}if(c)return pG(t.removed,e=>{e.element&&ut(e.element)}),me&&ht(e),e;if(xe){if(me&&ht(i),Se)for(s=N.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(ae.shadowroot||ae.shadowrootmode)&&(s=F.call(r,s,!0)),s}let d=ge?i.outerHTML:i.innerHTML;return ge&&ie[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&EG(Tje,i.ownerDocument.doctype.name)&&(d=` `+d),me&&(d=mt(d)),x&&Ce?D(d):d},t.setConfig=function(){W(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{}),_e=!0,ve=ie,ye=ae},t.clearConfig=function(){Ze=null,_e=!1,ve=null,ye=null,x=C,S=``},t.isValidAttribute=function(e,t,n){return Ze||W({}),Ct(Xe(e),Xe(t),n)},t.addHook=function(e,t){typeof t==`function`&&wG(I,e)&&hG(I[e],t)},t.removeHook=function(e,t){if(wG(I,e)){if(t!==void 0){let n=sje(I[e],t);return n===-1?void 0:cje(I[e],n,1)[0]}return mG(I[e])}},t.removeHooks=function(e){wG(I,e)&&(I[e]=[])},t.removeAllHooks=function(){I=GG()},t}var JG=qG();function YG(e){this.content=e}YG.prototype={constructor:YG,find:function(e){for(var t=0;t>1}},YG.from=function(e){if(e instanceof YG)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new YG(t)};function XG(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=XG(i.content,a.content,n+1);if(e!=null)return e}n+=i.nodeSize}}function ZG(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?eK(t+1,i):eK(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}};nK.none=[];var rK=class extends Error{},iK=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=oK(this.content,t+this.openStart,n);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(aK(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(QG.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)}};iK.empty=new iK(QG.empty,0,0);function aK(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(aK(a.content,t-i-1,n-i-1)))}function oK(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=oK(o.content,t-a-1,n,o);return s&&e.replaceChild(i,o.copy(s))}function jje(e,t,n){if(n.openStart>e.depth)throw new rK(`Inserted content deeper than insertion position`);if(e.depth-n.openStart!=t.depth-n.openEnd)throw new rK(`Inconsistent open depths`);return sK(e,t,n,0)}function sK(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&&(uK(e.nodeAfter,r),a++));for(let e=a;ei&&lK(e,t,i+1),o=r.depth>i&&lK(n,r,i+1),s=[];return dK(null,e,i,s),a&&o&&t.index(i)==n.index(i)?(cK(a,o),uK(fK(a,pK(e,t,n,r,i+1)),s)):(a&&uK(fK(a,mK(e,t,i+1)),s),dK(t,n,i,s),o&&uK(fK(o,mK(n,r,i+1)),s)),dK(r,null,i,s),new QG(s)}function mK(e,t,n){let r=[];return dK(null,e,n,r),e.depth>n&&uK(fK(lK(e,t,n+1),mK(e,t,n+1)),r),dK(t,null,n,r),new QG(r)}function Mje(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(QG.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}var hK=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 _K(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=gK.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()+`)`),yK(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=QG.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=QG.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}};vK.prototype.text=void 0;var Ije=class e extends vK{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):yK(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 yK(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+`(`+t+`)`;return t}var bK=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new Lje(t,n);if(r.next==null)return e.empty;let i=xK(r);r.next&&r.err(`Unexpected trailing text`);let a=Wje(Uje(i));return Gje(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(` `)}};bK.empty=new bK(!0);var Lje=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==``&&this.tokens.pop(),this.tokens[0]==``&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw SyntaxError(e+` (in content expression '`+this.string+`')`)}};function xK(e){let t=[];do t.push(Rje(e));while(e.eat(`|`));return t.length==1?t[0]:{type:`choice`,exprs:t}}function Rje(e){let t=[];do t.push(zje(e));while(e.next&&e.next!=`)`&&e.next!=`|`);return t.length==1?t[0]:{type:`seq`,exprs:t}}function zje(e){let t=Hje(e);for(;;)if(e.eat(`+`))t={type:`plus`,expr:t};else if(e.eat(`*`))t={type:`star`,expr:t};else if(e.eat(`?`))t={type:`opt`,expr:t};else if(e.eat(`{`))t=Bje(e,t);else break;return t}function SK(e){/\D/.test(e.next)&&e.err(`Expected number, got '`+e.next+`'`);let t=Number(e.next);return e.pos++,t}function Bje(e,t){let n=SK(e),r=n;return e.eat(`,`)&&(r=e.next==`}`?-1:SK(e)),e.eat(`}`)||e.err(`Unclosed braced range`),{type:`range`,min:n,max:r,expr:t}}function Vje(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let i=[];for(let e in n){let r=n[e];r.isInGroup(t)&&i.push(r)}return i.length==0&&e.err(`No node type or group '`+t+`' found`),i}function Hje(e){if(e.eat(`(`)){let t=xK(e);return e.eat(`)`)||e.err(`Missing closing paren`),t}else if(/\W/.test(e.next))e.err(`Unexpected token '`+e.next+`'`);else{let t=Vje(e,e.next).map(t=>(e.inline==null?e.inline=t.isInline:e.inline!=t.isInline&&e.err(`Mixing inline and block content`),{type:`name`,value:t}));return e.pos++,t.length==1?t[0]:{type:`choice`,exprs:t}}}function Uje(e){let t=[[]];return i(a(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let i={term:r,to:n};return t[e].push(i),i}function i(e,t){e.forEach(e=>e.to=t)}function a(e,t){if(e.type==`choice`)return e.exprs.reduce((e,n)=>e.concat(a(n,t)),[]);if(e.type==`seq`)for(let r=0;;r++){let o=a(e.exprs[r],t);if(r==e.exprs.length-1)return o;i(o,t=n())}else if(e.type==`star`){let o=n();return r(t,o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`plus`){let o=n();return i(a(e.expr,t),o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`opt`)return[r(t)].concat(a(e.expr,t));else if(e.type==`range`){let o=t;for(let t=0;t{e[t].forEach(({term:t,to:n})=>{if(!t)return;let r;for(let e=0;e{r||i.push([t,r=[]]),r.indexOf(e)==-1&&r.push(e)})})});let a=t[r.join(`,`)]=new bK(r.indexOf(e.length-1)>-1);for(let e=0;e-1}get whitespace(){return this.spec.whitespace||(this.spec.code?`pre`:`normal`)}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:EK(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error(`NodeType.create can't construct text nodes`);return new vK(this,this.computeAttrs(e),QG.from(t),nK.setFrom(n))}createChecked(e=null,t,n){return t=QG.from(t),this.checkContent(t),new vK(this,this.computeAttrs(e),t,nK.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=QG.from(t),t.size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let r=this.contentMatch.matchFragment(t),i=r&&r.fillBefore(QG.empty,!0);return i?new vK(this,e,t.append(i),nK.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let t=0;t-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[t]=new e(t,n,i));let i=n.spec.topNode||`doc`;if(!r[i])throw RangeError(`Schema is missing its top node type ('`+i+`')`);if(!r.text)throw RangeError(`Every schema needs a 'text' type`);for(let e in r.text.attrs)throw RangeError(`The text node type should not have attributes`);return r}};function Kje(e,t,n){let r=n.split(`|`);return n=>{let i=n===null?`null`:typeof n;if(r.indexOf(i)<0)throw RangeError(`Expected value of type ${r} for attribute ${t} on type ${e}, got ${i}`)}}var qje=class{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,`default`),this.default=n.default,this.validate=typeof n.validate==`string`?Kje(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}},AK=class e{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=OK(e,r.attrs),this.excluded=null;let i=TK(this.attrs);this.instance=i?new nK(this,i):null}create(e=null){return!e&&this.instance?this.instance:new nK(this,EK(this.attrs,e))}static compile(t,n){let r=Object.create(null),i=0;return t.forEach((t,a)=>r[t]=new e(t,i++,n,a)),r}removeFromSet(e){for(var t=0;t-1}},jK=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=YG.from(e.nodes),t.marks=YG.from(e.marks||{}),this.nodes=kK.compile(this.spec.nodes,this),this.marks=AK.compile(this.spec.marks,this);let n=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw RangeError(e+` can not be both a node and a mark`);let t=this.nodes[e],r=t.spec.content||``,i=t.spec.marks;if(t.contentMatch=n[r]||(n[r]=bK.parse(r,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw RangeError(`Multiple linebreak nodes defined`);if(!t.isInline||!t.isLeaf)throw RangeError(`Linebreak replacement nodes must be inline leaf nodes`);this.linebreakReplacement=t}t.markSet=i==`_`?null:i?MK(this,i.split(` `)):i==``||!t.inlineContent?[]:null}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=n==null?[t]:n==``?[]:MK(this,n.split(` `))}this.nodeFromJSON=e=>vK.fromJSON(this,e),this.markFromJSON=e=>nK.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||`doc`],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if(typeof e==`string`)e=this.nodeType(e);else if(!(e instanceof kK))throw RangeError(`Invalid node type: `+e);else if(e.schema!=this)throw RangeError(`Node type from different schema used (`+e.name+`)`);return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new Ije(n,n.defaultAttrs,e,nK.setFrom(t))}mark(e,t){return typeof e==`string`&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw RangeError(`Unknown node type: `+e);return t}};function MK(e,t){let n=[];for(let r=0;r-1)&&n.push(o=r)}if(!o)throw SyntaxError(`Unknown mark type: '`+t[r]+`'`)}return n}function Jje(e){return e.tag!=null}function Yje(e){return e.style!=null}var NK=class e{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(Jje(e))this.tags.push(e);else if(Yje(e)){let t=/[^=]*/.exec(e.style)[0];n.indexOf(t)<0&&n.push(t),this.styles.push(e)}}),this.normalizeLists=!this.tags.some(t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)})}parse(e,t={}){let n=new VK(this,t,!1);return n.addAll(e,nK.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new VK(this,t,!0);return n.addAll(e,nK.none,t.from,t.to),iK.maxOpen(n.finish())}matchTag(e,t,n){for(let r=n?this.tags.indexOf(n)+1:0;re.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=t))){if(r.getAttrs){let e=r.getAttrs(t);if(e===!1)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=e.priority==null?50:e.priority,r=0;for(;r{n(e=HK(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let r=e.nodes[t].spec.parseDOM;r&&r.forEach(e=>{n(e=HK(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new e(t,e.schemaRules(t)))}},PK={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Xje={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},FK={ol:!0,ul:!0},IK=1,LK=2,RK=4;function zK(e,t,n){return t==null?e&&e.whitespace==`pre`?3:n&-5:(t?IK:0)|(t===`full`?LK:0)}var BK=class{constructor(e,t,n,r,i,a){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=a,this.content=[],this.activeMarks=nK.none,this.match=i||(a&RK?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(QG.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let t=this.type.contentMatch,n;return(n=t.findWrapping(e.type))?(this.match=t,n):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&IK)){let e=this.content[this.content.length-1],t;if(e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))){let n=e;e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-t[0].length))}}let t=QG.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(QG.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!PK.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},VK=class{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r=t.topNode,i,a=zK(null,t.preserveWhitespace,0)|(n?RK:0);i=r?new BK(r.type,r.attrs,nK.none,!0,t.topMatch||r.type.contentMatch,a):n?new BK(null,null,nK.none,!0,null,a):new BK(e.schema.topNodeType,null,nK.none,!0,null,a),this.nodes=[i],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,r=this.top,i=r.options&LK?`full`:this.localPreserveWS||(r.options&IK)>0,{schema:a}=this.parser;if(i===`full`||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(!i){if(n=n.replace(/[ \t\r\n\u000c]+/g,` `),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=r.content[r.content.length-1],i=e.previousSibling;(!t||i&&i.nodeName==`BR`||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}}else if(i===`full`)n=n.replace(/\r\n?/g,` diff --git a/static/index.html b/static/index.html index c364a1d1c..f526bc06e 100644 --- a/static/index.html +++ b/static/index.html @@ -26,7 +26,7 @@ - +